List of usage examples for org.dom4j.io SAXReader setDocumentFactory
public void setDocumentFactory(DocumentFactory documentFactory)
This sets the DocumentFactory
used to create new documents.
From source file:com.fonoster.astive.examples.ws.YahooParser.java
License:Apache License
private SAXReader createXmlReader() { Map<String, String> uris = new HashMap<String, String>(); uris.put("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0"); DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(uris); SAXReader xmlReader = new SAXReader(); xmlReader.setDocumentFactory(factory); return xmlReader; }
From source file:com.mycompany.simple.weather.YahooParser.java
License:Apache License
private SAXReader createXmlReader() { Map<String, String> uris = new HashMap<String, String>(); uris.put("y", "http://xml.weather.yahoo.com/ns/rss/1.0"); DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(uris); SAXReader xmlReader = new SAXReader(); xmlReader.setDocumentFactory(factory); return xmlReader; }
From source file:com.zia.freshdocs.cmis.CMISParser10.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from ww w .j a va 2 s .c o m public NodeRef[] parseChildren(InputStream is) { NodeRef[] children = null; HashMap<String, String> nsMap = new HashMap<String, String>(); nsMap.put("atom", ATOM_NS); nsMap.put("cmis", CMIS_NS); DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(nsMap); SAXReader reader = new SAXReader(); reader.setDocumentFactory(factory); try { Document document = reader.read(is); List<Element> entries = (List<Element>) document.selectNodes("/atom:feed/atom:entry"); int numEntries = entries.size(); children = new NodeRef[numEntries]; Element entry; NodeRef nodeRef; // Iterate over each entry element and find corresponding attrs for (int i = 0; i < numEntries; i++) { nodeRef = new NodeRef(); children[i] = nodeRef; entry = entries.get(i); // Get either the node uuid or src uri and content type Element id = entry.element("id"); String uuid = id.getTextTrim().replace(URN_UUID, ""); nodeRef.setContent(uuid); Element content = entry.element("content"); String contentType = content.attributeValue("type"); if (contentType != null) { nodeRef.setContentType(contentType); nodeRef.setContent(content.attributeValue("src")); } List<Element> cmisProperties = entry.selectNodes(".//cmis:properties/*"); int numProperties = cmisProperties.size(); Element cmisProperty; // Iterate over each property and populate associated field in NodeRef for (int j = 0; j < numProperties; j++) { cmisProperty = cmisProperties.get(j); String attrValue = cmisProperty.attributeValue("propertyDefinitionId"); if (attrValue == null) { continue; } if (attrValue.equals("cmis:name")) { nodeRef.setName(cmisProperty.elementTextTrim("value")); } if (attrValue.equals("cmis:baseTypeId")) { String typeId = cmisProperty.elementTextTrim("value"); nodeRef.setFolder(typeId != null && typeId.equals("cmis:folder")); } if (attrValue.equals("cmis:lastModificationDate")) { nodeRef.setLastModificationDate(cmisProperty.elementTextTrim("value")); } if (attrValue.equals("cmis:lastModifiedBy")) { nodeRef.setLastModifiedBy(cmisProperty.elementTextTrim("value")); } if (attrValue.equals("cmis:versionLabel")) { nodeRef.setVersion(cmisProperty.elementTextTrim("value")); } if (attrValue.equals("cmis:createdBy")) { nodeRef.setCreateBy(cmisProperty.elementTextTrim("value")); } if (attrValue.equals("cmis:objectId")) { nodeRef.setObjectId(cmisProperty.elementTextTrim("value")); } if (attrValue.equals("cmis:parentId")) { nodeRef.setParentId(cmisProperty.elementTextTrim("value")); } if (attrValue.equals("cmis:contentStreamLength")) { nodeRef.setContentLength(Long.valueOf(cmisProperty.elementTextTrim("value"))); } } } } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } return children; }
From source file:com.zimbra.common.soap.W3cDomUtil.java
License:Open Source License
public static SAXReader getDom4jSAXReaderWhichUsesSecureProcessing(DocumentFactory fact) throws XmlParseException, SAXException { SAXReader dom4jSAXReader = new SAXReader(getDom4jSAXParserWhichUsesSecureProcessing().getXMLReader()); if (null != fact) { dom4jSAXReader.setDocumentFactory(fact); }/*w ww . jav a 2 s. co m*/ return dom4jSAXReader; }
From source file:de.innovationgate.wgpublisher.lucene.LuceneIndexConfiguration.java
License:Open Source License
public LuceneIndexConfiguration(WGACore core, File indexDir) throws IllegalArgumentException, DocumentException { _core = core;/*from w ww.j av a2 s . com*/ _configFile = new File(indexDir, "wgalucene.xml"); if (!_configFile.exists()) { _newConfiguration = true; _configDoc = DatatypeDocumentFactory.getInstance().createDocument(); _configDocRoot = _configDoc.addElement("wgalucene"); _configDocRoot.addAttribute("version", VERSION); } else { SAXReader saxReader = new SAXReader(); saxReader.setDocumentFactory(DatatypeDocumentFactory.getInstance()); _configDoc = saxReader.read(_configFile); _configDocRoot = _configDoc.getRootElement(); // check if configfile has right version String version = _configDocRoot.attributeValue("version"); if ((version == null) || (!version.equals(VERSION))) { _core.getLog().warn("Unsupported index configuration found. New configuration will be created ..."); _newConfiguration = true; _configDoc = DatatypeDocumentFactory.getInstance().createDocument(); _configDocRoot = _configDoc.addElement("wgalucene"); _configDocRoot.addAttribute("version", VERSION); } } }
From source file:org.dom4j.samples.DatatypeDemo.java
License:Open Source License
protected Document parse(String xmlFile) throws Exception { SAXReader reader = new SAXReader(); reader.setDocumentFactory(DatatypeDocumentFactory.getInstance()); return reader.read(xmlFile); }
From source file:org.dom4j.samples.VisitorDemo2.java
License:Open Source License
protected SAXReader createSAXReader() throws Exception { println("Using SAX parser: " + System.getProperty("org.xml.sax.driver", "default")); SAXReader answer = new SAXReader(); if (documentFactoryClassName != null) { try {// w w w . j a va 2s .co m Class theClass = Class.forName(documentFactoryClassName); DocumentFactory factory = (DocumentFactory) theClass.newInstance(); if (factory != null) { println("DocumentFactory: " + factory); answer.setDocumentFactory(factory); } } catch (Exception e) { println("ERROR: Failed to create an instance of DocumentFactory: " + documentFactoryClassName); println("Exception: " + e); e.printStackTrace(); } } return answer; }
From source file:org.orbeon.oxf.processor.tamino.dom4j.TDOM4JInputStreamInterpreter.java
License:Open Source License
/** ** Interprets the a general inputStream in a generic fashion. As a consequence only the ** result state will be obtained.//from w w w. jav a2 s . c om ** ** @param inputStream is the InputStream for a response to a previous operation on Tamino. ** @exception TStreamInterpretException when interpreting errors occur. **/ protected void doInterpret(TInputStream inputStream) throws TStreamInterpretException { // please have a look at comment in the initialize method. try { // Create the DOM4J SAXReader with the DOM4J specific underlying SAX parser. This is a JAXP parser! SAXReader saxReader = (parserName == null || parserName.equals("")) ? new SAXReader() : new SAXReader(parserName); // Make sure the document and its children are thread safe by using our // document factory. final DocumentFactory factory = NonLazyUserDataDocumentFactory.getInstance(); saxReader.setDocumentFactory(factory); // Invoke the parsing and obtain the Document instance document = saxReader.read(inputStream); TStreamHeader header = inputStream.getHeader(); // Set the result state setResponseInfoContent(document); // Set the result set of querried XML objects only if result relates to a query if (document.getRootElement().element(new QName(TXQLNamespace.QUERY.getName(), xqlNamespace)) != null || document.getRootElement() .element(new QName(TXQNamespace.XQUERY.getName(), xqNamespace)) != null) { setResponseQueryContent(document, (String) header.getValue(TStreamHeader.COLLECTION), (String) header.getValue(TStreamHeader.DOCTYPE)); } } catch (SAXException saxException) { throw new TStreamInterpretException("Interpreting the input stream for DOM4J failed!", saxException); } catch (Exception exception) { throw new TStreamInterpretException("Interpreting the input stream failed!", exception); } }
From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java
License:Open Source License
private static SAXReader createSAXReader(XMLUtils.ParserConfiguration parserConfiguration) throws SAXException { final XMLReader xmlReader = XMLUtils.newXMLReader(parserConfiguration); final SAXReader saxReader = new SAXReader(xmlReader); final DocumentFactory factory = NonLazyUserDataDocumentFactory.getInstance(); saxReader.setDocumentFactory(factory); return saxReader; }
From source file:org.pentaho.aggdes.model.ssas.ConversionUtil.java
License:Open Source License
public static Document parseAssl(final InputStream input) throws DocumentException, IOException { Map<String, String> uris = new HashMap<String, String>(); uris.put("assl", "http://schemas.microsoft.com/analysisservices/2003/engine"); uris.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); uris.put("xs", "http://www.w3.org/2001/XMLSchema"); uris.put("msprop", "urn:schemas-microsoft-com:xml-msprop"); uris.put("msdata", "urn:schemas-microsoft-com:xml-msdata"); DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(uris); SAXReader reader = new SAXReader(); reader.setDocumentFactory(factory); // get bytes from InputStream and cache them so they can be read multiple times byte[] bytes = IOUtils.toByteArray(input); ByteArrayInputStream byteInput = new ByteArrayInputStream(bytes); // try default encoding first, then fall back on iso-8859-1 Document document = null;/*w w w . j a v a2s.c o m*/ try { logger.debug("attempting to parse assuming utf-8 encoding"); document = reader.read(byteInput); } catch (DocumentException e) { // retry reader.setEncoding("iso-8859-1"); // exception will propagate if it fails to read with iso-8859-1 logger.debug("parse failed; attempting to parse assuming iso=8859-1 encoding"); // start over from the first byte by creating a new stream byteInput = new ByteArrayInputStream(bytes); document = reader.read(byteInput); } return document; }