public void configure(String pluginName) { try { 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); } }
private void parse() { if (!parsed) { parsed = true; try { document = readDocument(getOriginalInputStream(), getName(), true); } catch (DocumentException e) { log.warn("Not a valid XML doc: {}, source={},\n{}", new Object[] { getName(), originalSource, e.getMessage() }); document = null; } } }
private void parse() { if (!parsed) { parsed = true; try { document = readDocument(getOriginalInputStream(), getName(), true); } catch (DocumentException e) { log.warn("Not a valid XML doc: {}, source={},\n{}", new Object[] { getName(), originalSource, e.getMessage() }); document = null; } } }
private void parse() { if (!parsed) { parsed = true; try { document = readDocument(getOriginalInputStream(), getName(), true); } catch (DocumentException e) { log.warn("Not a valid XML doc: {}, source={},\n{}", new Object[] { getName(), originalSource, e.getMessage() }); document = null; } } }
/** {@inheritDoc} */ @Override public Document convert(String source) { try { return DocumentHelper.parseText(source); } catch (DocumentException e) { throw new IllegalArgumentException("Failed to parse xml " + source + ", cause: " + e.getMessage(), e); } }
/** {@inheritDoc} */ @Override public Element convert(String source) { try { return DocumentHelper.parseText(source).getRootElement(); } catch (DocumentException e) { throw new IllegalArgumentException("Failed to parse xml " + source + ", cause: " + e.getMessage(), e); } }
public static Element fromString(final String str) { if (StringUtils.isBlank(str) == true) { return null; } try { final Document document = DocumentHelper.parseText(str); return document.getRootElement(); } catch (final DocumentException ex) { log.error("Exception encountered " + ex.getMessage()); } return null; }
public static Document string2xml(String xmlStr) { // SAXReader saxReader = new SAXReader(); Document xmlDoc = null; try { // InputStream in = new ByteArrayInputStream(xmlStr.getBytes()); // InputStreamReader isReader = new InputStreamReader(in, "GBK"); // xmlDoc = saxReader.read(isReader); xmlDoc = DocumentHelper.parseText(xmlStr); } catch (DocumentException e) { logger.error(e.getMessage(),e); } // } catch (UnsupportedEncodingException e) { // logger.error(e.getMessage(),e.getCause()); // } return xmlDoc; }
private Element loadXml(String fileName) { Element element = (Element) INCLUDED.get(fileName); if (element != null) return element; String content = read(fileName); SAXReader reader = new SAXReader(); StringReader stream = new StringReader(content); try { Element root = reader.read(stream).getRootElement(); INCLUDED.put(fileName, root); return root; } catch (DocumentException e) { logger.error("读取include指令指定的文件失败", e); throw new RuntimeException(e.getMessage(), e); } }
private static Document loadXML(InputStream in) throws IOException { try { // the SAXReader is closing the stream so that we need to copy the // content somewhere ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(in, baos); return new SAXReader().read(new ByteArrayInputStream(baos.toByteArray())); } catch (DocumentException e) { IOException ioe = new IOException("Failed to read log entry " + ": " + e.getMessage()); ioe.setStackTrace(e.getStackTrace()); throw ioe; } }
@POST @Path("/toEditLogback/{workerId}") public Map<String, String> toEditLogback(@PathParam("workerId") String workerId) throws Throwable { logger.info("Receive a request to edit logback.xml, with workerId " + workerId); String path = System.getProperty("logback.configurationFile"); SAXReader reader = new SAXReader(); Map<String, String> result = new HashMap<>(); try { Document document = reader.read(new File(path)); result.put("content", document.asXML()); return result; } catch (DocumentException e) { logger.info("reading logback.xml error:", e); result.put("content", e.getMessage()); } return result; }
private static Document loadXML(File file) throws IOException { BufferedInputStream in = null; try { in = new BufferedInputStream(new FileInputStream(file)); return new SAXReader().read(in); } catch (DocumentException e) { IOException ioe = new IOException("Failed to read file document " + file + ": " + e.getMessage()); ioe.setStackTrace(e.getStackTrace()); throw ioe; } finally { if (in != null) { in.close(); } } }
public static Object xmlStringToObject(String xmlString){ try { Document doc = DocumentHelper.parseText(xmlString); return elementToObject(doc.getRootElement()); } catch (DocumentException e) { logger.error(e.getMessage(),e);//e.printStackTrace(); return null; } } }
public static Map<String, Object> xmlStringToJSONObject(String xmlString){ try { Document doc = DocumentHelper.parseText(xmlString); return elementToJSONObject(doc.getRootElement()); } catch (DocumentException e) { logger.error(e.getMessage(),e);//e.printStackTrace(); return null; } }
@SuppressWarnings("unchecked") void parse(String xml) { try { Document document = DocumentHelper.parseText(xml); Element rootElement = document.getRootElement(); Iterator<Element> elementIterator = rootElement.elementIterator("persistence-unit"); while (elementIterator.hasNext()) { parsePersistentUnit(elementIterator.next()); } } catch (DocumentException e) { throw new RuntimeException(e.getMessage()); } }
public void configure(String pluginName) { try { 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); } }
public Object load(InputStream istream) throws ConfigurationException { try { return loadDocument(istream); } catch (DocumentException e) { throw new ConfigurationException("Failed to load Xml doc: " + e.getMessage(), e); } }
public Object load(InputStream is) throws ConfigurationException { try { loadDocument(is); } catch (DocumentException e) { throw new ConfigurationException("Failed to parse config file: " + e.getMessage(), e); } return null; }
private void parse() { if (!parsed) { parsed = true; try { document = readDocument(getOriginalInputStream(), getName(), true); } catch (DocumentException e) { log.warn("Not a valid XML doc: {}, source={},\n{}", new Object[] { getName(), originalSource, e.getMessage() }); document = null; } } }
@Override protected void installServerXML() throws InstallationFailedException { try { File distServerXML = new File(getConf(), "server.xml"); TomcatServerXML serverXML = new TomcatServerXML(distServerXML, getOptions()); serverXML.update(); serverXML.write(distServerXML.getAbsolutePath()); } catch (IOException e) { throw new InstallationFailedException(e.getMessage(), e); } catch (DocumentException e) { throw new InstallationFailedException(e.getMessage(), e); } }