List of usage examples for com.google.gson.stream JsonReader beginObject
public void beginObject() throws IOException
From source file:com.nridge.core.io.gson.RelationshipJSON.java
License:Open Source License
/** * Parses an JSON stream and loads it into a relationship and returns * an instance to it./*from w w w.ja v a2 s. c o m*/ * * @param aReader Json reader stream instance. * * @throws java.io.IOException I/O related exception. */ public Relationship loadRelationship(JsonReader aReader) throws IOException { String jsonName, jsonValue; Relationship relationship = new Relationship(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, IO.JSON_TYPE_MEMBER_NAME)) relationship.setType(aReader.nextString()); else if (StringUtils.equals(jsonName, IO.JSON_FEATURES_ARRAY_NAME)) { aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = aReader.nextString(); relationship.addFeature(jsonName, jsonValue); } aReader.endObject(); } else if (StringUtils.equals(jsonName, IO.JSON_DOCUMENTS_ARRAY_NAME)) loadDocuments(aReader, relationship); else aReader.skipValue(); } aReader.endObject(); return relationship; }
From source file:com.nridge.ds.solr.SolrCollection.java
License:Open Source License
private ArrayList<String> load(InputStream anIS) throws IOException { String jsonName, jsonValue;//from w ww . j a va 2 s. co m ArrayList<String> configSetList = new ArrayList<>(); String configSetString = IOUtils.toString(anIS, StrUtl.CHARSET_UTF_8); StringReader stringReader = new StringReader(configSetString); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, "collections")) { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonValue = jsonReader.nextString(); configSetList.add(jsonValue); } jsonReader.endArray(); } } jsonReader.endObject(); return configSetList; }
From source file:com.nridge.ds.solr.SolrCollection.java
License:Open Source License
private void parseReply(String aMessage) throws DSException, IOException { String jsonName;//from ww w. jav a 2s .co m Logger appLogger = mAppMgr.getLogger(this, "parseReply"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); int msgCode = 0; String msgString = StringUtils.EMPTY; StringReader stringReader = new StringReader(aMessage); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, "exception")) { jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, "msg")) msgString = jsonReader.nextString(); else if (StringUtils.equals(jsonName, "rspCode")) msgCode = jsonReader.nextInt(); else jsonReader.skipValue(); } jsonReader.endObject(); } else jsonReader.skipValue(); } jsonReader.endObject(); if (StringUtils.isNotEmpty(msgString)) throw new DSException(String.format("Solr Exception [%d]: %s", msgCode, msgString)); appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:com.nridge.ds.solr.SolrConfigJSON.java
License:Open Source License
private void populateCfgUpdateHandler(JsonReader aReader, Document aCfgDocument, String aDocType) throws IOException { DataBag dataBag;/*from w w w . j av a 2s . com*/ String jsonName, jsonValue; Document iwDocument, cwDocument, acDocument, ascDocument; Document uhDocument = new Document(aDocType); DataBag uhBag = uhDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_UH_IW)) { iwDocument = new Document(Solr.RESPONSE_CONFIG_UH_INDEX_WRITER); iwDocument.setName(jsonName); dataBag = iwDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); addBagTextField(dataBag, jsonName, jsonValue); } aReader.endObject(); uhDocument.addRelationship(Solr.RESPONSE_CONFIG_UH_INDEX_WRITER, iwDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_UH_CW)) { cwDocument = new Document(Solr.RESPONSE_CONFIG_UH_COMMIT_WITHIN); cwDocument.setName(jsonName); dataBag = cwDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); addBagTextField(dataBag, jsonName, jsonValue); } aReader.endObject(); uhDocument.addRelationship(Solr.RESPONSE_CONFIG_UH_COMMIT_WITHIN, cwDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_UH_AC)) { acDocument = new Document(Solr.RESPONSE_CONFIG_UH_AUTO_COMMIT); acDocument.setName(jsonName); dataBag = acDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); addBagTextField(dataBag, jsonName, jsonValue); } aReader.endObject(); uhDocument.addRelationship(Solr.RESPONSE_CONFIG_UH_AUTO_COMMIT, acDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_UH_ASC)) { ascDocument = new Document(Solr.RESPONSE_CONFIG_UH_AUTO_SOFT_COMMIT); ascDocument.setName(jsonName); dataBag = ascDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); addBagTextField(dataBag, jsonName, jsonValue); } aReader.endObject(); uhDocument.addRelationship(Solr.RESPONSE_CONFIG_UH_AUTO_SOFT_COMMIT, ascDocument); } else { jsonValue = nextValueAsString(aReader); addBagTextField(uhBag, jsonName, jsonValue); } } aReader.endObject(); aCfgDocument.addRelationship(Solr.RESPONSE_CONFIG_UPDATE_HANDLER, uhDocument); }
From source file:com.nridge.ds.solr.SolrConfigJSON.java
License:Open Source License
private void populateCfgQuery(JsonReader aReader, Document aCfgDocument, String aDocType) throws IOException { DataBag dataBag;//from ww w . j a va 2 s . c o m String jsonName, jsonValue; Document fcDocument, rcDocument, dcDocument, fvcDocument; Document queryDocument = new Document(aDocType); DataBag queryBag = queryDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_QUERY_FC)) { fcDocument = new Document(Solr.RESPONSE_CONFIG_QUERY_FC); fcDocument.setName(jsonName); dataBag = fcDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); addBagTextField(dataBag, jsonName, jsonValue); } aReader.endObject(); queryDocument.addRelationship(Solr.RESPONSE_CONFIG_QUERY_FC, fcDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_QUERY_RC)) { rcDocument = new Document(Solr.RESPONSE_CONFIG_QUERY_RC); rcDocument.setName(jsonName); dataBag = rcDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); addBagTextField(dataBag, jsonName, jsonValue); } aReader.endObject(); queryDocument.addRelationship(Solr.RESPONSE_CONFIG_QUERY_RC, rcDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_QUERY_DC)) { dcDocument = new Document(Solr.RESPONSE_CONFIG_QUERY_DC); dcDocument.setName(jsonName); dataBag = dcDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); addBagTextField(dataBag, jsonName, jsonValue); } aReader.endObject(); queryDocument.addRelationship(Solr.RESPONSE_CONFIG_QUERY_DC, dcDocument); } else if ((StringUtils.isEmpty(jsonName)) || // This handles a Solr 7.5 JSON output bug (empty string) (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_QUERY_FVC))) { fvcDocument = new Document(Solr.RESPONSE_CONFIG_QUERY_FVC); fvcDocument.setName(jsonName); dataBag = fvcDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); addBagTextField(dataBag, jsonName, jsonValue); } aReader.endObject(); queryDocument.addRelationship(Solr.RESPONSE_CONFIG_QUERY_FVC, fvcDocument); } else { jsonValue = nextValueAsString(aReader); addBagTextField(queryBag, jsonName, jsonValue); } } aReader.endObject(); aCfgDocument.addRelationship(Solr.RESPONSE_CONFIG_QUERY, queryDocument); }
From source file:com.nridge.ds.solr.SolrConfigJSON.java
License:Open Source License
private void addFieldToDocument(JsonReader aReader, Document aDocument, String aName) throws IOException { DataBag childBag;//from w w w. ja va 2 s . c o m JsonToken jsonToken; boolean isArrayArray; Document childDocument; String jsonName, jsonValue; DataTextField dataTextField; DataBag dataBag = aDocument.getBag(); if (isNextTokenAnArray(aReader)) { aReader.beginArray(); dataTextField = new DataTextField(aName, Field.nameToTitle(aName)); dataTextField.addFeature(Field.FEATURE_IS_STORED, StrUtl.STRING_TRUE); jsonToken = aReader.peek(); if (jsonToken == JsonToken.BEGIN_ARRAY) { isArrayArray = true; aReader.beginArray(); jsonToken = aReader.peek(); } else isArrayArray = false; while (jsonToken != JsonToken.END_ARRAY) { jsonValue = nextValueAsString(aReader); dataTextField.addValue(jsonValue); jsonToken = aReader.peek(); } aReader.endArray(); if (isArrayArray) aReader.endArray(); dataBag.add(dataTextField); } else if (isNextTokenAnObject(aReader)) { childDocument = new Document(aName); childDocument.setName(aName); childBag = childDocument.getBag(); aReader.beginObject(); jsonToken = aReader.peek(); while (jsonToken != JsonToken.END_OBJECT) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); addBagTextField(childBag, jsonName, jsonValue); jsonToken = aReader.peek(); } aReader.endObject(); aDocument.addRelationship(aName, childDocument); } else { jsonValue = nextValueAsString(aReader); addBagTextField(dataBag, aName, jsonValue); } }
From source file:com.nridge.ds.solr.SolrConfigJSON.java
License:Open Source License
private void populateCfgRequestHandler(JsonReader aReader, Document aCfgDocument, String aDocType) throws IOException { DataBag rhBag, snBag;//w ww .j ava2 s. c o m String jsonName, jsonValue; Document snDocument, defDocument, coDocument, lcDocument, inDocument, upDocument; Document rhDocument = new Document(aDocType); rhBag = rhDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.startsWith(jsonName, "/")) { snDocument = new Document(Solr.RESPONSE_CONFIG_RH_SN); snDocument.setName(jsonName); snBag = snDocument.getBag(); DataTextField operationField = new DataTextField(Solr.CONFIG_OPERATION_FIELD_NAME, Field.nameToTitle(Solr.CONFIG_OPERATION_FIELD_NAME)); operationField.addFeature(Field.FEATURE_IS_STORED, StrUtl.STRING_FALSE); snBag.add(operationField); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_SN_DEFAULTS)) { defDocument = new Document(Solr.RESPONSE_CONFIG_RH_SN_DEFAULTS); defDocument.setName(jsonName); aReader.beginObject(); while (aReader.hasNext()) addFieldToDocument(aReader, defDocument); aReader.endObject(); snDocument.addRelationship(Solr.RESPONSE_CONFIG_RH_SN_DEFAULTS, defDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_SN_CO)) { coDocument = new Document(Solr.RESPONSE_CONFIG_RH_SN_COMPONENTS); coDocument.setName(jsonName); addFieldToDocument(aReader, coDocument, jsonName); snDocument.addRelationship(Solr.RESPONSE_CONFIG_RH_SN_COMPONENTS, coDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_SN_LC)) { lcDocument = new Document(Solr.RESPONSE_CONFIG_RH_SN_LAST_COMPONENTS); lcDocument.setName(jsonName); addFieldToDocument(aReader, lcDocument, jsonName); snDocument.addRelationship(Solr.RESPONSE_CONFIG_RH_SN_LAST_COMPONENTS, lcDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_SN_IN)) { inDocument = new Document(Solr.RESPONSE_CONFIG_RH_SN_INVARIANTS); inDocument.setName(jsonName); aReader.beginObject(); while (aReader.hasNext()) addFieldToDocument(aReader, inDocument); aReader.endObject(); snDocument.addRelationship(Solr.RESPONSE_CONFIG_RH_SN_INVARIANTS, inDocument); } else { jsonValue = nextValueAsString(aReader); addBagTextField(snBag, jsonName, jsonValue); snBag.add(new DataTextField(jsonName, Field.nameToTitle(jsonName), jsonValue)); } } aReader.endObject(); rhDocument.addRelationship(Solr.RESPONSE_CONFIG_RH_SN, snDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_SN_UPDATE)) { upDocument = new Document(Solr.RESPONSE_CONFIG_RH_SN_UPDATE); upDocument.setName(jsonName); aReader.beginObject(); while (aReader.hasNext()) addFieldToDocument(aReader, upDocument); aReader.endObject(); rhDocument.addRelationship(Solr.RESPONSE_CONFIG_RH_SN_UPDATE, upDocument); } else { jsonValue = nextValueAsString(aReader); addBagTextField(rhBag, jsonName, jsonValue); } } aReader.endObject(); aCfgDocument.addRelationship(Solr.RESPONSE_CONFIG_REQUEST_HANDLER, rhDocument); }
From source file:com.nridge.ds.solr.SolrConfigJSON.java
License:Open Source License
private void populateQueryResponseWriterHandler(JsonReader aReader, Document aCfgDocument, String aDocType) throws IOException { DataBag dataBag;// ww w. j a va 2s.c om Document rwDocument; String jsonName, jsonValue; Document qrwDocument = new Document(aDocType); DataBag qewBag = qrwDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (isNextTokenAnObject(aReader)) { rwDocument = new Document(Solr.RESPONSE_CONFIG_QRW_RESPONSE_WRITER); rwDocument.setName(jsonName); dataBag = rwDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); addBagTextField(dataBag, jsonName, jsonValue); } aReader.endObject(); qrwDocument.addRelationship(Solr.RESPONSE_CONFIG_QRW_RESPONSE_WRITER, rwDocument); } else { jsonValue = nextValueAsString(aReader); addBagTextField(qewBag, jsonName, jsonValue); } } aReader.endObject(); aCfgDocument.addRelationship(Solr.RESPONSE_CONFIG_QUERY_RESPONSE_WRITER, qrwDocument); }
From source file:com.nridge.ds.solr.SolrConfigJSON.java
License:Open Source License
private void addObjectToDocument(JsonReader aReader, Document aParentDocument, String aType, String aName) throws IOException { String jsonValue;/*from w w w. jav a2s . com*/ JsonToken jsonToken; boolean isArrayArray; Document childDocument; DataBag dataBag = aParentDocument.getBag(); if (isNextTokenAnArray(aReader)) { aReader.beginArray(); jsonToken = aReader.peek(); if (jsonToken == JsonToken.BEGIN_ARRAY) { isArrayArray = true; aReader.beginArray(); jsonToken = aReader.peek(); } else isArrayArray = false; while (jsonToken != JsonToken.END_ARRAY) { childDocument = new Document(aType); childDocument.setName(aName); aReader.beginObject(); while (aReader.hasNext()) addFieldToDocument(aReader, childDocument); aReader.endObject(); aParentDocument.addRelationship(aType, childDocument); jsonToken = aReader.peek(); } aReader.endArray(); if (isArrayArray) aReader.endArray(); } else if (isNextTokenAnObject(aReader)) { childDocument = new Document(aType); childDocument.setName(aName); aReader.beginObject(); while (aReader.hasNext()) addFieldToDocument(aReader, childDocument); aReader.endObject(); aParentDocument.addRelationship(aType, childDocument); } else { jsonValue = nextValueAsString(aReader); addBagTextField(dataBag, aName, jsonValue); } }
From source file:com.nridge.ds.solr.SolrConfigJSON.java
License:Open Source License
private void populateSearchComponent(JsonReader aReader, Document aCfgDocument, String aDocType) throws IOException { DataBag scBag;//from w ww.jav a2s . c om Document scDocument; JsonToken jsonToken; boolean isArrayArray; Document childDocument; String jsonName, jsonValue; Document searchComponentDocument = new Document(aDocType); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); scDocument = new Document(Solr.RESPONSE_CONFIG_SEARCH_COMPONENT); scDocument.setName(jsonName); scBag = scDocument.getBag(); DataTextField operationField = new DataTextField(Solr.CONFIG_OPERATION_FIELD_NAME, Field.nameToTitle(Solr.CONFIG_OPERATION_FIELD_NAME)); operationField.addFeature(Field.FEATURE_IS_STORED, StrUtl.STRING_FALSE); scBag.add(operationField); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (isNextTokenAnArray(aReader)) { aReader.beginArray(); jsonToken = aReader.peek(); if (jsonToken == JsonToken.BEGIN_ARRAY) { isArrayArray = true; aReader.beginArray(); jsonToken = aReader.peek(); } else isArrayArray = false; while (jsonToken != JsonToken.END_ARRAY) { childDocument = new Document(Field.nameToTitle(jsonName)); childDocument.setName(jsonName); aReader.beginObject(); while (aReader.hasNext()) addFieldToDocument(aReader, childDocument); aReader.endObject(); scDocument.addRelationship(Field.nameToTitle(jsonName), childDocument); jsonToken = aReader.peek(); } aReader.endArray(); if (isArrayArray) aReader.endArray(); } else if (isNextTokenAnObject(aReader)) { childDocument = new Document(Field.nameToTitle(jsonName)); childDocument.setName(jsonName); aReader.beginObject(); while (aReader.hasNext()) addFieldToDocument(aReader, childDocument); aReader.endObject(); scDocument.addRelationship(Field.nameToTitle(jsonName), childDocument); } else { jsonValue = nextValueAsString(aReader); addBagTextField(scBag, jsonName, jsonValue); } } aReader.endObject(); assignSearchComponentType(scDocument); searchComponentDocument.addRelationship(scDocument.getType(), scDocument); } aCfgDocument.addRelationship(aDocType, searchComponentDocument); }