List of usage examples for org.dom4j Document addDocType
Document addDocType(String name, String publicId, String systemId);
From source file:org.apache.openmeetings.util.XmlExport.java
License:Apache License
public static Element createRoot(Document document) { document.addDocType("properties", null, "http://java.sun.com/dtd/properties.dtd"); Element root = document.addElement("properties"); return root;//from ww w . j a va 2 s .c o m }
From source file:org.codehaus.aspectwerkz.metadata.AttributeC.java
License:Open Source License
/** * Creates a DOM documents out of the definition. * * @param definition the AspectWerkz definition * @param uuid the UUID for the definition * @return the DOM document//from w w w .java2 s.c om */ public static Document createDocument(final AspectWerkzDefinitionImpl definition, final String uuid) { if (definition == null) throw new IllegalArgumentException("definition can not be null"); Document document = DocumentHelper.createDocument(); document.addDocType("aspectwerkz", "-//AspectWerkz//DTD//EN", "http://aspectwerkz.codehaus.org/dtd/aspectwerkz.dtd"); Element root = document.addElement("aspectwerkz"); Element system = root.addElement("system"); system.addAttribute("id", uuid); handleIntroductionDefinitions(system, definition); handleAdviceDefinitions(system, definition); handleAspectDefinitions(system, definition); return document; }
From source file:org.dentaku.gentaku.cartridge.entity.hibernate.HibernateEntityGenerator.java
License:Apache License
public void touchupOutputDocument(Document outputDocument) throws GenerationException { outputDocument.addDocType("hibernate-mapping", "-//Hibernate/Hibernate Mapping DTD 3.0//EN", "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"); }
From source file:org.dentaku.gentaku.cartridge.entity.jdo.JDOEntityGenerator.java
License:Apache License
public void touchupOutputDocument(Document outputDocument) throws GenerationException { outputDocument.addDocType("jdo", "-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 2.0//EN", "http://java.sun.com/dtd/jdo_2_0.dtd"); }
From source file:org.dom4j.samples.validate.SAXValidatorDemo.java
License:Open Source License
protected void validate(String url, boolean validateOnParse) throws Exception { println("Parsing: " + url + " with validation mode: " + validateOnParse); XMLErrorHandler errorHandler = new XMLErrorHandler(); if (validateOnParse) { // validate as we parse SAXReader reader = new SAXReader(true); reader.setErrorHandler(errorHandler); try {//from w w w . j av a2 s .c o m Document document = reader.read(url); println("Document: " + url + " is valid!"); } catch (DocumentException e) { println("Document: " + url + " is not valid"); println("Exception: " + e); } } else { // parse without validating, then do that later SAXReader reader = new SAXReader(); Document document = reader.read(url); println("Document URI: " + document.getName()); // now lets set a doc type if one isn't set DocumentType docType = document.getDocType(); if (docType == null) { println("Adding an NITF doc type"); document.addDocType("nitf", null, "nitf.dtd"); } // now lets validate try { SAXValidator validator = new SAXValidator(); validator.setErrorHandler(errorHandler); validator.validate(document); println("Document: " + url + " is valid!"); } catch (SAXException e) { println("Document: " + url + " is not valid"); println("Exception: " + e); } } // now lets output any errors as XML Element errors = errorHandler.getErrors(); if (errors.hasContent()) { XMLWriter writer = new XMLWriter(OutputFormat.createPrettyPrint()); writer.write(errors); } }
From source file:org.geolatte.common.automapper.MappingsGenerator.java
License:Open Source License
private Document initializeDocument() { Document doc = DocumentHelper.createDocument(); doc.addDocType("hibernate-mapping", "-//Hibernate/Hibernate Mapping DTD 3.0//EN", "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"); return doc;/*from w ww . j a v a2 s . c om*/ }
From source file:org.jasig.portal.tools.chanpub.UrlChannelPublisher.java
License:Open Source License
public static void publishChannel(Element m) { try {/*from ww w. j a v a 2 s . com*/ RDBMServices.setGetDatasourceFromJndi(false); m.remove(m.attribute("script")); Document d = m.getDocument(); d.addDocType("channel-definition", null, "channelDefinition.dtd"); String xml = d.asXML(); InputStream inpt = new ByteArrayInputStream(xml.getBytes()); ChannelPublisher pub = ChannelPublisher.getCommandLineInstance(); pub.publishChannel(inpt); } catch (Throwable t) { String msg = "Error publishing the channel definition."; throw new RuntimeException(msg, t); } }
From source file:org.mitre.ace2004.callisto.ExportAPF5_0_2.java
License:Open Source License
/** * Open and convert the data at the specified URI, to a new * AWBDocument. Implementations should verify that the URI specified is * absolute. URI's are used due to ambiguities in the URL class. * * @see URI#isAbsolute/* www . j a va2 s.c om*/ * @param doc the data to be exported * @param uri location to save data to * @return true if the export succeded, false otherwise. * @throws IOException on error writing to file. * @throws IllegalArgumentException implementations should throw an * IllegalArgumentException if the uri specified is of an unsupported * scheme, or if the preconditions of that scheme are not met (file: * and http: protocols require the uri be absolute and heirarchal). */ public boolean exportDocument(AWBDocument awbDoc, URI uri) throws IOException { // note that this only happens automatically on export of APF coreferenceRelations(awbDoc); Document xmlDoc = null; try { xmlDoc = DocumentHelper.createDocument(); xmlDoc.addDocType("source_file", "SYSTEM", "apf.v" + APF_VERSION + ".dtd"); String encoding = awbDoc.getEncoding(); // if this document came from import, it will have 'source' (maybe) // and 'uri' specified by the 'source_file' tag. keep them. String source = (String) awbDoc.getClientProperty(IdTracker.DOC_SOURCE); if (source == null) source = "unknown"; URI signalURI = (URI) awbDoc.getClientProperty(IdTracker.DOC_URI); if (signalURI == null) signalURI = awbDoc.getSignalURI(); // relativize with destination URI String path = uri.getRawPath(); URI base = uri.resolve(path.substring(0, path.lastIndexOf('/') + 1)); signalURI = base.relativize(signalURI); // what's the point in versioning by X.0 if every X.y is incompatable? Element root = xmlDoc.addElement("source_file").addAttribute("TYPE", "text") .addAttribute("VERSION", "5.0").addAttribute("SOURCE", source) .addAttribute("URI", signalURI.toString()).addAttribute("ENCODING", encoding); // warning to users reading the xml if (!encoding.equals("UTF-8")) root.addComment( "This document is encoded in 'UTF-8'," + " the /source/ is encoded in '" + encoding + "'"); Element doc = root.addElement("document").addAttribute("DOCID", IdTracker.getDocId(awbDoc)); // don't know the order returned, so make collections HashSet entities = new LinkedHashSet(); HashSet relations = new LinkedHashSet(); HashSet events = new LinkedHashSet(); HashSet quantities = new LinkedHashSet(); Iterator annotIter = awbDoc.getAllAnnotations(); while (annotIter.hasNext()) { AWBAnnotation annot = (AWBAnnotation) annotIter.next(); String type = annot.getAnnotationType().getName(); if (type.equals(ACE2004Task.ENTITY_TYPE_NAME)) entities.add(annot); else if (type.equals(ACE2004Task.QUANTITY_TYPE_NAME)) quantities.add(annot); else if (type.equals(ACE2004Task.RELATION_TYPE_NAME)) relations.add(annot); else if (type.equals(ACE2004Task.EVENT_TYPE_NAME)) events.add(annot); } if (DEBUG > 0) { System.err.println("Entities: " + entities.size()); System.err.println("Quantities: " + quantities.size()); System.err.println("Relations: " + relations.size()); System.err.println("Events: " + events.size()); } // iterate over each Iterator iterator = null; iterator = entities.iterator(); while (iterator.hasNext()) addEntity(doc, awbDoc, (HasSubordinates) iterator.next()); iterator = quantities.iterator(); while (iterator.hasNext()) addQuantity(doc, awbDoc, (HasSubordinates) iterator.next()); iterator = relations.iterator(); while (iterator.hasNext()) addRelation(doc, awbDoc, (HasSubordinates) iterator.next()); iterator = events.iterator(); while (iterator.hasNext()) addEvent(doc, awbDoc, (HasSubordinates) iterator.next()); } catch (Exception t) { t.printStackTrace(); } boolean success = writeAPF(xmlDoc, uri); if (DEBUG > 0) { System.err.println("\nExport succeeded: " + success + "\n"); } return success; }
From source file:org.mitre.ace2004.callisto.ExportAPF5_1_0.java
License:Open Source License
/** * Open and convert the data at the specified URI, to a new * AWBDocument. Implementations should verify that the URI specified is * absolute. URI's are used due to ambiguities in the URL class. * * @see URI#isAbsolute/*from w w w . j av a2 s . co m*/ * @param doc the data to be exported * @param uri location to save data to * @return true if the export succeded, false otherwise. * @throws IOException on error writing to file. * @throws IllegalArgumentException implementations should throw an * IllegalArgumentException if the uri specified is of an unsupported * scheme, or if the preconditions of that scheme are not met (file: * and http: protocols require the uri be absolute and heirarchal). */ public boolean exportDocument(AWBDocument awbDoc, URI uri) throws IOException { // note that this only happens automatically on export of APF coreferenceRelations(awbDoc); Document xmlDoc = null; try { xmlDoc = DocumentHelper.createDocument(); xmlDoc.addDocType("source_file", "SYSTEM", "apf.v" + APF_VERSION + ".dtd"); String encoding = awbDoc.getEncoding(); // if this document came from import, it will have 'source' (maybe) // and 'uri' specified by the 'source_file' tag. keep them. String source = (String) awbDoc.getClientProperty(IdTracker.DOC_SOURCE); if (source == null) source = "unknown"; URI signalURI = (URI) awbDoc.getClientProperty(IdTracker.DOC_URI); if (signalURI == null) signalURI = awbDoc.getSignalURI(); // relativize with destination URI String path = uri.getRawPath(); URI base = uri.resolve(path.substring(0, path.lastIndexOf('/') + 1)); signalURI = base.relativize(signalURI); // Let's find out who the "author" of *this* version of the APF file is: String userSystemName = System.getProperty("user.name"); // what's the point in versioning by X.0 if every X.y is incompatable? Element root = xmlDoc.addElement("source_file").addAttribute("URI", signalURI.toString()) .addAttribute("SOURCE", source).addAttribute("TYPE", "text").addAttribute("VERSION", "5.0") .addAttribute("AUTHOR", userSystemName).addAttribute("ENCODING", encoding); // warning to users reading the xml if (!encoding.equals("UTF-8")) root.addComment( "This document is encoded in 'UTF-8'," + " the /source/ is encoded in '" + encoding + "'"); Element doc = root.addElement("document").addAttribute("DOCID", IdTracker.getDocId(awbDoc)); // don't know the order returned, so make collections HashSet entities = new LinkedHashSet(); HashSet relations = new LinkedHashSet(); HashSet events = new LinkedHashSet(); HashSet quantities = new LinkedHashSet(); HashSet timex2entities = new LinkedHashSet(); Iterator annotIter = awbDoc.getAllAnnotations(); while (annotIter.hasNext()) { AWBAnnotation annot = (AWBAnnotation) annotIter.next(); String type = annot.getAnnotationType().getName(); if (type.equals(ACE2004Task.ENTITY_TYPE_NAME)) entities.add(annot); else if (type.equals(ACE2004Task.QUANTITY_TYPE_NAME)) quantities.add(annot); else if (type.equals(ACE2004Task.TIMEX2_TYPE_NAME)) timex2entities.add(annot); else if (type.equals(ACE2004Task.RELATION_TYPE_NAME)) relations.add(annot); else if (type.equals(ACE2004Task.EVENT_TYPE_NAME)) events.add(annot); } if (DEBUG > 0) { System.err.println("Entities: " + entities.size()); System.err.println("Values: " + quantities.size()); System.err.println("Timex2Entities: " + timex2entities.size()); System.err.println("Relations: " + relations.size()); System.err.println("Events: " + events.size()); } // iterate over each Iterator iterator = null; iterator = entities.iterator(); while (iterator.hasNext()) addEntity(doc, awbDoc, (HasSubordinates) iterator.next()); iterator = quantities.iterator(); while (iterator.hasNext()) addQuantity(doc, awbDoc, (HasSubordinates) iterator.next()); iterator = timex2entities.iterator(); while (iterator.hasNext()) addTimex2(doc, awbDoc, (TextExtentRegion) iterator.next()); iterator = relations.iterator(); while (iterator.hasNext()) addRelation(doc, awbDoc, (HasSubordinates) iterator.next()); iterator = events.iterator(); while (iterator.hasNext()) addEvent(doc, awbDoc, (HasSubordinates) iterator.next()); } catch (Exception t) { t.printStackTrace(); } boolean success = writeAPF(xmlDoc, uri); if (DEBUG > 0) { System.err.println("\nExport succeeded: " + success + "\n"); } return success; }
From source file:org.mitre.ace2004.callisto.ExportAPF5_1_1.java
License:Open Source License
/** * Open and convert the data at the specified URI, to a new * AWBDocument. Implementations should verify that the URI specified is * absolute. URI's are used due to ambiguities in the URL class. * * @see URI#isAbsolute//from ww w. j a v a2 s . c om * @param doc the data to be exported * @param uri location to save data to * @return true if the export succeded, false otherwise. * @throws IOException on error writing to file. * @throws IllegalArgumentException implementations should throw an * IllegalArgumentException if the uri specified is of an unsupported * scheme, or if the preconditions of that scheme are not met (file: * and http: protocols require the uri be absolute and heirarchal). */ public boolean exportDocument(AWBDocument awbDoc, URI uri) throws IOException { // note that this only happens automatically on export of APF coreferenceRelations(awbDoc); Document xmlDoc = null; try { xmlDoc = DocumentHelper.createDocument(); xmlDoc.addDocType("source_file", "SYSTEM", "apf.v" + APF_VERSION + ".dtd"); String encoding = awbDoc.getEncoding(); // if this document came from import, it will have 'source' (maybe) // and 'uri' specified by the 'source_file' tag. keep them. String source = (String) awbDoc.getClientProperty(IdTracker.DOC_SOURCE); if (source == null) source = "unknown"; URI signalURI = (URI) awbDoc.getClientProperty(IdTracker.DOC_URI); if (signalURI == null) signalURI = awbDoc.getSignalURI(); // relativize with destination URI String path = uri.getRawPath(); URI base = uri.resolve(path.substring(0, path.lastIndexOf('/') + 1)); signalURI = base.relativize(signalURI); // Let's find out who the "author" of *this* version of the APF file is: String userSystemName = System.getProperty("user.name"); // what's the point in versioning by X.0 if every X.y is incompatable? Element root = xmlDoc.addElement("source_file").addAttribute("URI", signalURI.toString()) .addAttribute("SOURCE", source).addAttribute("TYPE", "text").addAttribute("VERSION", "5.0") .addAttribute("AUTHOR", userSystemName).addAttribute("ENCODING", encoding); // warning to users reading the xml if (!encoding.equals("UTF-8")) root.addComment( "This document is encoded in 'UTF-8'," + " the /source/ is encoded in '" + encoding + "'"); Element doc = root.addElement("document").addAttribute("DOCID", IdTracker.getDocId(awbDoc)); // don't know the order returned, so make collections HashSet entities = new LinkedHashSet(); HashSet relations = new LinkedHashSet(); HashSet events = new LinkedHashSet(); HashSet quantities = new LinkedHashSet(); HashSet timex2entities = new LinkedHashSet(); Iterator annotIter = awbDoc.getAllAnnotations(); while (annotIter.hasNext()) { AWBAnnotation annot = (AWBAnnotation) annotIter.next(); String type = annot.getAnnotationType().getName(); if (type.equals(ACE2004Task.ENTITY_TYPE_NAME)) entities.add(annot); else if (type.equals(ACE2004Task.QUANTITY_TYPE_NAME)) quantities.add(annot); else if (type.equals(ACE2004Task.TIMEX2_TYPE_NAME)) timex2entities.add(annot); else if (type.equals(ACE2004Task.RELATION_TYPE_NAME)) relations.add(annot); else if (type.equals(ACE2004Task.EVENT_TYPE_NAME)) events.add(annot); } if (DEBUG > 0) { System.err.println("Entities: " + entities.size()); System.err.println("Values: " + quantities.size()); System.err.println("Timex2Entities: " + timex2entities.size()); System.err.println("Relations: " + relations.size()); System.err.println("Events: " + events.size()); } // iterate over each Iterator iterator = null; iterator = entities.iterator(); while (iterator.hasNext()) addEntity(doc, awbDoc, (HasSubordinates) iterator.next()); iterator = quantities.iterator(); while (iterator.hasNext()) addQuantity(doc, awbDoc, (HasSubordinates) iterator.next()); iterator = timex2entities.iterator(); while (iterator.hasNext()) addTimex2(doc, awbDoc, (TextExtentRegion) iterator.next()); iterator = relations.iterator(); while (iterator.hasNext()) addRelation(doc, awbDoc, (HasSubordinates) iterator.next()); iterator = events.iterator(); while (iterator.hasNext()) addEvent(doc, awbDoc, (HasSubordinates) iterator.next()); addExternalResourceDeclarations(doc, awbDoc); } catch (Exception t) { t.printStackTrace(); } boolean success = writeAPF(xmlDoc, uri); if (DEBUG > 0) { System.err.println("\nExport succeeded: " + success + "\n"); } return success; }