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.nridge.core.base.std.XMLUtl.java

public static void setAttrDoubleValue(Element anElement, String aName, double aValue) {
    Double doubleObject;//from  w w  w.j  a  v  a 2  s . co  m

    if (StringUtils.isNotEmpty(aName)) {
        doubleObject = aValue;
        anElement.setAttribute(aName, doubleObject.toString());
    }
}

From source file:at.gv.egovernment.moa.id.util.client.mis.simple.MISSimpleClient.java

private static Element packIntoSOAP(Element element) throws MISSimpleClientException {
    try {// w ww. j a  v a  2  s.co  m
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element soapEnvelope = doc.createElement("Envelope");
        soapEnvelope.setAttribute("xmlns", SOAP_NS);
        Element soapBody = doc.createElement("Body");
        soapEnvelope.appendChild(soapBody);
        soapBody.appendChild(doc.importNode(element, true));
        return soapEnvelope;
    } catch (ParserConfigurationException e) {
        throw new MISSimpleClientException("service.06", e);
    }
}

From source file:com.icesoft.faces.renderkit.dom_html_basic.FormRenderer.java

/**
 * @param uiComponent//from  w  w w .j  ava2s.  c o  m
 * @param facesContext
 * @param map
 */
private static void renderRequiredCommandLinkHiddenFields(UIComponent uiComponent, FacesContext facesContext,
        Map map) {
    DOMContext domContext = DOMContext.getDOMContext(facesContext, uiComponent);
    Element root = (Element) domContext.getRootNode();
    Element hiddenFieldsDiv = domContext.createElement(HTML.DIV_ELEM);
    hiddenFieldsDiv.setAttribute(HTML.ID_ATTR, uiComponent.getClientId(facesContext) + "hdnFldsDiv");
    hiddenFieldsDiv.setAttribute(HTML.STYLE_ATTR, "display:none;");
    root.appendChild(hiddenFieldsDiv);

    Iterator commandLinkFields = map.entrySet().iterator();
    while (commandLinkFields.hasNext()) {
        Map.Entry nextField = (Map.Entry) commandLinkFields.next();
        if (COMMAND_LINK_HIDDEN_FIELD.equals(nextField.getValue())) {
            Element next = domContext.createElement("input");
            next.setAttribute("type", "hidden");
            next.setAttribute("name", nextField.getKey().toString());
            hiddenFieldsDiv.appendChild(next);
        }
    }
}

From source file:com.googlecode.jgenhtml.JGenHtmlUtils.java

public static void setGlobalRootAttributes(final Element root, final String testName) {
    root.setAttribute("testname", testName);
    root.setAttribute("date", getDate());
    root.setAttribute("version", JGenHtml.VERSION);
}

From source file:com.photon.phresco.impl.WindowsApplicationProcessor.java

private static void updateContent(Document doc, List<ArtifactGroup> artifactGroups, List<Node> itemGroup,
        String elementName) {/*  w  ww .j a va 2  s . c om*/
    for (Node node : itemGroup) {
        NodeList childNodes = node.getChildNodes();
        for (int j = 0; j < childNodes.getLength(); j++) {
            Node item = childNodes.item(j);
            if (item.getNodeName().equals(elementName)) {
                Node parentNode = item.getParentNode();
                for (ArtifactGroup artifactGroup : artifactGroups) {
                    if (artifactGroup.getType().name().equals(Type.FEATURE.name())) {
                        Element content = doc.createElement(elementName);
                        if (elementName.equalsIgnoreCase(REFERENCE)) {
                            content.setAttribute(INCLUDE, artifactGroup.getName() + DLL);
                            Element hintPath = doc.createElement(HINTPATH);
                            hintPath.setTextContent(
                                    DOUBLE_DOT + COMMON + File.separator + artifactGroup.getName() + DLL);
                            content.appendChild(hintPath);
                        } else {
                            content.setAttribute(INCLUDE, artifactGroup.getName() + DLL);
                        }
                        parentNode.appendChild(content);
                    }
                }
                break;
            }
        }
    }
}

From source file:com.twinsoft.convertigo.engine.util.CarUtils.java

private static Document exportProject(Project project, final List<TestCase> selectedTestCases)
        throws EngineException {
    try {//from w w  w  .ja v  a 2s . c o  m
        final Document document = XMLUtils.getDefaultDocumentBuilder().newDocument();
        //            ProcessingInstruction pi = document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
        //            document.appendChild(pi);
        final Element rootElement = document.createElement("convertigo");

        rootElement.setAttribute("version", com.twinsoft.convertigo.engine.Version.fullProductVersion);
        rootElement.setAttribute("engine", com.twinsoft.convertigo.engine.Version.version);
        rootElement.setAttribute("beans", com.twinsoft.convertigo.beans.Version.version);
        String studioVersion = "";
        try {
            Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.Version");
            studioVersion = (String) c.getDeclaredField("version").get(null);
        } catch (Exception e) {
        } catch (Throwable th) {
        }

        rootElement.setAttribute("studio", studioVersion);
        document.appendChild(rootElement);

        new WalkHelper() {
            protected Element parentElement = rootElement;

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                Element parentElement = this.parentElement;

                Element element = parentElement;
                element = databaseObject.toXml(document);
                String name = " : " + databaseObject.getName();
                try {
                    name = CachedIntrospector.getBeanInfo(databaseObject.getClass()).getBeanDescriptor()
                            .getDisplayName() + name;
                } catch (IntrospectionException e) {
                    name = databaseObject.getClass().getSimpleName() + name;
                }
                Integer depth = (Integer) document.getUserData("depth");
                if (depth == null) {
                    depth = 0;
                }

                String openpad = StringUtils.repeat("   ", depth);
                String closepad = StringUtils.repeat("   ", depth);
                parentElement.appendChild(document.createTextNode("\n"));
                parentElement.appendChild(
                        document.createComment(StringUtils.rightPad(openpad + "<" + name + ">", 150)));

                if (databaseObject instanceof TestCase && selectedTestCases.size() > 0) {
                    if (selectedTestCases.contains((TestCase) databaseObject)) {
                        parentElement.appendChild(element);
                    }
                } else {
                    parentElement.appendChild(element);
                }

                document.setUserData("depth", depth + 1, null);

                this.parentElement = element;
                super.walk(databaseObject);

                element.appendChild(document.createTextNode("\n"));
                element.appendChild(
                        document.createComment(StringUtils.rightPad(closepad + "</" + name + ">", 150)));
                document.setUserData("depth", depth, null);

                databaseObject.hasChanged = false;
                databaseObject.bNew = false;

                this.parentElement = parentElement;
            }

        }.init(project);

        return document;
    } catch (Exception e) {
        throw new EngineException("Unable to export the project \"" + project.getName() + "\".", e);
    }
}

From source file:com.googlecode.jgenhtml.JGenHtmlUtils.java

public static Element getHitElement(final Document document, final String name, final int hits) {
    Element result = document.createElement("hit");
    result.setAttribute("name", name);
    result.setAttribute("count", String.valueOf(hits));
    return result;
}

From source file:XMLUtils.java

public static void replaceAttribute(Element element, String attr, String value) {
    if (element.hasAttribute(attr)) {
        element.removeAttribute(attr);//from  w ww.  j  a  va  2 s.  co  m
    }
    element.setAttribute(attr, value);
}

From source file:Main.java

/**
 *
 * @param element/*  w w  w .  ja  v a2 s .  c o m*/
 * @param attributeName
 * @param sequence
 * @param matches
 * @return
 */
private static int addAttributeLoopElement(Element element, String attributeName, int sequence,
        String... matches) {

    int seqNo = sequence;
    if (matches(element.getTagName(), matches)) {
        String seq = "00000000000000000000" + seqNo++;
        seq = seq.substring(seq.length() - 20);
        element.setAttribute(attributeName, attributeName + "_" + seq);
    }
    NodeList nodeList = element.getChildNodes();
    int length = nodeList.getLength();
    for (int seq = 0; seq < length; seq++) {
        Node node = nodeList.item(seq);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            seqNo = addAttributeLoopElement((Element) node, attributeName, seqNo, matches);
        }
    }

    return seqNo;
}

From source file:importer.handler.post.stages.Discriminator.java

/**
 * Add a new version to the current element
 * @param elem the element to add the new version to
 * @param wits the new version//from w  ww  .j a v  a2s  . c  o m
 */
static void addVersion(Element elem, String wits) {
    if (elem.hasAttribute(Splitter.VERSIONS))
        elem.setAttribute(Splitter.VERSIONS, mergeVersions(elem.getAttribute(Splitter.VERSIONS), wits));
    else
        elem.setAttribute(Splitter.VERSIONS, wits);
}