List of usage examples for org.dom4j Node ELEMENT_NODE
short ELEMENT_NODE
To view the source code for org.dom4j Node ELEMENT_NODE.
Click Source Link
From source file:com.nokia.helium.ant.data.TaskMeta.java
License:Open Source License
@SuppressWarnings("unchecked") public Map<String, String> getParams() { Map<String, String> params = new HashMap<String, String>(); if (getNode().getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) getNode(); List<Element> paramNodes = element.elements("param"); for (Element paramNode : paramNodes) { params.put(paramNode.attributeValue("name"), paramNode.attributeValue("value")); }// w w w .ja va 2s . c o m } return params; }
From source file:com.smartwork.im.utils.XMLWriter.java
License:Open Source License
public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException { try {//from www.ja va 2 s .co m charactersAdded = false; writePrintln(); indent(); writer.write("<"); writer.write(qName); writeNamespaces(); writeAttributes(attributes); writer.write(">"); ++indentLevel; lastOutputNodeType = Node.ELEMENT_NODE; super.startElement(namespaceURI, localName, qName, attributes); } catch (IOException e) { handleException(e); } }
From source file:com.smartwork.im.utils.XMLWriter.java
License:Open Source License
public void endElement(String namespaceURI, String localName, String qName) throws SAXException { try {/*from w ww. jav a 2 s .c o m*/ charactersAdded = false; --indentLevel; if (lastOutputNodeType == Node.ELEMENT_NODE) { writePrintln(); indent(); } // XXXX: need to determine this using a stack and checking for // content / children boolean hadContent = true; if (hadContent) { writeClose(qName); } else { writeEmptyElementClose(qName); } lastOutputNodeType = Node.ELEMENT_NODE; super.endElement(namespaceURI, localName, qName); } catch (IOException e) { handleException(e); } }
From source file:com.stgmastek.core.util.XMLUtil.java
License:Open Source License
/** * Returns the response data object// w ww . j a v a 2 s. co m * * @param responseString * The response string. * * @return List of Element instances from data tag. * * @throws Exception */ public static List<org.w3c.dom.Element> getData(String responseString) throws Exception { DocumentFactory factory = new org.dom4j.dom.DOMDocumentFactory(); SAXReader reader = new SAXReader(factory); List<org.w3c.dom.Element> elements = new ArrayList<org.w3c.dom.Element>(); try { Document responseDocument = reader.read(new StringReader(responseString)); org.dom4j.Node dataNode = responseDocument.selectSingleNode(DATA_XPATH); if ((dataNode != null) && (dataNode.getNodeType() == Node.ELEMENT_NODE)) { Element dataElement = (Element) dataNode; for (Iterator<?> nodeIterator = dataElement.elementIterator(); nodeIterator.hasNext();) { Element objectNode = (Element) nodeIterator.next(); elements.add(DOMNodeHelper.asDOMElement(objectNode)); } } } catch (DocumentException e) { throw new Exception("Invalid response", e); } return elements; }
From source file:com.webslingerz.jpt.PageTemplateImpl.java
License:Open Source License
private void defaultContent(Element element, ContentHandler contentHandler, LexicalHandler lexicalHandler, Interpreter beanShell, Stack<Map<String, Slot>> slotStack) throws SAXException, PageTemplateException, IOException { // Use default template content for (Iterator i = element.nodeIterator(); i.hasNext();) { Node node = (Node) i.next(); switch (node.getNodeType()) { case Node.ELEMENT_NODE: processElement((Element) node, contentHandler, lexicalHandler, beanShell, slotStack); break; case Node.TEXT_NODE: char[] text = Expression.evaluateText(node.getText().toString(), beanShell).toCharArray(); contentHandler.characters(text, 0, text.length); break; case Node.COMMENT_NODE: char[] comment = node.getText().toCharArray(); lexicalHandler.comment(comment, 0, comment.length); break; case Node.CDATA_SECTION_NODE: lexicalHandler.startCDATA(); char[] cdata = node.getText().toCharArray(); contentHandler.characters(cdata, 0, cdata.length); lexicalHandler.endCDATA();/* w w w. j a v a2 s . c o m*/ break; case Node.NAMESPACE_NODE: Namespace declared = (Namespace) node; // System.err.println( "Declared namespace: " + // declared.getPrefix() + ":" + declared.getURI() ); namespaces.put(declared.getPrefix(), declared.getURI()); // if ( declared.getURI().equals( TAL_NAMESPACE_URI ) ) { // this.talNamespacePrefix = declared.getPrefix(); // } // else if (declared.getURI().equals( METAL_NAMESPACE_URI ) ) { // this.metalNamespacePrefix = declared.getPrefix(); // } break; case Node.ATTRIBUTE_NODE: // Already handled break; case Node.DOCUMENT_TYPE_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.PROCESSING_INSTRUCTION_NODE: default: // System.err.println( "WARNING: Node type not supported: " + // node.getNodeTypeName() ); } } }
From source file:darks.orm.core.config.sqlmap.DMLConfigReader.java
License:Apache License
private void parseSqlTag(AbstractTag parent, Element el, String namesp) throws Exception { AbstractTag prevTag = null;//from www . ja v a2s . c o m List<Node> list = el.content(); Iterator<Node> it = list.iterator(); while (it.hasNext()) { Node node = it.next(); switch (node.getNodeType()) { case Node.ELEMENT_NODE: Element childEl = (Element) node; prevTag = parseElementTag(parent, node, childEl, namesp, prevTag); break; case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: String text = node.getText().replaceAll("\n|\t", " ").trim(); if (!"".equals(text)) { TextTag tag = new TextTag(text, prevTag); parent.addChild(tag); prevTag = tag; } break; } } }
From source file:dk.netarkivet.common.utils.XmlTree.java
License:Open Source License
/** * Initialise a node in an XML tree.//from ww w .j a v a 2s. c o m * * @param n The XML node for this node * @param parser The parser that can convert a leaf node to a value of type T. * @throws ArgumentNotValid on null argument, or if n is not of type element or document. */ private XmlTree(Node n, ValueParser<T> parser) { ArgumentNotValid.checkNotNull(n, "Node n"); ArgumentNotValid.checkNotNull(parser, "ValueParser<T> parser"); if (n.getNodeType() == Node.DOCUMENT_NODE) { root = (Document) n; element = null; } else if (n.getNodeType() == Node.ELEMENT_NODE) { element = (Element) n; root = null; } else { throw new ArgumentNotValid("Invalid XML node type '" + n.getNodeTypeName() + "'"); } this.parser = parser; }
From source file:fr.gouv.culture.vitam.utils.XmlDom.java
License:Open Source License
/** * Recursively sets the namespace of the List and all children if the current namespace is match *//*from w w w.j av a 2 s . c o m*/ private final static void setNamespaces(List<?> l, Namespace ns) { Node n = null; for (int i = 0; i < l.size(); i++) { n = (Node) l.get(i); if (n.getNodeType() == Node.ATTRIBUTE_NODE) { Namespace namespace = ((Attribute) n).getNamespace(); if (!namespace.equals(ns)) { ((Attribute) n).setNamespace(ns); } } if (n.getNodeType() == Node.ELEMENT_NODE) { Namespace namespace = ((Element) n).getNamespace(); if (!namespace.equals(ns)) { if (ns.equals(Namespace.NO_NAMESPACE)) { ((Element) n).remove(namespace); } setNamespaces((Element) n, ns); } } } }
From source file:freemarker.ext.xml._Dom4jNavigator.java
License:Apache License
String getType(Object node) { switch (((Node) node).getNodeType()) { case Node.ATTRIBUTE_NODE: { return "attribute"; }//from www .j a va 2 s. c o m case Node.CDATA_SECTION_NODE: { return "cdata"; } case Node.COMMENT_NODE: { return "comment"; } case Node.DOCUMENT_NODE: { return "document"; } case Node.DOCUMENT_TYPE_NODE: { return "documentType"; } case Node.ELEMENT_NODE: { return "element"; } case Node.ENTITY_REFERENCE_NODE: { return "entityReference"; } case Node.NAMESPACE_NODE: { return "namespace"; } case Node.PROCESSING_INSTRUCTION_NODE: { return "processingInstruction"; } case Node.TEXT_NODE: { return "text"; } } return "unknown"; }
From source file:gov.nih.nci.caarray.upgrade.SingleConnectionHibernateHelper.java
License:BSD License
/** * @param connection//from w ww .j a v a 2 s . co m */ public void initialize(Connection connection) { HibernateSingleConnectionProvider.setConnection(connection); InputStream configurationStream = FixIlluminaGenotypingCsvDesignProbeNamesMigrator.class .getResourceAsStream("/hibernate.cfg.xml"); SAXReader reader = new SAXReader(); reader.setEntityResolver(new org.hibernate.util.DTDEntityResolver()); Document configurationDocument = null; try { configurationDocument = reader.read(configurationStream); } catch (DocumentException e) { throw new UnhandledException(e); } Node sessionFactoryNode = configurationDocument .selectSingleNode("/hibernate-configuration/session-factory"); Iterator<?> iter = ((Branch) sessionFactoryNode).nodeIterator(); while (iter.hasNext()) { Node currentNode = (Node) iter.next(); if (currentNode.getNodeType() == Node.ELEMENT_NODE && !currentNode.getName().equals("mapping")) { iter.remove(); } } DOMWriter domWriter = new DOMWriter(); org.w3c.dom.Document document = null; try { document = domWriter.write(configurationDocument); } catch (DocumentException e) { throw new UnhandledException(e); } configuration = new AnnotationConfiguration(); configuration.setProperty(Environment.CONNECTION_PROVIDER, "gov.nih.nci.caarray.upgrade.HibernateSingleConnectionProvider"); configuration.configure(document); configuration.setProperty(Environment.TRANSACTION_STRATEGY, "org.hibernate.transaction.JDBCTransactionFactory"); configuration.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); configuration.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false"); configuration.getProperties().remove(Environment.TRANSACTION_MANAGER_STRATEGY); configuration.setNamingStrategy(new NamingStrategy()); sessionFactory = configuration.buildSessionFactory(); }