本文整理汇总了Java中org.xml.sax.XMLReader.setEntityResolver方法的典型用法代码示例。如果您正苦于以下问题:Java XMLReader.setEntityResolver方法的具体用法?Java XMLReader.setEntityResolver怎么用?Java XMLReader.setEntityResolver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xml.sax.XMLReader
的用法示例。
在下文中一共展示了XMLReader.setEntityResolver方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildItemList
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@Override
protected List<FeedItem> buildItemList() throws SAXException, ParserConfigurationException, IOException {
XMLReader reader = XMLUtil.createXMLReader( false, true );
FeedHandler handler = new FeedHandler( getMaxItemCount() );
reader.setContentHandler( handler );
reader.setEntityResolver( org.openide.xml.EntityCatalog.getDefault() );
reader.setErrorHandler( new ErrorCatcher() );
reader.parse( findInputSource(new URL(url1)) );
ArrayList<FeedItem> res = new ArrayList<FeedItem>( 2*getMaxItemCount() );
res.addAll( handler.getItemList() );
handler = new FeedHandler( getMaxItemCount() );
reader.setContentHandler( handler );
reader.parse( findInputSource(new URL(url2)) );
res.addAll( handler.getItemList() );
List<FeedItem> items = sortNodes( res );
if( items.size() > getMaxItemCount() ) {
items = items.subList( 0, getMaxItemCount() );
}
return items;
}
示例2: readDriverFromFile
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
private static JDBCDriver readDriverFromFile(FileObject fo) throws IOException, MalformedURLException {
Handler handler = new Handler();
// parse the XM file
try {
XMLReader reader = XMLUtil.createXMLReader();
InputSource is = new InputSource(fo.getInputStream());
is.setSystemId(fo.toURL().toExternalForm());
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.setEntityResolver(EntityCatalog.getDefault());
reader.parse(is);
} catch (SAXException ex) {
throw new IOException(ex.getMessage());
}
// read the driver from the handler
URL[] urls = new URL[handler.urls.size()];
int j = 0;
for (Iterator i = handler.urls.iterator(); i.hasNext(); j++) {
urls[j] = new URL((String)i.next());
}
if (checkClassPathDrivers(handler.clazz, urls) == false) {
return null;
}
if (handler.displayName == null) {
handler.displayName = handler.name;
}
return JDBCDriver.create(handler.name, handler.displayName, handler.clazz, urls);
}
示例3: xsltprocess
import org.xml.sax.XMLReader; //导入方法依赖的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();
}
}
示例4: parse
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
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();
}
示例5: testResolver
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
* 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));
}
示例6: read
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@Override
public Object read(Reader r) throws IOException, ClassNotFoundException {
Lookup lkp = findContext(r);
FileObject fo = lkp.lookup(FileObject.class);
String displayName = fo.getFileSystem().getDecorator().annotateName(fo.getName(), Collections.singleton(fo));
try {
XMLReader reader = XMLUtil.createXMLReader(true);
ToolbarParser parser = new ToolbarParser();
reader.setContentHandler(parser);
reader.setErrorHandler(parser);
reader.setEntityResolver(EntityCatalog.getDefault());
reader.parse(new InputSource(r));
return parser.createToolbarConfiguration( fo.getName(), displayName );
} catch( SAXException saxE ) {
IOException ioE = new IOException();
ioE.initCause(saxE);
throw ioE;
}
}
示例7: instanceCreate
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@Override
@NonNull
public synchronized RemotePlatform instanceCreate() throws IOException, ClassNotFoundException {
RemotePlatform remotePlatform = platformRef == null ? null : platformRef.get();
if (remotePlatform == null) {
final SAXHandler handler = new SAXHandler();
try (InputStream in = store.getPrimaryFile().getInputStream()) {
final XMLReader reader = XMLUtil.createXMLReader();
InputSource is = new InputSource(in);
is.setSystemId(store.getPrimaryFile().toURL().toExternalForm());
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.setEntityResolver(handler);
reader.parse(is);
} catch (SAXException ex) {
final Exception x = ex.getException();
if (x instanceof java.io.IOException) {
throw (IOException)x;
} else {
throw new java.io.IOException(ex);
}
}
remotePlatform = RemotePlatform.create(
handler.name,
handler.properties,
handler.sysProperties);
remotePlatform.addPropertyChangeListener(this);
platformRef = new WeakReference<>(remotePlatform);
}
return remotePlatform;
}
示例8: testCatalogResolver
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@Test(dataProvider = "catalog")
public void testCatalogResolver(String test, String expected, String catalogFile,
String xml, SAXParser saxParser) throws Exception {
URI catalog = null;
if (catalogFile != null) {
catalog = getClass().getResource(catalogFile).toURI();
}
String url = getClass().getResource(xml).getFile();
try {
CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalog);
XMLReader reader = saxParser.getXMLReader();
reader.setEntityResolver(cr);
MyHandler handler = new MyHandler(saxParser);
reader.setContentHandler(handler);
reader.parse(url);
System.out.println(test + ": expected [" + expected + "] <> actual [" + handler.getResult() + "]");
Assert.assertEquals(handler.getResult(), expected);
} catch (SAXException | IOException e) {
Assert.fail(e.getMessage());
}
}
示例9: doTests
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public void doTests() throws Exception {
String fileName ;
fileName = "torture.xml";
/* The tests do not check for content length */
StringMsgParser.setComputeContentLengthFromMessage(true);
try {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
XMLReader saxParser = saxParserFactory.newSAXParser()
.getXMLReader();
saxParser.setEntityResolver(new MyEntityResolver());
saxParser.setContentHandler(this);
saxParser
.setFeature("http://xml.org/sax/features/validation", true);
saxParser.parse(new InputSource ( Torture.class.getResourceAsStream(fileName)));
System.out.println("Elapsed time = "
+ (System.currentTimeMillis() - startTime) / counter);
} catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
}
示例10: load
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public static void load(ThemeNULL theme, InputStream in) throws IOException {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setValidating(true);
try {
SAXParser parser = spf.newSAXParser();
XMLReader reader = parser.getXMLReader();
XmlHandler handler = new XmlHandler();
handler.theme = theme;
reader.setEntityResolver(handler);
reader.setContentHandler(handler);
reader.setDTDHandler(handler);
reader.setErrorHandler(handler);
InputSource is = new InputSource(in);
is.setEncoding("UTF-8");
reader.parse(is);
} catch (/*SAX|ParserConfiguration*/Exception se) {
se.printStackTrace();
throw new IOException(se.toString());
}
}
示例11: parse
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public void parse(InputStream xml, OutputStream finf, String workingDirectory) throws Exception {
SAXParser saxParser = getParser();
SAXDocumentSerializer documentSerializer = getSerializer(finf);
XMLReader reader = saxParser.getXMLReader();
reader.setProperty("http://xml.org/sax/properties/lexical-handler", documentSerializer);
reader.setContentHandler(documentSerializer);
if (workingDirectory != null) {
reader.setEntityResolver(createRelativePathResolver(workingDirectory));
}
reader.parse(new InputSource(xml));
}
示例12: test
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
XMLReader reader = spf.newSAXParser().getXMLReader();
reader.setErrorHandler(null); // SAX 2.0.1 allows
reader.setContentHandler(null); // SAX 2.0.1 allows
reader.setEntityResolver(null); // SAX 2.0.1 allows
reader.setDTDHandler(null); // SAX 2.0.1 allows
}
示例13: getXMLReader
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
private XMLReader getXMLReader() throws SAXException {
XMLReader res = null == cachedReader ? null : cachedReader.get();
if( null == res ) {
res = XMLUtil.createXMLReader(true);
res.setEntityResolver(EntityCatalog.getDefault());
cachedReader = new WeakReference<XMLReader>(res);
}
return res;
}
示例14: parse
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
* The recognizer entry method taking an InputSource.
* @param input InputSource to be parsed.
* @throws IOException on I/O error.
* @throws SAXException propagated exception thrown by a DocumentHandler.
*/
public void parse(final InputSource input) throws SAXException, IOException {
XMLReader parser = XMLUtil.createXMLReader(false, false); // fastest mode
parser.setContentHandler(this);
parser.setErrorHandler(this);
parser.setEntityResolver(this);
parser.parse(input);
}
示例15: getXMLReader
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
private XMLReader getXMLReader() throws SAXException, ParserConfigurationException {
SAXParserFactory pfactory = SAXParserFactory.newInstance();
pfactory.setNamespaceAware(true);
// pfactory.setValidating(true);
XMLReader xmlreader = pfactory.newSAXParser().getXMLReader();
// entity resolver is used in stylesheets ra-ent.xsl,
// dec-ent.xsl. Other stylehsheets will not use it
// since they do not contain ext entities.
xmlreader.setEntityResolver(entityResolver);
return xmlreader;
}