use of org.w3c.dom.Element in project che by eclipse.
the class ClasspathEntry method decodeExtraAttributes.
static IClasspathAttribute[] decodeExtraAttributes(NodeList attributes) {
if (attributes == null)
return NO_EXTRA_ATTRIBUTES;
int length = attributes.getLength();
if (length == 0)
return NO_EXTRA_ATTRIBUTES;
IClasspathAttribute[] result = new IClasspathAttribute[length];
int index = 0;
for (int i = 0; i < length; ++i) {
Node node = attributes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element attribute = (Element) node;
String name = attribute.getAttribute(TAG_ATTRIBUTE_NAME);
if (name == null)
continue;
String value = attribute.getAttribute(TAG_ATTRIBUTE_VALUE);
if (value == null)
continue;
result[index++] = new ClasspathAttribute(name, value);
}
}
if (index != length)
System.arraycopy(result, 0, result = new IClasspathAttribute[index], 0, index);
return result;
}
use of org.w3c.dom.Element in project che by eclipse.
the class ClasspathEntry method decodeAccessRules.
static IAccessRule[] decodeAccessRules(NodeList list) {
if (list == null)
return null;
int length = list.getLength();
if (length == 0)
return null;
IAccessRule[] result = new IAccessRule[length];
int index = 0;
for (int i = 0; i < length; i++) {
Node accessRule = list.item(i);
if (accessRule.getNodeType() == Node.ELEMENT_NODE) {
Element elementAccessRule = (Element) accessRule;
String pattern = elementAccessRule.getAttribute(TAG_PATTERN);
if (pattern == null)
continue;
String tagKind = elementAccessRule.getAttribute(TAG_KIND);
int kind;
if (TAG_ACCESSIBLE.equals(tagKind))
kind = IAccessRule.K_ACCESSIBLE;
else if (TAG_NON_ACCESSIBLE.equals(tagKind))
kind = IAccessRule.K_NON_ACCESSIBLE;
else if (TAG_DISCOURAGED.equals(tagKind))
kind = IAccessRule.K_DISCOURAGED;
else
continue;
//$NON-NLS-1$
boolean ignoreIfBetter = "true".equals(elementAccessRule.getAttribute(TAG_IGNORE_IF_BETTER));
result[index++] = new ClasspathAccessRule(new Path(pattern), ignoreIfBetter ? kind | IAccessRule.IGNORE_IF_BETTER : kind);
}
}
if (index != length)
System.arraycopy(result, 0, result = new IAccessRule[index], 0, index);
return result;
}
use of org.w3c.dom.Element in project che by eclipse.
the class BuildFileGenerator method createProperty.
/**
* Create property tag.
* <property name="value" {location,value}="value"/>
*/
private void createProperty() {
Map<String, String> locationProperties = new TreeMap<>();
locationProperties.put("build", "${basedir}/build");
locationProperties.put("build.classes", "${build}/classes");
locationProperties.put("src.dir", "${basedir}/src");
Element nameProperty = doc.createElement("property");
nameProperty.setAttribute("name", "name");
nameProperty.setAttribute("value", projectName);
Node node = root.getFirstChild();
node = root.insertBefore(nameProperty, node);
for (Map.Entry<String, String> locationProperty : locationProperties.entrySet()) {
Element locationElement = doc.createElement("property");
locationElement.setAttribute("name", locationProperty.getKey());
locationElement.setAttribute("location", locationProperty.getValue());
node = node.getNextSibling();
node = root.insertBefore(locationElement, node);
}
}
use of org.w3c.dom.Element in project che by eclipse.
the class DialogSettings method load.
/* (non-Javadoc)
* Load the setting from the <code>document</code>
*/
private void load(Document document, Element root) {
name = root.getAttribute(TAG_NAME);
NodeList l = root.getElementsByTagName(TAG_ITEM);
for (int i = 0; i < l.getLength(); i++) {
Node n = l.item(i);
if (root == n.getParentNode()) {
String key = ((Element) l.item(i)).getAttribute(TAG_KEY);
String value = ((Element) l.item(i)).getAttribute(TAG_VALUE);
items.put(key, value);
}
}
l = root.getElementsByTagName(TAG_LIST);
for (int i = 0; i < l.getLength(); i++) {
Node n = l.item(i);
if (root == n.getParentNode()) {
Element child = (Element) l.item(i);
String key = child.getAttribute(TAG_KEY);
NodeList list = child.getElementsByTagName(TAG_ITEM);
List<String> valueList = new ArrayList<String>();
for (int j = 0; j < list.getLength(); j++) {
Element node = (Element) list.item(j);
if (child == node.getParentNode()) {
valueList.add(node.getAttribute(TAG_VALUE));
}
}
String[] value = new String[valueList.size()];
valueList.toArray(value);
arrayItems.put(key, value);
}
}
l = root.getElementsByTagName(TAG_SECTION);
for (int i = 0; i < l.getLength(); i++) {
Node n = l.item(i);
if (root == n.getParentNode()) {
//$NON-NLS-1$
DialogSettings s = new DialogSettings("NoName");
s.load(document, (Element) n);
addSection(s);
}
}
}
use of org.w3c.dom.Element in project hadoop by apache.
the class TestRMWithCSRFFilter method verifyClusterInfoXML.
public void verifyClusterInfoXML(String xml) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is);
NodeList nodes = dom.getElementsByTagName("clusterInfo");
assertEquals("incorrect number of elements", 1, nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
verifyClusterGeneric(WebServicesTestUtils.getXmlLong(element, "id"), WebServicesTestUtils.getXmlLong(element, "startedOn"), WebServicesTestUtils.getXmlString(element, "state"), WebServicesTestUtils.getXmlString(element, "haState"), WebServicesTestUtils.getXmlString(element, "haZooKeeperConnectionState"), WebServicesTestUtils.getXmlString(element, "hadoopVersionBuiltOn"), WebServicesTestUtils.getXmlString(element, "hadoopBuildVersion"), WebServicesTestUtils.getXmlString(element, "hadoopVersion"), WebServicesTestUtils.getXmlString(element, "resourceManagerVersionBuiltOn"), WebServicesTestUtils.getXmlString(element, "resourceManagerBuildVersion"), WebServicesTestUtils.getXmlString(element, "resourceManagerVersion"));
}
}
Aggregations