use of org.xml.sax.helpers.DefaultHandler in project OpenPanodroid by duerrfk.
the class RESTRequestorXML method parseResponse.
@Override
protected void parseResponse(InputStream is, int contentLength) {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
DefaultHandler saxHandler = createSAXHandler();
if (saxHandler == null) {
setSuccessState(false);
} else {
parser.parse(is, saxHandler);
}
} catch (Exception ex) {
setErrorMsg(ex.getLocalizedMessage());
setSuccessState(false);
}
}
use of org.xml.sax.helpers.DefaultHandler in project che by eclipse.
the class RefactoringHistoryManager method getCachedDocument.
/**
* Returns the cached refactoring history document.
*
* @param path
* the path of the document
* @param input
* the input stream where to read the document
* @return the cached refactoring history document
* @throws SAXException
* if an error occurs while parsing the history entry
* @throws IOException
* if an input/output error occurs
* @throws ParserConfigurationException
* if an error occurs in the parser configuration
*/
private Document getCachedDocument(final IPath path, final InputStream input) throws SAXException, IOException, ParserConfigurationException {
if (path.equals(fCachedPath) && fCachedDocument != null)
return fCachedDocument;
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
parser.setErrorHandler(new DefaultHandler());
final Document document = parser.parse(new InputSource(input));
fCachedDocument = document;
fCachedPath = path;
return document;
}
use of org.xml.sax.helpers.DefaultHandler in project che by eclipse.
the class TemplateReaderWriter method read.
/**
* Reads templates from an <code>InputSource</code> and adds them to the templates.
*
* @param source the input source
* @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
* @param singleId the template id to extract, or <code>null</code> to read in all templates
* @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
* @throws IOException if reading from the stream fails
*/
private TemplatePersistenceData[] read(InputSource source, ResourceBundle bundle, String singleId) throws IOException {
try {
Collection templates = new ArrayList();
Set ids = new HashSet();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
parser.setErrorHandler(new DefaultHandler());
Document document = parser.parse(source);
NodeList elements = document.getElementsByTagName(TEMPLATE_ELEMENT);
int count = elements.getLength();
for (int i = 0; i != count; i++) {
Node node = elements.item(i);
NamedNodeMap attributes = node.getAttributes();
if (attributes == null)
continue;
String id = getStringValue(attributes, ID_ATTRIBUTE, null);
if (id != null && ids.contains(id))
//$NON-NLS-1$
throw new IOException(TemplatePersistenceMessages.getString("TemplateReaderWriter.duplicate.id"));
if (singleId != null && !singleId.equals(id))
continue;
boolean deleted = getBooleanValue(attributes, DELETED_ATTRIBUTE, false);
String name = getStringValue(attributes, NAME_ATTRIBUTE);
name = translateString(name, bundle);
//$NON-NLS-1$
String description = getStringValue(attributes, DESCRIPTION_ATTRIBUTE, "");
description = translateString(description, bundle);
String context = getStringValue(attributes, CONTEXT_ATTRIBUTE);
if (name == null || context == null)
//$NON-NLS-1$
throw new IOException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.missing_attribute"));
boolean enabled = getBooleanValue(attributes, ENABLED_ATTRIBUTE, true);
boolean autoInsertable = getBooleanValue(attributes, AUTO_INSERTABLE_ATTRIBUTE, true);
StringBuffer buffer = new StringBuffer();
NodeList children = node.getChildNodes();
for (int j = 0; j != children.getLength(); j++) {
String value = children.item(j).getNodeValue();
if (value != null)
buffer.append(value);
}
String pattern = buffer.toString();
pattern = translateString(pattern, bundle);
Template template = new Template(name, description, context, pattern, autoInsertable);
TemplatePersistenceData data = new TemplatePersistenceData(template, enabled, id);
data.setDeleted(deleted);
templates.add(data);
if (singleId != null && singleId.equals(id))
break;
}
return (TemplatePersistenceData[]) templates.toArray(new TemplatePersistenceData[templates.size()]);
} catch (ParserConfigurationException e) {
Assert.isTrue(false);
} catch (SAXException e) {
//$NON-NLS-1$
throw (IOException) new IOException("Could not read template file").initCause(e);
}
// dummy
return null;
}
use of org.xml.sax.helpers.DefaultHandler in project che by eclipse.
the class Launching method restoreLibraryInfo.
/**
* Restores library information for VMs
*/
private static void restoreLibraryInfo() {
fgLibraryInfoMap = new HashMap<String, LibraryInfo>(10);
IPath libPath = getDefault().getStateLocation();
//$NON-NLS-1$
libPath = libPath.append("libraryInfos.xml");
File file = libPath.toFile();
if (file.exists()) {
try {
InputStream stream = new BufferedInputStream(new FileInputStream(file));
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
parser.setErrorHandler(new DefaultHandler());
Element root = parser.parse(new InputSource(stream)).getDocumentElement();
if (!root.getNodeName().equals("libraryInfos")) {
//$NON-NLS-1$
return;
}
NodeList list = root.getChildNodes();
int length = list.getLength();
for (int i = 0; i < length; ++i) {
Node node = list.item(i);
short type = node.getNodeType();
if (type == Node.ELEMENT_NODE) {
Element element = (Element) node;
String nodeName = element.getNodeName();
if (nodeName.equalsIgnoreCase("libraryInfo")) {
//$NON-NLS-1$
//$NON-NLS-1$
String version = element.getAttribute("version");
//$NON-NLS-1$
String location = element.getAttribute("home");
//$NON-NLS-1$
String[] bootpath = getPathsFromXML(element, "bootpath");
//$NON-NLS-1$
String[] extDirs = getPathsFromXML(element, "extensionDirs");
//$NON-NLS-1$
String[] endDirs = getPathsFromXML(element, "endorsedDirs");
if (location != null) {
LibraryInfo info = new LibraryInfo(version, bootpath, extDirs, endDirs);
fgLibraryInfoMap.put(location, info);
}
}
}
}
} catch (IOException | SAXException | ParserConfigurationException e) {
log(e);
}
}
}
use of org.xml.sax.helpers.DefaultHandler in project che by eclipse.
the class Launching method readInstallInfo.
/**
* Reads the file of saved time stamps and populates the {@link #fgInstallTimeMap}.
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=266651 for more information
*
* @since 3.7
*/
private static void readInstallInfo() {
fgInstallTimeMap = new HashMap<String, Long>();
IPath libPath = getDefault().getStateLocation();
//$NON-NLS-1$
libPath = libPath.append(".install.xml");
File file = libPath.toFile();
if (file.exists()) {
try {
InputStream stream = new BufferedInputStream(new FileInputStream(file));
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
parser.setErrorHandler(new DefaultHandler());
Element root = parser.parse(new InputSource(stream)).getDocumentElement();
if (root.getNodeName().equalsIgnoreCase("dirs")) {
//$NON-NLS-1$
NodeList nodes = root.getChildNodes();
Node node = null;
Element element = null;
for (int i = 0; i < nodes.getLength(); i++) {
node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
element = (Element) node;
if (element.getNodeName().equalsIgnoreCase("entry")) {
//$NON-NLS-1$
//$NON-NLS-1$
String loc = element.getAttribute("loc");
//$NON-NLS-1$
String stamp = element.getAttribute("stamp");
try {
Long l = new Long(stamp);
fgInstallTimeMap.put(loc, l);
} catch (NumberFormatException nfe) {
//do nothing
}
}
}
}
}
} catch (IOException e) {
log(e);
} catch (ParserConfigurationException e) {
log(e);
} catch (SAXException e) {
log(e);
}
}
}
Aggregations