use of org.w3c.dom.Attr in project jdk8u_jdk by JetBrains.
the class MyAttrNode method test2.
public static void test2() {
String name = "attr";
String oldValue = "old value";
String newValue = "new value";
Attr retAttr;
IIOMetadataNode parent = new IIOMetadataNode("parent");
MyAttrNode attrNode1 = new MyAttrNode(name, oldValue);
MyAttrNode attrNode2 = new MyAttrNode(name, newValue);
retAttr = parent.setAttributeNode(attrNode1);
retAttr = parent.setAttributeNode(attrNode2);
String actName = retAttr.getNodeName();
String actValue = retAttr.getValue();
if (!actName.equals(name) || !actValue.equals(oldValue)) {
throw new RuntimeException("Test 2 failed: Invalid attribute " + "returned: " + "(name: " + actName + ", value: " + actValue + ")");
}
}
use of org.w3c.dom.Attr in project midpoint by Evolveum.
the class DOMUtil method getNamespaceDeclarations.
/**
* Returns map of all namespace declarations from specified element (prefix -> namespace).
*/
public static Map<String, String> getNamespaceDeclarations(Element element) {
Map<String, String> nsDeclMap = new HashMap<>();
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Attr attr = (Attr) attributes.item(i);
if (isNamespaceDefinition(attr)) {
String prefix = getNamespaceDeclarationPrefix(attr);
String namespace = getNamespaceDeclarationNamespace(attr);
nsDeclMap.put(prefix, namespace);
}
}
return nsDeclMap;
}
use of org.w3c.dom.Attr in project midpoint by Evolveum.
the class DOMUtil method setQNameAttribute.
public static void setQNameAttribute(Element element, String attributeName, QName attributeValue) {
Document doc = element.getOwnerDocument();
Attr attr = doc.createAttribute(attributeName);
setQNameAttribute(element, attr, attributeValue, element);
}
use of org.w3c.dom.Attr in project midpoint by Evolveum.
the class DOMUtil method isPrefixUsed.
public static boolean isPrefixUsed(Element targetElement, String prefix) {
if (comparePrefix(prefix, targetElement.getPrefix())) {
return true;
}
NamedNodeMap attributes = targetElement.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Attr attr = (Attr) attributes.item(i);
if (comparePrefix(prefix, attr.getPrefix())) {
return true;
}
}
NodeList childNodes = targetElement.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node instanceof Element) {
Element element = (Element) node;
if (isPrefixUsed(element, prefix)) {
return true;
}
}
}
return false;
}
use of org.w3c.dom.Attr in project aries by apache.
the class SpringOsgiExtension method start.
@Override
public void start() throws Exception {
List<Object> bpPaths = new ArrayList<Object>();
Set<URI> namespaces = new LinkedHashSet<URI>();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
for (URL url : paths) {
InputStream is = url.openStream();
try {
InputSource inputSource = new InputSource(is);
DocumentBuilder builder = dbf.newDocumentBuilder();
Document doc = builder.parse(inputSource);
Attr schemaLoc = doc.getDocumentElement().getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
if (schemaLoc != null) {
List<String> locs = new ArrayList<String>(Arrays.asList(schemaLoc.getValue().split("\\s+")));
locs.remove("");
for (int i = 0; i < locs.size() / 2; i++) {
String ns = locs.get(i * 2);
namespaces.add(URI.create(ns));
if (ns.startsWith("http://www.springframework.org/schema/osgi-compendium")) {
namespaces.add(URI.create(SpringOsgiCompendiumNamespaceHandler.CM_NAMESPACE));
}
}
}
} finally {
is.close();
}
}
File file = File.createTempFile("blueprint-spring-extender", ".xml");
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
try {
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
writer.write("<blueprint xmlns=\"http://www.osgi.org/xmlns/blueprint/v1.0.0\"\n");
writer.write("\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
writer.write("\txmlns:bean=\"http://www.springframework.org/schema/beans\"\n");
writer.write("\txsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\">\n");
for (URL url : paths) {
writer.write("\t<bean:import resource=\"" + url.toString() + "\"/>\n");
}
writer.write("</blueprint>\n");
} finally {
writer.close();
}
LOGGER.info("Generated blueprint for bundle {}/{} at {}", bundle.getSymbolicName(), bundle.getVersion(), file);
bpPaths.add(file.toURI().toURL());
container = blueprintExtenderService.createContainer(bundle, bpPaths, namespaces);
}
Aggregations