Example usage for org.dom4j Element attributes

List of usage examples for org.dom4j Element attributes

Introduction

In this page you can find the example usage for org.dom4j Element attributes.

Prototype

List<Attribute> attributes();

Source Link

Document

Returns the Attribute instances this element contains as a backed List so that the attributes may be modified directly using the List interface.

Usage

From source file:com.testmax.handler.ActionHandler.java

License:CDDL license

private Element replaceData(Element data) {
    //ItemUtility iu=new ItemUtility();
    String xml = data.asXML();/*from w  w w . j  a v  a 2 s .  c om*/
    List<DefaultAttribute> attrs = data.attributes();
    for (DefaultAttribute attr : attrs) {
        xml = xml.replaceAll("@" + attr.getQualifiedName(), attr.getStringValue().trim());
    }
    Element newElm = iu.getRootElementFromXML(xml);

    return newElm;
}

From source file:com.testmax.handler.ActionHandler.java

License:CDDL license

public boolean executeValidator(Element data) {

    String validator = "";
    Element globalDataSet = null;
    //ItemUtility utl= new ItemUtility();
    boolean hasVariables = false;
    for (Element elm : vlidatorList) {
        //System.out.println(elm.asXML());
        List<Element> vElm = elm.elements();
        List<Element> vQuery = new ArrayList<Element>();
        List<Element> vApi = new ArrayList<Element>();
        List<Element> vInput = new ArrayList<Element>();
        List<Element> vAssert = new ArrayList<Element>();
        List<Element> vSetup = new ArrayList<Element>();
        List<Element> vWs = new ArrayList<Element>();
        List<Element> vJunit = new ArrayList<Element>();
        List<Element> vSpark = new ArrayList<Element>();
        List<Element> vCommand = new ArrayList<Element>();
        List<Element> variables = new ArrayList<Element>();
        validator = elm.attributeValue("name");
        for (Element vEach : vElm) {
            if (vEach.getName().equalsIgnoreCase("sql")) {

                //replace sql lib if included
                String includes = vEach.attributeValue("includes");
                if (includes != null && !includes.isEmpty()) {
                    vQuery.add(iu.replaceIncludeInSqlQuery(vEach));
                } else {
                    vQuery.add(vEach);// w  ww.  j av  a2  s.c  o m
                }
            } else if (vEach.getName().equalsIgnoreCase("ws")) {
                vWs.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("junit")
                    || vEach.getName().equalsIgnoreCase("testng")) {
                vJunit.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("spark")) {
                vSpark.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("command")) {
                vCommand.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("api")) {
                vApi.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("input")) {
                vInput.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("assert")) {
                vAssert.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("setup")) {
                //replace sql lib if included
                String includes = vEach.attributeValue("includes");
                if (includes != null && !includes.isEmpty()) {
                    vSetup.add(iu.replaceIncludeInSqlQuery(vEach));
                } else {
                    vSetup.add(vEach);
                }
            } else if (vEach.getName().equalsIgnoreCase("variables")) {
                hasVariables = true;
                //fillup as variable for each attribute
                if (data != null) {
                    List<DefaultAttribute> attrs = data.attributes();
                    for (DefaultAttribute attr : attrs) {
                        validator = validator.replaceAll("@" + attr.getQualifiedName().trim(),
                                data.attributeValue(attr.getQualifiedName()).trim());
                    }

                } else {

                    vEach = this.addRandomElementData(vEach);

                }

                variables.add(vEach);
            }
        }
        //if dataset presents and variables are not defined
        //if(data!=null){
        Element vVars = iu.getRootElementFromXML("<variables></variables>");

        //fillup as variable for each attribute
        if (data != null) {
            List<DefaultAttribute> attrs = data.attributes();
            for (DefaultAttribute attr : attrs) {
                Element sData = vVars.addElement("var");
                sData.addAttribute("id", attr.getQualifiedName().trim());
                sData.addAttribute("value", data.attributeValue(attr.getQualifiedName()).trim());
                validator = validator.replaceAll("@" + attr.getQualifiedName().trim(),
                        data.attributeValue(attr.getQualifiedName()).trim());
            }

        } else {
            vVars = this.addRandomElementData(vVars);
        }
        variables.add(vVars);

        //}

        List<Element> itemlist = new ArrayList();
        List<Element> varlist = new ArrayList();
        for (Element wsProp : variables) {
            if (wsProp.getName().equalsIgnoreCase("variables")) {
                List<Element> elList = wsProp.elements();
                for (Element el : elList) {
                    if (el.getName().equalsIgnoreCase("var")) {
                        varlist.add(el);
                    } else if (el.getName().equalsIgnoreCase("item")) {
                        itemlist.add(el);
                    }
                }

            }
        }
        //replace items id in the validator level
        if (!itemlist.isEmpty()) {
            if (!vWs.isEmpty())
                vWs = iu.replaceValidatorElementItemId(vWs, itemlist);
            if (!vQuery.isEmpty())
                vQuery = iu.replaceValidatorElementItemId(vQuery, itemlist);
            if (!vApi.isEmpty())
                vApi = iu.replaceValidatorElementItemId(vApi, itemlist);
            if (!vSpark.isEmpty())
                vSpark = iu.replaceValidatorElementItemId(vSpark, itemlist);
            if (!vJunit.isEmpty())
                vJunit = iu.replaceValidatorElementItemId(vJunit, itemlist);
            if (!vSetup.isEmpty())
                vSetup = iu.replaceValidatorElementItemId(vSetup, itemlist);
            if (!vAssert.isEmpty())
                vAssert = iu.replaceValidatorElementItemId(vAssert, itemlist);
        }
        //Replace variables
        if (!varlist.isEmpty()) {
            if (!vWs.isEmpty())
                vWs = iu.replaceValidatorElementVariables(vWs, varlist, this.resultParamSet,
                        this.resultDataSet);
            if (!vQuery.isEmpty())
                vQuery = iu.replaceValidatorElementVariables(vQuery, varlist, this.resultParamSet,
                        this.resultDataSet);
            if (!vJunit.isEmpty())
                vJunit = iu.replaceValidatorElementVariables(vJunit, varlist, this.resultParamSet,
                        this.resultDataSet);
            if (!vApi.isEmpty())
                vApi = iu.replaceValidatorElementVariables(vApi, varlist, this.resultParamSet,
                        this.resultDataSet);
            if (!vSetup.isEmpty())
                vSetup = iu.replaceValidatorElementVariables(vSetup, varlist, this.resultParamSet,
                        this.resultDataSet);
            if (!vAssert.isEmpty())
                vAssert = iu.replaceValidatorElementVariables(vAssert, varlist, this.resultParamSet,
                        this.resultDataSet);
        }

        //Execute Webservice call
        vQuery = this.executeWs(vWs, vQuery, varlist);

        //Execute API call
        this.executeAPI(vApi);

        //Execute SQL / Validator Query
        this.executevQuery(vQuery, vInput, validator);

        // execute Setup
        this.executeSetup(vSetup);

        if (!this.isMultiThread) {
            //Execute dataset          
            try {
                datasetIndex = new Integer(data.attributeValue("datasetIndex"));
            } catch (Exception e) {
                datasetIndex = 0;
            }

            //Execute Junit
            if (vJunit.size() > 0) {
                this.executeJunit(vJunit, varlist, itemlist, validator);
            }

            //Execute Spark
            if (vSpark.size() > 0) {
                this.executeSpark(vSpark, varlist, validator);
            }
            //Execute Command
            this.executeCommand(vCommand);

            //execute Asserts
            this.executeAssert(vAssert, validator, this.wsName, datasetIndex, String.valueOf(datasetIndex),
                    null);
        }

    }

    return (true);

}

From source file:com.testmax.handler.ActionHandler.java

License:CDDL license

public boolean executeValidatorPrePost(Element data, boolean isPreJunit) {

    String validator = "";
    Element globalDataSet = null;
    //ItemUtility utl= new ItemUtility();
    boolean hasVariables = false;
    boolean isJunitFound = false;
    for (Element elm : vlidatorList) {
        //System.out.println(elm.asXML());
        List<Element> vElm = elm.elements();
        List<Element> vQuery = new ArrayList<Element>();
        List<Element> vApi = new ArrayList<Element>();
        List<Element> vInput = new ArrayList<Element>();
        List<Element> vAssert = new ArrayList<Element>();
        List<Element> vSetup = new ArrayList<Element>();
        List<Element> vWs = new ArrayList<Element>();
        List<Element> vJunit = new ArrayList<Element>();
        List<Element> vSpark = new ArrayList<Element>();
        List<Element> vCommand = new ArrayList<Element>();
        List<Element> variables = new ArrayList<Element>();
        validator = elm.attributeValue("name");
        for (Element vEach : vElm) {
            if (vEach.getName().equalsIgnoreCase("sql")) {

                //replace sql lib if included
                String includes = vEach.attributeValue("includes");
                if (includes != null && !includes.isEmpty()) {
                    vQuery.add(iu.replaceIncludeInSqlQuery(vEach));
                } else {
                    vQuery.add(vEach);// ww  w.  j  ava  2s  . c  o  m
                }
            } else if (vEach.getName().equalsIgnoreCase("ws")) {
                vWs.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("junit")
                    || vEach.getName().equalsIgnoreCase("testng")) {
                vJunit.add(vEach);
                isJunitFound = true;
            } else if (vEach.getName().equalsIgnoreCase("spark")) {
                vSpark.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("command")) {
                vCommand.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("api")) {
                vApi.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("input")) {
                vInput.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("assert")) {
                vAssert.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("setup")) {
                //replace sql lib if included
                String includes = vEach.attributeValue("includes");
                if (includes != null && !includes.isEmpty()) {
                    vSetup.add(iu.replaceIncludeInSqlQuery(vEach));
                } else {
                    vSetup.add(vEach);
                }
            } else if (vEach.getName().equalsIgnoreCase("variables")) {
                hasVariables = true;
                //fillup as variable for each attribute
                if (data != null) {
                    List<DefaultAttribute> attrs = data.attributes();
                    for (DefaultAttribute attr : attrs) {
                        validator = validator.replaceAll("@" + attr.getQualifiedName().trim(),
                                data.attributeValue(attr.getQualifiedName()).trim());
                    }

                } else {

                    vEach = this.addRandomElementData(vEach);

                }

                variables.add(vEach);
            }
        }
        //if dataset presents and variables are not defined
        //if(data!=null){
        Element vVars = iu.getRootElementFromXML("<variables></variables>");

        //fillup as variable for each attribute
        if (data != null) {
            List<DefaultAttribute> attrs = data.attributes();
            for (DefaultAttribute attr : attrs) {
                Element sData = vVars.addElement("var");
                sData.addAttribute("id", attr.getQualifiedName().trim());
                sData.addAttribute("value", data.attributeValue(attr.getQualifiedName()).trim());
                validator = validator.replaceAll("@" + attr.getQualifiedName().trim(),
                        data.attributeValue(attr.getQualifiedName()).trim());
            }

        } else {
            vVars = this.addRandomElementData(vVars);
        }
        variables.add(vVars);

        //}

        List<Element> itemlist = new ArrayList();
        List<Element> varlist = new ArrayList();
        for (Element wsProp : variables) {
            if (wsProp.getName().equalsIgnoreCase("variables")) {
                List<Element> elList = wsProp.elements();
                for (Element el : elList) {
                    if (el.getName().equalsIgnoreCase("var")) {
                        varlist.add(el);
                    } else if (el.getName().equalsIgnoreCase("item")) {
                        itemlist.add(el);
                    }
                }

            }
        }
        //replace items id in the validator level
        if (!itemlist.isEmpty()) {
            if (!vWs.isEmpty())
                vWs = iu.replaceValidatorElementItemId(vWs, itemlist);
            if (!vQuery.isEmpty())
                vQuery = iu.replaceValidatorElementItemId(vQuery, itemlist);
            if (!vApi.isEmpty())
                vApi = iu.replaceValidatorElementItemId(vApi, itemlist);
            if (!vSpark.isEmpty())
                vSpark = iu.replaceValidatorElementItemId(vSpark, itemlist);
            if (!vJunit.isEmpty())
                vJunit = iu.replaceValidatorElementItemId(vJunit, itemlist);
            if (!vSetup.isEmpty())
                vSetup = iu.replaceValidatorElementItemId(vSetup, itemlist);
            if (!vAssert.isEmpty())
                vAssert = iu.replaceValidatorElementItemId(vAssert, itemlist);
        }
        //Replace variables
        if (!varlist.isEmpty()) {
            if (!vWs.isEmpty())
                vWs = iu.replaceValidatorElementVariables(vWs, varlist, this.resultParamSet,
                        this.resultDataSet);
            if (!vQuery.isEmpty())
                vQuery = iu.replaceValidatorElementVariables(vQuery, varlist, this.resultParamSet,
                        this.resultDataSet);
            if (!vJunit.isEmpty())
                vJunit = iu.replaceValidatorElementVariables(vJunit, varlist, this.resultParamSet,
                        this.resultDataSet);
            if (!vApi.isEmpty())
                vApi = iu.replaceValidatorElementVariables(vApi, varlist, this.resultParamSet,
                        this.resultDataSet);
            if (!vSetup.isEmpty())
                vSetup = iu.replaceValidatorElementVariables(vSetup, varlist, this.resultParamSet,
                        this.resultDataSet);
            if (!vAssert.isEmpty())
                vAssert = iu.replaceValidatorElementVariables(vAssert, varlist, this.resultParamSet,
                        this.resultDataSet);
        }

        if (!isPreJunit && vJunit.size() == 0 && !isJunitFound) {
            continue;
        } else if (isPreJunit && vJunit.size() > 0) {
            break;
        }

        //if(!isPreJunit &&vJunit.size()>0){
        //Execute Webservice call
        if (vWs.size() > 0) {
            vQuery = this.executeWs(vWs, vQuery, varlist);
        }

        //Execute API call
        if (vApi.size() > 0) {
            this.executeAPI(vApi);
        }

        //Execute SQL / Validator Query
        if (vQuery.size() > 0) {
            this.executevQuery(vQuery, vInput, validator);
        }

        // execute Setup
        if (vSetup.size() > 0) {
            this.executeSetup(vSetup);
        }

        //Execute Command
        if (vCommand.size() > 0) {
            this.executeCommand(vCommand);
        }

        if (!this.isMultiThread) {
            //Execute dataset          
            try {
                datasetIndex = new Integer(data.attributeValue("datasetIndex"));
            } catch (Exception e) {
                datasetIndex = 0;
            }

            //execute Asserts
            this.executeAssert(vAssert, validator, this.wsName, datasetIndex, String.valueOf(datasetIndex),
                    null);
        }

    }

    return (true);

}

From source file:com.testmax.handler.ActionHandler.java

License:CDDL license

public JunitHandler executeJunitAssertData(JunitHandler handler) {
    //JunitHandler handler=null;
    HashMap<String, String> junittmpvars = null;
    Element data = handler.getThreadDataElement();
    String threadIndex = handler.getThreadIndex();
    String validator = "";
    //ItemUtility utl= new ItemUtility();
    boolean hasVariables = false;
    Element elm = handler.getValidatorElement();
    //for(Element elm: vlidatorList){
    System.out.println(elm.asXML());
    List<Element> vElm = elm.elements();
    List<Element> vAssert = new ArrayList<Element>();
    List<Element> variables = new ArrayList<Element>();
    validator = elm.attributeValue("name");
    for (Element vEach : vElm) {
        if (vEach.getName().equalsIgnoreCase("assert")) {
            vAssert.add(vEach);//from  w ww. j  av  a 2 s .  c  o m
        } else if (vEach.getName().equalsIgnoreCase("variables")) {
            //System.out.println(vEach.asXML());
            variables.add(vEach);
        }
    }
    //if dataset presents and variables are not defined
    if (data != null) {
        Element vVars = iu.getRootElementFromXML("<variables></variables>");

        //fillup as variable for each attribute
        if (data != null) {
            List<DefaultAttribute> attrs = data.attributes();
            for (DefaultAttribute attr : attrs) {
                Element sData = vVars.addElement("var");
                sData.addAttribute("id", attr.getQualifiedName().trim());
                sData.addAttribute("value", data.attributeValue(attr.getQualifiedName()).trim());
                validator = validator.replaceAll("@" + attr.getQualifiedName().trim(),
                        data.attributeValue(attr.getQualifiedName()).trim());
            }

        }
        //System.out.println(vVars.asXML());
        variables.add(vVars);

    }

    List<Element> itemlist = new ArrayList();
    List<Element> varlist = new ArrayList();
    for (Element wsProp : variables) {
        if (wsProp.getName().equalsIgnoreCase("variables")) {
            System.out.println(wsProp.asXML());
            List<Element> elList = wsProp.elements();
            for (Element el : elList) {
                if (el.getName().equalsIgnoreCase("var")) {
                    varlist.add(el);
                } else if (el.getName().equalsIgnoreCase("item")) {
                    itemlist.add(el);
                }
            }
            //break;
        }
    }
    //replace items id in the validator level
    if (!itemlist.isEmpty()) {
        if (!vAssert.isEmpty())
            vAssert = iu.replaceValidatorElementItemId(vAssert, itemlist);
    }
    //Replace variables
    if (!varlist.isEmpty()) {
        if (!vAssert.isEmpty()) {
            vAssert = iu.replaceValidatorElementVariables(vAssert, varlist, this.resultParamSet,
                    this.resultDataSet);
        }
    }

    //Execute Asserts          
    try {
        datasetIndex = new Integer(data.attributeValue("datasetIndex"));
    } catch (Exception e) {
        datasetIndex = 0;
    }

    synchronized (this.resultDataSet) {
        if (BaseHandler.threadResult != null) {
            HashMap<String, String> resultdata = BaseHandler.threadResult.get(handler.getHandlerId());
            if (resultdata != null && resultdata.size() > 0) {
                junittmpvars = iu.extractOldJunitResultDataSet(resultDataSet, resultdata);
                if (junittmpvars != null && !junittmpvars.isEmpty()) {
                    for (String key : junittmpvars.keySet()) {
                        resultDataSet.remove(key);
                    }
                }
                for (Object key : resultdata.keySet()) {
                    this.resultDataSet.put(key.toString(), resultdata.get(key));
                }
            }

            this.executeAssert(vAssert, validator, this.wsName, datasetIndex, threadIndex, handler);
            this.junitAssertCounter++;
            itemlist = null;
            varlist = null;
            variables = null;

            //Reset resultdataset
            if (junittmpvars != null && !junittmpvars.isEmpty()) {
                for (String key : junittmpvars.keySet()) {
                    this.resultDataSet.put(key.toString(), junittmpvars.get(key));
                }
            }
        }
    }

    return (handler);

}

From source file:com.testmax.handler.ActionHandler.java

License:CDDL license

public ArrayList<JunitHandler> executeJunitThreadData(Element data) {

    ArrayList<JunitHandler> junitHandlers = new ArrayList<JunitHandler>();
    String validator = "";
    //ItemUtility utl= new ItemUtility();
    boolean hasVariables = false;
    for (Element elm : vlidatorList) {
        JunitHandler handler = null;//  w w w .  j a  v a  2  s . c o m
        System.out.println(elm.asXML());
        List<Element> vElm = elm.elements();
        //List<Element> vQuery=new ArrayList<Element>();
        List<Element> vAssert = new ArrayList<Element>();
        List<Element> vJunit = new ArrayList<Element>();
        List<Element> variables = new ArrayList<Element>();
        validator = elm.attributeValue("name");
        for (Element vEach : vElm) {
            /*if(vEach.getName().equalsIgnoreCase("sql")){
                       
               //replace sql lib if included
               String includes=vEach.attributeValue("includes");
               if(includes!=null &&!includes.isEmpty()){
                  vQuery.add(utl.replaceIncludeInSqlQuery(vEach));
               }else{
                  vQuery.add(vEach);
               }
            }else */
            if (vEach.getName().equalsIgnoreCase("junit")) {
                vJunit.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("assert")) {
                vAssert.add(vEach);
            } else if (vEach.getName().equalsIgnoreCase("variables")) {
                variables.add(iu.replaceData(vEach, data));
            }
        }
        //if dataset presents and variables are not defined
        if (data != null) {
            Element vVars = iu.getRootElementFromXML("<variables></variables>");

            //fillup as variable for each attribute
            if (data != null) {
                List<DefaultAttribute> attrs = data.attributes();
                for (DefaultAttribute attr : attrs) {
                    Element sData = vVars.addElement("var");
                    sData.addAttribute("id", attr.getQualifiedName().trim());
                    sData.addAttribute("value", data.attributeValue(attr.getQualifiedName()).trim());
                }
            }
            //System.out.println(vVars.asXML());
            variables.add(vVars);
        }

        List<Element> itemlist = new ArrayList();
        List<Element> varlist = new ArrayList();
        for (Element wsProp : variables) {
            if (wsProp.getName().equalsIgnoreCase("variables")) {
                List<Element> elList = wsProp.elements();
                for (Element el : elList) {
                    if (el.getName().equalsIgnoreCase("var")) {
                        varlist.add(el);
                    } else if (el.getName().equalsIgnoreCase("item")) {
                        itemlist.add(el);
                    }
                }

            }
        }
        //replace items id in the validator level
        if (!itemlist.isEmpty()) {

            if (!vJunit.isEmpty()) {
                vJunit = iu.replaceValidatorElementItemId(vJunit, itemlist);
            }
        }

        //Execute Asserts   
        if (handler == null && (vJunit.size() > 0)) {
            handler = this.getThreadHandler(vJunit, varlist, itemlist, validator);
            //handler.setValidatorElement(elm);
            //handler.setThreadDataElement(data);
            //handler.setThreadIndex(data.attributeValue("driver")+"-"+data.attributeValue("datasetIndex"));
        }
        if (handler == null && vAssert.size() > 0 && vJunit.size() == 0) {
            handler = this.getAssertThreadHandler(varlist, itemlist);
            //handler.setValidatorElement(elm);
            //handler.setThreadDataElement(data);
            //handler.setThreadIndex(data.attributeValue("driver")+"-"+data.attributeValue("datasetIndex"));
        }
        if (handler != null) {
            handler.setValidatorElement(elm);
            handler.setThreadDataElement(data);
            handler.setThreadIndex(data.attributeValue("driver") + "-" + data.attributeValue("datasetIndex"));
            junitHandlers.add(handler);
        }

    }

    return (junitHandlers);

}

From source file:com.testmax.util.ItemUtility.java

License:CDDL license

public Element replaceData(Element target, Element data) {
    //ItemUtility iu=new ItemUtility();
    String xml = target.asXML();/*from  w w w. j  a  v a 2s . c o m*/
    List<DefaultAttribute> attrs = data.attributes();
    for (DefaultAttribute attr : attrs) {
        xml = xml.replaceAll("@" + attr.getQualifiedName(), attr.getStringValue().trim());
    }
    Element newElm = this.getRootElementFromXML(xml);

    return newElm;
}

From source file:com.tustar.utils.NSGenerate.java

License:Apache License

/**
 * Translate element to component./*from  w  ww  .  j a va2 s. co m*/
 * 
 * @param root
 * @return
 */
public static List<Component> element2Components(Element root) {

    List<Component> components = new LinkedList<Component>();
    // Root component
    List<Attribute> attributes = root.attributes();
    for (Attribute attribute : attributes) {

        String name = attribute.getName();
        String value = attribute.getValue();

        if (name.equals("id")) {
            Component component = new Component();
            String id = "";
            if (LayoutUtils.isAndroidId(value)) {
                id = "android.R.id." + LayoutUtils.getIdInR(value);
            } else {
                id = "R.id." + LayoutUtils.getIdInR(value);
            }
            component.setId(id);
            component.setName("m" + LayoutUtils.cameId(value));
            component.setType(root.getName());
            components.add(component);
        }
    }

    // Elements
    List<Element> elements = root.elements();
    for (Element element : elements) {

        // Container component
        String type = element.getName();
        if (LayoutUtils.isContainerLayout(type)) {
            components.addAll(element2Components(element));
            continue;
        }

        // Include view component
        if (LayoutUtils.isIncludeLayout(type)) {
            List<Attribute> stubAttributes = element.attributes();
            String id = "";
            String cName = "";
            String stubLayout = "";
            for (Attribute attribute : stubAttributes) {

                String name = attribute.getName();
                String value = attribute.getValue();

                if (name.equals("id")) {
                    if (LayoutUtils.isAndroidId(value)) {
                        id = "android.R.id." + LayoutUtils.getIdInR(value);
                    } else {
                        id = "R.id." + LayoutUtils.getIdInR(value);
                    }
                    cName = value;
                    continue;
                }

                if (name.equals("layout")) {
                    stubLayout = LayoutUtils.getStubLayout(value);
                }
            }

            if (id == null || id.length() == 0) {
                Log.o(TAG, "element2Components :: ", type + " " + stubLayout + " id is empty");
                components.addAll(layout2Components(stubLayout));
            } else {
                Log.o(TAG, "element2Components :: ", type + " " + stubLayout + " id is normal");
                Component component = new Component();
                component.setId(id);
                component.setName("m" + LayoutUtils.cameId(cName));
                component.setType(LayoutUtils.xmlName2ClassName(CLASS_NAME_PREFIX, stubLayout));
                component.setInclude(true);
                components.add(component);
            }
            continue;
        }

        // ViewStub view component
        if (LayoutUtils.isViewStubLayout(type)) {
            List<Attribute> stubAttributes = element.attributes();
            String id = "";
            String cName = "";
            String stubLayout = "";
            for (Attribute attribute : stubAttributes) {

                String name = attribute.getName();
                String value = attribute.getValue();

                if (name.equals("id")) {
                    if (LayoutUtils.isAndroidId(value)) {
                        id = "android.R.id." + LayoutUtils.getIdInR(value);
                    } else {
                        id = "R.id." + LayoutUtils.getIdInR(value);
                    }
                    cName = value;
                    continue;
                }

                if (name.equals("layout")) {
                    stubLayout = LayoutUtils.getStubLayout(value);
                }
            }

            if (id == null || id.length() == 0) {
                Log.o(TAG, "element2Components :: ", type + " " + stubLayout + " id is empty");
                components.addAll(layout2Components(stubLayout));
            } else {
                Log.o(TAG, "element2Components :: ", type + " " + stubLayout + " id is normal");
                // ViewStub
                Component viewStub = new Component();
                viewStub.setId(id);
                viewStub.setName("m" + LayoutUtils.cameId(cName));
                viewStub.setType(type);
                components.add(viewStub);

                // Layout
                Component component = new Component();
                component.setId("m" + LayoutUtils.cameId(cName));
                component.setName("m" + LayoutUtils.cameId(cName) + "Layout");
                component.setType(LayoutUtils.xmlName2ClassName(CLASS_NAME_PREFIX, stubLayout));
                component.setStubView(true);
                components.add(component);
            }

            continue;
        }

        // Normal
        List<Attribute> stubAttributes = element.attributes();
        for (Attribute attribute : stubAttributes) {

            String name = attribute.getName();
            String value = attribute.getValue();
            if (name.equals("id")) {
                Component component = new Component();
                String id = "";
                if (LayoutUtils.isAndroidId(value)) {
                    id = "android.R.id." + LayoutUtils.getIdInR(value);
                } else {
                    id = "R.id." + LayoutUtils.getIdInR(value);
                }
                component.setId(id);
                component.setName("m" + LayoutUtils.cameId(value));
                component.setType(element.getName());
                components.add(component);
            }
        }
    }

    return components;
}

From source file:com.webslingerz.jpt.PageTemplateImpl.java

License:Open Source License

/**
 * With all of our namespace woes, getting an XPath expression to work has
 * proven futile, so we'll recurse through the tree ourselves to find what
 * we need./*  w w w.  j  a  v  a  2  s  .co  m*/
 */
private void findSlots(Element element, Map<String, Slot> slots) {
    // System.err.println( "element: " + element.getName() );
    for (Iterator i = element.attributes().iterator(); i.hasNext();) {
        Attribute attribute = (Attribute) i.next();
        // System.err.println( "\t" + attribute.getName() + "\t" +
        // attribute.getQualifiedName() );
    }

    // Look for our attribute
    // String qualifiedAttributeName = this.metalNamespacePrefix +
    // ":fill-slot";
    // String name = element.attributeValue( qualifiedAttributeName );
    String name = element.attributeValue("fill-slot");
    if (name != null) {
        slots.put(name, new SlotImpl(element));
    }

    // Recurse into child elements
    for (Iterator i = element.elementIterator(); i.hasNext();) {
        findSlots((Element) i.next(), slots);
    }
}

From source file:com.zimbra.cs.account.DataSourceConfig.java

License:Open Source License

private DataSourceConfig read(Element element) throws IOException {
    for (Object obj : element.attributes()) {
        Attribute attr = (Attribute) obj;
        String name = attr.getName();
        if (name.equals(SYNC_ALL_FOLDERS)) {
            syncAllFolders = Boolean.valueOf(attr.getValue());
        } else {//from   ww  w  .  j  a va2s .c om
            throw invalidConfig("Unrecognized attribute name: " + name);
        }
    }
    for (Object obj : element.elements()) {
        Element el = (Element) obj;
        String name = el.getName();
        if (name.equals(SERVICE)) {
            services.add(new Service().read(el));
        } else {
            throw invalidConfig("Unrecognized element name: " + name);
        }
    }
    return this;
}

From source file:cz.muni.stanse.utils.xmlpatterns.XMLAlgo.java

License:GNU General Public License

/**
 * Check if two elements are (recursively) equal
 *
 * TODO: remove and use equality tester from dom4j pkg
 *
 * @param e1 first element//from  w  ww  .ja  v  a  2 s . c o m
 * @param e2 second element
 */
public static boolean equalElements(final Element e1, final Element e2) {
    if (!e1.getName().equals(e2.getName()))
        return false;
    if (!e1.getText().equals(e2.getText()))
        return false;

    for (final Object attrObj : e1.attributes()) {
        final Attribute attr = (Attribute) attrObj;
        if (!attr.getName().equals("bl") && !attr.getName().equals("bc")
                && !attr.getValue().equals(e2.attributeValue(attr.getName())))
            return false;
    }

    final Iterator i = e1.elementIterator();
    final Iterator j = e2.elementIterator();
    while (i.hasNext() && j.hasNext())
        if (!equalElements((Element) i.next(), (Element) j.next()))
            return false;
    if (i.hasNext() || j.hasNext())
        return false;

    return true;
}