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();
}
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());
}
}
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());
}
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;
}
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);
}
Aggregations