Example usage for org.dom4j Attribute getValue

List of usage examples for org.dom4j Attribute getValue

Introduction

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

Prototype

String getValue();

Source Link

Document

Returns the value of the attribute.

Usage

From source file:net.yrom.builder.util.ManifestParser.java

License:Apache License

/**
 * ?meta-data//w  ww .  j a v  a 2 s  .com
 * @param name
 * @param value
 * @param add ???meta-data?
 */
public void replaceMetaData(String name, String value, boolean add) {
    Iterator<Element> iterator = application.elementIterator("meta-data");
    boolean hasData = false;
    for (; iterator.hasNext();) {

        Element data = iterator.next();
        String nameValue = data.attributeValue(androidName);
        if (nameValue != null && nameValue.equals(name)) {
            Attribute attribute = data.attribute(androidValue);
            hasData = attribute.getValue().equals(value);
            if (attribute != null && !hasData) {
                attribute.setValue(value);
                return;
            }
        }
    }
    if (add && !hasData)
        application.addElement("meta-data").addAttribute(androidName, name).addAttribute(androidValue, value);
}

From source file:nl.architolk.ldt.processors.HttpClientProcessor.java

License:Open Source License

private void populateJSONArray(JSONArray root, Element element) {
    //At this moment, only simple arrays are possible, not arrays that contain arrays or objects
    Attribute typeAttr = element.attribute("type");
    String nodeType = (typeAttr != null) ? typeAttr.getValue() : "";
    if (nodeType.equals("number")) {
        //Numeric field
        try {/*  w  w w  .  ja  va 2  s .c  o  m*/
            root.add(Float.valueOf(element.getText()));
        } catch (NumberFormatException e) {
            logger.warn("Not a number: " + element.getText());
        }
    } else {
        //Default = string
        root.add(element.getText());
    }
}

From source file:nl.architolk.ldt.processors.HttpClientProcessor.java

License:Open Source License

private void populateJSONObject(JSONObject root, Element element) {
    Attribute typeAttr = element.attribute("type");
    String nodeType = (typeAttr != null) ? typeAttr.getValue() : "";
    if (element.isTextOnly()) {
        if (nodeType.equals("node")) {
            //Text only means: no children. If type is explicitly set to "node", the result should be an empty object
            root.put(element.getQName().getName(), new JSONObject());
        } else if (nodeType.equals("number")) {
            //Numeric field
            try {
                root.put(element.getQName().getName(), Float.valueOf(element.getText()));
            } catch (NumberFormatException e) {
                logger.warn("Not a number: " + element.getText());
            }/*w  w w.  j a  va  2  s.com*/
        } else {
            //Default = string
            root.put(element.getQName().getName(), element.getText());
        }
    } else if (nodeType.equals("nodelist")) {
        JSONArray json = new JSONArray();
        Iterator<?> elit = element.elementIterator();
        while (elit.hasNext()) {
            Element child = (Element) elit.next();
            populateJSONArray(json, child);
        }
        root.put(element.getQName().getName(), json);
    } else {
        JSONObject json = new JSONObject();
        Iterator<?> elit = element.elementIterator();
        while (elit.hasNext()) {
            Element child = (Element) elit.next();
            populateJSONObject(json, child);
        }
        root.put(element.getQName().getName(), json);
    }
}

From source file:nl.nn.ibistesttool.PipeDescriptionProvider.java

License:Apache License

private void addResourceNamesToPipeDescription(Element element, PipeDescription pipeDescription) {
    for (int i = 0, size = element.attributeCount(); i < size; i++) {
        Attribute attribute = element.attribute(i);
        if ("styleSheetName".equals(attribute.getName())
                || "serviceSelectionStylesheetFilename".equals(attribute.getName())
                || "schema".equals(attribute.getName()) || "wsdl".equals(attribute.getName())
                || "fileName".equals(attribute.getName()) || "schemaLocation".equals(attribute.getName())) {
            if ("schemaLocation".equals(attribute.getName())) {
                StringTokenizer st = new StringTokenizer(attribute.getValue(), ", \t\r\n\f");
                while (st.hasMoreTokens()) {
                    st.nextToken();// ww  w  .j a v a 2 s .com
                    String resourceName = st.nextToken();
                    if (!pipeDescription.containsResourceName(resourceName)) {
                        pipeDescription.addResourceName(resourceName);
                    }
                }
            } else {
                String resourceName = attribute.getValue();
                if (!pipeDescription.containsResourceName(resourceName)) {
                    pipeDescription.addResourceName(resourceName);
                }
            }
        }
    }
    for (int i = 0, size = element.nodeCount(); i < size; i++) {
        Node node = element.node(i);
        if (node instanceof Element && "sender".equals(node.getName())) {
            addResourceNamesToPipeDescription((Element) node, pipeDescription);
        }
    }
}

From source file:nl.tue.gale.ae.processor.xmlmodule.ForModule.java

License:Open Source License

@SuppressWarnings("unchecked")
private void replace(Element element, Pattern p, String replace) {
    for (Attribute a : (List<Attribute>) element.attributes()) {
        a.setValue(replace(a.getValue(), p, replace));
    }//from w ww .  j ava2s.  c  om
    for (Element e : (List<Element>) element.elements())
        replace(e, p, replace);
}

From source file:nl.tue.gale.ae.processor.xmlmodule.ViewModule.java

License:Open Source License

@SuppressWarnings("unchecked")
public Element traverse(Element element, Resource resource) throws ProcessorException {
    GaleContext gale = GaleContext.of(resource);
    LayoutView view = (LayoutView) gale.cfgm().getObject(
            "gale://gale.tue.nl/config/presentation#view-" + element.attributeValue("name"), resource);
    List<String> params = new LinkedList<String>();
    for (Attribute a : (List<Attribute>) element.attributes())
        if (!a.getName().equals("name"))
            params.add(a.getName() + "=" + a.getValue());
    resource.put("current-view", element.attributeValue("name"));
    Element result = view.getXml(resource, params.toArray());
    processor.traverseChildren(result, resource);
    GaleUtil.replaceNode(element, result);
    resource.remove("current-view");
    return null;//from   w ww .  ja  v  a2s  . c  o  m
}

From source file:nz.co.fortytwo.freeboard.installer.ChartProcessor.java

License:Open Source License

/**
 * Reads the .kap file, and the generated tilesresource.xml to get
 * chart desc, bounding box, and zoom levels
 * @param chartFile/*ww w  .j  a v a2s .  co m*/
 * @param false 
 * @throws Exception
 */
public void processKapChart(File chartFile, boolean reTile, String charset) throws Exception {
    //String chartPath = chartFile.getParentFile().getAbsolutePath();
    String chartName = chartFile.getName();
    chartName = chartName.substring(0, chartName.lastIndexOf("."));
    File dir = new File(chartFile.getParentFile(), chartName);
    //      if(manager){
    //         logger.info("Chart tag:"+chartName+"\n");
    //         logger.info("Chart dir:"+dir.getPath()+"\n");
    //      }
    //      logger.info("Processing Chart tag:"+chartName);
    logger.info("Chart dir:" + dir.getPath());

    if (reTile) {
        KapProcessor processor = new KapProcessor();
        processor.setObserver(new KapObserver() {
            public void appendMsg(final String message) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        textArea.append(message);
                    }
                });
            }
        });
        processor.createTilePyramid(chartFile, mapCacheDir, false);
    }
    //process the layer data
    File xmlFile = new File(dir, "tilemapresource.xml");

    //read data from dirName/tilelayers.xml
    SAXReader reader = new SAXReader();

    Document document = reader.read(new InputStreamReader(new FileInputStream(xmlFile), charset));

    logger.info("KAP file using " + charset);
    //now get the Chart Name from the kap file
    InputStreamReader fileReader = new InputStreamReader(new FileInputStream(chartFile), charset);
    char[] chars = new char[4096];
    fileReader.read(chars);
    fileReader.close();
    String header = new String(new String(chars).getBytes(), "UTF-8");
    int pos = header.indexOf("BSB/NA=") + 7;
    String desc = header.substring(pos, header.indexOf("\n", pos)).trim();
    //if(desc.endsWith("\n"))desc=desc.substring(0,desc.length()-1);
    logger.debug("Name:" + desc);
    //we cant have + or , or = in name, as its used in storing ChartplotterViewModel
    //US50_2 BERING SEA CONTINUATION,NU=2401,RA=2746,3798,DU=254
    desc = desc.replaceAll("\\+", " ");
    desc = desc.replaceAll(",", " ");
    desc = desc.replaceAll("=", "/");
    //limit length too
    if (desc.length() > 40) {
        desc = desc.substring(0, 40);
    }

    //we need BoundingBox
    Element box = (Element) document.selectSingleNode("//BoundingBox");
    String minx = box.attribute("minx").getValue();
    String miny = box.attribute("miny").getValue();
    String maxx = box.attribute("maxx").getValue();
    String maxy = box.attribute("maxy").getValue();
    //        if(manager){
    //         logger.info("Box:"+minx+","+miny+","+maxx+","+maxy+"\n");
    //      }
    logger.debug("Box:" + minx + ", " + miny + ", " + maxx + ", " + maxy);

    //we need TileSets, each tileset has an href, we need first and last for zooms
    @SuppressWarnings("unchecked")
    List<Attribute> list = document.selectNodes("//TileSets/TileSet/@href");
    int minZoom = 18;
    int maxZoom = 0;
    for (Attribute attribute : list) {
        int zoom = Integer.valueOf(attribute.getValue());
        if (zoom < minZoom)
            minZoom = zoom;
        if (zoom > maxZoom)
            maxZoom = zoom;
    }
    //        if(manager){
    //         System.out.print("Zoom:"+minZoom+"-"+maxZoom+"\n");
    //      }
    logger.debug("Zoom:" + minZoom + "-" + maxZoom);

    //cant have - in js var name
    String chartNameJs = chartName.replaceAll("^[^a-zA-Z_$]|[^\\w$]", "_");
    String snippet = "\n\tvar " + chartNameJs + " = L.tileLayer(\"http://{s}.{server}:8080/mapcache/"
            + chartName + "/{z}/{x}/{y}.png\", {\n" + "\t\tserver: host,\n" + "\t\tsubdomains: 'abcd',\n"
            + "\t\tattribution: '" + chartName + " " + desc + "',\n" + "\t\tminZoom: " + minZoom + ",\n"
            + "\t\tmaxNativeZoom: " + maxZoom + ",\n" + "\t\tmaxZoom: " + (maxZoom + 3) + ",\n"
            + "\t\ttms: true\n" + "\t\t}).addTo(map);\n";

    //        if(manager){
    //         System.out.print(snippet+"\n");
    //      }
    logger.debug(snippet);
    //add it to local freeboard.txt
    File layers = new File(dir, "freeboard.txt");
    FileUtils.writeStringToFile(layers, snippet, StandardCharsets.UTF_8.name());
    //now zip the result
    logger.info("Zipping directory...");
    ZipUtils.zip(dir, new File(dir.getParentFile(), chartName + ".zip"));
    logger.info("Zipping directory complete, in "
            + new File(dir.getParentFile(), chartName + ".zip").getAbsolutePath());
}

From source file:nz.co.fortytwo.freeboard.server.util.ChartProcessor.java

License:Open Source License

/**
 * Reads the .kap file, and the generated tilesresource.xml to get
 * chart desc, bounding box, and zoom levels 
 * @param chartFile//from   ww  w . j  ava 2  s  . c o  m
 * @throws Exception
 */
public void processKapChart(File chartFile, boolean reTile) throws Exception {
    String chartName = chartFile.getName();
    chartName = chartName.substring(0, chartName.lastIndexOf("."));
    File dir = new File(chartFile.getParentFile(), chartName);
    if (manager) {
        System.out.print("Chart tag:" + chartName + "\n");
        System.out.print("Chart dir:" + dir.getPath() + "\n");
    }
    logger.debug("Chart tag:" + chartName);
    logger.debug("Chart dir:" + dir.getPath());
    //start by running the gdal scripts
    if (reTile) {
        executeGdal(chartFile, chartName,
                //this was for NZ KAP charts
                //Arrays.asList("gdal_translate", "-if","GTiff", "-of", "vrt", "-expand", "rgba",chartFile.getName(),"temp.vrt"),
                //this for US NOAA charts
                Arrays.asList("gdal_translate", "-of", "vrt", "-expand", "rgba", chartFile.getName(),
                        "temp.vrt"),
                Arrays.asList("gdal2tiles.py", "temp.vrt", chartName));
    }
    //now get the Chart Name from the kap file
    FileReader fileReader = new FileReader(chartFile);
    char[] chars = new char[4096];
    fileReader.read(chars);
    fileReader.close();
    String header = new String(chars);
    int pos = header.indexOf("BSB/NA=") + 7;
    String desc = header.substring(pos, header.indexOf("\n", pos)).trim();
    //if(desc.endsWith("\n"))desc=desc.substring(0,desc.length()-1);
    logger.debug("Name:" + desc);
    //we cant have + or , or = in name, as its used in storing ChartplotterViewModel
    //US50_2 BERING SEA CONTINUATION,NU=2401,RA=2746,3798,DU=254
    desc = desc.replaceAll("\\+", " ");
    desc = desc.replaceAll(",", " ");
    desc = desc.replaceAll("=", "/");
    //limit length too
    if (desc.length() > 40) {
        desc = desc.substring(0, 40);
    }
    //process the layer data

    //read data from dirName/tilelayers.xml
    SAXReader reader = new SAXReader();
    Document document = reader.read(new File(dir, "tilemapresource.xml"));
    //we need BoundingBox
    Element box = (Element) document.selectSingleNode("//BoundingBox");
    String minx = box.attribute("minx").getValue();
    String miny = box.attribute("miny").getValue();
    String maxx = box.attribute("maxx").getValue();
    String maxy = box.attribute("maxy").getValue();
    if (manager) {
        System.out.print("Box:" + minx + "," + miny + "," + maxx + "," + maxy + "\n");
    }
    logger.debug("Box:" + minx + "," + miny + "," + maxx + "," + maxy);

    //we need TileSets, each tileset has an href, we need first and last for zooms
    List<Attribute> list = document.selectNodes("//TileSets/TileSet/@href");
    int minZoom = 18;
    int maxZoom = 0;
    for (Attribute attribute : list) {
        int zoom = Integer.valueOf(attribute.getValue());
        if (zoom < minZoom)
            minZoom = zoom;
        if (zoom > maxZoom)
            maxZoom = zoom;
    }
    if (manager) {
        System.out.print("Zoom:" + minZoom + "-" + maxZoom + "\n");
    }
    logger.debug("Zoom:" + minZoom + "-" + maxZoom);

    String snippet = "\n\tvar " + chartName + " = L.tileLayer(\"http://{s}.{server}:8080/mapcache/" + chartName
            + "/{z}/{x}/{y}.png\", {\n" + "\t\tserver: host,\n" + "\t\tsubdomains: 'abcd',\n"
            + "\t\tattribution: '" + chartName + " " + desc + "',\n" + "\t\tminZoom: " + minZoom + ",\n"
            + "\t\tmaxZoom: " + maxZoom + ",\n" + "\t\ttms: true\n" + "\t\t}).addTo(map);\n";

    if (manager) {
        System.out.print(snippet + "\n");
    }
    logger.debug(snippet);
    //add it to local freeboard.txt
    File layers = new File(dir, "freeboard.txt");
    FileUtils.writeStringToFile(layers, snippet);
    //now zip the result
    System.out.print("Zipping directory...\n");
    ZipUtils.zip(dir, new File(dir.getParentFile(), chartName + ".zip"));
    System.out.print("Zipping directory complete, in "
            + new File(dir.getParentFile(), chartName + ".zip").getAbsolutePath() + "\n");
    System.out.print("Conversion of " + chartName + " was completed successfully!\n");
}

From source file:org.alfresco.module.vti.web.ws.GetListEndpoint.java

License:Open Source License

@SuppressWarnings("unchecked")
private void copyElement(Element source, Element target) {
    Element copy = target.addElement(source.getQName());
    for (Attribute attr : (List<Attribute>) source.attributes()) {
        copy.addAttribute(attr.getQName(), attr.getValue());
    }//from www. j a v  a  2s  .  co m
    for (Element child : (List<Element>) source.elements()) {
        copyElement(child, copy);
    }
    if (source.getText() != null) {
        copy.setText(source.getText());
    }
}

From source file:org.alfresco.web.config.forms.DependenciesElementReader.java

License:Open Source License

/**
 * This method takes the specified xml node, finds children matching the specified
 * xpath expression and returns a List<String> containing the values of the "src"
 * attribute on each of those child nodes.
 * /*from  www.  j  a  va 2  s.  com*/
 * @param typeNode Element
 * @param xpathExpression String
 * @return List<String>
 */
@SuppressWarnings("unchecked")
private List<String> getSrcDependencies(Element typeNode, final String xpathExpression) {
    List<String> result = new ArrayList<String>();

    for (Object cssObj : typeNode.selectNodes(xpathExpression)) {
        Element cssElem = (Element) cssObj;
        List<Attribute> cssAttributes = cssElem.selectNodes("./@*");
        for (Attribute nextAttr : cssAttributes) {
            String nextAttrName = nextAttr.getName();
            if (nextAttrName.equals("src")) {
                String nextAttrValue = nextAttr.getValue();
                result.add(nextAttrValue);
            }
            // Ignore attributes not called "src".
        }
    }

    return result;
}