List of usage examples for com.google.gson.stream JsonReader nextName
public String nextName() throws IOException
From source file:com.nridge.ds.solr.SolrConfigJSON.java
License:Open Source License
private void addFieldToDocument(JsonReader aReader, Document aDocument) throws IOException { String jsonName;/*from www. j ava 2 s .c om*/ jsonName = aReader.nextName(); addFieldToDocument(aReader, aDocument, jsonName); }
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 ww. jav a2 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 w w . j a v a 2 s.com*/ 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 populateSearchComponent(JsonReader aReader, Document aCfgDocument, String aDocType) throws IOException { DataBag scBag;/*from w w w. j a v a2 s .co 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 w ww .j a va2 s . co m * * @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;// w w w . j ava 2 s . c om 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;// w w w .j av a2 s .com 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 ww w . j a va 2 s . c o m 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(); }
From source file:com.nridge.ds.solr.SolrSchemaJSON.java
License:Open Source License
private void populateSchemaFieldTypeAnalyzer(JsonReader aReader, Document aFTDocument, String aDocType) throws IOException { String jsonName, jsonValue;/*from w ww . ja va 2s . c o m*/ DataTextField dataTextField; DataBag tokenizerBag, filterBag; Document tokenizerDocument, filterDocument; Document analyzerDocument = new Document(aDocType); DataBag analyzerBag = analyzerDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, OBJECT_SCHEMA_FT_ANALYZER_TOKENIZER)) { tokenizerDocument = new Document(Solr.RESPONSE_SCHEMA_FTA_TOKENIZER); tokenizerDocument.setName(jsonName); tokenizerBag = tokenizerDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); dataTextField = new DataTextField(jsonName, Field.nameToTitle(jsonName), jsonValue); dataTextField.addFeature(Field.FEATURE_IS_STORED, StrUtl.STRING_TRUE); tokenizerBag.add(dataTextField); } aReader.endObject(); analyzerDocument.addRelationship(Solr.RESPONSE_SCHEMA_FTA_TOKENIZER, tokenizerDocument); } else if (StringUtils.equals(jsonName, OBJECT_SCHEMA_FT_ANALYZER_FILTERS)) { aReader.beginArray(); while (aReader.hasNext()) { filterDocument = new Document(Solr.RESPONSE_SCHEMA_FTA_FILTERS); filterDocument.setName(jsonName); filterBag = filterDocument.getBag(); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); jsonValue = nextValueAsString(aReader); dataTextField = new DataTextField(jsonName, Field.nameToTitle(jsonName), jsonValue); dataTextField.addFeature(Field.FEATURE_IS_STORED, StrUtl.STRING_TRUE); filterBag.add(dataTextField); } aReader.endObject(); analyzerDocument.addRelationship(Solr.RESPONSE_SCHEMA_FTA_FILTERS, filterDocument); } aReader.endArray(); } else { jsonValue = nextValueAsString(aReader); if (StringUtils.equals(jsonName, "class")) analyzerDocument.setName(jsonName); dataTextField = new DataTextField(jsonName, Field.nameToTitle(jsonName), jsonValue); dataTextField.addFeature(Field.FEATURE_IS_STORED, StrUtl.STRING_TRUE); analyzerBag.add(dataTextField); } } aReader.endObject(); aFTDocument.addRelationship(Solr.RESPONSE_SCHEMA_FT_ANALYZERS, analyzerDocument); }
From source file:com.nridge.ds.solr.SolrSchemaJSON.java
License:Open Source License
private void populateSchemaFieldTypes(JsonReader aReader, Document aSchemaDocument) throws IOException { DataBag fieldTypeBag;/*from w w w . j a v a 2 s . com*/ String jsonName, jsonValue; Document fieldTypeDocument; DataTextField dataTextField; aReader.beginArray(); while (aReader.hasNext()) { fieldTypeDocument = new Document(Solr.RESPONSE_SCHEMA_FIELD_TYPE); fieldTypeBag = fieldTypeDocument.getBag(); DataTextField operationField = new DataTextField(Solr.SCHEMA_OPERATION_FIELD_NAME, Field.nameToTitle(Solr.SCHEMA_OPERATION_FIELD_NAME)); operationField.addFeature(Field.FEATURE_IS_STORED, StrUtl.STRING_FALSE); fieldTypeBag.add(operationField); aReader.beginObject(); while (aReader.hasNext()) { jsonName = aReader.nextName(); if (StringUtils.equals(jsonName, OBJECT_SCHEMA_FT_ANALYZER)) populateSchemaFieldTypeAnalyzer(aReader, fieldTypeDocument, Solr.RESPONSE_SCHEMA_FT_ANALYZER); else if (StringUtils.equals(jsonName, OBJECT_SCHEMA_FT_INDEX_ANALYZER)) populateSchemaFieldTypeAnalyzer(aReader, fieldTypeDocument, Solr.RESPONSE_SCHEMA_FT_INDEX_ANALYZER); else if (StringUtils.equals(jsonName, OBJECT_SCHEMA_FT_QUERY_ANALYZER)) populateSchemaFieldTypeAnalyzer(aReader, fieldTypeDocument, Solr.RESPONSE_SCHEMA_FT_QUERY_ANALYZER); else { jsonValue = nextValueAsString(aReader); if (StringUtils.equals(jsonName, "name")) fieldTypeDocument.setName(jsonValue); dataTextField = new DataTextField(jsonName, Field.nameToTitle(jsonName), jsonValue); dataTextField.addFeature(Field.FEATURE_IS_STORED, StrUtl.STRING_TRUE); fieldTypeBag.add(dataTextField); } } aReader.endObject(); aSchemaDocument.addRelationship(Solr.RESPONSE_SCHEMA_FIELD_TYPE, fieldTypeDocument); } aReader.endArray(); }