List of usage examples for org.w3c.dom Element getOwnerDocument
public Document getOwnerDocument();
Document
object associated with this node. From source file:com.msopentech.odatajclient.engine.data.impl.AbstractODataBinder.java
@Override @SuppressWarnings("unchecked") public <T extends Entry> T getEntry(final ODataEntity entity, final Class<T> reference, final boolean setType) { final T entry = ResourceFactory.newEntry(reference); entry.setType(entity.getName());//from w w w. j a v a2 s . com // ------------------------------------------------------------- // Add edit and self link // ------------------------------------------------------------- final URI editLink = entity.getEditLink(); if (editLink != null) { final Link entryEditLink = ResourceFactory.newLinkForEntry(reference); entryEditLink.setTitle(entity.getName()); entryEditLink.setHref(editLink.toASCIIString()); entryEditLink.setRel(ODataConstants.EDIT_LINK_REL); entry.setEditLink(entryEditLink); } if (entity.isReadOnly()) { final Link entrySelfLink = ResourceFactory.newLinkForEntry(reference); entrySelfLink.setTitle(entity.getName()); entrySelfLink.setHref(entity.getLink().toASCIIString()); entrySelfLink.setRel(ODataConstants.SELF_LINK_REL); entry.setSelfLink(entrySelfLink); } // ------------------------------------------------------------- // ------------------------------------------------------------- // Append navigation links (handling inline entry / feed as well) // ------------------------------------------------------------- // handle navigation links for (ODataLink link : entity.getNavigationLinks()) { // append link LOG.debug("Append navigation link\n{}", link); entry.addNavigationLink(getLinkResource(link, ResourceFactory.linkClassForEntry(reference))); } // ------------------------------------------------------------- // ------------------------------------------------------------- // Append edit-media links // ------------------------------------------------------------- for (ODataLink link : entity.getEditMediaLinks()) { LOG.debug("Append edit-media link\n{}", link); entry.addMediaEditLink(getLinkResource(link, ResourceFactory.linkClassForEntry(reference))); } // ------------------------------------------------------------- // ------------------------------------------------------------- // Append association links // ------------------------------------------------------------- for (ODataLink link : entity.getAssociationLinks()) { LOG.debug("Append association link\n{}", link); entry.addAssociationLink(getLinkResource(link, ResourceFactory.linkClassForEntry(reference))); } // ------------------------------------------------------------- final Element content = newEntryContent(); if (entity.isMediaEntity()) { entry.setMediaEntryProperties(content); entry.setMediaContentSource(entity.getMediaContentSource()); entry.setMediaContentType(entity.getMediaContentType()); } else { entry.setContent(content); } for (ODataProperty prop : entity.getProperties()) { content.appendChild(toDOMElement(prop, content.getOwnerDocument(), setType)); } return entry; }
From source file:com.msopentech.odatajclient.engine.data.AbstractODataBinder.java
@Override public <T extends EntryResource> T getEntry(final ODataEntity entity, final Class<T> reference, final boolean setType) { final T entry = client.getResourceFactory().newEntry(reference); entry.setType(entity.getName());/*w w w. jav a 2 s . c o m*/ // ------------------------------------------------------------- // Add edit and self link // ------------------------------------------------------------- final URI editLink = entity.getEditLink(); if (editLink != null) { final LinkResource entryEditLink = client.getResourceFactory().newLinkForEntry(reference); entryEditLink.setTitle(entity.getName()); entryEditLink.setHref(editLink.toASCIIString()); entryEditLink.setRel(ODataConstants.EDIT_LINK_REL); entry.setEditLink(entryEditLink); } if (entity.isReadOnly()) { final LinkResource entrySelfLink = client.getResourceFactory().newLinkForEntry(reference); entrySelfLink.setTitle(entity.getName()); entrySelfLink.setHref(entity.getLink().toASCIIString()); entrySelfLink.setRel(ODataConstants.SELF_LINK_REL); entry.setSelfLink(entrySelfLink); } // ------------------------------------------------------------- // ------------------------------------------------------------- // Append navigation links (handling inline entry / feed as well) // ------------------------------------------------------------- // handle navigation links for (ODataLink link : entity.getNavigationLinks()) { // append link LOG.debug("Append navigation link\n{}", link); entry.addNavigationLink( getLinkResource(link, client.getResourceFactory().linkClassForEntry(reference))); } // ------------------------------------------------------------- // ------------------------------------------------------------- // Append edit-media links // ------------------------------------------------------------- for (ODataLink link : entity.getEditMediaLinks()) { LOG.debug("Append edit-media link\n{}", link); entry.addMediaEditLink(getLinkResource(link, client.getResourceFactory().linkClassForEntry(reference))); } // ------------------------------------------------------------- // ------------------------------------------------------------- // Append association links // ------------------------------------------------------------- for (ODataLink link : entity.getAssociationLinks()) { LOG.debug("Append association link\n{}", link); entry.addAssociationLink( getLinkResource(link, client.getResourceFactory().linkClassForEntry(reference))); } // ------------------------------------------------------------- final Element content = newEntryContent(); if (entity.isMediaEntity()) { entry.setMediaEntryProperties(content); entry.setMediaContentSource(entity.getMediaContentSource()); entry.setMediaContentType(entity.getMediaContentType()); } else { entry.setContent(content); } for (ODataProperty prop : entity.getProperties()) { content.appendChild(toDOMElement(prop, content.getOwnerDocument(), setType)); } return entry; }
From source file:com.twinsoft.convertigo.beans.core.Sequence.java
private static void buildOutputDom(Element root, OutputFilter outputFilter) { try {// w w w .j a v a 2 s .c o m DocumentTraversal traversal = (DocumentTraversal) root.getOwnerDocument(); TreeWalker walker = traversal.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, outputFilter, false); traverseLevel(walker, null, ""); outputFilter.doOutPut(); } finally { if (outputFilter != null) { outputFilter.map.clear(); } } }
From source file:com.wfreitas.camelsoap.SoapClient.java
private void injectParameters(Element element, Map params, String soapNs) { NodeList children = element.getChildNodes(); int childCount = children.getLength(); for (int i = 0; i < childCount; i++) { Node node = children.item(i); if (childCount == 1 && node.getNodeType() == Node.TEXT_NODE) { if (node.getNodeValue().equals("?")) { String ognl = OGNLUtils.getOGNLExpression(element, soapNs); Object param;/*from w w w . j a v a2s . c om*/ param = OGNLUtils.getParameter(ognl, params); element.removeChild(node); element.appendChild(element.getOwnerDocument().createTextNode(param.toString())); } } else if (node.getNodeType() == Node.ELEMENT_NODE) { injectParameters((Element) node, params, soapNs); } } element.removeAttributeNS(OGNLUtils.JBOSSESB_SOAP_NS, IS_CLONE_ATTRIB); element.removeAttributeNS(OGNLUtils.JBOSSESB_SOAP_NS, OGNLUtils.OGNL_ATTRIB); }
From source file:com.haulmont.cuba.restapi.XMLConverter.java
/** * Encodes the closure of a persistent instance into a XML element. * * @param visited// w ww . j ava 2s. c o m * @param entity the managed instance to be encoded. Can be null. * @param parent the parent XML element to which the new XML element be added. Must not be null. Must be * owned by a document. * @param isRef * @param metaClass @return the new element. The element has been appended as a child to the given parent in this method. * @param view view on which loaded the entity */ private Element encodeEntityInstance(HashSet<Entity> visited, final Entity entity, final Element parent, boolean isRef, MetaClass metaClass, View view) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { if (!readPermitted(metaClass)) return null; if (parent == null) throw new NullPointerException("No parent specified"); Document doc = parent.getOwnerDocument(); if (doc == null) throw new NullPointerException("No document specified"); if (entity == null) { return encodeRef(parent, entity); } isRef |= !visited.add(entity); if (isRef) { return encodeRef(parent, entity); } Element root = doc.createElement(ELEMENT_INSTANCE); parent.appendChild(root); root.setAttribute(ATTR_ID, ior(entity)); MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME); List<MetaProperty> properties = ConverterHelper.getOrderedProperties(metaClass); for (MetaProperty property : properties) { Element child; if (!attrViewPermitted(metaClass, property.getName())) continue; if (!isPropertyIncluded(view, property, metadataTools)) { continue; } Object value = entity.getValue(property.getName()); switch (property.getType()) { case DATATYPE: String nodeType; if (property.equals(metadataTools.getPrimaryKeyProperty(metaClass)) && !property.getJavaType().equals(String.class)) { // skipping id for non-String-key entities continue; } else if (property.getAnnotatedElement().isAnnotationPresent(Version.class)) { nodeType = "version"; } else { nodeType = "basic"; } child = doc.createElement(nodeType); child.setAttribute(ATTR_NAME, property.getName()); if (value == null) { encodeNull(child); } else { String str = property.getRange().asDatatype().format(value); encodeBasic(child, str, property.getJavaType()); } break; case ENUM: child = doc.createElement("enum"); child.setAttribute(ATTR_NAME, property.getName()); if (value == null) { encodeNull(child); } else { //noinspection unchecked String str = property.getRange().asEnumeration().format(value); encodeBasic(child, str, property.getJavaType()); } break; case COMPOSITION: case ASSOCIATION: { MetaClass meta = propertyMetaClass(property); //checks if the user permitted to read a property if (!readPermitted(meta)) { child = null; break; } View propertyView = (view == null ? null : view.getProperty(property.getName()).getView()); if (!property.getRange().getCardinality().isMany()) { boolean isEmbedded = property.getAnnotatedElement().isAnnotationPresent(Embedded.class); child = doc.createElement(isEmbedded ? "embedded" : property.getRange().getCardinality().name().replace(UNDERSCORE, DASH).toLowerCase()); child.setAttribute(ATTR_NAME, property.getName()); if (isEmbedded) { encodeEntityInstance(visited, (Entity) value, child, false, property.getRange().asClass(), propertyView); } else { encodeEntityInstance(visited, (Entity) value, child, false, property.getRange().asClass(), propertyView); } } else { child = doc.createElement(getCollectionReferenceTag(property)); child.setAttribute(ATTR_NAME, property.getName()); child.setAttribute(ATTR_MEMBER_TYPE, typeOfEntityProperty(property)); if (value == null) { encodeNull(child); break; } Collection<?> members = (Collection<?>) value; for (Object o : members) { Element member = doc.createElement(ELEMENT_MEMBER); child.appendChild(member); if (o == null) { encodeNull(member); } else { encodeEntityInstance(visited, (Entity) o, member, true, property.getRange().asClass(), propertyView); } } } break; } default: throw new IllegalStateException("Unknown property type"); } if (child != null) { root.appendChild(child); } } return root; }
From source file:hoot.services.models.osm.Relation.java
/** * Returns an XML representation of the element; does not add tags * * @param parent/*from www . j av a2s . c om*/ * XML node this element should be attached under * @param modifyingUserId * ID of the user which created this element * @param modifyingUserDisplayName * user display name of the user which created this element * @param multiLayerUniqueElementIds * if true, ID's are prepended with <map id>_<first letter of the * element type>_; this setting activated is not compatible with * standard OSM clients (specific to Hootenanny iD) * @param addChildren * if true, element children are added to the element xml * @return an XML element * @throws Exception */ public org.w3c.dom.Element toXml(final org.w3c.dom.Element parentXml, final long modifyingUserId, final String modifyingUserDisplayName, final boolean multiLayerUniqueElementIds, final boolean addChildren) throws Exception { org.w3c.dom.Element element = super.toXml(parentXml, modifyingUserId, modifyingUserDisplayName, multiLayerUniqueElementIds, addChildren); Document doc = parentXml.getOwnerDocument(); if (addChildren) { final List<CurrentRelationMembers> members = getMembers(); // output in sequence order; query returns list in the proper order for (CurrentRelationMembers member : members) { org.w3c.dom.Element memberElement = doc.createElement("member"); memberElement.setAttribute("type", member.getMemberType().toString().toLowerCase()); assert (StringUtils.trimToNull(memberElement.getAttribute("type")) != null); String role = member.getMemberRole(); if (StringUtils.isEmpty(member.getMemberRole())) { memberElement.setAttribute("role", member.getMemberRole()); role = ""; } memberElement.setAttribute("role", role); assert (memberElement.getAttribute("role") != null); memberElement.setAttribute("ref", String.valueOf(member.getMemberId())); assert (StringUtils.trimToNull(memberElement.getAttribute("ref")) != null); element.appendChild(memberElement); } } org.w3c.dom.Element elementWithTags = addTagsXml(element); if (elementWithTags == null) { return element; } else { return elementWithTags; } }
From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java
private boolean addAppInfo(String type, String value) { // if (declaration == null) { // return true; // }/*from www . j a va 2 s. co m*/ if (declaration != null) { if (declaration.getAnnotation() == null) { declaration.setAnnotation(annotation); } } else if (complexTypeDef != null && type.startsWith("X_Label")) { //$NON-NLS-1$ if (complexTypeDef.getAnnotation() == null) { complexTypeDef.setAnnotation(annotation); } } else { return true; } Element appinfo = annotation.createApplicationInformation(type); Node text = appinfo.getOwnerDocument().createTextNode(value); appinfo.appendChild(text); annotation.getElement().appendChild(appinfo); hasChanged = true; return true; }
From source file:eu.europa.ec.markt.dss.validation.xades.XAdESSignature.java
private Element getUnsignedSignatureProperties(Element signatureEl) { try {/*from w w w .j a va 2 s. c om*/ Element unsignedSignaturePropertiesNode = XMLUtils.getElement(signatureEl, "./ds:Object/xades:QualifyingProperties/xades:UnsignedProperties/xades:UnsignedSignatureProperties"); if (unsignedSignaturePropertiesNode == null) { Element qualifyingProperties = XMLUtils.getElement(signatureEl, "./ds:Object/xades:QualifyingProperties"); Element unsignedProperties = XMLUtils.getElement(qualifyingProperties, "./ds:Object/xades:QualifyingProperties/xades:UnsignedProperties"); if (unsignedProperties == null) { unsignedProperties = qualifyingProperties.getOwnerDocument().createElementNS(XADES_NAMESPACE, "UnsignedProperties"); qualifyingProperties.appendChild(unsignedProperties); } unsignedSignaturePropertiesNode = unsignedProperties.getOwnerDocument() .createElementNS(XADES_NAMESPACE, "UnsignedSignatureProperties"); unsignedProperties.appendChild(unsignedSignaturePropertiesNode); } return unsignedSignaturePropertiesNode; } catch (XPathExpressionException e) { // Should never happens throw new RuntimeException("Cannot build unsigned signature properties"); } }
From source file:com.amalto.workbench.utils.XSDAnnotationsStructure.java
private boolean addDocumentation(String value) { if (declaration.getAnnotation() == null) { declaration.setAnnotation(annotation); }/* ww w . j a v a2s. c o m*/ Element appinfo = annotation.createUserInformation("documentation");//$NON-NLS-1$ Node text = appinfo.getOwnerDocument().createTextNode(value); appinfo.appendChild(text); annotation.getElement().appendChild(appinfo); hasChanged = true; return true; }
From source file:com.legstar.jaxb.gen.CobolJAXBCustomizer.java
/** * Inject a serializable element in the JAXB global bindings annotation. * <p/>/*from w ww . j a v a 2 s . c o m*/ * If the element is already present we update its attributes. * * @param globalbindingsEl the global bindings node * @param jaxbNamespace the JAXB namespace * @param jaxbNamespacePrefix the JAXB namespace prefix */ public void injectJaxbSerializableAnnotation(final Element globalbindingsEl, final String jaxbNamespace, final String jaxbNamespacePrefix) { Element serializableEl = null; NodeList nl = globalbindingsEl.getElementsByTagNameNS(jaxbNamespace, JAXB_SERIALIZABLE); if (nl.getLength() > 0) { serializableEl = (Element) nl.item(0); } else { serializableEl = globalbindingsEl.getOwnerDocument().createElementNS(jaxbNamespace, jaxbNamespacePrefix + ':' + JAXB_SERIALIZABLE); globalbindingsEl.appendChild(serializableEl); } serializableEl.setAttribute(JAXB_UID, Long.toString(getJaxbGenModel().getSerializableUid())); }