List of usage examples for java.lang String replaceFirst
public String replaceFirst(String regex, String replacement)
From source file:com.meltmedia.cadmium.servlets.ApiEndpointAccessFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try {//from ww w. jav a 2 s .co m String pathRequested = ((HttpServletRequest) request).getRequestURI(); if (pathRequested.startsWith(prefix)) { pathRequested = pathRequested.replaceFirst(Pattern.quote(prefix), "").replaceFirst("/$", ""); for (String disabled : controller.getDisabled()) { if (disabled.equals(pathRequested)) { ((HttpServletResponse) response).sendError(HttpStatus.SC_NOT_FOUND); return; } } } chain.doFilter(request, response); } catch (IOException ioe) { log.trace("Failed in api endpoint filter.", ioe); throw ioe; } catch (ServletException se) { log.trace("Failed in api endpoint filter.", se); throw se; } catch (Throwable t) { log.trace("Failed in api endpoint filter.", t); throw new ServletException(t); } }
From source file:org.apache.taverna.examples.JsonExport.java
public void convert(String[] filepaths) throws ReaderException, IOException, WriterException { if (filepaths.length == 0 || filepaths[0].equals("-h")) { System.out.println("Export workflow structore as JSON."); System.out.println("Usage: jsonexport [filename] ..."); System.out.println("If the filename is - the workflow will be read from STDIN and"); System.out.println("JSON written to STDOUT. "); System.out.println("Otherwise, the file is read as a workflow (t2flow, workflow bundle)"); System.out.println("and written as JSON to a file with the .json extension."); System.out.println("Multiple filenames can be given. JSON filenames are written to STDOUT"); return;//w ww . j ava 2s .c o m } if (filepaths[0].equals("-")) { // Do piped Stdin/Stdout instead WorkflowBundle wfBundle = io.readBundle(System.in, null); io.writeBundle(wfBundle, System.err, "application/ld+json"); return; } for (String filepath : filepaths) { File workflow = new File(filepath); String filename = workflow.getName(); filename = filename.replaceFirst("\\..*", ".json"); File workflowFile = new File(workflow.getParentFile(), filename); WorkflowBundle wfBundle = io.readBundle(workflow, null); io.writeBundle(wfBundle, workflowFile, "application/ld+json"); System.out.println(workflowFile); } }
From source file:com.kumarvv.setl.Setl.java
/** * check if valid file//from w w w .ja v a2 s. c o m * * @param file * @return */ protected String getValidPath(final String file) { if (StringUtils.isEmpty(file)) { return null; } // mac ~ fix String path = file.replaceFirst("^~", System.getProperty("user.home")); File f = Paths.get(path).toFile(); if (!f.exists()) { System.out.println("Invalid file path: " + f.getAbsolutePath()); return null; } LoggingContext.put("file", f.getName()); return f.getAbsolutePath(); }
From source file:com.appnexus.opensdk.MRAIDImplementation.java
void dispatch_mraid_call(String url) { // Remove the fake protocol url = url.replaceFirst("mraid://", ""); // Separate the function from the parameters String[] qMarkSplit = url.split("\\?"); String func = qMarkSplit[0].replaceAll("/", ""); String params;/*ww w . j a v a 2 s . co m*/ ArrayList<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>(); if (qMarkSplit.length > 1) { params = url.substring(url.indexOf("?") + 1); for (String s : params.split("&")) { if (s.split("=").length < 2) { continue; } parameters.add(new BasicNameValuePair(s.split("=")[0], s.split("=")[1])); } } if (func.equals("expand")) { expand(parameters); } else if (func.equals("close")) { close(); } }
From source file:com.gs.obevo.db.impl.core.util.MultiLineStringSplitter.java
@Override public MutableList<String> valueOf(String inputString) { inputString += "\n"; // add sentinel to facilitate line split MutableList<SqlToken> sqlTokens = this.tokenParser.parseTokens(inputString); sqlTokens = this.collapseWhiteSpaceAndTokens(sqlTokens); MutableList<String> finalSplitStrings = Lists.mutable.empty(); String currentSql = ""; for (SqlToken sqlToken : sqlTokens) { if (sqlToken.getTokenType() == SqlTokenType.COMMENT || sqlToken.getTokenType() == SqlTokenType.STRING) { currentSql += sqlToken.getText(); } else {/* ww w . j ava2 s .co m*/ String pattern = splitOnWholeLine ? "(?i)^" + this.splitToken + "$" : this.splitToken; MutableList<String> splitStrings = Lists.mutable .with(Pattern.compile(pattern, Pattern.MULTILINE).split(sqlToken.getText())); if (splitStrings.isEmpty()) { // means that we exactly match finalSplitStrings.add(currentSql); currentSql = ""; } else if (splitStrings.size() == 1) { currentSql += sqlToken.getText(); } else { splitStrings.set(0, currentSql + splitStrings.get(0)); if (splitOnWholeLine) { if (splitStrings.size() > 1) { splitStrings.set(0, StringUtils.chomp(splitStrings.get(0))); for (int i = 1; i < splitStrings.size(); i++) { String newSql = splitStrings.get(i); if (newSql.startsWith("\n")) { newSql = newSql.replaceFirst("^\n", ""); } else if (newSql.startsWith("\r\n")) { newSql = newSql.replaceFirst("^\r\n", ""); } // Chomping the end of each sql due to the split of the GO statement if (i < splitStrings.size() - 1) { newSql = StringUtils.chomp(newSql); } splitStrings.set(i, newSql); } } } finalSplitStrings.addAll(splitStrings.subList(0, splitStrings.size() - 1)); currentSql = splitStrings.getLast(); } } } if (!currentSql.isEmpty()) { finalSplitStrings.add(currentSql); } // accounting for the sentinel if (finalSplitStrings.getLast().isEmpty()) { finalSplitStrings.remove(finalSplitStrings.size() - 1); } else { finalSplitStrings.set(finalSplitStrings.size() - 1, StringUtils.chomp(finalSplitStrings.getLast())); } return finalSplitStrings; }
From source file:com.opengamma.bbg.loader.SecurityLoader.java
protected ExternalId buildUnderlyingTicker(String underlingTicker) { return ExternalSchemes.bloombergTickerSecurityId(underlingTicker.replaceFirst(" (?i)COMB ", " ")); }
From source file:com.linuxbox.enkive.statistics.gathering.mongodb.MongoStatsCollectionGatherer.java
@Override protected Map<String, Object> getPointStatistics(Date startTimestamp, Date endTimestamp) throws GathererException { Map<String, Object> pointStats = createMap(); for (String collName : db.getCollectionNames()) { String key = collName;//from w w w.j a v a 2s. c o m if (collName.startsWith("$")) { collName = collName.replaceFirst("$", "-"); } collName = collName.replace('.', '-'); pointStats.put(collName, getPointStats(key)); } return pointStats; }
From source file:de.appplant.cordova.plugin.notification.Asset.java
/** * The URI for a file./*from w ww. j av a2s . com*/ * * @param path * The given absolute path * * @return The URI pointing to the given path */ private Uri getUriForAbsolutePath(String path) { String absPath = path.replaceFirst("file://", ""); File file = new File(absPath); if (!file.exists()) { Log.e("Asset", "File not found: " + file.getAbsolutePath()); return Uri.EMPTY; } return Uri.fromFile(file); }
From source file:de.dlopes.stocks.facilitator.services.impl.FinanzenNetIndexHTMLExtractorImpl.java
@Override public List<String> getFinanceData(String url, FinanceDataType dataType) { List<String> list = new ArrayList<String>(); try {//from w ww .j a va 2s . co m Document doc = null; if (url.startsWith("file://")) { File input = new File(url.replaceFirst("file://", "")); doc = Jsoup.parse(input, "UTF-8"); } else { URL input = new URL(url); doc = Jsoup.parse(input, 30000); } //String index = doc.body().select("div#mainWrapper > div.main h1 > a").text(); Elements elements = doc.body().select("#fragIndexBarView > table tr"); for (Element e : elements) { String text = e.select("td > div").text(); // Guard: move on when the text is empty if (StringUtils.isEmpty(text)) { continue; } text = StringUtils.trimAllWhitespace(text); list.add(text); } } catch (IOException e) { e.printStackTrace(); } return list; }
From source file:com.linuxbox.enkive.statistics.gathering.mongodb.MongoStatsCollectionGatherer.java
@Override public RawStats getStatistics() { Map<String, Object> pointStats = new HashMap<String, Object>(); for (String collName : db.getCollectionNames()) { String key = collName;/*from ww w . j a v a 2 s .c om*/ if (collName.startsWith("$")) { collName = collName.replaceFirst("$", "-"); } collName = collName.replace('.', '-'); pointStats.put(collName, getPointStats(key)); } RawStats result = new RawStats(null, pointStats, new Date(), new Date()); return result; }