List of usage examples for java.lang String replaceFirst
public String replaceFirst(String regex, String replacement)
From source file:org.auraframework.archetype.AuraArchetypeSimpleTestMANUAL.java
private void verifySampleComponents() throws Exception { HttpGet get = obtainGetMethod(String.format("/%1$s/%1$s.app", project.artifactId)); HttpResponse httpResponse = perform(get); assertEquals("Failed requesting sample app", HttpStatus.SC_OK, getStatusCode(httpResponse)); String body = getResponseBody(httpResponse); get.releaseConnection();/*from w w w . j a v a 2 s. c o m*/ // strip lastmod values body = body.replaceFirst(" data-lm=\"[^\"]+\"", ""); body = body.replaceFirst("lastmod%22%3A%22\\d+", ""); goldFileText(body, "-sample.html"); }
From source file:de.dlopes.stocks.facilitator.services.impl.FinanznachrichtenOrderbuchExtractorImpl.java
@Override public List<String> getFinanceData(String url, FinanceDataType dataType) { List<String> list = new ArrayList<String>(); try {/*from www. j a va2 s .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); } Elements elements = doc.body().select("span[id^=productid] > span"); for (Element e : elements) { String text = e.text(); // Guard: move on when the text is empty if (StringUtils.isEmpty(text)) { continue; } text = StringUtils.trimAllWhitespace(text); // Guard: move on when the text does not contain the ISIN or WKN if (!text.startsWith(dataType.name() + ":")) { continue; } text = text.replace(dataType.name() + ":", ""); list.add(text); } } catch (IOException e) { e.printStackTrace(); } return list; }
From source file:ezbake.persist.FilePersist.java
private List<String> getFiles(String path, String root, List<String> data) { File file = new File(path); File[] files = file.listFiles(); if (file.exists()) { data.add(path.replaceFirst(joinPath(root, ""), "")); }//w w w . j a va2 s . c o m if (files != null) { for (File f : files) { getFiles(f.toString(), root, data); } } return data; }
From source file:com.wso2telco.core.authfilter.impl.authorization.BasicAuthenticationFilter.java
@Override public boolean isAuthenticated(ContainerRequestContext requestContext, Method method, String authorizationHeader) { String password = null;/*from w w w . j a v a 2s. c o m*/ boolean isAuthenticated = false; // get base 64 encoded username and password final String encodedUserPassword = authorizationHeader .replaceFirst(AuthFilterParam.AUTHENTICATION_SCHEME_BASIC.getTObject() + " ", ""); log.debug("base64 encoded username and password : " + encodedUserPassword); if (encodedUserPassword != null && encodedUserPassword.trim().length() > 0) { // decode username and password String usernameAndPassword = new String(Base64.decodeBase64(encodedUserPassword.getBytes())); // split username and password by : final StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":"); if (tokenizer.countTokens() > 1) { userName = tokenizer.nextToken(); password = tokenizer.nextToken(); log.debug("username : " + userName); log.debug("password : " + password); // validate user authentication isAuthenticated = userAuthentication.isAuthenticatedUser(userName, password); if (!isAuthenticated) { requestContext.abortWith(accessDenied); return false; } } else { requestContext.abortWith(accessDenied); return false; } } else { requestContext.abortWith(accessDenied); return false; } return true; }
From source file:de.appplant.cordova.plugin.notification.Asset.java
/** * The URI for an asset./* w w w. j av a 2 s . c o m*/ * * @param path * The given asset path * * @return The URI pointing to the given path */ private Uri getUriForAssetPath(String path) { String resPath = path.replaceFirst("file:/", "www"); String fileName = resPath.substring(resPath.lastIndexOf('/') + 1); File dir = activity.getExternalCacheDir(); if (dir == null) { Log.e("Asset", "Missing external cache dir"); return Uri.EMPTY; } String storage = dir.toString() + STORAGE_FOLDER; File file = new File(storage, fileName); new File(storage).mkdir(); try { AssetManager assets = activity.getAssets(); FileOutputStream outStream = new FileOutputStream(file); InputStream inputStream = assets.open(resPath); copyFile(inputStream, outStream); outStream.flush(); outStream.close(); return Uri.fromFile(file); } catch (Exception e) { Log.e("Asset", "File not found: assets/" + resPath); e.printStackTrace(); } return Uri.EMPTY; }
From source file:com.thoughtworks.go.server.service.ArtifactsService.java
public String findArtifactRoot(JobIdentifier identifier) throws IllegalArtifactLocationException { JobIdentifier id = jobResolverService.actualJobIdentifier(identifier); try {/*from www.j a v a 2 s. c o m*/ String fullArtifactPath = chooser.findArtifact(id, "").getCanonicalPath(); String artifactRoot = artifactsDirHolder.getArtifactsDir().getCanonicalPath(); String relativePath = fullArtifactPath.replace(artifactRoot, ""); if (relativePath.startsWith(File.separator)) { relativePath = relativePath.replaceFirst("\\" + File.separator, ""); } return relativePath; } catch (IOException e) { throw new IllegalArtifactLocationException("No artifact found.", e); } }
From source file:org.wso2.carbon.http2.transport.Http2TransportSender.java
/** * Handels requests come from Axis2 Engine * * @param msgCtx//w w w .ja v a2s . com * @param targetEPR * @param trpOut * @throws AxisFault */ public void sendMessage(MessageContext msgCtx, String targetEPR, OutTransportInfo trpOut) throws AxisFault { try { if (targetEPR.toLowerCase().contains("http2://")) { targetEPR = targetEPR.replaceFirst("http2://", "http://"); } else if (targetEPR.toLowerCase().contains("https2://")) { targetEPR = targetEPR.replaceFirst("https2://", "https://"); } URI uri = new URI(targetEPR); String scheme = uri.getScheme() != null ? uri.getScheme() : "http"; String hostname = uri.getHost(); int port = uri.getPort(); if (port == -1) { // use default if ("http".equals(scheme)) { port = 80; } else if ("https".equals(scheme)) { port = 443; } } HttpHost target = new HttpHost(hostname, port, scheme); boolean secure = "https".equals(target.getSchemeName()); HttpHost proxy = proxyConfig.selectProxy(target); msgCtx.setProperty(PassThroughConstants.PROXY_PROFILE_TARGET_HOST, target.getHostName()); HttpRoute route; if (proxy != null) { route = new HttpRoute(target, null, proxy, secure); } else { route = new HttpRoute(target, null, secure); } Http2TargetRequestUtil util = new Http2TargetRequestUtil(targetConfiguration, route); msgCtx.setProperty(Http2Constants.PASSTHROUGH_TARGET, util); if (msgCtx.getProperty(PassThroughConstants.PASS_THROUGH_PIPE) == null) { Pipe pipe = new Pipe(targetConfiguration.getBufferFactory().getBuffer(), "Test", targetConfiguration); msgCtx.setProperty(PassThroughConstants.PASS_THROUGH_PIPE, pipe); msgCtx.setProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED, Boolean.TRUE); } Http2ClientHandler clientHandler = connectionFactory.getChannelHandler(target); String tenantDomain = (msgCtx.getProperty(MultitenantConstants.TENANT_DOMAIN) == null) ? null : (String) msgCtx.getProperty(MultitenantConstants.TENANT_DOMAIN); String dispatchSequence = (msgCtx.getProperty(Http2Constants.HTTP2_DISPATCH_SEQUENCE) == null) ? null : (String) msgCtx.getProperty(Http2Constants.HTTP2_DISPATCH_SEQUENCE); String errorSequence = (msgCtx.getProperty(Http2Constants.HTTP2_ERROR_SEQUENCE) == null) ? null : (String) msgCtx.getProperty(Http2Constants.HTTP2_ERROR_SEQUENCE); InboundResponseSender responseSender = (msgCtx .getProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER) == null) ? null : (InboundResponseSender) msgCtx .getProperty(InboundEndpointConstants.INBOUND_ENDPOINT_RESPONSE_WORKER); boolean serverPushEnabled = (msgCtx .getProperty(Http2Constants.HTTP2_PUSH_PROMISE_REQEUST_ENABLED) == null) ? false : (boolean) msgCtx.getProperty(Http2Constants.HTTP2_PUSH_PROMISE_REQEUST_ENABLED); clientHandler.setResponseReceiver(tenantDomain, dispatchSequence, errorSequence, responseSender, targetConfiguration, serverPushEnabled); clientHandler.channelWrite(msgCtx); } catch (URISyntaxException e) { log.error("Error parsing the http2 endpoint url"); throw new AxisFault(e.getMessage()); } }
From source file:com.jasonstedman.maven.RequireConfigTransformer.java
@SuppressWarnings("unchecked") public void processResource(String resource, InputStream is, List<Relocator> relocators) throws IOException { String block = IOUtils.toString(is, "utf-8"); if (resource.equals(initialDefinition)) { initBlock = block;//from ww w . ja va 2s . c o m } else if (configFilePatternInstance.matcher(resource).matches()) { block = block.replaceFirst("\\s*require\\s*.\\s*config\\s*\\(", ""); block = block.substring(0, block.lastIndexOf(')')); logger.finer(block); configBlocks.add(mapper.readValue(block, Map.class)); } hasTransformedResource = true; }
From source file:com.sun.portal.portletcontainer.driver.admin.UploadServlet.java
private String getWarName(String warFileName) { String warName = PortletWarUpdaterUtil.getWarName(warFileName); String regexp = WarFileFilter.WAR_EXTENSION + "$"; return warName.replaceFirst(regexp, ""); }