List of usage examples for org.w3c.dom Document createAttribute
public Attr createAttribute(String name) throws DOMException;
Attr
of the given name. From source file:com.amalto.core.history.accessor.ManyFieldAccessor.java
public void markModified(Marker marker) { Document domDocument = document.asDOM(); Node collectionItemNode = getCollectionItemNode(); if (collectionItemNode != null) { Attr newAttribute = domDocument.createAttribute(MODIFIED_MARKER_ATTRIBUTE); switch (marker) { case ADD: newAttribute.setValue(FieldUpdateAction.MODIFY_ADD_MARKER_VALUE); break; case UPDATE: newAttribute.setValue(FieldUpdateAction.MODIFY_UPDATE_MARKER_VALUE); break; case REMOVE: newAttribute.setValue(FieldUpdateAction.MODIFY_REMOVE_MARKER_VALUE); break; default://from w w w . j a va2 s. co m throw new IllegalArgumentException("No support for marker " + marker); //$NON-NLS-1$ } collectionItemNode.getAttributes().setNamedItem(newAttribute); } }
From source file:clus.statistic.RegressionStat.java
@Override public Element getPredictElement(Document doc) { Element stats = doc.createElement("RegressionStat"); NumberFormat fr = ClusFormat.SIX_AFTER_DOT; Attr examples = doc.createAttribute("examples"); examples.setValue(fr.format(m_SumWeight)); stats.setAttributeNode(examples);/*from w w w .j av a2 s . com*/ for (int i = 0; i < m_NbAttrs; i++) { Element attr = doc.createElement("Target"); Attr name = doc.createAttribute("name"); name.setValue(m_Attrs[i].getName()); attr.setAttributeNode(name); double tot = getSumWeights(i); if (tot == 0) attr.setTextContent("?"); else attr.setTextContent(fr.format(getSumValues(i) / tot)); stats.appendChild(attr); } return stats; }
From source file:de.betterform.connector.ant.AntSubmissionHandler.java
public Map submit(Submission submission, Node instance) throws XFormsException { LOGGER.debug("AntSubmissionHandler.submit()"); ByteArrayOutputStream stream = new ByteArrayOutputStream(); if (submission.getMethod().equals("get")) { try {/*w ww. j av a2s .c om*/ String uri = getURI(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); String buildFilePath = (new URI(uri)).getSchemeSpecificPart() .substring((new URI(uri)).getSchemeSpecificPart().indexOf(':') + 1); if (!"".equals(buildFilePath)) { File buildFile = new File(buildFilePath); String target = null; if (uri.contains("#")) { //got Traget from uri target = uri.substring(uri.indexOf('#') + 1); } else if (((Document) instance).getElementsByTagName("target").item(0) != null) { //got target from xform target = ((Document) instance).getElementsByTagName("target").item(0).getTextContent(); } else { // use default target target = "default"; } LOGGER.debug("AntSubmissionHandler.runTarget() BuildFile: " + buildFile.getAbsolutePath() + " with Target:" + target); runTarget(buildFile, target, outputStream, errorStream); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); Document document = factory.newDocumentBuilder().newDocument(); document.appendChild(document.createElementNS(null, "ant")); Element rootElement = document.getDocumentElement(); Attr filename = document.createAttribute("fileName"); filename.setValue(buildFile.getName()); rootElement.setAttributeNode(filename); Element element = document.createElement("buildFile"); DOMUtil.setElementValue(element, buildFile.getAbsolutePath()); rootElement.appendChild(element); element = document.createElement("target"); DOMUtil.setElementValue(element, target); rootElement.appendChild(element); element = document.createElement("output-stream"); DOMUtil.setElementValue(element, outputStream.toString()); rootElement.appendChild(element); element = document.createElement("error-stream"); DOMUtil.setElementValue(element, errorStream.toString()); rootElement.appendChild(element); DOMUtil.prettyPrintDOM(document, stream); } else { throw new XFormsException("submission method '" + submission.getMethod() + "' at: " + DOMUtil.getCanonicalPath(submission.getElement()) + " not supported"); } } catch (Exception e) { throw new XFormsException(e); } } else { throw new XFormsException("submission method '" + submission.getMethod() + "' at: " + DOMUtil.getCanonicalPath(submission.getElement()) + " not supported"); } Map response = new HashMap(); response.put(XFormsProcessor.SUBMISSION_RESPONSE_STREAM, new ByteArrayInputStream(stream.toByteArray())); return response; }
From source file:de.uzk.hki.da.metadata.MetadataStructure.java
private Element addEdmProvidedCHOtoEdm(PreservationSystem preservationSystem, String id, Document edmDoc, Element rootElement) {//from w ww . j a v a 2s.c om String cho_identifier = preservationSystem.getUrisCho() + "/" + id; Element providedCHO = edmDoc.createElement(C.EDM_PROVIDED_CHO); Attr rdfAbout = edmDoc.createAttribute("rdf:about"); rdfAbout.setValue(cho_identifier); providedCHO.setAttributeNode(rdfAbout); rootElement.appendChild(providedCHO); return providedCHO; }
From source file:it.unibas.spicy.persistence.xml.operators.ExportXSD.java
private void processRoot(INode root, Document document) { Element schema = document.createElementNS(XSD_NS, PREFIX + "schema"); document.appendChild(schema);/*from w ww . ja va 2 s . co m*/ Attr elementFormDefault = document.createAttribute("elementFormDefault"); elementFormDefault.setValue("qualified"); schema.setAttributeNode(elementFormDefault); }
From source file:de.uzk.hki.da.metadata.MetadataStructure.java
private Element addOreAggregationToEdm(PreservationSystem preservationSystem, String id, Document edmDoc, Element rootElement) {//from w w w . j a v a 2 s . c o m String aggr_identifier = preservationSystem.getUrisAggr() + "/" + id; Element aggregation = edmDoc.createElement(C.EDM_ORE_AGGREGATION); Attr rdfAbout = edmDoc.createAttribute("rdf:about"); rdfAbout.setValue(aggr_identifier); aggregation.setAttributeNode(rdfAbout); rootElement.appendChild(aggregation); Element aggregatedCHO = edmDoc.createElement(C.EDM_AGGREGATED_CHO); Attr rdfAboutACho = edmDoc.createAttribute("rdf:resource"); rdfAboutACho.setValue(preservationSystem.getUrisCho() + "/" + id); aggregatedCHO.setAttributeNode(rdfAboutACho); aggregation.appendChild(aggregatedCHO); return aggregation; }
From source file:gov.medicaid.services.impl.FileNetServiceBean.java
/** * Creates the XML./*from w w w.ja v a 2 s .co m*/ * * @param outFile * the output file handler * @param attributes * the content * @throws PortalServiceException * if any error occurs */ private void createXML(File outFile, Map<String, String> attributes) throws PortalServiceException { try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // root elements Document doc = docBuilder.newDocument(); Element rootElement = doc.createElement("Document"); doc.appendChild(rootElement); for (String key : attributes.keySet()) { Element indexVal = doc.createElement("Indexvalue"); Attr attr = doc.createAttribute("name"); attr.setValue(key); indexVal.setAttributeNode(attr); if (attributes.get(key) != null) { indexVal.appendChild(doc.createTextNode(attributes.get(key))); } rootElement.appendChild(indexVal); } // write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(outFile); transformer.transform(source, result); } catch (ParserConfigurationException e) { throw new PortalServiceException("Failed to create FileNet xml", e); } catch (TransformerException e) { throw new PortalServiceException("Failed to create FileNet xml", e); } }
From source file:BuildXml.java
public Node createContactNode(Document document) { // create FirstName and LastName elements Element firstName = document.createElement("FirstName"); Element lastName = document.createElement("LastName"); firstName.appendChild(document.createTextNode("First Name")); lastName.appendChild(document.createTextNode("Last Name")); // create contact element Element contact = document.createElement("contact"); // create attribute Attr genderAttribute = document.createAttribute("gender"); genderAttribute.setValue("F"); // append attribute to contact element contact.setAttributeNode(genderAttribute); contact.appendChild(firstName);/*from w ww. j ava 2 s .c om*/ contact.appendChild(lastName); return contact; }
From source file:clus.ext.hierarchical.WHTDStatistic.java
@Override public Element getPredictElement(Document doc) { Element stats = doc.createElement("WHTDStat"); NumberFormat fr = ClusFormat.SIX_AFTER_DOT; Attr examples = doc.createAttribute("examples"); examples.setValue(fr.format(m_SumWeight)); stats.setAttributeNode(examples);//from w w w.j a v a 2s .co m if (m_Threshold >= 0.0) { String pred = computePrintTuple().toStringHuman(getHier()); Element predictions = doc.createElement("Predictions"); stats.appendChild(predictions); String[] predictionS = pred.split(","); for (String prediction : predictionS) { Element attr = doc.createElement("Prediction"); predictions.appendChild(attr); attr.setTextContent(prediction); } } else { for (int i = 0; i < m_NbAttrs; i++) { Element attr = doc.createElement("Target"); Attr name = doc.createAttribute("name"); name.setValue(m_Attrs[i].getName()); attr.setAttributeNode(name); if (m_SumWeight == 0.0) { attr.setTextContent("?"); } else { attr.setTextContent(fr.format(getMean(i))); } stats.appendChild(attr); } } return stats; }
From source file:de.uzk.hki.da.metadata.MetadataStructure.java
private void addNewElementToParent(PreservationSystem preservationSystem, String id, String elementName, String elementValue, Element parent, Document edmDoc) { Element eName = edmDoc.createElement(elementName); if (elementName.equals(C.EDM_HAS_VIEW) || elementName.equals(C.EDM_IS_PART_OF) || elementName.equals(C.EDM_HAS_PART) || elementName.equals(C.EDM_IS_SHOWN_BY) || elementName.equals(C.EDM_OBJECT)) { if (elementName.equals(C.EDM_IS_PART_OF) || elementName.equals(C.EDM_HAS_PART)) { elementValue = preservationSystem.getUrisCho() + "/" + elementValue; }//from www.j a va 2 s .co m Attr rdfResource = edmDoc.createAttribute("rdf:resource"); rdfResource.setValue(elementValue); eName.setAttributeNode(rdfResource); } else { eName.appendChild(edmDoc.createTextNode(elementValue)); } parent.appendChild(eName); }