List of usage examples for java.lang String subSequence
public CharSequence subSequence(int beginIndex, int endIndex)
From source file:pt.ist.socialsoftware.edition.export.ExpertEditionTEIExport.java
public String updateTeiHeader(String xml) { String header = ""; String result = ""; Resource resource = new ClassPathResource("teiCorpusHeader.xml"); try {/* w w w .j a va 2 s . co m*/ InputStream resourceInputStream = resource.getInputStream(); header = IOUtils.toString(resourceInputStream, "UTF-8"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } result = xml.subSequence(0, xml.indexOf("<teiHeader")) + header + "\n" + xml.substring(xml.indexOf("<TEI")); return result; }
From source file:org.pixmob.freemobile.netstat.MonitorService.java
/** * Check if we are connected on a Free Mobile femtocell *///from w ww . j ava 2 s . c o m @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) private void updateFemtocellStatus() { // No need to check LAC if current operator is not free mobile // And no need to check if network type is not femtocell supported network if ((!MobileOperator.FREE_MOBILE.equals(MobileOperator.fromString(mobileOperatorId))) || ((MobileOperator.FREE_MOBILE.equals(MobileOperator.fromString(mobileOperatorId))) && (!FEMTOCELL_AVAILABLE_NETWORK_TYPE.contains(mobileNetworkType)))) { isFemtocell = false; return; } Integer lac = null; if (tm != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { //get the cell list List<CellInfo> cellInfos = tm.getAllCellInfo(); if (cellInfos != null) { for (CellInfo cellInfo : cellInfos) { if (cellInfo.isRegistered()) { //we use only registered cells if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) && (cellInfo instanceof CellInfoWcdma)) { //manage the wcdma cell case Log.d(TAG, "We got a WCDMA cell"); CellIdentityWcdma ci = ((CellInfoWcdma) cellInfo).getCellIdentity(); if (ci != null) { //save the LAC and exit loop lac = ci.getLac(); Log.d(TAG, "We got the LAC - exit loop"); break; } } else if (cellInfo instanceof CellInfoGsm) { //test the gsm case CellIdentityGsm ci = ((CellInfoGsm) cellInfo).getCellIdentity(); Log.d(TAG, "We got a CDMA cell"); if (ci != null) { //save the LAC and exit loop lac = ci.getLac(); Log.d(TAG, "We got the LAC - exit loop"); break; } } } else Log.d(TAG, "Unregistered cell - skipping"); } } else Log.d(TAG, "No cell infos available"); } if (lac == null) { //use old API if LAC was not found with the new method (useful for buggy devices such as Samsung Galaxy S5) or if SDK is too old CellLocation cellLocation = tm.getCellLocation(); //cell location might be null... handle with care if ((cellLocation != null) && (cellLocation instanceof GsmCellLocation)) { Log.d(TAG, "We got a old GSM cell with LAC"); lac = ((GsmCellLocation) cellLocation).getLac(); } } } if (DEBUG) Log.d(TAG, "LAC value : " + lac); Log.i(TAG, "Femtocell value : " + isFemtocell); if (lac != null) { String lacAsString = String.valueOf(lac); isFemtocell = (lacAsString.length() == 4) && (lacAsString.subSequence(1, 3).equals(FREE_MOBILE_FEMTOCELL_LAC_CODE)); } }
From source file:org.kuali.test.runner.execution.TestWebClient.java
private void replaceJsessionId(WebRequest request) throws MalformedURLException { String urlString = request.getUrl().toExternalForm(); int pos = urlString.toLowerCase().indexOf(Constants.JSESSIONID_PARAMETER_NAME); if (pos > -1) { Cookie cookie = findJSessionIdCookie(request.getUrl()); if (cookie != null) { StringBuilder buf = new StringBuilder(urlString.length()); int pos2 = urlString.indexOf(Constants.SEPARATOR_QUESTION); buf.append(urlString.subSequence(0, pos)); buf.append(Constants.JSESSIONID_PARAMETER_NAME); buf.append(Constants.SEPARATOR_EQUALS); buf.append(cookie.getValue()); if (pos2 > -1) { buf.append(urlString.substring(pos2)); }// ww w . j a v a 2s. c o m request.setUrl(new URL(buf.toString())); } } }
From source file:org.wso2.carbon.dataservices.core.DBUtils.java
public static String evaluateString(String source, ExternalParamCollection params) throws DataServiceFault { StringBuilder builder = new StringBuilder(); /* http://www.product.fake/cd/{productCode} */ int leftBracketIndex = source.indexOf('{', 0); int rightBracketIndex = source.indexOf('}', leftBracketIndex); if (leftBracketIndex == -1 || rightBracketIndex == -1) { throw new DataServiceFault("The source string: " + source + " is not parameterized."); }/*from ww w . jav a2 s. co m*/ String paramName = source.substring(leftBracketIndex + 1, rightBracketIndex); /* workaround for different character case issues in column names */ paramName = paramName.toLowerCase(); ExternalParam exParam = params.getParam(paramName); if (exParam == null) { throw new DataServiceFault( "The parameter: " + paramName + " cannot be found for the source string: " + source); } String paramValue = exParam.getValue().getValueAsString(); builder.append(source.subSequence(0, leftBracketIndex)); builder.append(paramValue); builder.append(source.substring(rightBracketIndex + 1)); return builder.toString(); }
From source file:org.esa.nest.gpf.UndersamplingOp.java
/** * Update metadata in the target product. *///from w ww . j ava2s . co m private void updateTargetProductMetadata() { final MetadataElement absTgt = AbstractMetadata.getAbstractedMetadata(targetProduct); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.azimuth_spacing, azimuthSpacing); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.range_spacing, rangeSpacing); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.num_samples_per_line, targetImageWidth); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.num_output_lines, targetImageHeight); final float oldLineTimeInterval = (float) absTgt.getAttributeDouble(AbstractMetadata.line_time_interval); AbstractMetadata.setAttribute(absTgt, AbstractMetadata.line_time_interval, oldLineTimeInterval * (float) stepAzimuth); final String oldFirstLineTime = absTgt.getAttributeString(AbstractMetadata.first_line_time); final int idx = oldFirstLineTime.lastIndexOf(':') + 1; final String oldSecondsStr = oldFirstLineTime.substring(idx); final double oldSeconds = Double.parseDouble(oldSecondsStr); final double newSeconds = oldSeconds + oldLineTimeInterval * (filterHeight - 1) / 2.0; final String newFirstLineTime = String.valueOf(oldFirstLineTime.subSequence(0, idx)) + newSeconds + "000000"; AbstractMetadata.setAttribute(absTgt, AbstractMetadata.first_line_time, AbstractMetadata.parseUTC(newFirstLineTime.substring(0, 27))); // AbstractMetadata.parseUTC(newFirstLineTime.substring(0,27), "dd-MMM-yyyy HH:mm:ss")); }
From source file:edu.jhu.cvrg.ceptools.main.SearchPubs.java
public void convertStore(String fileinfo, Publication currlist) { int fname, fsize, ffigure, fpanel, fdescription = -1; String sname, ssize, sfigure, spanel, sdescription; sname = ssize = sfigure = spanel = sdescription = ""; fsize = fileinfo.indexOf("filesize:"); fdescription = fileinfo.indexOf(",filedescription:"); ffigure = fileinfo.indexOf(",filefigure:"); fpanel = fileinfo.indexOf(",filepanel:"); fname = fileinfo.indexOf(",filename:"); if (fsize != -1 && fdescription != -1) { ssize = (String) fileinfo.subSequence(fsize, fdescription); }//www . j a va2s . c o m if (ffigure != -1 && fdescription != -1) { sdescription = (String) fileinfo.subSequence(fdescription, ffigure); } if (ffigure != -1 && fpanel != -1) { sfigure = (String) fileinfo.subSequence(ffigure, fpanel); } if (fname != -1 && fpanel != -1) { spanel = (String) fileinfo.subSequence(fpanel, fname); } if (fname != -1) { sname = (String) fileinfo.subSequence(fname, fileinfo.length()); } ssize = ssize.replace("filesize:", ""); sname = sname.replace(",filename:", ""); sdescription = sdescription.replace(",filedescription:", ""); sfigure = sfigure.replace(",filefigure:", ""); spanel = spanel.replace(",filepanel:", ""); String fileloc = PropsUtil.get("data_store2") + pmid + "/"; FileStorer currfile = new FileStorer(); currfile.setDescription(sdescription); currfile.setFigure(sfigure); currfile.setFilesize(Long.valueOf(ssize)); currfile.setFilename(sname); currfile.setPanel(spanel); currfile.setIndex(solrindex); currfile.setFilelocation(fileloc); currfile.setLocalfilestore(fileloc); currlist.addFile(currfile); //filesfromsolr.add(currfile); solrindex++; }
From source file:us.mn.state.health.lims.analyzerimport.analyzerreaders.CobasC311Reader.java
private AnalyzerResults createAnalyzerResult(String analyzerTestName, String[] fields, int index, String accessionNumber, Timestamp orderTimeStamp) { if (fields.length <= index) { return null; }// w w w . j a va2s. co m String result = fields[index].trim(); if (GenericValidator.isBlankOrNull(result)) { return null; } AnalyzerResults analyzerResults = new AnalyzerResults(); MappedTestName mappedName = AnalyzerTestNameCache.instance().getMappedTest(AnalyzerTestNameCache.COBAS_C311, analyzerTestName); if (mappedName == null) { mappedName = AnalyzerTestNameCache.instance().getEmptyMappedTestName(AnalyzerTestNameCache.COBAS_C311, analyzerTestName); } analyzerResults.setAnalyzerId(mappedName.getAnalyzerId()); analyzerResults.setResult(adjustResult(analyzerTestName, result)); analyzerResults.setCompleteDate(orderTimeStamp); analyzerResults.setTestId(mappedName.getTestId()); analyzerResults.setIsControl( accessionNumber.length() < 9 || !VALID_PREFIXES.contains(accessionNumber.subSequence(0, 3))); analyzerResults.setTestName(mappedName.getOpenElisTestName()); analyzerResults.setResultType("N"); analyzerResults.setAccessionNumber(accessionNumber); return analyzerResults; }
From source file:CB_Core.Api.SearchForGeocaches_Core.java
String ParseJsonResult(Search search, CB_List<Cache> cacheList, ArrayList<LogEntry> logList, ArrayList<ImageEntry> imageList, long gpxFilenameId, String result, byte apiStatus, boolean isLite) { // Parse JSON Result try {/* ww w . j ava 2s . co m*/ JSONTokener tokener = new JSONTokener(result); JSONObject json = (JSONObject) tokener.nextValue(); JSONObject status = json.getJSONObject("Status"); if (status.getInt("StatusCode") == 0) { result = ""; JSONArray caches = json.getJSONArray("Geocaches"); // Log.debug(log, "got " + caches.length() + " Caches from gc"); for (int i = 0; i < caches.length(); i++) { JSONObject jCache = (JSONObject) caches.get(i); String gcCode = jCache.getString("Code"); // Log.debug(log, "handling " + gcCode); String name = jCache.getString("Name"); result += gcCode + " - " + name + "\n"; Boolean CacheERROR = false; Cache cache = new Cache(true); cache.setArchived(jCache.getBoolean("Archived")); cache.setAttributesPositive(new DLong(0, 0)); cache.setAttributesNegative(new DLong(0, 0)); JSONArray jAttributes = jCache.getJSONArray("Attributes"); for (int j = 0; j < jAttributes.length(); j++) { JSONObject jAttribute = jAttributes.getJSONObject(j); int AttributeTypeId = jAttribute.getInt("AttributeTypeID"); Boolean isOn = jAttribute.getBoolean("IsOn"); Attributes att = Attributes.getAttributeEnumByGcComId(AttributeTypeId); if (isOn) { cache.addAttributePositive(att); } else { cache.addAttributeNegative(att); } } cache.setAvailable(jCache.getBoolean("Available")); cache.setDateHidden(new Date()); try { String dateCreated = jCache.getString("DateCreated"); int date1 = dateCreated.indexOf("/Date("); int date2 = dateCreated.lastIndexOf("-"); String date = (String) dateCreated.subSequence(date1 + 6, date2); cache.setDateHidden(new Date(Long.valueOf(date))); } catch (Exception exc) { Log.err(log, "SearchForGeocaches_ParseDate", exc); } cache.setDifficulty((float) jCache.getDouble("Difficulty")); // Ein evtl. in der Datenbank vorhandenen "Found" nicht berschreiben Boolean Favorite = LoadBooleanValueFromDB( "select Favorit from Caches where GcCode = \"" + gcCode + "\""); cache.setFavorite(Favorite); // Ein evtl. in der Datenbank vorhandenen "Found" nicht berschreiben Boolean Found = LoadBooleanValueFromDB( "select found from Caches where GcCode = \"" + gcCode + "\""); if (!Found) { cache.setFound(jCache.getBoolean("HasbeenFoundbyUser")); } else { cache.setFound(true); } cache.setGcCode(jCache.getString("Code")); try { cache.setGcId(jCache.getString("ID")); } catch (Exception e) { // CacheERROR = true; gibt bei jedem Cache ein // Fehler ??? } cache.setGPXFilename_ID(gpxFilenameId); // Ein evtl. in der Datenbank vorhandenen "Found" nicht berschreiben Boolean userData = LoadBooleanValueFromDB( "select HasUserData from Caches where GcCode = \"" + gcCode + "\""); cache.setHasUserData(userData); if (!isLite) { try { cache.setHint(jCache.getString("EncodedHints")); } catch (Exception e1) { cache.setHint(""); } } cache.Id = Cache.GenerateCacheId(cache.getGcCode()); cache.setListingChanged(false); if (!isLite) { try { cache.setLongDescription(jCache.getString("LongDescription")); } catch (Exception e1) { Log.err(log, "SearchForGeocaches_LongDescription:" + cache.getGcCode(), e1); cache.setLongDescription(""); } if (!jCache.getBoolean("LongDescriptionIsHtml")) { cache.setLongDescription( cache.getLongDescription().replaceAll("(\r\n|\n\r|\r|\n)", "<br />")); } } cache.setName(jCache.getString("Name")); cache.setTourName(""); cache.setNoteChecksum(0); cache.NumTravelbugs = jCache.getInt("TrackableCount"); JSONObject jOwner = jCache.getJSONObject("Owner"); cache.setOwner(jOwner.getString("UserName")); cache.setPlacedBy(cache.getOwner()); try { cache.Pos = new CoordinateGPS(jCache.getDouble("Latitude"), jCache.getDouble("Longitude")); } catch (Exception e) { } cache.Rating = 0; if (!isLite) { try { cache.setShortDescription(jCache.getString("ShortDescription")); } catch (Exception e) { Log.err(log, "SearchForGeocaches_shortDescription:" + cache.getGcCode(), e); cache.setShortDescription(""); } if (!jCache.getBoolean("ShortDescriptionIsHtml")) { cache.setShortDescription( cache.getShortDescription().replaceAll("(\r\n|\n\r|\r|\n)", "<br />")); } } JSONObject jContainer = jCache.getJSONObject("ContainerType"); int jSize = jContainer.getInt("ContainerTypeId"); cache.Size = CacheSizes.parseInt(GroundspeakAPI.getCacheSize(jSize)); cache.setSolverChecksum(0); cache.setTerrain((float) jCache.getDouble("Terrain")); cache.Type = CacheTypes.Traditional; try { JSONObject jCacheType = jCache.getJSONObject("CacheType"); cache.Type = GroundspeakAPI.getCacheType(jCacheType.getInt("GeocacheTypeId")); } catch (Exception e) { if (gcCode.equals("GC4K089")) { cache.Type = CacheTypes.Giga; } else { cache.Type = CacheTypes.Undefined; } } cache.setUrl(jCache.getString("Url")); cache.setApiStatus(apiStatus); // Ein evtl. in der Datenbank vorhandenen "Favorit" nicht berschreiben Boolean fav = LoadBooleanValueFromDB( "select favorit from Caches where GcCode = \"" + gcCode + "\""); cache.setFavorite(fav); // Chk if Own or Found Boolean exclude = false; if (search.excludeFounds && cache.isFound()) exclude = true; if (search.excludeHides && cache.getOwner().equalsIgnoreCase(CB_Core_Settings.GcLogin.getValue())) exclude = true; if (search.available && (cache.isArchived() || !cache.isAvailable())) exclude = true; if (!CacheERROR && !exclude) { cacheList.add(cache); // insert Logs JSONArray logs = jCache.getJSONArray("GeocacheLogs"); for (int j = 0; j < logs.length(); j++) { JSONObject jLogs = (JSONObject) logs.get(j); JSONObject jFinder = (JSONObject) jLogs.get("Finder"); JSONObject jLogType = (JSONObject) jLogs.get("LogType"); LogEntry logEntry = new LogEntry(); logEntry.CacheId = cache.Id; logEntry.Comment = jLogs.getString("LogText"); logEntry.Finder = jFinder.getString("UserName"); logEntry.Id = jLogs.getInt("ID"); logEntry.Timestamp = new Date(); try { String dateCreated = jLogs.getString("VisitDate"); int date1 = dateCreated.indexOf("/Date("); int date2 = dateCreated.indexOf("-"); String date = (String) dateCreated.subSequence(date1 + 6, date2); logEntry.Timestamp = new Date(Long.valueOf(date)); } catch (Exception exc) { Log.err(log, "API", "SearchForGeocaches_ParseLogDate", exc); } logEntry.Type = LogTypes.GC2CB_LogType(jLogType.getInt("WptLogTypeId")); logList.add(logEntry); } // insert Images int imageListSizeOrg = imageList.size(); JSONArray images = jCache.getJSONArray("Images"); for (int j = 0; j < images.length(); j++) { JSONObject jImage = (JSONObject) images.get(j); ImageEntry image = new ImageEntry(); image.CacheId = cache.Id; image.GcCode = cache.getGcCode(); image.Name = jImage.getString("Name"); image.Description = jImage.getString("Description"); image.ImageUrl = jImage.getString("Url").replace("img.geocaching.com/gc/cache", "img.geocaching.com/cache"); // remove "/gc" to match the url used in the description image.IsCacheImage = true; imageList.add(image); } int imageListSizeGC = images.length(); // insert images from Cache description LinkedList<String> allImages = null; if (!search.isLite) allImages = DescriptionImageGrabber.GetAllImages(cache); int imageListSizeGrabbed = 0; if (allImages != null && allImages.size() > 0) { imageListSizeGrabbed = allImages.size(); } while (allImages != null && allImages.size() > 0) { String url; url = allImages.poll(); boolean found = false; for (ImageEntry im : imageList) { if (im.ImageUrl.equalsIgnoreCase(url)) { found = true; break; } } if (!found) { ImageEntry image = new ImageEntry(); image.CacheId = cache.Id; image.GcCode = cache.getGcCode(); image.Name = url.substring(url.lastIndexOf("/") + 1); image.Description = ""; image.ImageUrl = url; image.IsCacheImage = true; imageList.add(image); } } log.debug("Merged imageList has " + imageList.size() + " Entrys (" + imageListSizeOrg + "/" + imageListSizeGC + "/" + imageListSizeGrabbed + ")"); // insert Waypoints JSONArray waypoints = jCache.getJSONArray("AdditionalWaypoints"); for (int j = 0; j < waypoints.length(); j++) { JSONObject jWaypoints = (JSONObject) waypoints.get(j); Waypoint waypoint = new Waypoint(true); waypoint.CacheId = cache.Id; try { waypoint.Pos = new CoordinateGPS(jWaypoints.getDouble("Latitude"), jWaypoints.getDouble("Longitude")); } catch (Exception ex) { // no Coordinates -> Lat/Lon = 0/0 waypoint.Pos = new CoordinateGPS(0, 0); } waypoint.setTitle(jWaypoints.getString("Description")); waypoint.setDescription(jWaypoints.getString("Comment")); waypoint.Type = GroundspeakAPI.getCacheType(jWaypoints.getInt("WptTypeID")); waypoint.setGcCode(jWaypoints.getString("Code")); cache.waypoints.add(waypoint); } // User Waypoints - Corrected Coordinates of the Geocaching.com Website JSONArray userWaypoints = jCache.getJSONArray("UserWaypoints"); for (int j = 0; j < userWaypoints.length(); j++) { JSONObject jUserWaypoint = (JSONObject) userWaypoints.get(j); if (!jUserWaypoint.getString("Description").equals("Coordinate Override")) { continue; // only corrected Coordinate } Waypoint waypoint = new Waypoint(true); waypoint.CacheId = cache.Id; try { waypoint.Pos = new CoordinateGPS(jUserWaypoint.getDouble("Latitude"), jUserWaypoint.getDouble("Longitude")); } catch (Exception ex) { // no Coordinates -> Lat/Lon = 0/0 waypoint.Pos = new CoordinateGPS(0, 0); } waypoint.setTitle(jUserWaypoint.getString("Description")); waypoint.setDescription(jUserWaypoint.getString("Description")); waypoint.Type = CacheTypes.Final; waypoint.setGcCode("CO" + cache.getGcCode().substring(2, cache.getGcCode().length())); cache.waypoints.add(waypoint); } // Spoiler aktualisieren actualizeSpoilerOfActualCache(cache); } // Notes Object note = jCache.get("GeocacheNote"); if ((note != null) && (note instanceof String)) { String s = (String) note; System.out.println(s); cache.setTmpNote(s); } } GroundspeakAPI.checkCacheStatus(json, isLite); } else { result = "StatusCode = " + status.getInt("StatusCode") + "\n"; result += status.getString("StatusMessage") + "\n"; result += status.getString("ExceptionDetails"); } } catch (JSONException e) { Log.err(log, "SearchForGeocaches:ParserException: " + result, e); } catch (ClassCastException e) { Log.err(log, "SearchForGeocaches:ParserException: " + result, e); } return result; }
From source file:org.opentravel.schemacompiler.repository.RepositoryFileManager.java
/** * Returns the filename (without path information) of the repository meta-data file for the * specified library./*from w w w .j a v a2s . c om*/ * * @param libraryFilename * the filename of the OTM library * @return String */ protected String getLibraryMetadataFilename(String libraryFilename) { int dotIdx = libraryFilename.lastIndexOf('.'); String baseFilename = (dotIdx < 0) ? libraryFilename : libraryFilename.subSequence(0, dotIdx).toString(); return baseFilename + "-info.xml"; }
From source file:jp.zippyzip.web.ListServlet.java
void setBuilding(HttpServletRequest request, ParentChild data, SortedMap<String, Pref> prefs, SortedMap<String, City> cities) throws JSONException { LinkedList<ListItem> list = new LinkedList<ListItem>(); LinkedList<BreadCrumb> breadCrumbs = new LinkedList<BreadCrumb>(); String x0402 = ""; breadCrumbs.add(new BreadCrumb("prefs", PAGE_TITLE)); breadCrumbs.add(new BreadCrumb(null, "??")); request.setAttribute("breadCrumbs", breadCrumbs); request.setAttribute("br", ""); for (String json : data.getChildren()) { Zip zip = Zip.fromJson(json);//from ww w . j a v a 2s. co m if (!x0402.equals(zip.getX0402())) { x0402 = zip.getX0402(); list.add(new ListItem(null, "", "", prefs.get(x0402.subSequence(0, 2)).getName() + "" + cities.get(x0402).getName(), "", "")); } int sep = zip.getAdd1().indexOf(" "); String add1 = (sep < 0) ? "" : zip.getAdd1().substring(0, sep); String name = zip.getAdd1().substring(sep + 1); sep = zip.getAdd1Yomi().indexOf(" "); list.add(new ListItem(zip.getX0402() + "-" + toHex(add1 + name), null, null, name, zip.getAdd1Yomi().substring(sep + 1), null)); } request.setAttribute("list", list); request.setAttribute("timestamp", data.getTimestamp()); }