List of usage examples for org.apache.commons.lang3 StringUtils endsWith
public static boolean endsWith(final CharSequence str, final CharSequence suffix)
Check if a CharSequence ends with a specified suffix.
null s are handled without exceptions.
From source file:com.ottogroup.bi.spqr.pipeline.queue.chronicle.DefaultStreamingMessageQueue.java
/** * @see com.ottogroup.bi.spqr.pipeline.queue.StreamingMessageQueue#initialize(java.util.Properties) *//*from w ww. j a va 2 s . c om*/ public void initialize(Properties properties) throws RequiredInputMissingException { //////////////////////////////////////////////////////////////////////////////// // extract and validate input if (properties == null) throw new RequiredInputMissingException("Missing required properties"); if (StringUtils.isBlank(this.id)) throw new RequiredInputMissingException("Missing required queue identifier"); if (StringUtils.equalsIgnoreCase( StringUtils.trim(properties.getProperty(CFG_CHRONICLE_QUEUE_DELETE_ON_EXIT)), "false")) this.deleteOnExit = false; this.basePath = StringUtils.lowerCase(StringUtils.trim(properties.getProperty(CFG_CHRONICLE_QUEUE_PATH))); if (StringUtils.isBlank(this.basePath)) this.basePath = System.getProperty("java.io.tmpdir"); String tmpCycleFormat = StringUtils .trim(properties.getProperty(CFG_CHRONICLE_QUEUE_CYCLE_FORMAT, "yyyy-MM-dd-HH-mm")); if (StringUtils.isNotBlank(tmpCycleFormat)) this.cycleFormat = tmpCycleFormat; String pathToChronicle = this.basePath; if (!StringUtils.endsWith(pathToChronicle, File.separator)) pathToChronicle = pathToChronicle + File.separator; pathToChronicle = pathToChronicle + id; try { this.queueRollingInterval = TimeUnit.MINUTES.toMillis( Long.parseLong(StringUtils.trim(properties.getProperty(CFG_CHRONICLE_QUEUE_ROLLING_INTERVAL)))); if (this.queueRollingInterval < VanillaChronicle.MIN_CYCLE_LENGTH) { this.queueRollingInterval = VanillaChronicle.MIN_CYCLE_LENGTH; } } catch (Exception e) { logger.info("Invalid queue rolling interval found: " + e.getMessage() + ". Using default: " + TimeUnit.MINUTES.toMillis(60)); } this.queueWaitStrategy = getWaitStrategy( StringUtils.trim(properties.getProperty(CFG_QUEUE_MESSAGE_WAIT_STRATEGY))); // //////////////////////////////////////////////////////////////////////////////// // clears the queue if requested if (this.deleteOnExit) { ChronicleTools.deleteDirOnExit(pathToChronicle); ChronicleTools.deleteOnExit(pathToChronicle); } try { this.chronicle = ChronicleQueueBuilder.vanilla(pathToChronicle) .cycleLength((int) this.queueRollingInterval).cycleFormat(this.cycleFormat).build(); this.queueConsumer = new DefaultStreamingMessageQueueConsumer(this.getId(), this.chronicle.createTailer(), this.queueWaitStrategy); this.queueProducer = new DefaultStreamingMessageQueueProducer(this.getId(), this.chronicle.createAppender(), this.queueWaitStrategy); } catch (IOException e) { throw new RuntimeException( "Failed to initialize chronicle at '" + pathToChronicle + "'. Error: " + e.getMessage()); } logger.info("queue[type=chronicle, id=" + this.id + ", deleteOnExist=" + this.deleteOnExit + ", path=" + pathToChronicle + "']"); }
From source file:com.xpn.xwiki.plugin.activitystream.eventstreambridge.EventConverter.java
/** * Convert an old {@link ActivityEvent} to the new {@link Event}. * * @param e the activity event to transform * @return the equivalent event//from w ww .java 2 s . c o m */ public Event convertActivityToEvent(ActivityEvent e) { Event result = this.eventFactory.createRawEvent(); result.setApplication(e.getApplication()); result.setBody(e.getBody()); result.setDate(e.getDate()); result.setDocument(new DocumentReference( this.resolver.resolve(e.getPage(), EntityType.DOCUMENT, new WikiReference(e.getWiki())))); result.setId(e.getEventId()); result.setDocumentTitle(e.getParam1()); if (StringUtils.isNotEmpty(e.getParam2())) { if (StringUtils.endsWith(e.getType(), "Attachment")) { result.setRelatedEntity( this.explicitResolver.resolve(e.getParam2(), EntityType.ATTACHMENT, result.getDocument())); } else if (StringUtils.endsWith(e.getType(), "Comment") || StringUtils.endsWith(e.getType(), "Annotation")) { result.setRelatedEntity( this.explicitResolver.resolve(e.getParam2(), EntityType.OBJECT, result.getDocument())); } } result.setImportance(Event.Importance.MEDIUM); if (e.getPriority() > 0) { int priority = e.getPriority() / 10 - 1; if (priority >= 0 && priority < Event.Importance.values().length) { result.setImportance(Event.Importance.values()[priority]); } } result.setGroupId(e.getRequestId()); result.setStream(e.getStream()); result.setTitle(e.getTitle()); result.setType(e.getType()); if (StringUtils.isNotBlank(e.getUrl())) { try { result.setUrl(new URL(e.getUrl())); } catch (MalformedURLException ex) { // Should not happen } } result.setUser(new DocumentReference(this.resolver.resolve(e.getUser(), EntityType.DOCUMENT))); result.setDocumentVersion(e.getVersion()); result.setParameters(e.getParameters()); return result; }
From source file:com.funtl.framework.smoke.core.modules.act.service.ActModelService.java
/** * ?Model?/* w w w . j av a2 s. co m*/ */ @Transactional(readOnly = false) public String deploy(String id) { String message = ""; try { Model modelData = repositoryService.getModel(id); BpmnJsonConverter jsonConverter = new BpmnJsonConverter(); JsonNode editorNode = new ObjectMapper() .readTree(repositoryService.getModelEditorSource(modelData.getId())); BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode); BpmnXMLConverter xmlConverter = new BpmnXMLConverter(); byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel); String processName = modelData.getName(); if (!StringUtils.endsWith(processName, ".bpmn20.xml")) { processName += ".bpmn20.xml"; } // System.out.println("========="+processName+"============"+modelData.getName()); ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes); Deployment deployment = repositoryService.createDeployment().name(modelData.getName()) .addInputStream(processName, in).deploy(); // .addString(processName, new String(bpmnBytes)).deploy(); // ? List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery() .deploymentId(deployment.getId()).list(); for (ProcessDefinition processDefinition : list) { repositoryService.setProcessDefinitionCategory(processDefinition.getId(), modelData.getCategory()); message = "??ID=" + processDefinition.getId(); } if (list.size() == 0) { message = "?"; } } catch (Exception e) { throw new ActivitiException("?ID=" + id, e); } return message; }
From source file:br.com.autonomiccs.apacheCloudStack.client.ApacheCloudStackClient.java
/** * adds the suffix '{@value #CLOUDSTACK_BASE_ENDPOINT_URL_SUFFIX}' if it does have it. * It uses the method {@link #appendUrlSuffix(String)} to execute the appending. */// w ww . j a v a 2 s. c o m protected String adjustUrlIfNeeded(String url) { if (StringUtils.endsWith(url, "/client") || StringUtils.endsWith(url, "/client/")) { return url; } return appendUrlSuffix(url); }
From source file:io.wcm.devops.maven.nodejsproxy.resource.MavenProxyResource.java
/** * Maps all requests to NodeJS binaries simulating a Maven 2 directory structure. *///from w w w. j a v a 2 s . c o m @GET @Path("{groupIdPath:[a-zA-Z0-9\\-\\_]+(/[a-zA-Z0-9\\-\\_]+)*}" + "/{artifactId:[a-zA-Z0-9\\-\\_\\.]+}" + "/{version:\\d+(\\.\\d+)*}" + "/{artifactIdFilename:[a-zA-Z0-9\\-\\_\\.]+}" + "-{versionFilename:\\d+(\\.\\d+)*}" + "-{os:[a-zA-Z0-9\\_]+}" + "-{arch:[a-zA-Z0-9\\_]+}" + ".{type:[a-z]+(\\.[a-z]+)*(\\.sha1)?}") @Timed public Response getBinary(@PathParam("groupIdPath") String groupIdPath, @PathParam("artifactId") String artifactId, @PathParam("version") String version, @PathParam("artifactIdFilename") String artifactIdFilename, @PathParam("versionFilename") String versionFilename, @PathParam("os") String os, @PathParam("arch") String arch, @PathParam("type") String type) throws IOException { String groupId = mapGroupId(groupIdPath); if (!validateBasicParams(groupId, artifactId, version, artifactIdFilename, versionFilename)) { return Response.status(Response.Status.NOT_FOUND).build(); } ArtifactType artifactType = getArtifactType(artifactId); if (artifactType != ArtifactType.NODEJS) { return Response.status(Response.Status.NOT_FOUND).build(); } boolean getChecksum = false; if (StringUtils.endsWith(type, ".sha1")) { getChecksum = true; } String url = buildBinaryUrl(artifactType, version, os, arch, StringUtils.removeEnd(type, ".sha1")); return getBinaryWithChecksumValidation(url, version, getChecksum); }
From source file:br.com.autonomiccs.apacheCloudStack.client.ApacheCloudStackClient.java
/** * Appends the suffix '{@value #CLOUDSTACK_BASE_ENDPOINT_URL_SUFFIX}' at the end of the given URL. * If it is needed, it will also add, a '/' before the suffix is appended to the URL. *//*w w w .j a v a 2s .c o m*/ protected String appendUrlSuffix(String url) { if (StringUtils.endsWith(url, "/")) { return url + CLOUDSTACK_BASE_ENDPOINT_URL_SUFFIX; } return url + "/" + CLOUDSTACK_BASE_ENDPOINT_URL_SUFFIX; }
From source file:com.sonicle.webtop.core.versioning.SqlUpgradeScript.java
private void readFile(InputStreamReader readable, boolean flatNewLines) throws IOException { this.statements = new ArrayList<>(); StringBuilder sb = null, sbsql = null; String lines[] = null;// w ww . j a v a 2 s.co m Scanner s = new Scanner(readable); s.useDelimiter("(;( )?(\r)?\n)"); //s.useDelimiter("(;( )?(\r)?\n)|(--\n)"); while (s.hasNext()) { String block = s.next(); block = StringUtils.replace(block, "\r", ""); if (!StringUtils.isEmpty(block)) { // Remove remaining ; at the end of the block (only if this block is the last one) if (!s.hasNext() && StringUtils.endsWith(block, ";")) block = StringUtils.left(block, block.length() - 1); sb = new StringBuilder(); sbsql = new StringBuilder(); lines = StringUtils.split(block, "\n"); for (String line : lines) { if (AnnotationLine.matches(line)) { if (DataSourceAnnotationLine.matches(line)) { statements.add(new DataSourceAnnotationLine(line)); } else if (IgnoreErrorsAnnotationLine.matches(line)) { statements.add(new IgnoreErrorsAnnotationLine(line)); } else if (RequireAdminAnnotationLine.matches(line)) { statements.add(new RequireAdminAnnotationLine(line)); } else { throw new IOException("Bad line: " + line); } } else if (CommentLine.matches(line)) { sb.append(line); sb.append("\n"); } else { sbsql.append(StringUtils.trim(line)); sbsql.append(" "); if (!flatNewLines) sbsql.append("\n"); } } if (sb.length() > 0) statements.add(new CommentLine(StringUtils.removeEnd(sb.toString(), "\n"))); if (sbsql.length() > 0) statements.add(new SqlLine(StringUtils.removeEnd(sbsql.toString(), "\n"))); } } }
From source file:com.xpn.xwiki.user.impl.xwiki.MyFormAuthenticator.java
/** * Process any login information that was included in the request, if any. Returns true if SecurityFilter should * abort further processing after the method completes (for example, if a redirect was sent as part of the login * processing)./* w ww . j ava2s. com*/ * * @param request * @param response * @return true if the filter should return after this method ends, false otherwise */ public boolean processLogin(SecurityRequestWrapper request, HttpServletResponse response, XWikiContext context) throws Exception { try { Principal principal = MyBasicAuthenticator.checkLogin(request, response, context); if (principal != null) { return false; } if ("1".equals(request.getParameter("basicauth"))) { return true; } } catch (Exception e) { // in case of exception we continue on Form Auth. // we don't want this to interfere with the most common behavior } // process any persistent login information, if user is not already logged in, // persistent logins are enabled, and the persistent login info is present in this request if (this.persistentLoginManager != null) { String username = convertUsername(this.persistentLoginManager.getRememberedUsername(request, response), context); String password = this.persistentLoginManager.getRememberedPassword(request, response); Principal principal = request.getUserPrincipal(); // 1) if user is not already authenticated, authenticate // 2) if authenticated user for this session does not have the same name, authenticate // 3) if xwiki.authentication.always is set to 1 in xwiki.cfg file, authenticate if (principal == null || !StringUtils.endsWith(principal.getName(), "XWiki." + username) || context.getWiki().ParamAsLong("xwiki.authentication.always", 0) == 1) { principal = authenticate(username, password, context); if (principal != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("User " + principal.getName() + " has been authentified from cookie"); } // make sure the Principal contains wiki name information if (!StringUtils.contains(principal.getName(), ':')) { principal = new SimplePrincipal(context.getDatabase() + ":" + principal.getName()); } request.setUserPrincipal(principal); } else { // Failed to authenticate, better cleanup the user stored in the session request.setUserPrincipal(null); if (username != null || password != null) { // Failed authentication with remembered login, better forget login now this.persistentLoginManager.forgetLogin(request, response); } } } } // process login form submittal if ((this.loginSubmitPattern != null) && request.getMatchableURL().endsWith(this.loginSubmitPattern)) { String username = convertUsername(request.getParameter(FORM_USERNAME), context); String password = request.getParameter(FORM_PASSWORD); String rememberme = request.getParameter(FORM_REMEMBERME); rememberme = (rememberme == null) ? "false" : rememberme; return processLogin(username, password, rememberme, request, response, context); } return false; }
From source file:com.thruzero.test.support.AbstractCoreTestCase.java
/** * Returns the specified file by searching the class path for the "<code>test-classes</code>" directory ( * <code>TEST_CLASSES_DIR_NAME</code>) and appending the "temp" directory plus the requested fileName to create the * File instance that represents the requested test file. Returns null if the "<code>test-classes</code>" directory is * not found.//from ww w. java 2 s . co m */ protected File getTestFile(final String fileName) { // find the "test-classes" directory String classPath = System.getProperty(EnvironmentVariableKeys.JAVA_CLASS_PATH_ENV_VAR, "."); String[] classPathElements = classPath.split(EnvironmentHelper.CLASS_PATH_SEPARATOR); String testClassesDir = null; for (String path : classPathElements) { if (StringUtils.endsWith(path, TEST_CLASSES_DIR_NAME) || StringUtils.endsWith(path, TEST_CLASSES_DIR_NAME + EnvironmentHelper.FILE_PATH_SEPARATOR)) { testClassesDir = path; break; } } if (testClassesDir == null) { return null; } else { return new File(testClassesDir, fileName); } }
From source file:io.wcm.devops.maven.nodejsproxy.resource.MavenProxyResource.java
/** * Maps all requests to NPM binaries simulating a Maven 2 directory structure. *///from w w w . j a v a 2 s. c o m @GET @Path("{groupIdPath:[a-zA-Z0-9\\-\\_]+(/[a-zA-Z0-9\\-\\_]+)*}" + "/{artifactId:[a-zA-Z0-9\\-\\_\\.]+}" + "/{version:\\d+(\\.\\d+)*}" + "/{artifactIdFilename:[a-zA-Z0-9\\-\\_\\.]+}" + "-{versionFilename:\\d+(\\.\\d+)*}" + ".{type:[a-z]+(\\.[a-z]+)*(\\.sha1)?}") @Timed public Response getBinary(@PathParam("groupIdPath") String groupIdPath, @PathParam("artifactId") String artifactId, @PathParam("version") String version, @PathParam("artifactIdFilename") String artifactIdFilename, @PathParam("versionFilename") String versionFilename, @PathParam("type") String type) throws IOException { String groupId = mapGroupId(groupIdPath); if (!validateBasicParams(groupId, artifactId, version, artifactIdFilename, versionFilename)) { return Response.status(Response.Status.NOT_FOUND).build(); } ArtifactType artifactType = getArtifactType(artifactId); if (artifactType != ArtifactType.NPM) { return Response.status(Response.Status.NOT_FOUND).build(); } boolean getChecksum = false; if (StringUtils.endsWith(type, ".sha1")) { getChecksum = true; } String url = buildBinaryUrl(artifactType, version, null, null, StringUtils.removeEnd(type, ".sha1")); return getBinary(url, version, getChecksum, null); }