Example usage for org.dom4j Element getData

List of usage examples for org.dom4j Element getData

Introduction

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

Prototype

Object getData();

Source Link

Document

Accesses the data of this element which may implement data typing bindings such as XML Schema or Java Bean bindings or will return the same value as #getText

Usage

From source file:at.kc.tugraz.ss.serv.dataimport.impl.fct.op.SSDataImportAchsoFct.java

License:Apache License

public static List<SSi5CloudAchsoVideo> getVideoObjs(final SSUri userUri, final String vidXML)
        throws Exception {

    try {/*from   w w  w .j a  v  a  2 s  . c  om*/
        final Document document = DocumentHelper.parseText(vidXML);
        final Element rootElement = document.getRootElement();
        final Iterator vidIterator = rootElement.elementIterator();
        final List<SSi5CloudAchsoVideo> videos = new ArrayList<>();
        Iterator vidContentIterator;
        Element vid;
        Element vidContent;
        String title;
        String video_uri;
        String creator;
        Long created_at;
        List<String> annotations;
        List<String> keywords;
        SSi5CloudAchsoVideo videoObj;

        while (vidIterator.hasNext()) {

            vid = (Element) vidIterator.next();
            vidContentIterator = vid.elementIterator();
            title = null;
            video_uri = null;
            creator = null;
            created_at = null;
            annotations = new ArrayList<>();
            keywords = new ArrayList<>();

            while (vidContentIterator.hasNext()) {

                vidContent = (Element) vidContentIterator.next();

                switch (SSI5CloudAchsoVideoMetaDataE.get(vidContent.getName())) {

                case title:
                    title = (String) vidContent.getData();
                    break;
                case video_uri:
                    video_uri = (String) vidContent.getData();
                    break;
                case creator:
                    creator = (String) vidContent.getData();
                    break;
                case created_at:
                    created_at = getCreationTime((String) vidContent.getData());
                    break;
                case keywords:
                    keywords = getKeywords(vidContent.nodeIterator());
                    break;
                case annotations:
                    annotations = getAnnotations(vidContent.nodeIterator());
                    break;
                }
            }

            try {
                videoObj = SSi5CloudAchsoVideo.get(SSUri.get(video_uri), SSLabel.get(title),
                        SSLabel.get(creator), keywords, annotations);

                videoObj.creationTime = created_at;

                videos.add(videoObj);

            } catch (Exception error) {
                SSLogU.warn("couldnt add vid: " + video_uri);
            }
        }

        return videos;
    } catch (Exception error) {
        SSServErrReg.regErrThrow(error);
        return null;
    }
}

From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java

License:Open Source License

private ArrayList<String> checkUpCatalogRepositoryForTreeObject(TreeObject theObj, TreeObject folder) {
    if (theObj.getType() == 0 || theObj.getType() == TreeObject.CATEGORY_FOLDER) {
        return null;
    }//from  w w w.j a  v a  2s .c o m
    try {
        String modelName = getXPathForTreeObject(folder);
        String url = getURLFromTreeObject(theObj);

        String xpath = modelName + "//child::*[text() = '" + TreeObject.CATEGORY_FOLDER + "' and @Url='" + url //$NON-NLS-1$//$NON-NLS-2$
                + "']//child::*";//$NON-NLS-1$

        Document doc = credentials.get(getURLFromTreeObject(folder)).doc;
        List<Element> elems = doc.selectNodes(xpath);
        for (Element elem : elems) {
            String xpathElem = getXPathForElem(elem);
            String xpathObj = getXPathForTreeObject(theObj);
            int squarebk = xpathObj.indexOf("[");//$NON-NLS-1$
            if (squarebk != -1) {
                xpathObj = xpathObj.substring(0, squarebk);
            }
            if (elem.getName().equals(filterOutBlank(theObj.getDisplayName()))
                    && elem.getData().toString().equals(theObj.getType() + "")) {//$NON-NLS-1$
                ArrayList<String> path = new ArrayList<String>();
                HashMap<Integer, String> slice = new HashMap<Integer, String>();
                while (isAEXtentisObjects(elem, theObj) > XTENTIS_LEVEL) {
                    String elemName = elem.getParent().getName();
                    if (elem.getParent().attributeValue(REALNAME) != null) {
                        elemName = elem.getParent().attributeValue(REALNAME);
                    }
                    if (elem.getText() != null && StringUtils.trim(elem.getParent().getText())
                            .equals(TreeObject.CATEGORY_FOLDER + "")) {//$NON-NLS-1$
                        path.add(elem.getParent().getName());
                        if (elem.getParent().attributeValue(REALNAME) != null) {
                            slice.put(path.size() - 1, elem.getParent().attributeValue(REALNAME));
                        }
                    }

                    elem = elem.getParent();
                }

                ArrayList<String> pathCpy = new ArrayList<String>(path);
                Collections.reverse(path);
                if (!isEqualString(xpathElem, xpathObj, path)) {
                    path = null;
                }
                if (path != null) {
                    for (int i = 0; i < pathCpy.size(); i++) {
                        if (slice.get(i) != null) {
                            pathCpy.set(i, slice.get(i));
                        }
                    }
                    Collections.reverse(pathCpy);
                    path = pathCpy;
                }
                return path;
            }
        }
    } catch (Exception ex) {
        return null;
    }

    return null;
}

From source file:com.ewcms.content.particular.util.XmlConvert.java

License:Open Source License

@SuppressWarnings("unchecked")
public static List<Map<String, Object>> importXML(File xmlFile, String fileType) {
    if (xmlFile != null) {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        try {//  w ww. j  a  va2s  . c  o  m
            List<InputStream> inputStreams = new ArrayList<InputStream>();
            //FileType fileType = FileTypeJudge.getType(xmlFile);
            if (fileType.toLowerCase().equals("application/zip")) {
                inputStreams = parseXmlZIPFile(xmlFile);
            } else if (fileType.toLowerCase().equals("text/xml")) {
                InputStream in = new FileInputStream(xmlFile);
                inputStreams.add(in);
            } else {
                return null;
            }
            if (!inputStreams.isEmpty()) {
                SAXReader reader = new SAXReader();
                Document doc = null;
                for (InputStream inputStream : inputStreams) {
                    try {
                        doc = reader.read(inputStream);
                        if (doc != null) {
                            Element root = doc.getRootElement();
                            Element metaViewData;
                            Element projecties;
                            for (Iterator<?> metaViewDataIterator = root
                                    .elementIterator("MetaViewData"); metaViewDataIterator.hasNext();) {
                                metaViewData = (Element) metaViewDataIterator.next();
                                for (Iterator<?> projectiesIterator = metaViewData
                                        .elementIterator("PROPERTIES"); projectiesIterator.hasNext();) {
                                    projecties = (Element) projectiesIterator.next();
                                    List<Element> elements = projecties.elements();
                                    if (!elements.isEmpty()) {
                                        Map<String, Object> map = new HashMap<String, Object>();
                                        for (Element element : elements) {
                                            map.put(element.getName(), element.getData());
                                        }
                                        list.add(map);
                                    }
                                }
                            }
                        }
                    } catch (DocumentException e) {
                    } finally {
                        if (doc != null) {
                            doc.clearContent();
                            doc = null;
                        }
                    }
                }
            }
        } catch (IOException e) {
            return null;
        }
        return list;
    }
    return null;
}

From source file:com.openkm.openmeetings.service.RestService.java

License:Open Source License

/**
 * call/*  w ww.j a v  a 2 s  .com*/
 * 
 * @param request
 * @param param
 * @return
 * @throws Exception
 */
public static Map<String, Element> callMap(String request, Object param) throws Exception {
    HttpClient client = new HttpClient();
    GetMethod method = null;
    try {
        method = new GetMethod(getEncodetURI(request).toString());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    int statusCode = 0;
    try {
        statusCode = client.executeMethod(method);
    } catch (HttpException e) {
        throw new Exception(
                "Connection to OpenMeetings refused. Please check your OpenMeetings configuration.");
    } catch (IOException e) {
        throw new Exception(
                "Connection to OpenMeetings refused. Please check your OpenMeetings configuration.");
    }

    switch (statusCode) {
    case 200: // OK
        break;
    case 400:
        throw new Exception(
                "Bad request. The parameters passed to the service did not match as expected. The Message should tell you what was missing or incorrect.");
    case 403:
        throw new Exception(
                "Forbidden. You do not have permission to access this resource, or are over your rate limit.");
    case 503:
        throw new Exception(
                "Service unavailable. An internal problem prevented us from returning data to you.");
    default:
        throw new Exception("Your call to OpenMeetings! Web Services returned an unexpected  HTTP status of: "
                + statusCode);
    }

    InputStream rstream = null;
    try {
        rstream = method.getResponseBodyAsStream();
    } catch (IOException e) {
        e.printStackTrace();
        throw new Exception("No Response Body");
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(rstream));
    SAXReader reader = new SAXReader();
    Document document = null;
    String line;
    try {
        while ((line = br.readLine()) != null) {
            document = reader.read(new ByteArrayInputStream(line.getBytes("UTF-8")));
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        throw new Exception("UnsupportedEncodingException by SAXReader");
    } catch (IOException e) {
        e.printStackTrace();
        throw new Exception("IOException by SAXReader in REST Service");
    } catch (DocumentException e) {
        e.printStackTrace();
        throw new Exception("DocumentException by SAXReader in REST Service");
    } finally {
        br.close();
    }

    Element root = document.getRootElement();
    Map<String, Element> elementMap = new LinkedHashMap<String, Element>();

    for (@SuppressWarnings("unchecked")
    Iterator<Element> it = root.elementIterator(); it.hasNext();) {
        Element item = it.next();
        if (item.getNamespacePrefix() == "soapenv") {
            throw new Exception(item.getData().toString());
        }
        String nodeVal = item.getName();
        elementMap.put(nodeVal, item);
    }

    return elementMap;
}

From source file:com.openkm.openmeetings.service.RestService.java

License:Open Source License

/**
 * call/*from w  w  w  .  j a va  2s  .c  o m*/
 * 
 * @param request
 * @param param
 * @return
 * @throws Exception
 */
public static List<Element> callList(String request, Object param) throws Exception {
    HttpClient client = new HttpClient();
    GetMethod method = null;
    try {
        method = new GetMethod(getEncodetURI(request).toString());
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    int statusCode = 0;
    try {
        statusCode = client.executeMethod(method);
    } catch (HttpException e) {
        throw new Exception(
                "Connection to OpenMeetings refused. Please check your OpenMeetings configuration.");
    } catch (IOException e) {
        throw new Exception(
                "Connection to OpenMeetings refused. Please check your OpenMeetings configuration.");
    }

    switch (statusCode) {
    case 200: // OK
        break;
    case 400:
        throw new Exception(
                "Bad request. The parameters passed to the service did not match as expected. The Message should tell you what was missing or incorrect.");
    case 403:
        throw new Exception(
                "Forbidden. You do not have permission to access this resource, or are over your rate limit.");
    case 503:
        throw new Exception(
                "Service unavailable. An internal problem prevented us from returning data to you.");
    default:
        throw new Exception("Your call to OpenMeetings! Web Services returned an unexpected  HTTP status of: "
                + statusCode);
    }

    InputStream rstream = null;
    try {
        rstream = method.getResponseBodyAsStream();
    } catch (IOException e) {
        e.printStackTrace();
        throw new Exception("No Response Body");
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(rstream));
    SAXReader reader = new SAXReader();
    Document document = null;
    String line;
    try {
        while ((line = br.readLine()) != null) {
            document = reader.read(new ByteArrayInputStream(line.getBytes("UTF-8")));
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        throw new Exception("UnsupportedEncodingException by SAXReader");
    } catch (IOException e) {
        e.printStackTrace();
        throw new Exception("IOException by SAXReader in REST Service");
    } catch (DocumentException e) {
        e.printStackTrace();
        throw new Exception("DocumentException by SAXReader in REST Service");
    } finally {
        br.close();
    }

    Element root = document.getRootElement();
    List<Element> elementList = new ArrayList<Element>();

    for (@SuppressWarnings("unchecked")
    Iterator<Element> it = root.elementIterator(); it.hasNext();) {
        Element item = it.next();
        if (item.getNamespacePrefix() == "soapenv") {
            throw new Exception(item.getData().toString());
        }
        elementList.add(item);
    }

    return elementList;
}

From source file:com.sammyun.util.XmlHelper.java

License:Open Source License

/**
 * ?XMLDto(?XML?)//ww  w . j  ava 2 s.  com
 * 
 * @param pStrXml ?XML
 * @return outDto Dto
 */
public static final Dto parseXml2DtoBasedNode(String pStrXml) {
    Dto outDto = new BaseDto();
    String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    Document document = null;
    try {
        if (pStrXml.indexOf("<?xml") < 0)
            pStrXml = strTitle + pStrXml;
        document = DocumentHelper.parseText(pStrXml);
    } catch (DocumentException e) {
        logger.error(
                "==??:==\nXML??XML DOM?!"
                        + "\n?:");
        e.printStackTrace();
    }
    if (document != null) {
        // ?
        Element elNode = document.getRootElement();
        // ??Dto
        for (Iterator it = elNode.elementIterator(); it.hasNext();) {
            Element leaf = (Element) it.next();
            outDto.put(leaf.getName().toLowerCase(), leaf.getData());
        }
    }
    return outDto;
}

From source file:com.sammyun.util.XmlHelper.java

License:Open Source License

/**
 * ?XMLDto(?XML?)/*from ww  w.j  a  v  a2s  .c  o  m*/
 * 
 * @param pStrXml ?XML
 * @param pXPath ("//paralist/row" paralistrowxPath)
 * @return outDto Dto
 */
public static final Dto parseXml2DtoBasedNode(String pStrXml, String pXPath) {
    Dto outDto = new BaseDto();
    String strTitle = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    Document document = null;
    try {
        if (pStrXml.indexOf("<?xml") < 0)
            pStrXml = strTitle + pStrXml;
        document = DocumentHelper.parseText(pStrXml);
    } catch (DocumentException e) {
        logger.error(
                "==??:==\nXML??XML DOM?!"
                        + "\n?:");
        e.printStackTrace();
    }
    if (document != null) {
        // ?
        Element elNode = document.getRootElement();
        // ??Dto
        for (Iterator it = elNode.elementIterator(); it.hasNext();) {
            Element leaf = (Element) it.next();
            outDto.put(leaf.getName().toLowerCase(), leaf.getData());
        }
    }
    return outDto;
}

From source file:com.shlaunch.weixin.local.web.WeixinController.java

License:Open Source License

/**
 * parse?,map/*from  w  w w .j a  v a 2  s  .co m*/
 *
 * @param request
 * @return
 * @throws IOException
 * @throws DocumentException
 */
private Map<String, Object> parseInputStream(HttpServletRequest request) throws IOException, DocumentException {
    Map<String, Object> elementMap = null;
    ServletInputStream inputStream = request.getInputStream();

    if (null != inputStream) {

        String postStr = this.readStreamParameter(inputStream);

        Document document = null;
        try {
            document = DocumentHelper.parseText(postStr);
        } catch (Exception e) {
            logger.debug(e);
            e.printStackTrace();
        }
        if (null != document) {
            elementMap = new HashMap<String, Object>();
            Element rootElm = document.getRootElement();

            for (Iterator<Element> iterator = rootElm.elementIterator(); iterator.hasNext();) {
                Element element = iterator.next();
                String name = element.getName();
                Object data = element.getData();
                elementMap.put(name, data);
            }
        }
    }
    return elementMap;
}

From source file:com.sjdf.platform.attachment.helper.AttachmentHelper.java

/**
 * ?XMLVO List/*from  w  ww .  jav  a  2  s .  c  o m*/
 *
 * @param xml XML
 * @return VO List
 */
@SuppressWarnings("unchecked")
public static List<AttachmentHouseVo> parse(String xml) throws Exception {
    List<AttachmentHouseVo> attachmentVoList = new ArrayList<>();
    SAXReader saxReader = new SAXReader();
    try (InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"))) {
        Document document = saxReader.read(is);

        Node node = document.selectSingleNode("/error");
        if (node != null) {
            LOGGER.error(xml);
            throw new RuntimeException(((Element) node).getData().toString());
        }

        Element root = (Element) document.selectSingleNode("/attachmentList");
        List<Element> xmlDictionaryList = root.elements();
        if (xmlDictionaryList != null && !xmlDictionaryList.isEmpty()) {
            for (Element element : xmlDictionaryList) {
                List<Element> xmlDictionary = element.elements();

                AttachmentHouseVo attachmentHouseVo = new AttachmentHouseVo();
                for (Element e : xmlDictionary) {
                    if (e.elements().isEmpty() && (Tools.isEmpty(e.getData().toString())
                            || "null".equals(e.getData().toString()))) {
                        continue;
                    }
                    if ("path".equals(e.getName())) {
                        attachmentHouseVo.setPath(e.getData().toString());
                    } else if ("userId".equals(e.getName())) {
                        attachmentHouseVo.setUserId(Long.valueOf(e.getData().toString()));
                    } else if ("attachmentUseCode".equals(e.getName())) {
                        attachmentHouseVo.setAttachmentUseCode(Long.valueOf(e.getData().toString()));
                    } else if ("attachmentUseType".equals(e.getName())) {
                        attachmentHouseVo.setAttachmentUseType(Long.valueOf(e.getData().toString()));
                    } else if ("systemType".equals(e.getName())) {
                        attachmentHouseVo.setSystemType(Long.valueOf(e.getData().toString()));
                    } else if ("markDelete".equals(e.getName())) {
                        attachmentHouseVo.setMarkDelete(Long.valueOf(e.getData().toString()));
                    } else if ("remark".equals(e.getName())) {
                        attachmentHouseVo.setRemark(e.getData().toString());
                    } else if ("byte".equals(e.getName())) {
                        attachmentHouseVo.setAttachmentFileString(e.getData().toString());
                    } else if ("username".equals(e.getName())) {
                        attachmentHouseVo.setUsername(e.getData().toString());
                    } else if ("whetherChanged".equals(e.getName())) {
                        attachmentHouseVo.setWhetherChanged(Long.valueOf(e.getData().toString()));
                    } else if ("format".equals(e.getName())) {
                        attachmentHouseVo.setFormat(Long.valueOf(e.getData().toString()));
                    } else if ("sourcePath".equals(e.getName())) {
                        attachmentHouseVo.setSourcePath(e.getData().toString());
                    } else if ("subSystemPath".equals(e.getName())) {
                        attachmentHouseVo.setSubSystemPath(e.getData().toString());
                    } else if ("attachmentId".equals(e.getName())) {
                        attachmentHouseVo.setId(Long.valueOf(e.getData().toString()));
                    } else if ("auditResult".equals(e.getName())) {
                        attachmentHouseVo.setAuditResult(Long.valueOf(e.getData().toString()));
                    } else if ("fontColor".equals(e.getName())) {
                        attachmentHouseVo.setFontColor(Long.valueOf(e.getData().toString()));
                    } else if ("createTime".equals(e.getName())) {
                        attachmentHouseVo.setBeginDate(e.getData().toString());
                    } else if ("updateTime".equals(e.getName())) {
                        attachmentHouseVo.setEndDate(e.getData().toString());
                    } else if ("attachmentUseTypeMark".equals(e.getName())) {
                        attachmentHouseVo.setAttachmentUseTypeMark(e.getData().toString());
                    } else if ("attachmentSpecialMark".equals(e.getName())) {
                        //? element?
                        List<Element> ppgjzElementList = e.elements();
                        String specialMark;
                        if (ppgjzElementList.isEmpty() && !Tools.isEmpty(e.getData().toString())) {
                            specialMark = e.getData().toString();
                        } else {
                            specialMark = parseAttachmentSpecialMark(attachmentHouseVo.getAttachmentUseType(),
                                    attachmentHouseVo.getAttachmentUseCode(), ppgjzElementList);
                        }
                        attachmentHouseVo.setAttachmentSpecialMark(specialMark);
                    }
                }
                attachmentVoList.add(attachmentHouseVo);
            }
        }
    }
    return attachmentVoList;
}

From source file:com.taobao.sqlautoreview.HandleXMLConf.java

License:Open Source License

public String getDbConfigIP() {
    String ip = "";
    ///* ww w.ja va 2s.c  o  m*/
    for (Iterator<Element> r = root.elementIterator(); r.hasNext();) {
        Element tmp = r.next();
        if (tmp.getName().equals("ip")) {
            ip = tmp.getData().toString();
        }
    }
    return ip;
}