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:com.processpuzzle.internalization.domain.LocaleLoader.java

License:Open Source License

private void loadCurrencyElements(Element root, ProcessPuzzleLocale locale) {
    if (root == null)
        return;/* w w w  .  j  a  v a 2  s  .  c o m*/
    Attribute nameAttr = root.attribute("name");
    Attribute symbolAttr = root.attribute("symbol");

    if (nameAttr != null && symbolAttr != null) {
        Unit u = measurementContext.findUnitBySymbol(symbolAttr.getValue());
        if (u != null)
            locale.setLegalTender((Currency) u);
    } else
        return;

}

From source file:com.pureinfo.force.junit.AssertUtil.java

License:Open Source License

/**
 * ElementnameElement<br>/*  w  ww . j a  va  2  s .  com*/
 * Attribute
 * 
 * @param _expectedElement
 * @param _actualElement
 */
public static void assertXMLEquals(Element _expectedElement, Element _actualElement) {
    Assert.assertEquals("element name", _expectedElement.getName(), _actualElement.getName());
    List expectedAttributes = _expectedElement.attributes();
    List actualAttributes = _actualElement.attributes();
    Assert.assertEquals("attribute size", expectedAttributes.size(), actualAttributes.size());

    Map expectedNames = new HashMap();
    Map actualNames = new HashMap();
    for (Iterator iter = expectedAttributes.iterator(); iter.hasNext();) {
        Attribute attr = (Attribute) iter.next();
        expectedNames.put(attr.getName(), attr.getValue());
    }
    for (Iterator iter = actualAttributes.iterator(); iter.hasNext();) {
        Attribute attr = (Attribute) iter.next();
        actualNames.put(attr.getName(), attr.getValue());
    }
    Assert.assertEquals("attribute", expectedNames, actualNames);

    List expectedElements = _expectedElement.elements();
    List actualElements = _actualElement.elements();
    Assert.assertEquals("element size", expectedElements.size(), actualElements.size());

    for (Iterator iter1 = expectedElements.iterator(), iter2 = actualElements.iterator(); iter1.hasNext();) {
        Element expecteElement = (Element) iter1.next();
        Element actualElement = (Element) iter2.next();
        assertXMLEquals(expecteElement, actualElement);
    }
}

From source file:com.qagen.osfe.common.utils.DomReader.java

License:Apache License

public static String getValue(Element element, String attributeName) {
    final Attribute attribute = element.attribute(attributeName);

    if (attribute == null) {
        return null;
    }//www  .j  ava  2 s . c o  m

    return attribute.getValue();
}

From source file:com.rdvmedecin.proprietes.Properties.java

public Properties() throws DocumentException {
    File fichier = new File("configuration.xml");
    SAXReader reader = new SAXReader();
    Document doc = reader.read(fichier);
    Element root = doc.getRootElement();
    List attributes = root.attributes();
    List elements = root.elements();
    QName qName = root.getQName();
    String nom = qName.getName();
    // lecture du nom de l'espace de noms
    String nomEspaceDeNoms = qName.getNamespaceURI();
    // lecture du prfixe utilis pour cet espace de nom 
    String nomPrefix = qName.getNamespacePrefix();
    String texte = root.getText();
    Attribute attribute = (Attribute) attributes.iterator().next();
    QName attributeQName = attribute.getQName();
    String value = attribute.getValue();
    String nomAttribut = attribute.getName();
}

From source file:com.safi.workshop.sqlexplorer.preview.XmlPreviewer.java

License:Open Source License

public void createControls(Composite parent, final Object data) throws ExplorerException {
    Element rootElem = getXml(data);
    if (rootElem == null)
        return;/*from  w  w  w  .  jav a2s .co  m*/
    final Object[] root = new Object[] { rootElem };

    TreeViewer tree = new TreeViewer(parent, SWT.SINGLE);
    tree.setContentProvider(new ITreeContentProvider() {
        public void dispose() {
        }

        /**
         * Called to get the top level items
         */
        public Object[] getChildren(Object parentElement) {
            return root;
        }

        /**
         * Called to get the item's children
         */
        public Object[] getElements(Object inputElement) {
            Element elem = (Element) inputElement;
            return elem.elements().toArray();
        }

        public boolean hasChildren(Object element) {
            Element elem = (Element) element;
            List<Element> list = elem.elements();
            return list != null && list.size() > 0;
        }

        public Object getParent(Object element) {
            Element elem = (Element) element;
            return elem.getParent();
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            // Nothing
        }
    });

    tree.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object obj) {
            Element elem = (Element) obj;
            StringBuffer result = new StringBuffer();
            result.append('<');
            result.append(elem.getName());

            for (Object o : elem.attributes()) {
                Attribute attr = (Attribute) o;
                result.append(' ').append(attr.getName()).append('=').append('\"').append(attr.getValue())
                        .append('\"');
            }
            if (!elem.hasContent())
                result.append('/');
            result.append('>');
            return result.toString();
        }
    });

    tree.expandToLevel(1);
}

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

License:Open Source License

AttributesImpl getAttributes(Element element, Expressions expressions) throws PageTemplateException {
    AttributesImpl attributes = new AttributesImpl();
    for (Iterator i = element.attributeIterator(); i.hasNext();) {
        Attribute attribute = (Attribute) i.next();
        Namespace namespace = attribute.getNamespace();
        //String prefix = namespace.getPrefix();
        //System.err.println( "attribute: name=" + attribute.getName() + "\t" +
        //                    "qualified name=" + attribute.getQualifiedName() + "\t" +
        //                    "ns prefix=" + namespace.getPrefix() + "\t" +
        //                    "ns uri=" + namespace.getURI() );
        //String qualifiedName = attribute.getName();
        //String name = qualifiedName;
        //if ( qualifiedName.startsWith( prefix + ":" ) ) {
        //    name = qualifiedName.substring( prefix.length() + 1 );
        //}/*from   w  w w . j a  v  a2 s . c  o m*/
        String name = attribute.getName();

        // Handle JPT attributes
        //if ( prefix.equals( talNamespacePrefix ) ) {
        if (TAL_NAMESPACE_URI.equals(namespace.getURI())) {
            // tal:define
            if (name.equals("define")) {
                expressions.define = attribute.getValue();
            }

            // tal:condition
            else if (name.equals("condition")) {
                expressions.condition = attribute.getValue();
            }

            // tal:repeat
            else if (name.equals("repeat")) {
                expressions.repeat = attribute.getValue();
            }

            // tal:content
            else if (name.equals("content")) {
                expressions.content = attribute.getValue();
            }

            // tal:replace
            else if (name.equals("replace")) {
                if (expressions.omitTag == null) {
                    expressions.omitTag = "";
                }
                expressions.content = attribute.getValue();
            }

            // tal:attributes
            else if (name.equals("attributes")) {
                expressions.attributes = attribute.getValue();
            }

            // tal:omit-tag
            else if (name.equals("omit-tag")) {
                expressions.omitTag = attribute.getValue();
            }

            // error
            else {
                throw new PageTemplateException("unknown tal attribute: " + name);
            }
        }
        //else if ( prefix.equals( metalNamespacePrefix ) ) 
        else if (METAL_NAMESPACE_URI.equals(namespace.getURI())) {
            // metal:use-macro
            if (name.equals("use-macro")) {
                expressions.useMacro = attribute.getValue();
            }

            // metal:define-slot
            else if (name.equals("define-slot")) {
                expressions.defineSlot = attribute.getValue();
            }

            // metal:define-macro
            // metal:fill-slot
            else if (name.equals("define-macro") || name.equals("fill-slot")) {
                // these are ignored here, as they don't affect processing of current
                // template, but are called from other templates
            }

            // error
            else {
                throw new PageTemplateException("unknown metal attribute: " + name);
            }
        }

        // Pass on all other attributes
        else {
            //String qualifiedName = namespace.getPrefix() + ":" + name;
            attributes.addAttribute(namespace.getURI(), name, attribute.getQualifiedName(), "CDATA",
                    attribute.getValue());
            //attributes.addAttribute( getNamespaceURIFromPrefix(prefix), name, qualifiedName, "CDATA", attribute.getValue() );
        }
    }
    return attributes;
}

From source file:com.taobao.android.builder.tasks.app.manifest.StandardizeLibManifestTask.java

License:Apache License

/**
 * ?mainifest/*from  w  w  w .  j  a v a 2s  .  c  o m*/
 *
 * @param manifestFile
 * @return
 */
public static ManifestInfo getManifestFileObject(File manifestFile) throws DocumentException {

    ManifestInfo manifestFileObject = new ManifestInfo();
    manifestFileObject.setManifestFile(manifestFile);
    if (manifestFile.exists()) {
        Document document = XmlHelper.readXml(manifestFile);// ?XML
        Element root = document.getRootElement();// 
        for (Attribute attribute : root.attributes()) {
            if (StringUtils.isNotBlank(attribute.getNamespacePrefix())) {
                manifestFileObject.addManifestProperty(
                        attribute.getNamespacePrefix() + ":" + attribute.getName(), attribute.getValue());
            } else {
                manifestFileObject.addManifestProperty(attribute.getName(), attribute.getValue());
            }
        }
        Element useSdkElement = root.element("uses-sdk");
        Element applicationElement = root.element("application");
        if (null != useSdkElement) {
            for (Attribute attribute : useSdkElement.attributes()) {
                if (StringUtils.isNotBlank(attribute.getNamespacePrefix())) {
                    manifestFileObject.addUseSdkProperty(
                            attribute.getNamespacePrefix() + ":" + attribute.getName(), attribute.getValue());
                } else {
                    manifestFileObject.addUseSdkProperty(attribute.getName(), attribute.getValue());
                }
            }
        }
        if (null != applicationElement) {
            for (Attribute attribute : applicationElement.attributes()) {
                if (StringUtils.isNotBlank(attribute.getNamespacePrefix())) {
                    manifestFileObject.addApplicationProperty(
                            attribute.getNamespacePrefix() + ":" + attribute.getName(), attribute.getValue());
                } else {
                    manifestFileObject.addApplicationProperty(attribute.getName(), attribute.getValue());
                }
            }
        }
    }
    manifestFileObject.init();
    return manifestFileObject;
}

From source file:com.taobao.android.builder.tasks.tpatch.DiffBundleInfoTask.java

License:Apache License

private static ArtifactBundleInfo getMainArtifactBundInfo(File manifestFile) {
    ArtifactBundleInfo mainBundleInfo = new ArtifactBundleInfo();
    SAXReader reader = new SAXReader();
    Document document = null;// ?XML
    try {/* w  ww  . j  ava2  s . c  o m*/
        document = reader.read(manifestFile);
    } catch (DocumentException e) {
        throw new GradleException(e.getMessage(), e);
    }
    Element root = document.getRootElement();// 

    List<? extends Node> metadataNodes = root.selectNodes("//meta-data");
    for (Node node : metadataNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        if (attribute.getValue().equals("label")) {
            Attribute labelAttribute = element.attribute("value");
            mainBundleInfo.setName(labelAttribute.getValue());
        }
    }

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

    if ("manifest".equalsIgnoreCase(root.getName())) {
        List<Attribute> attributes = root.attributes();
        for (Attribute attr : attributes) {
            if (StringUtils.equalsIgnoreCase(attr.getName(), "versionName")) {
                String versionName = attr.getValue();
                mainBundleInfo.setVersion(versionName);
            }
        }
    }
    String pkgName = root.attributeValue("package");
    mainBundleInfo.setPkgName(pkgName);
    return mainBundleInfo;
}

From source file:com.taobao.android.builder.tools.bundleinfo.BundleInfoUtils.java

License:Apache License

/**
 * ?manifestBundleInfo/*  ww w .j  a  v a2  s  . c o m*/
 *
 * @return
 */
private static void update(AwbBundle awbBundle, Map<String, BundleInfo> bundleInfoMap,
        AppVariantContext appVariantContext, String apkVersion) throws DocumentException {

    String artifactId = awbBundle.getResolvedCoordinates().getArtifactId();
    BundleInfo bundleInfo = bundleInfoMap.get(artifactId);
    if (null != bundleInfo) {
        awbBundle.bundleInfo = bundleInfo;
    } else {
        bundleInfo = awbBundle.bundleInfo;
    }

    awbBundle.isRemote = appVariantContext.getAtlasExtension().getTBuildConfig().getOutOfApkBundles()
            .contains(artifactId);
    bundleInfo.setIsInternal(!awbBundle.isRemote);
    bundleInfo.setVersion(apkVersion + "@" + awbBundle.getResolvedCoordinates().getVersion());
    bundleInfo.setPkgName(awbBundle.getPackageName());

    String applicationName = ManifestFileUtils.getApplicationName(awbBundle.getOrgManifestFile());
    if (StringUtils.isNotEmpty(applicationName)) {
        bundleInfo.setApplicationName(applicationName);
    }

    SAXReader reader = new SAXReader();
    Document document = reader.read(awbBundle.getManifest());// ?XML
    Element root = document.getRootElement();// 

    List<? extends Node> metadataNodes = root.selectNodes("//meta-data");
    for (Node node : metadataNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        if (attribute.getValue().equals("label")) {
            Attribute labelAttribute = element.attribute("value");
            bundleInfo.setName(labelAttribute.getValue());
        } else if (attribute.getValue().equals("description")) {
            Attribute descAttribute = element.attribute("value");
            bundleInfo.setDesc(descAttribute.getValue());
        }
    }

    addComponents(bundleInfo, root);

    for (AndroidLibrary depLib : awbBundle.getLibraryDependencies()) {
        SAXReader reader2 = new SAXReader();
        Document document2 = reader2.read(depLib.getManifest());// ?XML
        Element root2 = document2.getRootElement();// 
        addComponents(bundleInfo, root2);
    }
}

From source file:com.taobao.android.builder.tools.bundleinfo.BundleInfoUtils.java

License:Apache License

private static void addComponents(BundleInfo bundleInfo, Element root) {
    List<? extends Node> serviceNodes = root.selectNodes("//service");
    for (Node node : serviceNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        bundleInfo.getServices().add(attribute.getValue());
    }//from  w ww  .j a  v a2  s .c o m
    List<? extends Node> receiverNodes = root.selectNodes("//receiver");
    for (Node node : receiverNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");

        bundleInfo.getReceivers().add(attribute.getValue());
    }
    List<? extends Node> providerNodes = root.selectNodes("//provider");
    for (Node node : providerNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");

        bundleInfo.getContentProviders().add(attribute.getValue());
    }
    List<? extends Node> activityNodes = root.selectNodes("//activity");
    for (Node node : activityNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");

        bundleInfo.getActivities().add(attribute.getValue());
    }
}