本文整理汇总了Java中org.apache.xerces.jaxp.DocumentBuilderFactoryImpl类的典型用法代码示例。如果您正苦于以下问题:Java DocumentBuilderFactoryImpl类的具体用法?Java DocumentBuilderFactoryImpl怎么用?Java DocumentBuilderFactoryImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DocumentBuilderFactoryImpl类属于org.apache.xerces.jaxp包,在下文中一共展示了DocumentBuilderFactoryImpl类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDocumentBuilderFactoryInWhiteList
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; //导入依赖的package包/类
/**
* Test we have set features the way we expect as defaults.
*/
public void testDocumentBuilderFactoryInWhiteList() throws Throwable
{
// Using constructor rather than the service locator and then using the helper to configure it.
DocumentBuilderFactory dbf = new DocumentBuilderFactoryImpl();
FactoryHelper factoryHelper = new FactoryHelper();
List<String> whiteListClasses = Collections.singletonList(getClass().getName());
factoryHelper.configureFactory(dbf, FactoryHelper.DEFAULT_FEATURES_TO_ENABLE,
FactoryHelper.DEFAULT_FEATURES_TO_DISABLE,
whiteListClasses);
assertFalse(dbf.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
assertFalse(dbf.getFeature(FactoryHelper.FEATURE_DISALLOW_DOCTYPE));
assertTrue(dbf.getFeature(FactoryHelper.FEATURE_EXTERNAL_GENERAL_ENTITIES));
assertTrue(dbf.getFeature(FactoryHelper.FEATURE_EXTERNAL_PARAMETER_ENTITIES));
assertTrue(dbf.getFeature(FactoryHelper.FEATURE_USE_ENTITY_RESOLVER2));
assertTrue(dbf.getFeature(FactoryHelper.FEATURE_LOAD_EXTERNAL_DTD));
assertTrue(dbf.isExpandEntityReferences());
assertFalse(dbf.isXIncludeAware()); // false is the default so is same as the non whitelist test
}
示例2: Parser
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; //导入依赖的package包/类
/**
* Parser constructor.
*
* @param fileName The input .xml file to parse.
* @param rootTag A root tag name to check against the XML document.
*/
public Parser(String fileName, String rootTag) throws FileNotFoundException {
try {
DocumentBuilderFactory dFactory = DocumentBuilderFactoryImpl.newInstance();
DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
document = dBuilder.parse(new File(fileName));
log.info("Parsed file: {}", fileName);
if(!document.getDocumentElement().getTagName().equals(rootTag)) {
throw new UnsupportedOperationException("Root tag \"" + rootTag + "\" not found.");
}
} catch(Exception e) {
if(e instanceof FileNotFoundException) {
throw new FileNotFoundException("Could not find XML document at " + fileName + ".");
}
log.error("Could not parse the XML document.", e);
}
}
示例3: testParseLocalFile
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; //导入依赖的package包/类
@Test
public void testParseLocalFile() throws Exception {
// Parse and traverse XML file with ScaleDOM
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
ScaleDomDocumentBuilderFactory.class.getName());
System.out.println("INFO: Parsing with ScaleDOM, please be patient (may take several minutes)...");
doParseFile("file://" + tmpXmlFile);
// Parse and traverse XML file with standard XML parser (Xerces)
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
DocumentBuilderFactoryImpl.class.getName());
System.out.println("INFO: Parsing with Xerces, please be patient (may take several minutes)...");
try {
System.gc();
doParseFile("file://" + tmpXmlFile);
} catch (OutOfMemoryError t) {
System.out.println("INFO: Xerces was unable to parse the file due to OutOfMemoryError. (This is EXPECTED!)");
}
}
示例4: MCRDOMUtils
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; //导入依赖的package包/类
private MCRDOMUtils() {
builderQueue = new ConcurrentLinkedQueue<>();
docBuilderFactory = DocumentBuilderFactory.newInstance(DocumentBuilderFactoryImpl.class.getName(), getClass()
.getClassLoader());
docBuilderFactory.setNamespaceAware(true);
MCRShutdownHandler.getInstance().addCloseable(this);
}
示例5: newDocumentBuilderFactory
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; //导入依赖的package包/类
private DocumentBuilderFactory newDocumentBuilderFactory() {
try{
return new DocumentBuilderFactoryImpl();
}
catch(Throwable t) {
return DocumentBuilderFactory.newInstance();
}
}
示例6: getDocumentBuilderFactory
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; //导入依赖的package包/类
/**
* @return a factory for parsers that use this schema.
*/
DocumentBuilderFactory getDocumentBuilderFactory()
{
if (mSchema == null)
{
throw new RuntimeException("Not yet parsed");
}
// Thanks http://xerces.apache.org/xerces2-j/faq-dom.html#faq-8
DocumentBuilderFactoryImpl lFactory =
(DocumentBuilderFactoryImpl)DocumentBuilderFactory.newInstance(
DocumentBuilderFactoryImpl.class.getName(), null);
lFactory.setNamespaceAware(true);
lFactory.setValidating(true);
lFactory.setAttribute("http://apache.org/xml/features/validation/schema",
Boolean.TRUE);
lFactory.setAttribute("http://apache.org/xml/features/validation/schema-full-checking",
Boolean.TRUE);
lFactory.setAttribute("http://apache.org/xml/properties/dom/document-class-name",
"org.apache.xerces.dom.PSVIDocumentImpl");
lFactory.setSchema(mSchema);
// Undocumented but necessary to force the
// org.apache.xerces.impl.xs.XmlSchemaValidator to actually use our schema
// - otherwise the above schema doesn't make it all the way down the
// stack. Sigh.
lFactory.setAttribute("http://apache.org/xml/properties/internal/grammar-pool",
((XSGrammarPoolContainer)mSchema).getGrammarPool());
return lFactory;
}
示例7: Generador
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; //导入依赖的package包/类
public Generador() throws ParserConfigurationException{
// Inicializamos factoría (xerces) de creación de documentos XML (DOM)
dbFactory = DocumentBuilderFactoryImpl.newInstance();
docBuilder = dbFactory.newDocumentBuilder();
}
示例8: newDocumentBuilderFactory
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; //导入依赖的package包/类
private static DocumentBuilderFactory newDocumentBuilderFactory() {
return new DocumentBuilderFactoryImpl();
// we do not use DocumentBuilderFactory.newInstance(); because it is unpredictable
}
示例9: ConfigParserContentHandler
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; //导入依赖的package包/类
public ConfigParserContentHandler() throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactoryImpl.newInstance(); // Xerces
db = dbf.newDocumentBuilder();
}
示例10: createReportDocument
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; //导入依赖的package包/类
/**
* Create an XML document based on mapping verification result
* @return
*/
private Document createReportDocument()
{
Document dom=null;
DocumentBuilderFactory dbf = DocumentBuilderFactoryImpl.newInstance();
try
{
//get an instance of builder
DocumentBuilder db = dbf.newDocumentBuilder();
//create an instance of DOM
dom = db.newDocument();
Element rootElm=dom.createElement("unmapped");
rootElm.setAttribute("type", reportType);
dom.appendChild(rootElm);
Element components=dom.createElement("components");
Element srcNode=dom.createElement("component");
srcNode.setAttribute("kind", "scs");
String srcFilePath = getSourceFileName();
if (srcFilePath.startsWith(FileUtil.getWorkingDirPath()))
srcFilePath = srcFilePath.replace(FileUtil.getWorkingDirPath(), Config.CAADAPTER_HOME_DIR_TAG);
srcNode.setAttribute("location", srcFilePath);
srcNode.setAttribute("type", "source");
components.appendChild(srcNode);
Element trgtNode=dom.createElement("component");
trgtNode.setAttribute("kind", "xmi");
String tgrtFilePath =getTargetFileName();
if (tgrtFilePath.startsWith(FileUtil.getWorkingDirPath()))
tgrtFilePath = tgrtFilePath.replace(FileUtil.getWorkingDirPath(), Config.CAADAPTER_HOME_DIR_TAG);
trgtNode.setAttribute("location", tgrtFilePath);
trgtNode.setAttribute("type", "target");
components.appendChild(trgtNode);
rootElm.appendChild(components);
Element unmappedFields=dom.createElement("fields");
for(String oneItem:reportElments)
{
Element rptItem=dom.createElement("field");
rptItem.setAttribute("kind", "scs");
rptItem.setAttribute("xmlPath", oneItem);
unmappedFields.appendChild(rptItem);
}
rootElm.appendChild(unmappedFields);
}
catch(ParserConfigurationException e)
{
e.printStackTrace();
}
return dom;
}
示例11: SimpleXMLParser
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl; //导入依赖的package包/类
/**
* Create an instance of the SimpleXMLParser.
* @throws ParserConfigurationException if the object cannot create an
* instance of the Xerces parser it uses internally.
*/
public SimpleXMLParser() throws ParserConfigurationException {
// throws ParserConfigurationException if creation fails
builder = DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder();
}