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

📄 a_cmsgallery.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        m_paramFieldId = fieldId;
    }

    /**
     * Sets the path of the gallery to display.<p>
     *
     * @param galleryPath the path of the gallery to display
     */
    public void setParamGalleryPath(String galleryPath) {

        m_paramGalleryPath = galleryPath;
    }

    /**
     * Sets the current page to display in the item list.<p>
     *
     * @param page the current page to display in the item list
     */
    public void setParamPage(String page) {

        m_paramPage = page;
    }

    /**
     * Sets the property value parameter.<p>
     *
     * @param paramPropertyValue the property value parameter to set
     */
    public void setParamPropertyValue(String paramPropertyValue) {

        m_paramPropertyValue = paramPropertyValue;
    }

    /**
     * Sets the resource path.<p>
     *
     * @param resourcePath the resource path to set
     */
    public void setParamResourcePath(String resourcePath) {

        m_paramResourcePath = resourcePath;
    }

    /**
     * Sets the search word to look up in the gallery items.<p>
     * 
     * @param searchWord the search word to look up in the gallery items
     */
    public void setParamSearchWord(String searchWord) {

        m_paramSearchWord = searchWord;
    }

    /**
     * Sets the extended folder resource type this gallery is based on.<p>
     * 
     * @param type the extended folder resource type this gallery is based on
     */
    public void setResourceType(CmsResourceTypeFolderExtended type) {

        m_resourceType = type;
    }

    /**
     * Generates a HTML String representing a target select box.<p>
     * 
     * @return a HTML String representing a target select box
     */
    public String targetSelectBox() {

        StringBuffer targetSelectBox = new StringBuffer(32);
        targetSelectBox.append(buttonBarSpacer(5));
        targetSelectBox.append("<td nowrap><b>");
        targetSelectBox.append(key(Messages.GUI_INPUT_LINKTARGET_0));
        targetSelectBox.append("</b>&nbsp;</td>");
        targetSelectBox.append("<td>\r\n");
        targetSelectBox.append("<select name=\"linktarget\" id=\"linktarget\" size=\"1\" style=\"width:150px\"");
        if (MODE_VIEW.equals(getParamDialogMode())) {
            targetSelectBox.append(" disabled=\"disabled\"");
        }
        targetSelectBox.append(">");
        targetSelectBox.append(getTargetOptions());
        targetSelectBox.append("</select>");
        targetSelectBox.append("</td>");

        return targetSelectBox.toString();
    }

    /**
     * Builds the HTML for the wizard button.<p>
     * 
     * @return the HTML for the wizard button
     */
    public String wizardButton() {

        return button("javascript:wizard();", null, "upload.png", OpenCms.getWorkplaceManager().getExplorerTypeSetting(
            "upload").getKey(), 0);
    }

    /**
     * Generates the HTML for custom columns to shown at the end of the list of gallery columns.<p>
     *  
     * @param res the current VFS resource 
     * @param tdClass the current syle sheet class name for the table cell
     * 
     * @return the HTML for custom columns to shown at the end of the list of gallery columns
     */
    protected String buildGalleryItemListCustomEndCols(CmsResource res, String tdClass) {

        StringBuffer result = new StringBuffer(64);
        result.append("\t<td class=\"");
        result.append(tdClass);
        result.append("\" style=\"text-align: right;\">");
        result.append(res.getLength() / 1024);
        result.append(" ");
        result.append(key(Messages.GUI_LABEL_KILOBYTES_0));
        result.append("</td>\n");
        return result.toString();
    }

    /**
     * Generates the HTML for custom columns to shown at the start of the list of gallery columns.<p>
     *  
     * @param res the current VFS resource 
     * @param tdClass the current syle sheet class name for the table cell
     * 
     * @return the HTML for custom columns to shown at the end of the list of gallery columns
     */
    protected String buildGalleryItemListCustomStartCols(CmsResource res, String tdClass) {

        String resType;
        try {
            // get the resource type name
            resType = OpenCms.getResourceManager().getResourceType(res.getTypeId()).getTypeName();
        } catch (CmsLoaderException e) {
            // unknown restype (highly unlikley)
            resType = null;
        }
        StringBuffer result = new StringBuffer(64);
        result.append("\t<td>");
        if ((resType != null) && (tdClass != null)) {
            result.append("<img src=\"");
            result.append(getSkinUri());
            result.append("filetypes/");
            result.append(resType);
            result.append(".gif\">");
        }
        result.append("</td>\n");
        return result.toString();
    }

    /**
     * Generates the HTML for the gallery item list headline.<p>
     * 
     * @return the HTML for the gallery item list headline
     */
    protected String buildGalleryItemListHeadline() {

        StringBuffer headline = new StringBuffer(32);
        headline.append("<tr>");
        headline.append("<td class=\"headline\">&nbsp;</td>");
        headline.append("<td class=\"headline\" width=\"35%\">");
        headline.append(key(Messages.GUI_LABEL_NAME_0));
        headline.append("</td>");
        headline.append("<td class=\"headline\" width=\"55%\">");
        headline.append(key(Messages.GUI_LABEL_TITLE_0));
        headline.append("</td>");
        headline.append("<td class=\"headline\" style=\"text-align: right;\" width=\"10%\">");
        headline.append(key(Messages.GUI_LABEL_SIZE_0));
        headline.append("</td>");
        headline.append("</tr>");

        return headline.toString();
    }

    /**
     * Returns the value of the given property definition of the specified resource.<p>
     * 
     * If the property value is null, '[resourcename]' will be returned instead.<p>
     *  
     * @param resource the cms resource
     * @param propertydefinition the property definition
     * @return the value of the title property or '[resourcename]' if property value was null 
     */
    protected String getPropertyValue(CmsResource resource, String propertydefinition) {

        String value = "";
        if (resource != null) {
            String resPath = getCms().getSitePath(resource);
            String resName = CmsResource.getName(resPath);
            try {
                CmsProperty property = getCms().readPropertyObject(resPath, propertydefinition, false);
                // get property value
                value = property.getValue("[" + resName + "]");
            } catch (CmsException e) {
                // error reading property object
                LOG.error(e);
            }
        }
        return value;
    }

    /**
     * Returns a list of hit items.<p>
     * 
     * Searches by the title property value and resource name.<p> 
     * 
     * @param items a list of resource items
     * @return a list of hit items
     */
    protected List getSearchHits(List items) {

        String searchword = getParamSearchWord().toLowerCase();
        List hitlist = new ArrayList();
        if (items != null) {
            Iterator i = items.iterator();
            while (i.hasNext()) {
                CmsResource res = (CmsResource)i.next();
                String resname = res.getName().toLowerCase();
                String restitle = getJsp().property(
                    CmsPropertyDefinition.PROPERTY_TITLE,
                    getCms().getSitePath(res),
                    resname).toLowerCase();
                if (restitle.indexOf(searchword) != -1 || resname.indexOf(searchword) != -1) {
                    // add this resource to the hitlist
                    hitlist.add(res);
                }
            }
        }

        return hitlist;
    }

    /**
     * Returns a HTML String representing the options of the target select box.<p>
     * 
     * @return a HTML String representing the options of the target select box
     */
    protected String getTargetOptions() {

        StringBuffer options = new StringBuffer();
        options.append("<option value=\"_self\">");
        options.append(key(Messages.GUI_INPUT_LINKTARGETSELF_0));
        options.append("</option>\r\n");
        options.append("<option value=\"_blank\">");
        options.append(key(Messages.GUI_INPUT_LINKTARGETBLANK_0));
        options.append("</option>\r\n");
        options.append("<option value=\"_top\">");
        options.append(key(Messages.GUI_INPUT_LINKTARGETTOP_0));
        options.append("</option>\r\n");

        return options.toString();
    }

    /**
     * Checks if the current user has required permissions to edit the current resource.<p>
     * 
     * @return true if the required permissions are satisfied
     * @throws CmsException if something goes wrong
     */
    protected boolean hasWritePermissions() throws CmsException {

        return getCms().hasPermissions(
            getCurrentResource(),
            CmsPermissionSet.ACCESS_WRITE,
            false,
            CmsResourceFilter.ALL);
    }

    /**
     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
     */
    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {

        // fill the parameter values in the get/set methods
        fillParamValues(request);
        // set the dialog type
        setParamDialogtype(DIALOG_TYPE);
        if (CmsStringUtil.isEmpty(getParamGalleryPath())) {
            String lastUsedGallery = getSettings().getLastUsedGallery(getGalleryTypeId());
            if (CmsStringUtil.isNotEmpty(lastUsedGallery)) {
                // set the resourcepath of the last used gallery if the resource is not deleted
                try {
                    getCms().readResource(lastUsedGallery, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED);
                    setParamGalleryPath(lastUsedGallery);
                } catch (CmsException e) {
                    // reading the last used gallery failed, may be deleted
                }
            }
        }
    }

    /**
     * Sorts the options and associated values in alphabetical order.<p>
     * 
     * @param options a list of options
     * @param values a list of associated values
     * 
     * @return the new index of the currently selected option according to the new order
     */
    protected int sortOptions(List options, List values) {

        int selectedIndex = -1;
        Map valuesByOption = new TreeMap();

        // save the values in a map keyed by their associated option
        for (int i = 0, n = options.size(); i < n; i++) {

            String option = (String)options.get(i);
            String value = (String)values.get(i);

            if (CmsStringUtil.isNotEmpty(option) && CmsStringUtil.isNotEmpty(value)) {
                valuesByOption.put(option, value);
            }
        }

        // sort the options
        values.clear();
        options.clear();

        // bring the values in the new order according to the sorted options
        Iterator it = valuesByOption.keySet().iterator();
        while (it.hasNext()) {
            String option = (String)it.next();
            String value = (String)valuesByOption.get(option);

            if (value.equals(getParamGalleryPath())) {
                selectedIndex = options.size();
            }

            options.add(option);
            values.add(value);
        }

        return selectedIndex;
    }

    /**
     * Changes the value of the property title for the specified resource.<p>
     *  
     * @param res the resource to change the property value
     */
    protected void writeTitleProperty(CmsResource res) {

        String resPath = getCms().getSitePath(res);
        String currentPropertyValue = getParamPropertyValue();
        try {
            CmsProperty currentProperty = getCms().readPropertyObject(
                resPath,
                CmsPropertyDefinition.PROPERTY_TITLE,
                false);
            // detect if property is a null property or not
            if (currentProperty.isNullProperty()) {
                // create new property object and set key and value
                currentProperty = new CmsProperty();
                currentProperty.setName(CmsPropertyDefinition.PROPERTY_TITLE);
                if (OpenCms.getWorkplaceManager().isDefaultPropertiesOnStructure()) {
                    // set structure value
                    currentProperty.setStructureValue(currentPropertyValue);
                    currentProperty.setResourceValue(null);
                } else {
                    // set resource value
                    currentProperty.setStructureValue(null);
                    currentProperty.setResourceValue(currentPropertyValue);
                }
            } else if (currentProperty.getStructureValue() != null) {
                // structure value has to be updated
                currentProperty.setStructureValue(currentPropertyValue);
                currentProperty.setResourceValue(null);
            } else {
                // resource value has to be updated
                currentProperty.setStructureValue(null);
                currentProperty.setResourceValue(currentPropertyValue);
            }
            CmsLock lock = getCms().getLock(res);
            if (lock.getType() == CmsLock.TYPE_UNLOCKED) {
                // lock resource before operation
                getCms().lockResource(resPath);
            }
            // write the property to the resource
            getCms().writePropertyObject(resPath, currentProperty);
            // unlock the resource
            getCms().unlockResource(resPath);
        } catch (CmsException e) {
            // writing the property failed, log error
            LOG.error(e);
        }
    }
}

⌨️ 快捷键说明

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