/** Corresponds to <element name="javaExecutable"> */ private Element createJavaExecutableElement(Document doc, JavaTask t) { Element executableE = doc.createElementNS(Schemas.SCHEMA_LATEST.namespace, XMLTags.JAVA_EXECUTABLE.getXMLName()); setAttribute(executableE, XMLAttributes.TASK_CLASS_NAME, t.getExecutableClassName(), true); // <ref name="javaParameters"/> try { Map<String, Serializable> args = t.getArguments(); if ((args != null) && (args.size() > 0)) { // <element name="parameter"> Element paramsE = doc.createElementNS( Schemas.SCHEMA_LATEST.namespace, XMLTags.TASK_PARAMETERS.getXMLName()); for (String name : args.keySet()) { Serializable val = args.get(name); Element paramE = doc.createElementNS( Schemas.SCHEMA_LATEST.namespace, XMLTags.TASK_PARAMETER.getXMLName()); setAttribute(paramE, XMLAttributes.COMMON_NAME, name, true); setAttribute(paramE, XMLAttributes.COMMON_VALUE, val.toString(), true); paramsE.appendChild(paramE); } executableE.appendChild(paramsE); } } catch (Exception e) { logger.error("Could not add arguments for Java Executable element of task " + t.getName(), e); } return executableE; }
/** * Exports a <code>GetRecordById</code> instance to a <code>GetRecordByIdDocument</code>. * * @param request * @return DOM representation of the <code>GetRecordById</code> * @throws XMLException if XML template could not be loaded */ public static GetRecordByIdDocument export(GetRecordById request) throws XMLException { GetRecordByIdDocument getRecordByIdDoc = new GetRecordByIdDocument(); try { getRecordByIdDoc.createEmptyDocument(); } catch (Exception e) { throw new XMLException(e.getMessage()); } Element rootElement = getRecordByIdDoc.getRootElement(); Document doc = rootElement.getOwnerDocument(); // 'version'-attribute rootElement.setAttribute("version", request.getVersion()); String[] ids = request.getIds(); for (int i = 0; i < ids.length; i++) { Element idElement = doc.createElementNS(CSWNS.toString(), "csw:Id"); idElement.appendChild(doc.createTextNode(ids[i])); rootElement.appendChild(idElement); } String elementSetName = request.getElementSetName(); if (elementSetName != null) { Element esnElement = doc.createElementNS(CSWNS.toString(), "csw:ElementSetName"); esnElement.appendChild(doc.createTextNode(elementSetName)); rootElement.appendChild(esnElement); } return getRecordByIdDoc; }
@Override public void walkJAXBElements(Object o) { Node existingParentNode = parentNode; if (o instanceof org.docx4j.wml.Tr) { tr.push(document.createElementNS(Namespaces.NS_WORD12, "tr")); // parentNode is in this case the DocumentFragment, that get's passed // to the TableModel/TableModelWriter parentNode.appendChild(tr.peek()); } else if (o instanceof org.docx4j.wml.Tc) { tc.push(document.createElementNS(Namespaces.NS_WORD12, "tc")); (tr.peek()).appendChild(tc.peek()); // now the html p content will go temporarily go in w:tc, // which is what we need for our existing table model. parentNode = tc.peek(); } super.walkJAXBElements(o); if (o instanceof org.docx4j.wml.Tr) { tr.pop(); } else if (o instanceof org.docx4j.wml.Tc) { tc.pop(); parentNode = existingParentNode; // restore } }
@Override public final Element put(final Element parentElement, final Object value) { Element newElement = document.createElementNS(XMLNS_ITEM, parentElement.getLocalName()); if (value == null) { newElement.setAttribute("isNull", "yes"); return newElement; } Map<String, Object> attributes = XmlHelper.extractAttributes(value); for (String key : attributes.keySet()) { try { newElement.setAttribute(key, attributes.get(key).toString()); } catch (Exception e) { // XXX: ignore exceptions silenty } } Map<String, Collection<?>> collections = XmlHelper.extractCollections(value); for (String key : collections.keySet()) { try { Element container = document.createElementNS(XMLNS_DATA, key); newElement.appendChild(container); for (Object item : collections.get(key)) { put(container, item); } } catch (Exception e) { // XXX: ignore exceptions silenty } } newElement.appendChild(document.createTextNode(value.toString())); parentElement.appendChild(newElement); return newElement; }
protected void writeFaultElement( Document d, Element bodyElement, ActionInvocation actionInvocation) { Element faultElement = d.createElementNS(Constants.SOAP_NS_ENVELOPE, "s:Fault"); bodyElement.appendChild(faultElement); // This stuff is really completely arbitrary nonsense... let's hope they fired the guy who // decided this XMLUtil.appendNewElement(d, faultElement, "faultcode", "s:Client"); XMLUtil.appendNewElement(d, faultElement, "faultstring", "UPnPError"); Element detailElement = d.createElement("detail"); faultElement.appendChild(detailElement); Element upnpErrorElement = d.createElementNS(Constants.NS_UPNP_CONTROL_10, "UPnPError"); detailElement.appendChild(upnpErrorElement); int errorCode = actionInvocation.getFailure().getErrorCode(); String errorDescription = actionInvocation.getFailure().getMessage(); log.fine("Writing fault element: " + errorCode + " - " + errorDescription); XMLUtil.appendNewElement(d, upnpErrorElement, "errorCode", Integer.toString(errorCode)); XMLUtil.appendNewElement(d, upnpErrorElement, "errorDescription", errorDescription); }
private static Element addLink(Element parent, Entry entry, Document doc) { Element link = doc.createElementNS(null, "link"); parent.appendChild(link); link.setAttributeNS(null, "class", "- topic/link "); link.setAttributeNS(null, "href", entry.href); if (entry.scope != null) { link.setAttributeNS(null, "scope", entry.scope); } if (entry.format != null) { link.setAttributeNS(null, "format", entry.format); } if (entry.linktext != null) { Element linktext = (Element) doc.importNode(entry.linktext, /*deep*/ true); linktext.setAttributeNS(null, "class", "- topic/linktext "); link.appendChild(linktext); } if (entry.shortdesc != null) { Element desc = doc.createElementNS(null, "desc"); desc.setAttributeNS(null, "class", "- topic/desc "); link.appendChild(desc); DOMUtil.copyChildren(entry.shortdesc, desc, doc); } return link; }
private Element addLinkpool(Element topic, boolean prepend, String linkpoolType, Document doc) { Element relatedLinks = DITAUtil.findChildByClass(topic, "topic/related-links"); if (relatedLinks == null) { relatedLinks = doc.createElementNS(null, "related-links"); relatedLinks.setAttributeNS(null, "class", "- topic/related-links "); topic.insertBefore(relatedLinks, DITAUtil.findChildByClass(topic, "topic/topic")); } Element linkpool = doc.createElementNS(null, "linkpool"); linkpool.setAttributeNS(null, "class", "- topic/linkpool "); if (mapHref != null && linkpoolType != null) { // mapkeyref is a standard DITA 1.2 attribute meant for this use. linkpool.setAttributeNS(null, "mapkeyref", mapHref + " type=" + linkpoolType); } Node before = null; if (prepend) { before = relatedLinks.getFirstChild(); } relatedLinks.insertBefore(linkpool, before); return linkpool; }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "getNamespaceURI", args = {}) public void testGetNamespaceURI() throws Throwable { Document doc; Element element; Element elementNS; Attr attr; Attr attrNS; String elemNSURI; String elemNSURINull; String attrNSURI; String attrNSURINull; String nullNS = null; doc = (Document) load("staff", builder); element = doc.createElementNS(nullNS, "elem"); elementNS = doc.createElementNS("http://www.w3.org/DOM/Test/elem", "qual:qelem"); attr = doc.createAttributeNS(nullNS, "attr"); attrNS = doc.createAttributeNS("http://www.w3.org/DOM/Test/attr", "qual:qattr"); elemNSURI = elementNS.getNamespaceURI(); elemNSURINull = element.getNamespaceURI(); attrNSURI = attrNS.getNamespaceURI(); attrNSURINull = attr.getNamespaceURI(); assertEquals("nodegetnamespaceuri03_elemNSURI", "http://www.w3.org/DOM/Test/elem", elemNSURI); assertNull("nodegetnamespaceuri03_1", elemNSURINull); assertEquals("nodegetnamespaceuri03_attrNSURI", "http://www.w3.org/DOM/Test/attr", attrNSURI); assertNull("nodegetnamespaceuri03_2", attrNSURINull); }
/** * Adds XSLT-elements for calling a named template to wrapperDoc * * <p>Following elements are added to utfxWrapperElement as childs <xsl:for-each * select="$utfx-wrapper-removed/*[1]"> or context-node attribute <xsl:call-template name="NAME OF * TEMPLATE"/> </xsl:for-each> <xsl:apply-templates select="$utfx-wrapper-removed/*[position() > * 1]"/> * * @param wrapperDoc DOM Document representing the UTF-X test definition file * @param utfxWrapperElement the utfx-wrapper element from wrapper.xsl * @param elem call-template element * @return void * @throws Exception */ private void addCallTemplate( Document wrapperDoc, Element utfxWrapperElement, Element elem, String sourceContextNode) throws Exception { String templateName = elem.getAttribute("name"); Element xslCallTemplate = wrapperDoc.createElementNS(UTFXNamespaceContext.XSL_NS_URI, "xsl:call-template"); xslCallTemplate.setAttribute("name", templateName); addCallTemplateParameters(wrapperDoc, elem, xslCallTemplate); // compose select expression for xsl:for-each StringBuffer selectExpression = new StringBuffer("$utfx-wrapper-removed"); if (sourceContextNode.length() == 0) { selectExpression.append("/*[1]"); } else if (sourceContextNode.equals("/")) { // adding a slash to $utfx-wrapper-removed would // result in an invalid XPath expression. therefore we don't add // anything } else { selectExpression.append(sourceContextNode); } Element xslForEach = wrapperDoc.createElementNS(UTFXNamespaceContext.XSL_NS_URI, "xsl:for-each"); xslForEach.setAttribute("select", selectExpression.toString()); xslForEach.appendChild(xslCallTemplate); Element xslApplyTemplates = wrapperDoc.createElementNS(UTFXNamespaceContext.XSL_NS_URI, "xsl:apply-templates"); xslApplyTemplates.setAttribute("select", "$utfx-wrapper-removed/*[position() > 1]"); utfxWrapperElement.appendChild(xslForEach); utfxWrapperElement.appendChild(xslApplyTemplates); }
private static void addDocumentation(Document doc, Element element, String documentation) { if (documentation != null) { Element annotation = doc.createElementNS(NS_XS, XS_ANNOTATION); element.appendChild(annotation); Element docEl = doc.createElementNS(NS_XS, XS_DOCUMENTATION); annotation.appendChild(docEl); docEl.appendChild(doc.createTextNode(documentation)); } }
@Override public Element getSOAPHeaders(Object portObject) { String securityToken = getSecurityToken(); // Exit if no security token found if (securityToken == null) { if (LOG.isDebugEnabled()) { LOG.debug("securityToken is null"); } return null; } // Set time SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); long created = System.currentTimeMillis(); long expires = created + 24 * 60 * 60 * 1000; // 24 hours // Create the SOAP WSSecurity header try { Document document = XMLUtils.newDomDocument(); Element wsseSecurityElement = document.createElementNS(WSSE_NAMESPACE, "Security"); Element wsuTimestampElement = document.createElementNS(WSU_NAMESPACE, "Timestamp"); wsseSecurityElement.appendChild(wsuTimestampElement); Element tsCreatedElement = document.createElementNS(WSU_NAMESPACE, "Created"); tsCreatedElement.appendChild(document.createTextNode(sdf.format(created))); wsuTimestampElement.appendChild(tsCreatedElement); Element tsExpiresElement = document.createElementNS(WSU_NAMESPACE, "Expires"); tsExpiresElement.appendChild(document.createTextNode(sdf.format(expires))); wsuTimestampElement.appendChild(tsExpiresElement); // Add the BinarySecurityToken (contains the LTPAv2 token) Element wsseBinarySecurityTokenElement = document.createElementNS(WSSE_NAMESPACE, "BinarySecurityToken"); wsseBinarySecurityTokenElement.setAttribute("xmlns:wsu", WSU_NAMESPACE); wsseBinarySecurityTokenElement.setAttribute( "xmlns:wsst", "http://www.ibm.com/websphere/appserver/tokentype"); wsseBinarySecurityTokenElement.setAttribute("wsu:Id", "ltpa_20"); wsseBinarySecurityTokenElement.setAttribute("ValueType", "wsst:LTPAv2"); wsseBinarySecurityTokenElement.appendChild(document.createTextNode(securityToken)); // Append BinarySecurityToken to Security section wsseSecurityElement.appendChild(wsseBinarySecurityTokenElement); return wsseSecurityElement; } catch (ParserConfigurationException e) { // shouldn't happen... throw new CmisRuntimeException("Could not build SOAP header: " + e.getMessage(), e); } }
/** * Carries out preprocessing that makes JEuclid handle the document better. * * @param doc Document */ static void preprocessForJEuclid(Document doc) { // underbrace and overbrace NodeList list = doc.getElementsByTagName("mo"); for (int i = 0; i < list.getLength(); i++) { Element mo = (Element) list.item(i); String parentName = ((Element) mo.getParentNode()).getTagName(); if (parentName == null) { continue; } if (parentName.equals("munder") && isTextChild(mo, "\ufe38")) { mo.setAttribute("stretchy", "true"); mo.removeChild(mo.getFirstChild()); mo.appendChild(doc.createTextNode("\u23df")); } else if (parentName.equals("mover") && isTextChild(mo, "\ufe37")) { mo.setAttribute("stretchy", "true"); mo.removeChild(mo.getFirstChild()); mo.appendChild(doc.createTextNode("\u23de")); } } // menclose for long division doesn't allow enough top padding. Oh, and // <mpadded> isn't implemented. And there isn't enough padding to left of // the bar either. Solve by adding an <mover> with just an <mspace> over# // the longdiv, contained within an mrow that adds a <mspace> before it. list = doc.getElementsByTagName("menclose"); for (int i = 0; i < list.getLength(); i++) { Element menclose = (Element) list.item(i); // Only for longdiv if (!"longdiv".equals(menclose.getAttribute("notation"))) { continue; } Element mrow = doc.createElementNS(WebMathsService.NS, "mrow"); Element mover = doc.createElementNS(WebMathsService.NS, "mover"); Element mspace = doc.createElementNS(WebMathsService.NS, "mspace"); Element mspaceW = doc.createElementNS(WebMathsService.NS, "mspace"); boolean previousElement = false; for (Node previous = menclose.getPreviousSibling(); previous != null; previous = previous.getPreviousSibling()) { if (previous.getNodeType() == Node.ELEMENT_NODE) { previousElement = true; break; } } if (previousElement) { mspaceW.setAttribute("width", "4px"); } menclose.getParentNode().insertBefore(mrow, menclose); menclose.getParentNode().removeChild(menclose); mrow.appendChild(mspaceW); mrow.appendChild(mover); mover.appendChild(menclose); mover.appendChild(mspace); } }
private static Element createComplexElement( Document doc, Element parentSequence, String name, int minOccurs, int maxOccurs) { Element element = doc.createElementNS(NS_XS, XS_ELEMENT); element.setAttribute(XS_NAME, name); if (minOccurs >= 0) element.setAttribute(XS_MIN_OCCURS, String.valueOf(minOccurs)); element.setAttribute(XS_MAX_OCCURS, maxOccurs < 0 ? "unbounded" : String.valueOf(maxOccurs)); parentSequence.appendChild(element); Element complex = doc.createElementNS(NS_XS, XS_COMPLEX_TYPE); element.appendChild(complex); return complex; }
/** * Delete md-record and add new with same name again. * * @throws Exception Thrown if behaviour differs from expected */ @Test public void testAddMdRecordAfterDelete() throws Exception { // create ContentRelation and remove md-records Document relationCreated = getDocument(relationXml); NodeList mdRecords = selectNodeList(relationCreated, "/content-relation/md-records/md-record"); String mdRecordPath = null; if (mdRecords.getLength() > 1) { mdRecordPath = "/content-relation/md-records/md-record[@name='escidoc']"; } else { mdRecordPath = "/content-relation/md-records"; } Node relationWithoutEscidocMdRecord = deleteElement(relationCreated, mdRecordPath); String relationWithoutEscidocMdRecordXml = toString(relationWithoutEscidocMdRecord, true); // update ContentRelation with missing md-records String updatedXml = update(this.relationId, relationWithoutEscidocMdRecordXml); assertXmlValidContentRelation(updatedXml); // check if md-records element is deleted Document updatedDocument = getDocument(updatedXml); Node notExistedMdRecord = selectSingleNode(updatedDocument, mdRecordPath); assertNull("Escidoc md-record must be deleted", notExistedMdRecord); // add new md-record element Element mdRecordsNew = updatedDocument.createElementNS( "http://www.escidoc.de/schemas/metadatarecords/0.5", "escidocMetadataRecords:md-records"); Element mdRecord = updatedDocument.createElementNS( "http://www.escidoc.de/schemas/metadatarecords/0.5", "escidocMetadataRecords:md-record"); mdRecordsNew.appendChild(mdRecord); mdRecord.setAttribute("name", "md2"); mdRecord.setAttribute("schema", "bla"); Element mdRecordContent = updatedDocument.createElement("md"); mdRecord.appendChild(mdRecordContent); mdRecordContent.setTextContent("more then bla"); Node resources = selectSingleNode(updatedDocument, "/content-relation/resources"); selectSingleNode(updatedDocument, "/content-relation").insertBefore(mdRecordsNew, resources); String relationWithNewMdRecord = toString(updatedDocument, false); // update with new md-record updatedXml = update(this.relationId, relationWithNewMdRecord); // check md-record element assertXmlValidContentRelation(updatedXml); Document updatedRelationDocument = getDocument(updatedXml); Node escidocMdRecord = selectSingleNode(updatedRelationDocument, mdRecordPath); assertNotNull(escidocMdRecord); }
protected Element writeBodyElement(Document d) { Element envelopeElement = d.createElementNS(Constants.SOAP_NS_ENVELOPE, "s:Envelope"); Attr encodingStyleAttr = d.createAttributeNS(Constants.SOAP_NS_ENVELOPE, "s:encodingStyle"); encodingStyleAttr.setValue(Constants.SOAP_URI_ENCODING_STYLE); envelopeElement.setAttributeNode(encodingStyleAttr); d.appendChild(envelopeElement); Element bodyElement = d.createElementNS(Constants.SOAP_NS_ENVELOPE, "s:Body"); envelopeElement.appendChild(bodyElement); return bodyElement; }
/* * Mock up an AppliesTo element using the supplied address */ private Element createAppliesToElement(String addressUrl) { Document doc = DOMUtils.createDocument(); Element appliesTo = doc.createElementNS(STSConstants.WSP_NS, "wsp:AppliesTo"); appliesTo.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsp", STSConstants.WSP_NS); Element endpointRef = doc.createElementNS(STSConstants.WSA_NS_05, "wsa:EndpointReference"); endpointRef.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsa", STSConstants.WSA_NS_05); Element address = doc.createElementNS(STSConstants.WSA_NS_05, "wsa:Address"); address.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:wsa", STSConstants.WSA_NS_05); address.setTextContent(addressUrl); endpointRef.appendChild(address); appliesTo.appendChild(endpointRef); return appliesTo; }
public Element getSchemaElement(Document document) { Element complexElement = document.createElementNS(Constants.URI_2001_SCHEMA_XSD, "xsd:complexType"); complexElement.setPrefix("xsd"); complexElement.setAttribute("name", this.name); Element sequenceElement = document.createElementNS(Constants.URI_2001_SCHEMA_XSD, "xsd:sequence"); sequenceElement.setPrefix("xsd"); complexElement.appendChild(sequenceElement); return complexElement; }
private DOMResult prepareDomResultForRpcRequest(final QName rpcQName) { final Document document = XmlUtil.newDocument(); final Element rpcNS = document.createElementNS( NETCONF_RPC_QNAME.getNamespace().toString(), NETCONF_RPC_QNAME.getLocalName()); // set msg id rpcNS.setAttribute( NetconfMessageTransformUtil.MESSAGE_ID_ATTR, counter.getNewMessageId(MESSAGE_ID_PREFIX)); final Element elementNS = document.createElementNS(rpcQName.getNamespace().toString(), rpcQName.getLocalName()); rpcNS.appendChild(elementNS); document.appendChild(rpcNS); return new DOMResult(elementNS); }
/** * Returns a DOM node for the entire workspace. This includes the block workspace, any custom * factories, canvas view state and position, pages * * @return the DOM node for the entire workspace. */ public Node getSaveNode() { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Element documentElement = document.createElementNS(Constants.XML_CODEBLOCKS_NS, "cb:CODEBLOCKS"); // schema reference documentElement.setAttributeNS( XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi:schemaLocation", Constants.XML_CODEBLOCKS_NS + " " + Constants.XML_CODEBLOCKS_SCHEMA_URI); Node workspaceNode = workspace.getSaveNode(document); if (workspaceNode != null) { documentElement.appendChild(workspaceNode); } document.appendChild(documentElement); validate(document); return document; } catch (ParserConfigurationException e) { throw new RuntimeException(e); } }
/** * Test adding a second md-record to ContentRelation. One md-record already exists. * * @throws Exception Thrown if adding one md-record failed. */ @Test public void testAddMdRecord() throws Exception { // add one more md-record Document relationCreated = getDocument(relationXml); NodeList mdRecordsCreated = selectNodeList(relationCreated, "/content-relation/md-records/md-record"); int numberMdRecordsCreated = mdRecordsCreated.getLength(); Element mdRecord = relationCreated.createElementNS( "http://www.escidoc.de/schemas/metadatarecords/0.5", "escidocMetadataRecords:md-record"); mdRecord.setAttribute("name", "md2"); mdRecord.setAttribute("schema", "bla"); Element mdRecordContent = relationCreated.createElement("md"); mdRecord.appendChild(mdRecordContent); mdRecordContent.setTextContent("bla"); selectSingleNode(relationCreated, "/content-relation/md-records").appendChild(mdRecord); String relationWithNewMdRecord = toString(relationCreated, false); String updatedXml = update(this.relationId, relationWithNewMdRecord); // check updated assertXmlValidContentRelation(updatedXml); Document updatedRelationDocument = getDocument(updatedXml); NodeList mdRecordsUpdated = selectNodeList(updatedRelationDocument, "/content-relation/md-records/md-record"); int numberMdRecordsUpdated = mdRecordsUpdated.getLength(); assertEquals( "the content relation should have one additional" + " md-record after update ", numberMdRecordsUpdated, numberMdRecordsCreated + 1); }
public Element AbstractFeatureTypeEncode( Object object, Document document, Element value, XSDIdRegistry idSet) { Feature feature = (Feature) object; String id = feature.getIdentifier().getID(); Name typeName; if (feature.getDescriptor() == null) { // no descriptor, assume WFS feature type name is the same as the name of the content // model type typeName = feature.getType().getName(); } else { // honour the name set in the descriptor typeName = feature.getDescriptor().getName(); } Element encoding = document.createElementNS(typeName.getNamespaceURI(), typeName.getLocalPart()); if (!(feature instanceof SimpleFeature) && idSet != null) { if (idSet.idExists(id)) { // XSD type ids can only appear once in the same document, otherwise the document is // not schema valid. Attributes of the same ids should be encoded as xlink:href to // the existing attribute. encoding.setAttributeNS(XLINK.NAMESPACE, XLINK.HREF.getLocalPart(), "#" + id.toString()); // make sure the attributes aren't encoded feature.setValue(Collections.emptyList()); return encoding; } else { idSet.add(id); } } encoding.setAttributeNS(gml.getNamespaceURI(), "id", id); encodeClientProperties(feature, value); return encoding; }
private static void addAlignment(EXIOptions exiOptions, Document doc, Element startExiElement) { Element alignmentElement = doc.createElementNS( XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_EXI_1_0, ALIGNMENT_KEY); alignmentElement.setTextContent(exiOptions.getAlignmentType().toString()); startExiElement.appendChild(alignmentElement); }
/** * Adds code for stylesheet parameters to wrapperDoc * * @param wrapperDoc DOM Document representing the UTF-X test definition file. * @param elem stylesheet-params element * @return void * @throws Exception */ private void addStylesheetParams(Document wrapperDoc, Element elem) throws Exception { // find refElement (for insertBefore) Element xslOutputElement = (Element) xpath.evaluate("xsl:output", wrapperDoc.getDocumentElement(), XPathConstants.NODE); Node refNode = xslOutputElement.getNextSibling(); NodeList params; try { params = (NodeList) xpath.evaluate("*[name() = 'utfx:with-param']", elem, XPathConstants.NODESET); } catch (XPathExpressionException e) { throw new AssertionError(e); } for (int i = 0; i < params.getLength(); i++) { Element withParamElement = (Element) params.item(i); // create xsl:param element Element xslParam = wrapperDoc.createElementNS(UTFXNamespaceContext.XSL_NS_URI, "xsl:param"); xslParam.setAttribute("name", withParamElement.getAttribute("name")); copySelectAttrOrChildNodes(withParamElement, wrapperDoc, xslParam); wrapperDoc.getDocumentElement().insertBefore(xslParam, refNode); } }
/** * Adds with-param elements to wrapperDoc * * @param wrapperDoc DOM Document representing the UTF-X test definition file. * @param elem stylesheet-params element * @param xslCallTemplate call-template element in wrapperDoc * @return void */ private void addCallTemplateParameters( Document wrapperDoc, Element elem, Element xslCallTemplate) { NodeList params; try { params = (NodeList) xpath.evaluate("*[name() = 'utfx:with-param']", elem, XPathConstants.NODESET); } catch (XPathExpressionException e) { throw new AssertionError(e); } int paramsCount = params.getLength(); for (int i = 0; i < paramsCount; i++) { Element paramElem = (Element) params.item(i); Element xslWithParam = wrapperDoc.createElementNS(UTFXNamespaceContext.XSL_NS_URI, "xsl:with-param"); String name = paramElem.getAttribute("name"); xslWithParam.setAttribute("name", name); copySelectAttrOrChildNodes(paramElem, wrapperDoc, xslWithParam); xslCallTemplate.appendChild(xslWithParam); } }
/** * creates a svg element by specifiying its parameters * * @param handle the current svg handle * @param text the text for the new element * @return the created svg element */ public Element createElement(SVGHandle handle, String text) { // the edited document Document doc = handle.getScrollPane().getSVGCanvas().getDocument(); // creating the text element final Element element = doc.createElementNS(doc.getDocumentElement().getNamespaceURI(), handledElementTagName); // getting the last color that has been used by the user String colorString = Editor.getColorChooser().getColorString(ColorManager.getCurrentColor()); element.setAttributeNS(null, "style", "fill:" + colorString + ";stroke:none;"); element.setAttributeNS(null, "style", "font-size:12pt;fill:" + colorString + ";"); EditorToolkit.setAttributeValue(element, xAtt, drawingPoint.getX()); EditorToolkit.setAttributeValue(element, yAtt, drawingPoint.getY()); // creating the text node Text textValue = doc.createTextNode(text); element.appendChild(textValue); // inserting the element in the document and handling the undo/redo // support insertShapeElement(handle, element); handle.getSelection().handleSelection(element, false, false); return element; }
/** * Get an XML DOM tree representation of the cue sheet. * * @param cueSheet The CueSheet to serialize. * @return An XML DOM tree representation of the cue sheet. */ public Document serializeCueSheet(final CueSheet cueSheet) { CueSheetToXmlSerializer.logger.entering( CueSheetToXmlSerializer.class.getCanonicalName(), "serializeCueSheet(CueSheet)", cueSheet); Document doc = docBuilder.newDocument(); Element cueSheetElement = doc.createElementNS(this.namespace, "cuesheet"); doc.appendChild(cueSheetElement); addAttribute(cueSheetElement, "genre", cueSheet.getGenre()); addAttribute(cueSheetElement, "date", cueSheet.getYear()); addAttribute(cueSheetElement, "discid", cueSheet.getDiscid()); addAttribute(cueSheetElement, "comment", cueSheet.getComment()); addAttribute(cueSheetElement, "catalog", cueSheet.getCatalog()); addAttribute(cueSheetElement, "performer", cueSheet.getPerformer()); addAttribute(cueSheetElement, "title", cueSheet.getTitle()); addAttribute(cueSheetElement, "songwriter", cueSheet.getSongwriter()); addAttribute(cueSheetElement, "cdtextfile", cueSheet.getCdTextFile()); for (FileData fileData : cueSheet.getFileData()) { serializeFileData(cueSheetElement, fileData); } CueSheetToXmlSerializer.logger.exiting( CueSheetToXmlSerializer.class.getCanonicalName(), "serializeCueSheet(CueSheet)", doc); return doc; }
/** * Serialize the TrackData. * * @param parentElement The parent element for the TrackData. * @param trackData The TrackData to serialize. */ private void serializeTrackData(final Element parentElement, final TrackData trackData) { CueSheetToXmlSerializer.logger.entering( CueSheetToXmlSerializer.class.getCanonicalName(), "serializeTrackData(Element,TrackData)", new Object[] {parentElement, trackData}); Document doc = parentElement.getOwnerDocument(); Element trackElement = doc.createElementNS(this.namespace, "track"); parentElement.appendChild(trackElement); addAttribute(trackElement, "number", trackData.getNumber()); addAttribute(trackElement, "type", trackData.getDataType()); addAttribute(trackElement, "isrc", trackData.getIsrcCode()); addAttribute(trackElement, "performer", trackData.getPerformer()); addAttribute(trackElement, "title", trackData.getTitle()); addAttribute(trackElement, "songwriter", trackData.getSongwriter()); addElement(trackElement, "pregap", trackData.getPregap()); addElement(trackElement, "postgap", trackData.getPostgap()); if (trackData.getFlags().size() > 0) { serializeFlags(trackElement, trackData.getFlags()); } for (Index index : trackData.getIndices()) { serializeIndex(trackElement, index); } CueSheetToXmlSerializer.logger.exiting( CueSheetToXmlSerializer.class.getCanonicalName(), "serializeTrackData(Element,TrackData)"); }
private SoapHeader makeSoapHeader( Document doc, String namespace, String localName, String value) { Element messageId = doc.createElementNS(namespace, localName); messageId.setTextContent(value); SoapHeader soapHeader = new SoapHeader(new QName(namespace, localName), messageId); return soapHeader; }
public Document build() { Document document = getNamespaceAwareDocument(); Element documentElement; if (prefixMapping == null) { documentElement = document.createElement(rootName); } else { documentElement = document.createElementNS(prefixMapping.getUri(), prefixMapping.qualify(rootName)); } documentElement.setAttributeNS(XMLNS_ATTRIBUTE_NS_URI, XMLNS_ATTRIBUTE, defaultNamespaceName); for (NamespaceUriPrefixMapping nsMapping : namespaceDeclarations) { documentElement.setAttributeNS( XMLNS_ATTRIBUTE_NS_URI, XMLNS_ATTRIBUTE + ":" + nsMapping.getPrefix(), nsMapping.getUri()); } for (XmlAttributeBuilder attributeBuilder : attributeBuilders) { documentElement.setAttributeNode(attributeBuilder.build(document)); } for (XmlStandaloneNodeBuilder xmlBuilder : childNodeBuilders) { documentElement.appendChild(xmlBuilder.build(document)); } document.appendChild(documentElement); return document; }
/** * Runs the test case. * * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { Document doc; NamedNodeMap notations; DocumentType docType; Node retval; Element elem; doc = (Document) load("hc_staff", true); docType = doc.getDoctype(); if (!(("text/html".equals(getContentType())))) { assertNotNull("docTypeNotNull", docType); notations = docType.getNotations(); assertNotNull("notationsNotNull", notations); elem = doc.createElementNS("http://www.w3.org/1999/xhtml", "br"); try { retval = notations.setNamedItemNS(elem); fail("throw_HIER_OR_NO_MOD_ERR"); } catch (DOMException ex) { switch (ex.code) { case 3: break; case 7: break; default: throw ex; } } } }