Example usage for org.w3c.dom Element setAttribute

List of usage examples for org.w3c.dom Element setAttribute

Introduction

In this page you can find the example usage for org.w3c.dom Element setAttribute.

Prototype

public void setAttribute(String name, String value) throws DOMException;

Source Link

Document

Adds a new attribute.

Usage

From source file:com.nebhale.gpxconverter.StandardRouteBuilder.java

private Element gpx(Document document, String name, List<Point> points) {
    Element gpx = document.createElement("gpx");
    gpx.setAttribute("version", "1.1");
    gpx.setAttribute("creator", "gpx-converter");
    gpx.setAttribute("xmlns", "http://www.topografix.com/GPX/1/1");
    gpx.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    gpx.setAttribute("xsi:schemaLocation",
            "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd");

    gpx.appendChild(trk(document, name, points));

    return gpx;//from  ww w  .  j  a v  a 2 s .  com
}

From source file:de.erdesignerng.model.serializer.CommonAbstractXMLSerializer.java

protected void setBooleanAttribute(Element aElement, String aAttributeName, boolean aValue) {
    aElement.setAttribute(aAttributeName, aValue ? TRUE : FALSE);
}

From source file:com.mtgi.analytics.aop.config.v11.BtJdbcPersisterBeanDefinitionParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    //configure ID generator settings
    NodeList children = element.getElementsByTagNameNS("*", ELT_ID_SQL);
    if (children.getLength() == 1) {
        BeanDefinition def = builder.getRawBeanDefinition();
        MutablePropertyValues props = def.getPropertyValues();

        Element child = (Element) children.item(0);
        String sql = child.getTextContent();
        if (StringUtils.hasText(sql))
            props.addPropertyValue("idSql", sql);

        if (child.hasAttribute(ATT_INCREMENT))
            props.addPropertyValue("idIncrement", child.getAttribute(ATT_INCREMENT));
    }/*from   w w w. j a v  a 2s .co m*/

    //configure nested dataSource
    NodeList nodes = element.getElementsByTagNameNS("*", "data-source");
    if (nodes.getLength() == 1) {
        Element ds = (Element) nodes.item(0);
        ds.setAttribute("name", "dataSource");
        parserContext.getDelegate().parsePropertyElement(ds, builder.getRawBeanDefinition());
    }

    //push persister into parent manager bean, if applicable
    if (parserContext.isNested()) {
        AbstractBeanDefinition def = builder.getBeanDefinition();
        String id = element.hasAttribute("id") ? element.getAttribute("id")
                : BeanDefinitionReaderUtils.generateBeanName(def,
                        parserContext.getReaderContext().getRegistry(), true);
        BeanDefinitionHolder holder = new BeanDefinitionHolder(def, id);
        BtManagerBeanDefinitionParser.registerNestedBean(holder, "persister", parserContext);
    }
}

From source file:fr.aliasource.webmail.server.proxy.client.http.filters.AbstractFilterMethod.java

protected void appendFilterDefinition(Element p, FilterDefinition fd) {
    Element fde = p;
    if (fd.getId() != null) {
        fde.setAttribute("id", fd.getId());
    }/*from  w ww  . j a  v  a2  s  .  c o m*/
    Element crits = DOMUtils.createElement(fde, "criteria");
    for (String criterion : fd.getCriteria().keySet()) {
        Element crit = DOMUtils.createElement(crits, "crit");
        crit.setAttribute("name", criterion);
        crit.setAttribute("value", fd.getCriteria().get(criterion));
    }
    Element actions = DOMUtils.createElement(fde, "actions");
    if (fd.isDelete()) {
        DOMUtils.createElement(actions, "delete");
    }
    if (fd.isStarIt()) {
        DOMUtils.createElement(actions, "start");
    }
    if (fd.isMarkAsRead()) {
        DOMUtils.createElement(actions, "mark-as-read");
    }
    if (fd.getDeliverInto() != null) {
        DOMUtils.createElementAndText(actions, "deliver-into", fd.getDeliverInto());
    }
    if (fd.getForwardTo() != null) {
        DOMUtils.createElementAndText(actions, "forward", fd.getForwardTo());
    }
}

From source file:fr.aliasource.webmail.attachments.AttachmentsMetadataAction.java

public void execute(IProxy p, IParameterSource req, IResponder responder) {
    Document doc = null;/*from w w w . ja v a 2  s  .  c  o  m*/
    String[] ids = req.getParameter("ids").split(",");
    logger.info("fetching metadata for " + ids.length + " attachments. (" + req.getParameter("ids") + ")");

    AttachmentManager mgr = p.getAccount().getAttachementManager();

    try {
        doc = DOMUtils.createDoc("http://minig.org/xsd/attachMetadatas", "attachmentId");
        Element root = doc.getDocumentElement();

        for (String id : ids) {
            logger.info("Going to load metadata for '" + id + "'");
            Map<String, String> meta = mgr.getMetadata(id);
            Element att = DOMUtils.createElement(root, "att");
            att.setAttribute(AttachmentManager.META_FILENAME, meta.get(AttachmentManager.META_FILENAME));
            att.setAttribute(AttachmentManager.META_SIZE, meta.get(AttachmentManager.META_SIZE));
            att.setAttribute(AttachmentManager.META_MIME, meta.get(AttachmentManager.META_MIME));
            att.setAttribute(AttachmentManager.META_PREVIEW, "" + mgr.hasPreview(id));
            if (meta.containsKey(AttachmentManager.META_PREVIEW_MIME)) {
                att.setAttribute(AttachmentManager.META_PREVIEW_MIME,
                        meta.get(AttachmentManager.META_PREVIEW_MIME));
            }
        }

        responder.sendDom(doc);
    } catch (Exception e) {
        logger.error("Error allocating attachment id", e);
    }
}

From source file:de.erdesignerng.model.serializer.xml20.XMLIndexSerializer.java

@Override
public void serialize(Index aIndex, Document aDocument, Element aRootElement) {
    Element theIndexElement = addElement(aDocument, aRootElement, INDEX);

    theIndexElement.setAttribute(INDEXTYPE, aIndex.getIndexType().toString());

    serializeProperties(aDocument, theIndexElement, aIndex);

    // Attribute/* www.j ava 2  s  .c o  m*/
    for (IndexExpression theExpression : aIndex.getExpressions()) {
        Element theAttributeElement = addElement(aDocument, theIndexElement, INDEXATTRIBUTE);
        theAttributeElement.setAttribute(ID, theExpression.getSystemId());
        if (!StringUtils.isEmpty(theExpression.getExpression())) {
            theAttributeElement.setAttribute(ATTRIBUTEEXPRESSION, theExpression.getExpression());
        } else {
            theAttributeElement.setAttribute(ATTRIBUTEREFID, theExpression.getAttributeRef().getSystemId());
        }
    }

}

From source file:net.sf.jabref.logic.mods.MODSDatabase.java

public Document getDOMrepresentation() {
    Document result = null;// w  ww .  ja  va 2  s .c  o m
    try {
        DocumentBuilder dbuild = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        result = dbuild.newDocument();
        Element modsCollection = result.createElement("modsCollection");
        modsCollection.setAttribute("xmlns", "http://www.loc.gov/mods/v3");
        modsCollection.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
        modsCollection.setAttribute("xsi:schemaLocation",
                "http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-0.xsd");

        for (MODSEntry entry : entries) {
            Node node = entry.getDOMrepresentation(result);
            modsCollection.appendChild(node);
        }

        result.appendChild(modsCollection);
    } catch (Exception e) {
        LOGGER.info("Could not get DOM representation", e);
    }
    return result;
}

From source file:de.codesourcery.eve.skills.calendar.impl.PlaintextPayloadType.java

@Override
public void storePayload(Document document, Element parent, ICalendarEntry entry) {
    final PlaintextPayload payload = (PlaintextPayload) entry.getPayload();

    final Element node = document.createElement("plaintext");
    parent.appendChild(node);/*from   w w  w.  jav a  2 s  . co  m*/

    node.setAttribute("summary", payload.getSummary());
    node.appendChild(document.createTextNode(payload.getNotes()));
}

From source file:de.ingrid.interfaces.csw.harvest.ibus.DefaultIdfRecordPreProcessor.java

@Override
public void process(Record record) {
    if (record.containsKey(IBusHarvester.PLUGDESCRIPTION)) {
        PlugDescription pd = (PlugDescription) record.get(IBusHarvester.PLUGDESCRIPTION);
        try {//from  ww w . ja  va  2 s  . c  o  m
            Document idfDoc = StringUtils.stringToDocument(IdfTool.getIdfDataFromRecord(record));
            Element htmlNode = (Element) xpath.getNode(idfDoc, "//idf:html");
            htmlNode.setAttribute("partner", StringUtils.join(pd.getPartners(), ","));
            htmlNode.setAttribute("provider", StringUtils.join(pd.getProviders(), ","));
            htmlNode.setAttribute("iplug", pd.getProxyServiceURL());
            record.put(IdfTool.KEY_DATA, StringUtils.nodeToString(idfDoc.getDocumentElement()));
            record.remove(IdfTool.KEY_COMPRESSED);
        } catch (Exception e) {
            log.error("Error manipulating idf record.", e);
        }
    }

}

From source file:ro.bmocanu.tests.ws.springws.server.ProductServiceDomPayloadEndpoint.java

/**
 * {@inheritDoc}//from  w  ww .  j a v  a2s. c om
 */
@Override
protected Element invokeInternal(Element requestElement, Document responseDocument) throws Exception {
    NodeList nodeList = requestElement.getChildNodes();
    String requestText = nodeList.item(1).getTextContent();
    long id = Long.parseLong(requestText);
    System.out.println("Client asked for product with ID=" + id);

    Product product = ProductManager.singleInstance.getProductById(id);

    Element responseElement = responseDocument.createElementNS("http://test.ro/product-service",
            "GetProductByIdResponse");
    Element productElement = responseDocument.createElementNS("http://test.ro/product-service", "Product");
    productElement.setAttribute("id", product.getId() + "");
    productElement.setAttribute("name", product.getName());
    productElement.setAttribute("descriptions", product.getDescription());
    productElement.setAttribute("received", product.getReceived().toString());

    responseElement.appendChild(productElement);

    return responseElement;
}