Example usage for org.jdom2 Element getChildText

List of usage examples for org.jdom2 Element getChildText

Introduction

In this page you can find the example usage for org.jdom2 Element getChildText.

Prototype

public String getChildText(final String cname, final Namespace ns) 

Source Link

Document

Returns the textual content of the named child element, or null if there's no such child.

Usage

From source file:ca.nrc.cadc.uws.JobReader.java

License:Open Source License

private Job parseJob(Document doc) throws ParseException, DataConversionException {
    Element root = doc.getRootElement();

    String jobID = root.getChildText(JobAttribute.JOB_ID.getAttributeName(), UWS.NS);
    if (jobID != null && jobID.trim().length() == 0)
        jobID = null;//from   w w  w  .  j av a  2s .  c  o m
    String runID = parseStringContent(root.getChild(JobAttribute.RUN_ID.getAttributeName(), UWS.NS));
    String ownerID = parseStringContent(root.getChild(JobAttribute.OWNER_ID.getAttributeName(), UWS.NS));
    Date quote = parseDate(parseStringContent(root.getChild(JobAttribute.QUOTE.getAttributeName(), UWS.NS)));
    Date startTime = parseDate(
            parseStringContent(root.getChild(JobAttribute.START_TIME.getAttributeName(), UWS.NS)));
    Date endTime = parseDate(
            parseStringContent(root.getChild(JobAttribute.END_TIME.getAttributeName(), UWS.NS)));
    Date creationTime = parseDate(
            parseStringContent(root.getChild(JobAttribute.CREATION_TIME.getAttributeName(), UWS.NS)));
    Date destructionTime = parseDate(
            parseStringContent(root.getChild(JobAttribute.DESTRUCTION_TIME.getAttributeName(), UWS.NS)));
    Long executionDuration = new Long(
            parseStringContent(root.getChild(JobAttribute.EXECUTION_DURATION.getAttributeName(), UWS.NS)));

    ExecutionPhase executionPhase = parseExecutionPhase(doc);

    ErrorSummary errorSummary = null;
    if (executionPhase.equals(ExecutionPhase.ERROR))
        errorSummary = parseErrorSummary(doc);

    List<Result> resultsList = parseResultsList(doc);

    List<Parameter> parameterList = parseParametersList(doc);

    JobInfo jobInfo = parseJobInfo(doc);

    Job job = new Job(jobID, executionPhase, executionDuration, destructionTime, quote, startTime, endTime,
            creationTime, errorSummary, ownerID, runID, null, null, jobInfo, parameterList, resultsList);

    return job;
}

From source file:ca.nrc.cadc.uws.JobReader.java

License:Open Source License

private ExecutionPhase parseExecutionPhase(Document doc) {
    ExecutionPhase rtn = null;/*from  w  w  w . j a va 2  s.  c  om*/
    Element root = doc.getRootElement();
    String strPhase = root.getChildText(JobAttribute.EXECUTION_PHASE.getAttributeName(), UWS.NS);
    if (strPhase.equalsIgnoreCase(ExecutionPhase.PENDING.toString()))
        rtn = ExecutionPhase.PENDING;
    else if (strPhase.equalsIgnoreCase(ExecutionPhase.QUEUED.toString()))
        rtn = ExecutionPhase.QUEUED;
    else if (strPhase.equalsIgnoreCase(ExecutionPhase.EXECUTING.toString()))
        rtn = ExecutionPhase.EXECUTING;
    else if (strPhase.equalsIgnoreCase(ExecutionPhase.COMPLETED.toString()))
        rtn = ExecutionPhase.COMPLETED;
    else if (strPhase.equalsIgnoreCase(ExecutionPhase.ERROR.toString()))
        rtn = ExecutionPhase.ERROR;
    else if (strPhase.equalsIgnoreCase(ExecutionPhase.UNKNOWN.toString()))
        rtn = ExecutionPhase.UNKNOWN;
    else if (strPhase.equalsIgnoreCase(ExecutionPhase.HELD.toString()))
        rtn = ExecutionPhase.HELD;
    else if (strPhase.equalsIgnoreCase(ExecutionPhase.SUSPENDED.toString()))
        rtn = ExecutionPhase.SUSPENDED;
    else if (strPhase.equalsIgnoreCase(ExecutionPhase.ABORTED.toString()))
        rtn = ExecutionPhase.ABORTED;

    return rtn;
}

From source file:ca.nrc.cadc.uws.JobReader.java

License:Open Source License

private ErrorSummary parseErrorSummary(Document doc) {
    ErrorSummary rtn = null;//from  w ww  . j a va  2s  .  c  o  m
    Element root = doc.getRootElement();
    Element e = root.getChild(JobAttribute.ERROR_SUMMARY.getAttributeName(), UWS.NS);
    if (e != null) {
        ErrorType errorType = null;
        String strType = e.getAttributeValue("type");
        if (strType.equalsIgnoreCase(ErrorType.FATAL.toString()))
            errorType = ErrorType.FATAL;
        else if (strType.equalsIgnoreCase(ErrorType.TRANSIENT.toString()))
            errorType = ErrorType.TRANSIENT;

        boolean hasDetail = false;
        String strDetail = e.getAttributeValue("hasDetail");
        if (strDetail.equalsIgnoreCase("true"))
            hasDetail = true;

        String summaryMessage = e.getChildText(JobAttribute.ERROR_SUMMARY_MESSAGE.getAttributeName(), UWS.NS);
        rtn = new ErrorSummary(summaryMessage, errorType, hasDetail);
    }
    return rtn;
}

From source file:ca.nrc.cadc.vos.TransferReader.java

License:Open Source License

private Transfer parseTransfer(Document document) throws URISyntaxException {
    Element root = document.getRootElement();

    Direction direction = parseDirection(root);
    // String serviceUrl; // not in XML yet
    VOSURI target = new VOSURI(root.getChildText("target", VOS_NS));

    // TODO: get view nodes and uri attribute
    View view = null;// w w  w  .j  a v a  2 s.c  om
    Parameter param = null;
    List views = root.getChildren("view", VOS_NS);
    if (views != null && views.size() > 0) {
        Element v = (Element) views.get(0);
        view = new View(new URI(v.getAttributeValue("uri")));
        List params = v.getChildren("param", VOS_NS);
        if (params != null) {
            for (Object o : params) {
                Element p = (Element) o;
                param = new Parameter(new URI(p.getAttributeValue("uri")), p.getText());
                view.getParameters().add(param);
            }
        }
    }
    List<Protocol> protocols = parseProtocols(root);
    String keepBytesStr = root.getChildText("keepBytes", VOS_NS);

    if (keepBytesStr != null) {
        boolean keepBytes = true;
        keepBytes = keepBytesStr.equalsIgnoreCase("true");
        return new Transfer(target, direction, view, protocols, keepBytes);
    }
    return new Transfer(target, direction, view, protocols);
}

From source file:ca.nrc.cadc.vos.TransferReader.java

License:Open Source License

private Direction parseDirection(Element root) {
    Direction rtn = null;//from   w ww. j  a  va2  s  .c o  m
    String strDirection = root.getChildText("direction", VOS_NS);

    if (strDirection == null)
        throw new RuntimeException("Did not find direction element in XML.");

    if (strDirection.equalsIgnoreCase(Direction.pullFromVoSpace.getValue()))
        rtn = Direction.pullFromVoSpace;
    else if (strDirection.equalsIgnoreCase(Direction.pullToVoSpace.getValue()))
        rtn = Direction.pullToVoSpace;
    else if (strDirection.equalsIgnoreCase(Direction.pushFromVoSpace.getValue()))
        rtn = Direction.pushFromVoSpace;
    else if (strDirection.equalsIgnoreCase(Direction.pushToVoSpace.getValue()))
        rtn = Direction.pushToVoSpace;
    else
        rtn = new Direction(strDirection);
    return rtn;
}

From source file:ca.nrc.cadc.vos.TransferReader.java

License:Open Source License

private List<Protocol> parseProtocols(Element root) {
    List<Protocol> rtn = null;
    //Element e = root.getChild("protocols", NS);
    List prots = root.getChildren("protocol", VOS_NS);
    if (prots != null && prots.size() > 0) {
        rtn = new ArrayList<Protocol>(prots.size());
        for (Object obj : prots) {
            Element eProtocol = (Element) obj;
            String uri = eProtocol.getAttributeValue("uri");
            String endpoint = eProtocol.getChildText("endpoint", VOS_NS);
            rtn.add(new Protocol(uri, endpoint, null));
        }/*from w  ww  .  j a  va2  s.  co m*/
    }
    return rtn;
}

From source file:com.eds.Model.XMLProcessor.java

License:Apache License

public SearchResponse ProcessSearchResponse(ServiceResponse serviceResponse) {

    BufferedReader reader = serviceResponse.getReader();
    SearchResponse searchResponse = new SearchResponse();
    if (null != serviceResponse.getErrorStream() && !serviceResponse.getErrorStream().isEmpty()) {
        searchResponse.setApierrormessage(
                ProcessError(serviceResponse.getErrorNumber(), serviceResponse.getErrorStream()));
    } else {//ww  w  .ja  v  a  2  s .c om
        String resultsListXML = "";
        try {
            String line = "";
            while ((line = reader.readLine()) != null) {
                resultsListXML += line;
            }
        } catch (IOException e1) {
            ApiErrorMessage errorMessage = new ApiErrorMessage();
            errorMessage.setErrorDescription("Error processing search response");
            errorMessage.setDetailedErrorDescription(e1.getMessage());
            searchResponse.setApierrormessage(errorMessage);
        }

        try {
            StringReader stringReader = new StringReader(resultsListXML);
            InputSource inputSource = new InputSource(stringReader);
            Document doc = (new SAXBuilder()).build(inputSource);
            // Process root element
            Element searchResponseMessageGet = doc.getRootElement();

            Element searchResult = searchResponseMessageGet.getChild("SearchResult",
                    searchResponseMessageGet.getNamespace());

            // Process search request message returned in the response.
            Element searchRequestGet = searchResponseMessageGet.getChild("SearchRequestGet",
                    searchResponseMessageGet.getNamespace());
            if (null != searchRequestGet) {

                // process the querystring
                String queryString = searchRequestGet.getChildText("QueryString",
                        searchRequestGet.getNamespace());
                searchResponse.setQueryString(queryString);

                // Process search criteria
                Element searchCriteriaWithActions = searchRequestGet.getChild("SearchCriteriaWithActions",
                        searchRequestGet.getNamespace());
                if (null != searchCriteriaWithActions) {

                    // Process Queries with actions
                    ArrayList<QueryWithAction> queryList = new ArrayList<QueryWithAction>();
                    Element queriesWithAction = searchCriteriaWithActions.getChild("QueriesWithAction",
                            searchCriteriaWithActions.getNamespace());
                    if (null != queriesWithAction) {
                        List<Element> queriesWithActions = queriesWithAction.getChildren();
                        for (Element queryWithAction : queriesWithActions) {
                            QueryWithAction queryObject = new QueryWithAction();
                            String removeAction = queryWithAction.getChildText("RemoveAction",
                                    queryWithAction.getNamespace());
                            queryObject.setRemoveAction(removeAction);

                            Element query = queryWithAction.getChild("Query", queryWithAction.getNamespace());
                            if (null != query) {
                                String term = query.getChildText("Term", queryWithAction.getNamespace());
                                String fieldCode = queryWithAction.getChildText("FieldCode",
                                        queryWithAction.getNamespace());
                                String booleanOperator = queryWithAction.getChildText("BooleanOperator",
                                        queryWithAction.getNamespace());
                                queryObject.setTerm(term);
                                queryObject.setFieldCode(fieldCode);
                                queryObject.setOperator(booleanOperator);
                            }
                            queryList.add(queryObject);
                        }
                    }
                    searchResponse.setQueryList(queryList);
                    if (null != searchResponse.getQueryList() && !searchResponse.getQueryList().isEmpty())
                        searchResponse.setQuery(searchResponse.getQueryList().get(0));

                    // process limiters with action
                    ArrayList<LimiterWithAction> limiterList = new ArrayList<LimiterWithAction>();
                    Element limitersWithAction = searchCriteriaWithActions.getChild("LimitersWithAction",
                            searchCriteriaWithActions.getNamespace());
                    if (limitersWithAction != null) {
                        List<Element> eLimitersWithAction = limitersWithAction.getChildren();
                        for (int i = 0; i < eLimitersWithAction.size(); i++) {
                            Element eLimiterWithAction = (Element) eLimitersWithAction.get(i);
                            LimiterWithAction lwa = new LimiterWithAction();
                            String Id = eLimiterWithAction.getChildText("Id",
                                    eLimiterWithAction.getNamespace());
                            String removeAction = eLimiterWithAction.getChildText("RemoveAction",
                                    eLimiterWithAction.getNamespace());
                            lwa.setId(Id);
                            lwa.setRemoveAction(removeAction);

                            Element eLimiterValuesWithAction = eLimiterWithAction
                                    .getChild("LimiterValuesWithAction", eLimiterWithAction.getNamespace());
                            List<Element> limiterValuesWithActionList = eLimiterValuesWithAction.getChildren();
                            ArrayList<LimiterValueWithAction> lvalist = new ArrayList<LimiterValueWithAction>();
                            for (int j = 0; j < limiterValuesWithActionList.size(); j++) {
                                LimiterValueWithAction lvwa = new LimiterValueWithAction();
                                Element eLimiterValueWithAction = (Element) limiterValuesWithActionList.get(j);
                                String value = eLimiterValueWithAction.getChildText("Value",
                                        eLimiterValueWithAction.getNamespace());

                                String vRemoveAction = eLimiterValueWithAction.getChildText("RemoveAction",
                                        eLimiterValueWithAction.getNamespace());
                                lvwa.setValue(value);
                                lvwa.setRemoveAction(vRemoveAction);
                                lvalist.add(lvwa);
                            }
                            lwa.setLvalist(lvalist);
                            limiterList.add(lwa);
                        }
                    }
                    searchResponse.setSelectedLimiterList(limiterList);

                    // Process applied expanders
                    ArrayList<ExpandersWithAction> expanderList = new ArrayList<ExpandersWithAction>();

                    Element ExpandersWithAction = searchCriteriaWithActions.getChild("ExpandersWithAction",
                            searchCriteriaWithActions.getNamespace());
                    if (ExpandersWithAction != null) {
                        List<Element> expandersWithActionList = ExpandersWithAction.getChildren();
                        for (int i = 0; i < expandersWithActionList.size(); i++) {
                            Element expanderWithAction = (Element) expandersWithActionList.get(i);
                            ExpandersWithAction ewa = new ExpandersWithAction();
                            String id = expanderWithAction.getChildText("Id",
                                    expanderWithAction.getNamespace());
                            String removeAction = expanderWithAction.getChildText("RemoveAction",
                                    expanderWithAction.getNamespace());
                            ewa.setId(id);
                            ewa.setRemoveAction(removeAction);
                            expanderList.add(ewa);
                        }
                    }
                    searchResponse.setExpanderwithActionList(expanderList);

                    // process applied facets
                    ArrayList<FacetFilterWithAction> facetFiltersList = new ArrayList<FacetFilterWithAction>();
                    Element facetFiltersWithAction = searchCriteriaWithActions
                            .getChild("FacetFiltersWithAction", searchCriteriaWithActions.getNamespace());
                    if (facetFiltersWithAction != null) {
                        for (Element facetFilterWithActionXML : facetFiltersWithAction.getChildren()) {
                            FacetFilterWithAction facetWithAction = new FacetFilterWithAction();

                            String filterId = facetFilterWithActionXML.getChildText("FilterId",
                                    facetFilterWithActionXML.getNamespace());
                            String removeAction = facetFilterWithActionXML.getChildText("RemoveAction",
                                    facetFilterWithActionXML.getNamespace());
                            facetWithAction.setFilterId(filterId);
                            facetWithAction.setRemoveAction(removeAction);

                            ArrayList<FacetValueWithAction> facetValuesWithActionList = new ArrayList<FacetValueWithAction>();
                            Element facetValuesWithAction = facetFilterWithActionXML
                                    .getChild("FacetValuesWithAction", facetFilterWithActionXML.getNamespace());

                            for (Element facetValueWithAction : facetValuesWithAction.getChildren()) {

                                FacetValueWithAction fvwa = new FacetValueWithAction();
                                String eRemoveAction = facetValueWithAction.getChildText("RemoveAction",
                                        facetValueWithAction.getNamespace());
                                fvwa.setRemoveAction(eRemoveAction);

                                Element eFacetValue = facetValueWithAction.getChild("FacetValue",
                                        facetValueWithAction.getNamespace());

                                if (null != eFacetValue) {
                                    EachFacetValue efv = new EachFacetValue();
                                    String id = eFacetValue.getChildText("Id", eFacetValue.getNamespace());
                                    String value = eFacetValue.getChildText("Value",
                                            eFacetValue.getNamespace());
                                    efv.setValue(value);
                                    efv.setId(id);
                                    fvwa.setEachfacetvalue(efv);
                                }
                                facetValuesWithActionList.add(fvwa);
                            }
                            facetWithAction.setFacetvaluewithaction(facetValuesWithActionList);
                            facetFiltersList.add(facetWithAction);
                        }
                    }
                    searchResponse.setFacetfiltersList(facetFiltersList);
                }
            }
            // Process the search result returned in the response

            // Get Total Hits and Total Search Time
            Element statistics = searchResult.getChild("Statistics", searchResult.getNamespace());
            long hits = 0;
            if (null != statistics) {
                String totalHits = statistics.getChildText("TotalHits", statistics.getNamespace());
                try {
                    hits = Long.parseLong(totalHits);
                } catch (Exception e) {
                    hits = 0;
                }
                String totalSearchTime = statistics.getChildText("TotalSearchTime", statistics.getNamespace());
                searchResponse.setSearchTime(totalSearchTime);
            }
            searchResponse.setHits(String.valueOf(hits));
            if (hits > 0) {
                // process results Results
                Element data = searchResult.getChild("Data", searchResult.getNamespace());
                if (null != data) {
                    Element records = data.getChild("Records", data.getNamespace());
                    if (null != records) {
                        List<Element> recordsList = records.getChildren();
                        for (int i = 0; i < recordsList.size(); i++) {
                            Element record = (Element) recordsList.get(i);
                            Result result = constructRecord(record);
                            searchResponse.getResultsList().add(result);
                        }
                    }
                }

                // Get Facets. if there are no hits, don't bother checking
                // facets
                Element availableFacets = searchResult.getChild("AvailableFacets", searchResult.getNamespace());
                if (null != availableFacets) {
                    List<Element> facetsList = availableFacets.getChildren();
                    for (int e = 0; e < facetsList.size(); e++) {
                        Facet facet = new Facet();
                        Element availableFacet = (Element) facetsList.get(e);
                        String id = availableFacet.getChildText("Id", availableFacet.getNamespace());
                        String label = availableFacet.getChildText("Label", availableFacet.getNamespace());
                        facet.setId(id);
                        facet.setLabel(label);

                        Element availableFacetValues = availableFacet.getChild("AvailableFacetValues",
                                availableFacet.getNamespace());
                        if (null != availableFacetValues) {
                            List<Element> availableFacetValuesList = availableFacetValues.getChildren();
                            for (int f = 0; f < availableFacetValuesList.size(); f++) {
                                FacetValue facetValue = new FacetValue();
                                Element availableFacetValue = (Element) availableFacetValuesList.get(f);
                                String value = availableFacetValue.getChildText("Value",
                                        availableFacetValue.getNamespace());
                                String count = availableFacetValue.getChildText("Count",
                                        availableFacetValue.getNamespace());
                                String addAction = availableFacetValue.getChildText("AddAction",
                                        availableFacetValue.getNamespace());
                                facetValue.setValue(value);
                                facetValue.setCount(count);
                                facetValue.setAddAction(addAction);
                                facet.getFacetsValueList().add(facetValue);
                            }
                        }
                        searchResponse.getFacetsList().add(facet);

                        // --------end to handle resultsList
                    }
                }
            }
        } catch (Exception e) {
            ApiErrorMessage errorMessage = new ApiErrorMessage();
            errorMessage.setErrorDescription("Error processing search response");
            errorMessage.setDetailedErrorDescription(e.getMessage());
            searchResponse.setApierrormessage(errorMessage);
        }
    }
    return searchResponse;

}

From source file:com.eds.Model.XMLProcessor.java

License:Apache License

public Info ProcessInfoResponse(ServiceResponse serviceResponse) {
    BufferedReader reader = serviceResponse.getReader();
    Info info = new Info();
    if (!serviceResponse.getErrorStream().equals("")) {
        ApiErrorMessage errorMessage = ProcessError(serviceResponse.getErrorNumber(),
                serviceResponse.getErrorStream());
        info.setErrorMessage(errorMessage);
    } else {/*from  w  w  w.j a v a2 s  . c  om*/
        String InfoXML = "";
        try {
            String line = "";
            while ((line = reader.readLine()) != null) {
                InfoXML += line;
            }
            StringReader stringReader = new StringReader(InfoXML);
            InputSource inputSource = new InputSource(stringReader);
            Document doc = (new SAXBuilder()).build(inputSource);
            Element infoResponseMessage = doc.getRootElement();

            Element availableSearchCriteria = infoResponseMessage.getChild("AvailableSearchCriteria",
                    infoResponseMessage.getNamespace());
            if (null != availableSearchCriteria) {
                // Process Sorts
                ArrayList<AvailableSort> sortsList = new ArrayList<AvailableSort>();
                Element availableSorts = availableSearchCriteria.getChild("AvailableSorts",
                        availableSearchCriteria.getNamespace());
                if (null != availableSorts) {
                    List<Element> availableSortsList = availableSorts.getChildren();
                    for (int i = 0; i < availableSortsList.size(); i++) {
                        Element eAvailableSort = (Element) availableSortsList.get(i);
                        if (null != eAvailableSort) {
                            AvailableSort as = new AvailableSort();
                            String Id = eAvailableSort.getChildText("Id", eAvailableSort.getNamespace());
                            String Label = eAvailableSort.getChildText("Label", eAvailableSort.getNamespace());
                            String AddAction = eAvailableSort.getChildText("AddAction",
                                    eAvailableSort.getNamespace());
                            as.setId(Id);
                            as.setLabel(Label);
                            as.setAddAction(AddAction);
                            sortsList.add(as);
                        }

                    }
                }
                info.setAvailableSortsList(sortsList);

                // Process available Search Field list
                ArrayList<AvailableSearchField> searchFieldsList = new ArrayList<AvailableSearchField>();
                Element availableSearchFields = availableSearchCriteria.getChild("AvailableSearchFields",
                        availableSearchCriteria.getNamespace());
                if (null != availableSearchFields) {
                    List<Element> availableSearchFieldsList = availableSearchFields.getChildren();
                    for (int i = 0; i < availableSearchFieldsList.size(); i++) {
                        Element eAvailableSearchField = (Element) availableSearchFieldsList.get(i);
                        AvailableSearchField asf = new AvailableSearchField();
                        String fieldCode = eAvailableSearchField.getContent(0).getValue();
                        String label = eAvailableSearchField.getContent(1).getValue();
                        asf.setFieldCode(fieldCode);
                        asf.setLabel(label);
                        searchFieldsList.add(asf);

                    }
                }
                info.setAvailableSearchFieldsList(searchFieldsList);

                // process available expanders
                ArrayList<AvailableExpander> expandersList = new ArrayList<AvailableExpander>();
                Element availableExpanders = availableSearchCriteria.getChild("AvailableExpanders",
                        availableSearchCriteria.getNamespace());
                if (null != availableExpanders) {
                    List<Element> availableExpandersList = availableExpanders.getChildren();
                    for (int i = 0; i < availableExpandersList.size(); i++) {

                        Element eAvailableExpander = (Element) availableExpandersList.get(i);
                        AvailableExpander ae = new AvailableExpander();
                        String id = eAvailableExpander.getChildText("Id", eAvailableExpander.getNamespace());
                        String label = eAvailableExpander.getChildText("Label",
                                eAvailableExpander.getNamespace());
                        String addAction = eAvailableExpander.getChildText("AddAction",
                                eAvailableExpander.getNamespace());
                        ae.setId(id);
                        ae.setLabel(label);
                        ae.setAddAction(addAction);
                        expandersList.add(ae);
                    }
                }
                info.setAvailableExpandersList(expandersList);

                // process available limiters
                ArrayList<AvailableLimiter> limitersList = new ArrayList<AvailableLimiter>();
                Element availableLimiters = availableSearchCriteria.getChild("AvailableLimiters",
                        availableSearchCriteria.getNamespace());
                if (null != availableLimiters) {
                    List<Element> availableLimitersList = availableLimiters.getChildren();
                    for (int i = 0; i < availableLimitersList.size(); i++) {
                        Element eAvailableLimiter = (Element) availableLimitersList.get(i);
                        AvailableLimiter al = new AvailableLimiter();
                        String id = eAvailableLimiter.getChildText("Id", eAvailableLimiter.getNamespace());
                        String label = eAvailableLimiter.getChildText("Label",
                                eAvailableLimiter.getNamespace());
                        String type = eAvailableLimiter.getChildText("Type", eAvailableLimiter.getNamespace());
                        String addAction = eAvailableLimiter.getChildText("AddAction",
                                eAvailableLimiter.getNamespace());
                        String defaultOn = eAvailableLimiter.getChildText("DefaultOn",
                                eAvailableLimiter.getNamespace());
                        String order = eAvailableLimiter.getChildText("Order",
                                eAvailableLimiter.getNamespace());
                        al.setId(id);
                        al.setLabel(label);
                        al.setType(type);
                        al.setAddAction(addAction);
                        al.setDefaultOn(defaultOn);
                        al.setOrder(order);

                        if (type.equals("multiselectvalue")) {
                            Element eLimiterValues = eAvailableLimiter.getChild("LimiterValues",
                                    eAvailableLimiter.getNamespace());
                            if (null != eLimiterValues) {
                                List<Element> limiterValues = eLimiterValues.getChildren();
                                ArrayList<LimiterValue> limiterValueList = new ArrayList<LimiterValue>();
                                for (int j = 0; j < limiterValues.size(); j++) {
                                    Element eLimiterValue = (Element) limiterValues.get(j);
                                    LimiterValue lv = new LimiterValue();

                                    String valueValue = eLimiterValue.getChildText("Id",
                                            eLimiterValue.getNamespace());
                                    String valueAddAction = eLimiterValue.getChildText("AddAction",
                                            eLimiterValue.getNamespace());
                                    // This sample application is only going
                                    // one
                                    // level deep
                                    lv.setValue(valueValue);
                                    lv.setAddAction(valueAddAction);
                                    limiterValueList.add(lv);
                                }
                                al.setLimitervalues(limiterValueList);
                            }
                        }
                        limitersList.add(al);
                    }
                    info.setAvailableLimitersList(limitersList);
                }

                // set available Search Modes
                ArrayList<AvailableSearchMode> searchModeList = new ArrayList<AvailableSearchMode>();
                Element availableSearchModes = availableSearchCriteria.getChild("AvailableSearchModes",
                        availableSearchCriteria.getNamespace());
                if (null != availableSearchModes) {
                    List<Element> availableSearchModeList = availableSearchModes.getChildren();
                    for (int i = 0; i < availableSearchModeList.size(); i++) {
                        Element eAvailableSearchMode = (Element) availableSearchModeList.get(i);
                        AvailableSearchMode asm = new AvailableSearchMode();
                        String mode = eAvailableSearchMode.getChildText("Mode",
                                eAvailableSearchMode.getNamespace());
                        String label = eAvailableSearchMode.getChildText("Label",
                                eAvailableSearchMode.getNamespace());
                        String addAction = eAvailableSearchMode.getChildText("AddAction",
                                eAvailableSearchMode.getNamespace());
                        String defaultOn = eAvailableSearchMode.getChildText("DefaultOn",
                                eAvailableSearchMode.getNamespace());
                        asm.setMode(mode);
                        asm.setLabel(label);
                        asm.setAddAction(addAction);
                        asm.setDefaultOn(defaultOn);
                        searchModeList.add(asm);
                    }
                }
                info.setAvailableSearchModeList(searchModeList);
            }

            // Set ViewResult settings
            Element viewResultSettings = infoResponseMessage.getChild("ViewResultSettings",
                    infoResponseMessage.getNamespace());
            if (null != viewResultSettings) {
                ViewResultSettings vrs = new ViewResultSettings();
                String resultsPerPage = viewResultSettings.getChildText("ResultsPerPage",
                        viewResultSettings.getNamespace());
                int rpp = 20;
                if (null != resultsPerPage) {
                    try {
                        rpp = Integer.parseInt(resultsPerPage);
                    } catch (NumberFormatException e) {
                    }
                }
                vrs.setResultsPerPage(rpp);
                vrs.setResultListView(
                        viewResultSettings.getChildText("ResultListView", viewResultSettings.getNamespace()));
                info.setViewResultSettings(vrs);
            }
        } catch (Exception e) {
            ApiErrorMessage errorMessage = new ApiErrorMessage();
            errorMessage.setErrorDescription("Error processing info response");
            errorMessage.setDetailedErrorDescription(e.getMessage());
            info.setErrorMessage(errorMessage);
        }
    }
    return info;
}

From source file:com.eds.Model.XMLProcessor.java

License:Apache License

public ApiErrorMessage ProcessError(String errorNumber, String errorStream) {
    ByteArrayInputStream errorInputStream = new ByteArrayInputStream(errorStream.getBytes());
    InputStreamReader in = new InputStreamReader(errorInputStream);
    BufferedReader errorreader = new BufferedReader(in);
    ApiErrorMessage apiErrorMessage = new ApiErrorMessage();
    try {/*  ww w .  j a  va 2 s. c om*/
        if (errorNumber.equals(HTTP_BAD_REQUEST)) {
            String line = "";
            String resultListErrorStream = "";

            try {
                while ((line = errorreader.readLine()) != null) {
                    resultListErrorStream += line;
                }
            } catch (IOException e) {
                apiErrorMessage.setErrorDescription("Error occurred");
                apiErrorMessage.setDetailedErrorDescription(e.getMessage());
                return apiErrorMessage;
            }
            StringReader stringReader = new StringReader(resultListErrorStream);
            InputSource inputSource = new InputSource(stringReader);
            Document doc = (new SAXBuilder()).build(inputSource);

            if (doc.getRootElement().getName() == "APIErrorMessage") {
                Element root = doc.getRootElement();
                String detailedErrorDescription = root.getChildText("DetailedErrorDescription",
                        root.getNamespace());
                String errorDescription = root.getChildText("ErrorDescription", root.getNamespace());
                String errorNum = root.getChildText("ErrorNumber", root.getNamespace());

                apiErrorMessage.setDetailedErrorDescription(detailedErrorDescription);
                apiErrorMessage.setErrorDescription(errorDescription);
                apiErrorMessage.setErrorNumber(errorNum);

            } else {
                apiErrorMessage.setDetailedErrorDescription(errorStream);
                apiErrorMessage.setErrorDescription(errorStream);
                apiErrorMessage.setErrorNumber(errorNumber);
            }
        }
    } catch (Exception e) {
        apiErrorMessage.setErrorDescription("Error occurred");
        apiErrorMessage.setDetailedErrorDescription(e.getMessage());
    }
    return apiErrorMessage;
}

From source file:com.eds.Model.XMLProcessor.java

License:Apache License

public ApiErrorMessage ProcessAuthError(String errorNumber, String errorStream) {
    ByteArrayInputStream errorInputStream = new ByteArrayInputStream(errorStream.getBytes());
    InputStreamReader in = new InputStreamReader(errorInputStream);
    BufferedReader errorreader = new BufferedReader(in);
    ApiErrorMessage apiErrorMessage = new ApiErrorMessage();
    try {/*  ww w . j  av  a2s.co m*/
        if (errorNumber.equals(HTTP_BAD_REQUEST)) {
            String line = "";
            String resultListErrorStream = "";

            try {
                while ((line = errorreader.readLine()) != null) {
                    resultListErrorStream += line;
                }
            } catch (IOException e) {
                apiErrorMessage.setErrorDescription("Error occurred");
                apiErrorMessage.setDetailedErrorDescription(e.getMessage());
                return apiErrorMessage;
            }

            StringReader stringReader = new StringReader(resultListErrorStream);
            InputSource inputSource = new InputSource(stringReader);
            Document doc = (new SAXBuilder()).build(inputSource);

            if (doc.getRootElement().getName() == "ErrorResponseMessage") {
                Element root = doc.getRootElement();
                String detailedErrorDescription = root.getChildText("AdditionalDetail", root.getNamespace());
                String errorDescription = root.getChildText("Reason", root.getNamespace());
                String errorNum = root.getChildText("ErrorCode", root.getNamespace());

                apiErrorMessage.setDetailedErrorDescription(detailedErrorDescription);
                apiErrorMessage.setErrorDescription(errorDescription);
                apiErrorMessage.setErrorNumber(errorNum);

            } else {
                apiErrorMessage.setDetailedErrorDescription(errorStream);
                apiErrorMessage.setErrorDescription(errorStream);
                apiErrorMessage.setErrorNumber(errorNumber);
            }
        }

    } catch (Exception e) {
        apiErrorMessage.setErrorDescription("Error occurred");
        apiErrorMessage.setDetailedErrorDescription(e.getMessage());
    }
    return apiErrorMessage;
}