Example usage for org.w3c.dom Element getTagName

List of usage examples for org.w3c.dom Element getTagName

Introduction

In this page you can find the example usage for org.w3c.dom Element getTagName.

Prototype

public String getTagName();

Source Link

Document

The name of the element.

Usage

From source file:com.icesoft.faces.context.DOMResponseWriter.java

public Element getHtmlElement() {
    Element html = document.getDocumentElement();
    if (html == null) {
        html = document.createElement("html");
        document.appendChild(html);/*from  ww w  . ja  v  a2 s  . c o  m*/
    }
    if (html.getTagName().equals("html"))
        return html;
    return fixHtml();
}

From source file:edu.lternet.pasta.common.eml.EMLParser.java

private void parseResponsibleParty(Node node, ResponsibleParty rp) {
    if (node instanceof Element) {
        Element element = (Element) node;
        String elementTagName = element.getTagName();

        if (elementTagName.equals("contact") || elementTagName.equals("creator")
                || elementTagName.equals("metadataProvider")) {
            NodeList nodeList = element.getChildNodes();

            for (int i = 0; i < nodeList.getLength(); i++) {
                Node rpNode = nodeList.item(i);

                if (rpNode instanceof Element) {
                    Element rpElement = (Element) rpNode;
                    String rpElementTagName = rpElement.getTagName();
                    String rpElementAttribute = rpElement.getAttribute("phonetype");

                    if (rpElementTagName.equals("individualName")) {
                        NodeList individualNameNodeList = rpElement.getChildNodes();

                        for (int j = 0; j < individualNameNodeList.getLength(); j++) {
                            Node individualNameNode = individualNameNodeList.item(j);

                            if (individualNameNode instanceof Element) {
                                Element individualNameElement = (Element) individualNameNode;
                                String individualNameElementTagName = individualNameElement.getTagName();

                                if (individualNameElementTagName.equals("salutation")) {
                                    NodeList salutationNodeList = individualNameElement.getChildNodes();

                                    for (int k = 0; k < salutationNodeList.getLength(); k++) {
                                        Node salutationNode = salutationNodeList.item(k);

                                        if (salutationNode instanceof Text) {
                                            Text salutationText = (Text) salutationNode;
                                            String salutationNodeValue = salutationText.getNodeValue();
                                            logger.debug("salutationNodeValue: " + salutationNodeValue);
                                            rp.setSalutation(salutationNodeValue);
                                        }
                                    }//from   w ww  .j av  a2  s.c  o m
                                } else if (individualNameElementTagName.equals("givenName")) {
                                    NodeList givenNameNodeList = individualNameElement.getChildNodes();

                                    for (int l = 0; l < givenNameNodeList.getLength(); l++) {
                                        Node givenNameNode = givenNameNodeList.item(l);

                                        if (givenNameNode instanceof Text) {
                                            Text givenNameText = (Text) givenNameNode;
                                            String givenNameNodeValue = givenNameText.getNodeValue();
                                            logger.debug("givenNameNodeValue: " + givenNameNodeValue);
                                            rp.addGivenName(givenNameNodeValue);
                                        }
                                    }
                                } else if (individualNameElementTagName.equals("surName")) {
                                    NodeList surNameNodeList = individualNameElement.getChildNodes();

                                    for (int m = 0; m < surNameNodeList.getLength(); m++) {
                                        Node surNameNode = surNameNodeList.item(m);

                                        if (surNameNode instanceof Text) {
                                            Text surNameText = (Text) surNameNode;
                                            String surNameNodeValue = surNameText.getNodeValue();
                                            logger.debug("surNameNodeValue: " + surNameNodeValue);
                                            rp.setSurName(surNameNodeValue);
                                        }
                                    }
                                }
                            }
                        }
                    } else if (rpElementTagName.equals("organizationName")) {
                        NodeList organizationNameNodeList = rpElement.getChildNodes();

                        for (int n = 0; n < organizationNameNodeList.getLength(); n++) {
                            Node organizationNameNode = organizationNameNodeList.item(n);

                            if (organizationNameNode instanceof Text) {
                                Text organizationNameText = (Text) organizationNameNode;
                                String organizationNameNodeValue = organizationNameText.getNodeValue();
                                logger.debug("organizationNameNodeValue: " + organizationNameNodeValue);
                                rp.setOrganizationName(organizationNameNodeValue);
                            }
                        }
                    } else if (rpElementTagName.equals("positionName")) {
                        NodeList positionNameNodeList = rpElement.getChildNodes();

                        for (int n = 0; n < positionNameNodeList.getLength(); n++) {
                            Node positionNameNode = positionNameNodeList.item(n);

                            if (positionNameNode instanceof Text) {
                                Text positionNameText = (Text) positionNameNode;
                                String positionNameNodeValue = positionNameText.getNodeValue();
                                logger.debug("positionNameNodeValue: " + positionNameNodeValue);
                                rp.setPositionName(positionNameNodeValue);
                            }
                        }
                    } else if (rpElementTagName.equals("address")) {
                        NodeList addressNodeList = rpElement.getChildNodes();

                        for (int o = 0; o < addressNodeList.getLength(); o++) {
                            Node addressNode = addressNodeList.item(o);

                            if (addressNode instanceof Element) {
                                Element addressElement = (Element) addressNode;
                                String addressElementTagName = addressElement.getTagName();

                                if (addressElementTagName.equals("deliveryPoint")) {
                                    NodeList deliveryPointNodeList = addressElement.getChildNodes();

                                    for (int p = 0; p < deliveryPointNodeList.getLength(); p++) {
                                        Node deliveryPointNode = deliveryPointNodeList.item(p);

                                        if (deliveryPointNode instanceof Text) {
                                            Text deliveryPointText = (Text) deliveryPointNode;
                                            String deliveryPointNodeValue = deliveryPointText.getNodeValue();
                                            logger.debug("deliveryPointNodeValue: " + deliveryPointNodeValue);
                                            rp.addDeliveryPoint(deliveryPointNodeValue);
                                        }
                                    }
                                } else if (addressElementTagName.equals("city")) {
                                    NodeList cityNodeList = addressElement.getChildNodes();

                                    for (int q = 0; q < cityNodeList.getLength(); q++) {
                                        Node cityNode = cityNodeList.item(q);

                                        if (cityNode instanceof Text) {
                                            Text cityText = (Text) cityNode;
                                            String cityNodeValue = cityText.getNodeValue();
                                            logger.debug("cityNodeValue: " + cityNodeValue);
                                            rp.setCity(cityNodeValue);
                                        }
                                    }
                                } else if (addressElementTagName.equals("administrativeArea")) {
                                    NodeList administrativeAreaNodeList = addressElement.getChildNodes();

                                    for (int r = 0; r < administrativeAreaNodeList.getLength(); r++) {
                                        Node administrativeAreaNode = administrativeAreaNodeList.item(r);

                                        if (administrativeAreaNode instanceof Text) {
                                            Text administrativeAreaText = (Text) administrativeAreaNode;
                                            String administrativeAreaNodeValue = administrativeAreaText
                                                    .getNodeValue();
                                            logger.debug("administrativeAreaNodeValue: "
                                                    + administrativeAreaNodeValue);
                                            rp.setAdministrativeArea(administrativeAreaNodeValue);
                                        }
                                    }
                                } else if (addressElementTagName.equals("postalCode")) {
                                    NodeList postalCodeNodeList = addressElement.getChildNodes();

                                    for (int r = 0; r < postalCodeNodeList.getLength(); r++) {
                                        Node postalCodeNode = postalCodeNodeList.item(r);

                                        if (postalCodeNode instanceof Text) {
                                            Text postalCodeText = (Text) postalCodeNode;
                                            String postalCodeNodeValue = postalCodeText.getNodeValue();
                                            logger.debug("postalCodeNodeValue: " + postalCodeNodeValue);
                                            rp.setPostalCode(postalCodeNodeValue);
                                        }
                                    }
                                } else if (addressElementTagName.equals("country")) {
                                    NodeList countryNodeList = addressElement.getChildNodes();

                                    for (int s = 0; s < countryNodeList.getLength(); s++) {
                                        Node countryNode = countryNodeList.item(s);

                                        if (countryNode instanceof Text) {
                                            Text countryText = (Text) countryNode;
                                            String countryNodeValue = countryText.getNodeValue();
                                            logger.debug("countryNodeValue: " + countryNodeValue);
                                            rp.setCountry(countryNodeValue);
                                        }
                                    }
                                }
                            }
                        }
                    } else if (rpElementTagName.equals("phone")
                            && !(rpElementAttribute.equals("facsimile") || rpElementAttribute.equals("fax"))) {

                        NodeList phoneNodeList = rpElement.getChildNodes();

                        for (int t = 0; t < phoneNodeList.getLength(); t++) {
                            Node phoneNode = phoneNodeList.item(t);

                            if (phoneNode instanceof Text) {
                                Text phoneText = (Text) phoneNode;
                                String phoneNodeValue = phoneText.getNodeValue();
                                logger.debug("phoneNodeValue: " + phoneNodeValue);
                                rp.setPhone(phoneNodeValue);
                            }
                        }
                    } else if (rpElementTagName.equals("electronicMailAddress")) {
                        NodeList electronicMailAddressNodeList = rpElement.getChildNodes();

                        for (int u = 0; u < electronicMailAddressNodeList.getLength(); u++) {
                            Node electronicMailAddressNode = electronicMailAddressNodeList.item(u);

                            if (electronicMailAddressNode instanceof Text) {
                                Text electronicMailAddressText = (Text) electronicMailAddressNode;
                                String electronicMailAddressNodeValue = electronicMailAddressText
                                        .getNodeValue();
                                logger.debug(
                                        "electronicMailAddressNodeValue: " + electronicMailAddressNodeValue);
                                rp.setElectronicMailAddress(electronicMailAddressNodeValue);
                            }
                        }
                    } else if (rpElementTagName.equals("onlineUrl")) {
                        NodeList onlineUrlNodeList = rpElement.getChildNodes();

                        for (int u = 0; u < onlineUrlNodeList.getLength(); u++) {
                            Node onlineUrlNode = onlineUrlNodeList.item(u);

                            if (onlineUrlNode instanceof Text) {
                                Text onlineUrlText = (Text) onlineUrlNode;
                                String onlineUrlNodeValue = onlineUrlText.getNodeValue();
                                logger.debug("onlineUrlNodeValue: " + onlineUrlNodeValue);
                                rp.setOnlineUrl(onlineUrlNodeValue);
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:com.concursive.connect.web.modules.api.beans.TransactionItem.java

public void setObject(Element element, HashMap mapping) throws Exception {
    name = element.getTagName();
    if (mapping.containsKey(name)) {
        SyncTable thisMapping = (SyncTable) mapping.get(name);
        // Instantiate the object
        object = Class.forName(thisMapping.getMappedClassName()).newInstance();
        LOG.debug("Instantiated object: " + object.getClass().getName());
    } else {/*  www .j  a v  a2  s  .co  m*/
        LOG.warn("Mapping does not exist for creating object: " + name);
    }
}

From source file:com.phresco.pom.util.PomProcessor.java

/**
 * Gets the plugin configuration value.// ww w  .  ja  va 2 s .  c  o m
 *
 * @param pluginGroupId the plugin group id
 * @param pluginArtifactId the plugin artifact id
 * @param tagName the tag name
 * @return the plugin configuration value
 * @throws PhrescoPomException the phresco pom exception
 */
public String getPluginConfigurationValue(String pluginGroupId, String pluginArtifactId, String tagName)
        throws PhrescoPomException {
    Plugin plugin = getPlugin(pluginGroupId, pluginArtifactId);
    Configuration configuration = plugin.getConfiguration();
    if (model.getBuild() != null && model.getBuild().getPlugins() != null && configuration != null) {
        for (Element config : configuration.getAny()) {
            if (tagName.equals(config.getTagName())) {
                return config.getTextContent();
            }
        }
    }
    return "";
}

From source file:com.phresco.pom.util.PomProcessor.java

/**
 * Sets the property./*from w w  w .  j av  a 2 s.c  om*/
 *
 * @param name the name
 * @param value the value
 * @throws ParserConfigurationException the parser configuration exception
 */

public void setProperty(String name, String value) throws ParserConfigurationException {

    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
    Document doc = docBuilder.newDocument();
    Element element = doc.createElement(name);
    element.setTextContent(value);

    if (model.getProperties() == null) {
        Properties properties = new Properties();
        model.setProperties(properties);
    }
    for (Element proElement : model.getProperties().getAny()) {
        if (proElement.getTagName().equals(name)) {
            proElement.setTextContent(value);
            return;
        }
    }
    model.getProperties().getAny().add(element);
}

From source file:com.cloud.hypervisor.vmware.mo.HypervisorHostHelper.java

public static String removeOVFNetwork(final String ovfString) {
    if (ovfString == null || ovfString.isEmpty()) {
        return ovfString;
    }//from  w ww . j  a  v  a 2  s .c om
    try {
        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        final Document doc = factory.newDocumentBuilder().parse(new ByteArrayInputStream(ovfString.getBytes()));
        final DocumentTraversal traversal = (DocumentTraversal) doc;
        final NodeIterator iterator = traversal.createNodeIterator(doc.getDocumentElement(),
                NodeFilter.SHOW_ELEMENT, null, true);
        for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) {
            final Element e = (Element) n;
            if ("NetworkSection".equals(e.getTagName())) {
                if (e.getParentNode() != null) {
                    e.getParentNode().removeChild(e);
                }
            } else if ("rasd:Connection".equals(e.getTagName())) {
                if (e.getParentNode() != null && e.getParentNode().getParentNode() != null) {
                    e.getParentNode().getParentNode().removeChild(e.getParentNode());
                }
            }
        }
        final DOMSource domSource = new DOMSource(doc);
        final StringWriter writer = new StringWriter();
        final StreamResult result = new StreamResult(writer);
        final TransformerFactory tf = TransformerFactory.newInstance();
        final Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);
        return writer.toString();
    } catch (SAXException | IOException | ParserConfigurationException | TransformerException e) {
        s_logger.warn("Unexpected exception caught while removing network elements from OVF:", e);
    }
    return ovfString;
}

From source file:com.enonic.vertical.engine.handlers.ContentObjectHandler.java

public void updateContentObject(Document doc) throws VerticalUpdateException {
    Element docElem = doc.getDocumentElement();
    Element[] contentobjectElems;
    if ("contentobject".equals(docElem.getTagName())) {
        contentobjectElems = new Element[] { docElem };
    } else {/* ww w  .ja  v a2 s. co  m*/
        contentobjectElems = XMLTool.getElements(doc.getDocumentElement());
    }

    Connection con = null;
    PreparedStatement preparedStmt = null;
    int pos = 0;
    String tmpStr = null;

    try {
        con = getConnection();
        preparedStmt = con.prepareStatement(COB_UPDATE);

        for (Element root : contentobjectElems) {
            Map subelems = XMLTool.filterElements(root.getChildNodes());

            int key = -1, menuKey = -1;
            ResourceKey styleSheetKey = null, borderStyleSheetKey = null;

            pos = 0;
            tmpStr = root.getAttribute("key");
            if (tmpStr != null && tmpStr.length() > 0) {
                key = Integer.parseInt(tmpStr);
            } else {
                String message = "No content object key specified.";
                VerticalEngineLogger.errorUpdate(this.getClass(), 0, message, null);
            }

            pos++;
            // was sitekey

            pos++;
            tmpStr = root.getAttribute("menukey");
            if (tmpStr != null && tmpStr.length() > 0) {
                menuKey = Integer.parseInt(tmpStr);
            } else {
                String message = "No menu key specified.";
                VerticalEngineLogger.errorUpdate(this.getClass(), 0, message, null);
            }

            pos++;
            Element subelem = (Element) subelems.get("objectstylesheet");
            if (subelem != null) {
                tmpStr = subelem.getAttribute("key");
                if (tmpStr != null && tmpStr.length() > 0) {
                    styleSheetKey = new ResourceKey(tmpStr);
                } else {
                    String message = "No object stylesheet key specified.";
                    VerticalEngineLogger.errorUpdate(this.getClass(), 0, message, null);
                }
            } else {
                String message = "No object stylesheet specified.";
                VerticalEngineLogger.errorUpdate(this.getClass(), 0, message, null);
            }

            pos++;
            subelem = (Element) subelems.get("borderstylesheet");
            if (subelem != null) {
                tmpStr = subelem.getAttribute("key");
                if (tmpStr != null && tmpStr.length() > 0) {
                    borderStyleSheetKey = new ResourceKey(tmpStr);
                }
            }

            // element: name
            String name = null;
            subelem = (Element) subelems.get("name");
            if (subelem != null) {
                name = XMLTool.getElementText(subelem);
                if (name == null || name.length() == 0) {
                    String message = "Empty stylesheet name.";
                    VerticalEngineLogger.errorUpdate(this.getClass(), 0, message, null);
                }
            } else {
                String message = "No stylesheet name specified.";
                VerticalEngineLogger.errorUpdate(this.getClass(), 0, message, null);
            }

            // element: contentobjectdata (optional)
            byte[] contentobjectdata;
            subelem = (Element) subelems.get("contentobjectdata");
            if (subelem != null) {
                Document codDoc = XMLTool.createDocument();
                codDoc.appendChild(codDoc.importNode(subelem, true));
                contentobjectdata = XMLTool.documentToBytes(codDoc, "UTF-8");
            } else {
                contentobjectdata = null;
            }

            preparedStmt.setInt(7, key);
            preparedStmt.setInt(1, menuKey);
            if (styleSheetKey != null) {
                preparedStmt.setString(2, styleSheetKey.toString());
            } else {
                preparedStmt.setNull(2, Types.VARCHAR);
            }
            if (borderStyleSheetKey != null) {
                preparedStmt.setString(3, borderStyleSheetKey.toString());
            } else {
                preparedStmt.setNull(3, Types.VARCHAR);
            }
            preparedStmt.setCharacterStream(4, new StringReader(name), name.length());
            if (contentobjectdata != null) {
                preparedStmt.setBinaryStream(5, new ByteArrayInputStream(contentobjectdata),
                        contentobjectdata.length);
            } else {
                preparedStmt.setNull(5, Types.VARCHAR);
            }

            RunAsType runAs = RunAsType.INHERIT;
            String runAsStr = root.getAttribute("runAs");
            if (StringUtils.isNotEmpty(runAsStr)) {
                runAs = RunAsType.valueOf(runAsStr);
            }
            preparedStmt.setInt(6, runAs.getKey());

            // update content object
            int result = preparedStmt.executeUpdate();
            if (result <= 0) {
                String message = "Failed to update content object, no content object updated.";
                VerticalEngineLogger.errorUpdate(this.getClass(), 0, message, null);
            }
        }

        preparedStmt.close();
        preparedStmt = null;
    } catch (SQLException sqle) {
        String message = "Failed to update content object(s): %t";
        VerticalEngineLogger.errorUpdate(this.getClass(), 0, message, sqle);
    } catch (NumberFormatException nfe) {
        String message = "Failed to parse %0: %1";
        Object[] msgData;
        switch (pos) {
        case 1:
            msgData = new Object[] { "site key", tmpStr };
            break;
        case 2:
            msgData = new Object[] { "menu key", tmpStr };
            break;
        case 3:
            msgData = new Object[] { "object stylesheet key", tmpStr };
            break;
        case 4:
            msgData = new Object[] { "border stylesheet key", tmpStr };
            break;
        default:
            msgData = new Object[] { "content object key", tmpStr };
        }
        VerticalEngineLogger.errorUpdate(this.getClass(), 0, message, msgData, nfe);
    } finally {
        close(preparedStmt);
        close(con);
    }
}

From source file:com.enonic.vertical.engine.handlers.ContentObjectHandler.java

public int[] createContentObject(CopyContext copyContext, Document doc, boolean useOldKey)
        throws VerticalCreateException {

    Element docElem = doc.getDocumentElement();
    Element[] contentobjectElems;
    if ("contentobject".equals(docElem.getTagName())) {
        contentobjectElems = new Element[] { docElem };
    } else {//from   ww w.ja  v a 2  s.com
        contentobjectElems = XMLTool.getElements(doc.getDocumentElement());
    }

    Connection con = null;
    PreparedStatement preparedStmt = null;
    int pos = 0;
    String tmpStr = null;
    TIntArrayList newKeys = new TIntArrayList();

    try {
        con = getConnection();
        preparedStmt = con.prepareStatement(COB_CREATE);

        for (Element root : contentobjectElems) {
            Map subelems = XMLTool.filterElements(root.getChildNodes());

            int key, menuKey = -1;
            String styleSheetKey = "", borderStyleSheetKey = "";

            pos = 0;
            String keyStr = root.getAttribute("key");
            if (!useOldKey || tmpStr == null || tmpStr.length() == 0) {
                key = getNextKey(COB_TABLE);
            } else {
                key = Integer.parseInt(tmpStr);
            }
            if (copyContext != null) {
                copyContext.putContentObjectKey(Integer.parseInt(keyStr), key);
            }
            newKeys.add(key);

            pos++;
            // was sitekey

            pos++;
            tmpStr = root.getAttribute("menukey");
            if (tmpStr != null && tmpStr.length() > 0) {
                menuKey = Integer.parseInt(tmpStr);
            } else {
                String message = "No menu key specified.";
                VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null);
            }

            pos++;
            Element subelem = (Element) subelems.get("objectstylesheet");
            if (subelem != null) {
                tmpStr = subelem.getAttribute("key");
                if (tmpStr != null && tmpStr.length() > 0) {
                    styleSheetKey = tmpStr;
                } else {
                    String message = "No object stylesheet key specified.";
                    VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null);
                }
            } else {
                String message = "No object stylesheet specified.";
                VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null);
            }

            pos++;
            subelem = (Element) subelems.get("borderstylesheet");
            if (subelem != null) {
                tmpStr = subelem.getAttribute("key");
                if (tmpStr != null && tmpStr.length() > 0) {
                    borderStyleSheetKey = tmpStr;
                }
            }

            String name = null;
            byte[] contentobjectdata;

            // element: name
            subelem = (Element) subelems.get("name");
            if (subelem != null) {
                name = XMLTool.getElementText(subelem);
                if (name == null || name.length() == 0) {
                    String message = "Empty stylesheet name.";
                    VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null);
                }
            } else {
                String message = "No stylesheet name specified.";
                VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null);
            }

            // element: contentobjectdata (optional)
            subelem = (Element) subelems.get("contentobjectdata");
            if (subelem != null) {
                Document codDoc = XMLTool.createDocument();
                codDoc.appendChild(codDoc.importNode(subelem, true));
                contentobjectdata = XMLTool.documentToBytes(codDoc, "UTF-8");
            } else {
                contentobjectdata = null;
            }

            preparedStmt.setInt(1, key);
            preparedStmt.setInt(2, menuKey);
            preparedStmt.setString(3, styleSheetKey);
            if (borderStyleSheetKey.length() > 0) {
                preparedStmt.setString(4, borderStyleSheetKey);
            } else {
                preparedStmt.setNull(4, Types.VARCHAR);
            }
            preparedStmt.setString(5, name);
            if (contentobjectdata != null) {
                preparedStmt.setBinaryStream(6, new ByteArrayInputStream(contentobjectdata),
                        contentobjectdata.length);
            } else {
                preparedStmt.setNull(6, Types.VARBINARY);
            }

            RunAsType runAs = RunAsType.INHERIT;
            String runAsStr = root.getAttribute("runAs");
            if (StringUtils.isNotEmpty(runAsStr)) {
                runAs = RunAsType.valueOf(runAsStr);
            }
            preparedStmt.setInt(7, runAs.getKey());

            // create content object
            int result = preparedStmt.executeUpdate();
            if (result <= 0) {
                String message = "Failed to create content object, no content object created.";
                VerticalEngineLogger.errorCreate(this.getClass(), 0, message, null);
            }
        }

        preparedStmt.close();
        preparedStmt = null;
    } catch (SQLException sqle) {
        String message = "Failed to create content object(s): %t";
        VerticalEngineLogger.errorCreate(this.getClass(), 0, message, sqle);
    } catch (NumberFormatException nfe) {
        String message = "Failed to parse %0: %1";
        Object[] msgData;
        switch (pos) {
        case 1:
            msgData = new Object[] { "site key", tmpStr };
            break;
        case 2:
            msgData = new Object[] { "menu key", tmpStr };
            break;
        case 3:
            msgData = new Object[] { "object stylesheet key", tmpStr };
            break;
        case 4:
            msgData = new Object[] { "border stylesheet key", tmpStr };
            break;
        default:
            msgData = new Object[] { "content object key", tmpStr };
        }
        VerticalEngineLogger.errorCreate(this.getClass(), 0, message, msgData, nfe);
    } catch (VerticalKeyException gke) {
        String message = "Failed to generate content object key";
        VerticalEngineLogger.errorCreate(this.getClass(), 0, message, gke);
    } finally {
        close(preparedStmt);
        close(con);
    }

    return newKeys.toArray();
}

From source file:com.connexta.arbitro.ConfigurationStore.java

/**
 * Private helper that parses the file and sets up the DOM tree.
 *//*from w ww  .j  a v  a2 s.c o m*/
private Node getRootNode(File configFile) throws ParsingException {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();

    dbFactory.setIgnoringComments(true);
    dbFactory.setNamespaceAware(false);
    dbFactory.setValidating(false);

    DocumentBuilder db = null;
    try {
        db = dbFactory.newDocumentBuilder();
    } catch (ParserConfigurationException pce) {
        throw new ParsingException("couldn't get a document builder", pce);
    }

    Document doc = null;
    InputStream stream = null;
    try {
        stream = new FileInputStream(configFile);
        doc = db.parse(stream);
    } catch (IOException ioe) {
        throw new ParsingException("failed to load the file ", ioe);
    } catch (SAXException saxe) {
        throw new ParsingException("error parsing the XML tree", saxe);
    } catch (IllegalArgumentException iae) {
        throw new ParsingException("no data to parse", iae);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                logger.error("Error while closing input stream");
            }
        }
    }

    Element root = doc.getDocumentElement();

    if (!root.getTagName().equals("config"))
        throw new ParsingException("unknown document type: " + root.getTagName());

    return root;
}