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

📄 a_cmsgallery.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                    buttonBar.append("<td class=\"maxwidth\">");
                    buttonBar.append("<input name=\"title\" value=\"");
                    buttonBar.append(title);
                    buttonBar.append("\" style=\"width: 95%\">");
                    buttonBar.append("</td>\r\n");
                    // hidden field 
                    buttonBar.append("<input type=\"hidden\" name=\"");
                    buttonBar.append(PARAM_PROPERTYVALUE);
                    buttonBar.append("\" value=\"");
                    buttonBar.append(title);
                    buttonBar.append("\">\r\n");
                    // edit property button
                    buttonBar.append(editPropertyButton());
                    // target select
                    buttonBar.append(targetSelectBox());
                    // preview button
                    buttonBar.append(previewButton());
                    buttonBar.append(buttonBar(HTML_END));
                }
            } else {
                // no resource to display, create empty row
                buttonBar.append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>");
                buttonBar.append("<img height=\"22\" border=\"0\" src=\"");
                buttonBar.append(getJsp().link(CmsWorkplace.VFS_PATH_RESOURCES + "tree/empty.gif"));
                buttonBar.append("\">");
                buttonBar.append("</td></tr></table>");
            }
        } catch (CmsException e) {
            // resource is deleted, display empty table
            buttonBar.append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td>");
            buttonBar.append("<img height=\"22\" border=\"0\" src=\"");
            buttonBar.append(getJsp().link(CmsWorkplace.VFS_PATH_RESOURCES + "tree/empty.gif"));
            buttonBar.append("\">");
            buttonBar.append("</td></tr></table>");
        }
        return buttonBar.toString();
    }

    /**
     * Builds the html String for the preview frame.<p>
     * 
     * @return the html String for the preview frame
     */
    public abstract String buildGalleryItemPreview();

    /**
     * Builds the html for the gallery items list.<p>
     * 
     * @return the html for the gallery items list 
     */
    public String buildGalleryItems() {

        StringBuffer result = new StringBuffer(64);
        result.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"maxwidth\">");
        result.append(buildGalleryItemListHeadline());
        List items = getGalleryItems();
        // get the current page number
        String pageno = getParamPage();
        if (pageno == null) {
            pageno = "1";
        }
        if (items != null && items.size() > 0) {
            // calculate page items
            int start = 0;
            int end = getSettings().getUserSettings().getExplorerFileEntries();
            start = (Integer.parseInt(pageno) * end) - end;
            end = (Integer.parseInt(pageno) * end);
            if (end > items.size()) {
                end = items.size();
            }
            if (start > end) {
                start = 0;
            }
            for (int i = start; i < end; i++) {

                CmsResource res = (CmsResource)items.get(i);
                int state = res.getState();
                String tdClass;
                switch (state) {
                    case CmsResource.STATE_CHANGED:
                        tdClass = "fc";
                        break;
                    case CmsResource.STATE_NEW:
                        tdClass = "fn";
                        break;
                    default:
                        tdClass = "list";
                }
                String resPath = getCms().getSitePath(res);
                String resName = CmsResource.getName(resPath);
                String title = getPropertyValue(res, CmsPropertyDefinition.PROPERTY_TITLE);

                result.append("<tr>\n");

                // append the custom start columns
                result.append(buildGalleryItemListCustomStartCols(res, tdClass));

                // file name
                result.append("\t<td class=\"");
                result.append(tdClass);
                result.append("\"><a class=\"");
                result.append(tdClass);
                result.append("\" href=\"javascript: preview(\'");
                result.append(resPath);
                result.append("\');\" title=\"");
                result.append(key(Messages.GUI_BUTTON_PREVIEW_0));
                result.append("\">");
                result.append(resName);
                result.append("</a></td>\n");
                // file title
                result.append("\t<td class=\"");
                result.append(tdClass);
                result.append("\">");
                result.append(CmsEncoder.escapeXml(title));
                result.append("</td>\n");

                // append the custom end columns
                result.append(buildGalleryItemListCustomEndCols(res, tdClass));

                result.append("</tr>\n");
            }
        }
        result.append("</table>");
        return result.toString();
    }

    /**
     * Returns the html for the gallery select box.<p>
     * 
     * @return the html for the gallery select box
     */
    public String buildGallerySelectBox() {

        List galleries = getGalleries();
        if (galleries != null && galleries.size() == 1) {
            // exactly one gallery present
            CmsResource res = (CmsResource)galleries.get(0);
            StringBuffer result = new StringBuffer(128);
            String path = getCms().getSitePath(res);
            String title = "";
            try {
                // read the gallery title
                title = getCms().readPropertyObject(path, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue("");
            } catch (CmsException e) {
                // error reading title property 
                LOG.error(e);
            }
            result.append(title);
            result.append(" (");
            result.append(path);
            result.append(" )\r\n");
            result.append("<input type=\"hidden\" name=\"");
            result.append(PARAM_GALLERYPATH);
            result.append("\" value=\"");
            result.append(path);
            result.append("\">");
            return result.toString();
        } else if (galleries.size() > 1) {
            // more than one gallery present
            int galleryCount = galleries.size();
            List options = new ArrayList(galleryCount);
            List values = new ArrayList(galleryCount);
            int selectedIndex = -1;
            for (int i = 0; i < galleryCount; i++) {
                CmsResource res = (CmsResource)galleries.get(i);
                String path = getCms().getSitePath(res);
                if (path.equals(getParamGalleryPath())) {
                    selectedIndex = i;
                }
                String title = "";
                try {
                    // read the gallery title
                    title = getCms().readPropertyObject(path, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue("");
                } catch (CmsException e) {
                    // error reading title property
                    if (LOG.isErrorEnabled()) {
                        LOG.error(e);
                    }
                }
                options.add(title + " (" + path + ")");
                values.add(path);

            }
            selectedIndex = sortOptions(options, values);
            String attrs = "name=\"" + PARAM_GALLERYPATH;
            attrs += "\" size=\"1\" style=\"width: 100%;\" onchange=\"displayGallery();\"";
            return buildSelect(attrs, options, values, selectedIndex);
        } else {
            // no gallery present, create hidden input field to avoid JS errors
            StringBuffer result = new StringBuffer(128);
            result.append(key(Messages.getGalleryNotFoundKey(getGalleryTypeName())));
            result.append("\r\n<input type=\"hidden\" name=\"");
            result.append(PARAM_GALLERYPATH);
            result.append("\">");
            return result.toString();
        }
    }

    /**
     * Builds the HTML String for the page select box.<p>
     * 
     * @return the HTML String for the page select box
     */
    public String buildPageSelectBox() {

        StringBuffer html = new StringBuffer(16);
        List items = getGalleryItems();
        // get the page number
        String pageno = getParamPage();
        if (pageno == null) {
            pageno = "1";
        }
        int count = 0;
        int pages = 1;
        int rest = 0;
        // get the maxentries per page from the user settings
        int maxentries = getSettings().getUserSettings().getExplorerFileEntries();

        if (items != null) {
            count = items.size();
        }
        // calculate the number of pages
        if (count > maxentries) {
            pages = count / maxentries;
            rest = count % maxentries;
            if (rest > 0) {
                rest = 1;
            } else {
                rest = 0;
            }
            pages += rest;
        }
        // display the select box if the number of pages > 1
        if (pages > 1) {
            html.append("<select name=\"page\" class=\"location\" onchange=\"displayGallery();\">");
            String selected = "";
            for (int i = 1; i < pages + 1; i++) {
                if (i == Integer.parseInt(pageno)) {
                    selected = " selected=\"selected\"";
                }
                html.append("<option value='");
                html.append(i);
                html.append("'");
                html.append(selected);
                html.append(">");
                html.append(i);
                html.append("</option>");
                selected = "";
            }
            html.append("</select>");
        }

        return html.toString();
    }

    /**
     * Compares gallery objects by their order, this is used to sort the gallery buttons for the editors.<p>
     * 
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    public int compareTo(Object o) {

        if (!(o instanceof A_CmsGallery)) {
            // wrong object
            return 0;
        }

        // compare the order values of the galleries
        return getOrder().compareTo(((A_CmsGallery)o).getOrder());
    }

    /**
     * Generates a delete button for the gallery button bar.<p>
     * 
     * This button is disabled if the urrent user has no write permissions.<p>
     * 
     * Overwrite this method if necessary in the specified gallery class.<p>
     * 
     * @return a delete button for the gallery button bar
     */
    public String deleteButton() {

        try {
            if (hasWritePermissions()) {
                return button(
                    "javascript:deleteResource(\'" + getParamResourcePath() + "\');",
                    null,
                    "deletecontent.png",
                    Messages.GUI_TITLE_DELETE_0,
                    0);
            }
        } catch (CmsException e) {
            // error checking permissions
            if (LOG.isErrorEnabled()) {
                LOG.error(e);
            }
        }
        return button(null, null, "deletecontent_in.png", "", 0);
    }

    /**
     * Generates an edit property button for the gallery button bar.<p>
     * 
     * If the current resource is not 'editable' a disabled button will be returned.<p>
     * 
     * Overwrite this method if necessary in the specified gallery class.<p>
     * 
     * @return an edit property button for the gallery button bar
     */
    public String editPropertyButton() {

        try {
            if (hasWritePermissions()) {
                return button(
                    "javascript:editProperty('" + getParamResourcePath() + "');",
                    null,
                    "edit.png",
                    Messages.GUI_INPUT_EDITPROPERTYINFO_0,
                    0);
            }
        } catch (CmsException e) {
            // error checking permissions
            LOG.error(e);
        }
        return button(null, null, "edit_in.png", "", 0);
    }

    /**
     * Checks if at least one gallery exists.<p>
     * 
     * @return true if at least one gallery exists, otherwise false
     */
    public boolean galleriesExists() {

        List galleries = getGalleries();
        if (galleries != null && galleries.size() > 0) {
            // at least one gallery exists
            return true;
        }
        return false;
    }

    /**
     * Returns the javascript body onload call for the gallery head frame.<p>
     * 
     * @return the javascript body onload call for the gallery head frame
     */
    public String getBodyOnload() {

        StringBuffer onload = new StringBuffer();
        onload.append("self.focus();");
        if (CmsStringUtil.isEmpty(getParamGalleryPath())) {
            onload.append("displayGallery();");
        }

        return onload.toString();
    }

    /**
     * Return the path of the css file used in the galleries.<p>
     * 
     * @return the path of the css file used in the galleries
     */
    public String getCssPath() {

        return getJsp().link(PATH_GALLERIES + CSS_FILENAME);
    }

    /**
     * Returns the current resource in the gallery.<p>
     *  
     * @return the current resource in the gallery
     */
    public CmsResource getCurrentResource() {

        return m_currentResource;
    }

    /**
     * Returns a list of galleries which have the required gallery type id.<p>
     * 
     * @return a list of galleries
     */
    public List getGalleries() {

        List galleries = null;
        int galleryTypeId = getGalleryTypeId();
        try {
            // get the galleries of the current site
            galleries = getCms().readResources(
                "/",
                CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(galleryTypeId));

⌨️ 快捷键说明

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