List of usage examples for org.w3c.dom Element setAttributeNS
public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException;
From source file:org.ojbc.util.helper.NIEMXMLUtils.java
public static Element createFirearmElement(Document doc, String structureId) { Element firearmElement = doc.createElementNS(OJBNamespaces.FIREARM_SEARCH_REQUEST_EXT, "Firearm"); firearmElement.setAttributeNS(NIEMNamespaces.STRUCT_NS, "id", structureId); return firearmElement; }
From source file:org.ojbc.util.helper.NIEMXMLUtils.java
public static Element createFirearmItemRegistration(Document doc, String structureId, String registrationId, String countyName, Boolean currentRegIndicator) { Element itemRegistrationElement = doc.createElementNS(OJBNamespaces.FIREARM_SEARCH_REQUEST_EXT, "ItemRegistration"); itemRegistrationElement.setAttributeNS(NIEMNamespaces.STRUCT_NS, "id", structureId); if (StringUtils.isNotBlank(registrationId)) { Element registrationIdElement = createIdentificationElementWithParent(doc, "RegistrationIdentification", registrationId);/*from w w w . j av a 2s. c o m*/ itemRegistrationElement.appendChild(registrationIdElement); } if (StringUtils.isNotBlank(countyName)) { Element countyNameElement = createNC20Element(doc, "LocationCountyName", countyName); itemRegistrationElement.appendChild(countyNameElement); } if (currentRegIndicator != null) { Element currentRegIndicatorElement = doc.createElementNS(OJBNamespaces.FIREARM_SEARCH_REQUEST_EXT, "CurrentRegistrationIndicator"); currentRegIndicatorElement.setTextContent(currentRegIndicator.toString()); itemRegistrationElement.appendChild(currentRegIndicatorElement); } return itemRegistrationElement; }
From source file:org.ojbc.util.helper.NIEMXMLUtils.java
public static Element createPropertyRegistrationAssociationElement(Document doc, String itemRegistrationRef, String itemRef) {/*from www .j a v a2s. c o m*/ Element parentElement = doc.createElementNS(NIEMNamespaces.NC_20_NS, "PropertyRegistrationAssociation"); Element itemRegistrationReferenceElement = doc.createElementNS(NIEMNamespaces.NC_20_NS, "ItemRegistrationReference"); itemRegistrationReferenceElement.setAttributeNS(NIEMNamespaces.STRUCT_NS, "ref", itemRegistrationRef); Element itemReferenceElement = doc.createElementNS(NIEMNamespaces.NC_20_NS, "ItemReference"); itemReferenceElement.setAttributeNS(NIEMNamespaces.STRUCT_NS, "ref", itemRef); parentElement.appendChild(itemRegistrationReferenceElement); parentElement.appendChild(itemReferenceElement); return parentElement; }
From source file:org.ojbc.util.helper.NIEMXMLUtils.java
public static Element createFirearmSearchMetaData(Document doc, String searchFieldMetaDataNamespace, SearchFieldMetadata searchFieldMetadata) { Element searchFieldMetadataElement = doc.createElementNS(searchFieldMetaDataNamespace, "SearchMetadata"); if (searchFieldMetadata == SearchFieldMetadata.ExactMatch) { searchFieldMetadataElement.setAttributeNS(NIEMNamespaces.STRUCT_NS, "id", "SM001"); }/*from w ww .j a v a2 s.com*/ if (searchFieldMetadata == SearchFieldMetadata.Partial) { searchFieldMetadataElement.setAttributeNS(NIEMNamespaces.STRUCT_NS, "id", "SM002"); } Element searchFieldQualifierCodeElement = doc.createElementNS(searchFieldMetaDataNamespace, "SearchQualifierCode"); searchFieldQualifierCodeElement.setTextContent(searchFieldMetadata.getMetadata()); searchFieldMetadataElement.appendChild(searchFieldQualifierCodeElement); return searchFieldMetadataElement; }
From source file:org.ojbc.util.xml.OjbcNamespaceContext.java
/** * This method collects all of the namespaces that are actually used, in this element and all of its descendants, and declares the proper prefixes * on this element./*from w w w. ja v a 2 s .c o m*/ * * @param e * the element on which to declare the namespace prefixes for itself and its descendants */ public void populateRootNamespaceDeclarations(Element e) { Set<String> namespaceURIs = collectNamespaceURIs(e); for (String uri : namespaceURIs) { String prefix = getPrefix(uri); if (prefix == null) { if (!"http://www.w3.org/2000/xmlns/".equals(uri)) { log.warn("Namespace URI " + uri + " not found in OjbcNamespaceContext"); } } else { e.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + prefix, uri); } } }
From source file:org.opencastproject.comments.CommentParser.java
/** * Serializes a comment collection.//w ww . jav a 2 s .co m * * @param comments * the comment collection * @return the serialized comment collection * @throws CommentException * unable to serialize comment collection to XML */ public static String getAsXml(Collection<Comment> comments) throws CommentException { Document doc = newDocument(); // Root element "comments" Element commentsXml = doc.createElementNS(NAMESPACE, "comments"); commentsXml.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", NAMESPACE); doc.appendChild(commentsXml); for (Comment c : comments) { commentsXml.appendChild(getAsXmlDocument(c, doc)); } return serializeNode(commentsXml.getOwnerDocument()); }
From source file:org.opencastproject.comments.CommentParser.java
/** * Serializes the comment to a {@link org.w3c.dom.Document}. * /*from ww w . j a v a 2 s . co m*/ * @param comment * the comment * @return the serialized comment */ private static Element getAsXmlDocument(Comment comment, Document doc) { // Root element "comment" Element commentXml = doc.createElementNS(NAMESPACE, "comment"); commentXml.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", NAMESPACE); // Identifier if (comment.getId().isSome()) commentXml.setAttribute("id", comment.getId().get().toString()); // Resolved status commentXml.setAttribute("resolved", Boolean.toString(comment.isResolvedStatus())); // Author Element authorNode = getAuthorNode(comment.getAuthor(), doc); commentXml.appendChild(authorNode); // Creation date Element creationDate = doc.createElement("creationDate"); creationDate.setTextContent(DateTimeSupport.toUTC(comment.getCreationDate().getTime())); commentXml.appendChild(creationDate); // Modification date Element modificationDate = doc.createElement("modificationDate"); modificationDate.setTextContent(DateTimeSupport.toUTC(comment.getModificationDate().getTime())); commentXml.appendChild(modificationDate); // Text Element text = doc.createElement("text"); if (StringUtils.isNotBlank(comment.getText())) text.appendChild(doc.createCDATASection(comment.getText())); commentXml.appendChild(text); // Reason Element reason = doc.createElement("reason"); if (StringUtils.isNotBlank(comment.getReason())) reason.setTextContent(comment.getReason()); commentXml.appendChild(reason); // Replies Element repliesNode = doc.createElement("replies"); for (CommentReply r : comment.getReplies()) { repliesNode.appendChild(getAsXml(r, doc)); } commentXml.appendChild(repliesNode); return commentXml; }
From source file:org.opencastproject.comments.CommentParser.java
private static Element getAsXml(CommentReply reply, Document doc) { // Root element "comment" Element replyXml = doc.createElementNS(NAMESPACE, "reply"); replyXml.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", NAMESPACE); // Identifier if (reply.getId().isSome()) replyXml.setAttribute("id", reply.getId().get().toString()); // Author/*from w ww .java 2s.c om*/ Element authorNode = getAuthorNode(reply.getAuthor(), doc); replyXml.appendChild(authorNode); // Creation date Element creationDate = doc.createElement("creationDate"); creationDate.setTextContent(DateTimeSupport.toUTC(reply.getCreationDate().getTime())); replyXml.appendChild(creationDate); // Modification date Element modificationDate = doc.createElement("modificationDate"); modificationDate.setTextContent(DateTimeSupport.toUTC(reply.getModificationDate().getTime())); replyXml.appendChild(modificationDate); // Text Element text = doc.createElement("text"); if (StringUtils.isNotBlank(reply.getText())) text.appendChild(doc.createCDATASection(reply.getText())); replyXml.appendChild(text); return replyXml; }
From source file:org.openmrs.module.drawing.obs.handler.DrawingHandler.java
public void saveAnnotation(Obs obs, ImageAnnotation annotation, boolean delete) { try {/*w w w .ja va 2 s.c o m*/ log.info("drawing: Saving annotation for obs " + obs.getObsId()); File metadataFile = getComplexMetadataFile(obs); log.info("drawing: Using file " + metadataFile.getCanonicalPath()); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document xmldoc; Element annotationsParent; int newId = 0; if (metadataFile.exists()) { xmldoc = builder.parse(metadataFile); annotationsParent = (Element) xmldoc.getElementsByTagName("Annotations").item(0); NodeList annotationNodeList = xmldoc.getElementsByTagName("Annotation"); for (int i = 0; i < annotationNodeList.getLength(); i++) { NamedNodeMap attributes = annotationNodeList.item(i).getAttributes(); String idString = attributes.getNamedItem("id").getNodeValue(); int existingId = Integer.parseInt(idString); if (existingId == annotation.getId() && !(annotation.getStatus() == Status.UNCHANGED)) { annotationsParent.removeChild(annotationNodeList.item(i)); break; } if (existingId >= newId) newId = existingId + 1; } } else { metadataFile.createNewFile(); DOMImplementation domImpl = builder.getDOMImplementation(); xmldoc = domImpl.createDocument(null, "ImageMetadata", null); Element root = xmldoc.getDocumentElement(); annotationsParent = xmldoc.createElementNS(null, "Annotations"); root.appendChild(annotationsParent); } if (!delete && annotation.getStatus() != Status.UNCHANGED) { if (annotation.getId() >= 0) newId = annotation.getId(); Element e = xmldoc.createElementNS(null, "Annotation"); Node n = xmldoc.createTextNode(annotation.getText()); e.setAttributeNS(null, "id", newId + ""); e.setAttributeNS(null, "xcoordinate", annotation.getLocation().getX() + ""); e.setAttributeNS(null, "ycoordinate", annotation.getLocation().getY() + ""); e.setAttributeNS(null, "userid", annotation.getUser().getUserId() + ""); e.setAttributeNS(null, "date", annotation.getDate().getTime() + ""); e.appendChild(n); annotationsParent.appendChild(e); } Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF8"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(new DOMSource(xmldoc), new StreamResult(metadataFile)); log.info("drawing: Saving annotation complete"); } catch (Exception e) { log.error("drawing: Error saving image metadata: " + e.getClass() + " " + e.getMessage()); } }
From source file:org.ow2.proactive.scheduler.common.job.factories.Job2XMLTransformer.java
/** * Creates the "job" element <define name="job"> *//*w w w.j av a2s . c om*/ private Element createRootJobElement(Document doc, TaskFlowJob job) { Element rootJob = doc.createElementNS(Schemas.SCHEMA_LATEST.getNamespace(), "job"); // ********** attributes *********** rootJob.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation", XSD_LOCATION); setAttribute(rootJob, XMLAttributes.JOB_PROJECT_NAME, job.getProjectName(), true); setAttribute(rootJob, XMLAttributes.JOB_PRIORITY, job.getPriority().toString()); if (job.getOnTaskErrorProperty().isSet()) { setAttribute(rootJob, XMLAttributes.COMMON_ON_TASK_ERROR, job.getOnTaskErrorProperty().getValue().toString(), true); } if (job.getMaxNumberOfExecutionProperty().isSet()) { setAttribute(rootJob, XMLAttributes.COMMON_MAX_NUMBER_OF_EXECUTION, Integer.toString(job.getMaxNumberOfExecution())); } setAttribute(rootJob, XMLAttributes.COMMON_NAME, job.getName(), true); if (job.getRestartTaskOnErrorProperty().isSet()) { setAttribute(rootJob, XMLAttributes.COMMON_RESTART_TASK_ON_ERROR, job.getRestartTaskOnError().toString()); } // *** elements *** // <ref name="variables"/> if (job.getVariables() != null && !job.getVariables().isEmpty()) { Element variablesE = createJobVariablesElement(doc, job.getVariables()); rootJob.appendChild(variablesE); } // <ref name="jobDescription"/> if (job.getDescription() != null) { Element descrNode = createElement(doc, XMLTags.COMMON_DESCRIPTION.getXMLName(), job.getDescription()); rootJob.appendChild(descrNode); } // <ref name="genericInformation"/> if ((job.getGenericInformation() != null) && (job.getGenericInformation().size() > 0)) { Element genericInfo = createGenericInformation(doc, job.getGenericInformation()); rootJob.appendChild(genericInfo); } // <ref name="inputSpace"/> if (job.getInputSpace() != null) { Element inputspace = createElement(doc, XMLTags.DS_INPUT_SPACE.getXMLName(), null, new Attribute(XMLAttributes.DS_URL.getXMLName(), job.getInputSpace())); rootJob.appendChild(inputspace); } // <ref name="outputSpace"/> if (job.getOutputSpace() != null) { Element outputSpace = createElement(doc, XMLTags.DS_OUTPUT_SPACE.getXMLName(), null, new Attribute(XMLAttributes.DS_URL.getXMLName(), job.getOutputSpace())); rootJob.appendChild(outputSpace); } // <ref name="globalSpace"/> if (job.getGlobalSpace() != null) { Element globalSpace = createElement(doc, XMLTags.DS_GLOBAL_SPACE.getXMLName(), null, new Attribute(XMLAttributes.DS_URL.getXMLName(), job.getGlobalSpace())); rootJob.appendChild(globalSpace); } // <ref name="userSpace"/> if (job.getUserSpace() != null) { Element userSpace = createElement(doc, XMLTags.DS_USER_SPACE.getXMLName(), null, new Attribute(XMLAttributes.DS_URL.getXMLName(), job.getUserSpace())); rootJob.appendChild(userSpace); } // <ref name="taskFlow"/> Element taskFlow = createTaskFlowElement(doc, job); rootJob.appendChild(taskFlow); return rootJob; }