⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a_cmsbackoffice.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        }
        return new Integer(-1);
    }

    /**
     * Gets the content of a given template file.
     * <P>
     * While processing the template file the table entry
     * <code>entryTitle<code> will be displayed in the delete dialog
     *
     * @param cms A_CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName not used here
     * @param parameters get the parameters action for the button activity
     * and id for the used content definition instance object
     * @param templateSelector template section that should be processed.
     * @return Processed content of the given template file.
     * @exception CmsException
     */
    public byte[] getContentPermissions(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException {
        //return var
        byte[] processResult = null;
        Object o = null;
        // session will be created or fetched
        I_CmsSession session = (CmsSession) cms.getRequestContext().getSession(true);
        //get the class of the content definition
        Class cdClass = getContentDefinitionClass();

        // get mode of permission changing
        String mode = (String) parameters.get("chmode");
        if(mode == null || "".equals(mode)){
            mode = "";
        }
        //get (stored) id parameter
        String id = (String) parameters.get("id");
        if (id == null) {
            id = "";
        }
        // get value of hidden input field action
        String action = (String) parameters.get("action");
        // get values of input fields
        int newOwner = 0;
        int newGroup = 0;
        String newOwnerString = (String) parameters.get("owner");
        if (newOwnerString != null && !"".equals(newOwnerString)){
            newOwner = Integer.parseInt(newOwnerString);
        }
        String newGroupString = (String) parameters.get("groupId");
        if (newGroupString != null && !"".equals(newGroupString)){
            newGroup = Integer.parseInt(newGroupString);
        }
        int newAccessFlags = getAccessValue(parameters);
        //no button pressed, go to the default section!
        //change permissions dialog, displays owner, group and access flags of the entry to be changed
        if (action == null || action.equals("")) {
            if (id != "" && mode != "") {
                //access content definition constructor by reflection
                o = getContentDefinition(cms, cdClass, new Integer(id));
                //set template section
                templateSelector = mode;
                int curOwner = ((I_CmsExtendedContentDefinition) o).getOwner();
                int curGroup = ((I_CmsExtendedContentDefinition) o).getGroupId();
                int curAccessFlags = ((I_CmsExtendedContentDefinition) o).getAccessFlags();
                // set the values in the dialog
                this.setOwnerSelectbox(cms, template, curOwner);
                this.setGroupSelectbox(cms, template, curGroup);
                this.setAccessValue(template, curAccessFlags);
                template.setData("id", id);
                template.setData("setaction", mode);
            }
            // confirmation button pressed, process data!
        } else {
            //set template section
            templateSelector = "done";
            //remove marker
            session.removeValue("idpermissions");
            //change the content definition instance
            Integer idInteger = null;
            try {
                idInteger = Integer.valueOf(id);
                //access content definition constructor by reflection
                o = getContentDefinition(cms, cdClass, idInteger);
            } catch (Exception e) {
                //access content definition constructor by reflection
                o = getContentDefinition(cms, cdClass, id);
            }

            //get change method and change content definition instance
            try {
                if ("chown".equalsIgnoreCase(action) && newOwner != 0){
                    ((I_CmsExtendedContentDefinition) o).chown(cms, newOwner);
                } else if ("chgrp".equalsIgnoreCase(action) && newGroup != 0){
                    ((I_CmsExtendedContentDefinition) o).chgrp(cms, newGroup);
                } else if ("chmod".equalsIgnoreCase(action)){
                    ((I_CmsExtendedContentDefinition) o).chmod(cms, newAccessFlags);
                }
            } catch (Exception e) {
                if (I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                    A_OpenCms.log(C_OPENCMS_INFO, getClassName() + ": Backoffice: changing permissions method throwed an exception!");
                }
                templateSelector = "permissionserror";
                template.setData("permissionserror", e.getMessage());
            }
        }
        //finally start the processing
        processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
        return processResult;
    }

  /**
  * Gets the content of a given template file.
  * <P>
  *
  * @param cms A_CmsObject Object for accessing system resources
  * @param templateFile Filename of the template file
  * @param elementName not used here
  * @param parameters get the parameters action for the button activity
  * and id for the used content definition instance object
  * and the author, title, text content for setting the new/changed data
  * @param templateSelector template section that should be processed.
  * @return Processed content of the given template file.
  * @exception CmsException
  */

  private byte[] getContentHead(CmsObject cms, CmsXmlWpTemplateFile template, String elementName, Hashtable parameters, String templateSelector) throws CmsException {

    //return var
    byte[] processResult = null;
    //get the class of the content definition
    Class cdClass = getContentDefinitionClass();

    //init vars
    String singleSelection = "";
    String allSelections = "";

    //create new or fetch existing session
    CmsSession session = (CmsSession) cms.getRequestContext().getSession(true);
    String uri = cms.getRequestContext().getUri();
    String sessionSelectBoxValue = uri+"selectBoxValue";
    //get filter method from session
    String selectBoxValue = (String) parameters.get("selectbox");
    if(selectBoxValue == null) {
      // set default value
      if((String)session.getValue(sessionSelectBoxValue) != null) {
        // came back from edit or something ... redisplay last filter
          selectBoxValue = (String)session.getValue(sessionSelectBoxValue);
      } else {
        // the very first time here...
         selectBoxValue = "0";
      }
    }
    boolean filterChanged = true;
    if( selectBoxValue.equals((String)session.getValue(sessionSelectBoxValue)) ) {
        filterChanged = false;
    }else {
        filterChanged = true;
    }

    //get vector of filter names from the content definition
    Vector filterMethods = getFilterMethods(cms);

    if( Integer.parseInt(selectBoxValue) >=  filterMethods.size() ) {
        // the stored seclectBoxValue is does not exist any more, ...
        selectBoxValue = "0";
    }

    session.putValue(sessionSelectBoxValue, selectBoxValue); // store in session for Selectbox!
    session.putValue("filter",selectBoxValue);  // store filter in session for getContentList!

    String filterParam = (String) parameters.get("filterparameter");
    String action = (String) parameters.get("action");
    String setaction = (String) parameters.get("setaction");
    // create the key for the filterparameter in the session ... should be unique to avoid problems...
    String sessionFilterParam = uri+selectBoxValue+"filterparameter";
    //store filterparameter in the session, new enty for every filter of every url ...
    if (filterParam != null) {
      session.putValue(sessionFilterParam, filterParam);
    }

    //create appropriate class name with underscores for labels
    String moduleName = "";
    moduleName = (String) getClass().toString(); //get name
    moduleName = moduleName.substring(5); //remove 'class' substring at the beginning
    moduleName = moduleName.trim();
    moduleName = moduleName.replace('.', '_'); //replace dots with underscores

    //create new language file object
    CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
    //set labels in the template
    template.setData("filterlabel", lang.getLanguageValue(moduleName + ".label.filter"));
    template.setData("filterparameterlabel", lang.getLanguageValue(moduleName + ".label.filterparameter"));

    //no filter selected so far, store a default filter in the session
    CmsFilterMethod filterMethod = null;
    if (selectBoxValue == null) {
      CmsFilterMethod defaultFilter = (CmsFilterMethod) filterMethods.firstElement();
      session.putValue("selectbox", defaultFilter.getFilterName());
    }

    // show param box ?
    CmsFilterMethod currentFilter = (CmsFilterMethod) filterMethods.elementAt(Integer.parseInt(selectBoxValue));
    if(currentFilter.hasUserParameter()) {
        if(filterChanged) {
            template.setData("filterparameter", currentFilter.getDefaultFilterParam());
            // access default in getContentList() ....
            session.putValue(sessionFilterParam, currentFilter.getDefaultFilterParam());
        } else if(filterParam!= null) {
            template.setData("filterparameter", filterParam);
        } else {
            // redisplay after edit or something like this ...
            template.setData("filterparameter", (String)session.getValue(sessionFilterParam));
        }
        // check if there is only one filtermethod, do not show the selectbox then
        if (filterMethods.size()<2) {
          // replace the selectbox with a simple text output
          CmsFilterMethod defaultFilter = (CmsFilterMethod) filterMethods.firstElement();
          template.setData("filtername",defaultFilter.getFilterName());
          template.setData("insertFilter", template.getProcessedDataValue("noSelectboxWithParam", this, parameters));
        } else {
          template.setData("insertFilter", template.getProcessedDataValue("selectboxWithParam", this, parameters));
          }
        template.setData("setfocus", template.getDataValue("focus"));
    }else{
        // check if there is only one filtermethod, do not show the selectbox then
        if (filterMethods.size()<2) {
          // replace the selectbox with a simple text output
          CmsFilterMethod defaultFilter = (CmsFilterMethod) filterMethods.firstElement();
          template.setData("filtername",defaultFilter.getFilterName());
          template.setData("insertFilter", template.getProcessedDataValue("noSelectbox", this, parameters));
        } else {
          template.setData("insertFilter", template.getProcessedDataValue("singleSelectbox", this, parameters));
        }
    }

    //if getCreateUrl equals null, the "create new entry" button
    //will not be displayed in the template
    String createButton = null;
    try {
      createButton = (String) getCreateUrl(cms, null, null, null);
    } catch (Exception e) {
    }
    if (createButton == null) {
      String cb = template.getDataValue("nowand");
      template.setData("createbutton", cb);
    } else {
        boolean buttonActiv = true;
        Boolean isProjectDependend = new Boolean(true);
        if(isExtendedList() && (cms.getRequestContext().currentProject().getId() == cms.onlineProject().getId())){
            buttonActiv = false;
        }
        if(buttonActiv){
            String cb = template.getProcessedDataValue("wand", this, parameters);
            template.setData("createbutton", cb);
        }else{
            String cb = template.getProcessedDataValue("deactivwand", this, parameters);
            template.setData("createbutton", cb);
        }
    }

    //if getSetupUrl is empty, the module setup button will not be displayed in the template.
    String setupButton = null;
    try {
      setupButton = (String) getSetupUrl(cms, null, null, null);
    } catch (Exception e) {
    }
    if ((setupButton == null) || (setupButton.equals(""))){
      String sb = template.getDataValue("nosetup");
      template.setData("setupbutton", sb);
    } else {
      String sb= template.getProcessedDataValue("setup", this, parameters);
      template.setData("setupbutton",sb);
    }

    //finally start the processing
    processResult = startProcessing(cms, template, elementName, parameters, templateSelector);
    return processResult;
  }
  /**
   * Gets the content of a given template file.
   * This method displays any content provided by a content definition
   * class on the template. The used backoffice class does not need to use a
   * special getContent method. It just has to extend the methods of this class!
   * Using reflection, this method creates the table headline and table content
   * with the layout provided by the template automatically!
   * @param cms CmsObjectfor accessing system resources
   * @param templateFile Filename of the template file
   * @param elementName <em>not used here</em>.
   * @param parameters <em>not used here</em>.
   * @param templateSelector template section that should be processed.
   * @return Processed content of the given template 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -