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

📄 xmlportlets.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            Properties oprops = new Properties();            oprops.put("method", "html");            oprops.put("indent-amount", "2");            serializer.setOutputProperties(oprops);            FileOutputStream fileStream = new FileOutputStream(destinationFileName);            serializer.transform(new DOMSource(xmlDoc),                             new StreamResult(fileStream));        } catch ( Throwable t ){            throw new JahiaException(  "XMLPortlets",                                        "Exception " + t.getMessage(),                                        JahiaException.ERROR,                                        JahiaException.SERVICE_ERROR);        }    }    //--------------------------------------------------------------------------    /**     * Processes through all the parameter tags of a given node to find the value of a certain named parameter     *     */    public String getParameterValue(Node paramParent, String parameterName) throws JahiaException {    if (!paramParent.hasChildNodes()) {        throw new JahiaException("No parameters available on portlet XML tag",                     "Parent has no children at all",                     JahiaException.CRITICAL,                     JahiaException.CONFIG_ERROR);    }    Node curNode = paramParent.getFirstChild();    while (curNode != null) {        // let's go through all the children nodes        if (curNode.getNodeType() == Node.ELEMENT_NODE) {        if (curNode.getNodeName().equalsIgnoreCase(PARAMETER_TAG)) {            // we have found a parameter tag, let's check further for match of param name            NamedNodeMap attrib = curNode.getAttributes();            Node paramAttrib = attrib.getNamedItem(PARAMETER_TAG_NAME_ATTRIBUTE);            if (paramAttrib != null) {            if (paramAttrib.getNodeValue().equalsIgnoreCase(parameterName)) {                // we found the parameter                // we must now extract value of text node below this node.                Node textNode = curNode.getFirstChild();                if (textNode.getNodeType() == Node.TEXT_NODE) {                return textNode.getNodeValue();                } else {                throw new JahiaException(ERROR_READING_PLML_FILE_MSG,                             "Value of parameter is not in correct format, should only be text",                             JahiaException.CRITICAL,                             JahiaException.CONFIG_ERROR);                }            }            } else {            throw new JahiaException(ERROR_READING_PLML_FILE_MSG,                         "No attribute name found on parameter !",                         JahiaException.CRITICAL,                         JahiaException.CONFIG_ERROR);            }        }        } else {        // we just ignore other type of tags        }        curNode = curNode.getNextSibling();    }    throw new JahiaException(ERROR_READING_PLML_FILE_MSG,                 "No parameter with name "+ parameterName +" found !",                 JahiaException.CRITICAL,                 JahiaException.CONFIG_ERROR);    } // end getParameterValue()    //--------------------------------------------------------------------------    /**     * Find the value of a certain named attribute     *     */    public String getAttributeValue(Node paramParent, String attributeName) throws JahiaException {    NamedNodeMap attrib = paramParent.getAttributes();    Node paramAttrib = attrib.getNamedItem(attributeName);    return paramAttrib.getNodeValue();    } // end getAttributeValue()    //--------------------------------------------------------------------------    /**     * Retrieves a column count for the specified page     *     * @author Jerome Bedat     *     */    public int getColumnCount() throws JahiaException {    MaxColumn  = 0;    boolean isPortletGroupNode = false;    portletgroupNode = plmlNode.getFirstChild();    try {        while (portletgroupNode != null) {            if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {                if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {                    isPortletGroupNode = true;                    Node portletNode = portletgroupNode.getFirstChild();                    while (portletNode != null) {                        // we are going through the portletgroup tags which represent list of portlets                        if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {                            // we are now on a PORTLET tag                            if (Integer.parseInt(getParameterValue(portletNode, "column_position")) > MaxColumn) { MaxColumn = Integer.parseInt(getParameterValue(portletNode, "column_position")); }                        }                        portletNode = portletNode.getNextSibling();                    }                }            }            portletgroupNode = portletgroupNode.getNextSibling();        }    } catch (NumberFormatException n) {        throw new JahiaException(ERROR_READING_PLML_FILE_MSG,                                "Invalid Integer !!!",                                JahiaException.CRITICAL,                                JahiaException.CONFIG_ERROR);    }    if (!isPortletGroupNode) {        addPortletGroup();        getColumnCount();    }    return MaxColumn;    } // end getColumnCount()    //--------------------------------------------------------------------------    /**     * Retrieves a portlet settings     *     * @author Jerome Bedat     *     */    public PortletObj getPortlet(int thePortletID) throws JahiaException {    PortletObj thePortlet = null;    boolean isPortletGroupNode = false;    portletgroupNode = plmlNode.getFirstChild();    try {        while (portletgroupNode != null) {            if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {                if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {                    isPortletGroupNode = true;                    Node portletNode = portletgroupNode.getFirstChild();                    while (portletNode != null) {                        // we are going through the portletgroup tags which represent list of portlets                        if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {                            // we are now on a PORTLET tag                            paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);                            if (Integer.parseInt(paramAttrNode) == thePortletID) {                                thePortlet = new PortletObj(Integer.parseInt(paramAttrNode),                                                            Integer.parseInt(getParameterValue(portletNode, "source_id")),                                                            Integer.parseInt(getParameterValue(portletNode, "active")),                                                            getParameterValue(portletNode, "title"),                                                            getParameterValue(portletNode, "icon_url"),                                                            getParameterValue(portletNode, "bgcolor"),                                                            getParameterValue(portletNode, "bgimage_url"),                                                            getParameterValue(portletNode, "font"),                                                            getParameterValue(portletNode, "fontsize"),                                                            getParameterValue(portletNode, "fontcolor"),                                                            Integer.parseInt(getParameterValue(portletNode, "skin_id")),                                                            Integer.parseInt(getParameterValue(portletNode, "scrollable")),                                                            Integer.parseInt(getParameterValue(portletNode, "resizable")),                                                            Integer.parseInt(getParameterValue(portletNode, "fixed")),                                                            Integer.parseInt(getParameterValue(portletNode, "innerspace")),                                                            Integer.parseInt(getParameterValue(portletNode, "x")),                                                            Integer.parseInt(getParameterValue(portletNode, "y")),                                                            Integer.parseInt(getParameterValue(portletNode, "w")),                                                            Integer.parseInt(getParameterValue(portletNode, "h")),                                                            Integer.parseInt(getParameterValue(portletNode, "column_position")),                                                            Integer.parseInt(getParameterValue(portletNode, "row_position")));                                break;                            }                        }                        portletNode = portletNode.getNextSibling();                    }                    break;                }            }            portletgroupNode = portletgroupNode.getNextSibling();        }    } catch (NumberFormatException n) {        throw new JahiaException(ERROR_READING_PLML_FILE_MSG,                                "Invalid Integer !!!",                                JahiaException.CRITICAL,                                JahiaException.CONFIG_ERROR);    }    if (!isPortletGroupNode) {        addPortletGroup();        getPortlet(thePortletID);    }    return thePortlet;    } // end getPortlet()    //--------------------------------------------------------------------------    /**     * Retrieves a list of portlet settings     *     * @author Jerome Bedat     *     */    public Vector getPortletList() throws JahiaException {    thePortletList = new Vector();    boolean isPortletGroupNode = false;    portletgroupNode = plmlNode.getFirstChild();    try {        while (portletgroupNode != null) {            if (portletgroupNode.getNodeType() == Node.ELEMENT_NODE && portletgroupNode.getNodeName().equalsIgnoreCase(PORTLETLIST_TAG)) {                if (Integer.parseInt(getParameterValue(portletgroupNode, "page_id")) == thePageID) {                    isPortletGroupNode = true;                    Node portletNode = portletgroupNode.getFirstChild();                    while (portletNode != null) {                        // we are going through the portletgroup tags which represent list of portlets                        if (portletNode.getNodeType() == Node.ELEMENT_NODE && portletNode.getNodeName().equalsIgnoreCase(PORTLET_TAG)) {                            // we are now on a PORTLET tag                            paramAttrNode = getAttributeValue(portletNode, PARAMETER_TAG_ID_ATTRIBUTE);                            thePortletList.addElement(new PortletObj(Integer.parseInt(paramAttrNode),                                                                    Integer.parseInt(getParameterValue(portletNode, "source_id")),                                                                    Integer.parseInt(getParameterValue(portletNode, "active")),

⌨️ 快捷键说明

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