当前位置: 首页>>代码示例>>Java>>正文


Java DocumentBuilderFactory.setExpandEntityReferences方法代码示例

本文整理汇总了Java中javax.xml.parsers.DocumentBuilderFactory.setExpandEntityReferences方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentBuilderFactory.setExpandEntityReferences方法的具体用法?Java DocumentBuilderFactory.setExpandEntityReferences怎么用?Java DocumentBuilderFactory.setExpandEntityReferences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.parsers.DocumentBuilderFactory的用法示例。


在下文中一共展示了DocumentBuilderFactory.setExpandEntityReferences方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: unsafeManualConfig3

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public static void unsafeManualConfig3() throws ParserConfigurationException, IOException, SAXException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setFeature("http://xml.org/sax/features/external-general-entities",true);
    dbf.setFeature("http://xml.org/sax/features/external-parameter-entities",true);
    //dbf.setXIncludeAware(false);
    dbf.setExpandEntityReferences(false);
    DocumentBuilder db = dbf.newDocumentBuilder();

    Document doc = db.parse(getInputFile());
    print(doc);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:12,代码来源:DocumentBuilderSafeProperty.java

示例2: setFeature

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
private void setFeature(DocumentBuilderFactory factory, String feature, boolean enable)
{
    try
    {
        if (ADDITIONAL_FEATURE_X_INCLUDE_AWARE.equals(feature))
        {
            factory.setXIncludeAware(enable);
        }
        else if (ADDITIONAL_FEATURE_EXPAND_ENTITY_REFERENCES.equals(feature))
        {
            factory.setExpandEntityReferences(enable);
        }
        else
        {
            factory.setFeature(feature, enable);
        }
        debug(debugCounter+" DocumentBuilderFactory "+feature+" "+enable);
    }
    catch (ParserConfigurationException pce)
    {
        logConfigurationFailure(factory.getClass().getName(), feature, pce);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-xml-factory,代码行数:24,代码来源:FactoryHelper.java

示例3: parse

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public static Flag parse(String name, InputStream in) throws IOException {
	try {
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		factory.setValidating(true); // make sure the XML is valid
		factory.setExpandEntityReferences(false); // don't allow custom entities
		DocumentBuilder builder = factory.newDocumentBuilder();
		builder.setEntityResolver(new KVXXEntityResolver());
		builder.setErrorHandler(new KVXXErrorHandler(name));
		Document document = builder.parse(new InputSource(in));
		return parseDocument(document);
	} catch (ParserConfigurationException pce) {
		throw new IOException(pce);
	} catch (SAXException saxe) {
		throw new IOException(saxe);
	}
}
 
开发者ID:kreativekorp,项目名称:vexillo,代码行数:17,代码来源:FlagParser.java

示例4: getDocumentBuilder

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Return JAXP document builder instance.
 */
protected DocumentBuilder getDocumentBuilder()
    throws ServletException {
    DocumentBuilder documentBuilder = null;
    DocumentBuilderFactory documentBuilderFactory = null;
    try {
        documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setNamespaceAware(true);
        documentBuilderFactory.setExpandEntityReferences(false);
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
        documentBuilder.setEntityResolver(
                new WebdavResolver(this.getServletContext()));
    } catch(ParserConfigurationException e) {
        throw new ServletException
            (sm.getString("webdavservlet.jaxpfailed"));
    }
    return documentBuilder;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:21,代码来源:WebdavServlet.java

示例5: initializePool

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Initializes the pool with a new set of configuration options.
 * 
 * @throws XMLParserException thrown if there is a problem initialzing the pool
 */
protected synchronized void initializePool() throws XMLParserException {
    if (!dirtyBuilderConfiguration) {
        // in case the pool was initialized by some other thread
        return;
    }

    DocumentBuilderFactory newFactory = DocumentBuilderFactory.newInstance();
    setAttributes(newFactory, builderAttributes);
    setFeatures(newFactory, builderFeatures);
    newFactory.setCoalescing(coalescing);
    newFactory.setExpandEntityReferences(expandEntityReferences);
    newFactory.setIgnoringComments(ignoreComments);
    newFactory.setIgnoringElementContentWhitespace(ignoreElementContentWhitespace);
    newFactory.setNamespaceAware(namespaceAware);
    newFactory.setSchema(schema);
    newFactory.setValidating(dtdValidating);
    newFactory.setXIncludeAware(xincludeAware);

    poolVersion++;
    dirtyBuilderConfiguration = false;
    builderFactory = newFactory;
    builderPool.clear();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:BasicParserPool.java

示例6: unMarshall

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
private Graph unMarshall(File inputFile) throws JAXBException, ParserConfigurationException, SAXException,
		IOException {
	LOGGER.debug("Un-Marshaling generated object into target XML");
	JAXBContext jaxbContext;
	Graph graph = null;
	Document document =null;
	parseXML(inputFile);
	String inputFileAsString = replaceParametersWithDefaultValues(inputFile);
	
	DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
	builderFactory.setExpandEntityReferences(false);
	builderFactory.setNamespaceAware(true);
	builderFactory.setFeature(Constants.DISALLOW_DOCTYPE_DECLARATION,true);
	
	DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
	ByteArrayInputStream byteStream = new ByteArrayInputStream(inputFileAsString.getBytes());
	InputSource inputSource=new InputSource(byteStream);

	document = documentBuilder.parse(inputSource);
	jaxbContext = JAXBContext.newInstance(Graph.class);
	Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
	graph = (Graph) jaxbUnmarshaller.unmarshal(document);
	if (graph != null) {
		componentRepo.genrateComponentRepo(graph);
	}
	byteStream.close();
	return graph;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:29,代码来源:UiConverterUtil.java

示例7: getSecurityXmlDocumentFactory

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public static DocumentBuilderFactory getSecurityXmlDocumentFactory() throws ParserConfigurationException {
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
  factory.setXIncludeAware(false);
  factory.setExpandEntityReferences(false);
  factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
  factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
  factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
  factory.setValidating(true);

  return factory;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:13,代码来源:FortifyUtils.java

示例8: getW3CXmlDoc

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 *  Gets a org.w3c.dom.Document for this record. This method is optimized to create only one DOM when
 *  accessed multiple times for the same XMLDocReader.
 *
 * @return    A org.w3c.dom.Document, or null if unable to read.
 */
public org.w3c.dom.Document getW3CXmlDoc() {
	if (w3cXmlDoc != null)
		return w3cXmlDoc;

	DocumentBuilderFactory docfactory
		 = DocumentBuilderFactory.newInstance();
	docfactory.setCoalescing(true);
	docfactory.setExpandEntityReferences(true);
	docfactory.setIgnoringComments(true);

	docfactory.setNamespaceAware(true);

	// We must set validation false since jdk1.4 parser
	// doesn't know about schemas.
	docfactory.setValidating(false);

	// Ignore whitespace doesn't work unless setValidating(true),
	// according to javadocs.
	docfactory.setIgnoringElementContentWhitespace(false);
	try {
		DocumentBuilder docbuilder = docfactory.newDocumentBuilder();
		w3cXmlDoc = docbuilder.parse(getXml());
	} catch (Throwable e) {
		return null;
	}
	return w3cXmlDoc;
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:34,代码来源:XMLDocReader.java

示例9: initializeFactory

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Initializes the pool with a new set of configuration options.
 * 
 * @throws XMLParserException thrown if there is a problem initialzing the pool
 */
protected synchronized void initializeFactory() throws XMLParserException {
    DocumentBuilderFactory newFactory = DocumentBuilderFactory.newInstance();
    setAttributes(newFactory, builderAttributes);
    setFeatures(newFactory, builderFeatures);
    newFactory.setCoalescing(coalescing);
    newFactory.setExpandEntityReferences(expandEntityReferences);
    newFactory.setIgnoringComments(ignoreComments);
    newFactory.setIgnoringElementContentWhitespace(ignoreElementContentWhitespace);
    newFactory.setNamespaceAware(namespaceAware);
    newFactory.setSchema(schema);
    newFactory.setValidating(dtdValidating);
    newFactory.setXIncludeAware(xincludeAware);
    builderFactory = newFactory;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:StaticBasicParserPool.java

示例10: getComponentConfig

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/** Reads the xml configuration files stored under the platform installation.
 * 	These files contain the configuration required to create the component on UI. 
 * @return see {@link Component}
 * @throws RuntimeException 
 * @throws IOException 
 * @throws SAXException 
 */
public List<Component> getComponentConfig() throws RuntimeException, SAXException, IOException {
	if(componentList != null && !componentList.isEmpty()){
		return componentList;
	}
	else{
		try{
			JAXBContext jaxbContext = JAXBContext.newInstance(Config.class);
			Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
			String[] configFileList = getFilteredFiles(XML_CONFIG_FILES_PATH, getFileNameFilter(Messages.XMLConfigUtil_FILE_EXTENTION));
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			dbf.setNamespaceAware(true);
			dbf.setExpandEntityReferences(false);
			dbf.setFeature(Constants.DISALLOW_DOCTYPE_DECLARATION,true);
			DocumentBuilder builder = dbf.newDocumentBuilder();
			for (int i = 0; i < configFileList.length; i++){
				logger.trace("Creating palette component: ", configFileList[i]);
				if(validateXMLSchema(COMPONENT_CONFIG_XSD_PATH, XML_CONFIG_FILES_PATH + SEPARATOR + configFileList[i])){
					
					Document document = builder.parse(new File(XML_CONFIG_FILES_PATH + SEPARATOR + configFileList[i]));
					Config config = (Config) unmarshaller.unmarshal(document);
					componentList.addAll(config.getComponent());
					builder.reset();
				}
			}
			validateAndFillComponentConfigList(componentList);
			return componentList;
		}catch(JAXBException | SAXException | IOException | ParserConfigurationException exception){
			Status status = new Status(IStatus.ERROR,Activator.PLUGIN_ID, "XML read failed", exception);
			StatusManager.getManager().handle(status, StatusManager.BLOCK);
			logger.error(exception.getMessage());
			throw new RuntimeException("Faild in reading XML Config files", exception); //$NON-NLS-1$
		}
	}
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:42,代码来源:XMLConfigUtil.java

示例11: getPolicyConfig

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Gets the policy config.
 * 
 * @return the policy config
 * @throws RuntimeException
 *             the runtime exception
 * @throws SAXException
 *             the SAX exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public PolicyConfig getPolicyConfig() throws RuntimeException, SAXException, IOException {
	if(policyConfig !=null){
		return policyConfig;
	}
	else{
		try{
			JAXBContext jaxbContext = JAXBContext.newInstance(PolicyConfig.class);
			Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
			
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			dbf.setNamespaceAware(true);
			dbf.setExpandEntityReferences(false);
			dbf.setFeature(Constants.DISALLOW_DOCTYPE_DECLARATION,true);
			DocumentBuilder builder = dbf.newDocumentBuilder();
			
			String[] configFileList = getFilteredFiles(CONFIG_FILES_PATH + SEPARATOR + Messages.XMLConfigUtil_POLICY, getFileNameFilter(Messages.XMLConfigUtil_FILE_EXTENTION));
			for (int i = 0; i < configFileList.length; i++) {
				if(validateXMLSchema(POLICY_CONFIG_XSD_PATH, CONFIG_FILES_PATH + SEPARATOR + Messages.XMLConfigUtil_POLICY + SEPARATOR + configFileList[i]))	{
					Document document = builder.parse(new File(CONFIG_FILES_PATH + SEPARATOR
							+ Messages.XMLConfigUtil_POLICY + SEPARATOR + configFileList[i]));
					policyConfig = (PolicyConfig) unmarshaller.unmarshal(document);
					builder.reset();
				}
			}
			return policyConfig;
		}catch(JAXBException | SAXException | IOException | ParserConfigurationException  exception){
			Status status = new Status(IStatus.ERROR,Activator.PLUGIN_ID, "XML read failed", exception);
			StatusManager.getManager().handle(status, StatusManager.BLOCK);
			logger.error(exception.getMessage());
			throw new RuntimeException("Faild in reading XML Config files", exception); //$NON-NLS-1$
		}
	}
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:45,代码来源:XMLConfigUtil.java

示例12: unsafeManualConfig1

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
public static void unsafeManualConfig1() throws ParserConfigurationException, IOException, SAXException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    //dbf.setFeature("http://xml.org/sax/features/external-general-entities",true);
    dbf.setFeature("http://xml.org/sax/features/external-parameter-entities",true);
    dbf.setXIncludeAware(false);
    dbf.setExpandEntityReferences(false);
    DocumentBuilder db = dbf.newDocumentBuilder();

    Document doc = db.parse(getInputFile());
    print(doc);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:12,代码来源:DocumentBuilderSafeProperty.java

示例13: testCheckDocumentBuilderFactory08

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Test the setExpandEntityReferences.
 * @throws Exception If any errors occur.
 */
@Test
public void testCheckDocumentBuilderFactory08() throws Exception {
    try (FileInputStream fis = new FileInputStream(new File(
            XML_DIR, "DocumentBuilderFactory02.xml"))) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setExpandEntityReferences(false);
        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
        Document doc = docBuilder.parse(fis);
        Element e = (Element) doc.getElementsByTagName("title").item(0);
        NodeList nl = e.getChildNodes();
        assertNull(nl.item(0).getNodeValue());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:DocumentBuilderFactoryTest.java

示例14: getDoc

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
Document getDoc() {
    InputStream xmlFile = getClass().getResourceAsStream("ElementTraversal.xml");
    Document doc = null;
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setExpandEntityReferences(false);
        DocumentBuilder db = dbf.newDocumentBuilder();
        doc = db.parse(xmlFile);
    } catch (ParserConfigurationException | SAXException | IOException e) {
        System.out.println("fail: " + e.getMessage());
    }

    return doc;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ElementTraversal.java

示例15: getDocumentBuilder

import javax.xml.parsers.DocumentBuilderFactory; //导入方法依赖的package包/类
/**
 * Return JAXP document builder instance.
 */
protected DocumentBuilder getDocumentBuilder() throws ServletException {
	DocumentBuilder documentBuilder = null;
	DocumentBuilderFactory documentBuilderFactory = null;
	try {
		documentBuilderFactory = DocumentBuilderFactory.newInstance();
		documentBuilderFactory.setNamespaceAware(true);
		documentBuilderFactory.setExpandEntityReferences(false);
		documentBuilder = documentBuilderFactory.newDocumentBuilder();
		documentBuilder.setEntityResolver(new WebdavResolver(this.getServletContext()));
	} catch (ParserConfigurationException e) {
		throw new ServletException(sm.getString("webdavservlet.jaxpfailed"));
	}
	return documentBuilder;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:18,代码来源:WebdavServlet.java


注:本文中的javax.xml.parsers.DocumentBuilderFactory.setExpandEntityReferences方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。