Example usage for org.dom4j Element attribute

List of usage examples for org.dom4j Element attribute

Introduction

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

Prototype

Attribute attribute(QName qName);

Source Link

Document

DOCUMENT ME!

Usage

From source file:com.haulmont.yarg.structure.xml.impl.DefaultXmlReader.java

License:Apache License

private void parseQueries(Element bandElement, BandBuilder bandDefinitionBuilder) {
    Element reportQueriesElement = bandElement.element("queries");

    if (reportQueriesElement != null) {
        List<Element> reportQueryElements = reportQueriesElement.elements("query");
        for (Element queryElement : reportQueryElements) {
            String script = queryElement.element("script").getText();
            String type = queryElement.attribute("type").getText();
            String queryName = queryElement.attribute("name").getText();

            bandDefinitionBuilder.query(queryName, script, type);
        }/*from   ww w  . java2 s.co m*/
    }
}

From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java

License:Apache License

/**
 * ???//from  w  ww .j  a va2 s.  c o  m
 *
 * @param element
 *            
 * @param attributeName
 *            ??
 * @return 
 */
public String getAttributeValue(Element element, String attributeName) {
    Attribute Attribute = element.attribute(attributeName);
    String attributeValue = Attribute.getValue();
    return attributeValue;
}

From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java

License:Apache License

/**
 * ???/*from   w w w .  j a  v a  2  s . c o  m*/
 *
 * @param element
 *            
 * @param attributeName
 *            ??
 * @return ?
 */
public void setAttributeValue(Element element, String attributeName, String attributeValue) {
    Attribute attribute = element.attribute(attributeName);
    attribute.setValue(attributeValue);
}

From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java

License:Apache License

/**
 *
 * @param element/*from ww  w. j  av  a  2  s  . c  om*/
 * @param attributeName
 */
public boolean deleteAllAttribute(Element element, String attributeName) {
    Attribute attribute = (Attribute) element.attribute(attributeName);
    boolean deleteFlag = element.remove(attribute);
    return deleteFlag;
}

From source file:com.hihsoft.baseclass.service.impl.InitFrameworkServiceImpl.java

License:Apache License

private void getObjMap(Document doc) throws Exception {
    // Document doc = getDoc();
    // //from www .  ja v  a2  s . c  o  m
    Element rootElement = xmlUtil.getRootElement(doc).element("models");
    // model?
    List<?> modelList = xmlUtil.elementList(rootElement);
    Iterator<?> modelIt = modelList.iterator();
    // ?,XmlObject?
    // objMap = new HashMap();
    while (modelIt.hasNext()) {
        Element model = (Element) modelIt.next();
        String modelClass = model.attribute("class").getValue();
        // ?
        List<?> objList = xmlUtil.elementList(model);
        Iterator<?> objIt = objList.iterator();
        while (objIt.hasNext()) {
            XmlObject xmlObj = new XmlObject();
            Element object = (Element) objIt.next();
            xmlObj.setObject(object.attribute("id").getValue());
            if (object.attribute("isload") != null) {
                xmlObj.setIsload(object.attribute("isload").getValue());
            }
            xmlObj.setModel(modelClass);
            // 
            xmlObj.setPropertys(getPropertys(object));
            if (objMap.containsKey(xmlObj.getObject())) {
                throw new Exception("id:'" + xmlObj.getObject() + "'??");
            }
            objMap.put(xmlObj.getObject(), xmlObj);
        }
    }
}

From source file:com.hihsoft.baseclass.service.impl.InitFrameworkServiceImpl.java

License:Apache License

public Map<String, Object> getPropertys(Element element) throws Exception {
    List<?> proList = xmlUtil.elementList(element);
    Iterator<?> proIt = proList.iterator();
    Map<String, Object> propertyMap = new HashMap<String, Object>();
    while (proIt.hasNext()) {
        Element proElen = (Element) proIt.next();
        XmlProperty pro = new XmlProperty();
        pro.setName(proElen.attribute("name").getValue());
        if (proElen.attribute("parent") != null) {
            pro.setParent(proElen.attribute("parent").getValue());
        }//from www  .j  a  v a  2 s .co m
        if (proElen.attribute("property") != null) {
            pro.setProperty(proElen.attribute("property").getValue());
        }
        if (proElen.attribute("value") != null) {
            pro.setValue(proElen.attribute("value").getValue());
        }
        propertyMap.put(pro.getName(), pro);
    }
    return propertyMap;
}

From source file:com.hyron.poscafe.util.ConfigurationWithWildcard.java

License:Open Source License

private void parseSessionFactory(Element sfNode, String name) {
    Iterator elements = sfNode.elementIterator();
    while (elements.hasNext()) {
        Element subelement = (Element) elements.next();
        String subelementName = subelement.getName();
        if ("mapping".equals(subelementName)) {
            parseMappingElement(subelement, name);
        } else if ("class-cache".equals(subelementName)) {
            String className = subelement.attributeValue("class");
            Attribute regionNode = subelement.attribute("region");
            final String region = (regionNode == null) ? className : regionNode.getValue();
            boolean includeLazy = !"non-lazy".equals(subelement.attributeValue("include"));
            setCacheConcurrencyStrategy(className, subelement.attributeValue("usage"), region, includeLazy);
        } else if ("collection-cache".equals(subelementName)) {
            String role = subelement.attributeValue("collection");
            Attribute regionNode = subelement.attribute("region");
            final String region = (regionNode == null) ? role : regionNode.getValue();
            setCollectionCacheConcurrencyStrategy(role, subelement.attributeValue("usage"), region);
        } else if ("listener".equals(subelementName)) {
            parseListener(subelement);//from w  w w  .j  av  a2s .c  o m
        } else if ("event".equals(subelementName)) {
            parseEvent(subelement);
        }
    }
}

From source file:com.hyron.poscafe.util.ConfigurationWithWildcard.java

License:Open Source License

private void parseMappingElement(Element mappingElement, String name) {
    final Attribute resourceAttribute = mappingElement.attribute("resource");
    final Attribute fileAttribute = mappingElement.attribute("file");
    final Attribute jarAttribute = mappingElement.attribute("jar");
    final Attribute packageAttribute = mappingElement.attribute("package");
    final Attribute classAttribute = mappingElement.attribute("class");

    if (resourceAttribute != null) {
        final String resourceName = resourceAttribute.getValue();
        log.debug("session-factory config [{}] named resource [{}] for mapping", name, resourceName);
        addResource(resourceName);/*from   www . ja va2  s. c  o m*/
    } else if (fileAttribute != null) {
        final String fileName = fileAttribute.getValue();
        log.debug("session-factory config [{}] named file [{}] for mapping", name, fileName);
        addFile(fileName);
    } else if (jarAttribute != null) {
        final String jarFileName = jarAttribute.getValue();
        log.debug("session-factory config [{}] named jar file [{}] for mapping", name, jarFileName);
        addJar(new File(jarFileName));
    } else if (packageAttribute != null) {
        final String packageName = packageAttribute.getValue();
        log.debug("session-factory config [{}] named package [{}] for mapping", name, packageName);
        addPackage(packageName);
    } else if (classAttribute != null) {
        final String classAttributeName = classAttribute.getValue();

        final List<String> classNames = new ArrayList<String>();

        if (classAttributeName.endsWith(".*")) {
            try {
                classNames.addAll(getAllAnnotatedClassNames(classAttributeName));
            } catch (IOException ioe) {
                log.error("Could not read class: " + classAttributeName, ioe);
            } catch (URISyntaxException use) {
                log.error("Could not read class: " + classAttributeName, use);
            }
        } else {
            classNames.add(classAttributeName);
        }

        for (String className : classNames) {
            try {
                log.debug("session-factory config [{}] named class [{}] for mapping", name, className);
                addAnnotatedClass(ReflectHelper.classForName(className));
            } catch (Exception e) {
                throw new MappingException("Unable to load class [ " + className
                        + "] declared in Hibernate configuration <mapping/> entry", e);
            }
        }
    } else {
        throw new MappingException("<mapping> element in configuration specifies no known attributes");
    }
}

From source file:com.ibm.cognos.MetaData.java

License:Open Source License

/**
 * ParseMetaData method will create a vector of MetaData objects by parsing
 * (using DOM) the metadata XML returned from the content store. Basically a
 * list of all tables and the columns./*from w w w  .ja v a  2 s. c o m*/
 * 
 * querySubject = tables queryItems = columns
 * 
 * @param connection
 * @param newReport
 * @param defaultPackageName
 * @return Vector
 */
public Vector parseMetaData(CRNConnect connection, ReportObject newReport, String defaultPackageName) {
    // retrieve the metadata from the selected package to display for
    // table/column selection.
    Vector packageMetaData = new Vector();

    if (defaultPackageName != null) {
        Document doc = newReport.getMetadata(connection, defaultPackageName);
        // returns a list of tables from the QuerySubject tag
        List tableList = (List) doc.selectNodes("/ResponseRoot/folder/folder/folder/querySubject");
        for (int i = 0; i < tableList.size(); i++) {
            Element eTable = (Element) tableList.get(i);
            Attribute nameAttrQuerySubject = eTable.attribute("name");
            String sTable = nameAttrQuerySubject.getValue();
            System.out.println(sTable);

            MetaData md = new MetaData();
            md.setQuerySubject(sTable);

            // set the current node to be the current QuerySubject
            Element eCurrent = (Element) doc.selectSingleNode(
                    "/ResponseRoot/folder/folder/folder/querySubject[@name='" + sTable + "']");
            // retrieve a list of columns in this table or queryItems from
            // the current querySubject node.
            List columnList = (List) eCurrent.selectNodes("queryItem");
            Vector metaQueryItems = new Vector();
            Vector metaFullNameQueryItems = new Vector();
            for (int j = 0; j < columnList.size(); j++) {
                Element eColumn = (Element) columnList.get(j);
                Attribute attrQueryItemName = eColumn.attribute("name");
                Attribute attrQueryItemRef = eColumn.attribute("_ref");
                String sColumn = attrQueryItemName.getValue();
                String sFullColumnName = attrQueryItemRef.getValue();
                System.out.println("           " + sColumn);
                metaQueryItems.add(sColumn);
                metaFullNameQueryItems.add(sFullColumnName);
            }
            md.setQueryItem(metaQueryItems);
            md.setFullNameQueryItems(metaFullNameQueryItems);
            packageMetaData.add(md);
        }
    } else
        System.out.println("Problem: default package name unavailable.");

    return packageMetaData;
}

From source file:com.iih5.smartorm.kit.SqlXmlKit.java

License:Apache License

private void init(File dataDir) {
    try {//from   w  w w  . java2s.  c om
        List<File> files = new ArrayList<File>();
        listDirectory(dataDir, files);
        for (File file : files) {
            if (file.getName().contains(".xml")) {
                SAXReader reader = new SAXReader();
                Document document = reader.read(file);
                Element xmlRoot = document.getRootElement();
                for (Object e : xmlRoot.elements("class")) {
                    Map<String, String> methods = new HashMap<String, String>();
                    Element clasz = (Element) e;
                    for (Object ebj : clasz.elements("sql")) {
                        Element sql = (Element) ebj;
                        methods.put(sql.attribute("method").getValue(), sql.getText());
                    }
                    resourcesMap.put(clasz.attributeValue("name"), methods);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}