Example usage for org.w3c.dom Node hasChildNodes

List of usage examples for org.w3c.dom Node hasChildNodes

Introduction

In this page you can find the example usage for org.w3c.dom Node hasChildNodes.

Prototype

public boolean hasChildNodes();

Source Link

Document

Returns whether this node has any children.

Usage

From source file:org.exist.xquery.modules.mail.SendEmailFunction.java

/**
 * Constructs a mail Object from an XML representation of an email
 *
 * The XML email Representation is expected to look something like this
 *
 * <mail>/*from  w  w w.java2s.c o m*/
 *    <from></from>
 *    <reply-to></reply-to>
 *    <to></to>
 *    <cc></cc>
 *    <bcc></bcc>
 *    <subject></subject>
 *    <message>
 *       <text></text>
 *       <xhtml></xhtml>
 *    </message>
 * </mail>
 *
 * @param mailElements   The XML mail Node
 * @return      A mail Object representing the XML mail Node
 */
private List<Mail> parseMailElement(List<Element> mailElements) throws TransformerException {
    List<Mail> mails = new ArrayList<>();

    for (Element mailElement : mailElements) {
        //Make sure that message has a Mail node
        if (mailElement.getLocalName().equals("mail")) {
            //New mail Object
            Mail mail = new Mail();

            //Get the First Child
            Node child = mailElement.getFirstChild();
            while (child != null) {
                //Parse each of the child nodes
                if (child.getNodeType() == Node.ELEMENT_NODE && child.hasChildNodes()) {
                    switch (child.getLocalName()) {
                    case "from":
                        mail.setFrom(child.getFirstChild().getNodeValue());
                        break;
                    case "reply-to":
                        mail.setReplyTo(child.getFirstChild().getNodeValue());
                        break;
                    case "to":
                        mail.addTo(child.getFirstChild().getNodeValue());
                        break;
                    case "cc":
                        mail.addCC(child.getFirstChild().getNodeValue());
                        break;
                    case "bcc":
                        mail.addBCC(child.getFirstChild().getNodeValue());
                        break;
                    case "subject":
                        mail.setSubject(child.getFirstChild().getNodeValue());
                        break;
                    case "message":
                        //If the message node, then parse the child text and xhtml nodes
                        Node bodyPart = child.getFirstChild();
                        while (bodyPart != null) {
                            if (bodyPart.getLocalName().equals("text")) {
                                mail.setText(bodyPart.getFirstChild().getNodeValue());
                            } else if (bodyPart.getLocalName().equals("xhtml")) {
                                //Convert everything inside <xhtml></xhtml> to text
                                TransformerFactory transFactory = TransformerFactory.newInstance();
                                Transformer transformer = transFactory.newTransformer();
                                DOMSource source = new DOMSource(bodyPart.getFirstChild());
                                StringWriter strWriter = new StringWriter();
                                StreamResult result = new StreamResult(strWriter);
                                transformer.transform(source, result);

                                mail.setXHTML(strWriter.toString());
                            }

                            //next body part
                            bodyPart = bodyPart.getNextSibling();
                        }
                        break;
                    case "attachment":
                        Element attachment = (Element) child;
                        MailAttachment ma = new MailAttachment(attachment.getAttribute("filename"),
                                attachment.getAttribute("mimetype"), attachment.getFirstChild().getNodeValue());
                        mail.addAttachment(ma);
                        break;
                    }
                }

                //next node
                child = child.getNextSibling();

            }
            mails.add(mail);
        }
    }

    return mails;
}

From source file:org.exist.xquery.modules.mail.SendEmailFunction.java

/**
 * Constructs a mail Object from an XML representation of an email
 *
 * The XML email Representation is expected to look something like this
 *
 * <mail>//  w  w w . j av a2  s  .  c om
 *    <from></from>
 *    <reply-to></reply-to>
 *    <to></to>
 *    <cc></cc>
 *    <bcc></bcc>
 *    <subject></subject>
 *    <message>
 *       <text charset="" encoding=""></text>
 *       <xhtml charset="" encoding=""></xhtml>
 *       <generic charset="" type="" encoding=""></generic>
 *    </message>
 *    <attachment mimetype="" filename=""></attachment>
 * </mail>
 *
 * @param mailElements   The XML mail Node
 * @return      A mail Object representing the XML mail Node
 */
private List<Message> parseMessageElement(Session session, List<Element> mailElements)
        throws IOException, MessagingException, TransformerException {
    List<Message> mails = new ArrayList<>();

    for (Element mailElement : mailElements) {
        //Make sure that message has a Mail node
        if (mailElement.getLocalName().equals("mail")) {
            //New message Object
            // create a message
            MimeMessage msg = new MimeMessage(session);

            ArrayList<InternetAddress> replyTo = new ArrayList<>();
            boolean fromWasSet = false;
            MimeBodyPart body = null;
            Multipart multibody = null;
            ArrayList<MimeBodyPart> attachments = new ArrayList<>();
            String firstContent = null;
            String firstContentType = null;
            String firstCharset = null;
            String firstEncoding = null;

            //Get the First Child
            Node child = mailElement.getFirstChild();
            while (child != null) {
                //Parse each of the child nodes
                if (child.getNodeType() == Node.ELEMENT_NODE && child.hasChildNodes()) {
                    switch (child.getLocalName()) {
                    case "from":
                        // set the from and to address
                        InternetAddress[] addressFrom = {
                                new InternetAddress(child.getFirstChild().getNodeValue()) };
                        msg.addFrom(addressFrom);
                        fromWasSet = true;
                        break;
                    case "reply-to":
                        // As we can only set the reply-to, not add them, let's keep
                        // all of them in a list
                        replyTo.add(new InternetAddress(child.getFirstChild().getNodeValue()));
                        msg.setReplyTo(replyTo.toArray(new InternetAddress[0]));
                        break;
                    case "to":
                        msg.addRecipient(Message.RecipientType.TO,
                                new InternetAddress(child.getFirstChild().getNodeValue()));
                        break;
                    case "cc":
                        msg.addRecipient(Message.RecipientType.CC,
                                new InternetAddress(child.getFirstChild().getNodeValue()));
                        break;
                    case "bcc":
                        msg.addRecipient(Message.RecipientType.BCC,
                                new InternetAddress(child.getFirstChild().getNodeValue()));
                        break;
                    case "subject":
                        msg.setSubject(child.getFirstChild().getNodeValue());
                        break;
                    case "header":
                        // Optional : You can also set your custom headers in the Email if you Want
                        msg.addHeader(((Element) child).getAttribute("name"),
                                child.getFirstChild().getNodeValue());
                        break;
                    case "message":
                        //If the message node, then parse the child text and xhtml nodes
                        Node bodyPart = child.getFirstChild();
                        while (bodyPart != null) {
                            if (bodyPart.getNodeType() != Node.ELEMENT_NODE)
                                continue;

                            Element elementBodyPart = (Element) bodyPart;
                            String content = null;
                            String contentType = null;

                            if (bodyPart.getLocalName().equals("text")) {
                                // Setting the Subject and Content Type
                                content = bodyPart.getFirstChild().getNodeValue();
                                contentType = "plain";
                            } else if (bodyPart.getLocalName().equals("xhtml")) {
                                //Convert everything inside <xhtml></xhtml> to text
                                TransformerFactory transFactory = TransformerFactory.newInstance();
                                Transformer transformer = transFactory.newTransformer();
                                DOMSource source = new DOMSource(bodyPart.getFirstChild());
                                StringWriter strWriter = new StringWriter();
                                StreamResult result = new StreamResult(strWriter);
                                transformer.transform(source, result);

                                content = strWriter.toString();
                                contentType = "html";
                            } else if (bodyPart.getLocalName().equals("generic")) {
                                // Setting the Subject and Content Type
                                content = elementBodyPart.getFirstChild().getNodeValue();
                                contentType = elementBodyPart.getAttribute("type");
                            }

                            // Now, time to store it
                            if (content != null && contentType != null && contentType.length() > 0) {
                                String charset = elementBodyPart.getAttribute("charset");
                                String encoding = elementBodyPart.getAttribute("encoding");

                                if (body != null && multibody == null) {
                                    multibody = new MimeMultipart("alternative");
                                    multibody.addBodyPart(body);
                                }

                                if (StringUtils.isEmpty(charset)) {
                                    charset = "UTF-8";
                                }

                                if (StringUtils.isEmpty(encoding)) {
                                    encoding = "quoted-printable";
                                }

                                if (body == null) {
                                    firstContent = content;
                                    firstCharset = charset;
                                    firstContentType = contentType;
                                    firstEncoding = encoding;
                                }
                                body = new MimeBodyPart();
                                body.setText(content, charset, contentType);
                                if (encoding != null) {
                                    body.setHeader("Content-Transfer-Encoding", encoding);
                                }
                                if (multibody != null)
                                    multibody.addBodyPart(body);
                            }

                            //next body part
                            bodyPart = bodyPart.getNextSibling();
                        }
                        break;
                    case "attachment":
                        Element attachment = (Element) child;
                        MimeBodyPart part;
                        // if mimetype indicates a binary resource, assume the content is base64 encoded
                        if (MimeTable.getInstance().isTextContent(attachment.getAttribute("mimetype"))) {
                            part = new MimeBodyPart();
                        } else {
                            part = new PreencodedMimeBodyPart("base64");
                        }
                        StringBuilder content = new StringBuilder();
                        Node attachChild = attachment.getFirstChild();
                        while (attachChild != null) {
                            if (attachChild.getNodeType() == Node.ELEMENT_NODE) {
                                TransformerFactory transFactory = TransformerFactory.newInstance();
                                Transformer transformer = transFactory.newTransformer();
                                DOMSource source = new DOMSource(attachChild);
                                StringWriter strWriter = new StringWriter();
                                StreamResult result = new StreamResult(strWriter);
                                transformer.transform(source, result);

                                content.append(strWriter.toString());
                            } else {
                                content.append(attachChild.getNodeValue());
                            }
                            attachChild = attachChild.getNextSibling();
                        }
                        part.setDataHandler(new DataHandler(new ByteArrayDataSource(content.toString(),
                                attachment.getAttribute("mimetype"))));
                        part.setFileName(attachment.getAttribute("filename"));
                        //                            part.setHeader("Content-Transfer-Encoding", "base64");
                        attachments.add(part);
                        break;
                    }
                }

                //next node
                child = child.getNextSibling();

            }
            // Lost from
            if (!fromWasSet)
                msg.setFrom();

            // Preparing content and attachments
            if (attachments.size() > 0) {
                if (multibody == null) {
                    multibody = new MimeMultipart("mixed");
                    if (body != null) {
                        multibody.addBodyPart(body);
                    }
                } else {
                    MimeMultipart container = new MimeMultipart("mixed");
                    MimeBodyPart containerBody = new MimeBodyPart();
                    containerBody.setContent(multibody);
                    container.addBodyPart(containerBody);
                    multibody = container;
                }
                for (MimeBodyPart part : attachments) {
                    multibody.addBodyPart(part);
                }
            }

            // And now setting-up content
            if (multibody != null) {
                msg.setContent(multibody);
            } else if (body != null) {
                msg.setText(firstContent, firstCharset, firstContentType);
                if (firstEncoding != null) {
                    msg.setHeader("Content-Transfer-Encoding", firstEncoding);
                }
            }

            msg.saveChanges();
            mails.add(msg);
        }
    }

    return mails;
}

From source file:org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore.java

@Override
protected int saveStructure(Node node, PreparedStatement structStmt, PreparedStatement parmStmt)
        throws SQLException {
    if (node == null) { // No more
        return 0;
    }//  w  w w  . java2s  .  c o m
    if (node.getNodeName().equals("parameter")) {
        //parameter, skip it and go on to the next node
        return this.saveStructure(node.getNextSibling(), structStmt, parmStmt);
    }
    if (!(node instanceof Element)) {
        return 0;
    }

    final Element structure = (Element) node;

    if (LOG.isDebugEnabled()) {
        LOG.debug("saveStructure XML content: " + XmlUtilitiesImpl.toString(node));
    }

    // determine the struct_id for storing in the db. For incorporated nodes in
    // the plf their ID is a system-wide unique ID while their struct_id for
    // storing in the db is cached in a dlm:plfID attribute.
    int saveStructId = -1;
    final String plfID = structure.getAttribute(Constants.ATT_PLF_ID);

    if (!plfID.equals("")) {
        saveStructId = Integer.parseInt(plfID.substring(1));
    } else {
        final String id = structure.getAttribute("ID");
        saveStructId = Integer.parseInt(id.substring(1));
    }

    int nextStructId = 0;
    int childStructId = 0;
    int chanId = -1;
    IPortletDefinition portletDef = null;
    final boolean isChannel = node.getNodeName().equals("channel");

    if (isChannel) {
        chanId = Integer.parseInt(node.getAttributes().getNamedItem("chanID").getNodeValue());
        portletDef = this.portletDefinitionRegistry.getPortletDefinition(String.valueOf(chanId));
        if (portletDef == null) {
            //Portlet doesn't exist any more, drop the layout node
            return 0;
        }
    }

    if (node.hasChildNodes()) {
        childStructId = this.saveStructure(node.getFirstChild(), structStmt, parmStmt);
    }
    nextStructId = this.saveStructure(node.getNextSibling(), structStmt, parmStmt);
    structStmt.clearParameters();
    structStmt.setInt(1, saveStructId);
    structStmt.setInt(2, nextStructId);
    structStmt.setInt(3, childStructId);

    final String externalId = structure.getAttribute("external_id");
    if (externalId != null && externalId.trim().length() > 0) {
        final Integer eID = new Integer(externalId);
        structStmt.setInt(4, eID.intValue());
    } else {
        structStmt.setNull(4, java.sql.Types.NUMERIC);

    }
    if (isChannel) {
        structStmt.setInt(5, chanId);
        structStmt.setNull(6, java.sql.Types.VARCHAR);
    } else {
        structStmt.setNull(5, java.sql.Types.NUMERIC);
        structStmt.setString(6, structure.getAttribute("name"));
    }
    final String structType = structure.getAttribute("type");
    structStmt.setString(7, structType);
    structStmt.setString(8, RDBMServices.dbFlag(xmlBool(structure.getAttribute("hidden"))));
    structStmt.setString(9, RDBMServices.dbFlag(xmlBool(structure.getAttribute("immutable"))));
    structStmt.setString(10, RDBMServices.dbFlag(xmlBool(structure.getAttribute("unremovable"))));
    if (LOG.isDebugEnabled()) {
        LOG.debug(structStmt.toString());
    }
    structStmt.executeUpdate();

    // code to persist extension attributes for dlm
    final NamedNodeMap attribs = node.getAttributes();
    for (int i = 0; i < attribs.getLength(); i++) {
        final Node attrib = attribs.item(i);
        final String name = attrib.getNodeName();

        if (name.startsWith(Constants.NS) && !name.equals(Constants.ATT_PLF_ID)
                && !name.equals(Constants.ATT_FRAGMENT) && !name.equals(Constants.ATT_PRECEDENCE)) {
            // a cp extension attribute. Push into param table.
            parmStmt.clearParameters();
            parmStmt.setInt(1, saveStructId);
            parmStmt.setString(2, name);
            parmStmt.setString(3, attrib.getNodeValue());
            if (LOG.isDebugEnabled()) {
                LOG.debug(parmStmt.toString());
            }
            parmStmt.executeUpdate();
        }
    }
    final NodeList parameters = node.getChildNodes();
    if (parameters != null && isChannel) {
        for (int i = 0; i < parameters.getLength(); i++) {
            if (parameters.item(i).getNodeName().equals("parameter")) {
                final Element parmElement = (Element) parameters.item(i);
                final NamedNodeMap nm = parmElement.getAttributes();
                final String parmName = nm.getNamedItem("name").getNodeValue();
                final String parmValue = nm.getNamedItem("value").getNodeValue();
                final Node override = nm.getNamedItem("override");

                // if no override specified then default to allowed
                if (override != null && !override.getNodeValue().equals("yes")) {
                    // can't override
                } else {
                    // override only for adhoc or if diff from chan def
                    final IPortletDefinitionParameter cp = portletDef.getParameter(parmName);
                    if (cp == null || !cp.getValue().equals(parmValue)) {
                        parmStmt.clearParameters();
                        parmStmt.setInt(1, saveStructId);
                        parmStmt.setString(2, parmName);
                        parmStmt.setString(3, parmValue);
                        if (LOG.isDebugEnabled()) {
                            LOG.debug(parmStmt);
                        }
                        parmStmt.executeUpdate();
                    }
                }
            }
        }
    }
    return saveStructId;
}

From source file:org.jasig.portal.layout.simple.RDBMUserLayoutStore.java

/**
 * Dump a document tree structure on stdout
 * @param node/* w w  w.ja  v  a 2s . c  o m*/
 * @param indent
 */
public static final void dumpDoc(Node node, String indent) {
    if (node == null) {
        return;
    }
    if (node instanceof Element) {
        System.err.print(indent + "element: tag=" + ((Element) node).getTagName() + " ");
    } else if (node instanceof Document) {
        System.err.print("document:");
    } else {
        System.err.print(indent + "node:");
    }
    System.err.println("name=" + node.getNodeName() + " value=" + node.getNodeValue());
    NamedNodeMap nm = node.getAttributes();
    if (nm != null) {
        for (int i = 0; i < nm.getLength(); i++) {
            System.err
                    .println(indent + " " + nm.item(i).getNodeName() + ": '" + nm.item(i).getNodeValue() + "'");
        }
        System.err.println(indent + "--");
    }
    if (node.hasChildNodes()) {
        dumpDoc(node.getFirstChild(), indent + "   ");
    }
    dumpDoc(node.getNextSibling(), indent);
}

From source file:org.jboss.dashboard.displayer.AbstractDataDisplayerXMLFormat.java

public DataDisplayer parse(NodeList xmlNodes, ImportResults results) throws Exception {
    for (int i = 0; i < xmlNodes.getLength(); i++) {
        Node item = xmlNodes.item(i);
        if (item.getNodeName().equals("displayer") && item.hasAttributes() && item.hasChildNodes()) {
            String typeUid = item.getAttributes().getNamedItem("type").getNodeValue();
            DataDisplayerType type = DataDisplayerServices.lookup().getDataDisplayerManager()
                    .getDisplayerTypeByUid(typeUid);
            DataDisplayerRenderer renderer = null;

            Node rendererNode = item.getAttributes().getNamedItem("renderer");
            if (rendererNode != null) {
                String rendUid = rendererNode.getNodeValue();
                renderer = DataDisplayerServices.lookup().getDataDisplayerManager()
                        .getDisplayerRendererByUid(rendUid);
            }//from   w w w.j a v  a2s.  c o m

            DataDisplayer displayer = type.createDataDisplayer();
            displayer.setDataDisplayerRenderer(renderer);
            parseDisplayer(displayer, item.getChildNodes(), results);
            return displayer;
        }
    }
    throw new IllegalArgumentException("Missing <displayer> tag.");
}

From source file:org.jboss.dashboard.displayer.AbstractDataDisplayerXMLFormat.java

protected DomainConfiguration parseDomain(NodeList domainNodes) {
    DomainConfiguration domainConfig = new DomainConfiguration();
    for (int k = 0; k < domainNodes.getLength(); k++) {
        Node item = domainNodes.item(k);
        if (item.getNodeName().equals("propertyid") && item.hasChildNodes()) {
            domainConfig.setPropertyId(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }/* www  . jav a  2 s  .co  m*/
        if (item.getNodeName().equals("name") && item.hasChildNodes()) {
            String name = item.getFirstChild().getNodeValue();
            Locale locale = LocaleManager.currentLocale();
            Node languageNode = item.getAttributes().getNamedItem("language");
            if (languageNode != null)
                locale = new Locale(languageNode.getNodeValue());
            domainConfig.setPropertyName(StringEscapeUtils.unescapeXml(name), locale);
        }
        if (item.getNodeName().equals("maxnumberofintervals") && item.hasChildNodes()) {
            domainConfig.setMaxNumberOfIntervals(
                    StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        // Label domain.
        if (item.getNodeName().equals("intervalstohide") && item.hasChildNodes()) {
            String interval = item.getFirstChild().getNodeValue();
            Locale locale = LocaleManager.currentLocale();
            Node languageNode = item.getAttributes().getNamedItem("language");
            if (languageNode != null)
                locale = new Locale(languageNode.getNodeValue());
            domainConfig.setLabelIntervalsToHide(StringEscapeUtils.unescapeXml(interval), locale);
        }
        // Date domain.
        if (item.getNodeName().equals("taminterval") && item.hasChildNodes()) {
            domainConfig.setDateTamInterval(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("mindate") && item.hasChildNodes()) {
            domainConfig.setDateMinDate(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("maxdate") && item.hasChildNodes()) {
            domainConfig.setDateMaxDate(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        // Numeric domain.
        if (item.getNodeName().equals("taminterval") && item.hasChildNodes()) {
            domainConfig
                    .setNumericTamInterval(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("minvalue") && item.hasChildNodes()) {
            domainConfig.setNumericMinValue(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("maxvalue") && item.hasChildNodes()) {
            domainConfig.setNumericMaxValue(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
    }
    return domainConfig;
}

From source file:org.jboss.dashboard.displayer.AbstractDataDisplayerXMLFormat.java

protected RangeConfiguration parseRange(NodeList rangeNodes) {
    RangeConfiguration rangeConfig = new RangeConfiguration();
    for (int k = 0; k < rangeNodes.getLength(); k++) {
        Node item = rangeNodes.item(k);
        if (item.getNodeName().equals("propertyid") && item.hasChildNodes()) {
            rangeConfig.setPropertyId(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }/*from w w  w.  j a  v a 2 s  .  c  o m*/
        if (item.getNodeName().equals("name") && item.hasChildNodes()) {
            String name = item.getFirstChild().getNodeValue();
            Locale locale = LocaleManager.currentLocale();
            Node languageNode = item.getAttributes().getNamedItem("language");
            if (languageNode != null)
                locale = new Locale(languageNode.getNodeValue());
            rangeConfig.setName(StringEscapeUtils.unescapeXml(name), locale);
        }
        if (item.getNodeName().equals("scalarfunction") && item.hasChildNodes()) {
            rangeConfig
                    .setScalarFunctionCode(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
        }
        if (item.getNodeName().equals("unit") && item.hasChildNodes()) {
            String unit = item.getFirstChild().getNodeValue();
            Locale locale = LocaleManager.currentLocale();
            Node languageNode = item.getAttributes().getNamedItem("language");
            if (languageNode != null)
                locale = new Locale(languageNode.getNodeValue());
            rangeConfig.setUnit(StringEscapeUtils.unescapeXml(unit), locale);
        }
    }
    return rangeConfig;
}

From source file:org.jboss.dashboard.displayer.chart.ChartDisplayerXMLFormat.java

protected void parseDisplayer(AbstractChartDisplayer displayer, Node item, ImportResults results)
        throws Exception {
    // Domain./*from   ww w.j  av a  2 s . c  o  m*/
    if (item.getNodeName().equals("domain") && item.hasChildNodes()) {
        NodeList domainNodes = item.getChildNodes();
        displayer.setDomainConfiguration(parseDomain(domainNodes));
    }
    // Range.
    else if (item.getNodeName().equals("range") && item.hasChildNodes()) {
        NodeList rangeNodes = item.getChildNodes();
        displayer.setRangeConfiguration(parseRange(rangeNodes));
    } else if (item.getNodeName().equals("type") && item.hasChildNodes()) {
        displayer.setType(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
    } else if (item.getNodeName().equals("showlabelsxaxis") && item.hasChildNodes()) {
        displayer.setShowLabelsXAxis(
                Boolean.parseBoolean(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("labelanglexaxis") && item.hasChildNodes()
            && displayer instanceof AbstractXAxisDisplayer) {
        AbstractXAxisDisplayer xAxisDisplayer = (AbstractXAxisDisplayer) displayer;
        xAxisDisplayer.setLabelAngleXAxis(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("showlinesarea") && item.hasChildNodes()
            && displayer instanceof AbstractXAxisDisplayer) {
        AbstractXAxisDisplayer xAxisDisplayer = (AbstractXAxisDisplayer) displayer;
        xAxisDisplayer.setShowLinesArea(
                Boolean.parseBoolean(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("intervalsortcriteria") && item.hasChildNodes()) {
        displayer.setIntervalsSortCriteria(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("intervalsortorder") && item.hasChildNodes()) {
        displayer.setIntervalsSortOrder(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("color") && item.hasChildNodes()) {
        displayer.setColor(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
    } else if (item.getNodeName().equals("backgroundcolor") && item.hasChildNodes()) {
        displayer.setBackgroundColor(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
    } else if (item.getNodeName().equals("width") && item.hasChildNodes()) {
        displayer
                .setWidth(Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("height") && item.hasChildNodes()) {
        displayer.setHeight(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("showlegend") && item.hasChildNodes()) {
        displayer.setShowLegend(Boolean
                .valueOf(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())).booleanValue());
    } else if (item.getNodeName().equals("axisinteger") && item.hasChildNodes()) {
        displayer.setAxisInteger(Boolean
                .valueOf(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())).booleanValue());
    } else if (item.getNodeName().equals("legendanchor") && item.hasChildNodes()) {
        displayer.setLegendAnchor(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
    } else if (item.getNodeName().equals("showtitle") && item.hasChildNodes()) {
        displayer.setShowTitle(Boolean
                .valueOf(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())).booleanValue());
    } else if (item.getNodeName().equals("align") && item.hasChildNodes()) {
        displayer.setGraphicAlign(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue()));
    } else if (item.getNodeName().equals("marginleft") && item.hasChildNodes()) {
        displayer.setMarginLeft(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("marginright") && item.hasChildNodes()) {
        displayer.setMarginRight(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("margintop") && item.hasChildNodes()) {
        displayer.setMarginTop(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    } else if (item.getNodeName().equals("marginbottom") && item.hasChildNodes()) {
        displayer.setMarginBottom(
                Integer.parseInt(StringEscapeUtils.unescapeXml(item.getFirstChild().getNodeValue())));
    }
}

From source file:org.jboss.dashboard.displayer.chart.MeterChartDisplayerXMLFormat.java

protected void parseDisplayer(AbstractChartDisplayer displayer, Node item, ImportResults results)
        throws Exception {
    if (item.hasChildNodes() && (item.getNodeName().equals("meter") || item.getNodeName().equals("thermometer")
            || item.getNodeName().equals("dial"))) {
        try {//from ww  w  .j a  v a2 s.c  o m
            parseMeterProperties(displayer, item, results);
        } catch (Exception e) {
            log.error("Can't parse meter displayer properties" + e);
        }
    } else {
        super.parseDisplayer(displayer, item, results);
    }
}

From source file:org.jboss.dashboard.displayer.chart.MeterChartDisplayerXMLFormat.java

protected void parseMeterProperties(DataDisplayer displayer, Node item, ImportResults results)
        throws Exception {
    Locale locale = LocaleManager.currentLocale();
    NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
    MeterChartDisplayer meterDisplayer = (MeterChartDisplayer) displayer;
    if (item.getNodeName().equals("meter") && item.hasChildNodes()) {
        NodeList meterNodes = item.getChildNodes();
        for (int k = 0; k < meterNodes.getLength(); k++) {
            Node meterItem = meterNodes.item(k);
            if (meterItem.getNodeName().equals("positionType") && meterItem.hasChildNodes()) {
                meterDisplayer.setPositionType(
                        StringEscapeUtils.unescapeXml(meterItem.getFirstChild().getNodeValue()));
            }//from   w  w w  .j a  va 2  s.  c  om
            if (meterItem.getNodeName().equals("minValue") && meterItem.hasChildNodes()) {
                meterDisplayer.setMinValue(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(meterItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (meterItem.getNodeName().equals("maxValue") && meterItem.hasChildNodes()) {
                meterDisplayer.setMaxValue(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(meterItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (meterItem.getNodeName().equals("maxMeterTicks") && meterItem.hasChildNodes()) {
                meterDisplayer.setMaxMeterTicks(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(meterItem.getFirstChild().getNodeValue()))
                        .intValue());
            }
            // Thresholds.
            if (meterItem.getNodeName().equals("warningThreshold") && meterItem.hasChildNodes()) {
                meterDisplayer.setWarningThreshold(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(meterItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (meterItem.getNodeName().equals("criticalThreshold") && meterItem.hasChildNodes()) {
                meterDisplayer.setCriticalThreshold(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(meterItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            // Critical interval.
            if (meterItem.getNodeName().equals("descripCriticalInterval") && meterItem.hasChildNodes()) {
                String descripCriticalInterval = meterItem.getFirstChild().getNodeValue();
                Node languageNode = meterItem.getAttributes().getNamedItem("language");
                if (languageNode != null)
                    locale = new Locale(languageNode.getNodeValue());
                meterDisplayer.setDescripCriticalInterval(
                        StringEscapeUtils.unescapeXml(descripCriticalInterval), locale);
            }
            // Warning interval.
            if (meterItem.getNodeName().equals("descripWarningInterval") && meterItem.hasChildNodes()) {
                String descripWarningInterval = meterItem.getFirstChild().getNodeValue();
                Node languageNode = meterItem.getAttributes().getNamedItem("language");
                if (languageNode != null)
                    locale = new Locale(languageNode.getNodeValue());
                meterDisplayer.setDescripWarningInterval(StringEscapeUtils.unescapeXml(descripWarningInterval),
                        locale);
            }
            // Normal interval.
            if (meterItem.getNodeName().equals("descripNormalInterval") && meterItem.hasChildNodes()) {
                String descripNormalInterval = meterItem.getFirstChild().getNodeValue();
                Node languageNode = meterItem.getAttributes().getNamedItem("language");
                if (languageNode != null)
                    locale = new Locale(languageNode.getNodeValue());
                meterDisplayer.setDescripNormalInterval(StringEscapeUtils.unescapeXml(descripNormalInterval),
                        locale);
            }
        }
    } else if (item.getNodeName().equals("thermometer") && item.hasChildNodes()) {
        NodeList thermoNodes = item.getChildNodes();
        for (int k = 0; k < thermoNodes.getLength(); k++) {
            Node thermoItem = thermoNodes.item(k);
            if (thermoItem.getNodeName().equals("positionType") && thermoItem.hasChildNodes()) {
                meterDisplayer.setPositionType(
                        StringEscapeUtils.unescapeXml(thermoItem.getFirstChild().getNodeValue()));
            }
            if (thermoItem.getNodeName().equals("thermoLowerBound") && thermoItem.hasChildNodes()) {
                meterDisplayer.setThermoLowerBound(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(thermoItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (thermoItem.getNodeName().equals("thermoUpperBound") && thermoItem.hasChildNodes()) {
                meterDisplayer.setThermoUpperBound(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(thermoItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            // Thresholds.
            if (thermoItem.getNodeName().equals("warningThermoThreshold") && thermoItem.hasChildNodes()) {
                meterDisplayer.setWarningThermoThreshold(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(thermoItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (thermoItem.getNodeName().equals("criticalThermoThreshold") && thermoItem.hasChildNodes()) {
                meterDisplayer.setCriticalThermoThreshold(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(thermoItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
        }
    } else if (item.getNodeName().equals("dial")) {
        NodeList dialNodes = item.getChildNodes();
        for (int k = 0; k < dialNodes.getLength(); k++) {
            Node dialItem = dialNodes.item(k);
            if (dialItem.getNodeName().equals("positionType") && dialItem.hasChildNodes()) {
                meterDisplayer.setPositionType(
                        StringEscapeUtils.unescapeXml(dialItem.getFirstChild().getNodeValue()));
            }
            if (dialItem.getNodeName().equals("pointerType") && dialItem.hasChildNodes()) {
                meterDisplayer
                        .setPointerType(StringEscapeUtils.unescapeXml(dialItem.getFirstChild().getNodeValue()));
            }
            if (dialItem.getNodeName().equals("dialLowerBound") && dialItem.hasChildNodes()) {
                meterDisplayer.setDialLowerBound(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(dialItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (dialItem.getNodeName().equals("dialUpperBound") && dialItem.hasChildNodes()) {
                meterDisplayer.setDialUpperBound(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(dialItem.getFirstChild().getNodeValue()))
                        .doubleValue());
            }
            if (dialItem.getNodeName().equals("maxTicks") && dialItem.hasChildNodes()) {
                meterDisplayer.setMaxTicks(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(dialItem.getFirstChild().getNodeValue()))
                        .intValue());
            }
            if (dialItem.getNodeName().equals("minorTickCount") && dialItem.hasChildNodes()) {
                meterDisplayer.setMinorTickCount(numberFormat
                        .parse(StringEscapeUtils.unescapeXml(dialItem.getFirstChild().getNodeValue()))
                        .intValue());
            }
        }
    }
}