當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLConstants類代碼示例

本文整理匯總了Java中javax.xml.XMLConstants的典型用法代碼示例。如果您正苦於以下問題:Java XMLConstants類的具體用法?Java XMLConstants怎麽用?Java XMLConstants使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XMLConstants類屬於javax.xml包,在下文中一共展示了XMLConstants類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createTransformerFactory

import javax.xml.XMLConstants; //導入依賴的package包/類
/**
 * Returns properly configured (e.g. security features) factory
 * - securityProcessing == is set based on security processing property, default is true
 */
public static TransformerFactory createTransformerFactory(boolean disableSecureProcessing) throws IllegalStateException {
    try {
        TransformerFactory factory = TransformerFactory.newInstance();
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.log(Level.FINE, "TransformerFactory instance: {0}", factory);
        }
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing));
        return factory;
    } catch (TransformerConfigurationException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
        throw new IllegalStateException( ex);
    } catch (AbstractMethodError er) {
        LOGGER.log(Level.SEVERE, null, er);
        throw new IllegalStateException(Messages.INVALID_JAXP_IMPLEMENTATION.format(), er);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:XmlFactory.java

示例2: fromXML

import javax.xml.XMLConstants; //導入依賴的package包/類
@Override
public T fromXML(String xml) {

    try {
        JAXBContext context = JAXBContext.newInstance(type);
        Unmarshaller u = context.createUnmarshaller();

        if(schemaLocation != null) {
            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

            StreamSource source = new StreamSource(getClass().getResourceAsStream(schemaLocation));
            Schema schema = schemaFactory.newSchema(source);
            u.setSchema(schema);
        }

        StringReader reader = new StringReader(xml);
        T obj = (T) u.unmarshal(reader);

        return obj;
    } catch (Exception e) {
        System.out.println("ERROR: "+e.toString());
        return null;
    }
}
 
開發者ID:arcuri82,項目名稱:testing_security_development_enterprise_systems,代碼行數:25,代碼來源:ConverterImpl.java

示例3: validateXML

import javax.xml.XMLConstants; //導入依賴的package包/類
private boolean validateXML(InputStream xml, InputStream xsd){
 try
 {
	 SchemaFactory factory = 
			 SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
	 javax.xml.validation.Schema schema = factory.newSchema(new StreamSource(xsd));
	 Validator validator = schema.newValidator();

	 validator.validate(new StreamSource(xml));
	 return true;
 }
 catch( SAXException| IOException ex)
 {
	 //MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", Messages.IMPORT_XML_FORMAT_ERROR + "-\n" + ex.getMessage());
	 MessageBox dialog = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_ERROR | SWT.OK);
	 dialog.setText(Messages.ERROR);
	 dialog.setMessage(Messages.IMPORT_XML_FORMAT_ERROR + "-\n" + ex.getMessage());
	 logger.error(Messages.IMPORT_XML_FORMAT_ERROR);
	 return false;
 }
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:22,代碼來源:ELTSchemaGridWidget.java

示例4: testSAXParserFactoryInWhiteList

import javax.xml.XMLConstants; //導入依賴的package包/類
/**
 * Test we have set features the way we expect as defaults.
 */
public void testSAXParserFactoryInWhiteList() throws Throwable
{
    // Using constructor rather than the service locator and then using the helper to configure it.
    SAXParserFactory spf = new SAXParserFactoryImpl();
    FactoryHelper factoryHelper = new FactoryHelper();
    List<String> whiteListClasses = Collections.singletonList(getClass().getName());
    factoryHelper.configureFactory(spf, FactoryHelper.DEFAULT_FEATURES_TO_ENABLE,
            FactoryHelper.DEFAULT_FEATURES_TO_DISABLE,
            whiteListClasses);

    assertFalse(spf.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
    assertFalse(spf.getFeature(FactoryHelper.FEATURE_DISALLOW_DOCTYPE));

    assertTrue(spf.getFeature(FactoryHelper.FEATURE_EXTERNAL_GENERAL_ENTITIES));
    assertTrue(spf.getFeature(FactoryHelper.FEATURE_EXTERNAL_PARAMETER_ENTITIES));
    assertTrue(spf.getFeature(FactoryHelper.FEATURE_USE_ENTITY_RESOLVER2));
    assertTrue(spf.getFeature(FactoryHelper.FEATURE_LOAD_EXTERNAL_DTD));

    assertFalse(spf.isXIncludeAware()); // false is the default so is same as the non whitelist test
}
 
開發者ID:Alfresco,項目名稱:alfresco-xml-factory,代碼行數:24,代碼來源:AppTest.java

示例5: newSAXParserFactory

import javax.xml.XMLConstants; //導入依賴的package包/類
public static SAXParserFactory newSAXParserFactory(boolean disableSecurity) {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    String featureToSet = XMLConstants.FEATURE_SECURE_PROCESSING;
    try {
        boolean securityOn = !xmlSecurityDisabled(disableSecurity);
        factory.setFeature(featureToSet, securityOn);
        factory.setNamespaceAware(true);
        if (securityOn) {
            featureToSet = DISALLOW_DOCTYPE_DECL;
            factory.setFeature(featureToSet, true);
            featureToSet = EXTERNAL_GE;
            factory.setFeature(featureToSet, false);
            featureToSet = EXTERNAL_PE;
            factory.setFeature(featureToSet, false);
            featureToSet = LOAD_EXTERNAL_DTD;
            factory.setFeature(featureToSet, false);
        }
    } catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) {
        LOGGER.log(Level.WARNING, "Factory [{0}] doesn't support "+featureToSet+" feature!", new Object[]{factory.getClass().getName()});
    }
    return factory;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:XmlUtil.java

示例6: main

import javax.xml.XMLConstants; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    try{
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(new File(System.getProperty("test.src", "."), XSDFILE));
    } catch (SAXException e) {
        throw new RuntimeException(e.getMessage());
    }


}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:XPathWhiteSpaceTest.java

示例7: processNamespaceAttribute

import javax.xml.XMLConstants; //導入依賴的package包/類
private void processNamespaceAttribute(String prefix, String uri) throws SAXException {
    _contentHandler.startPrefixMapping(prefix, uri);

    if (_namespacePrefixesFeature) {
        // Add the namespace delcaration as an attribute
        if (prefix != "") {
            _attributes.addAttributeWithQName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix,
                    getQName(XMLConstants.XMLNS_ATTRIBUTE, prefix),
                    "CDATA", uri);
        } else {
            _attributes.addAttributeWithQName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE,
                    XMLConstants.XMLNS_ATTRIBUTE,
                    "CDATA", uri);
        }
    }

    cacheNamespacePrefix(prefix);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:SAXBufferProcessor.java

示例8: resolve

import javax.xml.XMLConstants; //導入依賴的package包/類
@Override
public <T extends NamedReferenceable>
        T resolve(String namespace, String localName, Class<T> type) 
{
    if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(namespace) &&
        XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(getSchema().getTargetNamespace())) {
        return resolveImpl(namespace, localName, type);
    }
    
    if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(namespace)) {
        SchemaModel sm = SchemaModelFactory.getDefault().getPrimitiveTypesModel();
        return sm.findByNameAndType(localName, type);
    }
    
    return resolveImpl(namespace, localName, type);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:SchemaModelImpl.java

示例9: main

import javax.xml.XMLConstants; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(xsd.getBytes()));
    StreamSource xsdSource = new StreamSource(reader);

    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    schemaFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false);
    Schema schema = null;
    schema = schemaFactory.newSchema(xsdSource);

    Validator validator = schema.newValidator();

    if (validator.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)) {
        throw new RuntimeException("Feature set on the factory is not inherited!");
    }

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:FeaturePropagationTest.java

示例10: engineCanonicalize

import javax.xml.XMLConstants; //導入依賴的package包/類
/**
 * Method canonicalize
 *
 * @param inputBytes
 * @return the c14n bytes.
 *
 * @throws CanonicalizationException
 * @throws java.io.IOException
 * @throws javax.xml.parsers.ParserConfigurationException
 * @throws org.xml.sax.SAXException
 */
public byte[] engineCanonicalize(byte[] inputBytes)
    throws javax.xml.parsers.ParserConfigurationException, java.io.IOException,
    org.xml.sax.SAXException, CanonicalizationException {

    java.io.InputStream bais = new ByteArrayInputStream(inputBytes);
    InputSource in = new InputSource(bais);
    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
    dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);

    // needs to validate for ID attribute normalization
    dfactory.setNamespaceAware(true);

    DocumentBuilder db = dfactory.newDocumentBuilder();

    Document document = db.parse(in);
    return this.engineCanonicalizeSubTree(document);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:29,代碼來源:CanonicalizerSpi.java

示例11: run

import javax.xml.XMLConstants; //導入依賴的package包/類
public void run() {
    Set<String> declaredPrefixes = new HashSet<String>();
    for( Node n=node; n!=null && n.getNodeType()==Node.ELEMENT_NODE; n=n.getParentNode() ) {
        NamedNodeMap atts = n.getAttributes();
        if(atts==null)      continue; // broken DOM. but be graceful.
        for( int i=0; i<atts.getLength(); i++ ) {
            Attr a = (Attr)atts.item(i);
            String nsUri = a.getNamespaceURI();
            if(nsUri==null || !nsUri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI))
                continue;   // not a namespace declaration
            String prefix = a.getLocalName();
            if(prefix==null)
                continue;   // broken DOM. skip to be safe
            if(prefix.equals("xmlns")) {
                prefix = "";
            }
            String value = a.getValue();
            if(value==null)
                continue;   // broken DOM. skip to be safe
            if(declaredPrefixes.add(prefix)) {
                serializer.addInscopeBinding(value,prefix);
            }
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:DomPostInitAction.java

示例12: writeAttributeWithPrefix

import javax.xml.XMLConstants; //導入依賴的package包/類
private void writeAttributeWithPrefix(String prefix, String localName,
    String value) throws IOException {
    fWriter.write(SPACE);

    if ((prefix != null) && (prefix != XMLConstants.DEFAULT_NS_PREFIX)) {
        fWriter.write(prefix);
        fWriter.write(":");
    }

    fWriter.write(localName);
    fWriter.write("=\"");
    writeXMLContent(value,
            true,   // true = escapeChars
            true);  // true = escapeDoubleQuotes
    fWriter.write("\"");
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:XMLStreamWriterImpl.java

示例13: validation

import javax.xml.XMLConstants; //導入依賴的package包/類
/**
	 * 利用xsd驗證xml
	 * @param xsdFile xsdFile
	 * @param xmlInput xmlInput
	 * @throws SAXException  SAXException
	 * @throws IOException IOException
	 */
	public static void validation(String xsdFile, InputStream xmlInput) throws SAXException, IOException
	{
		SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
		URL xsdURL = Validation.class.getClassLoader().getResource(xsdFile);
		if(xsdURL != null)
		{
			Schema schema = factory.newSchema(xsdURL);
			Validator validator = schema.newValidator();
//			validator.setErrorHandler(new AutoErrorHandler());

			Source source = new StreamSource(xmlInput);
			
			try(OutputStream resultOut = new FileOutputStream(new File(PathUtil.getRootDir(), xsdFile + ".xml")))
			{
				Result result = new StreamResult(resultOut);
				validator.validate(source, result);
			}
		}
		else
		{
			throw new FileNotFoundException(String.format("can not found xsd file [%s] from classpath.", xsdFile));
		}
	}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:31,代碼來源:Validation.java

示例14: deserialiseObject

import javax.xml.XMLConstants; //導入依賴的package包/類
/** Attempt to construct the specified object from this XML string
 * @param xml the XML string to parse
 * @param xsdFile the name of the XSD schema that defines the object
 * @param objclass the class of the object requested
 * @return if successful, an instance of class objclass that captures the data in the XML string
 */
static public Object deserialiseObject(String xml, String xsdFile, Class<?> objclass) throws JAXBException, SAXException, XMLStreamException
{
    Object obj = null;
    JAXBContext jaxbContext = getJAXBContext(objclass);
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    final String schemaResourceFilename = new String(xsdFile);
    URL schemaURL = MalmoMod.class.getClassLoader().getResource(schemaResourceFilename);
    Schema schema = schemaFactory.newSchema(schemaURL);
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
    jaxbUnmarshaller.setSchema(schema);

    StringReader stringReader = new StringReader(xml);

    XMLInputFactory xif = XMLInputFactory.newFactory();
    xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
    xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
    XMLStreamReader XMLreader = xif.createXMLStreamReader(stringReader);

    obj = jaxbUnmarshaller.unmarshal(XMLreader);
    return obj;
}
 
開發者ID:Yarichi,項目名稱:Proyecto-DASI,代碼行數:28,代碼來源:SchemaHelper.java

示例15: buildNamespaceDeclaration

import javax.xml.XMLConstants; //導入依賴的package包/類
public static String buildNamespaceDeclaration(final Document xml)
{
   final Element docEl = xml.getDocumentElement();
   final NamedNodeMap attributes = docEl.getAttributes();
   final StringBuilder result = new StringBuilder();
   for (int i = 0; i < attributes.getLength(); i++)
   {
      final Node a = attributes.item(i);
      if (a.getNodeName().startsWith(XMLConstants.XMLNS_ATTRIBUTE))
      {
         final String prefix = a.getNodeName().substring((XMLConstants.XMLNS_ATTRIBUTE + ":").length());
         final String uri = a.getNodeValue();
         if (result.length() != 0)
         {
            result.append(",\n");
         }
         result.append("\"").append(prefix).append("\":\"").append(uri).append("\"");
      }
   }
   return "<#ftl ns_prefixes={\n" + result.toString() + "}>\n";
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:22,代碼來源:StandardRenditionLocationResolverImpl.java


注:本文中的javax.xml.XMLConstants類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。