当前位置: 首页>>代码示例>>Java>>正文


Java XMLFilter.setParent方法代码示例

本文整理汇总了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;
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:20,代码来源:JaxbUtils.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:SAXTFactoryTest.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:SAXTFactoryTest.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:SAXTFactoryTest.java

示例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;
  }
}
 
开发者ID:phax,项目名称:ph-stx,代码行数:36,代码来源:TransformerFactoryImpl.java

示例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();
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:17,代码来源:JAXBConfigImpl.java

示例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;
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:20,代码来源:JaxbUtils.java

示例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);

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:ModelLoader.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:SAXTFactoryTest.java

示例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();
}
 
开发者ID:sandor-balazs,项目名称:sentiment-analysis,代码行数:15,代码来源:AbstractXmlParser.java

示例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));
}
 
开发者ID:upenn-libraries,项目名称:xmlaminar,代码行数:12,代码来源:FilesystemXMLReaderRepo.java

示例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));
}
 
开发者ID:upenn-libraries,项目名称:xmlaminar,代码行数:9,代码来源:BufferingXMLFilter.java

示例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;
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:20,代码来源:JAXBUtil.java

示例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);
}
 
开发者ID:terraframe,项目名称:Runway-SDK,代码行数:8,代码来源:SAXSourceParser.java

示例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;
}
 
开发者ID:terraframe,项目名称:Runway-SDK,代码行数:14,代码来源:XMLHandler.java


注:本文中的org.xml.sax.XMLFilter.setParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。