List of usage examples for org.w3c.dom Element setAttribute
public void setAttribute(String name, String value) throws DOMException;
From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.AbstractXmlElementConverter.java
protected void setAttribute(Element xmlElement, String attributeName, Object value, Properties catalinaProperties, boolean required) { String oldValue = xmlElement.getAttribute(attributeName); String valueToWrite = determineNewValue(oldValue, value, catalinaProperties); if (required || (valueToWrite != null && !"".equals(valueToWrite))) { xmlElement.setAttribute(attributeName, valueToWrite); } else {//from w w w .j av a 2 s. c o m xmlElement.removeAttribute(attributeName); } }
From source file:io.cos.cas.authentication.handler.support.OpenScienceFrameworkPrincipalFromRequestRemoteUserNonInteractiveCredentialsAction.java
/** * Normalize the Remote Principal credential. * * @param credential the credential object bearing the username, password, etc... * @return the json object to serialize for authorization with the OSF API * @throws ParserConfigurationException a parser configuration exception * @throws TransformerException a transformer exception */// w w w . j a v a2s .com private JSONObject normalizeRemotePrincipal(final OpenScienceFrameworkCredential credential) throws ParserConfigurationException, TransformerException { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = factory.newDocumentBuilder(); final Document document = builder.newDocument(); final Element rootElement = document.createElement("auth"); document.appendChild(rootElement); for (final String key : credential.getAuthenticationHeaders().keySet()) { final Element attribute = document.createElement("attribute"); attribute.setAttribute("name", key); attribute.setAttribute("value", credential.getAuthenticationHeaders().get(key)); rootElement.appendChild(attribute); } // run the auth document through the transformer final DOMSource source = new DOMSource(document); final StringWriter writer = new StringWriter(); final StreamResult result = new StreamResult(writer); this.institutionsAuthTransformer.transform(source, result); // convert transformed xml to json return XML.toJSONObject(writer.getBuffer().toString()); }
From source file:com.intuit.karate.cucumber.KarateJunitFormatter.java
private void addDummyTestCase() { Element dummy = doc.createElement("testcase"); dummy.setAttribute("classname", "dummy"); dummy.setAttribute("name", "dummy"); rootElement.appendChild(dummy);/*from w ww . j av a 2s . co m*/ Element skipped = doc.createElement("skipped"); skipped.setAttribute("message", "No features found"); dummy.appendChild(skipped); }
From source file:it.unibas.spicy.persistence.xml.operators.ExportXSD.java
private void processForeignKeyConstraints(IDataSourceProxy dataSource, Node node, Document document) { int i = 0;/*from ww w . j a v a 2 s .co m*/ String name; for (ForeignKeyConstraint fkConstraint : dataSource.getForeignKeyConstraints()) { Element keyRefTag; i++; name = "keyRef" + i; keyRefTag = document.createElement(PREFIX + "keyref"); keyRefTag.setAttribute("name", name); if (fkConstraint.getKeyConstraint() == null || mapOfKeyConstraints.get(fkConstraint.getKeyConstraint()) == null) { throw new IllegalArgumentException(" --- Unable to locate referred key in a foreignKey constraint"); } keyRefTag.setAttribute("refer", mapOfKeyConstraints.get(fkConstraint.getKeyConstraint())); Element selectorTag = document.createElement(PREFIX + "selector"); selectorTag.setAttribute("xpath", ".//" + fkConstraint.getForeignKeyPaths().get(0) .getLastNode(dataSource.getIntermediateSchema()).getFather().getLabel()); keyRefTag.appendChild(selectorTag); for (PathExpression pathExpression : fkConstraint.getForeignKeyPaths()) { Element fieldTag = document.createElement(PREFIX + "field"); keyRefTag.appendChild(fieldTag); String xpath = ""; if (pathExpression.getLastNode(dataSource.getIntermediateSchema()) instanceof MetadataNode) { xpath = "@"; } xpath += pathExpression.getLastNode(dataSource.getIntermediateSchema()).getLabel(); fieldTag.setAttribute("xpath", xpath); } node.appendChild(keyRefTag); } }
From source file:com.microsoft.windowsazure.messaging.Registration.java
/** * Creates an XML representation of the Registration * @throws Exception/* w w w. j a va2 s.c o m*/ */ String toXml() throws Exception { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return null; } }); Document doc = builder.newDocument(); Element entry = doc.createElement("entry"); entry.setAttribute("xmlns", "http://www.w3.org/2005/Atom"); doc.appendChild(entry); appendNodeWithValue(doc, entry, "id", getURI()); appendNodeWithValue(doc, entry, "updated", getUpdatedString()); appendContentNode(doc, entry); return getXmlString(doc.getDocumentElement()); }
From source file:com.microsoft.windowsazure.messaging.Registration.java
/** * Appends the content node//from www .j av a 2 s . c om * @param doc The document to modify * @param entry The parent element */ private void appendContentNode(Document doc, Element entry) { Element content = doc.createElement("content"); content.setAttribute("type", "application/xml"); entry.appendChild(content); Element registrationDescription = doc.createElement(getSpecificPayloadNodeName()); registrationDescription.setAttribute("xmlns:i", "http://www.w3.org/2001/XMLSchema-instance"); registrationDescription.setAttribute("xmlns", "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"); content.appendChild(registrationDescription); appendNodeWithValue(doc, registrationDescription, "ETag", getETag()); appendNodeWithValue(doc, registrationDescription, "ExpirationTime", getExpirationTimeString()); appendNodeWithValue(doc, registrationDescription, "RegistrationId", getRegistrationId()); appendTagsNode(doc, registrationDescription); appendCustomPayload(doc, registrationDescription); }
From source file:com.redhat.plugin.eap6.EAP6DeploymentStructureMojo.java
protected void fillModuleEntries(Document doc, Element dependencies, Collection<String> modules) throws XPathExpressionException { for (String module : modules) { XPathExpression xp = xpf.newXPath().compile("module [@name=\"" + module + "\"]"); // getLog().debug(xp.toString()); Object result = xp.evaluate(dependencies, XPathConstants.NODE); if (result == null) { getLog().debug("insert module-dependency for " + module); Element moduleEl = doc.createElement("module"); moduleEl.setAttribute("name", module); if (defaultSlot != null && !defaultSlot.isEmpty()) { moduleEl.setAttribute("slot", defaultSlot); }//from w ww . jav a2s . c om if (exportModules) { moduleEl.setAttribute("export", "true"); } dependencies.appendChild(moduleEl); // if (verbose) { // getLog().debug("Module <" + moduleEl.getAttribute("name") + ">:" + moduleEl); // } } else { if (verbose) { getLog().debug("unresolved dependency with module-name " + module); } printXpathResult(result); } } }
From source file:es.gob.afirma.signers.ooxml.be.fedict.eid.applet.service.signer.ooxml.AbstractOOXMLSignatureService.java
private ZipOutputStream copyOOXMLContent(final String signatureZipEntryName, final OutputStream signedOOXMLOutputStream) throws IOException, ParserConfigurationException, SAXException, TransformerException { final ZipOutputStream zipOutputStream = new ZipOutputStream(signedOOXMLOutputStream); final ZipInputStream zipInputStream = new ZipInputStream( new ByteArrayInputStream(this.getOfficeOpenXMLDocument())); ZipEntry zipEntry;// ww w. j a v a 2 s . c om boolean hasOriginSigsRels = false; while (null != (zipEntry = zipInputStream.getNextEntry())) { zipOutputStream.putNextEntry(new ZipEntry(zipEntry.getName())); if ("[Content_Types].xml".equals(zipEntry.getName())) { //$NON-NLS-1$ final Document contentTypesDocument = loadDocumentNoClose(zipInputStream); final Element typesElement = contentTypesDocument.getDocumentElement(); // We need to add an Override element. final Element overrideElement = contentTypesDocument.createElementNS( "http://schemas.openxmlformats.org/package/2006/content-types", "Override"); //$NON-NLS-1$ //$NON-NLS-2$ overrideElement.setAttribute("PartName", "/" + signatureZipEntryName); //$NON-NLS-1$ //$NON-NLS-2$ overrideElement.setAttribute("ContentType", //$NON-NLS-1$ "application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml"); //$NON-NLS-1$ typesElement.appendChild(overrideElement); final Element nsElement = contentTypesDocument.createElement("ns"); //$NON-NLS-1$ nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:tns", //$NON-NLS-1$ "http://schemas.openxmlformats.org/package/2006/content-types"); //$NON-NLS-1$ final NodeList nodeList = XPathAPI.selectNodeList(contentTypesDocument, "/tns:Types/tns:Default[@Extension='sigs']", nsElement); //$NON-NLS-1$ if (0 == nodeList.getLength()) { // Add Default element for 'sigs' extension. final Element defaultElement = contentTypesDocument.createElementNS( "http://schemas.openxmlformats.org/package/2006/content-types", "Default"); //$NON-NLS-1$ //$NON-NLS-2$ defaultElement.setAttribute("Extension", "sigs"); //$NON-NLS-1$ //$NON-NLS-2$ defaultElement.setAttribute("ContentType", //$NON-NLS-1$ "application/vnd.openxmlformats-package.digital-signature-origin"); //$NON-NLS-1$ typesElement.appendChild(defaultElement); } writeDocumentNoClosing(contentTypesDocument, zipOutputStream, false); } else if ("_rels/.rels".equals(zipEntry.getName())) { //$NON-NLS-1$ final Document relsDocument = loadDocumentNoClose(zipInputStream); final Element nsElement = relsDocument.createElement("ns"); //$NON-NLS-1$ nsElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:tns", RELATIONSHIPS_SCHEMA); //$NON-NLS-1$ final NodeList nodeList = XPathAPI.selectNodeList(relsDocument, "/tns:Relationships/tns:Relationship[@Type='http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin']", //$NON-NLS-1$ nsElement); if (0 == nodeList.getLength()) { final Element relationshipElement = relsDocument.createElementNS(RELATIONSHIPS_SCHEMA, "Relationship"); //$NON-NLS-1$ relationshipElement.setAttribute("Id", "rel-id-" + UUID.randomUUID().toString()); //$NON-NLS-1$ //$NON-NLS-2$ relationshipElement.setAttribute("Type", //$NON-NLS-1$ "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin"); //$NON-NLS-1$ relationshipElement.setAttribute("Target", "_xmlsignatures/origin.sigs"); //$NON-NLS-1$ //$NON-NLS-2$ relsDocument.getDocumentElement().appendChild(relationshipElement); } writeDocumentNoClosing(relsDocument, zipOutputStream, false); } else if (zipEntry.getName().startsWith("_xmlsignatures/_rels/") //$NON-NLS-1$ && zipEntry.getName().endsWith(".rels")) { //$NON-NLS-1$ hasOriginSigsRels = true; final Document originSignRelsDocument = loadDocumentNoClose(zipInputStream); final Element relationshipElement = originSignRelsDocument.createElementNS(RELATIONSHIPS_SCHEMA, "Relationship"); //$NON-NLS-1$ relationshipElement.setAttribute("Id", "rel-" + UUID.randomUUID().toString()); //$NON-NLS-1$ //$NON-NLS-2$ relationshipElement.setAttribute("Type", //$NON-NLS-1$ "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature"); //$NON-NLS-1$ relationshipElement.setAttribute("Target", FilenameUtils.getName(signatureZipEntryName)); //$NON-NLS-1$ originSignRelsDocument.getDocumentElement().appendChild(relationshipElement); writeDocumentNoClosing(originSignRelsDocument, zipOutputStream, false); } else { IOUtils.copy(zipInputStream, zipOutputStream); } } if (!hasOriginSigsRels) { // Add signature relationships document. addOriginSigsRels(signatureZipEntryName, zipOutputStream); addOriginSigs(zipOutputStream); } // Return. zipInputStream.close(); return zipOutputStream; }
From source file:net.phoenix.thrift.xml.ProcessorBeanDefinitionParser.java
private String parseBeanName(Element element) { String beanName = element.getAttribute("id"); if (StringUtils.isEmpty(beanName)) { beanName = element.getAttribute("name"); }/*from ww w. j a v a2 s .c o m*/ if (StringUtils.isEmpty(beanName)) { beanName = "rpc-processor"; } if (StringUtils.isEmpty(element.getAttribute("id"))) { element.setAttribute("id", beanName); } return beanName; }
From source file:com.icesoft.faces.component.ext.renderkit.GroupRenderer.java
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException { try {/*from w w w . j av a 2s . c om*/ String viewID = facesContext.getViewRoot().getViewId(); String style = ((HtmlPanelGroup) uiComponent).getStyle(); String styleClass = ((HtmlPanelGroup) uiComponent).getStyleClass(); String blockingFlag = (String) facesContext.getExternalContext().getRequestMap().get("BlockingServlet"); String dndType = getDndType(uiComponent); DOMContext domContext = DOMContext.attachDOMContext(facesContext, uiComponent); if (!domContext.isInitialized()) { Element rootSpan = domContext.createElement(HTML.DIV_ELEM); domContext.setRootNode(rootSpan); setRootElementId(facesContext, rootSpan, uiComponent); if (dndType != null) { // Drag an drop needs some hidden fields UIComponent form = findForm(uiComponent); String formId = form.getClientId(facesContext); FormRenderer.addHiddenField(facesContext, ClientIdPool.get( formId + UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance()) + HIDDEN_FIELD)); } } Element rootSpan = (Element) domContext.getRootNode(); if (dndType != null) { DnDCache.getInstance(facesContext, true).put(uiComponent.getClientId(facesContext), (HtmlPanelGroup) uiComponent, facesContext); StringBuffer dropCall = new StringBuffer(); String call = addJavascriptCalls(uiComponent, dndType, null, facesContext, dropCall); String clientId = uiComponent.getClientId(facesContext); Element script = domContext.createElement(HTML.SCRIPT_ELEM); script.setAttribute(HTML.ID_ATTR, ClientIdPool.get(clientId + "script")); script.appendChild(domContext.createTextNodeUnescaped(dropCall.toString())); rootSpan.appendChild(script); Map rendererJavascriptDraggable = new HashMap(); rendererJavascriptDraggable.put(HTML.ONMOUSEOUT_ATTR, "Ice.Scriptaculous.Draggable.removeMe(this.id);"); rendererJavascriptDraggable.put(HTML.ONMOUSEMOVE_ATTR, call); rendererJavascriptDraggable.put(HTML.ONMOUSEOVER_ATTR, dropCall.toString()); LocalEffectEncoder.encode(facesContext, uiComponent, PASSTHRU_JS_EVENTS, rendererJavascriptDraggable, rootSpan, null); } else { LocalEffectEncoder.encode(facesContext, uiComponent, PASSTHRU_JS_EVENTS, null, rootSpan, null); } if (styleClass != null) { rootSpan.setAttribute("class", styleClass); } JavascriptContext.fireEffect(uiComponent, facesContext); String extraStyle = null; String scrollWidth = (String) uiComponent.getAttributes().get("scrollWidth"); String scrollHeight = (String) uiComponent.getAttributes().get("scrollHeight"); if (scrollHeight != null || scrollWidth != null) { if (extraStyle == null) { extraStyle = ""; } if (scrollHeight == null) { extraStyle += "width:" + scrollWidth + ";overflow:auto;"; } else if (scrollWidth == null) { extraStyle += "height:" + scrollHeight + ";overflow:auto;"; } else { extraStyle += "width:" + scrollWidth + ";height:" + scrollHeight + ";overflow:auto;"; } } CurrentStyle.apply(facesContext, uiComponent, null, extraStyle); MenuPopupHelper.renderMenuPopupHandler(facesContext, uiComponent, rootSpan); PassThruAttributeRenderer.renderNonBooleanHtmlAttributes(uiComponent, rootSpan, passThruAttributes); domContext.stepInto(uiComponent); // domContext.stepOver(); } catch (Exception e) { e.printStackTrace(); } }