List of usage examples for org.w3c.dom Element setAttribute
public void setAttribute(String name, String value) throws DOMException;
From source file:org.spearal.spring.jpa.xml.SpearalJpaBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { if ("".equals(element.getAttribute(ID_ATTRIBUTE))) element.setAttribute(ID_ATTRIBUTE, SpearalJpaConfigurator.class.getName()); }
From source file:bpsperf.modelgen.AbstractGenerator.java
protected Element addNode(String nodeType, String id, String name) { Element node = doc.createElementNS(ns, nodeType); node.setAttribute("id", id); node.setAttribute("name", name); parent.appendChild(node);/* ww w . j a v a 2s .c o m*/ return node; }
From source file:cz.zcu.kiv.eegdatabase.wui.core.experiments.metadata.ODMLSectionDeserializer.java
@Override public Section deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { long start = System.currentTimeMillis(); try {//www. ja v a 2 s . com String jsonString = jp.getCodec().readTree(jp).toString(); JSONObject jsonObject = new JSONObject(jsonString); String xmlString = XML.toString(jsonObject); Reader reader = new Reader(); ByteArrayInputStream stream = new ByteArrayInputStream(xmlString.getBytes("UTF-8")); // encoding is necessary DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder dbuilder = dbf.newDocumentBuilder(); InputSource source = new InputSource(stream); source.setEncoding("UTF-8"); // encoding is necessary Document dom = dbuilder.parse(source); Element rootElement = dom.getDocumentElement(); rootElement.setAttribute("version", "1.0"); byte[] xmlStringUpdated = getStringFromDocument(dom).getBytes("UTF-8"); stream = new ByteArrayInputStream(xmlStringUpdated); // encoding is necessary Section load = reader.load(stream); return load; } catch (JSONException e) { log.warn(e.getMessage(), e); } catch (Exception e) { log.warn(e.getMessage(), e); } finally { long end = System.currentTimeMillis(); log.trace("Deserialize time - " + (end - start) + " ms."); } return null; }
From source file:com.connexta.arbitro.utils.policy.BasicPolicyHelper.java
public static Element createPolicyElement(BasicPolicyDTO basicPolicyDTO, Document doc) throws PolicyBuilderException { Element policyElement = doc.createElement(PolicyConstants.POLICY_ELEMENT); policyElement.setAttribute("xmlns", PolicyConstants.XACMLData.XACML3_POLICY_NAMESPACE); if (basicPolicyDTO.getPolicyId() != null && basicPolicyDTO.getPolicyId().trim().length() > 0) { policyElement.setAttribute(PolicyConstants.POLICY_ID, basicPolicyDTO.getPolicyId()); } else {//w w w .j a va 2 s.com throw new PolicyBuilderException("Policy name can not be null"); } if (basicPolicyDTO.getRuleAlgorithm() != null && basicPolicyDTO.getRuleAlgorithm().trim().length() > 0) { policyElement.setAttribute(PolicyConstants.RULE_ALGORITHM, basicPolicyDTO.getRuleAlgorithm()); } else { policyElement.setAttribute(PolicyConstants.RULE_ALGORITHM, PolicyConstants.RuleCombiningAlog.DENY_OVERRIDE_ID); // TODO log.warn("Rule combining algorithm is not defined. Use default algorithm; Deny Override"); } if (basicPolicyDTO.getVersion() != null && basicPolicyDTO.getVersion().trim().length() > 0) { policyElement.setAttribute(PolicyConstants.POLICY_VERSION, basicPolicyDTO.getVersion()); } else { // policy version is can be handled by policy registry. therefore we can ignore it, although it // is a required attribute policyElement.setAttribute(PolicyConstants.POLICY_VERSION, "1.0"); } if (basicPolicyDTO.getDescription() != null && basicPolicyDTO.getDescription().trim().length() > 0) { Element descriptionElement = doc.createElement(PolicyConstants.DESCRIPTION_ELEMENT); descriptionElement.setTextContent(basicPolicyDTO.getDescription()); policyElement.appendChild(descriptionElement); } BasicTargetDTO basicTargetDTO = basicPolicyDTO.getTargetDTO(); List<BasicRuleDTO> basicRuleDTOs = basicPolicyDTO.getBasicRuleDTOs(); if (basicTargetDTO != null) { policyElement.appendChild(BasicPolicyHelper.createTargetElement(basicTargetDTO, doc)); } else { policyElement.appendChild(doc.createElement(PolicyConstants.TARGET_ELEMENT)); } if (basicRuleDTOs != null && basicRuleDTOs.size() > 0) { for (BasicRuleDTO basicRuleDTO : basicRuleDTOs) { policyElement.appendChild(BasicPolicyHelper.createRuleElement(basicRuleDTO, doc)); } } else { BasicRuleDTO basicRuleDTO = new BasicRuleDTO(); basicRuleDTO.setRuleId(UUID.randomUUID().toString()); basicRuleDTO.setRuleEffect(PolicyConstants.RuleEffect.DENY); policyElement.appendChild(BasicPolicyHelper.createRuleElement(basicRuleDTO, doc)); } return policyElement; }
From source file:bpsperf.modelgen.AbstractGenerator.java
protected Element connect(String sourceId, String targetId, String flowId) { Element flow = doc.createElementNS(ns, "sequenceFlow"); flow.setAttribute("id", flowId); flow.setAttribute("sourceRef", sourceId); flow.setAttribute("targetRef", targetId); parent.appendChild(flow);//from ww w. ja va 2s. c om return flow; }
From source file:com.cburch.logisim.circuit.appear.AppearanceAnchor.java
@Override public Element toSvgElement(Document doc) { Location loc = getLocation(); Element ret = doc.createElement("circ-anchor"); ret.setAttribute("x", "" + (loc.getX() - RADIUS)); ret.setAttribute("y", "" + (loc.getY() - RADIUS)); ret.setAttribute("width", "" + 2 * RADIUS); ret.setAttribute("height", "" + 2 * RADIUS); ret.setAttribute("facing", facing.toString()); return ret;/*from ww w . j av a 2 s.co m*/ }
From source file:no.dusken.barweb.view.InvoiceView.java
private Element createInvoiceElement(Invoice invoice, Gjeng gjeng, Document dom) { Element root = dom.createElement("invoice"); root.setAttribute("gjeng", gjeng.getName()); root.setAttribute("invoiceID", invoice.getId().toString()); root.setAttribute("invoiceSum", String.valueOf(invoice.getSum())); root.setAttribute("comment", invoice.getComment()); SimpleDateFormat dateformat = new SimpleDateFormat("dd. MMMMMMMMM yyyy", new Locale("no")); Calendar earliest = InvoiceUtils.getEarliestTransaksjonCalendar(invoice); Calendar latest = InvoiceUtils.getLatestTransaksjonCalendar(invoice); String timespan = null;/*from w w w. j a v a 2 s . c o m*/ if (earliest != null && latest != null) { StringBuilder sb = new StringBuilder(); sb.append(dateformat.format(earliest.getTime())); sb.append(" - "); sb.append(dateformat.format(latest.getTime())); timespan = sb.toString(); } root.setAttribute("timespan", timespan); return root; }
From source file:com.codebutler.farebot.mifare.Card.java
public Element toXML() throws Exception { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.newDocument(); Element element = doc.createElement("card"); element.setAttribute("type", String.valueOf(getCardType().toInteger())); element.setAttribute("id", Utils.getHexString(mTagId)); element.setAttribute("scanned_at", Long.toString(mScannedAt.getTime())); doc.appendChild(element);/*from w w w .j a va2s .c o m*/ return doc.getDocumentElement(); }
From source file:bpsperf.modelgen.AbstractGenerator.java
protected void generateSkeleton(String processId) throws ParserConfigurationException { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); doc = docBuilder.newDocument();//from w w w .j a v a 2 s .co m Element rootElement = doc.createElementNS(ns, "definitions"); rootElement.setAttribute("targetNamespace", "http://www.activiti.org/test"); doc.appendChild(rootElement); Element process = doc.createElementNS(ns, "process"); process.setAttribute("id", processId); process.setAttribute("name", processId); process.setAttribute("isExecutable", "true"); rootElement.appendChild(process); this.parent = process; }
From source file:org.springmodules.cache.config.CacheSetupStrategyElementBuilder.java
/** * @see XmlElementBuilder#toXml()/* w ww. j a v a 2 s. co m*/ */ public Element toXml() { Element root = new DomElementStub("abstract"); root.setAttribute("providerId", cacheProviderId); if (!ObjectUtils.isEmpty(cachingListenerElementBuilders)) { Element listeners = new DomElementStub("cachingListeners"); appendChildren(listeners, cachingListenerElementBuilders); root.appendChild(listeners); } if (cacheKeyGeneratorElementBuilder != null) { root.appendChild(cacheKeyGeneratorElementBuilder.toXml()); } appendChildren(root, cachingModelElementBuilders); appendChildren(root, flushingModelElementBuilders); return root; }