use of javax.xml.parsers.SAXParser in project tdi-studio-se by Talend.
the class ComplexSAXLooper method parse.
/**
* Parse the XML file. Buffer the result in LoopEntry.
*
* @param is InputStream
*/
public void parse(java.io.InputStream is, String charset) {
this.charset = charset;
Reader reader = null;
try {
DefaultHandler hd = null;
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
if (rootPath == null || rootPath.equals("")) {
hd = newHandler();
} else {
hd = newHandler2();
}
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", hd);
// routines.system.UnicodeReader.java is used to ignore the BOM of the source file.
reader = new UnicodeReader(is, this.charset);
org.xml.sax.InputSource inSource = new org.xml.sax.InputSource(reader);
saxParser.parse(inSource, hd);
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of javax.xml.parsers.SAXParser in project tdi-studio-se by Talend.
the class Rfh2AreaParser method parse.
public RFH2Area parse(String stringToParse) {
SAXParser parser;
try {
parser = SAXParserFactory.newInstance().newSAXParser();
} catch (Exception e) {
throw new RuntimeException("Failed to create XML parser, can not parse RFH2 areas", e);
}
SaxHandler handler = new SaxHandler();
try {
parser.parse(new InputSource(new StringReader(stringToParse)), handler);
} catch (SAXException e) {
throw new RuntimeException("Invalid RFH2 header", e);
} catch (IOException e) {
throw new RuntimeException("Invalid RFH2 header", e);
}
return handler.getArea();
}
use of javax.xml.parsers.SAXParser in project Synthese_2BIN by TheYoungSensei.
the class MainSAXB method main.
public static void main(String[] args) {
try {
File inputFile = new File("library.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
SAXB userHandler = new SAXB();
saxParser.parse(inputFile, userHandler);
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.xml.parsers.SAXParser in project Synthese_2BIN by TheYoungSensei.
the class MainSAXC method main.
public static void main(String[] args) {
try {
File inputFile = new File("course.xml");
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
SAXC userHandler = new SAXC();
saxParser.parse(inputFile, userHandler);
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.xml.parsers.SAXParser in project wh-app-android by WhiteHouse.
the class FeedManager method updateFeedFromServer.
public static void updateFeedFromServer(String url, String title, String viewType) {
final BehaviorSubject<Observable<List<FeedItem>>> subject;
final OkHttpClient client = getClient();
final Request request = getBaseRequest().url(url).get().build();
if (sFeedItemsSubject.get(url) == null) {
sFeedItemsSubject.put(url, BehaviorSubject.create());
}
subject = sFeedItemsSubject.get(url);
subject.onNext(Observable.create((Subscriber<? super List<FeedItem>> op) -> {
Response response;
try {
response = client.newCall(request).execute();
if (response.code() >= 400) {
op.onError(new IOException("Response code " + Integer.toString(response.code())));
} else {
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
FeedHandler handler = new FeedHandler(title, viewType);
parser.parse(response.body().byteStream(), handler);
op.onNext(handler.getFeedItems());
}
op.onCompleted();
} catch (Exception e) {
op.onError(e);
}
}));
}
Aggregations