List of usage examples for org.apache.commons.lang StringUtils startsWith
public static boolean startsWith(String str, String prefix)
Check if a String starts with a specified prefix.
From source file:hudson.plugins.clearcase.ucm.UcmCommon.java
/** * @param clearToolLauncher//from ww w .j a v a2s .c o m * @param isUseDynamicView * @param viewName * @param filePath * @param readWriteComponents . if null both baselines on read and read-write components will be returned * @return List of latest baselines on read write components (only) * @throws InterruptedException * @throws IOException * @throws Exception */ public static List<String> getLatestBaselineNames(ClearTool clearTool, boolean isUseDynamicView, String viewName, FilePath filePath, List<String> readWriteComponents) throws IOException, InterruptedException { String output = clearTool.lsstream(null, viewName, "%[latest_bls]Xp"); String prefix = "baseline:"; List<String> baselineNames = new ArrayList<String>(); if (StringUtils.startsWith(output, prefix)) { String[] baselineNamesSplit = output.split("baseline:"); for (String baselineName : baselineNamesSplit) { if (StringUtils.isNotBlank(baselineName)) { String baselineNameTrimmed = StringUtils.trim(baselineName); // Retrict to baseline bind to read/write component String blComp = getDataforBaseline(clearTool, filePath, baselineNameTrimmed).getBaselineName(); if (readWriteComponents == null || readWriteComponents.contains(blComp)) { baselineNames.add(baselineNameTrimmed); } } } } return baselineNames; }
From source file:com.netflix.paas.cassandra.entity.CassandraClusterEntity.java
public Collection<String> getKeyspaceColumnFamilyNames(final String keyspaceName) { return Collections2.filter(this.columnFamilies.keySet(), new Predicate<String>() { @Override/*from www . j ava 2 s .com*/ public boolean apply(String cfName) { return StringUtils.startsWith(cfName, keyspaceName + "|"); } }); }
From source file:AIR.Common.Web.FileFtpHandler.java
public boolean allowScheme(String filePath) { if (appSettings.getBoolean(TDSCommonPropertyNames.ALLOW_FTP)) { // check if file path is ftp scheme return StringUtils.startsWith(filePath, "ftp://"); }// ww w . ja v a 2s. c o m return false; }
From source file:hydrograph.ui.expression.editor.composites.FunctionsUpperComposite.java
private void addListnersToSearchTextBox() { functionSearchTextBox.addModifyListener(new ModifyListener() { @Override/*from ww w . jav a 2s .c o m*/ public void modifyText(ModifyEvent e) { if (!StringUtils.equals(Constants.DEFAULT_SEARCH_TEXT, functionSearchTextBox.getText()) && (classNameList.getSelectionCount() != 0 && !StringUtils .startsWith(classNameList.getItem(0), Messages.CANNOT_SEARCH_INPUT_STRING))) { methodList.removeAll(); ClassDetails classDetails = (ClassDetails) methodList .getData(CategoriesComposite.KEY_FOR_ACCESSING_CLASS_FROM_METHOD_LIST); if (classDetails != null) { for (MethodDetails methodDetails : classDetails.getMethodList()) { if (StringUtils.containsIgnoreCase(methodDetails.getMethodName(), functionSearchTextBox.getText())) { methodList.add(methodDetails.getSignature()); methodList.setData(String.valueOf(methodList.getItemCount() - 1), methodDetails); } } } if (methodList.getItemCount() == 0 && StringUtils.isNotBlank(functionSearchTextBox.getText())) { methodList.add(Messages.CANNOT_SEARCH_INPUT_STRING + functionSearchTextBox.getText()); } descriptionStyledText.setText(Constants.EMPTY_STRING); } } }); }
From source file:com.xx_dev.apn.socks.local.FakeHttpClientDecoder.java
protected void _decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { switch (this.state()) { case READ_FAKE_HTTP: { int fakeHttpHeadStartIndex = in.readerIndex(); int fakeHttpHeadEndIndex = in.forEachByte(new ByteBufProcessor() { int c = 0; @Override//from ww w . ja v a2s .c om public boolean process(byte value) throws Exception { if (value == '\r' || value == '\n') { c++; } else { c = 0; } //logger.info("value=" + value + ", c=" + c); if (c >= 4) { return false; } else { return true; } } }); logger.debug("s: " + fakeHttpHeadStartIndex); logger.debug("e: " + fakeHttpHeadEndIndex); if (fakeHttpHeadEndIndex == -1) { logger.warn("w: " + fakeHttpHeadStartIndex); break; } byte[] buf = new byte[fakeHttpHeadEndIndex - fakeHttpHeadStartIndex + 1]; in.readBytes(buf, 0, fakeHttpHeadEndIndex - fakeHttpHeadStartIndex + 1); String s = TextUtil.fromUTF8Bytes(buf); //logger.info(s); String[] ss = StringUtils.split(s, "\r\n"); //System.out.println(s + "" + this + " " + Thread.currentThread().getName()); for (String line : ss) { if (StringUtils.startsWith(line, "X-C:")) { String lenStr = StringUtils.trim(StringUtils.split(line, ":")[1]); //System.out.println(lenStr + "" + this + " " + Thread.currentThread().getName()); //System.out.println("*****************************************"); try { length = Integer.parseInt(lenStr, 16); trafficLogger.info("D," + LocalConfig.ins().getUser() + "," + length); } catch (Throwable t) { logger.error("--------------------------------------"); logger.error(s + "" + this + " " + Thread.currentThread().getName()); logger.error("--------------------------------------"); } } } this.checkpoint(STATE.READ_CONTENT); } case READ_CONTENT: { if (length > 0) { byte[] buf = new byte[length]; in.readBytes(buf, 0, length); byte[] res = new byte[length]; for (int i = 0; i < length; i++) { res[i] = (byte) (buf[i] ^ (LocalConfig.ins().getEncryptKey() & 0xFF)); } ByteBuf outBuf = ctx.alloc().buffer(); outBuf.writeBytes(res); out.add(outBuf); } this.checkpoint(STATE.READ_FAKE_HTTP); break; } default: throw new Error("Shouldn't reach here."); } }
From source file:com.xx_dev.apn.socks.remote.FakeHttpServerDecoder.java
protected void _decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { switch (this.state()) { case READ_FAKE_HTTP: { int fakeHttpHeadStartIndex = in.readerIndex(); int fakeHttpHeadEndIndex = in.forEachByte(new ByteBufProcessor() { int c = 0; @Override//from ww w . j av a2 s .c o m public boolean process(byte value) throws Exception { if (value == '\r' || value == '\n') { c++; } else { c = 0; } //logger.info("value=" + value + ", c=" + c); if (c >= 4) { return false; } else { return true; } } }); logger.debug("s: " + fakeHttpHeadStartIndex); logger.debug("e: " + fakeHttpHeadEndIndex); if (fakeHttpHeadEndIndex == -1) { logger.warn("w: " + fakeHttpHeadStartIndex); break; } byte[] buf = new byte[fakeHttpHeadEndIndex - fakeHttpHeadStartIndex + 1]; in.readBytes(buf, 0, fakeHttpHeadEndIndex - fakeHttpHeadStartIndex + 1); String s = TextUtil.fromUTF8Bytes(buf); //logger.info(s); String[] ss = StringUtils.split(s, "\r\n"); //System.out.println(s + "" + this + " " + Thread.currentThread().getName()); for (String line : ss) { if (StringUtils.startsWith(line, "X-C:")) { String lenStr = StringUtils.trim(StringUtils.split(line, ":")[1]); //System.out.println(lenStr + "" + this + " " + Thread.currentThread().getName()); //System.out.println("*****************************************"); try { length = Integer.parseInt(lenStr, 16); } catch (Throwable t) { logger.error("--------------------------------------"); logger.error(s + "" + this + " " + Thread.currentThread().getName()); logger.error("--------------------------------------"); } } if (StringUtils.startsWith(line, "X-U:")) { String user = StringUtils.trim(StringUtils.split(line, ":")[1]); ctx.channel().attr(NettyAttributeKey.LINK_USER).set(user); logger.info(user); } } this.checkpoint(STATE.READ_CONTENT); } case READ_CONTENT: { trafficLogger.info("U," + ctx.channel().attr(NettyAttributeKey.LINK_USER).get() + "," + length); if (length > 0) { byte[] buf = new byte[length]; in.readBytes(buf, 0, length); byte[] res = new byte[length]; for (int i = 0; i < length; i++) { res[i] = (byte) (buf[i] ^ (RemoteConfig.ins().getEncryptKey() & 0xFF)); } ByteBuf outBuf = ctx.alloc().buffer(); outBuf.writeBytes(res); out.add(outBuf); } this.checkpoint(STATE.READ_FAKE_HTTP); break; } default: throw new Error("Shouldn't reach here."); } }
From source file:com.cognifide.cq.cqsm.foundation.actions.purge.Purge.java
private void purge(final Context context, final ActionResult actionResult) throws RepositoryException, ActionExecutionException { NodeIterator iterator = getPermissions(context); String normalizedPath = normalizePath(path); while (iterator != null && iterator.hasNext()) { Node node = iterator.nextNode(); if (node.hasProperty(PermissionConstants.REP_ACCESS_CONTROLLED_PATH)) { String parentPath = node.getProperty(PermissionConstants.REP_ACCESS_CONTROLLED_PATH).getString(); String normalizedParentPath = normalizePath(parentPath); if (StringUtils.startsWith(normalizedParentPath, normalizedPath)) { RemoveAll removeAll = new RemoveAll(parentPath); ActionResult removeAllResult = removeAll.execute(context); if (Status.ERROR.equals(removeAllResult.getStatus())) { actionResult.logError(removeAllResult); }//from w w w . j a va 2s . co m } } } }
From source file:com.adobe.acs.commons.rewriter.impl.ResourceResolverMapTransformerFactory.java
protected Attributes rebuildAttributes(final SlingHttpServletRequest slingRequest, final String elementName, final Attributes attrs) { if (slingRequest == null || !attributes.containsKey(elementName)) { // element is not defined as a candidate to rewrite return attrs; }/*from w ww . j a v a 2s . co m*/ final String[] modifiableAttributes = attributes.get(elementName); // clone the attributes final AttributesImpl newAttrs = new AttributesImpl(attrs); final int len = newAttrs.getLength(); for (int i = 0; i < len; i++) { final String attrName = newAttrs.getLocalName(i); if (ArrayUtils.contains(modifiableAttributes, attrName)) { final String attrValue = newAttrs.getValue(i); if (StringUtils.startsWith(attrValue, "/") && !StringUtils.startsWith(attrValue, "//")) { // Only map absolute paths (starting w /), avoid relative-scheme URLs starting w // newAttrs.setValue(i, slingRequest.getResourceResolver().map(slingRequest, attrValue)); } } } return newAttrs; }
From source file:it.openutils.mgnlaws.magnolia.AmazonMgnlServletContextListener.java
protected void initEc2(String accessKey, String secretKey, String endpoint) throws IOException, AmazonEc2InstanceNotFound { String ec2InstanceId;/*www . j a v a2 s. co m*/ BufferedReader in = null; try { URL url = new URL("http://169.254.169.254/latest/meta-data/instance-id"); URLConnection connection = url.openConnection(); in = new BufferedReader(new InputStreamReader(connection.getInputStream())); ec2InstanceId = in.readLine(); in.close(); } finally { IOUtils.closeQuietly(in); } AmazonEC2Client client = new AmazonEC2Client(new BasicAWSCredentials(accessKey, secretKey)); client.setEndpoint(endpoint); DescribeInstancesResult result = client .describeInstances(new DescribeInstancesRequest().withInstanceIds(ec2InstanceId)); if (result.getReservations().size() > 0 && result.getReservations().get(0).getInstances().size() > 0) { ec2Instance = result.getReservations().get(0).getInstances().get(0); if (ec2Instance == null) { // should never happen throw new AmazonEc2InstanceNotFound(ec2InstanceId); } } else { throw new AmazonEc2InstanceNotFound(ec2InstanceId); } for (Tag tag : ec2Instance.getTags()) { if (StringUtils.startsWith(tag.getKey(), "__")) { System.setProperty(StringUtils.substring(tag.getKey(), 2), tag.getValue()); } else { System.setProperty("aws.instance." + tag.getKey(), tag.getValue()); } } String clusterId = System.getProperty(EC2_TAG_CLUSTERID); if (StringUtils.isNotEmpty(clusterId)) { System.setProperty(JR_CLUSTERID, clusterId); } }
From source file:com.adobe.acs.commons.wcm.views.impl.WCMViewsServlet.java
@Override protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("UTF-8"); response.setContentType("application/json"); if (WCMMode.DISABLED.equals(WCMMode.fromRequest(request))) { response.setStatus(SlingHttpServletResponse.SC_NOT_FOUND); response.getWriter().write(""); return;/*from w w w .j av a2 s.c o m*/ } /* Valid WCMMode */ final PageManager pageManager = request.getResourceResolver().adaptTo(PageManager.class); final Page page = pageManager.getContainingPage(request.getResource()); final WCMViewsResourceVisitor visitor = new WCMViewsResourceVisitor(); visitor.accept(page.getContentResource()); final Set<String> viewSet = new HashSet<String>(visitor.getWCMViews()); // Get the Views provided by the Servlet for (final Map.Entry<String, String[]> entry : this.defaultViews.entrySet()) { if (StringUtils.startsWith(page.getPath(), entry.getKey())) { viewSet.addAll(Arrays.asList(entry.getValue())); } } final List<String> views = new ArrayList<String>(viewSet); Collections.sort(views); log.debug("Collected WCM Views {} for Page [ {} ]", views, page.getPath()); final JSONArray jsonArray = new JSONArray(); for (final String view : views) { final JSONObject json = new JSONObject(); try { json.put("title", StringUtils.capitalize(view) + " View"); json.put("value", view); jsonArray.put(json); } catch (JSONException e) { log.error("Unable to build WCM Views JSON output.", e); } } response.getWriter().write(jsonArray.toString()); }