List of usage examples for org.jdom2 Document getRootElement
public Element getRootElement()
Element
for this Document
From source file:com.dsatab.DsaTabApplication.java
License:Open Source License
public void saveHero() { if (hero == null) { Toast.makeText(getApplicationContext(), "Held kann nicht gespeichert werden, da noch kein Held geladen wurde.", Toast.LENGTH_SHORT) .show();// w w w .j a va 2 s .c o m return; } FileOutputStream out = null; File destFile = new File(hero.getPath()); try { String error = Util.checkFileWriteAccess(destFile); if (error != null) { Toast.makeText(this, error, Toast.LENGTH_LONG).show(); return; } FileInputStream fis = new FileInputStream(destFile); Document dom = HeldenXmlParser.readDocument(fis); fis.close(); Element heroElement = (Element) dom.getRootElement().getChild(Xml.KEY_HELD); HeldenXmlParser.onPreHeroSaved(hero, heroElement); out = new FileOutputStream(destFile); HeldenXmlParser.writeHero(hero, dom, out); hero.onPostHeroSaved(); saveHeroConfiguration(); Toast.makeText(this, getString(R.string.hero_saved, hero.getName()), Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(this, "Held konnte nicht gespeichert werden.", Toast.LENGTH_LONG).show(); Debug.error(e); BugSenseHandler.sendException(e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { Debug.error(e); } } } }
From source file:com.eds.Model.XMLProcessor.java
License:Apache License
public AuthToken ProcessUIDAuthResponse(ServiceResponse response) { BufferedReader reader = response.getReader(); String authTokenXML = ""; AuthToken authToken = new AuthToken(); if (null != response.getErrorStream() && !response.getErrorStream().isEmpty()) { authToken.setErrorMessage(ProcessAuthError(response.getErrorNumber(), response.getErrorStream())); return authToken; }/*ww w . j a v a 2 s. co m*/ if (null != reader) { try { String line = ""; while ((line = reader.readLine()) != null) { authTokenXML += line; } StringReader stringReader = new StringReader(authTokenXML); InputSource inputSource = new InputSource(stringReader); Document doc = (new SAXBuilder()).build(inputSource); Element root = doc.getRootElement(); Content content = root.getContent().get(0); Content timeout = root.getContent().get(1); if (content.getValue() != null) { authToken.setAuthToken(content.getValue()); authToken.setAuthTimeout(timeout.getValue()); } } catch (Exception e) { ApiErrorMessage errorMessage = new ApiErrorMessage(); errorMessage.setErrorDescription("Error processing UID auth response"); errorMessage.setDetailedErrorDescription(e.getMessage()); authToken.setErrorMessage(errorMessage); } } return authToken; }
From source file:com.eds.Model.XMLProcessor.java
License:Apache License
public SessionToken ProcessCreateSessionResponse(ServiceResponse response) { BufferedReader reader = response.getReader(); String line = ""; String sessionTokenXML = ""; // Check for errors SessionToken sessionToken = new SessionToken(); if (null != response.getErrorStream() && !response.getErrorStream().isEmpty()) { sessionToken.setApiErrorMessage(ProcessError(response.getErrorNumber(), response.getErrorStream())); } else {/* w w w.ja v a2 s . c o m*/ if (null != reader) { try { while ((line = reader.readLine()) != null) { sessionTokenXML += line; } } catch (IOException e) { ApiErrorMessage errorMessage = new ApiErrorMessage(); errorMessage.setErrorDescription("Error processing create session response"); errorMessage.setDetailedErrorDescription(e.getMessage()); sessionToken.setApiErrorMessage(errorMessage); } } /* * Parse String to XML and the get the value */ try { StringReader stringReader = new StringReader(sessionTokenXML); InputSource inputSource = new InputSource(stringReader); Document doc = (new SAXBuilder()).build(inputSource); Element root = doc.getRootElement(); Content content = root.getContent().get(0); if (content.getValue() != null) { sessionToken.setSessionToken(content.getValue()); } } catch (Exception e) { ApiErrorMessage errorMessage = new ApiErrorMessage(); errorMessage.setErrorDescription("Error processing search response"); errorMessage.setDetailedErrorDescription(e.getMessage()); sessionToken.setApiErrorMessage(errorMessage); } } return sessionToken; }
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 {/*from w w w .j a v a 2s. 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 RetrieveResponse ProcessRetrieveResponse(ServiceResponse serviceResponse) { RetrieveResponse retrieveResponse = new RetrieveResponse(); BufferedReader reader = serviceResponse.getReader(); if (!serviceResponse.getErrorStream().equals("")) { ApiErrorMessage errorMessage = ProcessError(serviceResponse.getErrorNumber(), serviceResponse.getErrorStream()); retrieveResponse.setApiErrorMessage(errorMessage); } else {//w ww. j a va2 s. c o m String RecordXML = ""; try { String line = ""; while ((line = reader.readLine()) != null) { RecordXML += line; } } catch (IOException e1) { ApiErrorMessage errorMessage = new ApiErrorMessage(); errorMessage.setErrorDescription("Error processing retrieve response"); errorMessage.setDetailedErrorDescription(e1.getMessage()); retrieveResponse.setApiErrorMessage(errorMessage); return retrieveResponse; } try { StringReader stringReader = new StringReader(RecordXML); InputSource inputSource = new InputSource(stringReader); Document doc = (new SAXBuilder()).build(inputSource); // root element (level 1) Element retrieveResponseMessage = doc.getRootElement(); // level 2 elements Element xmlRecord = retrieveResponseMessage.getChild("Record", retrieveResponseMessage.getNamespace()); Result result = this.constructRecord(xmlRecord, true); retrieveResponse.setRecord(result); } catch (Exception e) { ApiErrorMessage errorMessage = new ApiErrorMessage(); errorMessage.setErrorDescription("Error processing retrieve response"); errorMessage.setDetailedErrorDescription(e.getMessage()); retrieveResponse.setApiErrorMessage(errorMessage); } } return retrieveResponse; }
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 {/* w w w . ja v a 2 s . com*/ 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 String ProcessEndSessionResponse(ServiceResponse serviceResponse) { BufferedReader reader = serviceResponse.getReader(); String EndSessionXML = ""; String IsSuccessful = "0"; try {// w w w. ja v a 2s .com String line = ""; while ((line = reader.readLine()) != null) { EndSessionXML += line; } StringReader stringReader = new StringReader(EndSessionXML); InputSource inputSource = new InputSource(stringReader); Document doc = (new SAXBuilder()).build(inputSource); Element EndSessionResponse = doc.getRootElement(); IsSuccessful = EndSessionResponse.getContent(0).getValue(); } catch (Exception e) { } return IsSuccessful; }
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 {//from ww w. j a v a 2 s. c o 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() == "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 . jav a 2 s . c o 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; }
From source file:com.eds.Response.XMLProcessor.java
License:Apache License
/** * Constructs a session token object from an EDS API Response *//*from w w w .j av a 2 s . co m*/ public SessionToken buildSessionToken(Response response) { BufferedReader reader = response.getRead(); String sessionTokenXML = ""; // Check for errors SessionToken sessionToken = new SessionToken(); if (null != response.getErrorStream() && !response.getErrorStream().isEmpty()) { sessionToken.setApiErrorMessage(ProcessError(response.getErrorNumber(), response.getErrorStream())); } else { if (null != reader) { try { String line = ""; while ((line = reader.readLine()) != null) { sessionTokenXML += line; } } catch (IOException e) { ApiErrorMessage errorMessage = new ApiErrorMessage(); errorMessage.setErrorDescription("Error processing create session response"); errorMessage.setDetailedErrorDescription(e.getMessage()); sessionToken.setApiErrorMessage(errorMessage); } } /* * Parse String to XML and the get the value */ try { StringReader stringReader = new StringReader(sessionTokenXML); InputSource inputSource = new InputSource(stringReader); Document doc = (new SAXBuilder()).build(inputSource); Element root = doc.getRootElement(); Content content = root.getContent().get(0); if (content.getValue() != null) { sessionToken.setSessionToken(content.getValue()); } } catch (Exception e) { ApiErrorMessage errorMessage = new ApiErrorMessage(); errorMessage.setErrorDescription("Error processing search response"); errorMessage.setDetailedErrorDescription(e.getMessage()); sessionToken.setApiErrorMessage(errorMessage); } } return sessionToken; }