當前位置: 首頁>>代碼示例>>Java>>正文


Java SAXParserFactory類代碼示例

本文整理匯總了Java中javax.xml.parsers.SAXParserFactory的典型用法代碼示例。如果您正苦於以下問題:Java SAXParserFactory類的具體用法?Java SAXParserFactory怎麽用?Java SAXParserFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SAXParserFactory類屬於javax.xml.parsers包,在下文中一共展示了SAXParserFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convert

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
/**
 * Creates the image for the given display XML input source. (Note: The XML
 * is an encoded mxGraphView, not mxGraphModel.)
 * 
 * @param inputSource
 *            Input source that contains the display XML.
 * @return Returns an image representing the display XML input source.
 */
public static BufferedImage convert(InputSource inputSource,
		mxGraphViewImageReader viewReader)
		throws ParserConfigurationException, SAXException, IOException
{
	BufferedImage result = null;
	SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
	XMLReader reader = parser.getXMLReader();

	reader.setContentHandler(viewReader);
	reader.parse(inputSource);

	if (viewReader.getCanvas() instanceof mxImageCanvas)
	{
		result = ((mxImageCanvas) viewReader.getCanvas()).destroy();
	}

	return result;
}
 
開發者ID:GDSRS,項目名稱:TrabalhoFinalEDA2,代碼行數:27,代碼來源:mxGraphViewImageReader.java

示例2: testDefaultHandler

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
/**
 * Test default handler that transverses XML and  print all visited node.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testDefaultHandler() throws Exception {
    String outputFile = USER_DIR + "DefaultHandler.out";
    String goldFile = GOLDEN_DIR + "DefaultHandlerGF.out";
    String xmlFile = XML_DIR + "namespace1.xml";

    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    SAXParser saxparser = spf.newSAXParser();

    MyDefaultHandler handler = new MyDefaultHandler(outputFile);
    File file = new File(xmlFile);
    String Absolutepath = file.getAbsolutePath();
    String newAbsolutePath = Absolutepath;
    if (File.separatorChar == '\\')
            newAbsolutePath = Absolutepath.replace('\\', '/');
    saxparser.parse("file:///" + newAbsolutePath, handler);

    assertTrue(compareWithGold(goldFile, outputFile));

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:DefaultHandlerTest.java

示例3: getFromFile

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
@NonNull
public static RepoDetails getFromFile(InputStream inputStream, int pushRequests) {
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        SAXParser parser = factory.newSAXParser();
        XMLReader reader = parser.getXMLReader();
        RepoDetails repoDetails = new RepoDetails();
        MockRepo mockRepo = new MockRepo(100, pushRequests);
        RepoXMLHandler handler = new RepoXMLHandler(mockRepo, repoDetails);
        reader.setContentHandler(handler);
        InputSource is = new InputSource(new BufferedInputStream(inputStream));
        reader.parse(is);
        return repoDetails;
    } catch (ParserConfigurationException | SAXException | IOException e) {
        e.printStackTrace();
        fail();

        // Satisfies the compiler, but fail() will always throw a runtime exception so we never
        // reach this return statement.
        return null;
    }
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:24,代碼來源:RepoDetails.java

示例4: newSAXParser

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
/**
 * Create a <code>SAXParser</code> configured to support XML Schema and DTD
 * @param properties parser specific properties/features
 * @return an XML Schema/DTD enabled <code>SAXParser</code>
 */
public static SAXParser newSAXParser(Properties properties)
        throws ParserConfigurationException, 
               SAXException,
               SAXNotRecognizedException{ 

    SAXParserFactory factory = 
                    (SAXParserFactory)properties.get("SAXParserFactory");
    SAXParser parser = factory.newSAXParser();
    String schemaLocation = (String)properties.get("schemaLocation");
    String schemaLanguage = (String)properties.get("schemaLanguage");

    try{
        if (schemaLocation != null) {
            parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
            parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
        }
    } catch (SAXNotRecognizedException e){
        log.info(parser.getClass().getName() + ": "  
                                    + e.getMessage() + " not supported."); 
    }
    return parser;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:28,代碼來源:GenericParser.java

示例5: scan

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
/**
 * Identify available locales
 * @param locales_directory
 * @return
 */
public Map<String, String> scan(String locales_directory) throws IOException {
    final Map<String, String> locale_map = new HashMap<String, String>();

    String[] files = PhoeniciaContext.assetManager.list(locales_directory);
    for (String locale_dir: files) {
        if (locale_dir.equals("common")) continue;
        String locale_path = locales_directory+"/"+locale_dir+"/manifest.xml";
        LocaleHeaderScanner scanner = new LocaleHeaderScanner(locale_path, locale_map);
        try {
            InputStream locale_manifest_in = PhoeniciaContext.assetManager.open(locale_path);
            final SAXParserFactory spf = SAXParserFactory.newInstance();
            final SAXParser sp = spf.newSAXParser();
            final XMLReader xr = sp.getXMLReader();
            xr.setContentHandler(scanner);
            xr.parse(new InputSource(new BufferedInputStream(locale_manifest_in)));
        } catch (Exception e) {
            Debug.e(e);
        }
    }
    return locale_map;
}
 
開發者ID:Linguaculturalists,項目名稱:Phoenicia,代碼行數:27,代碼來源:LocaleManager.java

示例6: getSearchWords

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
private static String getSearchWords(String xml) {
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();

        ItemXMLHandler myXMLHandler = new ItemXMLHandler();
        xr.setContentHandler(myXMLHandler);
        InputSource inStream = new InputSource();

        inStream.setCharacterStream(new StringReader(xml));
        xr.parse(inStream);

        return myXMLHandler.getCollectedNodes();

    } catch (ParserConfigurationException | SAXException | IOException e) {
        e.printStackTrace();
    }
    return "";
}
 
開發者ID:ABTSoftware,項目名稱:SciChart.Android.Examples,代碼行數:21,代碼來源:ExampleSourceCodeParser.java

示例7: parseXML

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
/**Parses the XML to fetch parameters.
 * @param inputFile, source XML  
 * @return true, if XML is successfully parsed.
 * @throws Exception 
 */
public boolean parseXML(File inputFile,UIComponentRepo componentRepo) throws ParserConfigurationException, SAXException, IOException{
     LOGGER.debug("Parsing target XML for separating Parameters");
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser;
	try {
		factory.setFeature(Constants.DISALLOW_DOCTYPE_DECLARATION,true);
		saxParser = factory.newSAXParser();
		XMLHandler xmlhandler = new XMLHandler(componentRepo);
		saxParser.parse(inputFile, xmlhandler);
		return true;
	} catch (ParserConfigurationException | SAXException | IOException exception) {
		 LOGGER.error("Parsing failed...",exception);
		throw exception; 
	}
  }
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:21,代碼來源:XMLParser.java

示例8: main

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    try {
        SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
        saxParserFactory.setNamespaceAware(true);

        SAXParser saxParser = saxParserFactory.newSAXParser();

        ParserVocabulary referencedVocabulary = new ParserVocabulary();

        VocabularyGenerator vocabularyGenerator = new VocabularyGenerator(referencedVocabulary);
        File f = new File(args[0]);
        saxParser.parse(f, vocabularyGenerator);

        printVocabulary(referencedVocabulary);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:22,代碼來源:PrintTable.java

示例9: testCheckSchemaSupport3

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
/**
 * Test the default functionality of schema support method. In
 * this case the schema source property is set.
 * @throws Exception If any errors occur.
 */
@Test(dataProvider = "schema-source")
public void testCheckSchemaSupport3(Object schemaSource) throws Exception {
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setValidating(true);
        spf.setNamespaceAware(true);
        SAXParser sp = spf.newSAXParser();
        sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                W3C_XML_SCHEMA_NS_URI);
        sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", schemaSource);
        DefaultHandler dh = new DefaultHandler();
        // Not expect any unrecoverable error here.
        sp.parse(new File(XML_DIR, "test1.xml"), dh);
    } finally {
        if (schemaSource instanceof Closeable) {
            ((Closeable) schemaSource).close();
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:DocumentBuilderFactoryTest.java

示例10: testFactoryFind

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
@Test
public void testFactoryFind() {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    Assert.assertTrue(factory.getClass().getClassLoader() == null);

    runWithAllPerm(() -> Thread.currentThread().setContextClassLoader(null));
    factory = SAXParserFactory.newInstance();
    Assert.assertTrue(factory.getClass().getClassLoader() == null);

    runWithAllPerm(() -> Thread.currentThread().setContextClassLoader(new MyClassLoader()));
    factory = SAXParserFactory.newInstance();
    if (System.getSecurityManager() == null)
        Assert.assertTrue(myClassLoaderUsed);
    else
        Assert.assertFalse(myClassLoaderUsed);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:FactoryFindTest.java

示例11: setFeature01

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
/**
 * Set namespaces feature to a value to XMLFilter. it's expected same when
 * obtain it again.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void setFeature01() throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);

    XMLFilterImpl xmlFilter = new XMLFilterImpl();
    xmlFilter.setParent(spf.newSAXParser().getXMLReader());
    xmlFilter.setFeature(NAMESPACES, false);
    assertFalse(xmlFilter.getFeature(NAMESPACES));
    xmlFilter.setFeature(NAMESPACES, true);
    assertTrue(xmlFilter.getFeature(NAMESPACES));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:XMLFilterTest.java

示例12: DefenseInboundAdapter

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
public DefenseInboundAdapter(AdapterDefinition definition) throws ComponentException, ParserConfigurationException, SAXException, IOException
{
	super(definition);
	messageParser = new MessageParser(this);
	saxFactory = SAXParserFactory.newInstance();
	saxParser = saxFactory.newSAXParser();
}
 
開發者ID:Esri,項目名稱:defense-solutions-proofs-of-concept,代碼行數:8,代碼來源:DefenseInboundAdapter.java

示例13: testSAXParserFactoryInWhiteList

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
/**
 * Test we have set features the way we expect as defaults.
 */
public void testSAXParserFactoryInWhiteList() throws Throwable
{
    // Using constructor rather than the service locator and then using the helper to configure it.
    SAXParserFactory spf = new SAXParserFactoryImpl();
    FactoryHelper factoryHelper = new FactoryHelper();
    List<String> whiteListClasses = Collections.singletonList(getClass().getName());
    factoryHelper.configureFactory(spf, FactoryHelper.DEFAULT_FEATURES_TO_ENABLE,
            FactoryHelper.DEFAULT_FEATURES_TO_DISABLE,
            whiteListClasses);

    assertFalse(spf.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
    assertFalse(spf.getFeature(FactoryHelper.FEATURE_DISALLOW_DOCTYPE));

    assertTrue(spf.getFeature(FactoryHelper.FEATURE_EXTERNAL_GENERAL_ENTITIES));
    assertTrue(spf.getFeature(FactoryHelper.FEATURE_EXTERNAL_PARAMETER_ENTITIES));
    assertTrue(spf.getFeature(FactoryHelper.FEATURE_USE_ENTITY_RESOLVER2));
    assertTrue(spf.getFeature(FactoryHelper.FEATURE_LOAD_EXTERNAL_DTD));

    assertFalse(spf.isXIncludeAware()); // false is the default so is same as the non whitelist test
}
 
開發者ID:Alfresco,項目名稱:alfresco-xml-factory,代碼行數:24,代碼來源:AppTest.java

示例14: findLine

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
/**
 * Find the line number of a target in an Ant script, or some other line in an XML file.
 * Able to find a certain element with a certain attribute matching a given value.
 * See also AntTargetNode.TargetOpenCookie.
 * @param file an Ant script or other XML file
 * @param match the attribute value to match (e.g. target name)
 * @param elementLocalName the (local) name of the element to look for
 * @param elementAttributeName the name of the attribute to match on
 * @return the line number (0-based), or -1 if not found
 */
static final int findLine(FileObject file, final String match, final String elementLocalName, final String elementAttributeName) throws IOException, SAXException, ParserConfigurationException {
    InputSource in = new InputSource(file.getURL().toString());
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    SAXParser parser = factory.newSAXParser();
    final int[] line = new int[] {-1};
    class Handler extends DefaultHandler {
        private Locator locator;
        public void setDocumentLocator(Locator l) {
            locator = l;
        }
        public void startElement(String uri, String localname, String qname, Attributes attr) throws SAXException {
            if (line[0] == -1) {
                if (localname.equals(elementLocalName) && match.equals(attr.getValue(elementAttributeName))) { // NOI18N
                    line[0] = locator.getLineNumber() - 1;
                }
            }
        }
    }
    parser.parse(in, new Handler());
    return line[0];
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:33,代碼來源:JavaActions.java

示例15: setupReaders

import javax.xml.parsers.SAXParserFactory; //導入依賴的package包/類
/**
 * Setup readers.
 */
public void setupReaders() {
  SAXParserFactory spf = catalogManager.useServicesMechanism() ?
                  SAXParserFactory.newInstance() : new SAXParserFactoryImpl();
  spf.setNamespaceAware(true);
  spf.setValidating(false);

  SAXCatalogReader saxReader = new SAXCatalogReader(spf);

  saxReader.setCatalogParser(null, "XMLCatalog",
                             "com.sun.org.apache.xml.internal.resolver.readers.XCatalogReader");

  saxReader.setCatalogParser(OASISXMLCatalogReader.namespaceName,
                             "catalog",
                             "com.sun.org.apache.xml.internal.resolver.readers.ExtendedXMLCatalogReader");

  addReader("application/xml", saxReader);

  TR9401CatalogReader textReader = new TR9401CatalogReader();
  addReader("text/plain", textReader);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:24,代碼來源:Resolver.java


注:本文中的javax.xml.parsers.SAXParserFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。