List of usage examples for org.w3c.dom Element getOwnerDocument
public Document getOwnerDocument();
Document
object associated with this node. From source file:org.fireflow.service.java.JavaServiceParser.java
public void serializeService(ServiceDef service, Element parentElement) { if (!(service instanceof JavaService)) { return;/*from w ww . ja va2 s . c o m*/ } JavaService javaSvc = (JavaService) service; Document document = parentElement.getOwnerDocument(); Element svcElem = document.createElementNS(SERVICE_NS_URI, SERVICE_NS_PREFIX + ":" + SERVICE_NAME); this.writeCommonServiceAttribute(javaSvc, svcElem); Util4Serializer.addElement(svcElem, JAVA_BEAN_NAME, javaSvc.getJavaBeanName()); Util4Serializer.addElement(svcElem, JAVA_CLASS_NAME, javaSvc.getJavaClassName()); writeInterface(service.getInterface(), svcElem); parentElement.appendChild(svcElem); this.writeExtendedAttributes(javaSvc.getExtendedAttributes(), svcElem); }
From source file:org.fireflow.service.java.JavaServiceParser.java
public void writeInterface(InterfaceDef _interface, Element svcElm) { if (_interface == null || !(_interface instanceof JavaInterfaceDef)) { return;//w w w .j a v a 2s .co m } JavaInterfaceDef javaInterface = (JavaInterfaceDef) _interface; Document document = svcElm.getOwnerDocument(); Element interfaceElement = document.createElementNS(SERVICE_NS_URI, SERVICE_NS_PREFIX + ":" + INTERFACE); svcElm.appendChild(interfaceElement); Util4Serializer.addElement(interfaceElement, INTERFACE_CLASS_NAME, javaInterface.getInterfaceClassName()); }
From source file:org.globus.wsrf.tools.wsdl.TypesProcessor.java
public void addResourceProperties(QName portTypeName, Map resourcePropertyElements, Map schemaDocumentLocations) throws Exception { logger.debug("Starting to build resource properties element"); PortType portType = this.getPortType(portTypeName); QName resourceProperties = (QName) portType.getExtensionAttribute(RP); addPrefix(WSRP_NS, "wsrp"); Element schema = getSchema(); Document doc = schema.getOwnerDocument(); String schemaPrefix = ""; if (schema.getPrefix() != null) { schemaPrefix = schema.getPrefix() + ":"; }//from w w w . ja va2s. co m Element properties = null; if (resourceProperties == null) { resourceProperties = new QName(portType.getQName().getLocalPart() + "GTWSDLResourceProperties"); portType.setExtensionAttribute(RP, resourceProperties); properties = doc.createElementNS(XSD_NS, schemaPrefix + "element"); properties.setAttribute("name", resourceProperties.getLocalPart()); properties.appendChild(doc.createTextNode("\n ")); schema.appendChild(properties); schema.appendChild(doc.createTextNode("\n ")); } else { NodeList elementNodes = schema.getElementsByTagNameNS(XSD_NS, "element"); String name; Element element; for (int i = 0; i < elementNodes.getLength(); i++) { element = (Element) elementNodes.item(i); name = element.getAttribute("name"); if (name != null && XmlUtils.getFullQNameFromString(name, element).getLocalPart() .equals(resourceProperties.getLocalPart())) { properties = element; break; } } if (properties == null) { throw new Exception( "Unable to find '" + resourceProperties + "' element in WSDL schema section of '" + this.definition.getDocumentBaseURI() + "' document."); } } String type = properties.getAttribute("type"); NodeList complexTypeElements; Element complexType = null; if (type != null && !type.equals("")) { complexTypeElements = schema.getElementsByTagNameNS(XSD_NS, "complexType"); Element currentType; QName currentName; QName typeName = XmlUtils.getFullQNameFromString(type, properties); for (int i = 0; i < complexTypeElements.getLength(); i++) { currentType = (Element) complexTypeElements.item(i); currentName = XmlUtils.getFullQNameFromString(currentType.getAttribute("name"), currentType); if (currentName.getLocalPart().equals(typeName.getLocalPart())) { complexType = currentType; break; } } if (complexType == null) { throw new Exception("Unable to find type entry for '" + resourceProperties + "' element"); } } else { complexTypeElements = properties.getElementsByTagNameNS(XSD_NS, "complexType"); if (complexTypeElements.getLength() > 0) { complexType = (Element) complexTypeElements.item(0); } else { complexType = doc.createElementNS(XSD_NS, schemaPrefix + "complexType"); complexType.appendChild(doc.createTextNode("\n ")); properties.appendChild(complexType); properties.appendChild(doc.createTextNode("\n ")); } } NodeList sequenceElements = complexType.getElementsByTagNameNS(XSD_NS, "sequence"); Element sequence; if (sequenceElements.getLength() > 0) { sequence = (Element) sequenceElements.item(0); } else { sequence = doc.createElementNS(XSD_NS, schemaPrefix + "sequence"); complexType.appendChild(sequence); complexType.appendChild(doc.createTextNode("\n ")); } Collection resourcePropertiesList = resourcePropertyElements.values(); Iterator elementIterator = resourcePropertiesList.iterator(); int nsCounter = 0; while (elementIterator.hasNext()) { sequence.appendChild(doc.createTextNode("\n ")); Element resourcePropertyElement = doc.createElementNS(XSD_NS, schemaPrefix + "element"); XSParticle particle = (XSParticle) elementIterator.next(); XSElementDeclaration element = (XSElementDeclaration) particle.getTerm(); String prefix = XmlUtils.getPrefix(element.getNamespace(), schema); addSchemaDefinitions(element, schemaDocumentLocations, schema); if (prefix == null) { prefix = "rpns" + String.valueOf(nsCounter++); Attr nameSpace = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + prefix); nameSpace.setValue(element.getNamespace()); schema.setAttributeNode(nameSpace); } resourcePropertyElement.setAttribute("ref", prefix + ":" + element.getName()); resourcePropertyElement.setAttribute("minOccurs", String.valueOf(particle.getMinOccurs())); if (particle.getMaxOccursUnbounded()) { resourcePropertyElement.setAttribute("maxOccurs", String.valueOf("unbounded")); } else { resourcePropertyElement.setAttribute("maxOccurs", String.valueOf(particle.getMaxOccurs())); } sequence.appendChild(resourcePropertyElement); } sequence.appendChild(doc.createTextNode("\n ")); logger.debug("Resource properties element: " + XmlUtils.getElementAsString(properties)); }
From source file:org.globus.wsrf.tools.wsdl.TypesProcessor.java
private void addSchemaDefinitions(String elementNS, Map schemaDocumentLocations, Element schema) throws Exception { Map map = (Map) schemaDocumentLocations.get(elementNS); if (map == null) { return;/*from ww w .j a v a 2s . c o m*/ } Set locations = map.keySet(); Iterator locationsIterator = locations.iterator(); String targetNS = schema.getAttribute("targetNamespace"); Document owner = schema.getOwnerDocument(); String schemaPrefix = schema.getPrefix(); if (schemaPrefix == null) { schemaPrefix = ""; } else { schemaPrefix += ":"; } this.populateImportsMap(schema); this.populateIncludesMap(schema); while (locationsIterator.hasNext()) { String location = (String) locationsIterator.next(); if (!location.equals(definition.getDocumentBaseURI())) { location = WSDLPreprocessor.getRelativePath(definition.getDocumentBaseURI(), location); if (elementNS.equals(targetNS)) { Map includes = (Map) this.includes.get(elementNS); if (includes == null) { includes = new HashMap(); this.includes.put(elementNS, includes); } if (!includes.containsKey(location)) { Element include = owner.createElementNS(XSD_NS, schemaPrefix + "include"); include.setAttribute("schemaLocation", location); schema.insertBefore(owner.createTextNode("\n"), schema.getFirstChild()); schema.insertBefore(include, schema.getFirstChild()); schema.insertBefore(owner.createTextNode("\n"), schema.getFirstChild()); includes.put(location, null); } } else { Map imports = (Map) this.imports.get(elementNS); if (imports == null) { imports = new HashMap(); this.imports.put(elementNS, imports); } if (!imports.containsKey(location)) { Element xsdImport = owner.createElementNS(XSD_NS, schemaPrefix + "import"); xsdImport.setAttribute("namespace", elementNS); xsdImport.setAttribute("schemaLocation", location); schema.insertBefore(owner.createTextNode("\n"), schema.getFirstChild()); schema.insertBefore(xsdImport, schema.getFirstChild()); schema.insertBefore(owner.createTextNode("\n"), schema.getFirstChild()); imports.put(location, null); } } } } }
From source file:org.globus.wsrf.tools.wsdl.WSDLPreprocessor.java
private static XSModel loadSchema(Element schema, Definition def) { // add namespaces from definition element Map definitionNameSpaces = def.getNamespaces(); Set nameSpaces = definitionNameSpaces.entrySet(); Iterator nameSpacesIterator = nameSpaces.iterator(); while (nameSpacesIterator.hasNext()) { Entry nameSpaceEntry = (Entry) nameSpacesIterator.next(); if (!"".equals((String) nameSpaceEntry.getKey()) && !schema.hasAttributeNS("http://www.w3.org/2000/xmlns/", (String) nameSpaceEntry.getKey())) { Attr nameSpace = schema.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + nameSpaceEntry.getKey()); nameSpace.setValue((String) nameSpaceEntry.getValue()); schema.setAttributeNode(nameSpace); }/*from w ww . j a va 2 s. c o m*/ } LSInput schemaInput = new DOMInputImpl(); schemaInput .setStringData("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + XmlUtils.getElementAsString(schema)); log.info("Loading schema in types section of definition " + def.getDocumentBaseURI()); schemaInput.setSystemId(def.getDocumentBaseURI()); XMLSchemaLoader schemaLoader = new XMLSchemaLoader(); XSModel schemaModel = schemaLoader.load(schemaInput); log.info("Done loading"); return schemaModel; }
From source file:org.gvnix.flex.ui.MxmlRoundTripUtils.java
private static boolean addOrUpdateElements(Element original, Element proposed, boolean originalDocumentChanged) { NodeList proposedChildren = proposed.getChildNodes(); for (int i = 0; i < proposedChildren.getLength(); i++) { // check // proposed // elements and // compare to // originals to // find out if // we need to // add or // replace // elements Node node = proposedChildren.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element proposedElement = (Element) node; String proposedId = proposedElement.getAttribute("id"); if (proposedId.length() != 0) { // only proposed elements with // an id will be considered Element originalElement = XmlUtils.findFirstElement("//*[@id='" + proposedId + "']", original); if (null == originalElement) { // insert proposed element // given the original // document has no element // with a matching id Element placeHolder = XmlUtils.findFirstElementByName("util:placeholder", original); if (placeHolder != null) { // insert right before place // holder if we can find it placeHolder.getParentNode().insertBefore( original.getOwnerDocument().importNode(proposedElement, false), placeHolder); } else { // find the best place to insert the element if (proposed.getAttribute("id").length() != 0 || proposed.getTagName().substring(2).matches(":[a-z].*") || proposed.getTagName().equals("fx:Declarations")) { // try to find // the id of // the // proposed // element's // parent id // in // the // original // document Element originalParent = XmlUtils.findFirstElement( "//*[@id='" + proposed.getAttribute("id") + "']", original); if (originalParent != null) { // found parent // with the same // id, so we can // just add it as // new child originalParent.appendChild( original.getOwnerDocument().importNode(proposedElement, false)); } else if (proposed.getTagName().equals("fx:Declarations")) { originalParent = XmlUtils.findFirstElementByName("fx:Declarations", original); originalParent.appendChild( original.getOwnerDocument().importNode(proposedElement, true)); } else if (proposed.getTagName().substring(2).matches(":[a-z].*")) { // Likely an attribute tag rather than a // component, thus not allowed to have an // id, // so we must match on the next level up Element proposedParent = proposed.getParentNode() .getNodeType() == Node.ELEMENT_NODE ? (Element) proposed.getParentNode() : null; if (proposedParent != null && proposedParent.getAttribute("id").length() != 0) { String attrTag = proposed.getTagName() .substring(proposed.getTagName().indexOf(":") + 1); originalParent = XmlUtils.findFirstElement( "//*[@id='" + proposedParent.getAttribute("id") + "']/" + attrTag, original); if (originalParent != null) { // found a // matching // parent, // so we // can // just // add it // as new // child originalParent.appendChild( original.getOwnerDocument().importNode(proposedElement, false)); }//from ww w . j av a2 s. c om } } } } originalDocumentChanged = true; } else { // we found an element in the original document with // a matching id String originalElementHashCode = originalElement.getAttribute("z"); if (originalElementHashCode.length() > 0) { // only act // if a hash // code // exists if ("?".equals(originalElementHashCode) || originalElementHashCode .equals(MxmlRoundTripUtils.calculateUniqueKeyFor(originalElement))) { // only // act // if // hash // codes // match // (no // user // changes // in // the // element) // or // the // user // requests // for // the // hash // code // to // be // regenerated if (!equalElements(originalElement, proposedElement)) { // check if the // elements have // equal contents originalElement.getParentNode().replaceChild( original.getOwnerDocument().importNode(proposedElement, false), originalElement); // replace // the // original // with // the // proposed // element originalDocumentChanged = true; } if ("?".equals(originalElementHashCode)) { // replace // z // if // the // user // sets // its // value // to // '?' // as // an // indication // that // roo // should // take // over // the // management // of // this // element // again originalElement.setAttribute("z", MxmlRoundTripUtils.calculateUniqueKeyFor(proposedElement)); originalDocumentChanged = true; } } else { // if hash codes don't match we will mark the // element as z="user-managed" if (!originalElementHashCode.equals("user-managed")) { originalElement.setAttribute("z", "user-managed"); // mark the element // as // 'user-managed' // if the hash // codes don't // match any more originalDocumentChanged = true; } } } } } originalDocumentChanged = addOrUpdateElements(original, proposedElement, originalDocumentChanged); // walk // through // the // document // tree // recursively } } return originalDocumentChanged; }
From source file:org.gvnix.web.screen.roo.addon.WebScreenOperationsImpl.java
/** * Decides if write to disk is needed (ie updated or created)<br/> * Used for TAGx files/*from w w w. j a v a 2 s.c om*/ * * @param filePath * @param body * @return */ private boolean writeToDiskIfNecessary(String filePath, Element body) { // Build a string representation of the JSP ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); Transformer transformer = XmlUtils.createIndentingTransformer(); XmlUtils.writeXml(transformer, byteArrayOutputStream, body.getOwnerDocument()); String viewContent = byteArrayOutputStream.toString(); // If mutableFile becomes non-null, it means we need to use it to write // out the contents of jspContent to the file MutableFile mutableFile = null; if (fileManager.exists(filePath)) { // First verify if the file has even changed File newFile = new File(filePath); String existing = null; try { existing = IOUtils.toString(new FileReader(newFile)); } catch (IOException ignoreAndJustOverwriteIt) { LOGGER.finest("Problems writing ".concat(newFile.getAbsolutePath())); } if (!viewContent.equals(existing)) { mutableFile = fileManager.updateFile(filePath); } } else { mutableFile = fileManager.createFile(filePath); Validate.notNull(mutableFile, "Could not create '" + filePath + "'"); } if (mutableFile != null) { try { // We need to write the file out (it's a new file, or the // existing file has different contents) InputStream inputStream = null; OutputStreamWriter outputStream = null; try { inputStream = IOUtils.toInputStream(viewContent); outputStream = new OutputStreamWriter(mutableFile.getOutputStream()); IOUtils.copy(inputStream, outputStream); } finally { IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); } // Return and indicate we wrote out the file return true; } catch (IOException ioe) { throw new IllegalStateException("Could not output '" + mutableFile.getCanonicalPath() + "'", ioe); } } // A file existed, but it contained the same content, so we return false return false; }
From source file:org.gvnix.web.theme.roo.addon.ThemeOperationsImpl.java
/** * Decides if write to disk is needed (ie updated or created)<br/> * Used for TAGx files//from ww w. j ava2s .co m * * @param filePath * @param body * @return */ private boolean writeToDiskIfNecessary(String filePath, Element body) { // Build a string representation of the JSP ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); Transformer transformer = org.springframework.roo.support.util.XmlUtils.createIndentingTransformer(); org.springframework.roo.support.util.XmlUtils.writeXml(transformer, byteArrayOutputStream, body.getOwnerDocument()); String viewContent = byteArrayOutputStream.toString(); // If mutableFile becomes non-null, it means we need to use it to write // out the contents of jspContent to the file MutableFile mutableFile = null; if (fileManager.exists(filePath)) { // First verify if the file has even changed File newFile = new File(filePath); String existing = null; try { existing = IOUtils.toString(new FileReader(newFile)); } catch (IOException ignoreAndJustOverwriteIt) { LOGGER.finest("Problems reading file".concat(filePath)); } if (!viewContent.equals(existing)) { mutableFile = fileManager.updateFile(filePath); } } else { mutableFile = fileManager.createFile(filePath); Validate.notNull(mutableFile, "Could not create '" + filePath + "'"); } if (mutableFile != null) { try { // We need to write the file out (it's a new file, or the // existing file has different contents) OutputStreamWriter outputStream = null; InputStream inputStream = null; try { outputStream = new OutputStreamWriter(mutableFile.getOutputStream()); inputStream = IOUtils.toInputStream(viewContent); IOUtils.copy(inputStream, outputStream); } finally { IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(inputStream); } // Return and indicate we wrote out the file return true; } catch (IOException ioe) { throw new IllegalStateException("Could not output '" + mutableFile.getCanonicalPath() + "'", ioe); } } // A file existed, but it contained the same content, so we return false return false; }
From source file:org.infoglue.calendar.controllers.ContentTypeDefinitionController.java
/** * This method creates a parameter for the given input type. * This is to support form steering information later. *///ww w. ja v a 2s. co m private void addParameterElement(Element parent, String id, String inputTypeId) { Element parameter = parent.getOwnerDocument().createElement("param"); parameter.setAttribute("id", id); parameter.setAttribute("inputTypeId", inputTypeId); //Multiple values Element parameterValuesValues = parent.getOwnerDocument().createElement("values"); Element parameterValuesValue = parent.getOwnerDocument().createElement("value"); parameterValuesValue.setAttribute("id", "undefined" + (int) (Math.random() * 100)); parameterValuesValue.setAttribute("label", "undefined" + (int) (Math.random() * 100)); parameterValuesValues.appendChild(parameterValuesValue); parameter.appendChild(parameterValuesValues); parent.appendChild(parameter); }