Example usage for org.dom4j Attribute setValue

List of usage examples for org.dom4j Attribute setValue

Introduction

In this page you can find the example usage for org.dom4j Attribute setValue.

Prototype

void setValue(String value);

Source Link

Document

Sets the value of this attribute or this method will throw an UnsupportedOperationException if it is read-only.

Usage

From source file:com.sun.xml.ws.test.container.AbstractApplicationContainer.java

License:Open Source License

protected void updateWsitClient(WAR war, DeployedService deployedService, String id) throws Exception {
    File wsitClientFile = new File(deployedService.getResources(), "wsit-client.xml");
    if (wsitClientFile.exists()) {
        SAXReader reader = new SAXReader();
        Document document = reader.read(wsitClientFile);
        Element root = document.getRootElement();
        Element policy = root.element("Policy");
        Element sts = policy.element("ExactlyOne").element("All").element("PreconfiguredSTS");

        Attribute endpoint = sts.attribute("endpoint");
        endpoint.setValue(id);

        Attribute wsdlLoc = sts.attribute("wsdlLocation");
        String x = deployedService.service.wsdl.get(0).wsdlFile.toURI().toString();
        wsdlLoc.setValue(x);//  w w w  . j av  a 2 s . com

        XMLWriter writer = new XMLWriter(new FileWriter(wsitClientFile));
        writer.write(document);
        writer.close();
        war.copyWsit(wsitClientFile);
    } else {
        throw new RuntimeException("wsit-client.xml is absent. It is required. \n" + "Please check "
                + deployedService.getResources());
    }
}

From source file:com.sun.xml.ws.test.container.invm.InVmContainer.java

License:Open Source License

/**
 * Fix the address in the WSDL. to the local address.
 */// w ww  .jav  a2s . c  o  m
private void patchWsdl(DeployedService service, File wsdl, String id) throws Exception {
    Document doc = new SAXReader().read(wsdl);
    List<Element> ports = doc.getRootElement().element("service").elements("port");

    for (Element port : ports) {
        String portName = port.attributeValue("name");
        Element address = getSoapAddress(port);

        //Looks like invalid wsdl:port, MUST have a soap:address
        //TODO: give some error message
        if (address == null)
            continue;

        if (!"wsdl".equalsIgnoreCase(wsdl.getParentFile().getName())) {
            portName = wsdl.getParentFile().getName() + portName;
        }

        Attribute locationAttr = address.attribute("location");
        String newLocation = "in-vm://" + id + "/?" + portName;
        newLocation = newLocation.replace('\\', '/');
        locationAttr.setValue(newLocation);

        //Patch wsa:Address in wsa:EndpointReference as well
        Element wsaEprEl = port
                .element(QName.get("EndpointReference", "wsa", "http://www.w3.org/2005/08/addressing"));
        if (wsaEprEl != null) {
            Element wsaAddrEl = wsaEprEl
                    .element(QName.get("Address", "wsa", "http://www.w3.org/2005/08/addressing"));
            wsaAddrEl.setText(newLocation);

        }
    }

    // save file
    FileOutputStream os = new FileOutputStream(wsdl);
    new XMLWriter(os).write(doc);
    os.close();
}

From source file:com.sun.xml.ws.test.container.local.LocalApplicationContainer.java

License:Open Source License

/**
 * Fix the address in the WSDL. to the local address.
 *///  w  w  w  .  j  a va 2  s  .  c o m
private void patchWsdl(DeployedService service, File wsdl) throws Exception {
    Document doc = new SAXReader().read(wsdl);
    List<Element> ports = doc.getRootElement().element("service").elements("port");

    for (Element port : ports) {
        String portName = port.attributeValue("name");

        Element address = (Element) port.elements().get(0);

        Attribute locationAttr = address.attribute("location");
        String newLocation = "local://" + service.warDir.getAbsolutePath() + "?" + portName;
        newLocation = newLocation.replace('\\', '/');
        locationAttr.setValue(newLocation);

        //Patch wsa:Address in wsa:EndpointReference as well
        Element wsaEprEl = port
                .element(QName.get("EndpointReference", "wsa", "http://www.w3.org/2005/08/addressing"));
        if (wsaEprEl != null) {
            Element wsaAddrEl = wsaEprEl
                    .element(QName.get("Address", "wsa", "http://www.w3.org/2005/08/addressing"));
            wsaAddrEl.setText(newLocation);

        }
    }

    // save file
    FileOutputStream os = new FileOutputStream(wsdl);
    new XMLWriter(os).write(doc);
    os.close();
}

From source file:com.taobao.android.builder.tools.manifest.ManifestFileUtils.java

License:Apache License

/**
 * libManifest//from   w w  w .  j  av  a2s  .c  o m
 *
 * @param libManifestFile
 * @param mainManifestFileObject param updateSdkVersion
 */
public static void updatePreProcessManifestFile(File libManifestFile, ManifestFileObject mainManifestFileObject,
        boolean updateSdkVersion) throws IOException, DocumentException {

    if (!libManifestFile.exists()) {
        return;
    }

    File orgManifestFile = new File(libManifestFile.getParentFile(), "AndroidManifest-org.xml");
    if (orgManifestFile.exists()) {
        return;
    }

    libManifestFile.renameTo(orgManifestFile);

    SAXReader reader = new SAXReader();
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("UTF-8");// XML??

    Document document = reader.read(orgManifestFile);// ?XML
    Element root = document.getRootElement();// 
    if (updateSdkVersion) {
        Element useSdkElement = root.element("uses-sdk");

        if (null == useSdkElement) {
            useSdkElement = root.addElement("uses-sdk");
        }

        if (null != useSdkElement) {
            updateElement(useSdkElement, mainManifestFileObject.getUseSdkProperties());
        }
    }

    // ?tools:removetools:replace?ManifestMerge??
    Element applicationElement = root.element("application");
    Map<String, String> replaceAttrs = mainManifestFileObject.getReplaceApplicationAttribute();
    List<String> removeAttrs = mainManifestFileObject.getRemoveApplicationAttribute();

    if (null != applicationElement) {
        // libtools
        List<Attribute> toRomoved = new ArrayList<Attribute>();
        for (Attribute attribute : applicationElement.attributes()) {
            if (attribute.getName().equals("replace") || attribute.getName().equals("remove")) {
                // applicationElement.remove(attribute);
                // applicationElement.attributes().remove(attribute);
                toRomoved.add(attribute);
            }
        }
        if (toRomoved.size() > 0) {
            for (Attribute attribute : toRomoved) {
                applicationElement.remove(attribute);
            }
        }

        updateApplicationElement(applicationElement, replaceAttrs, removeAttrs);
    }

    //?packageName TODO
    String packageName = root.attributeValue("package");
    if (StringUtils.isEmpty(packageName)) {
        packageName = ManifestFileUtils.getPackage(orgManifestFile);
    }

    List<? extends Node> applicatNodes = root.selectNodes("//application");
    for (Node node : applicatNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        if (attribute != null) {
            if (!attribute.getValue().startsWith(packageName)) {
                attribute.setValue(packageName + attribute.getValue());
            }
        }
    }

    fillFullClazzName(root, packageName, "activity");
    fillFullClazzName(root, packageName, "provider");
    fillFullClazzName(root, packageName, "receiver");
    fillFullClazzName(root, packageName, "service");

    saveFile(document, format, libManifestFile);
}

From source file:com.taobao.android.builder.tools.manifest.ManifestFileUtils.java

License:Apache License

private static void fillFullClazzName(Element root, String packageName, String type) {
    List<? extends Node> applicatNodes = root.selectNodes("//" + type);
    for (Node node : applicatNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        if (attribute != null) {
            if (attribute.getValue().startsWith(".")) {
                attribute.setValue(packageName + attribute.getValue());
            }/*  w w w.j a v a 2 s.co  m*/
        }
    }
}

From source file:com.taobao.android.builder.tools.manifest.ManifestFileUtils.java

License:Apache License

/**
 * element/*from w w  w .ja  va  2s  .c  om*/
 *
 * @param element
 * @param properties
 */
private static void updateElement(Element element, Map<String, String> properties) {
    for (Map.Entry<String, String> entry : properties.entrySet()) {
        String key = entry.getKey();
        if (key.startsWith("tools:")) {
            continue;
        }
        String keyNoPrefix = key;
        String[] values = StringUtils.split(key, ":");
        if (values.length > 1) {
            keyNoPrefix = values[1];
        }
        if (null == entry.getValue()) {
            continue;
        } else {
            Attribute attribute = element.attribute(keyNoPrefix);
            if (null != attribute) {
                attribute.setValue(entry.getValue());
            } else {
                element.addAttribute(key, entry.getValue());
            }
        }
    }
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void setApprovalTypeForStage(String pipelineName, String stageName, String type) {
    Element stage = getStage(pipelineName, stageName);
    Element approval = stage.element("approval");
    if (approval == null) {
        approval = new DefaultElement("approval");
        Element jobs = stage.element("jobs");
        if (jobs != null) {
            jobs.detach();//from w w w.  j  a  v  a2s. c om
            stage.add(approval);
            stage.add(jobs);
        } else {
            stage.add(approval);
        }
    }
    Attribute attribute = approval.attribute("type");
    if (attribute != null) {
        attribute.setValue(type);
    } else {
        approval.addAttribute("type", type);
    }
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void setAllowOnlyKnownUsersToLogin(boolean value) {
    Element security = (Element) document.getRootElement().selectSingleNode("//security");
    if (security == null) {
        security = new DefaultElement("security");
        Element server = (Element) document.getRootElement().selectSingleNode("//server");
        server.add(security);//from  w w w  . j a va2s . co  m
    }
    Attribute allowOnlyKnownUsers = security.attribute("allowOnlyKnownUsersToLogin");
    if (allowOnlyKnownUsers == null) {
        allowOnlyKnownUsers = new DefaultAttribute("allowOnlyKnownUsersToLogin", Boolean.toString(value));
        security.add(allowOnlyKnownUsers);
    } else {
        allowOnlyKnownUsers.setValue(Boolean.toString(value));
    }
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void pipelineAutoUpdate(String pipelineName) {
    List<Element> materials = materialsForPipeline(pipelineName);
    for (Element material : materials) {
        Attribute autoUpdate = material.attribute("autoUpdate");
        if (autoUpdate == null) {
            material.add(new DefaultAttribute("autoUpdate", "true"));
        } else {//from  ww  w . j  a va 2  s .c o m
            autoUpdate.setValue("true");
        }
    }
}

From source file:com.thoughtworks.cruise.utils.configfile.CruiseConfigDom.java

License:Apache License

public void modifyPipeline(String pipelineName, String node, String attribute, String attrValue) {

    Element pipeline = pipelineElement(pipelineName);
    Element trackingTool = findOrCreateAt(pipeline, 0, node);
    Attribute linkAttr = trackingTool.attribute(attribute);
    if (linkAttr == null) {
        trackingTool.add(new DefaultAttribute(attribute, attrValue));
    } else {//from  w  w  w. j  a  v a  2s  .  c  om
        linkAttr.setValue(attrValue);
    }
}