List of usage examples for org.dom4j DocumentType getPublicID
String getPublicID();
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * dtd// w w w . ja va2 s .c om * * @param document * * @param dtdPublicId * dtd * @return boolean true,false */ public static boolean checkDocumentType(Document document, String dtdPublicId) { DocumentType documentType = document.getDocType(); if (documentType != null) { String publicId = documentType.getPublicID(); return publicId != null && publicId.equals(dtdPublicId); } return true; }
From source file:com.cladonia.xml.ExchangerDocument.java
License:Open Source License
public URL checkSchemaLocation() throws IOException { if (DEBUG)/*from w w w . j a v a 2 s . c o m*/ System.out.println("ExchangerDocument.checkSchemaLocation()"); if (!isError()) { int type = -1; String schemaLocation = null; URL baseURL = getURL(); if (grammar != null && grammar.useExternal() && grammar.getLocation() != null) { schemaLocation = grammar.getLocation(); type = grammar.getType(); } else { DocumentType docType = document.getDocType(); if (docType != null) { schemaLocation = XMLUtilities.resolve(docType.getPublicID(), docType.getSystemID()); type = XMLGrammar.TYPE_DTD; if (schemaLocation == null) { schemaLocation = docType.getSystemID(); } // no system id in the doctype, maybe internal DTD??? if (schemaLocation == null) { return null; } } if (schemaLocation == null) { schemaLocation = getRoot().getAttribute("schemaLocation"); if (schemaLocation != null) { StringTokenizer tokenizer = new StringTokenizer(schemaLocation); if (tokenizer.countTokens() > 1) { String namespace = tokenizer.nextToken(); // discard first token, it is a namespace... schemaLocation = schemaLocation.substring(namespace.length()).trim(); //schemaLocation = tokenizer.nextToken(); } //else { //schemaLocation = tokenizer.nextToken(); //} } type = XMLGrammar.TYPE_XSD; } if (schemaLocation == null) { schemaLocation = getRoot().getAttribute("noNamespaceSchemaLocation"); type = XMLGrammar.TYPE_XSD; } } if (DEBUG) System.out.println("schemaLocation: " + schemaLocation); if (schemaLocation == null) { throw new IOException("No validation schema location has been defined for this document."); } URL url = null; try { if (baseURL != null) { url = new URL(baseURL, schemaLocation); } else { url = new URL(schemaLocation); } } catch (Exception e) { url = XngrURLUtilities.getURLFromFile(new File(schemaLocation)); } if (DEBUG) System.out.println("url: " + url.toString()); InputStream stream = null; try { stream = url.openStream(); return url; } catch (IOException e) { String message = null; if (type == XMLGrammar.TYPE_DTD) { message = "No valid DTD location has been defined for this document."; } else if (type == XMLGrammar.TYPE_XSD) { message = "No valid Schema location has been defined for this document."; } else if (type == XMLGrammar.TYPE_RNG) { message = "No valid RelaxNG location has been defined for this document."; } else if (type == XMLGrammar.TYPE_RNC) { message = "No valid RelaxNG location has been defined for this document."; } else if (type == XMLGrammar.TYPE_NRL) { message = "No valid NRL location has been defined for this document."; } throw new IOException(message); } finally { if (stream != null) { stream.close(); } } } return null; }
From source file:com.cladonia.xml.ExchangerDocument.java
License:Open Source License
public String getPublicID() { DocumentType docType = document.getDocType(); if (docType != null) { return docType.getPublicID(); }// www . j av a2s.co m return null; }
From source file:com.cladonia.xml.ExchangerDocument.java
License:Open Source License
public String getSystemID() { DocumentType docType = document.getDocType(); if (docType != null) { String systemID = XMLUtilities.resolve(docType.getPublicID(), docType.getSystemID()); if (systemID == null) { systemID = docType.getSystemID(); }//from w w w.j a v a 2 s . co m return systemID; } return null; }
From source file:com.cladonia.xngreditor.grammar.GrammarProperties.java
License:Open Source License
/** * Constructor for the grammar properties. * * @param element the element that contains the properties, * for the editor.// w w w . j ava2s. c o m */ public GrammarProperties(ConfigurationProperties props, ExchangerDocument document) { super(new XElement(GRAMMAR_PROPERTIES)); this.properties = props; if (document != null) { String name = document.getName(); int dotPos = name.lastIndexOf('.'); if (dotPos != -1) { setExtensions(name.substring(dotPos + 1, name.length())); } if (!document.isError()) { XElement root = document.getRoot(); if (root != null) { setRootElementName(root.getName()); setNamespace(root.getNamespaceURI()); setNamespacePrefix(root.getNamespacePrefix()); } List namespaces = root.additionalNamespaces(); for (int i = 0; i < namespaces.size(); i++) { Namespace namespace = (Namespace) namespaces.get(i); addNamespace(new NamespaceProperties(namespace.getURI(), namespace.getPrefix())); } DocumentType docType = document.getDocument().getDocType(); if (docType != null) { setPublicID(docType.getPublicID()); setSystemID(docType.getSystemID()); setValidationLocation(docType.getSystemID()); setUseXMLValidationLocation(true); addTagCompletion(new TagCompletionProperties(docType.getSystemID(), XMLGrammar.TYPE_DTD)); // setTemplateLocation( docType.getSystemID()); // setTemplateGrammar( XMLGrammar.TYPE_DTD); setValidationGrammar(XMLGrammar.TYPE_DTD); } else { String location = root.getAttribute("schemaLocation"); if (location == null) { location = root.getAttribute("noNamespaceSchemaLocation"); } if (location != null) { StringTokenizer tokenizer = new StringTokenizer(location, " \t\n\r\f"); String targetURI = null; // if there is only one token than use this as the uri if (tokenizer.hasMoreTokens()) { targetURI = tokenizer.nextToken(); } // there is more than one token, use this token as the uri if (tokenizer.hasMoreTokens()) { targetURI = tokenizer.nextToken(); } setValidationLocation(targetURI); addTagCompletion(new TagCompletionProperties(targetURI, XMLGrammar.TYPE_XSD)); setUseXMLValidationLocation(true); setValidationGrammar(XMLGrammar.TYPE_XSD); } } setDescription(getRootElementName()); } else { setDescription(getExtensions()); } } }
From source file:com.cladonia.xngreditor.XMLDoctypeDialog.java
License:Open Source License
/** * Sets the values diaplayed by the dialog, plus what should be enabled\disabled *//*from w ww . ja v a 2 s . c om*/ private void setCurrentValues() { XDocument xdoc = document.getDocument(); DocumentType dt = xdoc.getDocType(); if (dt == null) { // set the defaults String name = xdoc.getRootElement().getName(); nameField.setText(name); // set the type to be internal typeField.setSelectedIndex(2); publicField.setText(""); publicField.setEnabled(false); publicLabel.setEnabled(false); systemField.setText(""); systemField.setEnabled(false); systemLabel.setEnabled(false); inputLocationButton.setEnabled(false); } else { String name = dt.getElementName(); nameField.setText(name); String publicId = dt.getPublicID(); if (publicId != null) { typeField.setSelectedIndex(1); publicField.setText(publicId); publicField.setEnabled(true); publicLabel.setEnabled(true); systemField.setText(dt.getSystemID()); systemField.setEnabled(true); systemLabel.setEnabled(true); inputLocationButton.setEnabled(true); } else { publicField.setText(""); publicField.setEnabled(false); publicLabel.setEnabled(false); String systemId = dt.getSystemID(); if (systemId != null) { systemField.setText(systemId); systemField.setEnabled(true); systemLabel.setEnabled(true); typeField.setSelectedIndex(0); inputLocationButton.setEnabled(true); } else { systemField.setText(""); systemField.setEnabled(false); systemLabel.setEnabled(false); typeField.setSelectedIndex(2); inputLocationButton.setEnabled(false); } } } }
From source file:freemarker.ext.xml._Dom4jNavigator.java
License:Apache License
void getAttributes(Object node, String localName, String namespaceUri, List result) { if (node instanceof Element) { Element e = (Element) node; if (localName == null) { result.addAll(e.attributes()); } else {//from w w w . j av a2 s .c om Attribute attr = e .attribute(e.getQName().getDocumentFactory().createQName(localName, "", namespaceUri)); if (attr != null) { result.add(attr); } } } else if (node instanceof ProcessingInstruction) { ProcessingInstruction pi = (ProcessingInstruction) node; if ("target".equals(localName)) { result.add(new DefaultAttribute("target", pi.getTarget())); } else if ("data".equals(localName)) { result.add(new DefaultAttribute("data", pi.getText())); } else { result.add(new DefaultAttribute(localName, pi.getValue(localName))); } } else if (node instanceof DocumentType) { DocumentType doctype = (DocumentType) node; if ("publicId".equals(localName)) { result.add(new DefaultAttribute("publicId", doctype.getPublicID())); } else if ("systemId".equals(localName)) { result.add(new DefaultAttribute("systemId", doctype.getSystemID())); } else if ("elementName".equals(localName)) { result.add(new DefaultAttribute("elementName", doctype.getElementName())); } } }
From source file:org.jboss.mx.metadata.XMLMetaData.java
License:Open Source License
/** * Constructs the Model MBean metadata. This implementation reads the * document type definition from the beginning of the XML file and picks * a corresponding XML builder based on the schema name. In case no * document type is defined the latest schema builder for this JBossMX * release is used. <p>/*from w w w.j a va2 s. c om*/ * * The SAX parser implementation is selected by default based on JAXP * configuration. If you want to use JAXP to select the parser, you can * set the system property <tt>"javax.xml.parsers.SAXParserFactory"</tt>. * For example, to use Xerces you might define: <br><pre> * * java -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl ... * * </pre> * * In case you can't or don't want to use JAXP to configure the SAX parser * implementation you can override the SAX parser implementation by setting * an MBean descriptor field {@link XMBeanConstants#SAX_PARSER} to the * parser class string value. * * @return initialized MBean info * @throws NotCompliantMBeanException if there were errors building the * MBean info from the given XML file. */ public MBeanInfo build() throws NotCompliantMBeanException { try { int version = NO_VERSION; if (versionString == null) { // by default, let JAXP pick the SAX parser SAXReader reader = new SAXReader(); // check if user wants to override the SAX parser property if (properties.get(SAX_PARSER) != null) { try { reader.setXMLReaderClassName(getStringProperty(SAX_PARSER)); } catch (SAXException e) { //Should log and ignore, I guess } // end of try-catch } // by default we validate reader.setValidation(true); // the user can override the validation by setting the VALIDATE property try { boolean validate = getBooleanProperty(XML_VALIDATION); reader.setValidation(validate); } catch (IllegalPropertyException e) { // FIXME: log the exception (warning) // fall through, use the default value } //supply it with our dtd locally. reader.setEntityResolver(new JBossEntityResolver()); // get the element and start parsing... Document doc = reader.read(url); element = doc.getRootElement(); DocumentType type = doc.getDocType(); version = validateVersionString(type.getPublicID()); if (version == NO_VERSION) { version = validateVersionString(type.getSystemID()); } // end of if () } else { version = validateVersionString(versionString); } // end of else if (element == null) { throw new IllegalStateException("No element supplied with explict version!"); } // These are the known schemas for us. Pick the correct one based on // schema or default to the latest.docURL.endsWith(JBOSSMX_XMBEAN_DTD_1_0) if (version == JBOSS_XMBEAN_1_0 || version == JBOSS_XMBEAN_1_1 || version == JBOSS_XMBEAN_1_2) { // jboss_xmbean_1_0.dtd is the only implemented useful xmbean return new JBossXMBean10(mmbClassName, resourceClassName, element, properties).build(); } else { throw new NotCompliantMBeanException("Unknown xmbean type " + versionString); } // end of else } catch (DocumentException e) { throw new JBossNotCompliantMBeanException("Error parsing the XML file, from XMLMetaData: ", e); } }
From source file:org.orbeon.oxf.processor.tamino.dom4j.TDOM4JXMLOutputter.java
License:Open Source License
/** * <p>//from w w w . j a v a2 s . c o m * This will write the DOCTYPE declaration if one exists. * </p> * * @param doc <code>Document</code> whose declaration to write. * @param out <code>Writer</code> to write to. */ protected void printDocType(DocumentType docType, Writer out) throws IOException { if (docType == null) { return; } String publicID = docType.getPublicID(); String systemID = docType.getSystemID(); boolean hasPublic = false; out.write("<!DOCTYPE "); out.write(docType.getElementName()); if ((publicID != null) && (!publicID.equals(""))) { out.write(" PUBLIC \""); out.write(publicID); out.write("\""); hasPublic = true; } if ((systemID != null) && (!systemID.equals(""))) { if (!hasPublic) { out.write(" SYSTEM"); } out.write(" \""); out.write(systemID); out.write("\""); } out.write(">"); maybePrintln(out); }
From source file:org.zenonpagetemplates.twoPhasesImpl.DocType.java
License:Open Source License
static public DocType generateDocTypeFromDOM4jDocument(Document document) { DocumentType documentType = document.getDocType(); if (documentType == null) { return null; }/*from ww w . j ava 2s . c o m*/ return new DocType(documentType.getName(), documentType.getPublicID(), documentType.getSystemID()); }