@Test
public void test() throws SAXException, ParserConfigurationException, IOException {
Schema schema = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema").newSchema(new StreamSource(new StringReader(xmlSchema)));
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
saxParserFactory.setSchema(schema);
// saxParserFactory.setFeature("http://java.sun.com/xml/schema/features/report-ignored-element-content-whitespace",
// true);
SAXParser saxParser = saxParserFactory.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
xmlReader.setContentHandler(new MyContentHandler());
// InputStream input =
// ClassLoader.getSystemClassLoader().getResourceAsStream("test/test.xml");
InputStream input = getClass().getResourceAsStream("Bug6946312.xml");
System.out.println("Parse InputStream:");
xmlReader.parse(new InputSource(input));
if (!charEvent) {
Assert.fail("missing character event");
}
}
java类javax.xml.parsers.SAXParser的实例源码
Bug6946312Test.java 文件源码
项目:openjdk-jdk10
阅读 24
收藏 0
点赞 0
评论 0
JspDocumentParser.java 文件源码
项目:lams
阅读 22
收藏 0
点赞 0
评论 0
private static SAXParser getSAXParser(
boolean validating,
JspDocumentParser jspDocParser)
throws Exception {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
// Preserve xmlns attributes
factory.setFeature(
"http://xml.org/sax/features/namespace-prefixes",
true);
factory.setValidating(validating);
//factory.setFeature(
// "http://xml.org/sax/features/validation",
// validating);
// Configure the parser
SAXParser saxParser = factory.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
xmlReader.setProperty(LEXICAL_HANDLER_PROPERTY, jspDocParser);
xmlReader.setErrorHandler(jspDocParser);
return saxParser;
}
XercesParser.java 文件源码
项目:tomcat7
阅读 30
收藏 0
点赞 0
评论 0
/**
* Configure schema validation as recommended by the JAXP 1.2 spec.
* The <code>properties</code> object may contains information about
* the schema local and language.
* @param properties parser optional info
*/
private static void configureOldXerces(SAXParser parser,
Properties properties)
throws ParserConfigurationException,
SAXNotSupportedException {
String schemaLocation = (String)properties.get("schemaLocation");
String schemaLanguage = (String)properties.get("schemaLanguage");
try{
if (schemaLocation != null) {
parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
}
} catch (SAXNotRecognizedException e){
log.info(parser.getClass().getName() + ": "
+ e.getMessage() + " not supported.");
}
}
GenericParser.java 文件源码
项目:tomcat7
阅读 26
收藏 0
点赞 0
评论 0
/**
* Create a <code>SAXParser</code> configured to support XML Schema and DTD
* @param properties parser specific properties/features
* @return an XML Schema/DTD enabled <code>SAXParser</code>
*/
public static SAXParser newSAXParser(Properties properties)
throws ParserConfigurationException,
SAXException,
SAXNotRecognizedException{
SAXParserFactory factory =
(SAXParserFactory)properties.get("SAXParserFactory");
SAXParser parser = factory.newSAXParser();
String schemaLocation = (String)properties.get("schemaLocation");
String schemaLanguage = (String)properties.get("schemaLanguage");
try{
if (schemaLocation != null) {
parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
}
} catch (SAXNotRecognizedException e){
log.info(parser.getClass().getName() + ": "
+ e.getMessage() + " not supported.");
}
return parser;
}
DefaultHandlerTest.java 文件源码
项目:openjdk-jdk10
阅读 26
收藏 0
点赞 0
评论 0
/**
* Test default handler that transverses XML and print all visited node.
*
* @throws Exception If any errors occur.
*/
@Test
public void testDefaultHandler() throws Exception {
String outputFile = USER_DIR + "DefaultHandler.out";
String goldFile = GOLDEN_DIR + "DefaultHandlerGF.out";
String xmlFile = XML_DIR + "namespace1.xml";
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
SAXParser saxparser = spf.newSAXParser();
MyDefaultHandler handler = new MyDefaultHandler(outputFile);
File file = new File(xmlFile);
String Absolutepath = file.getAbsolutePath();
String newAbsolutePath = Absolutepath;
if (File.separatorChar == '\\')
newAbsolutePath = Absolutepath.replace('\\', '/');
saxparser.parse("file:///" + newAbsolutePath, handler);
assertTrue(compareWithGold(goldFile, outputFile));
}
AttributesCollectorUsingSaxTest.java 文件源码
项目:oxygen-dita-translation-package-builder
阅读 25
收藏 0
点赞 0
评论 0
/**
* <p><b>Description:</b> Test the conrefs are handled by the SAXParser.</p>
* <p><b>Bug ID:</b> #15</p>
*
* @author adrian_sorop
*
* @throws Exception
*/
public void testSaxParserConref() throws Exception {
File ditaFile = new File(TestUtil.getPath("issue-15_1/topics"),"topic2.dita");
assertTrue("UNABLE TO LOAD FILE", ditaFile.exists());
URL url = URLUtil.correct(ditaFile);
SAXParserFactory factory = SAXParserFactory.newInstance();
// Ignore the DTD declaration
factory.setValidating(false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
factory.setFeature("http://xml.org/sax/features/validation", false);
SAXParser parser = factory.newSAXParser();
SaxContentHandler handler= new SaxContentHandler(url);
parser.parse(ditaFile, handler);
List<ReferencedResource> referredFiles = new ArrayList<ReferencedResource>();
referredFiles.addAll(handler.getDitaMapHrefs());
assertEquals("Two files should have been referred.", 2, referredFiles.size());
assertTrue("Should be a content reference to topicConref.dita but was" + referredFiles.get(1).getLocation(),
referredFiles.get(1).getLocation().toString().contains("issue-15_1/topics/topicConref.dita"));
assertTrue("Should be a xref to topic3.dita",
referredFiles.get(0).getLocation().toString().contains("issue-15_1/topics/topic3.dita"));
}
SAXParserTest.java 文件源码
项目:openjdk-jdk10
阅读 24
收藏 0
点赞 0
评论 0
/**
* Test with valid input source, parser should parse the XML document
* successfully.
*
* @param saxparser a SAXParser instance.
* @throws Exception If any errors occur.
*/
@Test(dataProvider = "parser-provider")
public void testParse25(SAXParser saxparser) throws Exception {
try (FileInputStream instream = new FileInputStream(
new File(XML_DIR, "parsertest.xml"))) {
saxparser.parse(instream, new DefaultHandler(),
new File(XML_DIR).toURI().toASCIIString());
}
}
XML_SAX_StAX_FI.java 文件源码
项目:OpenJSharp
阅读 29
收藏 0
点赞 0
评论 0
public void parse(InputStream xml, OutputStream finf, String workingDirectory) throws Exception {
StAXDocumentSerializer documentSerializer = new StAXDocumentSerializer();
documentSerializer.setOutputStream(finf);
SAX2StAXWriter saxTostax = new SAX2StAXWriter(documentSerializer);
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
SAXParser saxParser = saxParserFactory.newSAXParser();
XMLReader reader = saxParser.getXMLReader();
reader.setProperty("http://xml.org/sax/properties/lexical-handler", saxTostax);
reader.setContentHandler(saxTostax);
if (workingDirectory != null) {
reader.setEntityResolver(createRelativePathResolver(workingDirectory));
}
reader.parse(new InputSource(xml));
xml.close();
finf.close();
}
JAXPParser.java 文件源码
项目:OpenJSharp
阅读 23
收藏 0
点赞 0
评论 0
private static SAXParser allowFileAccess(SAXParser saxParser, boolean disableSecureProcessing) throws SAXException {
// if feature secure processing enabled, nothing to do, file is allowed,
// or user is able to control access by standard JAXP mechanisms
if (disableSecureProcessing) {
return saxParser;
}
try {
saxParser.setProperty(ACCESS_EXTERNAL_SCHEMA, "file");
LOGGER.log(Level.FINE, Messages.format(Messages.JAXP_SUPPORTED_PROPERTY, ACCESS_EXTERNAL_SCHEMA));
} catch (SAXException ignored) {
// nothing to do; support depends on version JDK or SAX implementation
LOGGER.log(Level.CONFIG, Messages.format(Messages.JAXP_UNSUPPORTED_PROPERTY, ACCESS_EXTERNAL_SCHEMA), ignored);
}
return saxParser;
}
XMLParser.java 文件源码
项目:Hydrograph
阅读 43
收藏 0
点赞 0
评论 0
/**Parses the XML to fetch parameters.
* @param inputFile, source XML
* @return true, if XML is successfully parsed.
* @throws Exception
*/
public boolean parseXML(File inputFile,UIComponentRepo componentRepo) throws ParserConfigurationException, SAXException, IOException{
LOGGER.debug("Parsing target XML for separating Parameters");
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser;
try {
factory.setFeature(Constants.DISALLOW_DOCTYPE_DECLARATION,true);
saxParser = factory.newSAXParser();
XMLHandler xmlhandler = new XMLHandler(componentRepo);
saxParser.parse(inputFile, xmlhandler);
return true;
} catch (ParserConfigurationException | SAXException | IOException exception) {
LOGGER.error("Parsing failed...",exception);
throw exception;
}
}
DatasetReader.java 文件源码
项目:parabuild-ci
阅读 28
收藏 0
点赞 0
评论 0
/**
* Reads a {@link CategoryDataset} from a stream.
*
* @param in the stream.
*
* @return A dataset.
*
* @throws IOException if there is a problem reading the file.
*/
public static CategoryDataset readCategoryDatasetFromXML(final InputStream in) throws IOException {
CategoryDataset result = null;
final SAXParserFactory factory = SAXParserFactory.newInstance();
try {
final SAXParser parser = factory.newSAXParser();
final CategoryDatasetHandler handler = new CategoryDatasetHandler();
parser.parse(in, handler);
result = handler.getDataset();
}
catch (SAXException e) {
System.out.println(e.getMessage());
}
catch (ParserConfigurationException e2) {
System.out.println(e2.getMessage());
}
return result;
}
Bug6963468Test.java 文件源码
项目:openjdk-jdk10
阅读 22
收藏 0
点赞 0
评论 0
@Test
public void testInstance() throws ParserConfigurationException, SAXException, IOException {
System.out.println(Bug6963468Test.class.getResource("Bug6963468.xsd").getPath());
File schemaFile = new File(Bug6963468Test.class.getResource("Bug6963468.xsd").getPath());
SAXParser parser = createParser(schemaFile);
try {
parser.parse(Bug6963468Test.class.getResource("Bug6963468.xml").getPath(), new DefaultHandler());
} catch (SAXException e) {
e.printStackTrace();
Assert.fail("Fatal Error: " + strException(e));
}
}
Bug4991020.java 文件源码
项目:openjdk-jdk10
阅读 25
收藏 0
点赞 0
评论 0
protected static SAXParser createParser() throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);
SAXParser parser = spf.newSAXParser();
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
return parser;
}
JavaActions.java 文件源码
项目:incubator-netbeans
阅读 27
收藏 0
点赞 0
评论 0
/**
* Find the line number of a target in an Ant script, or some other line in an XML file.
* Able to find a certain element with a certain attribute matching a given value.
* See also AntTargetNode.TargetOpenCookie.
* @param file an Ant script or other XML file
* @param match the attribute value to match (e.g. target name)
* @param elementLocalName the (local) name of the element to look for
* @param elementAttributeName the name of the attribute to match on
* @return the line number (0-based), or -1 if not found
*/
static final int findLine(FileObject file, final String match, final String elementLocalName, final String elementAttributeName) throws IOException, SAXException, ParserConfigurationException {
InputSource in = new InputSource(file.getURL().toString());
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
SAXParser parser = factory.newSAXParser();
final int[] line = new int[] {-1};
class Handler extends DefaultHandler {
private Locator locator;
public void setDocumentLocator(Locator l) {
locator = l;
}
public void startElement(String uri, String localname, String qname, Attributes attr) throws SAXException {
if (line[0] == -1) {
if (localname.equals(elementLocalName) && match.equals(attr.getValue(elementAttributeName))) { // NOI18N
line[0] = locator.getLineNumber() - 1;
}
}
}
}
parser.parse(in, new Handler());
return line[0];
}
SaxParserSafePrivilegedExceptionAction.java 文件源码
项目:Android_Code_Arbiter
阅读 78
收藏 0
点赞 0
评论 0
private static void receiveXMLStream(final InputStream inStream,
final DefaultHandler defHandler)
throws ParserConfigurationException, SAXException, IOException {
// ...
SAXParserFactory spf = SAXParserFactory.newInstance();
final SAXParser saxParser = spf.newSAXParser();
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws SAXException, IOException {
saxParser.parse(inStream, defHandler);
return null;
}
}, RESTRICTED_ACCESS_CONTROL); // From nested class
} catch (PrivilegedActionException pae) {
System.out.println("Filesystem access blocked");
pae.printStackTrace();
}
}
AuctionItemRepository.java 文件源码
项目:openjdk-jdk10
阅读 23
收藏 0
点赞 0
评论 0
/**
* Testing set MaxOccursLimit to 10000 in the secure processing enabled for
* SAXParserFactory.
*
* @throws Exception If any errors occur.
*/
@Test
public void testMaxOccurLimitPos() throws Exception {
String schema_file = XML_DIR + "toys.xsd";
String xml_file = XML_DIR + "toys.xml";
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
factory.setFeature(FEATURE_SECURE_PROCESSING, true);
setSystemProperty(SP_MAX_OCCUR_LIMIT, String.valueOf(10000));
SAXParser parser = factory.newSAXParser();
parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
parser.setProperty(JAXP_SCHEMA_SOURCE, new File(schema_file));
try (InputStream is = new FileInputStream(xml_file)) {
MyErrorHandler eh = new MyErrorHandler();
parser.parse(is, eh);
assertFalse(eh.isAnyError());
}
}
BeanDeploymentArchiveImpl.java 文件源码
项目:testee.fi
阅读 25
收藏 0
点赞 0
评论 0
private BeansXml readBeansXml(BeanArchive beanArchive, ClasspathResource resource) {
try {
final SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
final SAXParser parser = factory.newSAXParser();
final InputSource source = new InputSource(new ByteArrayInputStream(resource.getBytes()));
if (source.getByteStream().available() == 0) {
// The file is just acting as a marker file
return EMPTY_BEANS_XML;
}
final BeansXmlHandler handler = new BeansXmlHandler(beanArchive.getClasspathEntry().getURL());
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", loadXsds());
parser.parse(source, handler);
return handler.createBeansXml();
} catch (final SAXException | ParserConfigurationException | IOException e) {
throw new TestEEfiException(
"Failed to parse META-INF/beans.xml in " + beanArchive.getClasspathEntry().getURL(),
e
);
}
}
ResolverTest.java 文件源码
项目:openjdk-jdk10
阅读 29
收藏 0
点赞 0
评论 0
/**
* Unit test for entityResolver setter.
*
* @throws Exception If any errors occur.
*/
public void testResolver() throws Exception {
String outputFile = USER_DIR + "EntityResolver.out";
String goldFile = GOLDEN_DIR + "EntityResolverGF.out";
String xmlFile = XML_DIR + "publish.xml";
Files.copy(Paths.get(XML_DIR + "publishers.dtd"),
Paths.get(USER_DIR + "publishers.dtd"), REPLACE_EXISTING);
Files.copy(Paths.get(XML_DIR + "familytree.dtd"),
Paths.get(USER_DIR + "familytree.dtd"), REPLACE_EXISTING);
try(FileInputStream instream = new FileInputStream(xmlFile);
MyEntityResolver eResolver = new MyEntityResolver(outputFile)) {
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
xmlReader.setEntityResolver(eResolver);
InputSource is = new InputSource(instream);
xmlReader.parse(is);
}
assertTrue(compareWithGold(goldFile, outputFile));
}
SynthParser.java 文件源码
项目:openjdk-jdk10
阅读 28
收藏 0
点赞 0
评论 0
/**
* Parses a set of styles from <code>inputStream</code>, adding the
* resulting styles to the passed in DefaultSynthStyleFactory.
* Resources are resolved either from a URL or from a Class. When calling
* this method, one of the URL or the Class must be null but not both at
* the same time.
*
* @param inputStream XML document containing the styles to read
* @param factory DefaultSynthStyleFactory that new styles are added to
* @param urlResourceBase the URL used to resolve any resources, such as Images
* @param classResourceBase the Class used to resolve any resources, such as Images
* @param defaultsMap Map that UIDefaults properties are placed in
*/
public void parse(InputStream inputStream,
DefaultSynthStyleFactory factory,
URL urlResourceBase, Class<?> classResourceBase,
Map<String, Object> defaultsMap)
throws ParseException, IllegalArgumentException {
if (inputStream == null || factory == null ||
(urlResourceBase == null && classResourceBase == null)) {
throw new IllegalArgumentException(
"You must supply an InputStream, StyleFactory and Class or URL");
}
assert(!(urlResourceBase != null && classResourceBase != null));
_factory = factory;
_classResourceBase = classResourceBase;
_urlResourceBase = urlResourceBase;
_defaultsMap = defaultsMap;
try {
try {
SAXParser saxParser = SAXParserFactory.newInstance().
newSAXParser();
saxParser.parse(new BufferedInputStream(inputStream), this);
} catch (ParserConfigurationException e) {
throw new ParseException("Error parsing: " + e, 0);
}
catch (SAXException se) {
throw new ParseException("Error parsing: " + se + " " +
se.getException(), 0);
}
catch (IOException ioe) {
throw new ParseException("Error parsing: " + ioe, 0);
}
} finally {
reset();
}
}
PersistenceUnitParser.java 文件源码
项目:aries-jpa
阅读 24
收藏 0
点赞 0
评论 0
private static void parse(Bundle bundle, InputStream is, Collection<PersistenceUnit> punits) {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
try {
SAXParser parser = parserFactory.newSAXParser();
JPAHandler handler = new JPAHandler(bundle);
parser.parse(is, handler);
punits.addAll(handler.getPersistenceUnits());
} catch (Exception e) {
throw new RuntimeException("Error parsing persistence unit in bundle " + bundle.getSymbolicName(), e); // NOSONAR
} finally {
safeClose(is);
}
}
XercesParser.java 文件源码
项目:tomcat7
阅读 32
收藏 0
点赞 0
评论 0
/**
* Create a <code>SAXParser</code> based on the underlying
* <code>Xerces</code> version.
* @param properties parser specific properties/features
* @return an XML Schema/DTD enabled <code>SAXParser</code>
*/
public static SAXParser newSAXParser(Properties properties)
throws ParserConfigurationException,
SAXException,
SAXNotSupportedException {
SAXParserFactory factory =
(SAXParserFactory)properties.get("SAXParserFactory");
if (versionNumber == null){
versionNumber = getXercesVersion();
version = Float.parseFloat(versionNumber);
}
// Note: 2.2 is completely broken (with XML Schema).
if (version > 2.1) {
configureXerces(factory);
return factory.newSAXParser();
} else {
SAXParser parser = factory.newSAXParser();
configureOldXerces(parser,properties);
return parser;
}
}
Digester.java 文件源码
项目:tomcat7
阅读 31
收藏 0
点赞 0
评论 0
/**
* 返回解析器
* Return the SAXParser we will use to parse the input stream. If there
* is a problem creating the parser, return <code>null</code>.
*/
public SAXParser getParser() {
// Return the parser we already created (if any)
if (parser != null) {
return (parser);
}
// Create a new parser
try {
parser = getFactory().newSAXParser();
} catch (Exception e) {
log.error("Digester.getParser: ", e);
return (null);
}
return (parser);
}
EHFatalTest.java 文件源码
项目:openjdk-jdk10
阅读 23
收藏 0
点赞 0
评论 0
/**
* Error Handler to capture all error events to output file. Verifies the
* output file is same as golden file.
*
* @throws Exception If any errors occur.
*/
@Test
public void testEHFatal() throws Exception {
String outputFile = USER_DIR + "EHFatal.out";
String goldFile = GOLDEN_DIR + "EHFatalGF.out";
String xmlFile = XML_DIR + "invalid.xml";
try(MyErrorHandler eHandler = new MyErrorHandler(outputFile);
FileInputStream instream = new FileInputStream(xmlFile)) {
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
xmlReader.setErrorHandler(eHandler);
InputSource is = new InputSource(instream);
xmlReader.parse(is);
fail("Parse should throw SAXException");
} catch (SAXException expected) {
// This is expected.
}
// Need close the output file before we compare it with golden file.
assertTrue(compareWithGold(goldFile, outputFile));
}
JAXPParser.java 文件源码
项目:openjdk-jdk10
阅读 27
收藏 0
点赞 0
评论 0
private static SAXParser allowFileAccess(SAXParser saxParser, boolean disableSecureProcessing) throws SAXException {
// if feature secure processing enabled, nothing to do, file is allowed,
// or user is able to control access by standard JAXP mechanisms
if (disableSecureProcessing) {
return saxParser;
}
try {
saxParser.setProperty(ACCESS_EXTERNAL_SCHEMA, "file");
LOGGER.log(Level.FINE, Messages.format(Messages.JAXP_SUPPORTED_PROPERTY, ACCESS_EXTERNAL_SCHEMA));
} catch (SAXException ignored) {
// nothing to do; support depends on version JDK or SAX implementation
LOGGER.log(Level.CONFIG, Messages.format(Messages.JAXP_UNSUPPORTED_PROPERTY, ACCESS_EXTERNAL_SCHEMA), ignored);
}
return saxParser;
}
ServiceProvisioningServiceBeanImportExportSchemaIT.java 文件源码
项目:oscm
阅读 26
收藏 0
点赞 0
评论 0
private void verifyXML(byte[] xml) throws IOException, SAXException,
ParserConfigurationException {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
SchemaFactory sf = SchemaFactory
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
ClassLoader classLoader = Thread.currentThread()
.getContextClassLoader();
if (classLoader == null) {
classLoader = getClass().getClassLoader();
}
final Schema schema;
try (InputStream inputStream = ResourceLoader.getResourceAsStream(
getClass(), "TechnicalServices.xsd")) {
schema = sf.newSchema(new StreamSource(inputStream));
}
spf.setSchema(schema);
SAXParser saxParser = spf.newSAXParser();
XMLReader reader = saxParser.getXMLReader();
ErrorHandler errorHandler = new MyErrorHandler();
reader.setErrorHandler(errorHandler);
reader.parse(new InputSource(new ByteArrayInputStream(xml)));
}
XMLSecureParsingTest.java 文件源码
项目:oscm
阅读 21
收藏 0
点赞 0
评论 0
@Test
public void testSaxParsing() throws ParserConfigurationException,
SAXException, IOException {
// given
byte[] fileAsByteArray = BaseAdmUmTest.getFileAsByteArray(
this.getClass(), FILE_TEST);
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
assertTrue(spf.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
SAXParser saxParser = spf.newSAXParser();
XMLReader reader = saxParser.getXMLReader();
try {
// when
reader.parse(new InputSource(new ByteArrayInputStream(
fileAsByteArray)));
fail();
} catch (SAXParseException e) {
// then
assertThatMaxEntitiesExceeded(e);
}
}
LocaleLoader.java 文件源码
项目:Phoenicia
阅读 35
收藏 0
点赞 0
评论 0
/**
* Load and read the manifest.xml for a Locale.
* @param locale_manifest_in
* @return
*/
public Locale load(InputStream locale_manifest_in) {
LocaleParser localeParser = new LocaleParser();
try {
final SAXParserFactory spf = SAXParserFactory.newInstance();
final SAXParser sp = spf.newSAXParser();
final XMLReader xr = sp.getXMLReader();
xr.setContentHandler(localeParser);
xr.parse(new InputSource(new BufferedInputStream(locale_manifest_in)));
} catch (Exception e) {
Debug.e(e);
}
return localeParser.getLocale();
}
AttributesCollectorUsingSaxTest.java 文件源码
项目:oxygen-dita-translation-package-builder
阅读 26
收藏 0
点赞 0
评论 0
/**
* <p><b>Description:</b> Verify the attribute collector over DITA map.
* Collect referred files non-recursion.</p>
* <p><b>Bug ID:</b> #9</p>
*
* @author adrian_sorop
*
* @throws Exception
*/
public void testSaxParser() throws Exception {
File ditaFile = new File(rootDir,"rootMap.ditamap");
assertTrue("UNABLE TO LOAD FILE", ditaFile.exists());
URL url = URLUtil.correct(ditaFile);
SAXParserFactory factory = SAXParserFactory.newInstance();
// Ignore the DTD declaration
factory.setValidating(false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
factory.setFeature("http://xml.org/sax/features/validation", false);
SAXParser parser = factory.newSAXParser();
SaxContentHandler handler= new SaxContentHandler(url);
parser.parse(ditaFile, handler);
List<ReferencedResource> referredFiles = new ArrayList<ReferencedResource>();
referredFiles.addAll(handler.getDitaMapHrefs());
assertEquals("Two files should have been referred.", 2, referredFiles.size());
assertTrue("Referred topic in dita maps should be topic2.dita",
referredFiles.toString().contains("issue-9/topics/topic2.dita"));
assertTrue("Referred topic in dita maps should be topic1.dita",
referredFiles.toString().contains("issue-9/topics/topic1.dita"));
}
Digester.java 文件源码
项目:lazycat
阅读 25
收藏 0
点赞 0
评论 0
/**
* Return the SAXParser we will use to parse the input stream. If there is a
* problem creating the parser, return <code>null</code>.
*/
public SAXParser getParser() {
// Return the parser we already created (if any)
if (parser != null) {
return (parser);
}
// Create a new parser
try {
parser = getFactory().newSAXParser();
} catch (Exception e) {
log.error("Digester.getParser: ", e);
return (null);
}
return (parser);
}
XercesParser.java 文件源码
项目:lams
阅读 33
收藏 0
点赞 0
评论 0
/**
* Configure schema validation as recommended by the JAXP 1.2 spec.
* The <code>properties</code> object may contains information about
* the schema local and language.
* @param properties parser optional info
*/
private static void configureOldXerces(SAXParser parser,
Properties properties)
throws ParserConfigurationException,
SAXNotSupportedException {
String schemaLocation = (String)properties.get("schemaLocation");
String schemaLanguage = (String)properties.get("schemaLanguage");
try{
if (schemaLocation != null) {
parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
}
} catch (SAXNotRecognizedException e){
log.info(parser.getClass().getName() + ": "
+ e.getMessage() + " not supported.");
}
}