Example usage for org.w3c.dom Attr setValue

List of usage examples for org.w3c.dom Attr setValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr setValue.

Prototype

public void setValue(String value) throws DOMException;

Source Link

Document

On retrieval, the value of the attribute is returned as a string.

Usage

From source file:org.globus.wsrf.tools.wsdl.WSDLPreprocessor.java

private static XSModel loadSchema(Element schema, Definition def) {
    // add namespaces from definition element
    Map definitionNameSpaces = def.getNamespaces();
    Set nameSpaces = definitionNameSpaces.entrySet();
    Iterator nameSpacesIterator = nameSpaces.iterator();

    while (nameSpacesIterator.hasNext()) {
        Entry nameSpaceEntry = (Entry) nameSpacesIterator.next();
        if (!"".equals((String) nameSpaceEntry.getKey())
                && !schema.hasAttributeNS("http://www.w3.org/2000/xmlns/", (String) nameSpaceEntry.getKey())) {
            Attr nameSpace = schema.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/",
                    "xmlns:" + nameSpaceEntry.getKey());
            nameSpace.setValue((String) nameSpaceEntry.getValue());
            schema.setAttributeNode(nameSpace);
        }// w w w  .j a va 2 s  .c  o m
    }

    LSInput schemaInput = new DOMInputImpl();
    schemaInput
            .setStringData("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + XmlUtils.getElementAsString(schema));
    log.info("Loading schema in types section of definition " + def.getDocumentBaseURI());
    schemaInput.setSystemId(def.getDocumentBaseURI());
    XMLSchemaLoader schemaLoader = new XMLSchemaLoader();
    XSModel schemaModel = schemaLoader.load(schemaInput);
    log.info("Done loading");
    return schemaModel;
}

From source file:org.jboss.windup.util.xml.LocationAwareContentHandler.java

@Override
public void startElement(final String uri, final String localName, final String qName, final Attributes attrs)
        throws SAXException {
    Element e = null;/*from  w  ww. j a v a 2s. c o  m*/
    if (localName != null && !"".equals(localName)) {
        e = doc.createElementNS(uri, localName);
    } else {
        e = doc.createElement(qName);
    }

    storeLineInformation(e);
    if (StringUtils.isNotBlank(uri)) {
        namespaceURIs.add(uri);
    }

    if (doc.getUserData(NAMESPACE_KEY_NAME) == null) {
        doc.setUserData(NAMESPACE_KEY_NAME, namespaceURIs, null);
    }

    if (current == null) {
        doc.appendChild(e);
    } else {
        current.appendChild(e);
    }
    current = e;

    if (attrs != null) {
        for (int i = 0; i < attrs.getLength(); i++) {
            Attr attr = null;
            if (attrs.getLocalName(i) != null && !"".equals(attrs.getLocalName(i))) {
                attr = doc.createAttributeNS(attrs.getURI(i), attrs.getLocalName(i));
                attr.setValue(attrs.getValue(i));
                storeLineInformation(attr);
                current.setAttributeNodeNS(attr);
            } else {
                attr = doc.createAttribute(attrs.getQName(i));
                attr.setValue(attrs.getValue(i));
                storeLineInformation(attr);
                current.setAttributeNode(attr);
            }
        }
    }
}

From source file:org.jbpm.bpel.integration.soap.SoapUtil.java

public static void copyAttributes(Element target, SOAPElement source) {
    // easy way out: no attributes to copy
    if (!source.hasAttributes())
        return;/*from w  w  w.j a  v a2  s .  com*/
    // traverse attributes
    Iterator attrNameIt = source.getAllAttributes();
    while (attrNameIt.hasNext()) {
        Name attrName = (Name) attrNameIt.next();
        String namespaceURI = attrName.getURI();

        // isn't the attribute a namespace declaration?
        if (BpelConstants.NS_XMLNS.equals(namespaceURI))
            continue;

        // unqualified?
        if (namespaceURI == null || namespaceURI.length() == 0) {
            String localName = attrName.getLocalName();
            target.setAttribute(localName, source.getAttributeValue(attrName));
            if (traceEnabled)
                log.trace("set attribute: " + localName);
        }
        // qualified
        else {
            Attr attr = target.getOwnerDocument().createAttributeNS(namespaceURI, attrName.getQualifiedName());
            attr.setValue(source.getAttributeValue(attrName));
            target.setAttributeNodeNS(attr);
            XmlUtil.ensureNamespaceDeclared(attr, namespaceURI, attrName.getPrefix());
            if (traceEnabled)
                log.trace("set attribute: {" + namespaceURI + '}' + attrName.getQualifiedName());
        }
    }
}

From source file:org.jbpm.bpel.xml.util.XmlUtil.java

public static void setQNameValue(Attr attr, QName value) {
    attr.setValue(formatQName(value, attr.getOwnerElement()));
}

From source file:org.jbpm.bpel.xml.util.XmlUtil.java

public static void copyAttributes(Element target, Element source) {
    // easy way out: no attributes
    if (!source.hasAttributes())
        return;/*from  www  .ja  va2  s  . c o  m*/
    // traverse attributes
    NamedNodeMap attributes = source.getAttributes();
    for (int i = 0, n = attributes.getLength(); i < n; i++) {
        Node sourceAttr = attributes.item(i);
        String namespaceURI = sourceAttr.getNamespaceURI();
        String name = sourceAttr.getNodeName();
        // namespace declaration?
        if (BpelConstants.NS_XMLNS.equals(namespaceURI))
            continue;
        // unqualified?
        if (namespaceURI == null || namespaceURI.length() == 0) {
            target.setAttribute(name, sourceAttr.getNodeValue());
            if (traceEnabled)
                log.trace("set attribute: " + name);
        }
        // qualified
        else {
            Attr targetAttr = target.getOwnerDocument().createAttributeNS(namespaceURI, name);
            targetAttr.setValue(sourceAttr.getNodeValue());
            target.setAttributeNodeNS(targetAttr);
            ensureNamespaceDeclared(targetAttr, namespaceURI, sourceAttr.getPrefix());
            if (traceEnabled)
                log.trace("set attribute: {" + namespaceURI + '}' + name);
        }
    }
}

From source file:org.mrgeo.resources.tms.TileMapServiceResource.java

protected static Document mrsPyramidMetadataToTileMapXml(final String raster, final String url,
        final MrsPyramidMetadata mpm) throws ParserConfigurationException {
    /*/*from  w w w .j a  v  a 2 s. c o  m*/
     * String tileMap = "<?xml version='1.0' encoding='UTF-8' ?>" +
     * "<TileMap version='1.0.0' tilemapservice='http://localhost/mrgeo-services/api/tms/1.0.0'>" +
     * "  <Title>AfPk Elevation V2</Title>" + "  <Abstract>A test of V2 MrsPyramid.</Abstract>"
     * + "  <SRS>EPSG:4326</SRS>" + "  <BoundingBox minx='68' miny='33' maxx='72' maxy='35' />" +
     * "  <Origin x='68' y='33' />" +
     * "  <TileFormat width='512' height='512' mime-type='image/tiff' extension='tif' />" +
     * "  <TileSets profile='global-geodetic'>" +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/1' units-per-pixel='0.3515625' order='1' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/2' units-per-pixel='0.17578125' order='2' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/3' units-per-pixel='0.08789063' order='3' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/4' units-per-pixel='0.08789063' order='4' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/5' units-per-pixel='0.08789063' order='5' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/6' units-per-pixel='0.08789063' order='6' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/7' units-per-pixel='0.08789063' order='7' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/8' units-per-pixel='0.08789063' order='8' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/9' units-per-pixel='0.08789063' order='9' />"
     * +
     * "    <TileSet href='http://localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2/10' units-per-pixel='0.08789063' order='10' />"
     * + "  </TileSets>" + "</TileMap>";
     */

    final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

    // root elements
    final Document doc = docBuilder.newDocument();
    final Element rootElement = doc.createElement("TileMap");
    doc.appendChild(rootElement);
    final Attr v = doc.createAttribute("version");
    v.setValue(VERSION);
    rootElement.setAttributeNode(v);
    final Attr tilemapservice = doc.createAttribute("tilemapservice");
    tilemapservice.setValue(normalizeUrl(normalizeUrl(url).replace(raster, "")));
    rootElement.setAttributeNode(tilemapservice);

    // child elements
    final Element title = doc.createElement("Title");
    title.setTextContent(raster);
    rootElement.appendChild(title);

    final Element abst = doc.createElement("Abstract");
    abst.setTextContent("");
    rootElement.appendChild(abst);

    final Element srs = doc.createElement("SRS");
    srs.setTextContent(SRS);
    rootElement.appendChild(srs);

    final Element bbox = doc.createElement("BoundingBox");
    rootElement.appendChild(bbox);
    final Attr minx = doc.createAttribute("minx");
    minx.setValue(String.valueOf(mpm.getBounds().w));
    bbox.setAttributeNode(minx);
    final Attr miny = doc.createAttribute("miny");
    miny.setValue(String.valueOf(mpm.getBounds().s));
    bbox.setAttributeNode(miny);
    final Attr maxx = doc.createAttribute("maxx");
    maxx.setValue(String.valueOf(mpm.getBounds().e));
    bbox.setAttributeNode(maxx);
    final Attr maxy = doc.createAttribute("maxy");
    maxy.setValue(String.valueOf(mpm.getBounds().n));
    bbox.setAttributeNode(maxy);

    final Element origin = doc.createElement("Origin");
    rootElement.appendChild(origin);
    final Attr x = doc.createAttribute("x");
    x.setValue(String.valueOf(mpm.getBounds().w));
    origin.setAttributeNode(x);
    final Attr y = doc.createAttribute("y");
    y.setValue(String.valueOf(mpm.getBounds().s));
    origin.setAttributeNode(y);

    final Element tileformat = doc.createElement("TileFormat");
    rootElement.appendChild(tileformat);
    final Attr w = doc.createAttribute("width");
    w.setValue(String.valueOf(mpm.getTilesize()));
    tileformat.setAttributeNode(w);
    final Attr h = doc.createAttribute("height");
    h.setValue(String.valueOf(mpm.getTilesize()));
    tileformat.setAttributeNode(h);
    final Attr mt = doc.createAttribute("mime-type");
    mt.setValue("image/tiff");
    tileformat.setAttributeNode(mt);
    final Attr ext = doc.createAttribute("extension");
    ext.setValue("tif");
    tileformat.setAttributeNode(ext);

    final Element tilesets = doc.createElement("TileSets");
    rootElement.appendChild(tilesets);
    final Attr profile = doc.createAttribute("profile");
    profile.setValue("global-geodetic");
    tilesets.setAttributeNode(profile);

    for (int i = 0; i <= mpm.getMaxZoomLevel(); i++) {
        final Element tileset = doc.createElement("TileSet");
        tilesets.appendChild(tileset);
        final Attr href = doc.createAttribute("href");
        href.setValue(normalizeUrl(normalizeUrl(url)) + "/" + i);
        tileset.setAttributeNode(href);
        final Attr upp = doc.createAttribute("units-per-pixel");
        upp.setValue(String.valueOf(180d / 256d / Math.pow(2, i)));
        tileset.setAttributeNode(upp);
        final Attr order = doc.createAttribute("order");
        order.setValue(String.valueOf(i));
        tileset.setAttributeNode(order);
    }

    return doc;
}

From source file:org.mrgeo.resources.tms.TileMapServiceResource.java

protected static Document mrsPyramidToTileMapServiceXml(final String url, final List<String> pyramidNames)
        throws ParserConfigurationException, DOMException, UnsupportedEncodingException {
    /*/*  w  w w .ja  va2s .  c  o m*/
     * String tileMapService = "<?xml version='1.0' encoding='UTF-8' ?>" +
     * "<TileMapService version='1.0.0' services='http://localhost/mrgeo-services/api/tms/'>" +
     * "  <Title>Example Tile Map Service</Title>" +
     * "  <Abstract>This is a longer description of the example tiling map service.</Abstract>" +
     * "  <TileMaps>" + "    <TileMap " + "      title='AfPk Elevation V2' " +
     * "      srs='EPSG:4326' " + "      profile='global-geodetic' " +
     * "      href='http:///localhost/mrgeo-services/api/tms/1.0.0/AfPkElevationV2' />" +
     * "  </TileMaps>" + "</TileMapService>";
     */

    final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

    // root elements
    final Document doc = docBuilder.newDocument();
    final Element rootElement = doc.createElement("TileMapService");
    doc.appendChild(rootElement);
    final Attr v = doc.createAttribute("version");
    v.setValue(VERSION);
    rootElement.setAttributeNode(v);
    final Attr service = doc.createAttribute("services");
    service.setValue(normalizeUrl(normalizeUrl(url).replace(VERSION, "")));
    rootElement.setAttributeNode(service);

    // child elements
    final Element title = doc.createElement("Title");
    title.setTextContent("Tile Map Service");
    rootElement.appendChild(title);

    final Element abst = doc.createElement("Abstract");
    abst.setTextContent("MrGeo MrsPyramid rasters available as TMS");
    rootElement.appendChild(abst);

    final Element tilesets = doc.createElement("TileMaps");
    rootElement.appendChild(tilesets);

    Collections.sort(pyramidNames);
    for (final String p : pyramidNames) {
        final Element tileset = doc.createElement("TileMap");
        tilesets.appendChild(tileset);
        final Attr href = doc.createAttribute("href");
        href.setValue(normalizeUrl(url) + "/" + URLEncoder.encode(p, "UTF-8"));
        tileset.setAttributeNode(href);
        final Attr maptitle = doc.createAttribute("title");
        maptitle.setValue(p);
        tileset.setAttributeNode(maptitle);
        final Attr srs = doc.createAttribute("srs");
        srs.setValue(SRS);
        tileset.setAttributeNode(srs);
        final Attr profile = doc.createAttribute("profile");
        profile.setValue("global-geodetic");
        tileset.setAttributeNode(profile);
    }

    return doc;
}

From source file:org.mrgeo.resources.tms.TileMapServiceResource.java

protected static Document rootResourceXml(final String url) throws ParserConfigurationException {
    /*//from  ww w .j  a va  2 s  . co m
     * <?xml version="1.0" encoding="UTF-8" ?> <Services> <TileMapService
     * title="MrGeo Tile Map Service" version="1.0.0"
     * href="http://localhost:8080/mrgeo-services/api/tms/1.0.0" /> </Services>
     */

    final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    final Document doc = docBuilder.newDocument();
    final Element rootElement = doc.createElement("Services");
    doc.appendChild(rootElement);
    final Element tms = doc.createElement("TileMapService");
    rootElement.appendChild(tms);
    final Attr title = doc.createAttribute("title");
    title.setValue("MrGeo Tile Map Service");
    tms.setAttributeNode(title);
    final Attr v = doc.createAttribute("version");
    v.setValue(VERSION);
    tms.setAttributeNode(v);
    final Attr href = doc.createAttribute("href");
    href.setValue(normalizeUrl(url) + "/" + VERSION);
    tms.setAttributeNode(href);

    return doc;
}

From source file:org.openbravo.erpCommon.modules.ImportModule.java

/**
 * Adds a single classpath entry to the xml file
 */// w  w  w . j  a  va 2  s. c  o  m
private void addClassPathEntry(Document doc, String dir) throws Exception {
    log4j.info("adding entry for directory" + dir);
    final Node root = doc.getFirstChild();
    final Node classpath = doc.createElement("classpathentry");
    final NamedNodeMap cpAttributes = classpath.getAttributes();

    Attr attr = doc.createAttribute("kind");
    attr.setValue("src");
    cpAttributes.setNamedItem(attr);

    attr = doc.createAttribute("path");
    attr.setValue(dir);
    cpAttributes.setNamedItem(attr);

    root.appendChild(classpath);

}

From source file:org.opencastproject.oaipmh.util.XmlGen.java

protected Node $aSome(final String name, final Option<String> value) {
    return value.fold(new Option.Match<String, Node>() {
        @Override//from www  .  j a v  a  2s .  c  o m
        public Node some(String value) {
            Attr a = document.createAttribute(name);
            a.setValue(value);
            return a;
        }

        @Override
        public Node none() {
            return nodeZero();
        }
    });
}