List of usage examples for org.dom4j DocumentFactory DocumentFactory
public DocumentFactory()
From source file:org.eclipse.birt.build.GenCaseResult.java
License:Open Source License
private void genReport(String path) { /*/*from www . j av a2 s .c om*/ * Add genDate node to report */ DOMElement testElement = new DOMElement("ReportDate"); Calendar cal = Calendar.getInstance(); SimpleDateFormat currentDate = new SimpleDateFormat("yyyy-MM-dd"); String strDate = currentDate.format(cal.getTime()); testElement.setText(strDate); this.rootElement.add(testElement); DocumentFactory factory = new DocumentFactory(); Document doc = factory.createDocument(rootElement); OutputFormat format = OutputFormat.createPrettyPrint(); try { XMLWriter writer = new XMLWriter(new FileWriter(this.getReportPath(path)), format); writer.write(doc); writer.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.eclipse.birt.build.VersionUpdater.java
License:Open Source License
/** * @author //from w w w . j a va 2 s . c o m * @param folderPath * @param plug_id * @param lastDate * @param dayInpast */ private void genVersionLog(File folderPath, String plug_id, String lastDate, int dayInpast) { // gen the dest file path String parentPath = folderPath.getAbsolutePath(); String fileName = plug_id + "_DayInPast" + ".xml"; String fullName = parentPath + "/" + fileName; File dest = new File(fullName); System.out.println("dest file full path:\t" + fullName); try { //genarate document factory DocumentFactory factory = new DocumentFactory(); //create root element DOMElement rootElement = new DOMElement("plugin"); rootElement.setAttribute("id", plug_id); //add child:lastdate DOMElement dateElement = new DOMElement("LastDate"); dateElement.setText(lastDate); rootElement.add(dateElement); //add child:dayinpast DOMElement dayElement = new DOMElement("DayInPast"); dayElement.setText(Integer.toString(dayInpast)); rootElement.add(dayElement); //gen the doc Document doc = factory.createDocument(rootElement); //PrettyFormat OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(dest), format); writer.write(doc); writer.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:org.hibernate.build.gradle.publish.auth.maven.SettingsXmlCredentialsProvider.java
License:Open Source License
private SAXReader buildSAXReader() { SAXReader saxReader = new SAXReader(new DocumentFactory()); saxReader.setMergeAdjacentText(true); return saxReader; }
From source file:org.jasig.portal.tenants.TemplateDataTenantOperationsListener.java
License:Apache License
@PostConstruct public void setup() throws Exception { templateResources = applicationContext.getResources(TEMPLATE_LOCATION); Map<String, String> nsPrefixes = new HashMap<String, String>(); nsPrefixes.put("dlm", FragmentDefinition.NAMESPACE_URI); DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(nsPrefixes); reader.setDocumentFactory(factory);// ww w . j av a 2s . c o m DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); fac.setNamespaceAware(true); domImpl = fac.newDocumentBuilder().getDOMImplementation(); }
From source file:org.jenkins_ci.update_center.Main.java
License:Open Source License
private SAXReader createXmlReader() { DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(Collections.singletonMap("m", "http://maven.apache.org/POM/4.0.0")); return new SAXReader(factory); }
From source file:org.jvnet.hudson.update_center.Pom.java
License:Open Source License
public Pom(InputStream pomFile, Pom parent) throws IOException, DocumentException { this.parent = parent; DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(Collections.singletonMap("m", "http://maven.apache.org/POM/4.0.0")); this.xmlReader = new SAXReader(factory); this.pom = readPOM(pomFile); }
From source file:org.mitre.ace2004.callisto.config.RNGParser.java
License:Open Source License
public RNGParser() { uris = new HashMap(); uris.put("rng", "http://relaxng.org/ns/structure/1.0"); uris.put("aif", "http://callisto.mitre.org/ns/aif/1.0"); DocumentFactory factory = new DocumentFactory(); factory.setXPathNamespaceURIs(uris); reader = new SAXReader(); reader.setDocumentFactory(factory);//from w w w. ja va2 s .c o m reader.setIncludeExternalDTDDeclarations(false); }
From source file:org.opencms.setup.xml.A_CmsSetupXmlUpdate.java
License:Open Source License
/** * Prepares a new document.<p>/*from w w w .j av a 2 s. com*/ * * @param doc the original document * * @return a new document */ protected Document prepareDoc(Document doc) { Document newDoc = new DocumentFactory().createDocument(); newDoc.addElement(CmsConfigurationManager.N_ROOT); newDoc.setName(doc.getName()); return newDoc; }
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);//from www . j a v a 2 s . c o m // 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; 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; }
From source file:ru.gelin.fictionbook.common.FBDocument.java
License:Open Source License
/** * Constructor from file./*from w w w .jav a 2s . c o m*/ * @param file file with Fiction Book document * @throws FBException if any error occured while reading document, * cause of error is wrapped. */ public FBDocument(File file) throws FBException { factory = new DocumentFactory(); factory.setXPathNamespaceURIs(NS_URIS); //for correct working of XPath for elements if (log.isInfoEnabled()) { log.info("creating document from file " + file); } try { if (file.getName().endsWith(".zip")) { dom = readZip(file); } else if (file.getName().endsWith(".gz")) { dom = readGZip(file); } if (dom == null) { dom = read(file); } prepareXPaths(); } catch (Exception e) { String err = "can't create document from file " + file; log.error(err, e); throw new FBException(err, e); } }