Search in sources :

Example 76 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project Gargoyle by callakrsos.

the class FXMLPreviewLoader method start.

/**
	 * @inheritDoc
	 */
@Override
public void start(Stage primaryStage) throws Exception {
    BorderPane borderPane = new BorderPane();
    FXMLLoader loader = new FXMLLoader() {
    };
    // InputStream resourceAsStream =
    // FXMLPreviewLoader.class.getResourceAsStream("lang_ko.properties");
    //
    // loader.setResources(new PropertyResourceBundle(new
    // InputStreamReader(resourceAsStream, "UTF-8")) {
    // /*
    // * @inheritDoc
    // */
    // @Override
    // public boolean containsKey(String key) {
    // return true;
    // }
    //
    // /*
    // * @inheritDoc
    // */
    // @Override
    // public Object handleGetObject(String key) {
    // if (key == null) {
    // return "";
    // }
    //
    // Object result = null;
    //
    // try {
    // result = super.handleGetObject(key);
    // } catch (Exception e) {
    // ;
    // }
    //
    // return (result == null) ? key : result;
    // }
    // });
    // loader.setLocation(/*FXMLPreviewLoader.class.getResource("ColumnExam3.fxml")*/url);
    loader.setBuilderFactory(new BuilderFactory() {

        @Override
        public Builder<?> getBuilder(Class<?> param) {
            return new JavaFXBuilderFactory().getBuilder(param);
        }
    });
    loader.setControllerFactory(new Callback<Class<?>, Object>() {

        @Override
        public Object call(Class<?> param) {
            return null;
        }
    });
    FileInputStream inputStream = new FileInputStream(file);
    InputStream is = null;
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        FXMLSaxHandler handler = new FXMLSaxHandler(out);
        sp.parse(inputStream, handler);
        String string = out.toString("UTF-8");
        string = ValueUtil.regexReplaceMatchs("<!\\[CDATA\\[[?<a-zA-Z. *?>]+]]>", string, str -> {
            return ValueUtil.regexMatch("<\\?import [a-zA-Z.*?]+>", str);
        });
        System.out.println(string);
        byte[] bytes = string.getBytes();
        is = new ByteArrayInputStream(bytes);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // FileInputStream inputStream = new FileInputStream(file);
    borderPane.setCenter(loader.load(is));
    Scene scene = new Scene(borderPane);
    primaryStage.setScene(scene);
    primaryStage.show();
}
Also used : JavaFXBuilderFactory(javafx.fxml.JavaFXBuilderFactory) FXMLSaxHandler(com.kyj.fx.voeditor.visual.framework.parser.FXMLSaxHandler) FXMLSaxHandler(com.kyj.fx.voeditor.visual.framework.parser.FXMLSaxHandler) Scene(javafx.scene.Scene) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JavaFXBuilderFactory(javafx.fxml.JavaFXBuilderFactory) SAXParserFactory(javax.xml.parsers.SAXParserFactory) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) FileInputStream(java.io.FileInputStream) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Application(javafx.application.Application) Matcher(java.util.regex.Matcher) ByteArrayInputStream(java.io.ByteArrayInputStream) Stage(javafx.stage.Stage) FXMLLoader(javafx.fxml.FXMLLoader) SAXParser(javax.xml.parsers.SAXParser) Pattern(java.util.regex.Pattern) BorderPane(javafx.scene.layout.BorderPane) BuilderFactory(javafx.util.BuilderFactory) Callback(javafx.util.Callback) Builder(javafx.util.Builder) InputStream(java.io.InputStream) BorderPane(javafx.scene.layout.BorderPane) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Builder(javafx.util.Builder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) JavaFXBuilderFactory(javafx.fxml.JavaFXBuilderFactory) BuilderFactory(javafx.util.BuilderFactory) FileInputStream(java.io.FileInputStream) FileNotFoundException(java.io.FileNotFoundException) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 77 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project jgnash by ccavanaugh.

the class ActionParser method loadFile.

/**
     * Adds the set of actions and action-lists from an action-set document into
     * the ActionManager.
     *
     * @param stream InputStream containing an actionSet document
     */
public void loadFile(final InputStream stream) {
    final SAXParserFactory parserFactory = SAXParserFactory.newInstance();
    parserFactory.setValidating(false);
    try {
        final SAXParser parser = parserFactory.newSAXParser();
        parser.parse(stream, this);
        // create reflective actions
        createActions();
    } catch (SAXException | ParserConfigurationException | IOException se) {
        log.severe(se.toString());
    }
}
Also used : SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 78 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project ddf by codice.

the class EXIEncoderTest method testEncode.

/**
     * Tests that the encode method converts xml into exi-compressed xml.
     *
     * @throws Exception
     */
@Test
public void testEncode() throws Exception {
    ByteArrayOutputStream exiStream = new ByteArrayOutputStream();
    InputStream xmlStream = getClass().getResourceAsStream(TEST_FILE);
    EXIEncoder.encode(xmlStream, exiStream);
    StringWriter stringWriter = new StringWriter();
    GrammarCache grammarCache;
    SAXTransformerFactory saxTransformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
    saxParserFactory.setNamespaceAware(true);
    TransformerHandler transformerHandler = saxTransformerFactory.newTransformerHandler();
    EXIReader reader = new EXIReader();
    grammarCache = new GrammarCache(null, GrammarOptions.DEFAULT_OPTIONS);
    reader.setGrammarCache(grammarCache);
    transformerHandler.setResult(new StreamResult(stringWriter));
    reader.setContentHandler(transformerHandler);
    reader.parse(new InputSource(new ByteArrayInputStream(exiStream.toByteArray())));
    XMLUnit.setNormalize(true);
    XMLUnit.setNormalizeWhitespace(true);
    InputStream stream = getClass().getResourceAsStream(TEST_FILE);
    Diff diff = XMLUnit.compareXML(IOUtils.toString(stream), stringWriter.getBuffer().toString());
    IOUtils.closeQuietly(stream);
    assertTrue("The XML input file (" + TEST_FILE + ") did not match the EXI-decoded output", diff.similar());
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) InputSource(org.xml.sax.InputSource) EXIReader(org.openexi.sax.EXIReader) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) Diff(org.custommonkey.xmlunit.Diff) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GrammarCache(org.openexi.proc.grammars.GrammarCache) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Test(org.junit.Test)

Example 79 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project little-bear-dictionary by daimajia.

the class QueryProcessor method parseConfigureXML.

private DictionaryParseInfomation parseConfigureXML(String childDir, String xmlPath) throws ParserConfigurationException, SAXException, IOException {
    DictionaryParseInfomation dictionaryParseInfomation;
    if (mCacheXMLInformation.containsKey(xmlPath)) {
        dictionaryParseInfomation = mCacheXMLInformation.get(xmlPath);
    } else {
        SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
        SAXParser saxParser = saxParserFactory.newSAXParser();
        DictionaryXMLHandler dictionaryXMLHandler = new DictionaryXMLHandler();
        String xmlFilePath = Constants.getSaveDirectory() + File.separator + childDir + File.separator + xmlPath;
        saxParser.parse(new File(xmlFilePath), dictionaryXMLHandler);
        dictionaryParseInfomation = dictionaryXMLHandler.getResults();
        mCacheXMLInformation.put(xmlPath, dictionaryParseInfomation);
    }
    return dictionaryParseInfomation;
}
Also used : SAXParser(javax.xml.parsers.SAXParser) DictionaryXMLHandler(com.zhan_dui.dictionary.handlers.DictionaryXMLHandler) SpannableString(android.text.SpannableString) File(java.io.File) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 80 with SAXParserFactory

use of javax.xml.parsers.SAXParserFactory in project hbase by apache.

the class TestTableScan method testScanUsingListenerUnmarshallerXML.

/**
   * An example to scan using listener in unmarshaller for XML.
   * @throws Exception the exception
   */
@Test
public void testScanUsingListenerUnmarshallerXML() throws Exception {
    StringBuilder builder = new StringBuilder();
    builder.append("/*");
    builder.append("?");
    builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
    builder.append("&");
    builder.append(Constants.SCAN_LIMIT + "=10");
    Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    JAXBContext context = JAXBContext.newInstance(ClientSideCellSetModel.class, RowModel.class, CellModel.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    final ClientSideCellSetModel.Listener listener = new ClientSideCellSetModel.Listener() {

        @Override
        public void handleRowModel(ClientSideCellSetModel helper, RowModel row) {
            assertTrue(row.getKey() != null);
            assertTrue(row.getCells().size() > 0);
        }
    };
    // install the callback on all ClientSideCellSetModel instances
    unmarshaller.setListener(new Unmarshaller.Listener() {

        public void beforeUnmarshal(Object target, Object parent) {
            if (target instanceof ClientSideCellSetModel) {
                ((ClientSideCellSetModel) target).setCellSetModelListener(listener);
            }
        }

        public void afterUnmarshal(Object target, Object parent) {
            if (target instanceof ClientSideCellSetModel) {
                ((ClientSideCellSetModel) target).setCellSetModelListener(null);
            }
        }
    });
    // create a new XML parser
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XMLReader reader = factory.newSAXParser().getXMLReader();
    reader.setContentHandler(unmarshaller.getUnmarshallerHandler());
    assertFalse(ClientSideCellSetModel.listenerInvoked);
    reader.parse(new InputSource(response.getStream()));
    assertTrue(ClientSideCellSetModel.listenerInvoked);
}
Also used : InputSource(org.xml.sax.InputSource) JAXBContext(javax.xml.bind.JAXBContext) Response(org.apache.hadoop.hbase.rest.client.Response) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) Unmarshaller(javax.xml.bind.Unmarshaller) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Test(org.junit.Test)

Aggregations

SAXParserFactory (javax.xml.parsers.SAXParserFactory)183 SAXParser (javax.xml.parsers.SAXParser)141 InputSource (org.xml.sax.InputSource)76 SAXException (org.xml.sax.SAXException)75 IOException (java.io.IOException)62 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)53 XMLReader (org.xml.sax.XMLReader)37 DefaultHandler (org.xml.sax.helpers.DefaultHandler)27 InputStream (java.io.InputStream)22 File (java.io.File)21 SAXSource (javax.xml.transform.sax.SAXSource)21 ByteArrayInputStream (java.io.ByteArrayInputStream)16 StringReader (java.io.StringReader)15 Unmarshaller (javax.xml.bind.Unmarshaller)13 Attributes (org.xml.sax.Attributes)13 JAXBContext (javax.xml.bind.JAXBContext)12 SAXParseException (org.xml.sax.SAXParseException)10 InputStreamReader (java.io.InputStreamReader)9 ArrayList (java.util.ArrayList)9 ValidationEvent (javax.xml.bind.ValidationEvent)9