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


Java XMLFilter类代码示例

本文整理汇总了Java中org.xml.sax.XMLFilter的典型用法代码示例。如果您正苦于以下问题:Java XMLFilter类的具体用法?Java XMLFilter怎么用?Java XMLFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XMLFilter类属于org.xml.sax包,在下文中一共展示了XMLFilter类的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: newXMLFilter

import org.xml.sax.XMLFilter; //导入依赖的package包/类
/**
 * javax.xml.transform.sax.SAXTransformerFactory implementation.
 * Create an XMLFilter that uses the given source as the
 * transformation instructions.
 *
 * @param templates The source of the transformation instructions.
 * @return An XMLFilter object, or null if this feature is not supported.
 * @throws TransformerConfigurationException
 */
@Override
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException
{
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch (TransformerConfigurationException e1) {
        if (_errorListener != null) {
            try {
                _errorListener.fatalError(e1);
                return null;
            }
            catch (TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:TransformerFactoryImpl.java

示例3: newXMLFilter

import org.xml.sax.XMLFilter; //导入依赖的package包/类
/**
 * Create an XMLFilter that uses the given source as the
 * transformation instructions. Uses
 * com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactory.
 */
public XMLFilter newXMLFilter(Source src)
    throws TransformerConfigurationException {
    if (_xsltcFactory == null) {
        createXSLTCTransformerFactory();
    }
    if (_errorlistener != null) {
        _xsltcFactory.setErrorListener(_errorlistener);
    }
    if (_uriresolver != null) {
        _xsltcFactory.setURIResolver(_uriresolver);
    }
    Templates templates = _xsltcFactory.newTemplates(src);
    if (templates == null ) return null;
    return newXMLFilter(templates);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:SmartTransformerFactoryImpl.java

示例4: 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

示例5: 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

示例6: 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

示例7: getXmlFilter

import org.xml.sax.XMLFilter; //导入依赖的package包/类
/**
 * Returns the SAX XML filter applying the transform sheet to its input.
 * 
 * @return The SAX XML filter.
 * @throws IOException
 */
public XMLFilter getXmlFilter() throws IOException {
    XMLFilter result = null;
    final Templates templates = getTemplates();

    if (templates != null) {
        try {
            result = getSaxTransformerFactory().newXMLFilter(templates);
        } catch (TransformerConfigurationException tce) {
            throw new IOException("Transformer configuration exception. "
                    + tce.getMessage());
        }
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:22,代码来源:TransformRepresentation.java

示例8: 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

示例9: 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

示例10: getXMLFilter

import org.xml.sax.XMLFilter; //导入依赖的package包/类
@Override
public XMLFilter getXMLFilter(ArgFactory arf, InputCommandFactory.InputCommand inputBase, CommandType maxType) {
    this.inputBase = inputBase;
    if (!init(parser.parse(arf.getArgs(parser.recognizedOptions().keySet())))) {
        return null;
    }
    CommandFactory.conditionalInit(first, inputBase, EXPECT_INPUT);
    JoiningXMLFilter joiner = new JoiningXMLFilter(!joinAll);
    if (first && inputBase.filesFrom != null) {
        joiner.setInputType(QueueSourceXMLFilter.InputType.indirect);
        if (inputBase.delim != null) {
            joiner.setDelimiterPattern(Pattern.compile(inputBase.delim, Pattern.LITERAL));
        }
    }
    return joiner;
}
 
开发者ID:upenn-libraries,项目名称:xmlaminar,代码行数:17,代码来源:JoinCommand.java

示例11: getXMLFilter

import org.xml.sax.XMLFilter; //导入依赖的package包/类
@Override
public XMLFilter getXMLFilter(ArgFactory arf, InitCommand inputBase, CommandType maxType) {
    String[] args = arf.getArgs(Collections.EMPTY_SET);
    if (args.length != 1) {
        throw new IllegalArgumentException("Command \"" + getKey() + "\" should have only one argument: dumpfile");
    }
    this.inputBase = inputBase;
    File df = new File(args[0]);
    DumpingXMLFilter dxf = new DumpingXMLFilter();
    String path = df.getPath();
    if ("-".equals(path)) {
        dxf.setDumpStream(System.out);
    } else if ("-h".equals(path) || "--help".equals(path)) {
        return null;
    } else {
        dxf.setDumpFile(df);
    }
    return dxf;
}
 
开发者ID:upenn-libraries,项目名称:xmlaminar,代码行数:20,代码来源:TeeCommandFactory.java

示例12: getXMLFilter

import org.xml.sax.XMLFilter; //导入依赖的package包/类
@Override
public XMLFilter getXMLFilter(ArgFactory arf, InputCommandFactory.InputCommand inputBase, CommandType maxType) {
    if (txf != null) {
        return txf;
    }
    if (!init(parser.parse(arf.getArgs(parser.recognizedOptions().keySet())), inputBase)) {
        return null;
    }
    CommandFactory.conditionalInit(first, inputBase, EXPECT_INPUT);
    try {
        txf = new TXMLFilter(new StreamSource(xsl), recordIdXPath, subdivide, recordDepth);
    } catch (TransformerConfigurationException ex) {
        throw new RuntimeException(ex);
    }
    if (first && inputBase.filesFrom != null) {
        txf.setInputType(QueueSourceXMLFilter.InputType.indirect);
        if (inputBase.delim != null) {
            txf.setDelimiterPattern(Pattern.compile(inputBase.delim, Pattern.LITERAL));
        }
    }
    return txf;
}
 
开发者ID:upenn-libraries,项目名称:xmlaminar,代码行数:23,代码来源:ProcessCommandFactory.java

示例13: getXMLFilter

import org.xml.sax.XMLFilter; //导入依赖的package包/类
@Override
public XMLFilter getXMLFilter(ArgFactory arf, InputCommandFactory.InputCommand inputBase, CommandType maxType) {
    if (ret != null) {
        return ret;
    }
    this.inputBase = inputBase;
    if (!init(parser.parse(parseMainOut(arf.getArgs(parser.recognizedOptions().keySet()))), inputBase)) {
        return null;
    }
    if (first || !last) {
        throw new IllegalArgumentException(KEY + " command must be last, and must not be first");
    }
    String inBaseSystemId = inputBase.input.getSystemId();
    File inBaseFile = inBaseSystemId == null ? null : new File(inBaseSystemId);
    ret = new OutputXMLFilter(inBaseFile, output, baseName, suffixLength, outputExtension, noIndent, gzipOutput);
    return ret;
}
 
开发者ID:upenn-libraries,项目名称:xmlaminar,代码行数:18,代码来源:OutputCommandFactory.java

示例14: getXMLFilter

import org.xml.sax.XMLFilter; //导入依赖的package包/类
@Override
public XMLFilter getXMLFilter(ArgFactory arf, InputCommandFactory.InputCommand inputBase, CommandType maxType) {
    if (!init(parser.parse(arf.getArgs(parser.recognizedOptions().keySet())), inputBase)) {
        return null;
    }
    CommandFactory.conditionalInit(first, inputBase, EXPECT_INPUT);
    SAXSolrPoster ssp = new SAXSolrPoster();
    ssp.setServer(new ConcurrentUpdateSolrServer(solrURL, queueSize, threadCount));
    if (first && inputBase.getFilesFrom() != null) {
        ssp.setInputType(QueueSourceXMLFilter.InputType.indirect);
        if (inputBase.getDelim() != null) {
            ssp.setDelimiterPattern(Pattern.compile(inputBase.getDelim(), Pattern.LITERAL));
        }
    }
    return ssp;
}
 
开发者ID:upenn-libraries,项目名称:xmlaminar,代码行数:17,代码来源:SolrPostCommandFactory.java

示例15: createXMLReader

import org.xml.sax.XMLFilter; //导入依赖的package包/类
private void createXMLReader(XMLReader paramXMLReader)
{
  if (paramXMLReader == null)
  {
    this.xmlReader = new SaxWriter();
  }
  else if ((paramXMLReader instanceof XMLFilter))
  {
    for (XMLFilter localXMLFilter = (XMLFilter)paramXMLReader; (localXMLFilter.getParent() instanceof XMLFilter); localXMLFilter = (XMLFilter)localXMLFilter.getParent());
    if (!(localXMLFilter.getParent() instanceof SaxWriter))
      localXMLFilter.setParent(new SaxWriter());
    this.xmlReader = paramXMLReader;
  }
  else
  {
    throw new UnsupportedOperationException();
  }
  configureXMLReader();
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:20,代码来源:TraxSource.java


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