List of usage examples for org.w3c.dom Element setAttribute
public void setAttribute(String name, String value) throws DOMException;
From source file:com.nortal.jroad.wsdl.XTeeSoapProvider.java
@Override protected void populatePort(Definition definition, Port port) throws WSDLException { super.populatePort(definition, port); ExtensionRegistry extensionRegistry = definition.getExtensionRegistry(); extensionRegistry.mapExtensionTypes(Port.class, new QName(XTeeWsdlDefinition.XROAD_NAMESPACE, "address", XTeeWsdlDefinition.XROAD_PREFIX), UnknownExtensibilityElement.class); UnknownExtensibilityElement element = (UnknownExtensibilityElement) extensionRegistry.createExtension( Port.class, new QName(XTeeWsdlDefinition.XROAD_NAMESPACE, "address", XTeeWsdlDefinition.XROAD_NAMESPACE)); Document doc;//from w w w .j a v a 2 s .c om try { doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { throw new RuntimeException(e); } Element xRoadAddr = doc.createElementNS(XTeeWsdlDefinition.XROAD_NAMESPACE, "address"); xRoadAddr.setPrefix(XTeeWsdlDefinition.XROAD_PREFIX); xRoadAddr.setAttribute("producer", xRoadDatabase); element.setElement(xRoadAddr); port.addExtensibilityElement(element); }
From source file:it.pronetics.madstore.crawler.publisher.impl.AtomPublisherImpl.java
private Element createCollectionElement(String key, String href, String title) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);/*from w w w . j a va 2 s.c om*/ DocumentBuilder builder = factory.newDocumentBuilder(); Document collectionDocument = builder.newDocument(); Element collectionelElement = collectionDocument.createElementNS(AtomConstants.APP_NS, AtomConstants.ATOM_COLLECTION); collectionelElement.setAttribute(AtomConstants.ATOM_KEY, key); collectionelElement.setAttribute(AtomConstants.ATOM_COLLECTION_HREF, href); Element acceptElement = collectionDocument.createElementNS(AtomConstants.APP_NS, AtomConstants.ATOM_COLLECTION_ACCEPT); Element titleElement = collectionDocument.createElementNS(AtomConstants.ATOM_NS, AtomConstants.ATOM_COLLECTION_TITLE); titleElement.setTextContent(title); collectionelElement.appendChild(acceptElement); collectionelElement.appendChild(titleElement); collectionDocument.appendChild(collectionelElement); return collectionelElement; }
From source file:ambit.data.qmrf.QMRFAttachment.java
public Element toXML(Document document) throws XMLException { Element element = document.createElement(getName()); element.setAttribute(attribute_filetype, filetype); element.setAttribute(attribute_description, description); element.setAttribute(attribute_url, url); if (getEmbedded()) { try {/*ww w . j a v a 2 s .c om*/ if (content == null) { content = retrieveContent(); } System.out.println("encoding"); byte[] encoded = Base64.encodeBase64(content.toString().getBytes(UTF8charset)); CDATASection cdata = document.createCDATASection(new String(encoded, UTF8charset)); if (cdata != null) element.appendChild(cdata); } catch (Exception x) { x.printStackTrace(); setEmbedded(false); } } else setEmbedded(false); if (getEmbedded()) element.setAttribute(attribute_embedded, Answer.YES.toString()); else element.setAttribute(attribute_embedded, Answer.NO.toString()); return element; }
From source file:com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.java
/** * <p/>// w w w .j a va 2s .co m * Sets a non-null, non-empty-string, UIComponent property to the * corresponding DOM Element * <p/> * * @param uiComponent the source of the attribute value * @param targetElement the DOM Element that will receive the * attribute * @param attrNameInComponent the property name in the UIComponent object * @param attrNameInDom the attribute name in the DOM Element */ public static void renderAttribute(UIComponent uiComponent, Element targetElement, String attrNameInComponent, String attrNameInDom) { Object attrValue = uiComponent.getAttributes().get(attrNameInComponent); if (attrValue != null && !attrValue.equals("")) { if (attrValue.toString().equalsIgnoreCase("true") || attrValue.toString().equalsIgnoreCase("false")) { boolean trueValue = new Boolean(attrValue.toString()).booleanValue(); if (!trueValue) { targetElement.removeAttribute(attrNameInDom.toString()); return; } } targetElement.setAttribute(attrNameInDom.toString(), attrValue.toString()); } }
From source file:net.sourceforge.eclipsetrader.core.internal.TradingSystemRepository.java
void saveTradingSystems() { try {/* w w w . j a v a 2 s . com*/ DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.getDOMImplementation().createDocument(null, "data", null); //$NON-NLS-1$ Element root = document.getDocumentElement(); root.setAttribute("nextId", String.valueOf(tsNextId)); //$NON-NLS-1$ root.setAttribute("nextGroupId", String.valueOf(tsGroupNextId)); //$NON-NLS-1$ for (Iterator iter = tsGroupMap.values().iterator(); iter.hasNext();) { TradingSystemGroup group = (TradingSystemGroup) iter.next(); if (group.getParent() == null) saveGroup(group, document, root); } for (Iterator iter = tsMap.values().iterator(); iter.hasNext();) { TradingSystem system = (TradingSystem) iter.next(); if (system.getGroup() == null) saveSystem(system, document, root); } repository.saveDocument(document, "", "ts.xml"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (Exception e) { logger.error(e.toString(), e); } }
From source file:cn.itcast.fredck.FCKeditor.connector.ConnectorServlet.java
private void setCreateFolderResponse(String retValue, Node root, Document doc) { Element myEl = doc.createElement("Error"); myEl.setAttribute("number", retValue); root.appendChild(myEl);//from w w w.j av a 2 s . c om }
From source file:com.connexta.arbitro.utils.PolicyUtils.java
/** * This method creates the attribute value element * @param attributeValueElementDTO attribute value element data object * @param doc XML document/*from w w w .jav a2 s . co m*/ * @return attribute value element */ public static Element createAttributeValueElement(AttributeValueElementDTO attributeValueElementDTO, Document doc) { Element attributeValueElement = doc.createElement(PolicyConstants.ATTRIBUTE_VALUE); if (attributeValueElementDTO.getAttributeValue() != null && attributeValueElementDTO.getAttributeValue().trim().length() > 0) { attributeValueElement.setTextContent(attributeValueElementDTO.getAttributeValue().trim()); if (attributeValueElementDTO.getAttributeDataType() != null && attributeValueElementDTO.getAttributeDataType().trim().length() > 0) { attributeValueElement.setAttribute(PolicyConstants.DATA_TYPE, attributeValueElementDTO.getAttributeDataType()); } else { attributeValueElement.setAttribute(PolicyConstants.DATA_TYPE, PolicyConstants.STRING_DATA_TYPE); } } return attributeValueElement; }
From source file:org.openmrs.module.xforms.aop.XformsLocationAdvisor.java
/** * Adds a new location node to the xforms document. * /* w w w . ja va 2 s . co m*/ * @param doc the xforms document. * @param locationSelect1Element the select1 element to add the location node. * @param location the location to add. * @param personId the person id represented by the location. */ private void addNewLocationNode(Document doc, Element locationSelect1Element, Location location) { Element itemNode = doc.createElement(XformBuilder.PREFIX_XFORMS + ":" + XformBuilder.NODE_ITEM); itemNode.setAttribute(XformBuilder.ATTRIBUTE_ID, location.getLocationId().toString()); Element node = doc.createElement(XformBuilder.PREFIX_XFORMS + ":" + XformBuilder.NODE_LABEL); node.setTextContent(XformBuilder.getLocationName(location)); itemNode.appendChild(node); node = doc.createElement(XformBuilder.PREFIX_XFORMS + ":" + XformBuilder.NODE_VALUE); node.setTextContent(location.getLocationId().toString()); itemNode.appendChild(node); locationSelect1Element.appendChild(itemNode); }
From source file:net.sourceforge.eclipsetrader.core.internal.TradingSystemRepository.java
private void saveGroup(TradingSystemGroup group, Document document, Element root) { Element element = document.createElement("group"); //$NON-NLS-1$ element.setAttribute("id", String.valueOf(group.getId())); //$NON-NLS-1$ root.appendChild(element);// w ww .j av a2 s . c o m Element node = document.createElement("description"); //$NON-NLS-1$ node.appendChild(document.createTextNode(group.getDescription())); element.appendChild(node); for (Iterator iter = group.getGroups().iterator(); iter.hasNext();) { TradingSystemGroup grp = (TradingSystemGroup) iter.next(); saveGroup(grp, document, element); } for (Iterator iter = group.getTradingSystems().iterator(); iter.hasNext();) { TradingSystem system = (TradingSystem) iter.next(); saveSystem(system, document, element); } }
From source file:com.alvexcore.share.ShareExtensionRegistry.java
public ExtensionUpdateInfo checkForUpdates(String extensionId, String shareId, Map<String, String> shareHashes, String shareVersion, String repoId, Map<String, String> repoHashes, String repoVersion, String licenseId) throws Exception { // search for extension DocumentBuilderFactory xmlFact = DocumentBuilderFactory.newInstance(); xmlFact.setNamespaceAware(true);/* w w w . j av a 2 s . c o m*/ xmlBuilder = xmlFact.newDocumentBuilder(); // build query Document queryXML = xmlBuilder.newDocument(); Element rootElement = queryXML.createElement("extension"); queryXML.appendChild(rootElement); Element el = queryXML.createElement("license-id"); el.appendChild(queryXML.createTextNode(licenseId)); rootElement.appendChild(el); el = queryXML.createElement("id"); el.appendChild(queryXML.createTextNode(extensionId)); rootElement.appendChild(el); el = queryXML.createElement("share-version"); el.appendChild(queryXML.createTextNode(shareVersion)); rootElement.appendChild(el); el = queryXML.createElement("repo-version"); el.appendChild(queryXML.createTextNode(repoVersion)); rootElement.appendChild(el); el = queryXML.createElement("share-id"); el.appendChild(queryXML.createTextNode(shareId)); rootElement.appendChild(el); el = queryXML.createElement("repo-id"); el.appendChild(queryXML.createTextNode(repoId)); rootElement.appendChild(el); el = queryXML.createElement("share-files"); rootElement.appendChild(el); for (String fileName : shareHashes.keySet()) { Element fileElem = queryXML.createElement("file"); fileElem.setAttribute("md5hash", shareHashes.get(fileName)); fileElem.appendChild(queryXML.createTextNode(fileName)); el.appendChild(fileElem); } el = queryXML.createElement("repo-files"); rootElement.appendChild(el); for (String fileName : repoHashes.keySet()) { Element fileElem = queryXML.createElement("file"); fileElem.setAttribute("md5hash", repoHashes.get(fileName)); fileElem.appendChild(queryXML.createTextNode(fileName)); el.appendChild(fileElem); } // query server try { URL url = new URL( "https://update.alvexhq.com:443/alfresco/s/api/alvex/extension/" + extensionId + "/update"); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); // disable host verification conn.setHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String arg0, SSLSession arg1) { return true; } }); conn.setDoOutput(true); conn.setDoInput(true); conn.connect(); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); TransformerFactory.newInstance().newTransformer().transform(new DOMSource(queryXML), new StreamResult(wr)); wr.close(); // get response Document responseXML = xmlBuilder.parse(conn.getInputStream()); XPath xpath = XPathFactory.newInstance().newXPath(); // get version String repoLatestVersion = ((Node) xpath.evaluate("/extension/repo-version/text()", responseXML, XPathConstants.NODE)).getNodeValue(); String shareLatestVersion = ((Node) xpath.evaluate("/extension/share-version/text()", responseXML, XPathConstants.NODE)).getNodeValue(); NodeList nl = (NodeList) xpath.evaluate("/extension/repo-files/file", responseXML, XPathConstants.NODESET); Map<String, Boolean> repoFiles = new HashMap<String, Boolean>(nl.getLength()); for (int i = 0; i < nl.getLength(); i++) repoFiles.put(nl.item(i).getTextContent(), "ok".equals(nl.item(i).getAttributes().getNamedItem("status").getNodeValue())); nl = (NodeList) xpath.evaluate("/extension/share-files/file", responseXML, XPathConstants.NODESET); Map<String, Boolean> shareFiles = new HashMap<String, Boolean>(nl.getLength()); for (int i = 0; i < nl.getLength(); i++) shareFiles.put(nl.item(i).getTextContent(), "ok".equals(nl.item(i).getAttributes().getNamedItem("status").getNodeValue())); String motd = ((Node) xpath.evaluate("/extension/motd/text()", responseXML, XPathConstants.NODE)) .getNodeValue(); return new ExtensionUpdateInfo(extensionId, repoVersion, shareVersion, repoLatestVersion, shareLatestVersion, repoFiles, shareFiles, motd); } catch (Exception e) { return new ExtensionUpdateInfo(extensionId, repoVersion, shareVersion, "", "", new HashMap<String, Boolean>(), new HashMap<String, Boolean>(), ""); } }