List of usage examples for org.dom4j.io SAXReader setEncoding
public void setEncoding(String encoding)
From source file:org.craftercms.cstudio.alfresco.dm.content.pipeline.impl.PipelineContentImpl.java
License:Open Source License
@Override public Document getDocument() throws ContentProcessException { if (_xml && _document == null) { if (_contentStream != null) { try { SAXReader saxReader = new SAXReader(); saxReader.setEncoding(_encoding); _document = saxReader.read(_contentStream); _contentStream = null;//w w w . j av a 2s . c om } catch (DocumentException e) { throw new ContentProcessException("Error while converting " + _id + " into document.", e); } finally { ContentUtils.release(_contentStream); _contentStream = null; } } else { throw new ContentProcessException("Error while converting " + _id + " into document. Both document and content stream cannot be null."); } } return _document; }
From source file:org.craftercms.cstudio.publishing.processor.SearchUpdateFlattenXmlProcessor.java
License:Open Source License
private Document flattenXml(String root, File file, Set<String> flattenedFiles) throws IOException, DocumentException, URISyntaxException { SAXReader reader = new SAXReader(); SAXReader includeReader = new SAXReader(); try {//from w ww. j a va 2 s . co m reader.setEncoding(charEncoding); Document document = reader.read(file); List<Element> includeElements = document.selectNodes(includeElementXPathQuery); if (CollectionUtils.isEmpty(includeElements)) { return document; } for (Element includeElement : includeElements) { String includeSrcPath = root + File.separatorChar + includeElement.getTextTrim(); if (StringUtils.isEmpty(includeSrcPath)) { continue; } File includeFile = new File(includeSrcPath); if (includeFile != null && includeFile.exists()) { flattenedFiles.add(includeSrcPath); Document includeDocument = flattenXml(root, includeFile, flattenedFiles); if (logger.isDebugEnabled()) { logger.debug("Include found in " + file.getAbsolutePath() + ": " + includeSrcPath); } doInclude(includeElement, includeSrcPath, includeDocument); } } return document; } finally { reader.resetHandlers(); reader = null; includeReader.resetHandlers(); includeReader = null; } }
From source file:org.craftercms.search.service.impl.SolrDocumentBuilder.java
License:Open Source License
protected SAXReader createSAXReader() { SAXReader reader = new SAXReader(); reader.setEncoding(CharEncoding.UTF_8); reader.setMergeAdjacentText(true);/*from ww w . ja v a 2 s. c om*/ return reader; }
From source file:org.craftercms.search.service.impl.SolrDocumentBuilderImpl.java
License:Open Source License
protected SAXReader createSAXReader() { SAXReader reader = new SAXReader(); reader.setEncoding(CharEncoding.UTF_8); reader.setMergeAdjacentText(true);/*w ww.ja v a 2 s . c om*/ try { reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); reader.setFeature("http://xml.org/sax/features/external-general-entities", false); reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false); } catch (SAXException ex) { logger.error("Unable to turn off external entity loading, This could be a security risk.", ex); } return reader; }
From source file:org.fireflow.engine.modules.persistence.hibernate.VariableHeaderType.java
License:Open Source License
public static Properties xmlString2Map(String theString) { String s = (String) theString; if (s == null || s.trim().equals("")) return new Properties(); String encoding = Utils.findXmlCharset(theString); Properties map = new Properties(); SAXReader reader = new SAXReader(); reader.setEncoding(encoding); try {/* w w w . j a va 2 s .c om*/ Document doc = reader.read(new ByteArrayInputStream(s.getBytes(encoding))); Element theMapElement = doc.getRootElement(); List<Element> entryElements = theMapElement.elements("entry"); if (entryElements != null) { for (Element entryElm : entryElements) { Element key = entryElm.element("key"); Element value = entryElm.element("value"); map.put(key.getText(), value.getText()); } } } catch (UnsupportedEncodingException e) { log.error(e.getMessage(), e); } catch (DocumentException e) { log.error(e.getMessage(), e); } return map; }
From source file:org.frogx.service.component.container.PluginManager.java
License:Open Source License
public void loadPlugin(String pluginName, File pluginDir) { try {/*from w w w.j a v a 2s .co m*/ File pluginConfig = new File(pluginDir, "frogx.xml"); if (pluginConfig.exists()) { SAXReader saxReader = new SAXReader(); saxReader.setEncoding("UTF-8"); Document xmlConfig = saxReader.read(pluginConfig); Element rootEl = xmlConfig.getRootElement(); Element element = rootEl.element("type"); if (element == null || "match".equalsIgnoreCase(element.getText())) { element = rootEl.element("match"); if (element != null && element.getText().trim().length() > 0) { PluginClassLoader pluginLoader = new PluginClassLoader(mugManager); pluginLoader.addDirectory(pluginDir); ClassLoader oldLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(pluginLoader); DefaultMultiUserGame game = new DefaultMultiUserGame(pluginDir, mugManager); game.setMatchClassloader(pluginLoader); classloaders.put(pluginName, pluginLoader); games.put(pluginName, game); mugManager.registerMultiUserGame(game.getNamespace(), game); Thread.currentThread().setContextClassLoader(oldLoader); } } } } catch (Exception e) { log.error("Error while loading plugin.", e); } }
From source file:org.frogx.service.core.DefaultMultiUserGame.java
License:Open Source License
/** * Read the provided game descriptor and update the plug-in attributes. * //from w ww .j a v a 2s .com * @param gameDescriptor The file which describes the game descriptor. * @throws DocumentException if the file can't be read. */ @SuppressWarnings("unchecked") public void readGameDescriptor(File gameDescriptor) throws DocumentException { SAXReader reader = new SAXReader(); reader.setEncoding("UTF-8"); Document document = reader.read(gameDescriptor); Element root = document.getRootElement(); Element type = root.element("type"); if (type == null || "match".equals(type.getText().toLowerCase())) { for (Iterator i = root.elementIterator(); i.hasNext();) { Element child = (Element) i.next(); if ("match".equals(child.getName())) { matchClassName = child.getText(); } else if ("namespace".equals(child.getName())) { namespace = child.getText(); } else if ("name".equals(child.getName())) { name = child.getText(); } else if ("description".equals(child.getName())) { description = child.getText(); } else if ("category".equals(child.getName())) { category = child.getText(); } } } else { throw new IllegalArgumentException("The descriptor don't provide a match."); } // verify if (matchClassName == null || matchClassName.trim().length() == 0) { throw new IllegalArgumentException("The descriptor don't provide a match class."); } if (namespace == null || namespace.trim().length() == 0) { throw new IllegalArgumentException("The descriptor don't provide a namespace."); } if (description == null || description.trim().length() == 0) { description = name; } }
From source file:org.gbif.harvest.digir.DigirMetadataHandler.java
License:Open Source License
/** * Parse the response file and write the parsed values to their * appropriate file./*w w w . j av a 2 s.c om*/ * * @param inputStream representing harvested xml response * * @throws DocumentException thrown if parsing error occurred * @throws IOException thrown */ private void parseResponseFile(ByteArrayInputStream inputStream) throws DocumentException, IOException { // create a DOM4J tree, reading a Document from the given File SAXReader reader = new SAXReader(); reader.setEncoding("UTF-8"); Document document = reader.read(inputStream); document.setXMLEncoding("UTF-8"); // get all resource Elements List<Node> resourceEntities = (metadataRepeatingElementsXpath.get(resourceEntityRepeatingElementName)) .selectNodes(document); // iterate over resource Elements for (Node resourceEntity : resourceEntities) { // Detatch resource Element and create new Document with it DefaultDocument doc1 = new DefaultDocument(); doc1.setRootElement((Element) resourceEntity.detach()); // get all resource contact Elements List<Node> resourceContacts = (metadataRepeatingElementsXpath.get(contactEntityRepeatingElementName)) .selectNodes(doc1); // iterate over contact Elements for (Node resourceContact : resourceContacts) { // Detatch relatedEntity Element and create new Document with it DefaultDocument doc2 = new DefaultDocument(); doc2.setRootElement((Element) resourceContact.detach()); // write hasContact elements-of-interest to file fileUtils.writeValuesToFile(resourceContactsBW, metadataResourceContactElementsOfInterest.values(), doc2, namespaceMap, String.valueOf(getLineNumber())); } // write relatedEntity elements-of-interest to file fileUtils.writeValuesToFile(resourcesBW, metadataElementsOfInterest.values(), doc1, namespaceMap, String.valueOf(getLineNumber())); setLineNumber(getLineNumber() + 1); } }
From source file:org.gbif.harvest.tapir.TapirMetadataHandler.java
License:Open Source License
/** * Parse the response file and write the parsed values to their * appropriate file.//from w w w. j av a 2 s . c o m * * @param stream file representing harvested xml response as ByteArrayInputStream * * @throws DocumentException thrown if parsing errors occur * @throws IOException thrown */ private void parseResponseFile(ByteArrayInputStream stream) throws DocumentException, IOException { // create a DOM4J tree, reading a Document from the given File SAXReader reader = new SAXReader(); reader.setEncoding("UTF-8"); Document document = reader.read(stream); document.setXMLEncoding("UTF-8"); // get all relatedEntity Elements List<Node> relatedEntities = (metadataRepeatingElementsXpath.get(RELATEDENTITY_REPEATING_ELEMENT_NAME)) .selectNodes(document); // iterate over dataset Elements for (Node relatedEntity : relatedEntities) { // Detatch relatedEntity Element and create new Document with it DefaultDocument doc1 = new DefaultDocument(); doc1.setRootElement((Element) relatedEntity.detach()); // get all hasContact Elements List<Node> hasContacts = (metadataRepeatingElementsXpath.get(HASCONTACT_REPEATING_ELEMENT_NAME)) .selectNodes(doc1); // iterate over hasContact Elements for (Node hasContact : hasContacts) { // Detatch relatedEntity Element and create new Document with it DefaultDocument doc2 = new DefaultDocument(); doc2.setRootElement((Element) hasContact.detach()); // write hasContact elements-of-interest to file fileUtils.writeValuesToFile(hasContactBW, harvestedHasContactElementsOfInterest.values(), doc2, namespaceMap, String.valueOf(getLineNumber())); } // write relatedEntity elements-of-interest to file fileUtils.writeValuesToFile(relatedEntityBW, harvestedRelatedEntityElementsOfInterest.values(), doc1, namespaceMap, String.valueOf(getLineNumber())); setLineNumber(getLineNumber() + 1); } }
From source file:org.jivesoftware.openfire.container.PluginCacheConfigurator.java
License:Open Source License
public void configure(String pluginName) { try {//from w w w .j av a2s. co m SAXReader saxReader = new SAXReader(); saxReader.setEncoding("UTF-8"); Document cacheXml = saxReader.read(configDataStream); List<Node> mappings = cacheXml.selectNodes("/cache-config/cache-mapping"); for (Node mapping : mappings) { registerCache(pluginName, mapping); } } catch (DocumentException e) { Log.error(e.getMessage(), e); } }