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.bstek.dorado.idesupport.robot.EntityDataTypeReflectionRobot.java

private Element createPropertyElement(Element parentElement, String propertyName) {
    Document document = parentElement.getOwnerDocument();
    Element propertyElement = document.createElement("Property");
    propertyElement.setAttribute(XmlConstants.ATTRIBUTE_NAME, propertyName);
    parentElement.appendChild(propertyElement);
    return propertyElement;
}

From source file:no.dusken.barweb.view.XListView.java

private Document generateXml(List<BarPerson> barPersons, Gjeng gjeng, List<Vare> varer, int lowlimit,
        Boolean panger) {//w  ww .ja v  a  2 s  .c  o m
    Document dom = null;
    //get an instance of factory
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
        //get an instance of builder
        DocumentBuilder db = dbf.newDocumentBuilder();

        //create an instance of DOM
        dom = db.newDocument();

    } catch (ParserConfigurationException pce) {
        log.error("Error when generating x-list");
    }
    Element root = dom.createElement("xlist");
    root.setAttribute("gjeng", gjeng.getName());
    SimpleDateFormat dateformat = new SimpleDateFormat("d. MMMMMMMMM yyyy - HH:mm", new Locale("no"));
    root.setAttribute("generated", dateformat.format((new GregorianCalendar()).getTime()));
    root.setAttribute("magicNumber", String.valueOf(((new Random()).nextDouble() * 1000)));
    root.setAttribute("panger", panger.toString());
    dom.appendChild(root);
    Element personsEle = dom.createElement("barPersons");

    for (BarPerson p : barPersons) {
        Element personEle = createPersonElement(p, dom, lowlimit);
        personsEle.appendChild(personEle);
    }

    root.appendChild(personsEle);

    Element vareEle = dom.createElement("varer");

    for (Vare v : varer) {
        Element vare = createVareElement(v, dom);
        vareEle.appendChild(vare);
    }
    root.appendChild(vareEle);

    return dom;
}

From source file:com.codebutler.farebot.card.Card.java

public Element toXML() throws Exception {
    try {/*  w  w w .  j a  v a2 s  .  c o m*/
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.newDocument();

        Element element = doc.createElement("card");
        element.setAttribute("type", String.valueOf(getCardType().toInteger()));
        element.setAttribute("id", Utils.getHexString(mTagId, null));
        element.setAttribute("scanned_at", Long.toString(mScannedAt.getTime()));
        doc.appendChild(element);

        return doc.getDocumentElement();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.spearal.spring.rest.xml.SpearalRestBeanDefinitionParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    if ("".equals(element.getAttribute(ID_ATTRIBUTE)))
        element.setAttribute(ID_ATTRIBUTE, SpearalRestConfigurator.class.getName());

    if (!parserContext.getRegistry().containsBeanDefinition(SpearalMessageConverter.class.getName())) {
        BeanDefinitionBuilder messageConverterBuilder = BeanDefinitionBuilder
                .genericBeanDefinition(SpearalMessageConverter.class);
        messageConverterBuilder.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
        registerInfrastructureComponent(element, parserContext, messageConverterBuilder,
                SpearalMessageConverter.class.getName());
    }/*from ww w  .j  av  a 2  s  .com*/

    if (!parserContext.getRegistry().containsBeanDefinition(SpearalResponseBodyAdvice.class.getName())) {
        BeanDefinitionBuilder responseBodyAdviceBuilder = BeanDefinitionBuilder
                .genericBeanDefinition(SpearalResponseBodyAdvice.class);
        responseBodyAdviceBuilder.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
        registerInfrastructureComponent(element, parserContext, responseBodyAdviceBuilder,
                SpearalResponseBodyAdvice.class.getName());
    }
}

From source file:de.pixida.logtest.reporting.XUnitReportGenerator.java

private void addProperties(final Document doc, final Element rootElement) {
    final Element properties = doc.createElement("properties");
    for (final Object property : System.getProperties().keySet()) {
        final String key = property.toString();
        final String value = System.getProperty(key);
        final Element element = doc.createElement("property");
        element.setAttribute("name", key);
        element.setAttribute("value", value);
        properties.appendChild(element);
    }//w ww  . j a v  a 2 s .c  om
    rootElement.appendChild(properties);
}

From source file:com.stratio.decision.service.SolrOperationsService.java

public void createSolrSchema(List<ColumnNameTypeValue> columns, String confpath)
        throws ParserConfigurationException, URISyntaxException, IOException, SAXException,
        TransformerException {//w w w  .j a v a 2  s .  c o m
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setIgnoringComments(true);
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    Document doc = builder.parse(new File(ClassLoader.getSystemResource("./solr-config/schema.xml").toURI()));
    NodeList nodes = doc.getElementsByTagName("schema");
    for (ColumnNameTypeValue column : columns) {
        Element field = doc.createElement("field");
        field.setAttribute("name", column.getColumn());
        field.setAttribute("type", streamingToSolr(column.getType()));
        field.setAttribute("indexed", "true");
        field.setAttribute("stored", "true");
        nodes.item(0).appendChild(field);
    }
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    DOMSource source = new DOMSource(doc);
    StreamResult streamResult = new StreamResult(new File(confpath + "/schema.xml"));
    transformer.transform(source, streamResult);
}

From source file:com.cburch.logisim.circuit.appear.AppearancePort.java

@Override
public Element toSvgElement(Document doc) {
    Location loc = getLocation();
    Location pinLoc = pin.getLocation();
    Element ret = doc.createElement("circ-port");
    int r = isInput() ? INPUT_RADIUS : OUTPUT_RADIUS;
    ret.setAttribute("x", "" + (loc.getX() - r));
    ret.setAttribute("y", "" + (loc.getY() - r));
    ret.setAttribute("width", "" + 2 * r);
    ret.setAttribute("height", "" + 2 * r);
    ret.setAttribute("pin", "" + pinLoc.getX() + "," + pinLoc.getY());
    return ret;/*  w w  w . ja  v  a2 s. co m*/
}

From source file:au.gov.ga.earthsci.bookmark.properties.layer.LayersPropertyPersister.java

@Override
public void exportToXML(IBookmarkProperty property, Element parent) {
    if (property == null) {
        return;//from  w  ww  .ja  v a2  s.c  om
    }
    Validate.isTrue(property.getType().equals(LayersProperty.TYPE), INVALID_TYPE_MSG);
    Validate.notNull(parent, "A property element is required"); //$NON-NLS-1$

    Element layerStateElement = XMLUtil.appendElement(parent, "layerState"); //$NON-NLS-1$

    for (Entry<String, Map<String, String>> layerInfo : ((LayersProperty) property).getLayerStateInfo()
            .entrySet()) {
        Element state = XMLUtil.appendElement(layerStateElement, LAYER_ELEMENT_NAME);
        state.setAttribute(ID_ATTRIBUTE_NAME, layerInfo.getKey());
        for (Entry<String, String> stateInfo : layerInfo.getValue().entrySet()) {
            state.setAttribute(stateInfo.getKey(), stateInfo.getValue());
        }

    }

    //      for (Entry<String, Double> e : ((LayersProperty) property).getLayerState().entrySet())
    //      {
    //         Element state = XMLUtil.appendElement(layerStateElement, LAYER_ELEMENT_NAME);
    //         state.setAttribute(ID_ATTRIBUTE_NAME, e.getKey());
    //         state.setAttribute(OPACITY_ATTRIBUTE_NAME, Double.toString(e.getValue()));
    //      }
}

From source file:com.connexta.arbitro.utils.PolicyUtils.java

/**
 * This creates XML representation of attribute designator Element using AttributeDesignatorDTO object
 *
 * @param attributeDesignatorDTO  AttributeDesignatorDTO
 * @param doc Document//from   w w  w  .j  a v  a2  s . c o  m
 * @return DOM element
 * @throws PolicyBuilderException throws
 */
public static Element createAttributeDesignatorElement(AttributeDesignatorDTO attributeDesignatorDTO,
        Document doc) throws PolicyBuilderException {

    String attributeDesignatorElementName = PolicyConstants.ATTRIBUTE_DESIGNATOR;

    Element attributeDesignatorElement = doc.createElement(attributeDesignatorElementName);

    String attributeId = attributeDesignatorDTO.getAttributeId();
    String category = attributeDesignatorDTO.getCategory();

    if (attributeId != null && attributeId.trim().length() > 0 && category != null
            && category.trim().length() > 0) {

        attributeDesignatorElement.setAttribute(PolicyConstants.ATTRIBUTE_ID,
                attributeDesignatorDTO.getAttributeId());

        attributeDesignatorElement.setAttribute(PolicyConstants.CATEGORY, attributeDesignatorDTO.getCategory());

        if (attributeDesignatorDTO.getDataType() != null
                && attributeDesignatorDTO.getDataType().trim().length() > 0) {
            attributeDesignatorElement.setAttribute(PolicyConstants.DATA_TYPE,
                    attributeDesignatorDTO.getDataType());
        } else {
            attributeDesignatorElement.setAttribute(PolicyConstants.DATA_TYPE,
                    PolicyConstants.STRING_DATA_TYPE);
        }

        if (attributeDesignatorDTO.getIssuer() != null
                && attributeDesignatorDTO.getIssuer().trim().length() > 0) {
            attributeDesignatorElement.setAttribute(PolicyConstants.ISSUER, attributeDesignatorDTO.getIssuer());
        }

        if (attributeDesignatorDTO.getMustBePresent() != null
                && attributeDesignatorDTO.getMustBePresent().trim().length() > 0) {
            attributeDesignatorElement.setAttribute(PolicyConstants.MUST_BE_PRESENT,
                    attributeDesignatorDTO.getMustBePresent());
        } else {
            attributeDesignatorElement.setAttribute(PolicyConstants.MUST_BE_PRESENT, "true");
        }
    } else {
        throw new PolicyBuilderException("Category  name can not be null"); // TODO
    }

    return attributeDesignatorElement;
}

From source file:no.dusken.barweb.view.InvoiceView.java

private Element createPersonElement(BarPerson p, Integer owes, Document dom) {
    Element personEle = dom.createElement("person");
    personEle.setTextContent(p.getName());
    personEle.setAttribute("owes", owes.toString());
    return personEle;
}