List of usage examples for org.w3c.dom Element setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:org.apache.ode.il.epr.WSAEndpoint.java
public void setSessionId(String sessionId) { NodeList idList = _eprElmt.getElementsByTagNameNS(Namespaces.ODE_SESSION_NS, "session"); if (idList.getLength() > 0) idList.item(0).setTextContent(sessionId); else {/*from w w w.j a v a 2s . c o m*/ Element sessElmt = _eprElmt.getOwnerDocument().createElementNS(Namespaces.ODE_SESSION_NS, "session"); sessElmt.setTextContent(sessionId); _eprElmt.appendChild(sessElmt); } }
From source file:org.apache.ode.il.epr.WSAEndpoint.java
public void fromMap(Map eprMap) { Document doc = DOMUtils.newDocument(); Element serviceRef = doc.createElementNS(SERVICE_REF_QNAME.getNamespaceURI(), SERVICE_REF_QNAME.getLocalPart()); doc.appendChild(serviceRef);/*from w w w . j a v a 2s . c om*/ _eprElmt = doc.createElementNS(Namespaces.WS_ADDRESSING_NS, "EndpointReference"); serviceRef.appendChild(_eprElmt); Element addrElmt = doc.createElementNS(Namespaces.WS_ADDRESSING_NS, "Address"); addrElmt.setTextContent((String) eprMap.get(ADDRESS)); if (eprMap.get(SESSION) != null) { Element sessElmt = doc.createElementNS(Namespaces.ODE_SESSION_NS, "session"); sessElmt.setTextContent((String) eprMap.get(SESSION)); _eprElmt.appendChild(sessElmt); } if (eprMap.get(SERVICE_QNAME) != null) { Element metadataElmt = doc.createElementNS(Namespaces.WS_ADDRESSING_NS, "Metadata"); _eprElmt.appendChild(metadataElmt); Element serviceElmt = doc.createElementNS(Namespaces.WS_ADDRESSING_WSDL_NS, "ServiceName"); metadataElmt.appendChild(serviceElmt); QName serviceQName = (QName) eprMap.get(SERVICE_QNAME); serviceElmt.setAttribute("xmlns:servicens", serviceQName.getNamespaceURI()); serviceElmt.setTextContent("servicens:" + serviceQName.getLocalPart()); serviceElmt.setAttribute("EndpointName", (String) eprMap.get(PORT_NAME)); } _eprElmt.appendChild(addrElmt); if (__log.isDebugEnabled()) __log.debug("Constructed a new WSAEndpoint: " + DOMUtils.domToString(_eprElmt)); }
From source file:org.apache.openaz.xacml.pdp.policy.dom.DOMAttributeAssignmentExpression.java
public static boolean repair(Node nodeAttributeAssignmentExpression) throws DOMStructureException { Element elementAttributeAssignmentExpression = DOMUtil.getElement(nodeAttributeAssignmentExpression); boolean result = false; if (DOMUtil.getFirstChildElement(elementAttributeAssignmentExpression) == null) { /*//from ww w. jav a 2 s . com * See if we can repair the <AttributeAssignmentExpression * DataType="">string</AttributeAssignmentExpression> pattern */ Identifier identifier = DOMUtil.getIdentifierAttribute(elementAttributeAssignmentExpression, XACML3.ATTRIBUTE_DATATYPE); String textContent = elementAttributeAssignmentExpression.getTextContent(); if (textContent != null) { textContent = textContent.trim(); } if (textContent != null && textContent.length() > 0 && identifier != null) { Element attributeValue = elementAttributeAssignmentExpression.getOwnerDocument() .createElementNS(XACML3.XMLNS, XACML3.ELEMENT_ATTRIBUTEVALUE); attributeValue.setAttribute(XACML3.ATTRIBUTE_DATATYPE, identifier.stringValue()); attributeValue.setTextContent(textContent); logger.warn("Adding a new AttributeValue using the DataType from the AttributeAssignment"); elementAttributeAssignmentExpression.removeAttribute(XACML3.ATTRIBUTE_DATATYPE); while (elementAttributeAssignmentExpression.hasChildNodes()) { elementAttributeAssignmentExpression .removeChild(elementAttributeAssignmentExpression.getFirstChild()); } elementAttributeAssignmentExpression.appendChild(attributeValue); result = true; } else { throw DOMUtil.newMissingElementException(elementAttributeAssignmentExpression, XACML3.XMLNS, XACML3.ELEMENT_EXPRESSION); } } result = DOMUtil.repairIdentifierAttribute(elementAttributeAssignmentExpression, XACML3.ATTRIBUTE_ATTRIBUTEID, logger) || result; return result; }
From source file:org.apache.openaz.xacml.std.dom.DOMUtil.java
public static boolean repairIdentifierContent(Element element, Log logger) throws DOMStructureException { Identifier identifier = getIdentifierContent(element); if (identifier == null) { identifier = IdentifierImpl.gensym(); logger.warn("Setting missing content to " + identifier.stringValue()); element.setTextContent(identifier.stringValue()); return true; }//from ww w . j a va2 s.co m return false; }
From source file:org.apache.shindig.gadgets.parse.caja.CajaCssSanitizer.java
/** * Sanitize the CSS content of a style tag. * @param styleElem to sanitize//from w ww . j a v a2 s.co m * @param linkContext url of containing content * @param gadgetContext The gadget context. * @param importRewriter to rewrite @imports to sanitizing proxy * @param imageRewriter to rewrite images to sanitizing proxy */ public void sanitize(Element styleElem, Uri linkContext, GadgetContext gadgetContext, ProxyUriManager importRewriter, ProxyUriManager imageRewriter) { String content = null; try { CssTree.StyleSheet stylesheet = parser.parseDom(styleElem.getTextContent(), linkContext); sanitize(stylesheet, linkContext, gadgetContext, importRewriter, imageRewriter); // Write the rewritten CSS back into the element content = parser.serialize(stylesheet); } catch (GadgetException ge) { // Failed to parse stylesheet so log and continue LOG.log(Level.INFO, "Failed to parse stylesheet", ge); } if (StringUtils.isEmpty(content)) { // Remove the owning node styleElem.getParentNode().removeChild(styleElem); } else { styleElem.setTextContent(content); } }
From source file:org.apache.shindig.gadgets.render.RenderingGadgetRewriter.java
protected void injectGadgetBeacon(Gadget gadget, Node headTag, Node firstHeadChild) throws GadgetException { Element beaconNode = headTag.getOwnerDocument().createElement("script"); beaconNode.setTextContent(IS_GADGET_BEACON); headTag.insertBefore(beaconNode, firstHeadChild); }
From source file:org.apache.shindig.gadgets.rewrite.CssRequestRewriter.java
/** * Rewrite the CSS content in a style DOM node. * @param styleNode Rewrite the CSS content of this node * @param source Uri of content/*www . ja v a 2 s. co m*/ * @param rewriter Rewrite urls * @param extractImports If true remove the import statements from the output and return their * referenced URIs. * @return Empty list of extracted import URIs. */ public List<String> rewrite(Element styleNode, Uri source, LinkRewriter rewriter, boolean extractImports) { try { List<Object> stylesheet = cssParser.parse(styleNode.getTextContent()); List<String> imports = rewrite(stylesheet, source, rewriter, extractImports); // Write the rewritten CSS back into the element String content = cssParser.serialize(stylesheet); if (StringUtils.isEmpty(content) || StringUtils.isWhitespace(content)) { // Remove the owning node styleNode.getParentNode().removeChild(styleNode); } else { styleNode.setTextContent(content); } return imports; } catch (GadgetException ge) { if (ge.getCause() instanceof ParseException) { logger.log(Level.WARNING, "Caja CSS parse failure: " + ge.getCause().getMessage() + " for " + source); return Collections.emptyList(); } else { throw new RuntimeException(ge); } } }
From source file:org.apache.shindig.gadgets.rewrite.CssResponseRewriter.java
/** * Rewrite the CSS content in a style DOM node. * @param styleNode Rewrite the CSS content of this node * @param source Uri of content// w w w .ja v a 2 s .c o m * @param uriMaker a UriMaker * @param extractImports If true remove the import statements from the output and return their * referenced URIs. * @param gadgetContext The gadgetContext * @return Empty list of extracted import URIs. */ public List<String> rewrite(Element styleNode, Uri source, UriMaker uriMaker, boolean extractImports, GadgetContext gadgetContext) throws RewritingException { try { CssTree.StyleSheet stylesheet = cssParser.parseDom(styleNode.getTextContent(), source); List<String> imports = rewrite(stylesheet, source, uriMaker, extractImports, gadgetContext); // Write the rewritten CSS back into the element String content = cssParser.serialize(stylesheet); if (StringUtils.isEmpty(content) || StringUtils.isWhitespace(content)) { // Remove the owning node styleNode.getParentNode().removeChild(styleNode); } else { styleNode.setTextContent(content); } return imports; } catch (GadgetException ge) { if (ge.getCause() instanceof ParseException) { LOG.log(Level.WARNING, "Caja CSS parse failure: " + ge.getCause().getMessage() + " for " + source); return Collections.emptyList(); } else { throw new RewritingException(ge, ge.getHttpStatusCode()); } } }
From source file:org.apache.shindig.gadgets.rewrite.TemplateRewriter.java
private void injectTemplateLibraryAssets(TemplateResource resource, Element head) { Element contentElement; switch (resource.getType()) { case JAVASCRIPT: contentElement = head.getOwnerDocument().createElement("script"); contentElement.setAttribute("type", "text/javascript"); break;/* w ww . j a va 2 s .com*/ case STYLE: contentElement = head.getOwnerDocument().createElement("style"); contentElement.setAttribute("type", "text/css"); break; default: throw new IllegalStateException("Unhandled type"); } if (resource.isSafe()) { SanitizingGadgetRewriter.bypassSanitization(contentElement, false); } contentElement.setTextContent(resource.getContent()); head.appendChild(contentElement); }
From source file:org.apache.shindig.gadgets.rewrite.TemplateRewriter.java
private void injectTemplateLibrary(TemplateLibrary library, Element head) { try {//from ww w. j a v a2s . c om String libraryContent = library.serialize(); if (StringUtils.isEmpty(libraryContent)) { return; } Element scriptElement = head.getOwnerDocument().createElement("script"); scriptElement.setAttribute("type", "text/javascript"); StringBuilder buffer = new StringBuilder(); buffer.append("opensocial.template.Loader.loadContent("); JsonSerializer.appendString(buffer, library.serialize()); buffer.append(','); JsonSerializer.appendString(buffer, library.getLibraryUri().toString()); buffer.append(");"); scriptElement.setTextContent(buffer.toString()); head.appendChild(scriptElement); } catch (IOException ioe) { // This should never happen. } }