List of usage examples for java.util Vector toArray
@SuppressWarnings("unchecked") public synchronized <T> T[] toArray(T[] a)
From source file:com.example.bdcoe.sunshine.FetchWeatherTask.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us.//from w ww . j a v a2s.c om */ private String[] getWeatherDataFromJson(String forecastJsonStr, int numDays, String locationSetting) throws JSONException { // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; final String OWM_COORD_LAT = "lat"; final String OWM_COORD_LONG = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_DATETIME = "dt"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject coordJSON = cityJson.getJSONObject(OWM_COORD); double cityLatitude = coordJSON.getLong(OWM_COORD_LAT); double cityLongitude = coordJSON.getLong(OWM_COORD_LONG); Log.v(LOG_TAG, cityName + ", with coord: " + cityLatitude + " " + cityLongitude); // Insert the location into the database. // The function referenced here is not yet implemented, so we've commented it out for now. long locationID = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Get and insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); String[] resultStrs = new String[numDays]; for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // The date/time is returned as a long. We need to convert that // into something human-readable, since most people won't read "1400356800" as // "this saturday". dateTime = dayForecast.getLong(OWM_DATETIME); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_LOC_KEY, locationID); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DATETEXT, WeatherContract.getDbDateString(new Date(dateTime * 1000L))); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); String highAndLow = formatHighLows(high, low); String day = getReadableDateString(dateTime); resultStrs[i] = day + " - " + description + " - " + highAndLow; } if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); int rowsInserted = mContext.getContentResolver().bulkInsert(WeatherContract.WeatherEntry.CONTENT_URI, cvArray); Log.v(LOG_TAG, "inserted " + rowsInserted + " rows of weather data"); } return resultStrs; }
From source file:de.juwimm.cms.remote.UserServiceSpringImpl.java
@Override protected UserUnitsGroupsValue[] handleGetUserUnitsGroups4UnitAndGroup(Integer unitId, Integer groupId) throws Exception { Vector<UserUnitsGroupsValue> vec = new Vector<UserUnitsGroupsValue>(); try {//w ww . j a v a 2s .co m ArrayList<UserHbm> userList = new ArrayList<UserHbm>(); UserHbm userLogged = super.getUserHbmDao().load(AuthenticationHelper.getUserName()); if (!isUserInRole(userLogged.getUserId(), this.getActiveSiteId(), UserRights.SITE_ROOT)) { if (isUserInRole(userLogged.getUserId(), this.getActiveSiteId(), UserRights.UNIT_ADMIN)) { Iterator unitsIt = userLogged.getUnits().iterator(); while (unitsIt.hasNext()) { UnitHbm unit = (UnitHbm) unitsIt.next(); Collection users = unit.getUsers(); Iterator<UserHbm> userIt = users.iterator(); while (userIt.hasNext()) { UserHbm current = userIt.next(); //not allowed to see user in higher roles than himself if (!isUserInRole(current.getUserId(), this.getActiveSiteId(), UserRights.SITE_ROOT)) { userList.add(current); } } } } } else { if (unitId != null && unitId.intValue() > 0 && groupId != null && groupId.intValue() > 0) { userList.addAll(super.getUserHbmDao().findAll4UnitAndGroup(unitId, groupId)); } else if (unitId != null && unitId.intValue() > 0) { userList.addAll(super.getUserHbmDao().findAll4Unit(unitId)); } else if (groupId != null && groupId.intValue() > 0) { userList.addAll(super.getUserHbmDao().findAll4Group(groupId)); } else { userList.addAll(super.getUserHbmDao().findAll(this.getActiveSiteId())); } } Iterator<UserHbm> it = userList.iterator(); while (it.hasNext()) { UserHbm user = it.next(); vec.add(getUserHbmDao().getUserUnitsGroupsValue(user)); // vec.add(user.getUserUnitsGroupsValue()); } } catch (Exception e) { throw new UserException(e.getMessage(), e); } return vec.toArray(new UserUnitsGroupsValue[0]); }
From source file:trendanalisis.main.tools.weka.CoreWekaTFIDF.java
/** * Gets the current settings of the filter. * //w w w .j a va2s. c o m * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> result = new Vector<String>(); result.add("-R"); result.add(getSelectedRange().getRanges()); if (getInvertSelection()) { result.add("-V"); } if (!"".equals(getAttributeNamePrefix())) { result.add("-P"); result.add(getAttributeNamePrefix()); } result.add("-W"); result.add(String.valueOf(getWordsToKeep())); result.add("-prune-rate"); result.add(String.valueOf(getPeriodicPruning())); if (getOutputWordCounts()) { result.add("-C"); } if (getTFTransform()) { result.add("-T"); } if (getIDFTransform()) { result.add("-I"); } result.add("-N"); result.add("" + m_filterType); if (getLowerCaseTokens()) { result.add("-L"); } if (getStemmer() != null) { result.add("-stemmer"); String spec = getStemmer().getClass().getName(); if (getStemmer() instanceof OptionHandler) { spec += " " + Utils.joinOptions(((OptionHandler) getStemmer()).getOptions()); } result.add(spec.trim()); } if (getStopwordsHandler() != null) { result.add("-stopwords-handler"); String spec = getStopwordsHandler().getClass().getName(); if (getStopwordsHandler() instanceof OptionHandler) { spec += " " + Utils.joinOptions(((OptionHandler) getStopwordsHandler()).getOptions()); } result.add(spec.trim()); } result.add("-M"); result.add(String.valueOf(getMinTermFreq())); if (getDoNotOperateOnPerClassBasis()) { result.add("-O"); } result.add("-tokenizer"); String spec = getTokenizer().getClass().getName(); if (getTokenizer() instanceof OptionHandler) { spec += " " + Utils.joinOptions(((OptionHandler) getTokenizer()).getOptions()); } result.add(spec.trim()); return result.toArray(new String[result.size()]); }
From source file:de.mpg.mpdl.inge.pubman.web.easySubmission.EasySubmission.java
/** * Handles the import from an external ingestion sources. * //from www .j ava2 s .c o m * @return navigation String */ public String harvestData() { FileVO fileVO = new FileVO(); Vector<FileVO> fileVOs = new Vector<FileVO>(); String fetchedItem = null; String service = this.getEasySubmissionSessionBean().getCurrentExternalServiceType(); PubItemVO itemVO = null; byte[] fetchedItemByte = null; DataHandlerBean dataHandler = new DataHandlerBean(); // Fetch data from external system if (EasySubmissionSessionBean.IMPORT_METHOD_EXTERNAL .equals(this.getEasySubmissionSessionBean().getImportMethod())) { if (getServiceID() == null || "".equals(getServiceID())) { warn(getMessage("easy_submission_external_service_no_id")); return null; } try { // Harvest metadata logger.debug("HarvestData: " + this.getEasySubmissionSessionBean().getCurrentExternalServiceType() + ": " + getServiceID()); fetchedItemByte = dataHandler.doFetch(service, getServiceID(), this.INTERNAL_MD_FORMAT); fetchedItem = new String(fetchedItemByte, 0, fetchedItemByte.length, "UTF8"); // Harvest full text if (this.getEasySubmissionSessionBean().isFulltext() && ((!this.getEasySubmissionSessionBean() .getRadioSelectFulltext().equals(this.getEasySubmissionSessionBean().FULLTEXT_NONE)) && !fetchedItem.equals("")) && !service.equalsIgnoreCase("escidoc")) { DataSourceVO source = this.dataSourceHandler.getSourceByName(service); Vector<FullTextVO> ftFormats = source.getFtFormats(); FullTextVO fulltext = new FullTextVO(); Vector<String> formats = new Vector<String>(); // Get DEFAULT full text version from source if (this.getEasySubmissionSessionBean().getRadioSelectFulltext() .equals(this.getEasySubmissionSessionBean().FULLTEXT_DEFAULT)) { for (int x = 0; x < ftFormats.size(); x++) { fulltext = ftFormats.get(x); if (fulltext.isFtDefault()) { formats.add(fulltext.getName()); break; } } } // Get ALL full text versions from source if (this.getEasySubmissionSessionBean().getRadioSelectFulltext() .equals(this.getEasySubmissionSessionBean().FULLTEXT_ALL)) { for (int x = 0; x < ftFormats.size(); x++) { fulltext = ftFormats.get(x); formats.add(fulltext.getName()); } } String[] arrFormats = new String[formats.size()]; byte[] ba = dataHandler.doFetch( this.getEasySubmissionSessionBean().getCurrentExternalServiceType(), getServiceID(), formats.toArray(arrFormats)); LoginHelper loginHelper = (LoginHelper) this.getBean(LoginHelper.class); ByteArrayInputStream in = new ByteArrayInputStream(ba); URL fileURL = this.uploadFile(in, dataHandler.getContentType(), loginHelper.getESciDocUserHandle()); if (fileURL != null && !fileURL.toString().trim().equals("")) { fileVO = dataHandler.getComponentVO(); MdsFileVO fileMd = fileVO.getDefaultMetadata(); fileVO.setStorage(FileVO.Storage.INTERNAL_MANAGED); fileVO.setVisibility(dataHandler.getVisibility()); fileVO.setDefaultMetadata(fileMd); fileVO.getDefaultMetadata() .setTitle(this.replaceSlashes(getServiceID().trim() + dataHandler.getFileEnding())); fileVO.setMimeType(dataHandler.getContentType()); fileVO.setName(this.replaceSlashes(getServiceID().trim() + dataHandler.getFileEnding())); FormatVO formatVO = new FormatVO(); formatVO.setType("dcterms:IMT"); formatVO.setValue(dataHandler.getContentType()); fileVO.getDefaultMetadata().getFormats().add(formatVO); fileVO.setContent(fileURL.toString()); fileVO.getDefaultMetadata().setSize(ba.length); fileVO.getDefaultMetadata().setDescription( "File downloaded from " + service + " at " + CommonUtils.currentDate()); fileVO.setContentCategory(dataHandler.getContentCategory()); fileVOs.add(fileVO); } } } catch (AccessException inre) { logger.error("Error fetching from external import source", inre); error(getMessage("easy_submission_import_from_external_service_access_denied_error") + getServiceID()); return null; } catch (IdentifierNotRecognisedException inre) { logger.error("Error fetching from external import source", inre); error(getMessage("easy_submission_import_from_external_service_identifier_error") + getServiceID()); return null; } catch (SourceNotAvailableException anae) { logger.error("Import source currently not available", anae); long millis = anae.getRetryAfter().getTime() - (new Date()).getTime(); if (millis < 1) { millis = 1; } error(getMessage("easy_submission_external_source_not_available_error").replace("$1", Math.ceil(millis / 1000) + "")); return null; } catch (FormatNotAvailableException e) { error(getMessage("formatNotAvailable_FromFetchingSource").replace("$1", e.getMessage()) .replace("$2", service)); this.getEasySubmissionSessionBean() .setRadioSelectFulltext(this.getEasySubmissionSessionBean().FULLTEXT_NONE); } catch (Exception e) { logger.error("Error fetching from external import source", e); error(getMessage("easy_submission_import_from_external_service_error")); return null; } // Generate item ValueObject if (fetchedItem != null && !fetchedItem.trim().equals("")) { try { itemVO = this.xmlTransforming.transformToPubItem(fetchedItem); // Upload fulltexts from other escidoc repositories to current repository if (this.getEasySubmissionSessionBean().isFulltext() && this.getEasySubmissionSessionBean().getRadioSelectFulltext() != null && this.getEasySubmissionSessionBean().getRadioSelectFulltext() .equals(this.getEasySubmissionSessionBean().FULLTEXT_ALL) && service.equalsIgnoreCase("escidoc")) { boolean hasFile = false; List<FileVO> fetchedFileList = itemVO.getFiles(); for (int i = 0; i < fetchedFileList.size(); i++) { FileVO file = fetchedFileList.get(i); if (file.getStorage().equals(FileVO.Storage.INTERNAL_MANAGED)) { try { FileVO newFile = new FileVO(); byte[] content = dataHandler.retrieveComponentContent(this.getServiceID(), file.getContent()); LoginHelper loginHelper = (LoginHelper) this.getBean(LoginHelper.class); ByteArrayInputStream in = new ByteArrayInputStream(content); URL fileURL; fileURL = this.uploadFile(in, dataHandler.getContentType(), loginHelper.getESciDocUserHandle()); if (fileURL != null && !fileURL.toString().trim().equals("") && file.getVisibility().equals(FileVO.Visibility.PUBLIC)) { hasFile = true; newFile.setStorage(FileVO.Storage.INTERNAL_MANAGED); newFile.setVisibility(file.getVisibility()); newFile.setDefaultMetadata(new MdsFileVO()); newFile.getDefaultMetadata().setTitle( this.replaceSlashes(file.getDefaultMetadata().getTitle())); newFile.setMimeType(file.getMimeType()); newFile.setName(this.replaceSlashes(file.getName())); FormatVO formatVO = new FormatVO(); formatVO.setType("dcterms:IMT"); formatVO.setValue(file.getMimeType()); newFile.getDefaultMetadata().getFormats().add(formatVO); newFile.setContent(fileURL.toString()); newFile.getDefaultMetadata().setSize(content.length); if (file.getDescription() != null) { newFile.getDefaultMetadata() .setDescription(file.getDescription() + " File downloaded from " + service + " at " + CommonUtils.currentDate()); } else { newFile.getDefaultMetadata().setDescription("File downloaded from " + service + " at " + CommonUtils.currentDate()); } newFile.setContentCategory(file.getContentCategory()); fileVOs.add(newFile); } } catch (Exception e) { logger.error("Error fetching file from coreservice", e); } } else if (file.getStorage().equals(FileVO.Storage.EXTERNAL_URL) && file.getVisibility().equals(FileVO.Visibility.PUBLIC)) { // Locator is just added as is fileVOs.add(file); } } if (!hasFile) { info(getMessage("easy_submission_import_from_external_service_identifier_info")); } } itemVO.getFiles().clear(); itemVO.setContext(getItem().getContext()); if (dataHandler.getItemUrl() != null) { IdentifierVO id = new IdentifierVO(); id.setType(IdType.URI); try { id.setId(java.net.URLDecoder.decode(dataHandler.getItemUrl().toString(), "UTF-8")); itemVO.getMetadata().getIdentifiers().add(id); } catch (UnsupportedEncodingException e) { logger.warn("Item URL could not be decoded"); } } if (this.getEasySubmissionSessionBean().isFulltext() && !this.getEasySubmissionSessionBean() .getRadioSelectFulltext().equals(this.getEasySubmissionSessionBean().FULLTEXT_NONE)) { for (int i = 0; i < fileVOs.size(); i++) { FileVO tmp = fileVOs.get(i); itemVO.getFiles().add(tmp); } fileVOs.clear(); } this.getItemControllerSessionBean().getCurrentPubItem().setMetadata(itemVO.getMetadata()); this.getItemControllerSessionBean().getCurrentPubItem().getFiles().clear(); this.getItemControllerSessionBean().getCurrentPubItem().getFiles().addAll(itemVO.getFiles()); // Reset info for next call // this.setImportSourcesInfo(); Commented out because of browser back button problem. this.setBibTexInfo(); } catch (TechnicalException e) { logger.warn("Error transforming item to pubItem."); error(getMessage("easy_submission_import_from_external_service_error")); return null; } } else { logger.warn("Empty fetched Item."); error(getMessage("easy_submission_import_from_external_service_error")); return null; } } // Fetch data from provided file else if (EasySubmissionSessionBean.IMPORT_METHOD_BIBTEX .equals(this.getEasySubmissionSessionBean().getImportMethod())) { String uploadResult = uploadBibtexFile(); if (uploadResult == null) { return null; } } this.getEditItemSessionBean().clean(); return "loadEditItem"; }
From source file:com.jll.sunshine.FetchWeatherTask.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us./*from w w w . j a v a 2 s .c o m*/ */ private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting) throws JSONException { // Now we have a String representing the complete forecast in JSON Format. // Fortunately parsing is easy: constructor takes the JSON string and converts it // into an Object hierarchy for us. // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; // Location coordinate final String OWM_LATITUDE = "lat"; final String OWM_LONGITUDE = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; try { JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD); double cityLatitude = cityCoord.getDouble(OWM_LATITUDE); double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE); long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); // OWM returns daily forecasts based upon the local time of the city that is being // asked for, which means that we need to know the GMT offset to translate this data // properly. // Since this data is also sent in-order and the first day is always the // current day, we're going to take advantage of that to get a nice // normalized UTC date for all of our weather. Time dayTime = new Time(); dayTime.setToNow(); // we start at the day returned by local time. Otherwise this is a mess. int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); // now we work exclusively in UTC dayTime = new Time(); for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // Cheating to convert this to UTC time, which is what we want anyhow dateTime = dayTime.setJulianDay(julianStartDay + i); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationId); weatherValues.put(WeatherEntry.COLUMN_DATE, dateTime); weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } // add to database if (cVVector.size() > 0) { ContentValues[] contents = new ContentValues[cVVector.size()]; cVVector.toArray(contents); mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, contents); } } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:de.mpg.escidoc.pubman.easySubmission.EasySubmission.java
/** * Fill import source values dynamically from importsourceHandler *//* ww w . j a va 2 s . co m*/ private void setImportSourcesInfo() { try { this.dataSources = this.dataSourceHandler.getSources(this.INTERNAL_MD_FORMAT); Vector<SelectItem> v_serviceOptions = new Vector<SelectItem>(); Vector<FullTextVO> ftFormats = new Vector<FullTextVO>(); String currentSource = ""; for (int i = 0; i < this.dataSources.size(); i++) { DataSourceVO source = (DataSourceVO) this.dataSources.get(i); v_serviceOptions.add(new SelectItem(source.getName())); this.getEasySubmissionSessionBean().setCurrentExternalServiceType(source.getName()); currentSource = source.getName(); // Get full text informations from this source ftFormats = source.getFtFormats(); for (int x = 0; x < ftFormats.size(); x++) { this.getEasySubmissionSessionBean().setFulltext(true); FullTextVO ft = ftFormats.get(x); if (ft.isFtDefault()) { this.getEasySubmissionSessionBean().setCurrentFTLabel(ft.getFtLabel()); this.getEasySubmissionSessionBean() .setRadioSelectFulltext(this.getEasySubmissionSessionBean().FULLTEXT_DEFAULT); } } if (ftFormats.size() <= 0) { this.getEasySubmissionSessionBean().setFulltext(false); this.getEasySubmissionSessionBean().setCurrentFTLabel(""); } } this.EXTERNAL_SERVICE_OPTIONS = new SelectItem[v_serviceOptions.size()]; v_serviceOptions.toArray(this.EXTERNAL_SERVICE_OPTIONS); this.getEasySubmissionSessionBean().setEXTERNAL_SERVICE_OPTIONS(this.EXTERNAL_SERVICE_OPTIONS); if (currentSource.toLowerCase().equals("escidoc")) { this.getEasySubmissionSessionBean() .setFULLTEXT_OPTIONS(new SelectItem[] { new SelectItem(this.getEasySubmissionSessionBean().FULLTEXT_ALL, getLabel("easy_submission_lblFulltext_all")), new SelectItem(this.getEasySubmissionSessionBean().FULLTEXT_NONE, getLabel("easy_submission_lblFulltext_none")) }); this.getEasySubmissionSessionBean() .setRadioSelectFulltext(this.getEasySubmissionSessionBean().FULLTEXT_ALL); } else { if (ftFormats.size() > 1) { this.getEasySubmissionSessionBean() .setFULLTEXT_OPTIONS(new SelectItem[] { new SelectItem(this.getEasySubmissionSessionBean().FULLTEXT_DEFAULT, this.getEasySubmissionSessionBean().getCurrentFTLabel()), new SelectItem(this.getEasySubmissionSessionBean().FULLTEXT_ALL, getLabel("easy_submission_lblFulltext_all")), new SelectItem(this.getEasySubmissionSessionBean().FULLTEXT_NONE, getLabel("easy_submission_lblFulltext_none")) }); } else this.getEasySubmissionSessionBean() .setFULLTEXT_OPTIONS(new SelectItem[] { new SelectItem(this.getEasySubmissionSessionBean().FULLTEXT_DEFAULT, this.getEasySubmissionSessionBean().getCurrentFTLabel()), new SelectItem(this.getEasySubmissionSessionBean().FULLTEXT_NONE, getLabel("easy_submission_lblFulltext_none")) }); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.msrproduction.sunshine.app.FetchWeatherTask.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us./*from ww w .j a v a 2 s . co m*/ */ private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting) throws JSONException { // Now we have a String representing the complete forecast in JSON Format. // Fortunately parsing is easy: constructor takes the JSON string and converts it // into an Object hierarchy for us. // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; // Location coordinate final String OWM_LATITUDE = "lat"; final String OWM_LONGITUDE = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; try { JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD); double cityLatitude = cityCoord.getDouble(OWM_LATITUDE); double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE); long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); // OWM returns daily forecasts based upon the local time of the city that is being // asked for, which means that we need to know the GMT offset to translate this data // properly. // Since this data is also sent in-order and the first day is always the // current day, we're going to take advantage of that to get a nice // normalized UTC date for all of our weather. Time dayTime = new Time(); dayTime.setToNow(); // we start at the day returned by local time. Otherwise this is a mess. int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); // now we work exclusively in UTC dayTime = new Time(); for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // Cheating to convert this to UTC time, which is what we want anyhow dateTime = dayTime.setJulianDay(julianStartDay + i); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationId); weatherValues.put(WeatherEntry.COLUMN_DATE, dateTime); weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } int inserted = 0; // add to database if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray); } Log.d(LOG_TAG, "FetchWeatherTask Complete. " + inserted + " Inserted"); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:com.example.jz.mysunshine.FetchWeatherTask.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * <p/>//from ww w .j a v a2 s .c o m * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us. */ private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting) throws JSONException { // Now we have a String representing the complete forecast in JSON Format. // Fortunately parsing is easy: constructor takes the JSON string and converts it // into an Object hierarchy for us. // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; // Location coordinate final String OWM_LATITUDE = "lat"; final String OWM_LONGITUDE = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; try { JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD); double cityLatitude = cityCoord.getDouble(OWM_LATITUDE); double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE); long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); // OWM returns daily forecasts based upon the local time of the city that is being // asked for, which means that we need to know the GMT offset to translate this data // properly. // Since this data is also sent in-order and the first day is always the // current day, we're going to take advantage of that to get a nice // normalized UTC date for all of our weather. Time dayTime = new Time(); dayTime.setToNow(); // we start at the day returned by local time. Otherwise this is a mess. int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); // now we work exclusively in UTC dayTime = new Time(); for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // Cheating to convert this to UTC time, which is what we want anyhow dateTime = dayTime.setJulianDay(julianStartDay + i); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationId); weatherValues.put(WeatherEntry.COLUMN_DATE, dateTime); weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } int inserted = 0; // add to database if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray); } Log.d(LOG_TAG, "FetchWeatherTask Complete. " + inserted + "Inserted"); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:app.com.example.android.sunshine.FetchWeatherTask.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * <p/>//from w w w . j ava 2s .c om * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us. */ private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting) throws JSONException { // Now we have a String representing the complete forecast in JSON Format. // Fortunately parsing is easy: constructor takes the JSON string and converts it // into an Object hierarchy for us. // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; // Location coordinate final String OWM_LATITUDE = "lat"; final String OWM_LONGITUDE = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; try { JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD); double cityLatitude = cityCoord.getDouble(OWM_LATITUDE); double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE); long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); // OWM returns daily forecasts based upon the local time of the city that is being // asked for, which means that we need to know the GMT offset to translate this data // properly. // Since this data is also sent in-order and the first day is always the // current day, we're going to take advantage of that to get a nice // normalized UTC date for all of our weather. Time dayTime = new Time(); dayTime.setToNow(); // we start at the day returned by local time. Otherwise this is a mess. int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); // now we work exclusively in UTC dayTime = new Time(); for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // Cheating to convert this to UTC time, which is what we want anyhow dateTime = dayTime.setJulianDay(julianStartDay + i); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationId); weatherValues.put(WeatherEntry.COLUMN_DATE, dateTime); weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } int inserted = 0; // add to database if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); // Student: call bulkInsert to add the weatherEntries to the database here inserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray); } Log.d(LOG_TAG, "FetchWeatherTask Complete. " + cVVector.size() + "Inserted"); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } //return null; }
From source file:com.example.android.sunshine.app.FetchWeatherTask_old.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us./*from w w w . j a v a 2s. c om*/ */ private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting) throws JSONException { // Now we have a String representing the complete forecast in JSON Format. // Fortunately parsing is easy: constructor takes the JSON string and converts it // into an Object hierarchy for us. // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; // Location coordinate final String OWM_LATITUDE = "lat"; final String OWM_LONGITUDE = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "src/main/temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; try { JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD); double cityLatitude = cityCoord.getDouble(OWM_LATITUDE); double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE); long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); // OWM returns daily forecasts based upon the local time of the city that is being // asked for, which means that we need to know the GMT offset to translate this data // properly. // Since this data is also sent in-order and the first day is always the // current day, we're going to take advantage of that to get a nice // normalized UTC date for all of our weather. Time dayTime = new Time(); dayTime.setToNow(); // we start at the day returned by local time. Otherwise this is a mess. int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); // now we work exclusively in UTC dayTime = new Time(); for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // Cheating to convert this to UTC time, which is what we want anyhow dateTime = dayTime.setJulianDay(julianStartDay + i); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationId); weatherValues.put(WeatherEntry.COLUMN_DATE, dateTime); weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } int inserted = 0; // add to database if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray); } Log.d(LOG_TAG, "FetchWeatherTask_old Complete. " + inserted + " Inserted"); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }