List of usage examples for com.google.gson.stream JsonReader endObject
public void endObject() throws IOException
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 w w w. j a v a 2 s. c om*/ 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 www . j a va2 s .co 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;//from w w w .j ava 2 s . com 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;/*w ww . j av a 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 .ja v a2 s . 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. j ava2 s . c o m 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); }
From source file:com.nridge.ds.solr.SolrConfigJSON.java
License:Open Source License
/** * Parses an JSON string representing the Solr schema and loads it into a document * and returns an instance to it.//from www .j a v a2 s. c om * * @param aConfigString JSON string representation of the Solr schema. * * @return Document instance containing the parsed data. * * @throws IOException I/O related exception. */ public Document loadDocument(String aConfigString) throws IOException { String jsonName, jsonValue; Document componentDocument; Document configDocument = new Document(Solr.DOCUMENT_SCHEMA_TYPE); DataBag configBag = configDocument.getBag(); StringReader stringReader = new StringReader(aConfigString); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, OBJECT_RESPONSE_HEADER)) { Document headerDocument = new Document(Solr.RESPONSE_SCHEMA_HEADER); DataBag headerBag = headerDocument.getBag(); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); jsonValue = nextValueAsString(jsonReader); headerBag.add(new DataTextField(jsonName, Field.nameToTitle(jsonName), jsonValue)); } jsonReader.endObject(); configDocument.addRelationship(Solr.RESPONSE_SCHEMA_HEADER, headerDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG)) { jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_UPDATE_HANDLER)) populateCfgUpdateHandler(jsonReader, configDocument, Solr.RESPONSE_CONFIG_UPDATE_HANDLER); else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_QUERY)) populateCfgQuery(jsonReader, configDocument, Solr.RESPONSE_CONFIG_QUERY); else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_REQUEST_HANDLER)) populateCfgRequestHandler(jsonReader, configDocument, Solr.RESPONSE_CONFIG_REQUEST_HANDLER); else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_RESPONSE_WRITER)) populateQueryResponseWriterHandler(jsonReader, configDocument, Solr.RESPONSE_CONFIG_QUERY_RESPONSE_WRITER); else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_SEARCH_COMPONENT)) populateSearchComponent(jsonReader, configDocument, Solr.RESPONSE_CONFIG_SEARCH_COMPONENT); else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_INIT_PARAMS)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_INIT_PARAMS); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_INIT_PARAMETERS, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_INIT_PARAMS, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_LISTENER)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_LISTENER); jsonReader.beginArray(); while (jsonReader.hasNext()) addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_LISTENER_EVENTS, jsonName); jsonReader.endArray(); configDocument.addRelationship(Solr.RESPONSE_CONFIG_LISTENER, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_DIRECTORY_FACTORY)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_DIRECTORY_FACTORY); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_DIRECTORY_ENTRIES, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_DIRECTORY_FACTORY, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_CODEC_FACTORY)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_CODEC_FACTORY); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_CODEC_ENTRIES, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_CODEC_FACTORY, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_UPDATE_HU_LOG)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_UPDATE_HANDLER_ULOG); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_UHUL_ENTRIES, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_UPDATE_HANDLER_ULOG, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_REQUEST_DISPATCHER)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_REQUEST_DISPATCHER); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_RD_ENTRIES, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_REQUEST_DISPATCHER, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_INDEX_CONFIG)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_REQUEST_DISPATCHER); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_INDEX_CONFIG, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_IC_ENTRIES, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_PEER_SYNC)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_PEER_SYNC); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_PS_ENTRIES, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_PEER_SYNC, componentDocument); } else { jsonValue = nextValueAsString(jsonReader); addBagTextField(configBag, jsonName, jsonValue); } } jsonReader.endObject(); } else jsonReader.skipValue(); } jsonReader.endObject(); jsonReader.close(); return configDocument; }
From source file:com.nridge.ds.solr.SolrConfigSet.java
License:Open Source License
private ArrayList<String> load(InputStream anIS) throws IOException { String jsonName, jsonValue;/*from w ww . j a v a2 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, "configSets")) { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonValue = jsonReader.nextString(); configSetList.add(jsonValue); } jsonReader.endArray(); } } jsonReader.endObject(); return configSetList; }
From source file:com.nridge.ds.solr.SolrSchemaJSON.java
License:Open Source License
private DataTable createSchemaFieldTable(String aSchemaString, String aFieldName, String aTitle) throws IOException { String jsonName;/*ww w .ja va2s. c o m*/ DataField dataField; DataTable dataTable = new DataTable(aTitle); DataBag dataBag = dataTable.getColumnBag(); StringReader stringReader = new StringReader(aSchemaString); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, OBJECT_SCHEMA)) { jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, aFieldName)) { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); dataField = dataBag.getFieldByName(jsonName); if (dataField == null) { dataField = new DataTextField(jsonName, Field.nameToTitle(jsonName)); dataField.addFeature(Field.FEATURE_IS_STORED, StrUtl.STRING_TRUE); dataBag.add(dataField); } jsonReader.skipValue(); } jsonReader.endObject(); } jsonReader.endArray(); ; } else jsonReader.skipValue(); } jsonReader.endObject(); } else jsonReader.skipValue(); } jsonReader.endObject(); jsonReader.close(); return dataTable; }
From source file:com.nridge.ds.solr.SolrSchemaJSON.java
License:Open Source License
private void populateSchemaFieldTable(JsonReader aReader, DataTable aTable) throws IOException { String jsonName, jsonValue;//from w w w . j av a 2 s. c om aReader.beginArray(); while (aReader.hasNext()) { aTable.newRow(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); aTable.setValueByName(jsonName, jsonValue); } aReader.endObject(); aTable.addRow(); } aReader.endArray(); }