當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。