/** Adds XML to the responses in a QueryReply. */ public static boolean addXMLToResponses( QueryReply qr, LimeXMLDocumentHelper limeXMLDocumentHelper) { // get xml collection string, then get dis-aggregated docs, then // in loop // you can match up metadata to responses String xmlCollectionString = ""; try { LOG.trace("Trying to do uncompress XML....."); byte[] xmlCompressed = qr.getXMLBytes(); if (xmlCompressed.length > 1) { byte[] xmlUncompressed = LimeXMLUtils.uncompress(xmlCompressed); xmlCollectionString = new String(xmlUncompressed, "UTF-8"); } } catch (UnsupportedEncodingException use) { // b/c this should never happen, we will show and error // if it ever does for some reason. // we won't throw a BadPacketException here but we will show it. // the uee will effect the xml part of the reply but we could // still show the reply so there shouldn't be any ill effect if // xmlCollectionString is "" ErrorService.error(use); } catch (IOException ignored) { } // valid response, no XML in EQHD. if (xmlCollectionString.equals("")) return true; Response[] responses; int responsesLength; try { responses = qr.getResultsArray(); responsesLength = responses.length; } catch (BadPacketException bpe) { LOG.trace("Unable to get responses", bpe); return false; } if (LOG.isDebugEnabled()) LOG.debug("xmlCollectionString = " + xmlCollectionString); List<LimeXMLDocument[]> allDocsArray = limeXMLDocumentHelper.getDocuments(xmlCollectionString, responsesLength); for (int i = 0; i < responsesLength; i++) { Response response = responses[i]; LimeXMLDocument[] metaDocs; for (int schema = 0; schema < allDocsArray.size(); schema++) { metaDocs = allDocsArray.get(schema); // If there are no documents in this schema, try another. if (metaDocs == null) continue; // If this schema had a document for this response, use it. if (metaDocs[i] != null) { response.setDocument(metaDocs[i]); break; // we only need one, so break out. } } } return true; }