List of usage examples for com.google.gson JsonArray iterator
public Iterator<JsonElement> iterator()
From source file:org.dartlang.analysis.server.protocol.ImplementedClass.java
License:Open Source License
public static List<ImplementedClass> fromJsonArray(JsonArray jsonArray) { if (jsonArray == null) { return EMPTY_LIST; }//from w ww. j a v a 2s . co m ArrayList<ImplementedClass> list = new ArrayList<ImplementedClass>(jsonArray.size()); Iterator<JsonElement> iterator = jsonArray.iterator(); while (iterator.hasNext()) { list.add(fromJson(iterator.next().getAsJsonObject())); } return list; }
From source file:org.dartlang.analysis.server.protocol.ImplementedMember.java
License:Open Source License
public static List<ImplementedMember> fromJsonArray(JsonArray jsonArray) { if (jsonArray == null) { return EMPTY_LIST; }//from w w w.jav a2 s .c om ArrayList<ImplementedMember> list = new ArrayList<ImplementedMember>(jsonArray.size()); Iterator<JsonElement> iterator = jsonArray.iterator(); while (iterator.hasNext()) { list.add(fromJson(iterator.next().getAsJsonObject())); } return list; }
From source file:org.dartlang.analysis.server.protocol.ImportedElements.java
License:Open Source License
public static List<ImportedElements> fromJsonArray(JsonArray jsonArray) { if (jsonArray == null) { return EMPTY_LIST; }/*from ww w. ja va2s . c om*/ ArrayList<ImportedElements> list = new ArrayList<ImportedElements>(jsonArray.size()); Iterator<JsonElement> iterator = jsonArray.iterator(); while (iterator.hasNext()) { list.add(fromJson(iterator.next().getAsJsonObject())); } return list; }
From source file:org.displaytag.model.CustomTableData.java
License:Artistic License
public CustomTableData(Long recnum, JsonObject tableCustomization) { this.recnum = recnum; JsonArray columnCnfigurations = tableCustomization.getAsJsonArray("columnConfigurations").getAsJsonArray(); for (Iterator<JsonElement> it = columnCnfigurations.iterator(); it.hasNext();) { JsonObject colConfig = it.next().getAsJsonObject(); CustomColumnData columnData = new CustomColumnData(colConfig); if (!columnData.getIsAdded()) columnConfigByCotsTitle.put(columnData.getCotsTitle(), columnData); if (columnData.isHidden()) hiddenColumnList.add(columnData); else//w w w . j av a 2s . c o m visibleColumnList.add(columnData); if (columnData.getIsAdded()) addedColumnList.add(columnData); } // sort visible columns by display order: Collections.sort(visibleColumnList); if (!(tableCustomization.get("defaultTableSortProperty") instanceof JsonNull)) { defaultTableSortProperty = tableCustomization.get("defaultTableSortProperty").getAsString(); for (int i = 0; i < visibleColumnList.size(); i++) { if (StringUtils.equals(defaultTableSortProperty, visibleColumnList.get(i).getSortOnProperty())) { defaultTableSortColumnIndex = i; break; } } } }
From source file:org.dmu.expertiserecognition.doiResults.java
private doiResults extractFullAuthorList(String jsonresp, String alt) throws Exception { doiResults dr = new doiResults(standardizeAuthorName(alt)); ArrayList<String> strlst = new ArrayList<>(); JsonElement json = new JsonParser().parse(jsonresp); JsonArray array = json.getAsJsonArray(); if (array.iterator().hasNext() == false) { return dr; }/*from w w w . j av a 2 s . c o m*/ JsonElement elem = array.iterator().next(); JsonObject jsonobj = elem.getAsJsonObject(); String coins = URLDecoder.decode(jsonobj.get("coins").getAsString(), "UTF-8"); String[] coinlist = coins.split("&"); int i; String[] pair; for (i = 0; i < coinlist.length; i++) { pair = coinlist[i].split("="); if ((pair.length >= 2) && (pair[0].trim().equalsIgnoreCase("rft.au"))) { strlst.add(standardizeAuthorName(pair[1])); } } dr.authList = strlst; StringBuilder sb = new StringBuilder("<a href=\""); sb.append(jsonobj.get("doi").getAsString()); sb.append("\" target=\"_blank\">"); sb.append(jsonobj.get("fullCitation").getAsString()); sb.append("</a>"); dr.citation = sb.toString(); // Adding "year" field verification; it may come as null // (translated by Gson as a JsonNull field) JsonElement year = jsonobj.get("year"); if (year == null || year.isJsonNull()) { dr.year = "N/A"; } else { dr.year = year.getAsString(); } return dr; }
From source file:org.dmu.expertiserecognition.Geocode.java
private GeoCoord extractGeocoordFromDataScienceToolkit(String jsonresp, String loc) throws Exception { GeoCoord gcd = new GeoCoord(loc); JsonElement json = new JsonParser().parse(jsonresp); JsonObject mainj = json.getAsJsonObject(); if (mainj.get("status").getAsString().equals("OK") == false) return gcd; JsonArray res = mainj.get("results").getAsJsonArray(); Iterator<JsonElement> iter = res.iterator(); if (iter.hasNext() == false) return gcd; JsonObject geom = iter.next().getAsJsonObject().get("geometry").getAsJsonObject(); JsonObject locg = geom.get("location").getAsJsonObject(); gcd.latd = locg.get("lat").getAsString(); gcd.longd = locg.get("lng").getAsString(); return gcd;//from w ww. j a va 2s. c o m }
From source file:org.dmu.expertiserecognition.ResultsInfo.java
private ArrayList<Entry> extractEntries(JsonArray jsonArr) throws Exception { Iterator<JsonElement> iter = jsonArr.iterator(); JsonObject jsonEntry;// w w w . j av a 2 s. c o m ArrayList<Entry> entries1 = new ArrayList<>(); while (iter.hasNext()) { jsonEntry = iter.next().getAsJsonObject(); entries1.add(extractEntry(jsonEntry)); } return entries1; }
From source file:org.dmu.expertiserecognition.ResultsInfo.java
private Entry extractEntry(JsonObject jsonEntry) throws Exception { Entry entry = new Entry(); if (checkJsonElement(jsonEntry.get("dc:title"))) entry.title = jsonEntry.get("dc:title").getAsString(); String creator = ""; if (checkJsonElement(jsonEntry.get("dc:creator"))) creator = jsonEntry.get("dc:creator").getAsString(); if (checkJsonElement(jsonEntry.get("prism:publicationName"))) entry.publicationName = jsonEntry.get("prism:publicationName").getAsString(); if (checkJsonElement(jsonEntry.get("prism:issn"))) entry.issn = jsonEntry.get("prism:issn").getAsString(); if (checkJsonElement(jsonEntry.get("prism:doi"))) entry.doi = jsonEntry.get("prism:doi").getAsString(); if (checkJsonElement(jsonEntry.get("prism:coverDate"))) { entry.year = jsonEntry.get("prism:coverDate").getAsString().substring(0, 4); }//w w w .ja v a 2s .c om JsonArray jsonAffils = new JsonArray(); if (checkJsonElement(jsonEntry.get("citedby-count"))) entry.citedby = jsonEntry.get("citedby-count").getAsInt(); if (checkJsonElement(jsonEntry.get("affiliation"))) jsonAffils = jsonEntry.get("affiliation").getAsJsonArray(); Iterator<JsonElement> iter = jsonAffils.iterator(); JsonObject jsonAffil; Affil aff; while (iter.hasNext()) { aff = new Affil(); jsonAffil = iter.next().getAsJsonObject(); if (checkJsonElement(jsonAffil.get("affilname"))) aff.affilName = jsonAffil.get("affilname").getAsString(); if (checkJsonElement(jsonAffil.get("affiliation-city"))) aff.affilCity = jsonAffil.get("affiliation-city").getAsString(); if (checkJsonElement(jsonAffil.get("affiliation-country"))) aff.affilCountry = jsonAffil.get("affiliation-country").getAsString(); entry.affils.add(aff); } doiResults dr = dfal.getAuthorListFromDoi(entry.doi, creator); entry.authors = dr.authList; entry.citation = dr.citation; if ((entry.doi != null) && (entry.doi.isEmpty() == false)) entry.year = dr.year; entry.sjr = JournalRankDB.getInstance().querySJR(entry.title, entry.issn); entry.impactFactor = JournalRankDB.getInstance().queryIF(entry.title, entry.issn); entry.h5index = JournalRankDB.getInstance().queryGSC(entry.title, entry.issn); entry.eigenFactor = 1000 * JournalRankDB.getInstance().queryEF(entry.title, entry.issn); return entry; }
From source file:org.eclipse.dirigible.ide.template.ui.db.service.DatabaseGenerationWorker.java
License:Open Source License
protected void setParametersToModel(JsonObject parametersObject, DataStructureTemplateModel model, TemplateType[] templates) throws GenerationException { // template type if (parametersObject.has(PARAM_TEMPLATE_TYPE)) { String templateType = parametersObject.get(PARAM_TEMPLATE_TYPE).getAsString(); for (TemplateType template : templates) { if (template.getLocation() .substring(DataStructureTemplateTypeDiscriminator.getTemplatesPath().length()) .indexOf(templateType + ICommonConstants.SEPARATOR) == 0) { model.setTemplate(template); break; }//from w ww . ja va 2s .co m } if (model.getTemplate() == null) { throw new GenerationException( String.format(TEMPLATE_S_DOES_NOT_EXIST_IN_THIS_INSTANCE, templateType)); } } else { throw new GenerationException( String.format(MANDATORY_PARAMETER_S_HAS_NOT_BEEN_PROVIDED, PARAM_TEMPLATE_TYPE)); } // file name if (parametersObject.has(PARAM_FILE_NAME)) { model.setFileName(parametersObject.get(PARAM_FILE_NAME).getAsString()); } else { throw new GenerationException( String.format(MANDATORY_PARAMETER_S_HAS_NOT_BEEN_PROVIDED, PARAM_FILE_NAME)); } // project name if (parametersObject.has(PARAM_PROJECT_NAME)) { String projectName = parametersObject.get(PARAM_PROJECT_NAME).getAsString(); IProject project = getWorkspace().getRoot().getProject(projectName); if (!project.exists()) { try { project.create(new LogProgressMonitor()); } catch (CoreException e) { throw new GenerationException(e); } } model.setTargetContainer(project.getFullPath().toString()); } else { throw new GenerationException( String.format(MANDATORY_PARAMETER_S_HAS_NOT_BEEN_PROVIDED, PARAM_PROJECT_NAME)); } // package name if (parametersObject.has(PARAM_PACKAGE_NAME)) { String packageName = parametersObject.get(PARAM_PACKAGE_NAME).getAsString(); model.setProjectPackageName( ICommonConstants.ARTIFACT_TYPE.DATA_STRUCTURES + IRepository.SEPARATOR + packageName); model.setPackageName(packageName); } else { throw new GenerationException( String.format(MANDATORY_PARAMETER_S_HAS_NOT_BEEN_PROVIDED, PARAM_PACKAGE_NAME)); } // columns if (parametersObject.has(PARAM_COLUMNS)) { List<ColumnDefinition> columnDefinitions = new ArrayList<ColumnDefinition>(); JsonArray columns = parametersObject.get(PARAM_COLUMNS).getAsJsonArray(); Iterator<JsonElement> iter = columns.iterator(); while (iter.hasNext()) { JsonElement columnElement = iter.next(); if (columnElement.isJsonObject()) { JsonObject columnObject = columnElement.getAsJsonObject(); ColumnDefinition columnDefinition = new ColumnDefinition(); columnDefinition.setName(columnObject.get(PARAM_COLUMN_NAME).getAsString()); columnDefinition.setType(columnObject.get(PARAM_COLUMN_TYPE).getAsString()); columnDefinition.setLength(columnObject.get(PARAM_COLUMN_LENGTH).getAsInt()); columnDefinition.setPrimaryKey(columnObject.get(PARAM_COLUMN_PRIMARY_KEY).getAsBoolean()); columnDefinition.setNotNull(columnObject.get(PARAM_COLUMN_NOT_NULL).getAsBoolean()); columnDefinition.setDefaultValue(columnObject.get(PARAM_COLUMN_DEFAULT_VALUE).getAsString()); columnDefinitions.add(columnDefinition); } } model.setColumnDefinitions(columnDefinitions.toArray(new ColumnDefinition[] {})); } else { checkIfRequired(model, PARAM_COLUMNS); } // query if (parametersObject.has(PARAM_QUERY)) { model.setQuery(parametersObject.get(PARAM_QUERY).getAsString()); } else { checkIfRequired(model, PARAM_QUERY); } // query if (parametersObject.has(PARAM_ROWS)) { String rows = parametersObject.get(PARAM_ROWS).getAsString(); model.setDsvSampleRows(rows.split((rows.indexOf("\n") >= 0) ? "\n" : "\r")); } else { checkIfRequired(model, PARAM_ROWS); } }
From source file:org.eclipse.dirigible.ide.template.ui.html.service.WebContentEntityGenerationWorker.java
License:Open Source License
protected void setParametersToModel(JsonObject parametersObject, HtmlForEntityTemplateModel model, TemplateType[] templates) throws GenerationException { // template type if (parametersObject.has(PARAM_TEMPLATE_TYPE)) { String templateType = parametersObject.get(PARAM_TEMPLATE_TYPE).getAsString(); for (TemplateType template : templates) { if (template.getLocation() .substring(WebContentEntityTemplateTypeDiscriminator.getTemplatesPath().length()) .indexOf(templateType + ICommonConstants.SEPARATOR) == 0) { model.setTemplate(template); break; }/* w ww .j a v a 2s . c o m*/ } if (model.getTemplate() == null) { throw new GenerationException( String.format(TEMPLATE_S_DOES_NOT_EXIST_IN_THIS_INSTANCE, templateType)); } } else { throw new GenerationException( String.format(MANDATORY_PARAMETER_S_HAS_NOT_BEEN_PROVIDED, PARAM_TEMPLATE_TYPE)); } // file name if (parametersObject.has(PARAM_FILE_NAME)) { model.setFileName(parametersObject.get(PARAM_FILE_NAME).getAsString()); } else { throw new GenerationException( String.format(MANDATORY_PARAMETER_S_HAS_NOT_BEEN_PROVIDED, PARAM_FILE_NAME)); } // project name if (parametersObject.has(PARAM_PROJECT_NAME)) { String projectName = parametersObject.get(PARAM_PROJECT_NAME).getAsString(); IProject project = getWorkspace().getRoot().getProject(projectName); if (!project.exists()) { try { project.create(new LogProgressMonitor()); } catch (CoreException e) { throw new GenerationException(e); } } model.setTargetContainer(project.getFullPath().toString()); } else { throw new GenerationException( String.format(MANDATORY_PARAMETER_S_HAS_NOT_BEEN_PROVIDED, PARAM_PROJECT_NAME)); } // package name if (parametersObject.has(PARAM_PACKAGE_NAME)) { String packageName = parametersObject.get(PARAM_PACKAGE_NAME).getAsString(); model.setProjectPackageName( ICommonConstants.ARTIFACT_TYPE.WEB_CONTENT + IRepository.SEPARATOR + packageName); model.setPackageName(packageName); } else { throw new GenerationException( String.format(MANDATORY_PARAMETER_S_HAS_NOT_BEEN_PROVIDED, PARAM_PACKAGE_NAME)); } // columns if (parametersObject.has(PARAM_COLUMNS)) { List<TableColumn> columnDefinitions = new ArrayList<TableColumn>(); JsonArray columns = parametersObject.get(PARAM_COLUMNS).getAsJsonArray(); Iterator<JsonElement> iter = columns.iterator(); while (iter.hasNext()) { JsonElement columnElement = iter.next(); if (columnElement.isJsonObject()) { JsonObject columnObject = columnElement.getAsJsonObject(); TableColumn columnDefinition = new TableColumn( columnObject.get(PARAM_COLUMN_NAME).getAsString(), columnObject.get(PARAM_COLUMN_PRIMARY_KEY).getAsBoolean(), columnObject.get(PARAM_COLUMN_VISIBLE).getAsBoolean(), columnObject.get(PARAM_COLUMN_TYPE).getAsString(), columnObject.get(PARAM_COLUMN_SIZE).getAsInt(), columnObject.get(PARAM_COLUMN_WIDGET_TYPE).getAsString(), columnObject.get(PARAM_COLUMN_LABEL).getAsString()); columnDefinitions.add(columnDefinition); } } model.setTableColumns(columnDefinitions.toArray(new TableColumn[] {})); } else { checkIfRequired(model, PARAM_COLUMNS); } // table name if (parametersObject.has(PARAM_TABLE_NAME)) { model.setTableName(parametersObject.get(PARAM_TABLE_NAME).getAsString()); } else { checkIfRequired(model, PARAM_TABLE_NAME); } // page title if (parametersObject.has(PARAM_PAGE_TITLE)) { model.setPageTitle(parametersObject.get(PARAM_PAGE_TITLE).getAsString()); } else { checkIfRequired(model, PARAM_PAGE_TITLE); } // service endpoint if (parametersObject.has(PARAM_SERVICE_ENDPOINT)) { model.setServiceEndpoint(parametersObject.get(PARAM_SERVICE_ENDPOINT).getAsString()); } else { checkIfRequired(model, PARAM_SERVICE_ENDPOINT); } }