List of usage examples for com.fasterxml.jackson.core JsonParser nextTextValue
public String nextTextValue() throws IOException, JsonParseException
From source file:msearch.filmlisten.MSFilmlisteLesen.java
public void readFilmListe(String source, final ListeFilme listeFilme, int days) { JsonToken jsonToken;/* ww w .j a va 2 s. c o m*/ String sender = "", thema = ""; listeFilme.clear(); this.notifyStart(source, PROGRESS_MAX); // fr die Progressanzeige if (days > 0) { final long maxDays = 1000L * 60L * 60L * 24L * days; seconds = new Date().getTime() - maxDays; } else { seconds = 0; } try { InputStream in = selectDecompressor(source, getInputStreamForLocation(source)); JsonParser jp = new JsonFactory().createParser(in); if (jp.nextToken() != JsonToken.START_OBJECT) { throw new IllegalStateException("Expected data to start with an Object"); } while ((jsonToken = jp.nextToken()) != null) { if (jsonToken == JsonToken.END_OBJECT) { break; } if (jp.isExpectedStartArrayToken()) { for (int k = 0; k < ListeFilme.MAX_ELEM; ++k) { listeFilme.metaDaten[k] = jp.nextTextValue(); } break; } } while ((jsonToken = jp.nextToken()) != null) { if (jsonToken == JsonToken.END_OBJECT) { break; } if (jp.isExpectedStartArrayToken()) { // sind nur die Feldbeschreibungen, brauch mer nicht jp.nextToken(); break; } } while (!MSConfig.getStop() && (jsonToken = jp.nextToken()) != null) { if (jsonToken == JsonToken.END_OBJECT) { break; } if (jp.isExpectedStartArrayToken()) { DatenFilm datenFilm = new DatenFilm(); for (int i = 0; i < DatenFilm.COLUMN_NAMES_JSON.length; ++i) { //if we are in FASTAUTO mode, we dont need film descriptions. //this should speed up loading on low end devices... if (workMode == WorkMode.FASTAUTO) { if (DatenFilm.COLUMN_NAMES_JSON[i] == DatenFilm.FILM_BESCHREIBUNG_NR || DatenFilm.COLUMN_NAMES_JSON[i] == DatenFilm.FILM_WEBSEITE_NR || DatenFilm.COLUMN_NAMES_JSON[i] == DatenFilm.FILM_GEO_NR) { jp.nextToken(); continue; } } datenFilm.arr[DatenFilm.COLUMN_NAMES_JSON[i]] = jp.nextTextValue(); /// fr die Entwicklungszeit if (datenFilm.arr[DatenFilm.COLUMN_NAMES_JSON[i]] == null) { datenFilm.arr[DatenFilm.COLUMN_NAMES_JSON[i]] = ""; } } if (datenFilm.arr[DatenFilm.FILM_SENDER_NR].isEmpty()) { datenFilm.arr[DatenFilm.FILM_SENDER_NR] = sender; } else { sender = datenFilm.arr[DatenFilm.FILM_SENDER_NR]; } if (datenFilm.arr[DatenFilm.FILM_THEMA_NR].isEmpty()) { datenFilm.arr[DatenFilm.FILM_THEMA_NR] = thema; } else { thema = datenFilm.arr[DatenFilm.FILM_THEMA_NR]; } listeFilme.importFilmliste(datenFilm); if (seconds > 0) { // muss "rckwrts" laufen, da das Datum sonst 2x gebaut werden muss // wenns drin bleibt, kann mans noch ndern if (!checkDate(datenFilm)) { listeFilme.remove(datenFilm); } } } } } catch (FileNotFoundException ex) { listeFilme.clear(); } catch (Exception ex) { MSLog.fehlerMeldung(945123641, MSLog.FEHLER_ART_PROG, "MSearchIoXmlFilmlisteLesen.readFilmListe: " + source, ex); listeFilme.clear(); } if (MSConfig.getStop()) { listeFilme.clear(); } notifyFertig(source, listeFilme); }
From source file:com.joliciel.jochre.search.highlight.Snippet.java
private void read(JsonParser jsonParser) { try {/*from w ww .j a v a2 s . c om*/ if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) throw new RuntimeException("Expected START_OBJECT, but was " + jsonParser.getCurrentToken() + " at " + jsonParser.getCurrentLocation()); while (jsonParser.nextToken() != JsonToken.END_OBJECT) { String fieldName = jsonParser.getCurrentName(); if (fieldName.equals("docId")) { this.docId = jsonParser.nextIntValue(0); } else if (fieldName.equals("field")) { this.field = jsonParser.nextTextValue(); } else if (fieldName.equals("start")) { this.startOffset = jsonParser.nextIntValue(0); } else if (fieldName.equals("end")) { this.endOffset = jsonParser.nextIntValue(0); } else if (fieldName.equals("score")) { jsonParser.nextValue(); this.score = jsonParser.getDoubleValue(); this.scoreCalculated = true; } else if (fieldName.equals("terms")) { if (jsonParser.nextToken() != JsonToken.START_ARRAY) throw new RuntimeException("Expected START_ARRAY, but was " + jsonParser.getCurrentToken() + " at " + jsonParser.getCurrentLocation()); while (jsonParser.nextToken() != JsonToken.END_ARRAY) { if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) throw new RuntimeException("Expected START_OBJECT, but was " + jsonParser.getCurrentToken() + " at " + jsonParser.getCurrentLocation()); int termDocId = docId; String termField = field; int termStart = 0; int termEnd = 0; int pageIndex = 0; int imageIndex = 0; double weight = 0.0; while (jsonParser.nextToken() != JsonToken.END_OBJECT) { String termFieldName = jsonParser.getCurrentName(); if (termFieldName.equals("docId")) { termDocId = jsonParser.nextIntValue(0); } else if (termFieldName.equals("field")) { termField = jsonParser.nextTextValue(); } else if (termFieldName.equals("start")) { termStart = jsonParser.nextIntValue(0); } else if (termFieldName.equals("end")) { termEnd = jsonParser.nextIntValue(0); } else if (termFieldName.equals("pageIndex")) { pageIndex = jsonParser.nextIntValue(0); } else if (termFieldName.equals("imageIndex")) { imageIndex = jsonParser.nextIntValue(0); } else if (termFieldName.equals("weight")) { jsonParser.nextValue(); weight = jsonParser.getDoubleValue(); } else { throw new RuntimeException("Unexpected term field name: " + termFieldName + " at " + jsonParser.getCurrentLocation()); } } HighlightTerm highlightTerm = new HighlightTerm(termDocId, termField, termStart, termEnd, imageIndex, pageIndex); highlightTerm.setWeight(weight); this.highlightTerms.add(highlightTerm); } } else { throw new RuntimeException( "Unexpected field name: " + fieldName + " at " + jsonParser.getCurrentLocation()); } } } catch (JsonParseException e) { LOG.error(e); throw new RuntimeException(e); } catch (IOException e) { LOG.error(e); throw new RuntimeException(e); } }
From source file:eu.project.ttc.models.index.JsonTermIndexIO.java
/** * Loads the json-serialized term index into the param {@link TermIndex} object. * //from w w w . j a va 2 s .c o m * @param reader * @param options * The deserialization {@link IOOptions}. * @return * @throws JsonParseException * @throws IOException */ public static TermIndex load(Reader reader, JsonOptions options) throws JsonParseException, IOException { TermIndex termIndex = null; JsonFactory jsonFactory = new JsonFactory(); JsonParser jp = jsonFactory.createParser(reader); // or Stream, Reader jp.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES); jp.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION); String fieldname; String compLemma = null; int fileSource = -1; String wordLemma = null; String syntacticLabel = null; int begin = -1; int end = -1; int nbWordAnnos = -1; int nbSpottedTerms = -1; Term b; Term v; String text; String base; String variant; // String rule; String infoToken; String variantType; double variantScore; Map<Integer, String> inputSources = Maps.newTreeMap(); Map<Integer, List<TempVecEntry>> contextVectors = Maps.newHashMap(); OccurrenceStore occurrenceStore = null; // useful var for debug JsonToken tok; while ((tok = jp.nextToken()) != JsonToken.END_OBJECT) { fieldname = jp.getCurrentName(); if (METADATA.equals(fieldname)) { jp.nextToken(); String termIndexName = null; Lang lang = null; String corpusID = null; String occurrenceStorage = null; String occurrenceStoreURI = null; while ((tok = jp.nextToken()) != JsonToken.END_OBJECT) { fieldname = jp.getCurrentName(); if (LANG.equals(fieldname)) { lang = Lang.forName(jp.nextTextValue()); } else if (NAME.equals(fieldname)) { termIndexName = jp.nextTextValue(); } else if (NB_WORD_ANNOTATIONS.equals(fieldname)) { nbWordAnnos = jp.nextIntValue(-1); } else if (NB_SPOTTED_TERMS.equals(fieldname)) { nbSpottedTerms = jp.nextIntValue(-1); } else if (CORPUS_ID.equals(fieldname)) { corpusID = jp.nextTextValue(); } else if (OCCURRENCE_STORAGE.equals(fieldname)) { occurrenceStorage = jp.nextTextValue(); } else if (OCCURRENCE_MONGODB_STORE_URI.equals(fieldname)) { occurrenceStoreURI = jp.nextTextValue(); } } Preconditions.checkState(lang != null, "The property meta.lang must be defined"); Preconditions.checkState(termIndexName != null, "The property meta.name must be defined"); if (occurrenceStorage != null && occurrenceStorage.equals(OCCURRENCE_STORAGE_MONGODB)) { Preconditions.checkNotNull(occurrenceStoreURI, "Missing attribute " + OCCURRENCE_MONGODB_STORE_URI); occurrenceStore = new MongoDBOccurrenceStore(occurrenceStoreURI, OccurrenceStore.State.INDEXED); } else occurrenceStore = new MemoryOccurrenceStore(); termIndex = new MemoryTermIndex(termIndexName, lang, occurrenceStore); if (corpusID != null) termIndex.setCorpusId(corpusID); if (nbWordAnnos != -1) termIndex.setWordAnnotationsNum(nbWordAnnos); if (nbSpottedTerms != -1) termIndex.setSpottedTermsNum(nbSpottedTerms); if (options.isMetadataOnly()) return termIndex; } else if (WORDS.equals(fieldname)) { jp.nextToken(); while ((tok = jp.nextToken()) != JsonToken.END_ARRAY) { WordBuilder wordBuilder = WordBuilder.start(); while ((tok = jp.nextToken()) != JsonToken.END_OBJECT) { fieldname = jp.getCurrentName(); if (LEMMA.equals(fieldname)) wordBuilder.setLemma(jp.nextTextValue()); else if (COMPOUND_TYPE.equals(fieldname)) wordBuilder.setCompoundType(CompoundType.fromName(jp.nextTextValue())); else if (STEM.equals(fieldname)) wordBuilder.setStem(jp.nextTextValue()); else if (COMPONENTS.equals(fieldname)) { while ((tok = jp.nextToken()) != JsonToken.END_ARRAY) { while ((tok = jp.nextToken()) != JsonToken.END_OBJECT) { fieldname = jp.getCurrentName(); if (LEMMA.equals(fieldname)) compLemma = jp.nextTextValue(); else if (BEGIN.equals(fieldname)) begin = jp.nextIntValue(-2); else if (END.equals(fieldname)) end = jp.nextIntValue(-2); } wordBuilder.addComponent(begin, end, compLemma); } } } try { termIndex.addWord(wordBuilder.create()); } catch (Exception e) { LOGGER.error("Could not add word " + wordBuilder.getLemma() + " to term index", e); LOGGER.warn("Error ignored, trying ton continue the loading of TermIndex"); } } } else if (TERMS.equals(fieldname)) { jp.nextToken(); while ((tok = jp.nextToken()) != JsonToken.END_ARRAY) { TermBuilder builder = TermBuilder.start(termIndex); List<TempVecEntry> currentContextVector = Lists.newArrayList(); int currentTermId = -1; while ((tok = jp.nextToken()) != JsonToken.END_OBJECT) { fieldname = jp.getCurrentName(); if (GROUPING_KEY.equals(fieldname)) builder.setGroupingKey(jp.nextTextValue()); else if (SPOTTING_RULE.equals(fieldname)) builder.setSpottingRule(jp.nextTextValue()); else if (ID.equals(fieldname)) { currentTermId = jp.nextIntValue(-2); builder.setId(currentTermId); } else if (RANK.equals(fieldname)) { builder.setRank(jp.nextIntValue(-1)); } else if (FREQUENCY.equals(fieldname)) { builder.setFrequency(jp.nextIntValue(-1)); } else { if (FREQ_NORM.equals(fieldname)) { jp.nextToken(); builder.setFrequencyNorm((double) jp.getFloatValue()); } else if (SPECIFICITY.equals(fieldname)) { jp.nextToken(); builder.setSpecificity((double) jp.getDoubleValue()); } else if (GENERAL_FREQ_NORM.equals(fieldname)) { jp.nextToken(); builder.setGeneralFrequencyNorm((double) jp.getFloatValue()); } else if (WORDS.equals(fieldname)) { while ((tok = jp.nextToken()) != JsonToken.END_ARRAY) { wordLemma = null; syntacticLabel = null; while ((tok = jp.nextToken()) != JsonToken.END_OBJECT) { fieldname = jp.getCurrentName(); if (LEMMA.equals(fieldname)) wordLemma = jp.nextTextValue(); else if (SYN.equals(fieldname)) syntacticLabel = jp.nextTextValue(); } Preconditions.checkArgument(wordLemma != null, MSG_EXPECT_PROP_FOR_TERM_WORD, LEMMA); Preconditions.checkArgument(syntacticLabel != null, MSG_EXPECT_PROP_FOR_TERM_WORD, SYN); builder.addWord(termIndex.getWord(wordLemma), syntacticLabel); } // end words } else if (OCCURRENCES.equals(fieldname)) { tok = jp.nextToken(); if (tok == JsonToken.START_ARRAY) { while ((tok = jp.nextToken()) != JsonToken.END_ARRAY) { begin = -1; end = -1; fileSource = -1; text = null; while ((tok = jp.nextToken()) != JsonToken.END_OBJECT) { fieldname = jp.getCurrentName(); if (BEGIN.equals(fieldname)) begin = jp.nextIntValue(-1); else if (TEXT.equals(fieldname)) text = jp.nextTextValue(); else if (END.equals(fieldname)) end = jp.nextIntValue(-1); else if (FILE.equals(fieldname)) { fileSource = jp.nextIntValue(-1); } } Preconditions.checkArgument(begin != -1, MSG_EXPECT_PROP_FOR_OCCURRENCE, BEGIN); Preconditions.checkArgument(end != -1, MSG_EXPECT_PROP_FOR_OCCURRENCE, END); Preconditions.checkArgument(fileSource != -1, MSG_EXPECT_PROP_FOR_OCCURRENCE, FILE); Preconditions.checkNotNull(inputSources.get(fileSource), "No file source with id: %s", fileSource); Preconditions.checkNotNull(text, MSG_EXPECT_PROP_FOR_OCCURRENCE, TEXT); if (occurrenceStore.getStoreType() == OccurrenceStore.Type.MEMORY) builder.addOccurrence(begin, end, termIndex.getDocument(inputSources.get(fileSource)), text); } } // end occurrences } else if (CONTEXT.equals(fieldname)) { @SuppressWarnings("unused") int totalCooccs = 0; while ((tok = jp.nextToken()) != JsonToken.END_OBJECT) { fieldname = jp.getCurrentName(); if (TOTAL_COOCCURRENCES.equals(fieldname)) /* * value never used since the total will * be reincremented in the contextVector */ totalCooccs = jp.nextIntValue(-1); else if (CO_OCCURRENCES.equals(fieldname)) { jp.nextToken(); while ((tok = jp.nextToken()) != JsonToken.END_ARRAY) { TempVecEntry entry = new TempVecEntry(); while ((tok = jp.nextToken()) != JsonToken.END_OBJECT) { fieldname = jp.getCurrentName(); if (NB_COCCS.equals(fieldname)) entry.setNbCooccs(jp.nextIntValue(-1)); else if (ASSOC_RATE.equals(fieldname)) { jp.nextToken(); entry.setAssocRate(jp.getFloatValue()); } else if (CO_TERM.equals(fieldname)) entry.setTermGroupingKey(jp.nextTextValue()); else if (FILE.equals(fieldname)) { fileSource = jp.nextIntValue(-1); } } currentContextVector.add(entry); } } } } } //end if fieldname } // end term object try { builder.createAndAddToIndex(); } catch (Exception e) { LOGGER.error("Could not add term " + builder.getGroupingKey() + " to term index", e); LOGGER.warn("Error ignored, trying ton continue the loading of TermIndex"); } if (options.isWithContexts()) contextVectors.put(currentTermId, currentContextVector); } // end array of terms } else if (INPUT_SOURCES.equals(fieldname)) { jp.nextToken(); while ((tok = jp.nextToken()) != JsonToken.END_OBJECT) { String id = jp.getCurrentName(); try { inputSources.put(Integer.parseInt(id), jp.nextTextValue()); } catch (NumberFormatException e) { IOUtils.closeQuietly(jp); throw new IllegalArgumentException("Bad format for input source key: " + id); } } } else if (TERM_VARIATIONS.equals(fieldname)) { jp.nextToken(); while ((tok = jp.nextToken()) != JsonToken.END_ARRAY) { base = null; variant = null; infoToken = null; variantType = null; variantScore = 0; while ((tok = jp.nextToken()) != JsonToken.END_OBJECT) { fieldname = jp.getCurrentName(); if (BASE.equals(fieldname)) base = jp.nextTextValue(); else if (VARIANT.equals(fieldname)) variant = jp.nextTextValue(); else if (VARIANT_TYPE.equals(fieldname)) variantType = jp.nextTextValue(); else if (VARIANT_SCORE.equals(fieldname)) { jp.nextToken(); variantScore = jp.getDoubleValue(); } else if (INFO.equals(fieldname)) infoToken = jp.nextTextValue(); } // end syntactic variant object Preconditions.checkNotNull(base, MSG_EXPECT_PROP_FOR_VAR, BASE); Preconditions.checkNotNull(variant, MSG_EXPECT_PROP_FOR_VAR, VARIANT); Preconditions.checkNotNull(infoToken, MSG_EXPECT_PROP_FOR_VAR, INFO); b = termIndex.getTermByGroupingKey(base); v = termIndex.getTermByGroupingKey(variant); if (b != null && v != null) { VariationType vType = VariationType.fromShortName(variantType); TermVariation tv = new TermVariation(vType, b, v, vType == VariationType.GRAPHICAL ? Double.parseDouble(infoToken) : infoToken); tv.setScore(variantScore); b.addTermVariation(tv); } else { if (b == null) LOGGER.warn("Could not build variant because term \"{}\" was not found.", base); if (v == null) LOGGER.warn("Could not build variant because term \"{}\" was not found.", variant); } // Preconditions.checkNotNull(b, MSG_TERM_DOES_NOT_EXIST, base); // Preconditions.checkNotNull(v, MSG_TERM_DOES_NOT_EXIST, variant); } // end syntactic variations array } } jp.close(); if (options.isWithContexts()) { /* * map term ids with terms in context vectors and * set context vectors */ List<TempVecEntry> currentTempVecList; Term term = null; Term coTerm = null; ContextVector contextVector; for (int termId : contextVectors.keySet()) { currentTempVecList = contextVectors.get(termId); term = termIndex.getTermById(termId); contextVector = new ContextVector(term); for (TempVecEntry tempVecEntry : currentTempVecList) { coTerm = termIndex.getTermByGroupingKey(tempVecEntry.getTermGroupingKey()); contextVector.addEntry(coTerm, tempVecEntry.getNbCooccs(), tempVecEntry.getAssocRate()); } if (!contextVector.getEntries().isEmpty()) term.setContextVector(contextVector); } } return termIndex; }
From source file:org.seedstack.seed.core.internal.data.DataManagerImpl.java
@Override public void importData(InputStream inputStream, String acceptGroup, String acceptName, boolean clear) { Set<DataImporter<Object>> usedDataImporters = new HashSet<>(); try {/*w ww .ja va 2 s . c o m*/ ParsingState state = ParsingState.START; String group = null; String name = null; JsonParser jsonParser = this.jsonFactory .createParser(new InputStreamReader(inputStream, Charset.forName(UTF_8))); JsonToken jsonToken = jsonParser.nextToken(); while (jsonToken != null) { switch (state) { case START: if (jsonToken == JsonToken.START_ARRAY) { state = ParsingState.DEFINITION_START; } else { throwParsingError(jsonParser.getCurrentLocation(), "start array expected"); } break; case DEFINITION_START: if (jsonToken == JsonToken.START_OBJECT) { state = ParsingState.DEFINITION_GROUP; } else { throwParsingError(jsonParser.getCurrentLocation(), "start object expected"); } break; case DEFINITION_GROUP: if (jsonToken == JsonToken.FIELD_NAME && GROUP.equals(jsonParser.getCurrentName())) { group = jsonParser.nextTextValue(); state = ParsingState.DEFINITION_NAME; } else { throwParsingError(jsonParser.getCurrentLocation(), "group field expected"); } break; case DEFINITION_NAME: if (jsonToken == JsonToken.FIELD_NAME && NAME.equals(jsonParser.getCurrentName())) { name = jsonParser.nextTextValue(); state = ParsingState.DEFINITION_ITEMS; } else { throwParsingError(jsonParser.getCurrentLocation(), "name field expected"); } break; case DEFINITION_ITEMS: if (jsonToken == JsonToken.FIELD_NAME && ITEMS.equals(jsonParser.getCurrentName())) { usedDataImporters.add(consumeItems(jsonParser, group, name, acceptGroup, acceptName)); state = ParsingState.DEFINITION_END; } else { throwParsingError(jsonParser.getCurrentLocation(), "items field expected"); } break; case DEFINITION_END: if (jsonToken == JsonToken.END_OBJECT) { group = null; name = null; state = ParsingState.END; } else { throwParsingError(jsonParser.getCurrentLocation(), "end object expected"); } break; case END: if (jsonToken == JsonToken.START_OBJECT) { state = ParsingState.DEFINITION_GROUP; } else if (jsonToken == JsonToken.END_ARRAY) { state = ParsingState.START; } else { throwParsingError(jsonParser.getCurrentLocation(), "start object or end array expected"); } break; default: throwParsingError(jsonParser.getCurrentLocation(), "unexpected parser state"); } jsonToken = jsonParser.nextToken(); } } catch (Exception e1) { for (DataImporter<Object> usedDataImporter : usedDataImporters) { try { usedDataImporter.rollback(); } catch (Exception e2) { e2.initCause(e1); throw SeedException.wrap(e2, DataErrorCode.FAILED_TO_ROLLBACK_IMPORT).put(IMPORTER_CLASS, usedDataImporter.getClass().getName()); } } throw SeedException.wrap(e1, DataErrorCode.IMPORT_FAILED); } for (DataImporter<Object> usedDataImporter : usedDataImporters) { try { usedDataImporter.commit(clear); } catch (Exception e) { throw SeedException.wrap(e, DataErrorCode.FAILED_TO_COMMIT_IMPORT).put(IMPORTER_CLASS, usedDataImporter.getClass().getName()); } } }
From source file:com.msopentech.odatajclient.engine.metadata.edm.v4.annotation.DynExprConstructDeserializer.java
@Override protected DynExprConstruct doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { DynExprConstruct construct = null;//from w w w. j a v a 2 s. co m if (DynExprSingleParamOp.Type.fromString(jp.getCurrentName()) != null) { final DynExprSingleParamOp dynExprSingleParamOp = new DynExprSingleParamOp(); dynExprSingleParamOp.setType(DynExprSingleParamOp.Type.fromString(jp.getCurrentName())); jp.nextToken(); jp.nextToken(); dynExprSingleParamOp.setExpression(jp.getCodec().readValue(jp, DynExprConstruct.class)); construct = dynExprSingleParamOp; } else if (DynExprDoubleParamOp.Type.fromString(jp.getCurrentName()) != null) { final DynExprDoubleParamOp dynExprDoubleParamOp = new DynExprDoubleParamOp(); dynExprDoubleParamOp.setType(DynExprDoubleParamOp.Type.fromString(jp.getCurrentName())); jp.nextToken(); jp.nextToken(); dynExprDoubleParamOp.setLeft(jp.getCodec().readValue(jp, DynExprConstruct.class)); dynExprDoubleParamOp.setRight(jp.getCodec().readValue(jp, DynExprConstruct.class)); construct = dynExprDoubleParamOp; } else if (ArrayUtils.contains(EL_OR_ATTR, jp.getCurrentName())) { final AbstractElOrAttrConstruct elOrAttr = getElOrAttrInstance(jp.getCurrentName()); elOrAttr.setValue(jp.nextTextValue()); construct = elOrAttr; } else if (APPLY.equals(jp.getCurrentName())) { jp.nextToken(); construct = jp.getCodec().readValue(jp, Apply.class); } else if (CAST.equals(jp.getCurrentName())) { jp.nextToken(); construct = jp.getCodec().readValue(jp, Cast.class); } else if (COLLECTION.equals(jp.getCurrentName())) { jp.nextToken(); construct = jp.getCodec().readValue(jp, Collection.class); } else if (IF.equals(jp.getCurrentName())) { jp.nextToken(); jp.nextToken(); final If _if = new If(); _if.setGuard(parseConstOrEnumExprConstruct(jp)); _if.setThen(parseConstOrEnumExprConstruct(jp)); _if.setElse(parseConstOrEnumExprConstruct(jp)); construct = _if; } else if (IS_OF.equals(jp.getCurrentName())) { jp.nextToken(); construct = jp.getCodec().readValue(jp, IsOf.class); } else if (LABELED_ELEMENT.equals(jp.getCurrentName())) { jp.nextToken(); construct = jp.getCodec().readValue(jp, LabeledElement.class); } else if (NULL.equals(jp.getCurrentName())) { jp.nextToken(); construct = jp.getCodec().readValue(jp, Null.class); } else if (RECORD.equals(jp.getCurrentName())) { jp.nextToken(); construct = jp.getCodec().readValue(jp, Record.class); } else if (URL_REF.equals(jp.getCurrentName())) { jp.nextToken(); construct = jp.getCodec().readValue(jp, UrlRef.class); } return construct; }
From source file:org.n52.movingcode.runtime.processors.config.ProcessorConfig.java
/** * Parsing routine for processor objects * /*from w ww . j a va 2 s .c o m*/ * @param jp * @return * @throws JsonParseException * @throws IOException */ private static final ProcessorDescription parseProcessorJSON(JsonParser jp) throws JsonParseException, IOException { ProcessorDescription p = new ProcessorDescription(); while (jp.nextToken() != END_OBJECT) { JsonToken jt = jp.getCurrentToken(); // look for ID and parse it if (jp.getCurrentName().equalsIgnoreCase(KEY_ID) && jt == VALUE_STRING) { p.setId(jp.getValueAsString()); } // look for temp workspace and parse it if (jp.getCurrentName().equalsIgnoreCase(KEY_TEMPWORKSPACE) && jt == VALUE_STRING) { p.setTempWorkspace(jp.getValueAsString()); } // look for containers and parse them (Value Case) if (jp.getCurrentName().equalsIgnoreCase(KEY_SUPPORTED_CONTAINER) && jt == VALUE_STRING) { p.addContainer(jp.getValueAsString()); } // look for containers and parse them (Array Case) if (jp.getCurrentName().equalsIgnoreCase(KEY_SUPPORTED_CONTAINER) && jt == START_ARRAY) { while (jp.nextToken() != END_ARRAY) { if (jp.getCurrentToken() == VALUE_STRING) { p.addPlatform(jp.getValueAsString()); } } } // look for platforms and parse them (Array Case) if (jp.getCurrentName().equalsIgnoreCase(KEY_AVAILABLE_PLATFORMS) && jt == JsonToken.START_ARRAY) { while (jp.nextToken() != END_ARRAY) { if (jp.getCurrentToken() == VALUE_STRING) { p.addPlatform(jp.getValueAsString()); } } } // look for platforms and parse them (Value Case) if (jp.getCurrentName().equalsIgnoreCase(KEY_AVAILABLE_PLATFORMS) && jt == JsonToken.VALUE_STRING) { p.addPlatform(jp.getValueAsString()); } // look for properties and parse them if (jp.getCurrentName().equalsIgnoreCase(KEY_PROPERTIES) && jt == JsonToken.START_ARRAY) { HashMap<String, String> props = new HashMap<String, String>(); while (jp.nextToken() != END_ARRAY) { if (jp.getCurrentToken() == FIELD_NAME) { props.put(jp.getCurrentName(), jp.nextTextValue()); } } p.setProperties(props); } } return p; }
From source file:msearch.io.MSFilmlisteLesen.java
private boolean filmlisteJsonEinlesen(File vonDatei, ListeFilme listeFilme) { boolean ret = false; BZip2CompressorInputStream bZip2CompressorInputStream; JsonFactory jsonF = new JsonFactory(); JsonParser jp = null; JsonToken jsonToken;/*w w w.ja v a 2 s . c o m*/ String sender = "", thema = ""; try { // ########################################################## // und jetzt die Liste einlesen, URL kann es jetzt schon nicht mehr sein! if (!vonDatei.exists()) { MSLog.fehlerMeldung(702030698, MSLog.FEHLER_ART_PROG, "MSearchIoXmlFilmlisteLesen.filmlisteLesen", "Datei existiert nicht: " + vonDatei.getName()); return false; } if (vonDatei.getName().endsWith(MSConst.FORMAT_XZ)) { XZInputStream xZInputStream = new XZInputStream(new FileInputStream(vonDatei)); jp = jsonF.createParser(new InputStreamReader(xZInputStream, MSConst.KODIERUNG_UTF)); } else if (vonDatei.getName().endsWith(MSConst.FORMAT_BZ2)) { bZip2CompressorInputStream = new BZip2CompressorInputStream(new FileInputStream(vonDatei)); jp = jsonF.createParser(new InputStreamReader(bZip2CompressorInputStream, MSConst.KODIERUNG_UTF)); } else if (vonDatei.getName().endsWith(MSConst.FORMAT_ZIP)) { ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(vonDatei)); zipInputStream.getNextEntry(); jp = jsonF.createParser(new InputStreamReader(zipInputStream, MSConst.KODIERUNG_UTF)); } else { jp = jsonF.createParser(vonDatei); // geht so am schnellsten } if (jp.nextToken() != JsonToken.START_OBJECT) { throw new IOException("Expected data to start with an Object"); } while ((jsonToken = jp.nextToken()) != null) { if (jsonToken == JsonToken.END_OBJECT) { break; } if (jp.isExpectedStartArrayToken()) { for (int k = 0; k < ListeFilme.MAX_ELEM; ++k) { listeFilme.metaDaten[k] = jp.nextTextValue(); } break; } } while ((jsonToken = jp.nextToken()) != null) { if (jsonToken == JsonToken.END_OBJECT) { break; } if (jp.isExpectedStartArrayToken()) { // sind nur die Feldbeschreibungen, brauch mer nicht jp.nextToken(); break; } } while ((jsonToken = jp.nextToken()) != null) { if (jsonToken == JsonToken.END_OBJECT) { break; } if (jp.isExpectedStartArrayToken()) { DatenFilm datenFilm = new DatenFilm(); for (int i = 0; i < DatenFilm.COLUMN_NAMES_JSON.length; ++i) { datenFilm.arr[DatenFilm.COLUMN_NAMES_JSON[i]] = jp.nextTextValue(); /// fr die Entwicklungszeit if (datenFilm.arr[DatenFilm.COLUMN_NAMES_JSON[i]] == null) { datenFilm.arr[DatenFilm.COLUMN_NAMES_JSON[i]] = ""; } } if (datenFilm.arr[DatenFilm.FILM_SENDER_NR].equals("")) { datenFilm.arr[DatenFilm.FILM_SENDER_NR] = sender; } else { sender = datenFilm.arr[DatenFilm.FILM_SENDER_NR]; } if (datenFilm.arr[DatenFilm.FILM_THEMA_NR].equals("")) { datenFilm.arr[DatenFilm.FILM_THEMA_NR] = thema; } else { thema = datenFilm.arr[DatenFilm.FILM_THEMA_NR]; } listeFilme.importFilmliste(datenFilm); } } jp.close(); ret = true; } catch (Exception ex) { MSLog.fehlerMeldung(468956200, MSLog.FEHLER_ART_PROG, "MSearchIoXmlFilmlisteLesen.filmlisteLesen", ex, "von: " + vonDatei.getName()); } return ret; }
From source file:org.apache.olingo.client.core.edm.xml.ActionDeserializer.java
@Override protected ActionImpl doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final ActionImpl action = new ActionImpl(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { action.setName(jp.nextTextValue()); } else if ("IsBound".equals(jp.getCurrentName())) { action.setBound(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("EntitySetPath".equals(jp.getCurrentName())) { action.setEntitySetPath(jp.nextTextValue()); } else if ("Parameter".equals(jp.getCurrentName())) { jp.nextToken();/*from www . j a v a2s. c o m*/ action.getParameters().add(jp.readValueAs(ParameterImpl.class)); } else if ("ReturnType".equals(jp.getCurrentName())) { action.setReturnType(parseReturnType(jp, "Action")); } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); action.getAnnotations().add(jp.readValueAs(AnnotationImpl.class)); } } } return action; }
From source file:org.apache.olingo.client.core.edm.xml.annotation.DynamicAnnotationExpressionDeserializer.java
@Override protected AbstractDynamicAnnotationExpression doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { AbstractDynamicAnnotationExpression expression = null; if ("Not".equals(jp.getCurrentName())) { final NotImpl not = new NotImpl(); jp.nextToken();//w ww . j a v a 2 s .co m for (; jp.getCurrentToken() != JsonToken.FIELD_NAME; jp.nextToken()) { } not.setExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); for (; jp.getCurrentToken() != JsonToken.END_OBJECT || !jp.getCurrentName().equals("Not"); jp .nextToken()) { } expression = not; } else if (TwoParamsOpDynamicAnnotationExpression.Type.fromString(jp.getCurrentName()) != null) { final TwoParamsOpDynamicAnnotationExpressionImpl dynExprDoubleParamOp = new TwoParamsOpDynamicAnnotationExpressionImpl(); dynExprDoubleParamOp .setType(TwoParamsOpDynamicAnnotationExpression.Type.fromString(jp.getCurrentName())); jp.nextToken(); for (; jp.getCurrentToken() != JsonToken.FIELD_NAME; jp.nextToken()) { } dynExprDoubleParamOp.setLeftExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); dynExprDoubleParamOp.setRightExpression(jp.readValueAs(AbstractDynamicAnnotationExpression.class)); for (; jp.getCurrentToken() != JsonToken.END_OBJECT || !jp.getCurrentName().equals(dynExprDoubleParamOp.getType().name()); jp.nextToken()) { } expression = dynExprDoubleParamOp; } else if (ArrayUtils.contains(EL_OR_ATTR, jp.getCurrentName())) { final AbstractElementOrAttributeExpression elOrAttr = getElementOrAttributeExpressio( jp.getCurrentName()); elOrAttr.setValue(jp.nextTextValue()); expression = elOrAttr; } else if (APPLY.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(ApplyImpl.class); } else if (CAST.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(CastImpl.class); } else if (COLLECTION.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(CollectionImpl.class); } else if (IF.equals(jp.getCurrentName())) { jp.nextToken(); jp.nextToken(); final IfImpl _if = new IfImpl(); _if.setGuard(parseConstOrEnumExpression(jp)); _if.setThen(parseConstOrEnumExpression(jp)); _if.setElse(parseConstOrEnumExpression(jp)); expression = _if; } else if (IS_OF.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(IsOfImpl.class); } else if (LABELED_ELEMENT.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(LabeledElementImpl.class); } else if (NULL.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(NullImpl.class); } else if (RECORD.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(RecordImpl.class); } else if (URL_REF.equals(jp.getCurrentName())) { jp.nextToken(); expression = jp.readValueAs(UrlRefImpl.class); } return expression; }