public void write(final Writer out) throws IOException { try { if (isBackEndStream) { boolean isSubassetsQuery = type == Type.COLLECTION_CONTENT || type == Type.GROUP_COLLECTIONS; final StringTokenizer childRights = isSubassetsQuery ? new StringTokenizer(childRightsS, ",") : null, childPages = isSubassetsQuery ? new StringTokenizer(childPagesS, ",") : null; currikiPlugin.startSolrMethod(get); if (isSubassetsQuery) { out.write("["); CurrikiPlugin.SolrResultCollector collector = new CurrikiPlugin.SolrResultCollector() { boolean started = false; public void status(int statusCode, int qTime, int numFound, int start) {} public void newDocument() {} public void addValue(String name, String value) { if (!value.startsWith("{")) value = value.trim(); if (!value.startsWith("{")) throw new IllegalStateException( "Child metadata value \"" + value + "\" incompatible!"); String right = childRights != null ? childRights.nextToken() : null; String assetpage = childPages.nextToken(); try { if (!started) started = true; else out.write(", "); // \n if (childRights != null && canUserRead(right)) { System.err.println( "Rights: view: " + canUserRead(right) + ", edit:" + canUserModify(right) + ", delete:" + canUserDelete(assetpage) + "."); // TODO: convert the label "rights" to "ownership" if (canUserModify(right)) out.write("{rights:{'view':true, 'edit':true, 'delete': "); else out.write("{rights:{'view':true, 'edit':false, 'delete': "); if (canUserDelete(assetpage)) out.write("true},"); else out.write("false},"); out.write(value.substring(1)); } else { // no read allowance out.write( "{rights:{'view':false, 'edit':false, 'delete': false}, assetpage: \"" + assetpage + "\","); out.write(ghostSubAssetInfoJson); } } catch (Exception e) { throw new IllegalStateException(e); } } }; currikiPlugin.feedFieldFromXmlStream(get, collector, solrField); out.write("]"); } else { // Type.USER_COLLECTIONS, Type.USER_GROUPS: always requested from own user // currently, can be static currikiPlugin.feedFieldFromXmlStream(get, out, solrField); } } else { if (objectToOutput instanceof Map) { new Gson() .toJson( subAssetNames == null ? flattenMapToJSONArray( (Map<String, Object>) objectToOutput, propNameForFullname) : flattenMapToJSONArray( (Map<String, Object>) objectToOutput, subAssetNames, propNameForFullname), out); } else { new Gson().toJson(objectToOutput, out); } } } catch (Exception e) { e.printStackTrace(); throw new IllegalStateException(e); } }