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.jswiff.xml.TagXMLReader.java

License:Open Source License

private static Tag readEnableDebugger(Element tagElement) {
    Attribute password = tagElement.attribute("password");
    return new EnableDebugger((password == null) ? null : password.getValue());
}

From source file:com.jswiff.xml.TagXMLReader.java

License:Open Source License

private static Tag readEnableDebugger2(Element tagElement) {
    Attribute password = tagElement.attribute("password");
    return new EnableDebugger2((password == null) ? null : password.getValue());
}

From source file:com.jswiff.xml.TagXMLReader.java

License:Open Source License

private static Tag readPlaceObject2(Element tagElement) {
    int depth = RecordXMLReader.getIntAttribute("depth", tagElement);
    PlaceObject2 placeObject2 = new PlaceObject2(depth);
    Attribute characterId = tagElement.attribute("charid");
    if (characterId != null) {
        placeObject2.setCharacterId(Integer.parseInt(characterId.getValue()));
    }/*w w w .  j  ava  2 s  . c o m*/
    Attribute name = tagElement.attribute("name");
    if (name != null) {
        placeObject2.setName(name.getValue());
    }
    if (RecordXMLReader.getBooleanAttribute("move", tagElement)) {
        placeObject2.setMove();
    }
    Element matrix = tagElement.element("matrix");
    if (matrix != null) {
        placeObject2.setMatrix(RecordXMLReader.readMatrix(matrix));
    }
    Element colorTransform = tagElement.element("cxformwithalpha");
    if (colorTransform != null) {
        placeObject2.setColorTransform(RecordXMLReader.readCXformWithAlpha(colorTransform));
    }
    Attribute ratio = tagElement.attribute("ratio");
    if (ratio != null) {
        placeObject2.setRatio(Integer.parseInt(ratio.getValue()));
    }
    Attribute clipDepth = tagElement.attribute("clipdepth");
    if (clipDepth != null) {
        placeObject2.setClipDepth(Integer.parseInt(clipDepth.getValue()));
    }
    Element clipActions = tagElement.element("clipactions");
    if (clipActions != null) {
        placeObject2.setClipActions(RecordXMLReader.readClipActions(clipActions));
    }
    return placeObject2;
}

From source file:com.jswiff.xml.TagXMLReader.java

License:Open Source License

private static Tag readPlaceObject3(Element tagElement) {
    int depth = RecordXMLReader.getIntAttribute("depth", tagElement);
    PlaceObject3 placeObject3 = new PlaceObject3(depth);
    Attribute characterId = tagElement.attribute("charid");
    if (characterId != null) {
        placeObject3.setCharacterId(Integer.parseInt(characterId.getValue()));
    }/*w  w w  . j a va 2  s  . co  m*/
    Attribute name = tagElement.attribute("name");
    if (name != null) {
        placeObject3.setName(name.getValue());
    }
    if (RecordXMLReader.getBooleanAttribute("move", tagElement)) {
        placeObject3.setMove();
    }
    Element matrix = tagElement.element("matrix");
    if (matrix != null) {
        placeObject3.setMatrix(RecordXMLReader.readMatrix(matrix));
    }
    Element colorTransform = tagElement.element("cxformwithalpha");
    if (colorTransform != null) {
        placeObject3.setColorTransform(RecordXMLReader.readCXformWithAlpha(colorTransform));
    }
    Attribute ratio = tagElement.attribute("ratio");
    if (ratio != null) {
        placeObject3.setRatio(Integer.parseInt(ratio.getValue()));
    }
    Attribute clipDepth = tagElement.attribute("clipdepth");
    if (clipDepth != null) {
        placeObject3.setClipDepth(Integer.parseInt(clipDepth.getValue()));
    }
    Element clipActions = tagElement.element("clipactions");
    if (clipActions != null) {
        placeObject3.setClipActions(RecordXMLReader.readClipActions(clipActions));
    }
    Attribute blendMode = tagElement.attribute("blendmode");
    if (blendMode != null) {
        placeObject3.setBlendMode(BlendMode.getFromDescription(blendMode.getValue()));
    }
    placeObject3.setCacheAsBitmap(RecordXMLReader.getBooleanAttribute("cacheasbitmap", tagElement));
    Element filters = tagElement.element("filters");
    if (filters != null) {
        placeObject3.setFilters(RecordXMLReader.readFilters(filters));
    }
    return placeObject3;
}

From source file:com.jswiff.xml.TagXMLReader.java

License:Open Source License

private static Tag readProtect(Element tagElement) {
    Attribute password = tagElement.attribute("password");
    return new Protect((password == null) ? null : password.getValue());
}

From source file:com.l2jfree.loginserver.dao.impl.GameserversDAOXml.java

License:Open Source License

/**
 * Load server name from xml/* w  w  w.  j a va2 s. co m*/
 */
public GameserversDAOXml() {
    InputStream in = null;
    try {
        try {
            in = new FileInputStream("servername.xml");
        } catch (FileNotFoundException e) {
            // just for eclipse development, we have to search in dist folder
            in = new FileInputStream("dist/servername.xml");
        }

        SAXReader reader = new SAXReader();
        Document document = reader.read(in);

        Element root = document.getRootElement();

        // Find all servers_list (should have only one)
        for (Iterator<?> i = root.elementIterator("server"); i.hasNext();) {
            Element server = (Element) i.next();
            Integer id = null;
            String name = null;
            // For each server, read the attributes
            for (Iterator<?> iAttr = server.attributeIterator(); iAttr.hasNext();) {
                Attribute attribute = (Attribute) iAttr.next();
                if (attribute.getName().equals("id")) {
                    id = new Integer(attribute.getValue());
                } else if (attribute.getName().equals("name")) {
                    name = attribute.getValue();
                }
            }
            if (id != null && name != null) {
                Gameservers gs = new Gameservers();
                gs.setServerId(id);
                gs.setServerName(name);
                serverNames.put(id, gs);
            }
        }
        _log.info("Loaded " + serverNames.size() + " server names");
    } catch (FileNotFoundException e) {
        _log.warn("servername.xml could not be loaded : " + e.getMessage(), e);
    } catch (DocumentException e) {
        _log.warn("servername.xml could not be loaded : " + e.getMessage(), e);
    } finally {
        try {
            if (in != null)
                in.close();
        } catch (Exception e) {
        }
    }
}

From source file:com.liferay.alloy.tools.builder.base.BaseBuilder.java

License:Open Source License

protected List<Component> getAllComponents() throws Exception {
    DocumentFactory factory = SAXReaderUtil.getDocumentFactory();

    Document doc = factory.createDocument();

    String taglibsXML = "<components></components>";

    Document taglibsDoc = SAXReaderUtil
            .read(new InputSource(new ByteArrayInputStream(taglibsXML.getBytes("utf-8"))));

    Element root = taglibsDoc.getRootElement();

    for (Document currentDoc : getComponentDefinitionDocs()) {
        currentDoc = _getExtendedDocument(currentDoc);

        Element currentRoot = currentDoc.getRootElement();

        String defaultPackage = currentRoot.attributeValue("short-name");
        List<Element> extComponentNodes = currentRoot.elements("component");

        for (Element extComponent : extComponentNodes) {
            String extComponentPackage = Convert.toString(extComponent.attributeValue("package"),
                    defaultPackage);/*from  ww  w.  j  ava  2 s. c o  m*/

            extComponent.addAttribute("package", extComponentPackage);
        }

        Element authors = currentRoot.element("author");

        List<Element> components = currentRoot.elements("component");

        for (Element component : components) {
            Element copy = component.createCopy();
            Element componentAuthors = copy.element("authors");

            if ((authors != null) && (componentAuthors == null)) {
                copy.add(authors.createCopy());
            }

            root.add(copy);
        }

        List<org.dom4j.Attribute> attributes = currentRoot.attributes();

        for (org.dom4j.Attribute attribute : attributes) {
            root.addAttribute(attribute.getName(), attribute.getValue());
        }
    }

    doc.add(root.createCopy());

    return getComponents(doc);
}

From source file:com.liferay.alloy.tools.builder.base.BaseBuilder.java

License:Open Source License

protected Document mergeXMLAttributes(Document doc1, Document doc2) {
    Element doc2Root = doc2.getRootElement();
    Element doc1Root = doc1.getRootElement();
    Element docRoot = doc2Root.createCopy();

    docRoot.clearContent();// w  ww  .j  a  va  2  s.c o  m

    if (doc1Root != null) {
        Iterator<Object> attributesIterator = doc1Root.attributeIterator();

        while (attributesIterator.hasNext()) {
            org.dom4j.Attribute attribute = (org.dom4j.Attribute) attributesIterator.next();

            if (attribute.getName().equals("extends")) {
                continue;
            }

            docRoot.addAttribute(attribute.getName(), attribute.getValue());
        }

        Element descriptionElement = doc1Root.element("description");

        if (descriptionElement != null) {
            docRoot.add(descriptionElement.createCopy());
        }
    }

    DocumentFactory factory = SAXReaderUtil.getDocumentFactory();

    Document doc = factory.createDocument();
    doc.setRootElement(docRoot);

    List<Element> doc2Components = doc2Root.elements(_COMPONENT);

    for (Element doc2Component : doc2Components) {
        Element component = doc2Component.createCopy();

        String name = doc2Component.attributeValue("name");

        Element doc1Component = getComponentNode(doc1, name);

        if (doc1Component != null) {
            Element doc1ComponentDescriptionElement = doc1Component.element("description");

            if (doc1ComponentDescriptionElement != null) {
                Element descriptionElement = component.element("description");

                if (descriptionElement != null) {
                    component.remove(descriptionElement);
                }

                component.add(doc1ComponentDescriptionElement.createCopy());
            }

            Iterator<Object> attributesIterator = doc1Component.attributeIterator();

            while (attributesIterator.hasNext()) {
                org.dom4j.Attribute attribute = (org.dom4j.Attribute) attributesIterator.next();

                component.addAttribute(attribute.getName(), attribute.getValue());
            }

            Element doc1AttributesNode = doc1Component.element(_ATTRIBUTES);

            Element attributesNode = component.element(_ATTRIBUTES);

            if ((doc1AttributesNode != null) && (attributesNode != null)) {
                List<Element> doc1Attributes = doc1AttributesNode.elements(_ATTRIBUTE);

                List<Element> attributes = attributesNode.elements(_ATTRIBUTE);

                for (Element doc1Attribute : doc1Attributes) {
                    Element attribute = getElementByName(attributes, doc1Attribute.elementText("name"));

                    if (attribute != null) {
                        attributesNode.remove(attribute);
                    }

                    attributesNode.add(doc1Attribute.createCopy());
                }
            }

            Element doc1EventsNode = doc1Component.element(_EVENTS);

            Element eventsNode = component.element(_EVENTS);

            if ((doc1EventsNode != null) && (eventsNode != null)) {
                List<Element> doc1Events = doc1EventsNode.elements(_EVENT);

                List<Element> events = eventsNode.elements(_EVENT);

                for (Element doc1Event : doc1Events) {
                    Element event = getElementByName(events, doc1Event.elementText("name"));

                    if (event != null) {
                        eventsNode.add(event);
                    }

                    eventsNode.add(doc1Event.createCopy());
                }
            }
        }

        doc.getRootElement().add(component);
    }

    if (doc1Root != null) {
        List<Element> doc1Components = doc1Root.elements(_COMPONENT);

        for (Element doc1Component : doc1Components) {
            Element component = doc1Component.createCopy();

            String name = doc1Component.attributeValue("name");

            Element doc2Component = getComponentNode(doc2, name);

            if (doc2Component == null) {
                doc.getRootElement().add(component);
            }
        }
    }

    return doc;
}

From source file:com.liferay.util.xml.AttributeComparator.java

License:Open Source License

public int compare(Object obj1, Object obj2) {
    Attribute attr1 = (Attribute) obj1;
    Attribute attr2 = (Attribute) obj2;

    String attr1Value = attr1.getValue();
    String attr2Value = attr2.getValue();

    return attr1Value.compareTo(attr2Value);
}

From source file:com.log4ic.compressor.utils.MemcachedUtils.java

License:Open Source License

@SuppressWarnings("unchecked")
private static MemcachedConfig getMemcachedConfig(InputStream in) throws DocumentException {
    SAXReader reader = new SAXReader();

    MemcachedConfig config = new MemcachedConfig();

    Document doc = reader.read(in);

    logger.debug("??...");
    List<Node> nodeList = doc.selectNodes("/memcached/servers/server");
    if (nodeList.isEmpty()) {
        throw new DocumentException(CONFIG_FILE_PATH + " file memcached.servers server element empty!");
    } else {/*from w w w .ja  v  a 2s .  c  o m*/
        logger.debug("???" + nodeList.size() + ".");
    }

    AddressConfig addrConf = biludAddrMapConfig(nodeList);

    config.builder = new XMemcachedClientBuilder(addrConf.addressMap, addrConf.widgets);

    Element el = (Element) doc.selectSingleNode("/memcached");
    logger.debug("??...");
    Attribute attr = el.attribute("connectionPoolSize");
    if (attr != null) {
        String connPoolSize = attr.getValue();
        if (StringUtils.isNotBlank(connPoolSize)) {
            try {
                config.builder.setConnectionPoolSize(Integer.parseInt(connPoolSize));
                logger.debug("?" + connPoolSize);
            } catch (Exception e) {
                logger.error("???", e);
            }
        } else {
            logger.error("???");
        }
    } else {
        logger.warn("??");
    }
    logger.debug("??...");
    attr = el.attribute("enableHeartBeat");
    if (attr != null) {
        String enableHeartBeatS = attr.getValue();
        if (StringUtils.isNotBlank(enableHeartBeatS)) {
            try {
                config.enableHeartBeat = Boolean.parseBoolean(enableHeartBeatS);
                logger.debug("???" + enableHeartBeatS);
            } catch (Exception e) {
                logger.error("?????", e);
            }
        } else {
            logger.error("?????");
        }
    } else {
        logger.warn("????");
    }
    logger.debug("?...");
    attr = el.attribute("sessionIdleTimeout");
    if (attr != null) {
        String sessionIdleTimeout = attr.getValue();
        if (StringUtils.isNotBlank(sessionIdleTimeout)) {
            try {
                config.builder.getConfiguration().setSessionIdleTimeout(Long.parseLong(sessionIdleTimeout));
                logger.debug("?" + sessionIdleTimeout);
            } catch (Exception e) {
                logger.error("???", e);
            }
        } else {
            logger.error("???");
        }
    } else {
        logger.warn("??");
    }
    //?
    logger.debug("?...");
    attr = el.attribute("statisticsServer");
    if (attr != null) {
        String statisticsServer = attr.getValue();
        if (StringUtils.isNotBlank(statisticsServer)) {
            try {
                config.builder.getConfiguration().setStatisticsServer(Boolean.parseBoolean(statisticsServer));
                logger.debug("?" + statisticsServer);
            } catch (Exception e) {
                logger.error("???", e);
            }
        } else {
            logger.error("???");
        }
    } else {
        logger.warn("??");
    }
    logger.debug("?...");
    attr = el.attribute("statisticsInterval");
    if (attr != null) {
        String statisticsInterval = attr.getValue();
        if (StringUtils.isNotBlank(statisticsInterval)) {
            try {
                config.builder.getConfiguration().setStatisticsInterval(Long.parseLong(statisticsInterval));
                logger.debug("?" + statisticsInterval);
            } catch (Exception e) {
                logger.error("???", e);
            }
        } else {
            logger.error("???");
        }
    } else {
        logger.warn("??");
    }
    logger.debug("????...");
    attr = el.attribute("optimizeMergeBuffer");
    if (attr != null) {
        String optimizeMergeBufferS = attr.getValue();
        if (StringUtils.isNotBlank(optimizeMergeBufferS)) {
            try {
                config.optimizeMergeBuffer = Boolean.parseBoolean(optimizeMergeBufferS);
                logger.debug("????" + optimizeMergeBufferS);
            } catch (Exception e) {
                logger.error("??????", e);
            }
        } else {
            logger.error("??????");
        }
    } else {
        logger.warn("?????");
    }
    logger.debug("??...");
    attr = el.attribute("mergeFactor");
    if (attr != null) {
        String mergeFactorS = attr.getValue();
        if (StringUtils.isNotBlank(mergeFactorS)) {
            try {
                config.mergeFactor = Integer.parseInt(mergeFactorS);
                logger.debug("?" + mergeFactorS);
            } catch (Exception e) {
                logger.error("???", e);
            }
        } else {
            logger.error("???");
        }
    } else {
        logger.warn("??");
    }
    logger.debug("??...");
    attr = el.attribute("commandFactory");
    if (attr != null) {
        String commandFactory = attr.getValue();
        if (StringUtils.isNotBlank(commandFactory)) {
            try {
                config.builder.setCommandFactory((CommandFactory) Class.forName(commandFactory).newInstance());
                logger.debug("??" + commandFactory);
            } catch (Exception e) {
                logger.error("????", e);
            }
        } else {
            logger.error("????");
        }
    } else {
        logger.warn("???");
    }
    config.builder.setCommandFactory(new BinaryCommandFactory());
    logger.debug("...");
    nodeList = doc.selectNodes("/memcached/socketOption/*");
    if (!nodeList.isEmpty()) {
        for (Node n : nodeList) {
            try {
                attr = ((Element) n).attribute("type");
                if (attr == null) {
                    logger.error("type attribute undefined");
                } else {
                    String type = attr.getValue();
                    if (StringUtils.isNotBlank(type)) {
                        String name = n.getName();
                        String value = n.getStringValue();
                        Class valueType = Class.forName(type);
                        Constructor constructor = SocketOption.class.getConstructor(String.class, Class.class);
                        SocketOption socketOption = (SocketOption) constructor.newInstance(name, valueType);
                        constructor = valueType.getConstructor(String.class);
                        config.builder.setSocketOption(socketOption, constructor.newInstance(value));
                        logger.debug("[" + name + "]" + value);
                    }
                }
            } catch (NoSuchMethodException e) {
                logger.error("NoSuchMethodException", e);
            } catch (InvocationTargetException e) {
                logger.error("InvocationTargetException", e);
            } catch (InstantiationException e) {
                logger.error("InstantiationException", e);
            } catch (IllegalAccessException e) {
                logger.error("IllegalAccessException", e);
            } catch (ClassNotFoundException e) {
                logger.error("ClassNotFoundException", e);
            }
        }
    } else {
        logger.warn("?");
    }
    logger.debug("Failure?...");
    attr = el.attribute("failureMode");
    if (attr != null) {
        String failureMode = attr.getValue();
        if (StringUtils.isNotBlank(failureMode)) {
            try {
                config.builder.setFailureMode(Boolean.parseBoolean(failureMode));
                logger.debug("Failure?" + failureMode);
            } catch (Exception e) {
                logger.error("Failure???", e);
            }
        } else {
            logger.error("Failure???");
        }
    } else {
        logger.warn("Failure??");
    }
    return config;
}