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.mirth.connect.server.servlets.WebStartServlet.java

private Document getExtensionJnlp(String extensionPath) throws Exception {
    List<MetaData> allExtensions = new ArrayList<MetaData>();
    allExtensions/*from   w w  w.ja v  a  2  s.  c  o m*/
            .addAll(ControllerFactory.getFactory().createExtensionController().getConnectorMetaData().values());
    allExtensions
            .addAll(ControllerFactory.getFactory().createExtensionController().getPluginMetaData().values());
    Set<String> librariesToAddToJnlp = new HashSet<String>();
    List<String> extensionsWithThePath = new ArrayList<String>();

    for (MetaData metaData : allExtensions) {
        if (metaData.getPath().equals(extensionPath)) {
            extensionsWithThePath.add(metaData.getName());

            for (ExtensionLibrary library : metaData.getLibraries()) {
                if (library.getType().equals(ExtensionLibrary.Type.CLIENT)
                        || library.getType().equals(ExtensionLibrary.Type.SHARED)) {
                    librariesToAddToJnlp.add(library.getPath());
                }
            }
        }
    }

    if (extensionsWithThePath.isEmpty()) {
        throw new Exception("Extension metadata could not be located for the path: " + extensionPath);
    }

    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    Element jnlpElement = document.createElement("jnlp");

    Element informationElement = document.createElement("information");

    Element titleElement = document.createElement("title");
    titleElement
            .setTextContent("Mirth Connect Extension - [" + StringUtils.join(extensionsWithThePath, ",") + "]");
    informationElement.appendChild(titleElement);

    Element vendorElement = document.createElement("vendor");
    vendorElement.setTextContent("Mirth Corporation");
    informationElement.appendChild(vendorElement);

    jnlpElement.appendChild(informationElement);

    Element securityElement = document.createElement("security");
    securityElement.appendChild(document.createElement("all-permissions"));
    jnlpElement.appendChild(securityElement);

    Element resourcesElement = document.createElement("resources");

    for (String library : librariesToAddToJnlp) {
        Element jarElement = document.createElement("jar");
        jarElement.setAttribute("download", "eager");
        // this path is relative to the servlet path
        jarElement.setAttribute("href", "libs/" + extensionPath + "/" + library);
        resourcesElement.appendChild(jarElement);
    }

    jnlpElement.appendChild(resourcesElement);
    jnlpElement.appendChild(document.createElement("component-desc"));
    document.appendChild(jnlpElement);
    return document;
}

From source file:com.collabnet.ccf.core.recovery.HospitalArtifactReplayer.java

private void addGAImportComponents(Document document, Element routerElement) {
    NodeList propertyNodes = routerElement.getElementsByTagName("map");
    Element mapElement = (Element) propertyNodes.item(0);
    Element fileReaderEntry = document.createElement("entry");
    fileReaderEntry.setAttribute("key-ref", "FileReader");
    fileReaderEntry.setAttribute("value-ref", "GenericArtifactMultiLineParser");
    Element gaParserEntry = document.createElement("entry");
    gaParserEntry.setAttribute("key-ref", "GenericArtifactMultiLineParser");
    gaParserEntry.setAttribute("value-ref", entry.getSourceComponent());
    mapElement.appendChild(fileReaderEntry);
    mapElement.appendChild(gaParserEntry);

    Element documentElement = document.getDocumentElement();
    Element fileReaderElement = document.createElement("bean");
    fileReaderElement.setAttribute("id", "FileReader");
    fileReaderElement.setAttribute("class",
            "org.openadaptor.auxil.connector.iostream.reader.FileReadConnector");
    Element fileProperty = document.createElement("property");
    fileProperty.setAttribute("name", "filename");
    fileProperty.setAttribute("value", entry.getDataFile().getAbsolutePath());
    fileReaderElement.appendChild(fileProperty);
    documentElement.appendChild(fileReaderElement);

    Element gaParserElement = document.createElement("bean");
    gaParserElement.setAttribute("id", "GenericArtifactMultiLineParser");
    gaParserElement.setAttribute("class", "com.collabnet.ccf.core.utils.GenericArtifactMultiLineParser");

    documentElement.appendChild(gaParserElement);

    NodeList allBeans = document.getElementsByTagName("bean");
    String exceptionProcessorComponentName = null;
    for (int i = 0; i < allBeans.getLength(); i++) {
        Node beanNode = allBeans.item(i);
        NamedNodeMap atts = beanNode.getAttributes();
        Node beanIdNode = atts.getNamedItem("id");
        String beanId = beanIdNode.getNodeValue();
        // FIXME What happens if the router component is not called router
        if (beanId.equals("Router")) {
            NodeList routerPropertyNodes = ((Element) beanNode).getElementsByTagName("property");
            for (int j = 0; j < routerPropertyNodes.getLength(); j++) {
                Node propNode = routerPropertyNodes.item(j);
                NamedNodeMap routerPropAtts = propNode.getAttributes();
                Node nameNode = routerPropAtts.getNamedItem("name");
                String routerProperty = nameNode.getNodeValue();
                if (routerProperty.equals("exceptionProcessor")) {
                    Node expProcessorNode = routerPropAtts.getNamedItem("ref");
                    exceptionProcessorComponentName = expProcessorNode.getNodeValue();
                }/*from   ww w  . ja  va 2 s  .  c o m*/
            }
        } else if (beanId.equals(exceptionProcessorComponentName)) {
            NodeList exceptionPropertyNodes = ((Element) beanNode).getElementsByTagName("property");
            for (int j = 0; j < exceptionPropertyNodes.getLength(); j++) {
                Node propertyNode = exceptionPropertyNodes.item(j);
                NamedNodeMap excepPropAtts = propertyNode.getAttributes();
                Node nameNode = excepPropAtts.getNamedItem("name");
                String propertyName = nameNode.getNodeValue();
                if (propertyName.equals("hospitalFileName")) {
                    Node valueNode = excepPropAtts.getNamedItem("value");
                    valueNode.setNodeValue(replayWorkDir.getAbsolutePath() + File.separator + "hospital.txt");
                } else if (propertyName.equals("artifactsDirectory")) {
                    Node valueNode = excepPropAtts.getNamedItem("value");
                    valueNode.setNodeValue(replayWorkDir.getAbsolutePath() + File.separator + "artifacts");
                }
            }
        }
    }
}

From source file:com.codebutler.farebot.card.felica.FelicaCard.java

@Override
public Element toXML() throws Exception {
    Element root = super.toXML();

    Document doc = root.getOwnerDocument();

    Element idmElement = doc.createElement("idm");
    idmElement.setTextContent(Base64.encodeToString(mIDm.getBytes(), Base64.DEFAULT));
    root.appendChild(idmElement);/*from   ww  w .  j av a2 s. c  o m*/

    Element pmmElement = doc.createElement("pmm");
    pmmElement.setTextContent(Base64.encodeToString(mPMm.getBytes(), Base64.DEFAULT));
    root.appendChild(pmmElement);

    Element systemsElement = doc.createElement("systems");

    for (FelicaSystem system : mSystems) {
        Element systemElement = doc.createElement("system");
        systemElement.setAttribute("code", String.valueOf(system.getCode()));

        Element servicesElement = doc.createElement("services");
        for (FelicaService service : system.getServices()) {
            Element serviceElement = doc.createElement("service");
            serviceElement.setAttribute("code", String.valueOf(service.getServiceCode()));

            Element blocksElement = doc.createElement("blocks");
            for (FelicaBlock block : service.getBlocks()) {
                Element blockElement = doc.createElement("block");
                blockElement.setAttribute("address", String.valueOf(block.getAddress()));
                blockElement.setTextContent(Base64.encodeToString(block.getData(), Base64.DEFAULT));

                blocksElement.appendChild(blockElement);
            }

            serviceElement.appendChild(blocksElement);

            servicesElement.appendChild(serviceElement);
        }

        systemElement.appendChild(servicesElement);

        systemsElement.appendChild(systemElement);
    }

    root.appendChild(systemsElement);

    return root;
}

From source file:net.sourceforge.fullsync.fs.connection.SyncFileBufferedConnection.java

protected Element serializeFile(BufferedFile file, Document doc) throws IOException {
    Element elem = doc.createElement(file.isDirectory() ? ELEMENT_DIRECTORY : ELEMENT_FILE);
    elem.setAttribute(ATTRIBUTE_NAME, file.getName());
    if (file.isDirectory()) {
        for (File n : file.getChildren()) {
            if (n.exists()) {
                elem.appendChild(serializeFile((BufferedFile) n, doc));
            }// w ww  . ja va  2s.  c o  m
        }
    } else {
        elem.setAttribute(ATTRIBUTE_BUFFERED_LENGTH, String.valueOf(file.getSize()));
        elem.setAttribute(ATTRIBUTE_BUFFERED_LAST_MODIFIED, String.valueOf(file.getLastModified()));
        elem.setAttribute(ATTRIBUTE_FILE_SYSTEM_LENGTH, String.valueOf(file.getFsSize()));
        elem.setAttribute(ATTRIBUTE_FILE_SYSTEM_LAST_MODIFIED, String.valueOf(file.getFsLastModified()));
    }
    return elem;
}

From source file:es.juntadeandalucia.panelGestion.negocio.utiles.geosearch.GeosearchDataImportWriter.java

private Element generateField(GeosearchFieldVO field, Node document, String geomFieldName) {
    String column = field.getNameOnTable();
    String name = Utils.getFieldName(field);

    // uses the geometric field name as column name
    if ((geomFieldName != null) && geomFieldName.equals(column)) {
        column = name;//from  www  . ja v  a 2s. c  om
    }

    Element fieldElement = document.getOwnerDocument().createElement("field");
    fieldElement.setAttribute("column", column);
    fieldElement.setAttribute("name", name);

    return fieldElement;
}

From source file:Exporters.SaveFileExporter.java

public Element getVulnAsElement(Vulnerability vuln, Document doc) {

    Base64 b64 = new Base64();

    Element vulnElement = doc.createElement("vuln");
    if (vuln.isIs_custom_risk() == false) {
        vulnElement.setAttribute("custom-risk", "false");
        vulnElement.setAttribute("cvss", vuln.getCvss_vector_string());
    } else {/*from   w  ww . jav a  2 s.  c o m*/
        vulnElement.setAttribute("custom-risk", "true");
    }
    vulnElement.setAttribute("category", vuln.getRisk_category());
    vulnElement.setAttribute("risk-score", "" + vuln.getRiskScore());

    Element vulnTitle = doc.createElement("title");
    vulnTitle.appendChild(doc.createTextNode(b64.encodeAsString(vuln.getTitle().getBytes())));

    Element identifiersElement = doc.createElement("identifiers");
    HashMap identifiersMap = vuln.getIdentifiers();
    Iterator it = identifiersMap.keySet().iterator();
    while (it.hasNext()) {
        String hashed_title = (String) it.next();
        String import_tool = (String) identifiersMap.get(hashed_title);
        // add a tag mofo!
        Element identifier = doc.createElement("identifier");
        identifier.setAttribute("hash", hashed_title);
        identifier.setAttribute("import_tool", import_tool);
        identifiersElement.appendChild(identifier);
    }

    Element vulnDescription = doc.createElement("description");
    vulnDescription.appendChild(doc.createTextNode(b64.encodeAsString(vuln.getDescription().getBytes())));

    Element vulnRecommendation = doc.createElement("recommendation");
    vulnRecommendation.appendChild(doc.createTextNode(b64.encodeAsString(vuln.getRecommendation().getBytes())));

    //TODO Fill out <References> tag
    Element vulnReferences = doc.createElement("references");
    Enumeration refs_enums = vuln.getReferences().elements();
    while (refs_enums.hasMoreElements()) {
        Reference ref = (Reference) refs_enums.nextElement();
        Element vulnReference = doc.createElement("reference");
        vulnReference.setAttribute("description", ref.getDescription());
        vulnReference.appendChild(doc.createTextNode(ref.getUrl()));
        vulnReferences.appendChild(vulnReference);
    }

    Element affectedHosts = doc.createElement("affected-hosts");
    Enumeration enums = vuln.getAffectedHosts().elements();
    while (enums.hasMoreElements()) {
        Host host = (Host) enums.nextElement();

        // Create all the lovely element nodes
        Element affectedHost = doc.createElement("host");
        Element ipAddress = doc.createElement("ip-address");
        if (host.getIp_address() != null) {
            ipAddress.appendChild(doc.createTextNode(host.getIp_address()));
        }
        Element hostname = doc.createElement("hostname");
        if (host.getHostname() != null) {
            hostname.appendChild(doc.createTextNode(host.getHostname()));
        }
        Element netbios = doc.createElement("netbios-name");
        if (host.getNetbios_name() != null) {
            netbios.appendChild(doc.createTextNode(host.getNetbios_name()));
        }
        Element os = doc.createElement("operating-system");
        if (host.getOperating_system() != null) {
            os.appendChild(doc.createTextNode(host.getOperating_system()));
        }
        Element macAddress = doc.createElement("mac-address");
        if (host.getMac_address() != null) {
            macAddress.appendChild(doc.createTextNode(host.getMac_address()));
        }
        Element portnumber = doc.createElement("portnumber");
        if (host.getPortnumber() != null) {
            portnumber.appendChild(doc.createTextNode(host.getPortnumber()));
        }
        Element protocol = doc.createElement("protocol");
        if (host.getProtocol() != null) {
            protocol.appendChild(doc.createTextNode(host.getProtocol()));
        }

        Element note = doc.createElement("note");
        if (host.getNotes() != null) {
            Note n = host.getNotes();
            note.appendChild(doc.createTextNode(b64.encodeAsString(n.getNote_text().getBytes())));
        }

        // Append them to the affected Host node
        affectedHost.appendChild(ipAddress);
        affectedHost.appendChild(hostname);
        affectedHost.appendChild(netbios);
        affectedHost.appendChild(os);
        affectedHost.appendChild(macAddress);
        affectedHost.appendChild(portnumber);
        affectedHost.appendChild(protocol);
        affectedHost.appendChild(note);

        // Add that host to the affected hosts node
        affectedHosts.appendChild(affectedHost);
    }

    vulnElement.appendChild(vulnTitle);
    vulnElement.appendChild(identifiersElement);
    vulnElement.appendChild(vulnDescription);
    vulnElement.appendChild(vulnRecommendation);
    vulnElement.appendChild(vulnReferences);
    vulnElement.appendChild(affectedHosts);
    return vulnElement;
}

From source file:edu.umd.cfar.lamp.viper.examples.textline.AttributeWrapperTextline.java

public Element getXMLFormatConfig(Document root, Node container) {
    String qualifier = ViperData.ViPER_DATA_QUALIFIER;
    String uri = ViperData.ViPER_DATA_URI;
    Element poss = root.createElementNS(uri, qualifier + "textlink");
    if (getTextLink() != null)
        poss.setAttribute("value", getTextLink().getAttrName());
    return poss;//from w  ww.  j a  v  a  2 s . c  o  m
}

From source file:fi.helsinki.lib.simplerest.CommunitiesResource.java

@Get("xml")
public Representation toXml() {
    Context c = null;//  w  w w . java  2 s  .  c o m
    Community community = null;
    DomRepresentation representation = null;
    Document d = null;
    try {
        c = new Context();
        community = Community.find(c, this.communityId);
        if (community == null) {
            return errorNotFound(c, "Could not find the community.");
        }

        representation = new DomRepresentation(MediaType.TEXT_HTML);
        d = representation.getDocument();
    } catch (Exception e) {
        return errorInternal(c, e.toString());
    }

    Element html = d.createElement("html");
    d.appendChild(html);

    Element head = d.createElement("head");
    html.appendChild(head);

    Element title = d.createElement("title");
    head.appendChild(title);
    title.appendChild(d.createTextNode("Community " + community.getName()));

    Element body = d.createElement("body");
    html.appendChild(body);

    Element ulSubCommunities = d.createElement("ul");
    body.appendChild(ulSubCommunities);
    Community[] subCommunities;
    try {
        subCommunities = community.getSubcommunities();
    } catch (SQLException e) {
        return errorInternal(c, e.toString());
    }

    String url = getRequest().getResourceRef().getIdentifier();
    url = url.substring(0, url.lastIndexOf('/', url.lastIndexOf('/') - 1) + 1);
    for (Community subCommunity : subCommunities) {
        Element li = d.createElement("li");
        Element a = d.createElement("a");
        String href = url + Integer.toString(subCommunity.getID());
        setAttribute(a, "href", href);
        a.appendChild(d.createTextNode(subCommunity.getName()));
        li.appendChild(a);
        ulSubCommunities.appendChild(li);
    }

    Element form = d.createElement("form");
    form.setAttribute("enctype", "multipart/form-data");
    form.setAttribute("method", "post");
    makeInputRow(d, form, "name", "Name");
    makeInputRow(d, form, "short_description", "Short description");
    makeInputRow(d, form, "introductory_text", "Introductory text");
    makeInputRow(d, form, "copyright_text", "Copyright text");
    makeInputRow(d, form, "side_bar_text", "Side bar text");
    makeInputRow(d, form, "logo", "Logo", "file");

    Element submitButton = d.createElement("input");
    submitButton.setAttribute("type", "submit");
    submitButton.setAttribute("value", "Create a new sub community");
    form.appendChild(submitButton);

    body.appendChild(form);

    c.abort(); // Same as c.complete() because we didn't modify the db.

    return representation;
}

From source file:net.sourceforge.eclipsetrader.ats.Repository.java

void saveComponent(Component obj, Document document, Element element) {
    element.setAttribute("id", String.valueOf(obj.getId()));
    element.setAttribute("pluginId", String.valueOf(obj.getPluginId()));

    String[] keys = obj.getPreferences().preferenceNames();
    for (int i = 0; i < keys.length; i++) {
        Element node = document.createElement("param");
        node.setAttribute("key", keys[i]);
        node.setAttribute("value", (String) obj.getPreferences().getString(keys[i]));
        element.appendChild(node);/*from   w  ww . j  a v a2  s .com*/
    }
}

From source file:org.joy.config.Configuration.java

private void writeDatabase(Element elem, DatabaseElement db) {
    Element e = elem.getOwnerDocument().createElement("database");
    e.setAttribute("name", db.getName());
    setTextChild(e, "driverClass", db.getDriverClass());
    setTextChild(e, "url", db.getConnectionUrl());
    setTextChild(e, "username", db.getUsername());
    setTextChild(e, "password", db.getPassword());
    setTextChild(e, "schema", db.getSchema());

    elem.appendChild(e);/*from  w ww.  j ava2  s  . com*/
}