List of usage examples for org.w3c.dom Element setAttribute
public void setAttribute(String name, String value) throws DOMException;
From source file:bpsperf.modelgen.BPMNGenerator.java
public void generateRESTTaskSequence(int numNodes, String serviceURL) throws Exception { Element start = addNode(startEvent, "startEvent"); Element rtaskS = null;/*from ww w.j av a 2 s. com*/ for (int i = 1; i <= numNodes; i++) { Element rtask = addNode(serviceTask, "rt" + i); rtask.setAttributeNS(activitins, "class", "org.wso2.carbon.bpmn.extensions.rest.SyncInvokeTask"); Element extensions = addElement(rtask, ns, "extensionElements"); Element serviceURLField = addElement(extensions, activitins, "field"); serviceURLField.setAttribute("name", "serviceURL"); Element expression1 = addElement(serviceURLField, activitins, "expression"); expression1.setTextContent(serviceURL); Element methodField = addElement(extensions, activitins, "field"); methodField.setAttribute("name", "method"); Element expression2 = addElement(methodField, activitins, "string"); CDATASection postData = doc.createCDATASection("POST"); expression2.appendChild(postData); Element inputField = addElement(extensions, activitins, "field"); inputField.setAttribute("name", "input"); Element expression3 = addElement(inputField, activitins, "expression"); expression3.setTextContent("Message sent from: rt" + i); Element voutField = addElement(extensions, activitins, "field"); voutField.setAttribute("name", "vout"); Element expression4 = addElement(voutField, activitins, "string"); CDATASection outvarData = doc.createCDATASection("outvar1"); expression4.appendChild(outvarData); if (rtaskS == null) { connect(start, rtask); } else { connect(rtaskS, rtask); } rtaskS = rtask; } Element end = addNode(endEvent, "endEvent"); connect(rtaskS, end); }
From source file:eu.europa.esig.dss.xades.signature.EnvelopingSignatureBuilder.java
/** * Adds signature value to the signature and returns XML signature (InMemoryDocument) * * @param signatureValue// w w w . ja v a 2s . com * @return * @throws DSSException */ @Override public DSSDocument signDocument(final byte[] signatureValue) throws DSSException { if (!built) { build(); } final EncryptionAlgorithm encryptionAlgorithm = params.getEncryptionAlgorithm(); final byte[] signatureValueBytes = DSSSignatureUtils.convertToXmlDSig(encryptionAlgorithm, signatureValue); final String signatureValueBase64Encoded = Base64.encodeBase64String(signatureValueBytes); final Text signatureValueNode = documentDom.createTextNode(signatureValueBase64Encoded); signatureValueDom.appendChild(signatureValueNode); final List<DSSReference> references = params.getReferences(); for (final DSSReference reference : references) { // <ds:Object> final String base64EncodedOriginalDocument = reference.getContents().getBase64Encoded(); final Element objectDom = DSSXMLUtils.addTextElement(documentDom, signatureDom, XMLSignature.XMLNS, DS_OBJECT, base64EncodedOriginalDocument); final String id = reference.getUri().substring(1); objectDom.setAttribute(ID, id); } byte[] documentBytes = DSSXMLUtils.transformDomToByteArray(documentDom); final InMemoryDocument inMemoryDocument = new InMemoryDocument(documentBytes); inMemoryDocument.setMimeType(MimeType.XML); return inMemoryDocument; }
From source file:hd3gtv.as5kpc.protocol.ProtocolHandler.java
public ServerResponseHWstatus getHardwareStatus() throws IOException { Document document = createDocument(); Element root_ams_element = document.createElement("AMS"); document.appendChild(root_ams_element); Element last_order_element = document.createElement("Configuration"); Element hs = document.createElement("GetHardwareStatus"); hs.setAttribute("Verbose", "true"); last_order_element.appendChild(hs);//from w w w. j a v a2 s.com root_ams_element.appendChild(last_order_element); return (ServerResponseHWstatus) send(document, new ServerResponseHWstatus()); }
From source file:de.crowdcode.movmvn.plugin.general.GeneralPlugin.java
private Element createPomRootAndTitle(Document doc) { Element rootElement = doc.createElement("project"); doc.appendChild(rootElement);//from w ww .ja v a 2s. c om rootElement.setAttribute("xmlns", "http://maven.apache.org/POM/4.0.0"); rootElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); rootElement.setAttribute("xsi:schemaLocation", "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"); Element modelVersion = doc.createElement("modelVersion"); modelVersion.appendChild(doc.createTextNode("4.0.0")); rootElement.appendChild(modelVersion); createPomGroupArtifactVersion(doc, rootElement, "de.xxx", context.getProjectName(), "1.0.0-SNAPSHOT"); Element packaging = doc.createElement("packaging"); packaging.appendChild(doc.createTextNode("jar")); rootElement.appendChild(packaging); Element name = doc.createElement("name"); name.appendChild(doc.createTextNode(context.getProjectName())); rootElement.appendChild(name); Element url = doc.createElement("url"); url.appendChild(doc.createTextNode("http://maven.apache.org")); rootElement.appendChild(url); return rootElement; }
From source file:DomUtils.java
/** * Rename element./*from w w w . jav a 2 s .co m*/ * @param element The element to be renamed. * @param replacementElement The tag name of the replacement element. * @param keepChildContent <code>true</code> if the target element's child content * is to be copied to the replacement element, false if not. Default <code>true</code>. * @param keepAttributes <code>true</code> if the target element's attributes * are to be copied to the replacement element, false if not. Default <code>true</code>. * @return The renamed element. */ public static Element renameElement(Element element, String replacementElement, boolean keepChildContent, boolean keepAttributes) { Element replacement = element.getOwnerDocument().createElement(replacementElement); if (keepChildContent) { DomUtils.copyChildNodes(element, replacement); } if (keepAttributes) { NamedNodeMap attributes = element.getAttributes(); int attributeCount = attributes.getLength(); for (int i = 0; i < attributeCount; i++) { Attr attribute = (Attr) attributes.item(i); replacement.setAttribute(attribute.getName(), attribute.getValue()); } } DomUtils.replaceNode(replacement, element); return replacement; }
From source file:cn.itcast.fredck.FCKeditor.connector.ConnectorServlet.java
private Node CreateCommonXml(Document doc, String commandStr, String typeStr, String currentPath, String currentUrl) {//from www .j a v a 2s . c o m Element root = doc.createElement("Connector"); doc.appendChild(root); root.setAttribute("command", commandStr); root.setAttribute("resourceType", typeStr); Element myEl = doc.createElement("CurrentFolder"); myEl.setAttribute("path", currentPath); myEl.setAttribute("url", currentUrl); root.appendChild(myEl); return root; }
From source file:com.legstar.cob2xsd.XsdAnnotationEmitter.java
/** * Create an XML Schema annotation with markup corresponding to the original * COBOL// w w w. ja v a 2s.co m * data item attributes. * * @param xsdDataItem COBOL data item decorated with XSD attributes * @return an XML schema annotation */ public XmlSchemaAnnotation createLegStarAnnotation(final XsdDataItem xsdDataItem) { Document doc = _docBuilder.newDocument(); Element el = doc.createElementNS(getCOXBNamespace(), getCOXBElements()); Element elc = doc.createElementNS(getCOXBNamespace(), getCOXBElement()); elc.setAttribute(CobolMarkup.LEVEL_NUMBER, Integer.toString(xsdDataItem.getLevelNumber())); elc.setAttribute(CobolMarkup.COBOL_NAME, xsdDataItem.getCobolName()); elc.setAttribute(CobolMarkup.TYPE, xsdDataItem.getCobolType().toString()); if (xsdDataItem.getCobolType() != CobolType.GROUP_ITEM) { if (xsdDataItem.getPicture() != null) { elc.setAttribute(CobolMarkup.PICTURE, xsdDataItem.getPicture()); } if (xsdDataItem.getUsage() != null) { elc.setAttribute(CobolMarkup.USAGE, xsdDataItem.getUsageForCobol()); } if (xsdDataItem.isJustifiedRight()) { elc.setAttribute(CobolMarkup.IS_JUSTIFIED_RIGHT, "true"); } if (xsdDataItem.getTotalDigits() > 0) { elc.setAttribute(CobolMarkup.IS_SIGNED, (xsdDataItem.isSigned()) ? "true" : "false"); elc.setAttribute(CobolMarkup.TOTAL_DIGITS, Integer.toString(xsdDataItem.getTotalDigits())); if (xsdDataItem.getFractionDigits() > 0) { elc.setAttribute(CobolMarkup.FRACTION_DIGITS, Integer.toString(xsdDataItem.getFractionDigits())); } if (xsdDataItem.isSignLeading()) { elc.setAttribute(CobolMarkup.IS_SIGN_LEADING, "true"); } if (xsdDataItem.isSignSeparate()) { elc.setAttribute(CobolMarkup.IS_SIGN_SEPARATE, "true"); } } } /* * Annotations transfer the COBOL occurs semantic (as opposed to * the XSD semantic). No depending on => fixed size array */ if (xsdDataItem.getCobolMaxOccurs() > 0) { elc.setAttribute(CobolMarkup.MAX_OCCURS, Integer.toString(xsdDataItem.getCobolMaxOccurs())); if (xsdDataItem.getDependingOn() == null) { elc.setAttribute(CobolMarkup.MIN_OCCURS, Integer.toString(xsdDataItem.getCobolMaxOccurs())); } else { elc.setAttribute(CobolMarkup.DEPENDING_ON, xsdDataItem.getDependingOn()); elc.setAttribute(CobolMarkup.MIN_OCCURS, Integer.toString(xsdDataItem.getCobolMinOccurs())); } } if (xsdDataItem.isODOObject()) { elc.setAttribute(CobolMarkup.IS_ODO_OBJECT, "true"); } if (xsdDataItem.getRedefines() != null) { elc.setAttribute(CobolMarkup.REDEFINES, xsdDataItem.getRedefines()); } if (xsdDataItem.isRedefined()) { elc.setAttribute(CobolMarkup.IS_REDEFINED, "true"); elc.setAttribute(CobolMarkup.UNMARSHAL_CHOICE_STRATEGY, ""); } if (xsdDataItem.getValue() != null && xsdDataItem.getValue().length() > 0) { elc.setAttribute(CobolMarkup.VALUE, ValueUtil.resolveFigurative(xsdDataItem.getValue(), xsdDataItem.getMaxStorageLength(), getModel().quoteIsQuote())); } if (xsdDataItem.getSrceLine() > 0) { elc.setAttribute(CobolMarkup.SRCE_LINE, Integer.toString(xsdDataItem.getSrceLine())); } el.appendChild(elc); XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo(); appInfo.setMarkup(el.getChildNodes()); /* Create annotation */ XmlSchemaAnnotation annotation = new XmlSchemaAnnotation(); annotation.getItems().add(appInfo); return annotation; }
From source file:de.tudarmstadt.ukp.dkpro.core.io.mmax2.MMAXWriter.java
public void registerMarkableLevel(String levelname, String schemeFilename, String customizationFilename) throws MMAXWriterException { Document compath = loadXML(commonPathsFile); Element annotations = (Element) compath.getElementsByTagName("annotations").item(0); NodeList annos = annotations.getElementsByTagName("level"); boolean found = false; for (int j = 0; j < annos.getLength(); j++) { if (annos.item(j).getAttributes().getNamedItem("name").getTextContent().equals(levelname)) { found = true;/* w w w .ja va2s. co m*/ System.err.println("Level " + levelname + " already exists."); break; } } // if the level is not already present in the commons_path file, add it if (!found) { Element anno = compath.createElement("level"); anno.setAttribute("name", levelname); anno.setAttribute("schemefile", schemeFilename); anno.setAttribute("customization_file", customizationFilename); anno.appendChild(compath.createTextNode("$_" + levelname + ".xml")); annotations.appendChild(anno); } saveXML(compath, commonPathsFile, null, null); }
From source file:fi.helsinki.lib.simplerest.RootCommunitiesResource.java
@Get("html|xhtml|xml") public Representation toXml() { DomRepresentation representation = null; Document d = null;/*from w w w . ja v a2s . co m*/ try { representation = new DomRepresentation(MediaType.ALL); d = representation.getDocument(); } catch (IOException ex) { log.log(Priority.INFO, ex, ex); } representation.setIndenting(true); Element html = d.createElement("html"); d.appendChild(html); Element head = d.createElement("head"); html.appendChild(head); Element title = d.createElement("title"); head.appendChild(title); title.appendChild(d.createTextNode("Root communities")); Element body = d.createElement("body"); html.appendChild(body); Element ul = d.createElement("ul"); setId(ul, "rootcommunities"); body.appendChild(ul); String url = ""; try { url = getRequest().getResourceRef().getIdentifier(); } catch (NullPointerException e) { log.log(Priority.INFO, e, e); } url = url.substring(0, url.lastIndexOf('/') + 1); url += "community/"; for (Community community : communities) { Element li = d.createElement("li"); Element a = d.createElement("a"); a.setAttribute("href", url + Integer.toString(community.getID())); a.appendChild(d.createTextNode(community.getName())); li.appendChild(a); ul.appendChild(li); } Element form = d.createElement("form"); form.setAttribute("enctype", "multipart/form-data"); form.setAttribute("method", "post"); makeInputRow(d, form, "name", "Name"); makeInputRow(d, form, "short_description", "Short description"); makeInputRow(d, form, "introductory_text", "Introductory text"); makeInputRow(d, form, "copyright_text", "Copyright text"); makeInputRow(d, form, "side_bar_text", "Side bar text"); makeInputRow(d, form, "logo", "Logo", "file"); Element submitButton = d.createElement("input"); submitButton.setAttribute("type", "submit"); submitButton.setAttribute("value", "Create a new root community."); form.appendChild(submitButton); body.appendChild(form); try { if (context != null) { context.abort(); } } catch (NullPointerException e) { log.log(Priority.INFO, e, e); } return representation; }
From source file:com.dinstone.jrpc.spring.spi.ServerBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String id = element.getAttribute("id"); if (!StringUtils.hasText(id)) { builder.addPropertyValue("serverId", Server.class.getName()); element.setAttribute("id", Server.class.getName()); }// w w w .ja v a 2 s . c o m // ================================================ // Transport config // ================================================ builder.addPropertyValue("transportBean", getTransportBeanDefinition(element, parserContext)); // ================================================ // Registry config // ================================================ builder.addPropertyValue("registryBean", getRegistryBeanDefinition(element, parserContext)); // ================================================ // Services config // ================================================ builder.addPropertyValue("services", getServiceBeanDefinition(element, parserContext)); }