use of org.w3c.dom.NamedNodeMap in project buck by facebook.
the class SchemeGeneratorTest method buildableReferenceShouldHaveExpectedProperties.
@Test
public void buildableReferenceShouldHaveExpectedProperties() throws Exception {
ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder = ImmutableMap.builder();
PBXTarget rootTarget = new PBXNativeTarget("rootRule");
rootTarget.setGlobalID("rootGID");
rootTarget.setProductReference(new PBXFileReference("root.a", "root.a", PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Optional.empty()));
rootTarget.setProductType(ProductType.STATIC_LIBRARY);
Path pbxprojectPath = Paths.get("foo/Foo.xcodeproj/project.pbxproj");
targetToProjectPathMapBuilder.put(rootTarget, pbxprojectPath);
SchemeGenerator schemeGenerator = new SchemeGenerator(projectFilesystem, Optional.of(rootTarget), ImmutableSet.of(rootTarget), ImmutableSet.of(), ImmutableSet.of(), "TestScheme", Paths.get("_gen/Foo.xcworkspace/scshareddata/xcshemes"), false, /* primaryTargetIsBuildWithBuck */
false, /* parallelizeBuild */
Optional.empty(), /* runnablePath */
Optional.empty(), /* remoteRunnablePath */
SchemeActionType.DEFAULT_CONFIG_NAMES, targetToProjectPathMapBuilder.build(), XCScheme.LaunchAction.LaunchStyle.AUTO);
Path schemePath = schemeGenerator.writeScheme();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document scheme = dBuilder.parse(projectFilesystem.newFileInputStream(schemePath));
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath buildableReferenceXPath = xpathFactory.newXPath();
XPathExpression buildableReferenceExpr = buildableReferenceXPath.compile("//BuildableReference");
NodeList buildableReferences = (NodeList) buildableReferenceExpr.evaluate(scheme, XPathConstants.NODESET);
assertThat(buildableReferences.getLength(), greaterThan(0));
for (int i = 0; i < buildableReferences.getLength(); i++) {
NamedNodeMap attributes = buildableReferences.item(i).getAttributes();
assertThat(attributes, notNullValue());
assertThat(attributes.getNamedItem("BlueprintIdentifier"), notNullValue());
assertThat(attributes.getNamedItem("BuildableIdentifier"), notNullValue());
assertThat(attributes.getNamedItem("ReferencedContainer"), notNullValue());
assertThat(attributes.getNamedItem("BlueprintName"), notNullValue());
assertThat(attributes.getNamedItem("BuildableName"), notNullValue());
}
}
use of org.w3c.dom.NamedNodeMap in project che by eclipse.
the class ClasspathEntry method decodeUnknownNode.
private static void decodeUnknownNode(Node node, XMLWriter xmlWriter, boolean insertNewLine) {
switch(node.getNodeType()) {
case Node.ELEMENT_NODE:
NamedNodeMap attributes;
HashMap parameters = null;
if ((attributes = node.getAttributes()) != null) {
int length = attributes.getLength();
if (length > 0) {
parameters = new HashMap();
for (int i = 0; i < length; i++) {
Node attribute = attributes.item(i);
parameters.put(attribute.getNodeName(), attribute.getNodeValue());
}
}
}
NodeList children = node.getChildNodes();
int childrenLength = children.getLength();
String nodeName = node.getNodeName();
xmlWriter.printTag(nodeName, parameters, false, /*don't insert tab*/
false, /*don't insert new line*/
childrenLength == 0);
if (childrenLength > 0) {
for (int i = 0; i < childrenLength; i++) {
decodeUnknownNode(children.item(i), xmlWriter, false);
}
xmlWriter.endTag(nodeName, false, /*don't insert tab*/
insertNewLine);
}
break;
case Node.TEXT_NODE:
String data = ((Text) node).getData();
xmlWriter.printString(data, false, /*don't insert tab*/
false);
break;
}
}
use of org.w3c.dom.NamedNodeMap 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.w3c.dom.NamedNodeMap in project cogtool by cogtool.
the class ImportCogToolXML method addAttributes.
private static void addAttributes(IAttributed attributed, Node node, Map<IAttributed, String> pendingAttrSets) {
NamedNodeMap attributes = node.getAttributes();
if (attributes != null) {
int numAttributes = attributes.getLength();
if (numAttributes > 0) {
if (notInitialized) {
registerAttributes();
}
for (int i = 0; i < numAttributes; i++) {
Node attributeNode = attributes.item(i);
// Should never be null; sanity check
if (attributeNode != null) {
String attribute = attributeNode.getNodeName();
IAttributed.AttributeDefinition<?> attrDefn = ATTRIBUTE_REGISTRY.get(attribute);
if (attrDefn != null) {
String attrName = attrDefn.attrName;
String attrNodeValue = attributeNode.getNodeValue();
if (WidgetAttributes.SELECTION_ATTR.equals(attrName)) {
// attrNodeValue is name of the selected widget,
// but the widget may not exist yet.
pendingAttrSets.put(attributed, attrNodeValue);
} else if (VALUE_REGISTRY.containsKey(attrNodeValue)) {
Object attrValue = VALUE_REGISTRY.get(attrNodeValue);
if (!NullSafe.equals(attrValue, attrDefn.defaultValue)) {
attributed.setAttribute(attrName, attrValue);
}
} else {
// Assume string value (eg, APPENDED_TEXT_ATTR)
attributed.setAttribute(attrName, attrNodeValue);
}
}
}
}
}
}
}
use of org.w3c.dom.NamedNodeMap in project Apktool by iBotPeaches.
the class ResXmlPatcher method removeApplicationDebugTag.
/**
* Removes "debug" tag from file
*
* @param file AndroidManifest file
* @throws AndrolibException
*/
public static void removeApplicationDebugTag(File file) throws AndrolibException {
if (file.exists()) {
try {
Document doc = loadDocument(file);
Node application = doc.getElementsByTagName("application").item(0);
// load attr
NamedNodeMap attr = application.getAttributes();
Node debugAttr = attr.getNamedItem("android:debuggable");
// remove application:debuggable
if (debugAttr != null) {
attr.removeNamedItem("android:debuggable");
}
saveDocument(file, doc);
} catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
}
}
}
Aggregations