本文整理汇总了Java中org.xml.sax.helpers.XMLReaderFactory类的典型用法代码示例。如果您正苦于以下问题:Java XMLReaderFactory类的具体用法?Java XMLReaderFactory怎么用?Java XMLReaderFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XMLReaderFactory类属于org.xml.sax.helpers包,在下文中一共展示了XMLReaderFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testcase08
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
/**
* Test newTransformerHandler with a Template Handler.
*
* @throws Exception If any errors occur.
*/
public void testcase08() throws Exception {
String outputFile = USER_DIR + "saxtf008.out";
String goldFile = GOLDEN_DIR + "saxtf008GF.out";
try (FileOutputStream fos = new FileOutputStream(outputFile)) {
XMLReader reader = XMLReaderFactory.createXMLReader();
SAXTransformerFactory saxTFactory
= (SAXTransformerFactory)TransformerFactory.newInstance();
TemplatesHandler thandler = saxTFactory.newTemplatesHandler();
reader.setContentHandler(thandler);
reader.parse(XSLT_FILE);
TransformerHandler tfhandler
= saxTFactory.newTransformerHandler(thandler.getTemplates());
Result result = new StreamResult(fos);
tfhandler.setResult(result);
reader.setContentHandler(tfhandler);
reader.parse(XML_FILE);
}
assertTrue(compareWithGold(goldFile, outputFile));
}
示例2: load
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
public static SyntaxScheme load(Font baseFont, InputStream in)
throws IOException {
SyntaxSchemeLoader parser = null;
try {
XMLReader reader = XMLReaderFactory.createXMLReader();
parser = new SyntaxSchemeLoader(baseFont);
parser.baseFont = baseFont;
reader.setContentHandler(parser);
InputSource is = new InputSource(in);
is.setEncoding("UTF-8");
reader.parse(is);
} catch (SAXException se) {
throw new IOException(se.toString());
}
return parser.scheme;
}
示例3: getFileChecksum
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
private FileChecksum getFileChecksum(String f) throws IOException {
final HttpURLConnection connection = openConnection(
"/fileChecksum" + ServletUtil.encodePath(f),
"ugi=" + getEncodedUgiParameter());
try {
final XMLReader xr = XMLReaderFactory.createXMLReader();
xr.setContentHandler(this);
xr.parse(new InputSource(connection.getInputStream()));
} catch(SAXException e) {
final Exception embedded = e.getException();
if (embedded != null && embedded instanceof IOException) {
throw (IOException)embedded;
}
throw new IOException("invalid xml directory content", e);
} finally {
connection.disconnect();
}
return filechecksum;
}
示例4: instantiateXMLService
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
public static Object instantiateXMLService(String serviceName) throws Exception {
ClassLoader backup = Thread.currentThread().getContextClassLoader();
try {
// set thread context class loader to module class loader
Thread.currentThread().setContextClassLoader(XMLFactoryHelper.class.getClassLoader());
if (serviceName.equals("org.xml.sax.XMLReader"))
return XMLReaderFactory.createXMLReader();
else if (serviceName.equals("javax.xml.validation.SchemaFactory"))
return Class.forName(serviceName).getMethod("newInstance", String.class)
.invoke(null, W3C_XML_SCHEMA_NS_URI);
else
return Class.forName(serviceName).getMethod("newInstance").invoke(null);
} finally {
Thread.currentThread().setContextClassLoader(backup);
}
}
示例5: fillMaps
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
private static void fillMaps() throws IOException {
Logger log = Logger.getInstance(UnsupportedFeaturesUtil.class.getName());
FileReader reader = new FileReader(PythonHelpersLocator.getHelperPath("/tools/versions.xml"));
try {
XMLReader xr = XMLReaderFactory.createXMLReader();
VersionsParser parser = new VersionsParser();
xr.setContentHandler(parser);
xr.parse(new InputSource(reader));
}
catch (SAXException e) {
log.error("Improperly formed \"versions.xml\". " + e.getMessage());
}
finally {
reader.close();
}
}
示例6: xsltprocess
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
public void xsltprocess(String[] args) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException {
// 1. Instantiate a TransformerFactory.
SAXTransformerFactory tFactory = (SAXTransformerFactory) TransformerFactory.newInstance();
// 2. Use the TransformerFactory to process the stylesheet Source and
// generate a Transformer.
InputStream is = getClass().getResourceAsStream("xmg2pol.xsl");
Transformer transformer = tFactory.newTransformer (new StreamSource(is));
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "polarities.dtd,xml");
transformer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
// 3. Use the Transformer to transform an XML Source and send the
// output to a Result object.
try {
String input = args[0];
String output= args[1];
SAXSource saxs = new SAXSource(new InputSource(input));
XMLReader saxReader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
saxReader.setEntityResolver(new MyEntityResolver());
saxs.setXMLReader(saxReader);
transformer.transform(saxs, new StreamResult(new OutputStreamWriter(new FileOutputStream(output), "utf-8")));
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: parse
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
public static void parse(DefaultHandler handler, String file) throws SAXException, IOException {
XMLReader xreader = XMLReaderFactory.createXMLReader();
xreader.setContentHandler(handler);
xreader.setErrorHandler(handler);
FileReader reader = new FileReader(file);
xreader.parse(new InputSource(reader));
}
示例8: testAnalyzePom
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
@Test
public void testAnalyzePom(){
try {
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
PomDependencyHandler handler = new PomDependencyHandler();
xmlReader.setContentHandler(handler);
xmlReader.parse(new InputSource(this.getClass().getClassLoader().getResourceAsStream("testpom.xml")));
assertEquals(4, handler.getDependencies().size());
PomInfo pom = handler.getPomInfo();
boolean hasVI=false;
for (PomDependency d : handler.getDependencies()) {
assertNotNull(d.artifactId);
assertNotNull(d.groupId);
assertNotNull(d.version);
if("framework-validateinternals".equals(d.artifactId)){
hasVI=true;
assertEquals(d.version,"0.9");
}
}
assertTrue(hasVI);
}catch (Exception e){
e.printStackTrace();
}
}
示例9: parse
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
public Danmakus parse() {
if (this.mDataSource != null) {
AndroidFileSource source = this.mDataSource;
try {
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
XmlContentHandler contentHandler = new XmlContentHandler();
xmlReader.setContentHandler(contentHandler);
xmlReader.parse(new InputSource(source.data()));
return contentHandler.getResult();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
}
return null;
}
示例10: processSource
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
protected Source processSource(Source source) {
if (source instanceof StreamSource) {
StreamSource streamSource = (StreamSource) source;
InputSource inputSource = new InputSource(streamSource.getInputStream());
try {
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
String featureName = "http://xml.org/sax/features/external-general-entities";
xmlReader.setFeature(featureName, isProcessExternalEntities());
if (!isProcessExternalEntities()) {
xmlReader.setEntityResolver(NO_OP_ENTITY_RESOLVER);
}
return new SAXSource(xmlReader, inputSource);
}
catch (SAXException ex) {
logger.warn("Processing of external entities could not be disabled", ex);
return source;
}
}
else {
return source;
}
}
示例11: main
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {
XMLReader xr = XMLReaderFactory.createXMLReader();
BugCollection bugCollection = new SortedBugCollection();
Project project = new Project();
SAXBugCollectionHandler handler = new SAXBugCollectionHandler(bugCollection, project);
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
// Parse each file provided on the
// command line.
for (int i = 0; i < argv.length; i++) {
FileReader r = new FileReader(argv[i]);
xr.parse(new InputSource(r));
}
}
示例12: fetchList
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
private void fetchList(String path, boolean recur) throws IOException {
try {
XMLReader xr = XMLReaderFactory.createXMLReader();
xr.setContentHandler(this);
HttpURLConnection connection = openConnection(
"/listPaths" + ServletUtil.encodePath(path),
"ugi=" + getEncodedUgiParameter() + (recur ? "&recursive=yes" : ""));
InputStream resp = connection.getInputStream();
xr.parse(new InputSource(resp));
} catch(SAXException e) {
final Exception embedded = e.getException();
if (embedded != null && embedded instanceof IOException) {
throw (IOException)embedded;
}
throw new IOException("invalid xml directory content", e);
}
}
示例13: getContentSummary
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
/**
* Connect to the name node and get content summary.
* @param path The path
* @return The content summary for the path.
* @throws IOException
*/
private ContentSummary getContentSummary(String path) throws IOException {
final HttpURLConnection connection = openConnection(
"/contentSummary" + ServletUtil.encodePath(path),
"ugi=" + getEncodedUgiParameter());
InputStream in = null;
try {
in = connection.getInputStream();
final XMLReader xr = XMLReaderFactory.createXMLReader();
xr.setContentHandler(this);
xr.parse(new InputSource(in));
} catch(FileNotFoundException fnfe) {
//the server may not support getContentSummary
return null;
} catch(SAXException saxe) {
final Exception embedded = saxe.getException();
if (embedded != null && embedded instanceof IOException) {
throw (IOException)embedded;
}
throw new IOException("Invalid xml format", saxe);
} finally {
if (in != null) {
in.close();
}
connection.disconnect();
}
return contentsummary;
}
示例14: decode
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
/** This will unmarshal the input XML into a List of FormKey objects.
* @param historyNavXml The XML representation of the historyNavList.
* @return The List of FormKey objects.
*/
public static List decode(String historyNavXml) {
List historyNavList = null;
try {
// The following step may seem out of place.
// And the correct thing to do is to probably do a convertToHtml() on the String returned by the encode() method.
// However, on a Post, the browser implicitly converts all the entities to corresponding characters.
// Hence the need for the following step !!
historyNavXml = StringHelper.replace(historyNavXml, "&", "&");
if (log.isDebugEnabled())
log.debug("Unmarshalling the historyNavXml " + historyNavXml);
XMLReader reader = XMLReaderFactory.createXMLReader();
HistoryNavHandler handler = new HistoryNavHandler();
reader.setContentHandler(handler);
reader.parse(new InputSource(new BufferedReader(new StringReader(historyNavXml))));
historyNavList = handler.getHistoryNavList();
} catch (Exception e) {
if (log.isInfoEnabled())
log.info("Error while parsing the historyNavXml " + historyNavXml, e);
}
if (log.isDebugEnabled())
log.debug("Unmarshalled List: " + historyNavList);
return historyNavList;
}
示例15: main
import org.xml.sax.helpers.XMLReaderFactory; //导入依赖的package包/类
/**
public static void main(String[] args) {
TestRunner.run(JDK6770436Test.class);
}
*/
@Test
public void entityCallbackOrderJava() throws SAXException, IOException {
final String input = "<element> & some more text</element>";
final MockContentHandler handler = new MockContentHandler();
final XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(handler);
xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
xmlReader.parse(new InputSource(new StringReader(input)));
final List<String> events = handler.getEvents();
printEvents(events);
assertCallbackOrder(events); //regression from JDK5
}