Example usage for org.dom4j Element getText

List of usage examples for org.dom4j Element getText

Introduction

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

Prototype

String getText();

Source Link

Document

Returns the text value of this element without recursing through child elements.

Usage

From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java

License:Open Source License

/**
 * this function will return a boolean corresponding to the use or not of the FTP
 * @param ingest/* w  ww.j a  v  a2s  . c  o  m*/
 * @param type
 * @return
 */
public static boolean useFtp(String ingest, String type) {
    boolean use = false;

    Document doc = null;

    try {
        doc = DocumentHelper.parseText(ingest);
    } catch (DocumentException e) {
        logger.error("", e);
    }

    String xpath = "/fsxml/properties/" + type + "/ftp/enabled";
    Element isEnabled = (Element) doc.selectSingleNode(xpath);

    if (isEnabled != null) {
        String enabled = isEnabled.getText();
        if (enabled.equals("true"))
            use = true;
    }
    return use;
}

From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java

License:Open Source License

/**
 * this function will return a boolean corresponding to the use or not the backup
 * server for FTP//from  w ww  .j a  v  a2  s .  co m
 * @param ingest
 * @param type
 * @return
 */
public static boolean useBackup(String ingest) {
    boolean use = false;

    Document doc = null;

    try {
        doc = DocumentHelper.parseText(ingest);
    } catch (DocumentException e) {
        logger.error("", e);
    }

    String xpath = "/fsxml/properties/image/ftp/backup";
    Element isEnabled = (Element) doc.selectSingleNode(xpath);

    if (isEnabled != null) {
        String enabled = isEnabled.getText();
        if (enabled.equals("true"))
            use = true;
    }
    return use;
}

From source file:com.noterik.bart.fs.legacy.tools.XmlHelper.java

License:Open Source License

/**
 * this function will get the value in the given xpath
 *
 * @param ingest//from ww  w  . ja  v a2 s .c om
 * @param xpath
 * @return
 */
public static String getValueFromIngest(String ingest, String xpath) {
    Document doc = null;
    String value = "";

    try {
        doc = DocumentHelper.parseText(ingest);
    } catch (DocumentException e) {
        logger.error("", e);
    }

    Element elem = (Element) doc.selectSingleNode(xpath);

    if (elem != null)
        value = elem.getText();

    return value;
}

From source file:com.noterik.bart.fs.tools.FSXMLHelper.java

License:Open Source License

public static String getValueFromXml(String xml, String xpath) {
    String value = "";
    Document doc = XMLHelper.asDocument(xml);
    if (doc != null) {
        Element elem = (Element) doc.selectSingleNode(xpath);
        if (elem != null) {
            value = elem.getText();
        }//from  ww  w  . ja v  a2s.  c  o m
    }
    return value;
}

From source file:com.npower.dm.hibernate.management.ModelManagementBeanImpl.java

License:Open Source License

/**
 * //w ww.j  a va 2 s.c  om
 * <pre>
 * Import the TAC list of models form file.
 * &lt;pre&gt;
 * 
 * @param xmlFile
 * @throws DMException
 * 
 */
public void importModelTAC(File xmlFile) throws DMException {

    try {

        ManagementBeanFactory factory = this.getManagementBeanFactory();
        ModelBean modelBean = factory.createModelBean();
        factory.beginTransaction();

        SAXReader reader = new SAXReader();
        Document confDoc = reader.read(xmlFile);
        Element root = confDoc.getRootElement();

        for (Iterator<Element> i = root.elementIterator("Manufacturer"); i.hasNext();) {

            String manufacturerExternalID = "";
            Element manElement = i.next();
            manufacturerExternalID = manElement.elementText("ExternalID");
            Manufacturer manufacturerBean = modelBean.getManufacturerByExternalID(manufacturerExternalID);
            if (manufacturerBean == null) {
                System.err.println("Could not find this manufacturer: " + manufacturerExternalID);
                continue;
            }

            for (Iterator<Element> j = manElement.elementIterator("Model"); j.hasNext();) {
                String modelExternalID = "";
                Element modelElement = j.next();
                modelExternalID = modelElement.elementText("ExternalID");
                Model model = modelBean.getModelByManufacturerModelID(manufacturerBean, modelExternalID);
                if (model == null) {
                    System.err.println("Could not find this model: " + modelExternalID);
                    continue;
                }

                List<Element> TACsList = modelElement.elements("TACs");
                List<String> TACInfos = new ArrayList<String>();
                for (int k = 0; k < TACsList.size(); k++) {
                    List<Element> TACList = ((TACsList.get(k))).elements("TAC");
                    for (int m = 0; m < TACList.size(); m++) {
                        Element tacElement = TACList.get(m);
                        String tac = tacElement.getText();
                        if (StringUtils.isNotEmpty(tac) && tac.length() >= 8) {
                            TACInfos.add(tac);
                        }
                    }

                }
                modelBean.update(model);
                modelBean.setTACInfos(model, TACInfos);
            }
        }
        factory.commit();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:com.oakhole.core.uitls.XMLMapper.java

License:Apache License

/**
 * SAX??xml,// w w w .  j a va 2 s.  com
 *
 * @param inputStream
 * @return
 * @throws Exception
 */
public static Map<String, String> parseXml(InputStream inputStream) throws Exception {
    Map<String, String> map = Maps.newHashMap();
    SAXReader reader = new SAXReader();
    Document document = reader.read(inputStream);
    Element root = document.getRootElement();
    List<Element> elementList = root.elements();
    for (Element e : elementList) {
        map.put(e.getName(), e.getText());
    }
    inputStream.close();
    inputStream = null;
    return map;
}

From source file:com.onion.master.MasterConf.java

License:Apache License

public List<InetSocketAddress> getWorkerAddresses() throws Exception {
    Element address = root.element("InetAddress");
    List<Element> addList = address.elements();
    for (Element element : addList) {
        String[] addStr = element.getText().split(":");
        if (addStr.length < 2) {
            throw new Exception("The type of InetAddress is no correct!");
        }//from w ww .  jav  a 2  s . c  om
        workerAddresses.add(new InetSocketAddress(addStr[0], Integer.parseInt(addStr[1])));
    }
    return workerAddresses;
}

From source file:com.openedit.users.filesystem.FileSystemUserManager.java

License:Open Source License

/**
 * May be subclassed// w  ww . j  ava 2  s.c om
 */
protected User loadUser(String inUserName) throws UserManagerException {
    File userFile = loadUserFile(inUserName);
    if (!userFile.exists()) {
        ContentItem stub = getPageManager().getRepository().getStub("/WEB-INF/users/" + inUserName + ".xml");
        userFile = new File(stub.getAbsolutePath());
    }
    if (!userFile.exists()) {
        return null;
    }

    FileSystemUser user = new FileSystemUser();
    user.setUserName(inUserName);

    Element root = getXmlUtil().getXml(userFile, "UTF-8");

    user.setEnabled(true);
    String enabled = root.attributeValue("enabled");
    if (enabled != null && Boolean.parseBoolean(enabled) == false) {
        user.setEnabled(false);
    } else {
        user.setEnabled(true);
    }

    Element passwordElem = root.element("password");
    if (passwordElem != null) {
        user.setPassword(passwordElem.getText());
    }

    Element lastLoginElem = root.element("lastLogined-Time");
    if (lastLoginElem != null) {
        user.setLastLoginTime(lastLoginElem.getText());
    }

    Element creationDateElem = root.element("creation-date");
    if (creationDateElem != null) {
        long time = Long.parseLong(creationDateElem.getText());
        user.setCreationDate(new Date(time));
    }
    MapPropertyContainer container = new MapPropertyContainer();
    container.loadProperties(root.element("properties"));
    user.setPropertyContainer(container);

    for (Iterator iter = root.elementIterator("group"); iter.hasNext();) {
        Element group = (Element) iter.next();
        Group g = getGroup(group.attributeValue("id"));
        if (g != null) {
            user.addGroup(g);
        } else {
            log.error("Missing group " + group.attributeValue("id"));
        }
    }
    getUserNameToUserMap().put(user.getUserName(), user);

    return user;
}

From source file:com.openedit.users.filesystem.XmlUserArchive.java

License:Open Source License

/**
 * May be subclassed//from  w w w  . j  av a2s  .  co  m
 */
public User loadUser(String inUserName) throws UserManagerException {

    ContentItem userfolder = getPageManager().getRepository().getStub(getUserDirectory() + "/");
    if (!userfolder.exists()) {
        File userfolderfile = new File(userfolder.getAbsolutePath());
        userfolderfile.mkdirs();

    }

    File userFile = loadUserFile(inUserName);
    if (!userFile.exists()) {
        ContentItem stub = getPageManager().getRepository().getStub("/WEB-INF/users/" + inUserName + ".xml");
        userFile = new File(stub.getAbsolutePath());
    }
    if (!userFile.exists()) {
        return null;
    }

    FileSystemUser user = new FileSystemUser();
    user.setUserName(inUserName);

    Element root = getXmlUtil().getXml(userFile, "UTF-8");

    user.setEnabled(true);
    // String enabled = root.attributeValue("enabled");
    // if (enabled != null && Boolean.parseBoolean(enabled) == false)
    // {
    // user.setEnabled(false);
    // }
    // else
    // {
    // user.setEnabled(true);
    // }

    Element passwordElem = root.element("password");
    if (passwordElem != null) {
        user.setPassword(passwordElem.getText());
    }

    Element lastLoginElem = root.element("lastLogined-Time");
    if (lastLoginElem != null) {
        user.setLastLoginTime(lastLoginElem.getText());
    }

    Element creationDateElem = root.element("creation-date");
    if (creationDateElem != null) {
        long time = Long.parseLong(creationDateElem.getText());
        user.setCreationDate(new Date(time));
    }
    MapPropertyContainer container = new MapPropertyContainer();
    container.loadProperties(root.element("properties"));
    user.setPropertyContainer(container);

    for (Iterator iter = root.elementIterator("group"); iter.hasNext();) {
        Element group = (Element) iter.next();
        Group g = getGroup(group.attributeValue("id"));
        if (g != null) {
            user.addGroup(g);
        } else {
            log.error("Missing group " + group.attributeValue("id"));
        }
    }
    // TODO :Replace with cache
    getUserNameToUserMap().put(user.getUserName(), user);

    return user;
}

From source file:com.pactera.edg.am.metamanager.extractor.adapter.mapping.impl.CommonMappingServiceImpl.java

License:Open Source License

private MMMetadata genMetadata(MMMetadata parentMetadata, MMMetaModel cntMetaModel, Element element) {
    new MMMetadata();
    // metadata.setClassifierId(element.attributeValue("class"));
    String code = element.selectSingleNode("./attributes/instancecode").getText();
    String name = element.selectSingleNode("./attributes/instancename").getText();
    // metadata.setCode(code == null ? "" : code.trim());
    // metadata.setName(name == null ? "" : name.trim());
    MMMetadata metadata = super.createMetadata(parentMetadata, cntMetaModel, code == null ? "" : code.trim(),
            name == null ? "" : name.trim());
    // metadata.setParentMetadata(parentMetadata);
    //      //  ww w .  j  a va  2 s.com
    // parentMetadata.addChildMetadata(metadata);

    Map<String, String> attrs = new HashMap<String, String>();

    List<Element> attrElements = ((Element) element.selectSingleNode("./features")).elements();
    for (Element attrElement : attrElements) {
        String value = attrElement.getText();
        value = (value == null) ? null : value.trim(); // XML?trim()
        if (value == null || value.equals("")) {
            continue;
        }
        attrs.put(attrElement.getName(), value);
    }
    metadata.setAttrs(attrs);

    // ?
    metadatasCache.put(element.selectSingleNode("./attributes/instanceid").getText().hashCode(), metadata);
    return metadata;
}