当前位置: 首页>>代码示例>>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;未经允许,请勿转载。