List of usage examples for org.w3c.dom Element setAttributeNS
public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException;
From source file:Main.java
private static Node convertFromNamespaceForm(final Node node) { if (node instanceof Element) { final Document document = node.getOwnerDocument(); final Element newElement = document.createElementNS(null, node.getLocalName()); final NodeList children = node.getChildNodes(); for (int i = 0, n = children.getLength(); i < n; i++) { final Node oldChildNode = children.item(i); final Node newChildNode = convertFromNamespaceForm(oldChildNode); newElement.appendChild(newChildNode); }/*from w ww .ja v a2 s. c o m*/ final NamedNodeMap attributes = node.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { final Attr attr = (Attr) attributes.item(i); final String attrQualifiedName = attr.getNodeName(); final String attrLocalName = attr.getLocalName(); if (!attrQualifiedName.equals(XMLNS) && !attrQualifiedName.startsWith(XMLNS_COLON) && !attrLocalName.equals(XSI_SCHEMA_LOCATION_ATTR)) { newElement.setAttributeNS(null, attrLocalName, attr.getValue()); } } return newElement; } else { return node.cloneNode(true); } }
From source file:com.dhenton9000.batik.sandbox.BatikExplorer.java
public Document createDocument() { // Create a new document. DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; Document document = impl.createDocument(svgNS, "svg", null); Element root = document.getDocumentElement(); root.setAttributeNS(null, "width", "450"); root.setAttributeNS(null, "height", "500"); // Add some content to the document. Element e;// w ww . j av a 2s .co m e = document.createElementNS(svgNS, "rect"); e.setAttributeNS(null, "x", "10"); e.setAttributeNS(null, "y", "10"); e.setAttributeNS(null, "width", "200"); e.setAttributeNS(null, "height", "300"); e.setAttributeNS(null, "style", "fill:red;stroke:black;stroke-width:4"); root.appendChild(e); e = document.createElementNS(svgNS, "circle"); e.setAttributeNS(null, "cx", "225"); e.setAttributeNS(null, "cy", "250"); e.setAttributeNS(null, "r", "100"); e.setAttributeNS(null, "style", "fill:green;fill-opacity:.5"); root.appendChild(e); return document; }
From source file:be.fedict.eid.applet.service.signer.odf.OpenOfficeSignatureFacet.java
public void preSign(XMLSignatureFactory signatureFactory, Document document, String signatureId, List<X509Certificate> signingCertificateChain, List<Reference> references, List<XMLObject> objects) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { LOG.debug("pre sign"); Element dateElement = document.createElementNS("", "dc:date"); dateElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:dc", "http://purl.org/dc/elements/1.1/"); DateTime dateTime = new DateTime(DateTimeZone.UTC); DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis(); String now = fmt.print(dateTime); now = now.substring(0, now.indexOf("Z")); LOG.debug("now: " + now); dateElement.setTextContent(now);// www . j a va 2s .c om String signaturePropertyId = "sign-prop-" + UUID.randomUUID().toString(); List<XMLStructure> signaturePropertyContent = new LinkedList<XMLStructure>(); signaturePropertyContent.add(new DOMStructure(dateElement)); SignatureProperty signatureProperty = signatureFactory.newSignatureProperty(signaturePropertyContent, "#" + signatureId, signaturePropertyId); List<XMLStructure> objectContent = new LinkedList<XMLStructure>(); List<SignatureProperty> signaturePropertiesContent = new LinkedList<SignatureProperty>(); signaturePropertiesContent.add(signatureProperty); SignatureProperties signatureProperties = signatureFactory .newSignatureProperties(signaturePropertiesContent, null); objectContent.add(signatureProperties); objects.add(signatureFactory.newXMLObject(objectContent, null, null, null)); DigestMethod digestMethod = signatureFactory.newDigestMethod(this.digestAlgo.getXmlAlgoId(), null); Reference reference = signatureFactory.newReference("#" + signaturePropertyId, digestMethod); references.add(reference); }
From source file:no.met.jtimeseries.meteogram.SvgChartSaver.java
@Override public void save(File file, JFreeChart chart, int width, int height) throws IOException { if (file == null || chart == null) throw new IllegalArgumentException("Null 'file' or 'chart' argument."); //get the genric dom imp DOMImplementation dom = GenericDOMImplementation.getDOMImplementation(); //create document org.w3c.dom.Document document = dom.createDocument(null, "svg", null); //create svg 2d graphics SVGGraphics2D svgGenerator = new SVGGraphics2D(document); svgGenerator.getGeneratorContext().setPrecision(6); svgGenerator.setSVGCanvasSize(new Dimension(width, height)); //render chart with svg 2D graphics chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, width, height)); Element svgRoot = svgGenerator.getRoot(); /// set SVG Canvas size (For auto resizing) svgRoot.setAttributeNS(null, SVGGraphics2D.SVG_VIEW_BOX_ATTRIBUTE, String.format("0 0 %d %d", width, height)); svgRoot.setAttributeNS(null, "preserveAspectRatio", "xMidYMid meet"); svgRoot.removeAttribute("width"); svgRoot.removeAttribute("height"); OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); Writer writer = new OutputStreamWriter(out, "UTF-8"); svgGenerator.stream(svgRoot, writer, false, true); }
From source file:net.sf.jabref.logic.msbib.MSBibDatabase.java
public Document getDOM() { Document document = null;//from ww w . j a va 2 s . co m try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder documentBuilder = factory.newDocumentBuilder(); document = documentBuilder.newDocument(); Element rootNode = document.createElementNS(NAMESPACE, PREFIX + "Sources"); rootNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", NAMESPACE); rootNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + PREFIX.substring(0, PREFIX.length() - 1), NAMESPACE); rootNode.setAttribute("SelectedStyle", ""); for (MSBibEntry entry : entries) { Node node = entry.getDOM(document); rootNode.appendChild(node); } document.appendChild(rootNode); } catch (ParserConfigurationException e) { LOGGER.warn("Could not build XML document", e); } return document; }
From source file:it.unibas.spicy.persistence.xml.operators.ExportXMLInstances.java
private void processRoot(INode node, Document document) { Element root = document.getDocumentElement(); root.setAttributeNS(XSI_NS, "xsi:noNamespaceSchemaLocation", node.getLabel() + ".xsd"); }
From source file:no.digipost.api.interceptors.EbmsClientInterceptor.java
@Override public boolean handleRequest(final MessageContext messageContext) throws WebServiceClientException { SoapMessage requestMessage = (SoapMessage) messageContext.getRequest(); Element bodyElement = (Element) ((DOMSource) requestMessage.getSoapBody().getSource()).getNode(); bodyElement.setAttributeNS(Constants.WSSEC_UTILS_NAMESPACE, "wsu:Id", "soapBody"); bodyElement.setIdAttributeNS(Constants.WSSEC_UTILS_NAMESPACE, "Id", true); SoapHeader soapHeader = requestMessage.getSoapHeader(); EbmsContext context = EbmsContext.from(messageContext); SoapHeaderElement ebmsHeader = soapHeader.addHeaderElement(MESSAGING_QNAME); ebmsHeader.setMustUnderstand(true);/*from ww w . j a v a 2 s .c o m*/ context.processRequest(context, ebmsHeader, requestMessage); return true; }
From source file:be.fedict.eid.dss.document.zip.ZIPSignatureService.java
@Override protected Document getEnvelopingDocument() throws ParserConfigurationException, IOException, SAXException { FileInputStream fileInputStream = new FileInputStream(this.tmpFile); ZipInputStream zipInputStream = new ZipInputStream(fileInputStream); ZipEntry zipEntry;//from w w w . j a v a2 s . c o m while (null != (zipEntry = zipInputStream.getNextEntry())) { if (ODFUtil.isSignatureFile(zipEntry)) { Document documentSignaturesDocument = ODFUtil.loadDocument(zipInputStream); return documentSignaturesDocument; } } Document document = ODFUtil.getNewDocument(); Element rootElement = document.createElementNS(ODFUtil.SIGNATURE_NS, ODFUtil.SIGNATURE_ELEMENT); rootElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", ODFUtil.SIGNATURE_NS); document.appendChild(rootElement); return document; }
From source file:be.fedict.eid.applet.service.signer.odf.AbstractODFSignatureService.java
@Override protected final Document getEnvelopingDocument() throws ParserConfigurationException, IOException, SAXException { Document document = getODFSignatureDocument(); if (null != document) { return document; }/*from w w w . j av a 2 s . co m*/ document = ODFUtil.getNewDocument(); Element rootElement = document.createElementNS(ODFUtil.SIGNATURE_NS, ODFUtil.SIGNATURE_ELEMENT); rootElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", ODFUtil.SIGNATURE_NS); document.appendChild(rootElement); return document; }
From source file:bpsperf.modelgen.BPMNGenerator.java
public void generateUserTaskSequence(int numNodes) throws Exception { Element start = addNode(startEvent, "startEvent"); Element utask1 = addNode(userTask, "ut1"); utask1.setAttributeNS(activitins, "candidateUsers", "kermit,admin"); connect(start, utask1);//from w w w.ja va2s .co m Element utaskS = utask1; Element utaskT = utask1; for (int i = 2; i <= numNodes; i++) { utaskT = addNode(userTask, "ut" + i); utaskT.setAttributeNS(activitins, "candidateUsers", "kermit,admin"); connect(utaskS, utaskT); utaskS = utaskT; } Element end = addNode(endEvent, "endEvent"); connect(utaskS, end); }