本文整理汇总了Java中org.xml.sax.XMLFilter.setParent方法的典型用法代码示例。如果您正苦于以下问题:Java XMLFilter.setParent方法的具体用法?Java XMLFilter.setParent怎么用?Java XMLFilter.setParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xml.sax.XMLFilter
的用法示例。
在下文中一共展示了XMLFilter.setParent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getXMLFilterForClass
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
public static <T> XMLFilter getXMLFilterForClass(final Class<T> clazz) throws SAXException {
final XMLFilter filter;
final XmlSchema schema = clazz.getPackage().getAnnotation(XmlSchema.class);
if (schema != null) {
final String namespace = schema.namespace();
if (namespace != null && !"".equals(namespace)) {
LogUtils.tracef(clazz, "found namespace %s for class %s", namespace, clazz);
filter = new SimpleNamespaceFilter(namespace, true);
} else {
filter = new SimpleNamespaceFilter("", false);
}
} else {
filter = new SimpleNamespaceFilter("", false);
}
final XMLReader xmlReader = XMLReaderFactory.createXMLReader();
filter.setParent(xmlReader);
return filter;
}
示例2: testcase10
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
/**
* Unit test for contentHandler setter/getter along reader as handler's
* parent.
*
* @throws Exception If any errors occur.
*/
@Test
public void testcase10() throws Exception {
String outputFile = USER_DIR + "saxtf010.out";
String goldFile = GOLDEN_DIR + "saxtf010GF.out";
// The transformer will use a SAX parser as it's reader.
XMLReader reader = XMLReaderFactory.createXMLReader();
SAXTransformerFactory saxTFactory
= (SAXTransformerFactory)TransformerFactory.newInstance();
XMLFilter filter =
saxTFactory.newXMLFilter(new StreamSource(XSLT_FILE));
filter.setParent(reader);
filter.setContentHandler(new MyContentHandler(outputFile));
// Now, when you call transformer.parse, it will set itself as
// the content handler for the parser object (it's "parent"), and
// will then call the parse method on the parser.
filter.parse(new InputSource(XML_FILE));
assertTrue(compareWithGold(goldFile, outputFile));
}
示例3: testcase12
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
/**
* Unit test for contentHandler setter/getter.
*
* @throws Exception If any errors occur.
*/
@Test
public void testcase12() throws Exception {
String outputFile = USER_DIR + "saxtf012.out";
String goldFile = GOLDEN_DIR + "saxtf012GF.out";
// The transformer will use a SAX parser as it's reader.
XMLReader reader = XMLReaderFactory.createXMLReader();
InputSource is = new InputSource(new FileInputStream(XSLT_FILE));
SAXSource saxSource = new SAXSource();
saxSource.setInputSource(is);
SAXTransformerFactory saxTFactory = (SAXTransformerFactory)TransformerFactory.newInstance();
XMLFilter filter = saxTFactory.newXMLFilter(saxSource);
filter.setParent(reader);
filter.setContentHandler(new MyContentHandler(outputFile));
// Now, when you call transformer.parse, it will set itself as
// the content handler for the parser object (it's "parent"), and
// will then call the parse method on the parser.
filter.parse(new InputSource(XML_FILE));
assertTrue(compareWithGold(goldFile, outputFile));
}
示例4: testcase13
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
/**
* Unit test for TemplatesHandler setter/getter.
*
* @throws Exception If any errors occur.
*/
@Test
public void testcase13() throws Exception {
String outputFile = USER_DIR + "saxtf013.out";
String goldFile = GOLDEN_DIR + "saxtf013GF.out";
try(FileInputStream fis = new FileInputStream(XML_FILE)) {
// The transformer will use a SAX parser as it's reader.
XMLReader reader = XMLReaderFactory.createXMLReader();
SAXTransformerFactory saxTFactory
= (SAXTransformerFactory) TransformerFactory.newInstance();
TemplatesHandler thandler = saxTFactory.newTemplatesHandler();
// I have put this as it was complaining about systemid
thandler.setSystemId("file:///" + USER_DIR);
reader.setContentHandler(thandler);
reader.parse(XSLT_FILE);
XMLFilter filter
= saxTFactory.newXMLFilter(thandler.getTemplates());
filter.setParent(reader);
filter.setContentHandler(new MyContentHandler(outputFile));
filter.parse(new InputSource(fis));
}
assertTrue(compareWithGold(goldFile, outputFile));
}
示例5: newXMLFilter
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
/**
* Creates an <code>XMLFilter</code> that uses the given <code>Source</code>
* as the transformation instructions. Implementation of the
* {@link SAXTransformerFactory}
*
* @param src
* - The Source of the transformation instructions.
* @return An {@link XMLFilter} object, or <code>null</code> if this feature
* is not supported.
* @throws TransformerConfigurationException
*/
@Override
public XMLFilter newXMLFilter (final Source src) throws TransformerConfigurationException
{
if (CSTX.DEBUG)
if (log.isDebugEnabled ())
log.debug ("getting SAXTransformerFactory.FEATURE_XMLFILTER " + "from Source " + src.getSystemId ());
XMLFilter xFilter = null;
try
{
final Templates templates = newTemplates (src);
// get a XMLReader
final XMLReader parser = Processor.createXMLReader ();
xFilter = newXMLFilter (templates);
xFilter.setParent (parser);
return xFilter;
}
catch (final SAXException ex)
{
final TransformerConfigurationException tE = new TransformerConfigurationException (ex.getMessage (), ex);
m_aDefaultErrorListener.fatalError (tE);
return null;
}
}
示例6: unmarshal
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
protected org.kuali.rice.core.impl.config.property.Config unmarshal(Unmarshaller unmarshaller, InputStream in)
throws SAXException, ParserConfigurationException, IOException,
IllegalStateException, JAXBException {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
XMLFilter filter = new ConfigNamespaceURIFilter();
filter.setParent(spf.newSAXParser().getXMLReader());
UnmarshallerHandler handler = unmarshaller.getUnmarshallerHandler();
filter.setContentHandler(handler);
filter.parse(new InputSource(in));
return (org.kuali.rice.core.impl.config.property.Config) handler.getResult();
}
示例7: getXMLFilterForClass
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
public static <T> XMLFilter getXMLFilterForClass(final Class<T> clazz) throws SAXException {
final XMLFilter filter;
final XmlSchema schema = clazz.getPackage().getAnnotation(XmlSchema.class);
if (schema != null) {
final String namespace = schema.namespace();
if (namespace != null && !"".equals(namespace)) {
LogUtils.debugf(clazz, "found namespace %s for class %s", namespace, clazz);
filter = new SimpleNamespaceFilter(namespace, true);
} else {
filter = new SimpleNamespaceFilter("", false);
}
} else {
filter = new SimpleNamespaceFilter("", false);
}
final XMLReader xmlReader = XMLReaderFactory.createXMLReader();
filter.setParent(xmlReader);
return filter;
}
示例8: loadRELAXNG
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
/**
* Parses a RELAX NG grammar into an annotated grammar.
*/
private Model loadRELAXNG() throws SAXException {
// build DOM forest
final DOMForest forest = buildDOMForest( new RELAXNGInternalizationLogic() );
// use JAXP masquerading to validate the input document.
// DOMForest -> ExtensionBindingChecker -> RNGOM
XMLReaderCreator xrc = new XMLReaderCreator() {
public XMLReader createXMLReader() {
// foreset parser cannot change the receivers while it's working,
// so we need to have one XMLFilter that works as a buffer
XMLFilter buffer = new XMLFilterImpl() {
@Override
public void parse(InputSource source) throws IOException, SAXException {
forest.createParser().parse( source, this, this, this );
}
};
XMLFilter f = new ExtensionBindingChecker(Const.RELAXNG_URI,opt,errorReceiver);
f.setParent(buffer);
f.setEntityResolver(opt.entityResolver);
return f;
}
};
Parseable p = new SAXParseable( opt.getGrammars()[0], errorReceiver, xrc );
return loadRELAXNG(p);
}
示例9: testcase11
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
/**
* Unit test for contentHandler setter/getter with parent.
*
* @throws Exception If any errors occur.
*/
@Test
public void testcase11() throws Exception {
String outputFile = USER_DIR + "saxtf011.out";
String goldFile = GOLDEN_DIR + "saxtf011GF.out";
// The transformer will use a SAX parser as it's reader.
XMLReader reader = XMLReaderFactory.createXMLReader();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder docBuilder = dbf.newDocumentBuilder();
Document document = docBuilder.parse(new File(XSLT_FILE));
Node node = (Node)document;
DOMSource domSource= new DOMSource(node);
SAXTransformerFactory saxTFactory
= (SAXTransformerFactory)TransformerFactory.newInstance();
XMLFilter filter = saxTFactory.newXMLFilter(domSource);
filter.setParent(reader);
filter.setContentHandler(new MyContentHandler(outputFile));
// Now, when you call transformer.parse, it will set itself as
// the content handler for the parser object (it's "parent"), and
// will then call the parse method on the parser.
filter.parse(new InputSource(XML_FILE));
assertTrue(compareWithGold(goldFile, outputFile));
}
示例10: unmarshal
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
public static Object unmarshal(String path, String contextPath, String namespace)
throws JAXBException, SAXException, ParserConfigurationException,
IOException {
UnmarshallerHandler unmarshallerHandler = JAXBContext
.newInstance(contextPath).createUnmarshaller()
.getUnmarshallerHandler();
XMLFilter xmlFilter = new NamespaceFilter(namespace);
xmlFilter.setParent(
SAXParserFactory.newInstance().newSAXParser().getXMLReader());
xmlFilter.setContentHandler(unmarshallerHandler);
xmlFilter.parse(new InputSource(Thread.currentThread()
.getContextClassLoader().getResource(path).getPath()));
return unmarshallerHandler.getResult();
}
示例11: main
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
public static void main(String[] args) throws FileNotFoundException, TransformerConfigurationException, TransformerException, IOException {
FilesystemXMLReader instance = new FilesystemXMLReaderRepo();
instance.setFollowSymlinks(false);
XMLFilter inclRepoContents = new IncludeRepoContentsXMLFilter();
inclRepoContents.setParent(instance);
File rootFile = new File("/repo/3");
TransformerFactory tf = TransformerFactory.newInstance(TRANSFORMER_FACTORY_CLASS, null);
Transformer t = tf.newTransformer();
t.setOutputProperty(OutputKeys.INDENT, "yes");
t.transform(new SAXSource(inclRepoContents, new InputSource(rootFile.getAbsolutePath())), new StreamResult(System.out));
}
示例12: main
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Transformer t = TransformerFactory.newInstance().newTransformer();
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
XMLFilter blah = new Blah();
blah.setParent(spf.newSAXParser().getXMLReader());
t.transform(new SAXSource(blah, new InputSource("./sample.xml")), new StreamResult(System.out));
}
示例13: createFilteredSource
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
/**
* @see ImportFilter
* @see ExtensionFilter
* @see ElementFilter
*/
static
public SAXSource createFilteredSource(InputSource source, XMLFilter... filters) throws SAXException {
XMLReader reader = XMLReaderFactory.createXMLReader();
for(XMLFilter filter : filters){
filter.setParent(reader);
reader = filter;
}
SAXSource filteredSource = new SAXSource(reader, source);
return filteredSource;
}
示例14: SAXSourceParser
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
public SAXSourceParser(StreamSource source, String schemaLocation, XMLFilter filter, ImportPluginIF... plugins) throws SAXException
{
filter.setParent(this.createReader());
this.reader = filter;
this.init(new ImportManager(source, schemaLocation), plugins);
}
示例15: XMLHandler
import org.xml.sax.XMLFilter; //导入方法依赖的package包/类
public XMLHandler(ImportManager manager, XMLFilter filter) throws SAXException
{
filter.setParent(this.createReader());
reader = filter;
reader.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true);
reader.setFeature(VALIDATION_FEATURE_ID, true);
reader.setEntityResolver(new RunwayClasspathEntityResolver());
// Root Handler
this.previousHandler = null;
this.manager = manager;
}