Example usage for org.w3c.dom Node hasAttributes

List of usage examples for org.w3c.dom Node hasAttributes

Introduction

In this page you can find the example usage for org.w3c.dom Node hasAttributes.

Prototype

public boolean hasAttributes();

Source Link

Document

Returns whether this node (if it is an element) has any attributes.

Usage

From source file:org.apache.hadoop.mapred.QueueConfigurationParser.java

/**
 * Populate the properties for Queue//from  w ww.ja v  a 2  s.  c  om
 *
 * @param field
 * @return
 */
private Properties populateProperties(Element field) {
    Properties props = new Properties();

    NodeList propfields = field.getChildNodes();

    for (int i = 0; i < propfields.getLength(); i++) {
        Node prop = propfields.item(i);

        //If this node is not of type element
        //skip this.
        if (!(prop instanceof Element)) {
            continue;
        }

        if (PROPERTY_TAG.equals(prop.getNodeName())) {
            if (prop.hasAttributes()) {
                NamedNodeMap nmp = prop.getAttributes();
                if (nmp.getNamedItem(KEY_TAG) != null && nmp.getNamedItem(VALUE_TAG) != null) {
                    props.setProperty(nmp.getNamedItem(KEY_TAG).getTextContent(),
                            nmp.getNamedItem(VALUE_TAG).getTextContent());
                }
            }
        }
    }
    return props;
}

From source file:org.bibsonomy.scraper.url.kde.ieee.IEEEXploreBookScraper.java

/**
 * @param sc/*from  w ww . j a v  a 2s.c  o  m*/
 * @return bibtex
 * @throws ScrapingException
 */
public String ieeeBookScrape(ScrapingContext sc) throws ScrapingException {
    try {
        //-- init all NodeLists and Node
        NodeList pres = null;
        Node currNode = null;
        NodeList temp = null;

        //-- init String map for bibtex entries
        String type = IEEE_BOOK;
        String url = sc.getUrl().toString();
        String authors = "";
        String numpages = "";
        String title = "";
        String isbn = "";
        String publisher = "";
        String month = "";
        String year = "";
        String edition = "";
        String abstr = "";

        String bibtexkey = null;
        String _tempabs = null;
        String ident1 = null;
        String ident2 = null;

        //-- get the html doc and parse the DOM
        final Document doc = XmlUtils.getDOM(sc.getPageContent());

        /*
         * -- Search title and extract --
         * The title has always the css-class "headNavBlueXLarge".
         *
         * FIXME: this part could be deprecated. don't knot it at all...
         *
        pres = null;
        pres = doc.getElementsByTagName("span"); //get all <span>-Tags
        for (int i = 0; i < pres.getLength(); i++) {
           Node curr = pres.item(i);
           Element g = (Element)curr;
           Attr own = g.getAttributeNode("class");         
                
           //-- Extract the title
           if ("headNavBlueXLarge".equals(own.getValue())){
              title = curr.getFirstChild().getNodeValue();
           }
        } */

        if (title == null || title.equals("")) {
            ident1 = "<title>";
            ident2 = "</title>";
            if (sc.getPageContent().contains(ident1) && sc.getPageContent().contains(ident2)) {
                int _startIndex = sc.getPageContent().indexOf(ident1) + ident1.length();
                int _endIndex = sc.getPageContent().indexOf(ident2);
                title = sc.getPageContent().substring(_startIndex, _endIndex);
                title = title.replaceAll("IEEEXplore#\\s", "");
            }
        }

        /* 
         * get the abstract block
         * 
         * FIXME: this part could be deprecated. don't knot it at all...
         * 
        ident1 = "<strong>Abstract</strong>";
        ident2 = "<strong>Table of Contents </strong>";
        if (sc.getPageContent().indexOf(ident1) != -1 && sc.getPageContent().indexOf(ident2) != -1 ){
           _tempabs = sc.getPageContent().substring(sc.getPageContent().indexOf(ident1)+ident1.length(),sc.getPageContent().indexOf(ident2)).replaceAll("\\s\\s+", "").replaceAll("(<.+?>)", "").trim();
           abstr = _tempabs;         
        } */

        ident1 = "<span class=\"sectionHeaders\">Abstract</span>";
        ident2 = "<td class=\"bodyCopyGrey\"><p class=\"bodyCopyGreySpaced\"><strong>";
        if (sc.getPageContent().contains(ident1) && sc.getPageContent().contains(ident2)) {
            int _startIndex = sc.getPageContent().indexOf(ident1) + ident1.length();
            int _endIndex = sc.getPageContent().indexOf(ident2);
            _tempabs = sc.getPageContent().substring(_startIndex, _endIndex);
            abstr = _tempabs.replaceAll("\\s\\s+", "").replaceAll("(<.+?>)", "").trim();
        }

        /* 
         * get the book formats like hardcover
         * 
         * FIXME: this part could be deprecated. don't knot it at all...
         * 
         *
        ident1 = "<td class=\"bodyCopyBlackLarge\" nowrap>Hardcover</td>";
        ident2 = "<td class=\"bodyCopyBlackLarge\" nowrap><span class=\"sectionHeaders\">&raquo;</span>";
        if (sc.getPageContent().indexOf(ident1) != -1){
           _format = sc.getPageContent().substring(sc.getPageContent().indexOf(ident1),sc.getPageContent().indexOf(ident2)).replaceAll("\\s\\s+", "").replaceAll("(<.+?>)", "");
                
           _format = _format.substring(_format.indexOf(CONST_ISBN) + CONST_ISBN.length());
           isbn = _format.substring(0,_format.indexOf("&nbsp;"));
        }*/

        /*-- get all <p>-Tags to extract the standard informations
         *  In every standard page the css-class "bodyCopyBlackLargeSpaced"
         *  indicates the collection of all informations.
         * */
        pres = null;
        pres = doc.getElementsByTagName("p"); //get all <p>-Tags
        for (int i = 0; i < pres.getLength(); i++) {
            currNode = pres.item(i);

            if (currNode.hasAttributes()) {
                Element g = (Element) currNode;
                Attr own = g.getAttributeNode("class");
                if ("bodyCopyBlackLargeSpaced".equals(own.getValue()) && currNode.hasChildNodes()) {
                    temp = currNode.getChildNodes();

                    for (int j = 0; j < temp.getLength(); j++) {
                        if (temp.item(j).getNodeValue().indexOf(CONST_DATE) != -1) {
                            String date = temp.item(j).getNodeValue().substring(18);
                            year = date.substring(date.length() - 5).trim();
                            month = date.substring(0, date.length() - 4).trim();
                            // not correct in all cases
                            // publisher = temp.item(j+2).getNodeValue().trim();
                        }
                        if (temp.item(j).getNodeValue().indexOf(CONST_PAGES) != -1) {
                            numpages = temp.item(j).getNodeValue().substring(CONST_PAGES.length()).trim();
                        } else if (temp.item(j).getNodeValue().indexOf(CONST_ON_PAGES) != -1) {
                            numpages = temp.item(j).getNodeValue().substring(CONST_ON_PAGES.length()).trim();
                        }
                        if (temp.item(j).getNodeValue().indexOf(CONST_EDITION) != -1) {
                            edition = temp.item(j).getNodeValue().substring(CONST_EDITION.length()).trim();
                        } else if (temp.item(j).getNodeValue().indexOf(CONST_VOLUME) != -1) {
                            edition = temp.item(j).getNodeValue().substring(CONST_VOLUME.length()).trim();
                        }
                        if (isbn == "" && temp.item(j).getNodeValue().indexOf(CONST_ISBN) != -1) {
                            isbn = temp.item(j).getNodeValue().substring(CONST_ISBN.length()).trim();
                        }
                    }
                    break;
                }
            }
        }

        /*-- Search authors and save them --
         * 
         * FIXME: this part could be deprecated. don't knot it at all...
         * 
        pres = null;
        pres = doc.getElementsByTagName("a"); //get all <a>-Tags
                
        //init vars to count authors to form a bibtex String
        int numaut = 0;
                
         *
         * iterate through the a tags and search the attribute value "<in>aud)" 
         * to identify the authors in the source of the ieeexplore page
         * 
        for (int i = 39; i < pres.getLength(); i++) {
           Node curr = pres.item(i);
           Element g = (Element)curr;
           Attr own = g.getAttributeNode("href");
                
           if (own.getValue().indexOf("<in>au)") != -1){
              //Form Bibtex String by counting authors
              if (numaut > 0 ){
          authors += " and " + curr.getFirstChild().getNodeValue(); 
              }
              if (numaut == 0) {
          numaut=i;
          authors += curr.getFirstChild().getNodeValue();
                
          if (curr.getFirstChild().getNodeValue().indexOf(",") != -1 && bibtexkey == null){
             bibtexkey = curr.getFirstChild().getNodeValue().substring(0,curr.getFirstChild().getNodeValue().trim().indexOf(","));
          } else if (curr.getFirstChild().getNodeValue().trim().indexOf(" ") != -1 && bibtexkey == null){
             bibtexkey = curr.getFirstChild().getNodeValue().trim().substring(0,curr.getFirstChild().getNodeValue().trim().indexOf(" "));
          } else if (bibtexkey == null){
             bibtexkey = curr.getFirstChild().getNodeValue().trim();
          }
              }
           }
        } */

        /*
         * get authors
         */
        if (authors == null || authors.equals("")) {
            ident1 = "<font color=990000><b>";
            ident2 = "<br>";
            int _startIndex = sc.getPageContent().indexOf(ident1) + ident1.length();
            if (sc.getPageContent().contains(ident1)
                    && sc.getPageContent().indexOf(ident2, _startIndex) != -1) {
                int _endIndex = sc.getPageContent().indexOf(ident2, _startIndex);
                authors = sc.getPageContent().substring(_startIndex, _endIndex);
                authors = authors.replaceAll("\\s\\s+", "").replaceAll("(<.+?>)", "").trim();
                authors = authors.replaceAll("&nbsp;&nbsp;", " and ");

                if (authors.endsWith(" and ")) {
                    authors = authors.substring(0, authors.length() - 5);
                }
            }
        }

        //-- kill special chars and add the year to bibtexkey
        if ((isbn == null || !isbn.equals("")) && (year == null || !year.equals(""))) {
            bibtexkey = isbn.replaceAll("-", "");
            bibtexkey = bibtexkey.replaceAll("[^0-9A-Za-z]", "") + ":" + year;
        }

        //create the book-bibtex
        return type + " { " + bibtexkey + ", \n" + "author = {" + authors + "}, \n" + "title = {" + title
                + "}, \n" + "year = {" + year + "}, \n" + "url = {" + url + "}, \n" + "pages = {" + numpages
                + "}, \n" + "edition = {" + edition + "}, \n" + "publisher = {" + publisher + "}, \n"
                + "isbn = {" + isbn + "}, \n" + "abstract = {" + abstr + "}, \n" + "month = {" + month + "}\n}";

    } catch (Exception e) {
        throw new InternalFailureException(e);
    }
}

From source file:org.bibsonomy.scraper.url.kde.ieee.IEEEXploreStandardsScraper.java

public String ieeeStandardsScrape(ScrapingContext sc) throws ScrapingException {
    try {//from   w w  w  .  j  a  v a  2 s.c o  m
        //-- init all NodeLists and Node
        NodeList pres = null;
        Node currNode = null;
        NodeList temp = null;

        //-- init String map for bibtex entries
        String type = IEEE_STANDARDS;
        String url = sc.getUrl().toString();
        String numpages = "";
        String title = "";
        String isbn = "";
        String abstr = "";
        String year = "";

        //-- get the html doc and parse the DOM
        final Document document = XmlUtils.getDOM(sc.getPageContent());

        /* -- get the spans to extract the title and abstract
         */
        pres = null;
        pres = document.getElementsByTagName("span"); //get all <span>-Tags
        for (int i = 0; i < pres.getLength(); i++) {
            currNode = pres.item(i);
            if (currNode.hasAttributes()) {
                Element g = (Element) currNode;
                Attr own = g.getAttributeNode("class");
                //-- Extract the title
                if ("headNavBlueXLarge2".equals(own.getValue())) {
                    temp = currNode.getChildNodes();
                    title = temp.item(temp.getLength() - 1).getNodeValue().trim();
                }
                //-- Extract the abstract
                if ("sectionHeaders".equals(own.getValue())
                        && "Abstract".equals(currNode.getFirstChild().getNodeValue())) {
                    abstr = currNode.getParentNode().getLastChild().getNodeValue().trim();
                }
            }
        }

        /*-- get all <p>-Tags to extract the standard informations
         *  In every standard page the css-class "bodyCopyBlackLargeSpaced"
         *  indicates the collection of all informations.
         * */
        pres = null;
        pres = document.getElementsByTagName("p"); //get all <p>-Tags
        for (int i = 0; i < pres.getLength(); i++) {
            currNode = pres.item(i);
            if (currNode.hasAttributes()) {
                Element g = (Element) currNode;
                Attr own = g.getAttributeNode("class");
                if ("bodyCopyBlackLargeSpaced".equals(own.getValue())) {
                    temp = currNode.getChildNodes();

                    for (int j = 0; j < temp.getLength(); j++) {
                        if (temp.item(j).getNodeValue().indexOf(CONST_DATE) != -1) {
                            String date = temp.item(j).getNodeValue().substring(CONST_DATE.length()).trim();
                            year = date.substring(date.length() - 4).trim();
                        }
                        if (temp.item(j).getNodeValue().indexOf(CONST_PAGE) != -1) {
                            numpages = temp.item(j).getNodeValue().substring(CONST_PAGE.length()).trim();
                        }
                        if (temp.item(j).getNodeValue().indexOf(CONST_EISBN) != -1) {
                            isbn = temp.item(j).getNodeValue().substring(CONST_EISBN.length()).trim();
                        }
                    }
                }
            }
        }

        //create valid bibtex snippet
        return type + " {," + "title = {" + title + "}, " + "year = {" + year + "}, " + "url = {" + url + "}, "
                + "pages = {" + numpages + "}, " + "abstract = {" + abstr + "}, " + "isbn = {" + isbn + "}}";

    } catch (Exception e) {
        throw new InternalFailureException(e);
    }
}

From source file:org.dasein.cloud.vcloud.compute.vAppSupport.java

public void deploy(@Nonnull String vmId) throws CloudException, InternalException {
    APITrace.begin(getProvider(), "VM.deploy");
    try {/*from w  w  w  .  j  a v  a2  s . co m*/
        vCloudMethod method = new vCloudMethod(getProvider());
        String xml = method.get("vApp", vmId);

        if (xml != null) {
            Document doc = method.parseXML(xml);
            String docElementTagName = doc.getDocumentElement().getTagName();
            String nsString = "";
            if (docElementTagName.contains(":"))
                nsString = docElementTagName.substring(0, docElementTagName.indexOf(":") + 1);
            NodeList nodes = doc.getElementsByTagName(nsString + "VApp");

            for (int i = 0; i < nodes.getLength(); i++) {
                NodeList links = nodes.item(i).getChildNodes();

                for (int j = 0; j < links.getLength(); j++) {
                    Node node = links.item(j);
                    if (node.getNodeName().contains(":"))
                        nsString = node.getNodeName().substring(0, node.getNodeName().indexOf(":") + 1);
                    else
                        nsString = "";

                    if (node.getNodeName().equalsIgnoreCase(nsString + "Link") && node.hasAttributes()) {
                        Node rel = node.getAttributes().getNamedItem("rel");

                        if (rel != null && rel.getNodeValue().trim().equalsIgnoreCase("deploy")) {
                            Node href = node.getAttributes().getNamedItem("href");

                            if (href != null) {
                                String endpoint = href.getNodeValue().trim();
                                String action = method.getAction(endpoint);
                                StringBuilder payload = new StringBuilder();

                                payload.append(
                                        "<DeployVAppParams powerOn=\"false\" xmlns=\"http://www.vmware.com/vcloud/v1.5\"/>");
                                method.waitFor(method.post(action, endpoint,
                                        method.getMediaTypeForActionDeployVApp(), payload.toString()));
                                break;
                            }
                        }
                    }
                }
            }
        }
    } finally {
        APITrace.end();
    }
}

From source file:org.dasein.cloud.vcloud.compute.vAppSupport.java

private @Nullable String getVDC(@Nonnull String vappId) throws CloudException, InternalException {
    vCloudMethod method = new vCloudMethod(getProvider());
    String xml = method.get("vApp", vappId);

    if (xml == null || xml.equals("")) {
        return null;
    }//from  ww w  .  ja v  a 2  s.co m
    Document doc = method.parseXML(xml);
    String docElementTagName = doc.getDocumentElement().getTagName();
    String nsString = "";
    if (docElementTagName.contains(":"))
        nsString = docElementTagName.substring(0, docElementTagName.indexOf(":") + 1);
    NodeList nodes = doc.getElementsByTagName(nsString + "VApp");

    if (nodes.getLength() < 1) {
        return null;
    }
    Node node = nodes.item(0);
    NodeList elements = node.getChildNodes();

    for (int i = 0; i < elements.getLength(); i++) {
        Node n = elements.item(i);
        if (n.getNodeName().contains(":"))
            nsString = n.getNodeName().substring(0, n.getNodeName().indexOf(":") + 1);
        else
            nsString = "";

        if (n.getNodeName().equalsIgnoreCase(nsString + "Link") && n.hasAttributes()) {
            Node rel = n.getAttributes().getNamedItem("rel");

            if (rel != null && rel.getNodeValue().trim().equals("up")) {
                Node type = n.getAttributes().getNamedItem("type");

                if (type != null && type.getNodeValue().trim().equals(method.getMediaTypeForVDC())) {
                    Node href = n.getAttributes().getNamedItem("href");

                    if (href != null) {
                        return getProvider().toID(href.getNodeValue().trim());
                    }
                }
            }
        }
    }
    return null;
}

From source file:org.dasein.cloud.vcloud.compute.vAppSupport.java

@Override
public VirtualMachine getVirtualMachine(@Nonnull String vmId) throws InternalException, CloudException {
    APITrace.begin(getProvider(), "VM.getVirtualMachine");
    try {//w  w  w . ja  v a2s .co  m
        vCloudMethod method = new vCloudMethod(getProvider());
        String xml = method.get("vApp", vmId);

        if (xml != null && !xml.equals("")) {
            Document doc = method.parseXML(xml);
            String docElementTagName = doc.getDocumentElement().getTagName();
            String nsString = "";
            if (docElementTagName.contains(":"))
                nsString = docElementTagName.substring(0, docElementTagName.indexOf(":") + 1);
            NodeList vmNodes = doc.getElementsByTagName(nsString + "Vm");

            if (vmNodes.getLength() < 1) {
                return null;
            }
            Node vmNode = vmNodes.item(0);
            NodeList vmElements = vmNode.getChildNodes();
            String vdc = null, parentVapp = null;

            for (int i = 0; i < vmElements.getLength(); i++) {
                Node n = vmElements.item(i);
                if (n.getNodeName().contains(":"))
                    nsString = n.getNodeName().substring(0, n.getNodeName().indexOf(":") + 1);
                else
                    nsString = "";

                if (n.getNodeName().equalsIgnoreCase(nsString + "Link") && n.hasAttributes()) {
                    Node rel = n.getAttributes().getNamedItem("rel");

                    if (rel != null && rel.getNodeValue().trim().equals("up")) {
                        Node type = n.getAttributes().getNamedItem("type");

                        if (type != null && type.getNodeValue().trim().equals(method.getMediaTypeForVApp())) {
                            Node href = n.getAttributes().getNamedItem("href");

                            if (href != null) {
                                parentVapp = getProvider().toID(href.getNodeValue().trim());
                                vdc = getVDC(parentVapp);
                            }
                        }
                    }
                }
            }
            if (vdc != null) {
                return toVirtualMachine(vdc, parentVapp, vmNode,
                        getProvider().getNetworkServices().getVlanSupport().listVlans());
            }
        }
        return null;
    } finally {
        APITrace.end();
    }
}

From source file:org.dasein.cloud.vcloud.compute.vAppSupport.java

private String parseVmId(NodeList vmNodes) {
    String vmId = "";
    Node vmNode = vmNodes.item(0);

    if (vmNode != null && vmNode.hasAttributes()) {
        Node vmHref = vmNode.getAttributes().getNamedItem("href");
        if (vmHref != null) {
            String vmUrl = vmHref.getNodeValue().trim();
            vmId = getProvider().toID(vmUrl);
        } else {/*from  w  ww  .  j a  va 2 s  .  co m*/
            vmId = null;
        }
    } else {
        vmId = null;
    }
    return vmId;
}

From source file:org.dasein.cloud.vcloud.compute.vAppSupport.java

@Override
public @Nonnull Iterable<VirtualMachine> listVirtualMachines() throws InternalException, CloudException {
    getProvider().hold();//from w w w .j a  va 2  s.com
    PopulatorThread<VirtualMachine> populator = new PopulatorThread<VirtualMachine>(
            new JiteratorPopulator<VirtualMachine>() {
                @Override
                public void populate(@Nonnull Jiterator<VirtualMachine> iterator) throws Exception {
                    try {
                        APITrace.begin(getProvider(), "VM.listVirtualMachines");
                        try {
                            Iterable<VLAN> vlans = getProvider().getNetworkServices().getVlanSupport()
                                    .listVlans();
                            vCloudMethod method = new vCloudMethod(getProvider());

                            for (DataCenter dc : method.listDataCenters()) {
                                String xml = method.get("vdc", dc.getProviderDataCenterId());

                                if (xml != null && !xml.equals("")) {
                                    Document doc = method.parseXML(xml);
                                    String docElementTagName = doc.getDocumentElement().getTagName();
                                    String nsString = "";
                                    if (docElementTagName.contains(":"))
                                        nsString = docElementTagName.substring(0,
                                                docElementTagName.indexOf(":") + 1);
                                    NodeList vdcs = doc.getElementsByTagName(nsString + "Vdc");

                                    if (vdcs.getLength() > 0) {
                                        NodeList attributes = vdcs.item(0).getChildNodes();

                                        for (int i = 0; i < attributes.getLength(); i++) {
                                            Node attribute = attributes.item(i);
                                            if (attribute.getNodeName().contains(":"))
                                                nsString = attribute.getNodeName().substring(0,
                                                        attribute.getNodeName().indexOf(":") + 1);
                                            else
                                                nsString = "";

                                            if (attribute.getNodeName()
                                                    .equalsIgnoreCase(nsString + "ResourceEntities")
                                                    && attribute.hasChildNodes()) {
                                                NodeList resources = attribute.getChildNodes();

                                                for (int j = 0; j < resources.getLength(); j++) {
                                                    Node resource = resources.item(j);

                                                    if (resource.getNodeName()
                                                            .equalsIgnoreCase(nsString + "ResourceEntity")
                                                            && resource.hasAttributes()) {
                                                        Node type = resource.getAttributes()
                                                                .getNamedItem("type");

                                                        if (type != null
                                                                && type.getNodeValue().equalsIgnoreCase(
                                                                        method.getMediaTypeForVApp())) {
                                                            Node href = resource.getAttributes()
                                                                    .getNamedItem("href");

                                                            loadVmsFor(dc.getProviderDataCenterId(),
                                                                    getProvider()
                                                                            .toID(href.getNodeValue().trim()),
                                                                    iterator, vlans);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        } finally {
                            APITrace.end();
                        }
                    } finally {
                        getProvider().release();
                    }
                }
            });
    populator.populate();
    return populator.getResult();
}

From source file:org.dasein.cloud.vcloud.compute.vAppSupport.java

private void loadVmsFor(@Nonnull String vdcId, @Nonnull String id, @Nonnull Jiterator<VirtualMachine> vms,
        @Nonnull Iterable<VLAN> vlans) throws InternalException, CloudException {
    vCloudMethod method = new vCloudMethod(getProvider());

    String xml = method.get("vApp", id);

    if (xml == null || xml.equals("")) {
        return;/*ww w.j a  va  2  s.  co  m*/
    }
    Document doc = method.parseXML(xml);
    String docElementTagName = doc.getDocumentElement().getTagName();
    String nsString = "";
    if (docElementTagName.contains(":"))
        nsString = docElementTagName.substring(0, docElementTagName.indexOf(":") + 1);
    NodeList vapps = doc.getElementsByTagName(nsString + "VApp");

    if (vapps.getLength() < 1) {
        return;
    }
    NodeList attributes = vapps.item(0).getChildNodes();

    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);
        if (attribute.getNodeName().contains(":"))
            nsString = attribute.getNodeName().substring(0, attribute.getNodeName().indexOf(":") + 1);
        else
            nsString = "";

        if (attribute.getNodeName().equals(nsString + "Children") && attribute.hasChildNodes()) {
            NodeList children = attribute.getChildNodes();

            for (int j = 0; j < children.getLength(); j++) {
                Node vmNode = children.item(j);

                if (vmNode.getNodeName().equalsIgnoreCase(nsString + "Vm") && vmNode.hasAttributes()) {
                    VirtualMachine vm = toVirtualMachine(vdcId, id, vmNode, vlans);

                    if (vm != null) {
                        vms.push(vm);
                    }
                }
            }
        }
    }
}

From source file:org.dasein.cloud.vcloud.compute.vAppSupport.java

@Override
public void reboot(@Nonnull String vmId) throws CloudException, InternalException {
    APITrace.begin(getProvider(), "VM.reboot");
    try {//w w  w. j av  a 2 s . c  om
        vCloudMethod method = new vCloudMethod(getProvider());
        String xml = method.get("vApp", vmId);

        if (xml != null) {
            Document doc = method.parseXML(xml);
            String docElementTagName = doc.getDocumentElement().getTagName();
            String nsString = "";
            if (docElementTagName.contains(":"))
                nsString = docElementTagName.substring(0, docElementTagName.indexOf(":") + 1);
            NodeList nodes = doc.getElementsByTagName(nsString + "VApp");

            if (nodes.getLength() > 0) {
                for (int i = 0; i < nodes.getLength(); i++) {
                    Node node = nodes.item(i);
                    if (node.getNodeName().contains(":"))
                        nsString = node.getNodeName().substring(0, node.getNodeName().indexOf(":") + 1);
                    else
                        nsString = "";

                    if (node.getNodeName().equalsIgnoreCase(nsString + "Link") && node.hasAttributes()) {
                        Node rel = node.getAttributes().getNamedItem("rel");

                        if (rel != null && rel.getNodeValue().trim().equalsIgnoreCase("power:reboot")) {
                            Node href = node.getAttributes().getNamedItem("href");

                            if (href != null) {
                                String endpoint = href.getNodeValue().trim();
                                String action = method.getAction(endpoint);

                                method.post(action, endpoint, null, null);
                                break;
                            }
                        }
                    }
                }
            } else {
                nodes = doc.getElementsByTagName(nsString + "Vm");
                if (nodes.getLength() > 0) {
                    Node vmNode = nodes.item(0);
                    if (vmNode != null && vmNode.hasChildNodes()) {
                        NodeList links = vmNode.getChildNodes();
                        for (int i = 0; i < links.getLength(); i++) {
                            Node link = links.item(i);
                            if (link.getNodeName().equalsIgnoreCase(nsString + "Link")
                                    && link.hasAttributes()) {
                                Node rel = link.getAttributes().getNamedItem("rel");

                                if (rel != null && rel.getNodeValue().trim().equalsIgnoreCase("power:reboot")) {
                                    Node href = link.getAttributes().getNamedItem("href");

                                    if (href != null) {
                                        String endpoint = href.getNodeValue().trim();
                                        String action = method.getAction(endpoint);

                                        method.post(action, endpoint, null, null);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } finally {
        APITrace.end();
    }
}