use of org.w3c.dom.Element in project che by eclipse.
the class Launching method writeInstallInfo.
/**
* Writes out the mappings of SDK install time stamps to disk. See
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=266651 for more information.
*/
private static void writeInstallInfo() {
if (fgInstallTimeMap != null) {
OutputStream stream = null;
try {
Document doc = newDocument();
//$NON-NLS-1$
Element root = doc.createElement("dirs");
doc.appendChild(root);
Map.Entry<String, Long> entry = null;
Element e = null;
String key = null;
for (Iterator<Map.Entry<String, Long>> i = fgInstallTimeMap.entrySet().iterator(); i.hasNext(); ) {
entry = i.next();
key = entry.getKey();
if (fgLibraryInfoMap == null || fgLibraryInfoMap.containsKey(key)) {
//only persist the info if the library map also has info OR is null - prevent persisting deleted JRE information
//$NON-NLS-1$
e = doc.createElement("entry");
root.appendChild(e);
//$NON-NLS-1$
e.setAttribute("loc", key);
//$NON-NLS-1$
e.setAttribute("stamp", entry.getValue().toString());
}
}
String xml = serializeDocument(doc);
IPath libPath = getDefault().getStateLocation();
//$NON-NLS-1$
libPath = libPath.append(".install.xml");
File file = libPath.toFile();
if (!file.exists()) {
file.createNewFile();
}
stream = new BufferedOutputStream(new FileOutputStream(file));
//$NON-NLS-1$
stream.write(xml.getBytes("UTF8"));
} catch (IOException e) {
log(e);
} catch (CoreException e) {
log(e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e1) {
}
}
}
}
}
use of org.w3c.dom.Element 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.w3c.dom.Element 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);
}
}
}
use of org.w3c.dom.Element in project hackpad by dropbox.
the class XmlNode method addNamespaces.
private void addNamespaces(Namespaces rv, Element element) {
if (element == null)
throw new RuntimeException("element must not be null");
String myDefaultNamespace = toUri(element.lookupNamespaceURI(null));
String parentDefaultNamespace = "";
if (element.getParentNode() != null) {
parentDefaultNamespace = toUri(element.getParentNode().lookupNamespaceURI(null));
}
if (!myDefaultNamespace.equals(parentDefaultNamespace) || !(element.getParentNode() instanceof Element)) {
rv.declare(Namespace.create("", myDefaultNamespace));
}
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Attr attr = (Attr) attributes.item(i);
if (attr.getPrefix() != null && attr.getPrefix().equals("xmlns")) {
rv.declare(Namespace.create(attr.getLocalName(), attr.getValue()));
}
}
}
use of org.w3c.dom.Element in project hackpad by dropbox.
the class XmlNode method ecmaToXMLString.
String ecmaToXMLString(XmlProcessor processor) {
if (this.isElementType()) {
Element copy = (Element) this.dom.cloneNode(true);
Namespace[] inScope = this.getInScopeNamespaces();
for (int i = 0; i < inScope.length; i++) {
declareNamespace(copy, inScope[i].getPrefix(), inScope[i].getUri());
}
return processor.ecmaToXmlString(copy);
} else {
return processor.ecmaToXmlString(dom);
}
}
Aggregations