List of usage examples for org.w3c.dom Element setAttribute
public void setAttribute(String name, String value) throws DOMException;
From source file:de.uni_potsdam.hpi.bpt.promnicat.importer.sap_rm.SapReferenceModelImporter.java
public void splitEPML(File file) throws ParserConfigurationException, SAXException, IOException, TransformerException, JSONException { DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = fac.newDocumentBuilder(); Document doc = builder.parse(file); NodeList epcNodes = doc.getElementsByTagName("epc"); for (int i = 0; i < epcNodes.getLength(); i++) { String epcName = epcNodes.item(i).getAttributes().getNamedItem("name").getNodeValue(); Model model = this.persistenceApi.loadCompleteModelWithImportedId(epcName); if (model != null) { continue; }//from w ww . ja va2s .co m Document newEpcDoc = builder.newDocument(); Element epml = newEpcDoc.createElement("epml:epml"); Element directory = newEpcDoc.createElement("directory"); newEpcDoc.appendChild(epml); epml.appendChild(directory); directory.setAttribute("name", "ROOT"); Node epcNode = newEpcDoc.importNode(epcNodes.item(i), true); directory.appendChild(epcNode); DOMSource epmlSource = new DOMSource(newEpcDoc); final File epml2eRDFxsltFile = new File("resources/xslt/EPML2eRDF.xslt"); final Source epml2eRDFxsltSource = new StreamSource(epml2eRDFxsltFile); // Transformer Factory final TransformerFactory transformerFactory = TransformerFactory.newInstance(); // Get the epml source Transformer transformer = transformerFactory.newTransformer(epml2eRDFxsltSource); StringWriter writer = new StringWriter(); transformer.transform(epmlSource, new StreamResult(writer)); String erdf = writer.toString(); String rdf = erdfToRdf(erdf); rdf = rdf.replaceAll("ns[0-9]+:", ""); rdf = rdf.replace("#resource", "#"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); Document rdfDoc = builder.parse(new ByteArrayInputStream(rdf.getBytes("UTF-8"))); String json = RdfJsonTransformation.toJson(rdfDoc, "").toString(); //Diagram diagram = DiagramBuilder.parseJson(json); Representation representation = new Representation(Constants.FORMAT_BPMAI_JSON, Constants.NOTATION_EPC); Diagram parseJson = DiagramBuilder.parseJson(json); representation.setDataContent(json.getBytes()); model = new Model(epcName, Constants.ORIGIN_SAP_RM); model.setImportedId(epcName); Revision revision = new Revision(0); revision.connectRepresentation(representation); model.connectLatestRevision(revision); revision.connectModel(model); model.connectLatestRevision(revision); persistenceApi.savePojo(model); } }
From source file:it.unibas.spicy.persistence.xml.operators.ExportXSD.java
private void checkLeafNode(INode node, Element element) { element.setAttribute("name", node.getLabel()); INode leafNode = node.getChild(0);//from ww w . j a va 2 s . co m if (leafNode != null) { element.setAttribute("type", ExportXSD.PREFIX + leafNode.getLabel()); } }
From source file:fi.csc.kapaVirtaAS.WSDLManipulator.java
public void generateVirtaKapaWSDL() throws Exception { // Fetch current WSDL-file File inputFile = new File("opiskelijatiedot.wsdl"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inputFile); doc.setXmlVersion("1.0"); doc.getDocumentElement().normalize(); // Manipulate WSDL to meet the requirements of xroad // Root element <wsdl:definitions> attribute manipulations Element root = doc.getDocumentElement(); root.setAttribute("xmlns:" + conf.getXroadSchemaPrefixForWSDL(), conf.getXroadSchema()); root.setAttribute("xmlns:" + conf.getXroadIdSchemaPrefixForWSDL(), conf.getXroadIdSchema()); root = replaceAttribute(root, "xmlns:tns", conf.getAdapterServiceSchema()); root = replaceAttribute(root, "targetNamespace", conf.getAdapterServiceSchema()); // Schema elements <xs:schema> attribute manipulations NodeList schemas = root.getElementsByTagName("xs:schema"); for (int i = 0; i < schemas.getLength(); ++i) { Node schema = schemas.item(i); if (schema != null) { NamedNodeMap schemaAttributes = schema.getAttributes(); if (schemaAttributes != null && schemaAttributes.getNamedItem("xmlns:virtaluku") != null) { schemaAttributes.getNamedItem("xmlns:virtaluku").setTextContent(conf.getAdapterServiceSchema()); if (schemaAttributes != null && schemaAttributes.getNamedItem("targetNamespace") != null) { schemaAttributes.getNamedItem("targetNamespace") .setTextContent(conf.getAdapterServiceSchema()); }/*from w w w. j a v a 2 s . co m*/ Element el = (Element) schema.appendChild(doc.createElement("xs:import")); el.setAttribute("id", conf.getXroadSchemaPrefixForWSDL()); el.setAttribute("namespace", conf.getXroadSchema()); el.setAttribute("schemaLocation", conf.getXroadSchema()); // Remove Request part from xs:element -elements NodeList elementsInSchema = schema.getChildNodes(); for (int j = 0; j < elementsInSchema.getLength(); ++j) { Element el1 = (Element) elementsInSchema.item(j); if (el1.getNodeName() == "xs:element") { replaceAttribute(el1, "name", StringUtils.substringBefore(el1.getAttribute("name"), "Request")); } } } } } // Append xroad request headers Element xroadReqHeadersElement = doc.createElement("wsdl:message"); xroadReqHeadersElement.setAttribute("name", "requestheader"); for (String xroadHeader : conf.getXroadHeaders()) { Element reqHeader = doc.createElement("wsdl:part"); reqHeader.setAttribute("name", xroadHeader); reqHeader.setAttribute("element", conf.getXroadSchemaPrefixForWSDL() + ":" + xroadHeader); xroadReqHeadersElement.appendChild(reqHeader); } root.appendChild(xroadReqHeadersElement); NodeList childrenList = root.getChildNodes(); for (int i = 0; i < childrenList.getLength(); ++i) { if (childrenList.item(i).getNodeName().contains(":binding")) { NodeList binding = childrenList.item(i).getChildNodes(); for (int j = 0; j < binding.getLength(); ++j) { if (binding.item(j).getNodeName().contains(":operation")) { Element el1 = (Element) binding.item(j) .appendChild(doc.createElement(conf.getXroadIdSchemaPrefixForWSDL() + ":version")); el1.setTextContent(conf.getVirtaVersionForXRoad()); for (Node child = binding.item(j).getFirstChild(); child != null; child = child .getNextSibling()) { // Append xroad wsdl:binding operation headers if (child.getNodeName().contains(":input") || child.getNodeName().contains(":output")) { Element el = (Element) child; for (String xroadHeader : conf.getXroadHeaders()) { el.appendChild(soapHeader(doc.createElement("soap:header"), "tns:requestheader", xroadHeader, "literal")); } } if (child.getNodeName().contains(":input")) { Element el = (Element) child; replaceAttribute(el, "name", StringUtils.substringBefore(el.getAttribute("name"), "Request")); } } } } // Remove Request from wsdl:message > wsdl:part element so that can see element } else if (childrenList.item(i).getNodeName().contains(":message") && childrenList.item(i) .getAttributes().getNamedItem("name").getNodeValue().contains("Request")) { Element part = (Element) childrenList.item(i).getFirstChild().getNextSibling(); replaceAttribute(part, "element", StringUtils.substringBefore(part.getAttribute("element"), "Request")); } // Change wsdl input names to meet XRoad standard if (childrenList.item(i).getNodeName().contains(":portType")) { NodeList binding = childrenList.item(i).getChildNodes(); for (int j = 0; j < binding.getLength(); ++j) { if (binding.item(j).getNodeName().contains(":operation")) { for (Node child = binding.item(j).getFirstChild(); child != null; child = child .getNextSibling()) { if (child.getNodeName().contains(":input")) { Element el = (Element) child; replaceAttribute(el, "name", StringUtils.substringBefore(el.getAttribute("name"), "Request")); } } } } } // Append kapaVirtaAS service address if (childrenList.item(i).getNodeName().contains(":service")) { NodeList service = childrenList.item(i).getChildNodes(); for (int j = 0; j < service.getLength(); ++j) { if (service.item(j).getNodeName().contains(":port")) { for (Node child = service.item(j).getFirstChild(); child != null; child = child .getNextSibling()) { if (child.getNodeName().contains(":address")) { Element el = (Element) child; replaceAttribute(el, "location", conf.getAdapterServiceSOAPURL()); } } } } } } // Write manipulated WSDL to file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(new File(conf.getAdapterServiceWSDLPath() + "/kapavirta_as.wsdl")); transformer.transform(source, result); }
From source file:net.sourceforge.eclipsetrader.core.internal.TradingSystemRepository.java
private void saveSystem(TradingSystem system, Document document, Element root) { Element element = document.createElement("system"); //$NON-NLS-1$ element.setAttribute("id", String.valueOf(system.getId())); //$NON-NLS-1$ element.setAttribute("pluginId", system.getPluginId()); //$NON-NLS-1$ root.appendChild(element);// w w w . j ava 2s.co m Element node = document.createElement("security"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(system.getSecurity().getId()))); element.appendChild(node); node = document.createElement("account"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(system.getAccount().getId()))); element.appendChild(node); node = document.createElement("max_exposure"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(system.getMaxExposure()))); element.appendChild(node); node = document.createElement("min_amount"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(system.getMinAmount()))); element.appendChild(node); node = document.createElement("max_amount"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(system.getMaxAmount()))); element.appendChild(node); if (system.getDate() != null) { node = document.createElement("date"); //$NON-NLS-1$ node.appendChild(document.createTextNode(dateTimeFormat.format(system.getDate()))); element.appendChild(node); } node = document.createElement("signal"); //$NON-NLS-1$ node.appendChild(document.createTextNode(String.valueOf(system.getSignal()))); element.appendChild(node); for (Iterator paramIter = system.getParameters().keySet().iterator(); paramIter.hasNext();) { String key = (String) paramIter.next(); node = document.createElement("param"); //$NON-NLS-1$ node.setAttribute("key", key); //$NON-NLS-1$ node.appendChild(document.createTextNode((String) system.getParameters().get(key))); element.appendChild(node); } }
From source file:com.idega.chiba.web.xml.xforms.ui.IdegaText.java
public IdegaText(Element element, Model model) { super(element, model); if (element == null) { return;// ww w . j ava 2 s .com } if (execute(element)) { element.removeAttribute("style"); return; } element.setAttribute("style", "display: none;"); }
From source file:hd3gtv.as5kpc.protocol.ProtocolHandler.java
public ServerResponseClipdata getClipData(String id) throws IOException { Document document = createDocument(); Element root_ams_element = document.createElement("AMS"); document.appendChild(root_ams_element); Element last_order_element = document.createElement("DatabaseControl"); Element cd = document.createElement("GetClipData"); cd.setAttribute("ID", id); last_order_element.appendChild(cd);/* ww w . j av a 2 s . c o m*/ root_ams_element.appendChild(last_order_element); return (ServerResponseClipdata) send(document, new ServerResponseClipdata()); }
From source file:elaborate.editor.export.tei.TeiMaker.java
private int addPb(Element body, int _pageno, ProjectEntry projectEntry, String folio) { int pageno = _pageno; Element pb = tei.createElement("pb"); if (StringUtils.isNotEmpty(folio)) { pb.setAttribute("f", folio); }/* w w w. jav a 2 s. c o m*/ pb.setAttribute("facs", "#facs-" + projectEntry.getShortName() + "-" + pageno); pb.setAttribute("n", String.valueOf(pageno++)); body.appendChild(pb); return pageno; }
From source file:hd3gtv.as5kpc.protocol.ProtocolHandler.java
public ServerResponseId recordCue(String id, String name) throws IOException { Document document = createDocument(); Element root_ams_element = document.createElement("AMS"); document.appendChild(root_ams_element); Element last_order_element = document.createElement("TransportControl"); Element rec = document.createElement("RecordCue"); rec.setAttribute("ID", id); rec.setAttribute("Name", name); rec.setAttribute("EjectFirst", "true"); last_order_element.appendChild(rec); root_ams_element.appendChild(last_order_element); return (ServerResponseId) send(document, new ServerResponseId()); }
From source file:hd3gtv.as5kpc.protocol.ProtocolHandler.java
public ServerResponseStatus getStatus() throws IOException { Document document = createDocument(); Element root_ams_element = document.createElement("AMS"); document.appendChild(root_ams_element); Element last_order_element = document.createElement("TransportControl"); Element status = document.createElement("GetStatus"); status.setAttribute("InputStatus", "true"); last_order_element.appendChild(status); root_ams_element.appendChild(last_order_element); return (ServerResponseStatus) send(document, new ServerResponseStatus()); }
From source file:com.dinstone.jrpc.spring.spi.ClientBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String id = element.getAttribute("id"); if (!StringUtils.hasText(id)) { builder.addPropertyValue("clientId", Client.class.getName()); element.setAttribute("id", Client.class.getName()); }/*from ww w . j ava2 s.co m*/ // ================================================ // Transport config // ================================================ builder.addPropertyValue("transportBean", getTransportBeanDefinition(element, parserContext)); // ================================================ // Registry config // ================================================ builder.addPropertyValue("registryBean", getRegistryBeanDefinition(element, parserContext)); }