List of usage examples for org.apache.commons.lang StringUtils removeEnd
public static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
From source file:org.betaconceptframework.astroboa.engine.jcr.dao.ContentDefinitionDao.java
public byte[] getXMLSchemaFileForDefinition(String definitionFullPath) { try {//from ww w .j av a2 s . co m if (StringUtils.isBlank(definitionFullPath)) { return null; } if (definitionFullPath.endsWith(".dtd")) { return null; } if (definitionFullPath.endsWith(".xsd")) { //First try directly byte[] schema = definitionCacheRegion.getXMLSchemaForDefinitionFilename(definitionFullPath); if (schema == null || schema.length == 0) { //Probably an internal complex cms property //Replace version info along with xsd suffix definitionFullPath = definitionFullPath.replaceAll("-.*\\.xsd", ""); //In case no version info exists just remove xsd suffix definitionFullPath = StringUtils.removeEnd(definitionFullPath, ".xsd"); } else { return schema; } } CmsDefinition cmsDefinition = retrieveDefinition(definitionFullPath); String schemaFilename = ResourceApiURLUtils.retrieveSchemaFileName(cmsDefinition); if (StringUtils.isBlank(schemaFilename)) { logger.warn("Could not retrieve XML Schema filename for definition {}", cmsDefinition.getName()); return null; } return definitionCacheRegion.getXMLSchemaForDefinitionFilename(schemaFilename); } catch (Exception e) { logger.error("", e); throw new CmsException(e.getMessage()); } }
From source file:org.betaconceptframework.astroboa.engine.jcr.util.CmsRepositoryEntityUtils.java
/** * Converts greek characters to English and * replaces all characters not supported in regular expression * {@link CmsConstants#SYSTEM_NAME_ACCEPTABLE_CHARACTERS} with dash (-) * /*from w ww . j ava 2 s. co m*/ * @return */ public String fixSystemName(String systemName) { if (systemName == null) { return null; } //Remove leading and trailing whitespace systemName = systemName.trim(); //Replace all accented characters systemName = deAccent(systemName); //Replace all Greek Characters with their Latin equivalent systemName = GreekToEnglish.convertString(systemName); //Replace all invalid characters with '-' systemName = systemName.replaceAll("[^" + CmsConstants.SYSTEM_NAME_ACCEPTABLE_CHARACTERS + "]", "-"); //Replace all '--' with '-' while (systemName.contains("--")) { systemName = systemName.replaceAll("--", "-"); } //Remove leading and trailing '-' if (systemName.startsWith("-")) { systemName = systemName.replaceFirst("-", ""); } if (systemName.endsWith("-")) { systemName = StringUtils.removeEnd(systemName, "-"); } return systemName; }
From source file:org.betaconceptframework.astroboa.security.AstroboaPasswordEncryptor.java
public String encrypt(String password) { initDigester();/*from w ww .j av a 2 s . c o m*/ String encryptedPass = this.digester.digest(password); /* Current setup with StandardStringDigester and Base64 from Apache Commons Codec v1.4 * adds the Base64_LINE_SEPARATOR (that is a CRLF ("\r\n")) * at the end of the digested result. * * For example, for the value 'myPassword' the digester will produce * the following '2rnNFkiLbEDM+S46twlB3VTwtafMOexbQARYRGLb5aM=\r\n' * * If this value is saved as a value of a property, * Jackrabbit (JCR implementation used by Astroboa) truncates the CRLF * and thus, when we get the value back, we get * * '2rnNFkiLbEDM+S46twlB3VTwtafMOexbQARYRGLb5aM=' * * However, if we call method checkPassword('myPassword', '2rnNFkiLbEDM+S46twlB3VTwtafMOexbQARYRGLb5aM='), * we get the same result with the call checkPassword('myPassword', '2rnNFkiLbEDM+S46twlB3VTwtafMOexbQARYRGLb5aM=\r\n'), * which is TRUE. * * This is happening because the digester silently ignores Base64_LINE_SEPARATOR upon decoding!!! * * This abnormally, however, may cause problems to every one who wants to check a password (which is a value of a property) * without the use of the method checkPassword(). * * In this case, she will get the encrypted value from this method (2rnNFkiLbEDM+S46twlB3VTwtafMOexbQARYRGLb5aM=\r\n), * she will get the value stored in the property (2rnNFkiLbEDM+S46twlB3VTwtafMOexbQARYRGLb5aM=) and she will get no match. * * Since the CRLF is ignored and does not play any role to decoding, it is safe to return the encrypted value without the CRLF. * This way, password checking can be done with the use of this digester. * */ if (encryptedPass != null && encryptedPass.endsWith(Base64_LINE_SEPARATOR)) { return StringUtils.removeEnd(encryptedPass, Base64_LINE_SEPARATOR); } return encryptedPass; }
From source file:org.bigmouth.nvwa.network.http.HttpServletRequestLogger.java
public void info(final HttpServletRequest request) { if (null == request) return;/* w ww .j av a2 s. c o m*/ if (LOGGER.isInfoEnabled()) { StringBuilder url = new StringBuilder(256); StringBuilder parameter = new StringBuilder(256); StringBuilder headers = new StringBuilder(256); StringBuilder body = new StringBuilder(); String uri = request.getRequestURI(); String address = request.getRemoteAddr(); Map<?, ?> map = request.getParameterMap(); if (MapUtils.isNotEmpty(map)) { parameter.append("?"); } for (Entry<?, ?> entry : map.entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); parameter.append(key); if (value instanceof String[]) { parameter.append("="); String[] values = (String[]) value; for (int i = 0; i < values.length; i++) { parameter.append(values[i]); } } parameter.append("&"); } url.append(uri).append(StringUtils.removeEnd(parameter.toString(), "&")); String method = request.getMethod(); int contentLength = request.getContentLength(); Enumeration<?> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { Object nextElement = headerNames.nextElement(); String value = request.getHeader(String.valueOf(nextElement)); headers.append(nextElement).append(": ").append(value).append(";"); } HttpServletRequestLog log = new HttpServletRequestLog(); log.setAddress(address); log.setContentLength(contentLength); log.setHeaders(StringUtils.removeEnd(headers.toString(), ";")); log.setMethod(method); log.setUri(url.toString()); log.setBody(body.toString()); LOGGER.info(log.toString()); } }
From source file:org.bigmouth.nvwa.utils.url.URLEncoder.java
public static String encode(Object obj, String jointChar, boolean sort, Comparator<String> comparator) { StringBuilder rst = new StringBuilder(); List<String> list = Lists.newArrayList(); Field[] fields = obj.getClass().getDeclaredFields(); for (Field field : fields) { String fieldName = field.getName(); String paramName = fieldName; if (field.isAnnotationPresent(Argument.class)) { paramName = field.getAnnotation(Argument.class).name(); }// ww w .j a v a2s. c o m String invokeName = StringUtils.join(new String[] { "get", StringUtils.capitalize(fieldName) }); try { Object value = MethodUtils.invokeMethod(obj, invokeName, new Object[0]); if (null != value) list.add(StringUtils.join(new String[] { paramName, String.valueOf(value) }, "=")); } catch (NoSuchMethodException e) { LOGGER.warn("NoSuchMethod-" + invokeName); } catch (IllegalAccessException e) { LOGGER.warn("IllegalAccess-" + invokeName); } catch (InvocationTargetException e) { LOGGER.warn("InvocationTarget-" + invokeName); } } if (sort) Collections.sort(list, (null != comparator) ? comparator : String.CASE_INSENSITIVE_ORDER); for (String item : list) { rst.append(item).append(jointChar); } return StringUtils.removeEnd(rst.toString(), jointChar); }
From source file:org.bits4j.samples.SimpleUpload.java
/** * The argument is the URL for the upload location of the BITS server. If * none is provided, the url http://localhost/upload-dir is used. * /*w w w .j ava 2 s .c om*/ * @param args */ public static void main(String[] args) { String url = localHost; if (args.length == 0) { System.out.println("URL is not provided using:" + url); } else { url = args[0]; } // just making sure that there is an ending / url = StringUtils.removeEnd(url, "/") + "/"; try { // BitsHttpClient extends apaches HttpClient BitsHttpClient client = new BitsHttpClient(); client.setAckHeaderHandler(new AckHeaderHandlerImpl()); /* * Needed for Basic Authentication against http (not https). */ /* Credentials defaultcreds = new UsernamePasswordCredentials( userName, password); client.getState() .setCredentials( new AuthScope(serverDomainOrIpAddress, port80or443, "realm"), defaultcreds); //preemtive is required for the current bits4j code base. client.getParams().setAuthenticationPreemptive(true); */ // Create a BITS Session String bitsSessionId = null; String contentName = "text.txt"; String contentUrl = url + contentName; BitsPostMethod bitsPost = new BitsPostMethod(contentUrl); bitsPost.setRequestHeader(Constants.BITS_PACKET_TYPE, Constants.CREATE_SESSION); bitsPost.setRequestHeader(Constants.BITS_SUPPORTED_PROTOCOLS, Constants.BITS_1_5_UPLOAD_PROTOCAL_GUID); bitsPost.setRequestHeader(Constants.USER_AGENT, "My BITS Client"); bitsPost.setRequestHeader(Constants.CONTENT_NAME, contentName); bitsPost.setRequestHeader(Constants.CONTENT_LENGTH, "0"); client.executeMethod(bitsPost); // get the BITS server assigned Session Id bitsSessionId = ((Header) bitsPost.getResponseHeader(Constants.BITS_SESSION_ID)).getValue(); bitsPost.releaseConnection(); // Send Fragment to the BITS Server. bitsPost = new BitsPostMethod(contentUrl); bitsPost.setRequestHeader(Constants.BITS_SESSION_ID, bitsSessionId); String bytesRead = "my very small content of the file"; ByteArrayRequestEntity byteArrayRequestEntity = new ByteArrayRequestEntity(bytesRead.getBytes()); bitsPost.setRequestHeader(Constants.BITS_PACKET_TYPE, Constants.FRAGMENT); bitsPost.setRequestHeader(Constants.USER_AGENT, "My BITS Client"); bitsPost.setRequestHeader(Constants.CONTENT_NAME, contentName); bitsPost.setRequestHeader(Constants.CONTENT_LENGTH, String.valueOf(bytesRead.getBytes().length)); // Content-Range: bytes start-(bytesReat-1)/totalFileSize StringBuilder contentRange = new StringBuilder("bytes ").append("0").append("-") .append(String.valueOf((bytesRead.getBytes().length) - 1)).append("/") .append(bytesRead.getBytes().length); bitsPost.setRequestHeader(Constants.CONTENT_RANGE, contentRange.toString()); bitsPost.setRequestEntity(byteArrayRequestEntity); client.executeMethod(bitsPost); // Close the session bitsPost = new BitsPostMethod(contentUrl); bitsPost.setRequestHeader(Constants.BITS_SESSION_ID, bitsSessionId); bitsPost.setRequestHeader(Constants.BITS_PACKET_TYPE, Constants.CLOSE_SESSION); bitsPost.setRequestHeader(Constants.USER_AGENT, "My BITS Client"); bitsPost.setRequestHeader(Constants.CONTENT_NAME, contentName); bitsPost.setRequestHeader(Constants.CONTENT_LENGTH, "0"); client.executeMethod(bitsPost); // There should now be a file called text.txt on the BITS server // with the content "my very small content of the file" // You should be able to down load it in a browser with the url // defined by content above. } catch (Throwable t) { t.printStackTrace(); } }
From source file:org.caleydo.core.internal.startup.LoadSampleProjectStartupAddon.java
@Override public Composite create(Composite parent, final WizardPage page, Listener listener) { SelectionListener l = new SelectionAdapter() { @Override/*ww w .jav a2s.co m*/ public void widgetSelected(SelectionEvent e) { selectedChoice = (URL) ((Button) e.getSource()).getData(); // page.setPageComplete(true); } }; ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL); scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); scrolledComposite.setExpandVertical(true); scrolledComposite.setExpandHorizontal(true); Composite g = new Composite(scrolledComposite, SWT.NONE); g.setLayout(new GridLayout(1, false)); Button first = null; for (IConfigurationElement elem : RegistryFactory.getRegistry() .getConfigurationElementsFor(EXTENSION_POINT)) { String name = elem.getAttribute("name"); String url = elem.getAttribute("url").replace("DATA_URL_PREFIX", StringUtils.removeEnd(GeneralManager.DATA_URL_PREFIX, "/")); String description = elem.getAttribute("description"); if (first == null) first = createSample(url, name, description, g, l, true, listener); else createSample(url, name, description, g, l, false, listener); } if (selectedChoice == null && first != null) { first.setSelection(true); selectedChoice = (URL) first.getData(); } scrolledComposite.setContent(g); scrolledComposite.setMinSize(g.computeSize(500, SWT.DEFAULT)); return scrolledComposite; }
From source file:org.caleydo.core.view.opengl.layout2.internal.SandBoxLibraryLoader.java
/** * extract the given library of the classpath and put it to a temporary file *//* w w w .jav a 2 s . c o m*/ public static File toTemporaryFile(String libName) throws IOException { // convert to native library name libName = System.mapLibraryName(libName); if (SystemUtils.IS_OS_MAC_OSX) libName = StringUtils.replace(libName, ".dylib", ".jnilib"); // create String extension = Files.getFileExtension(libName); File file = File.createTempFile(StringUtils.removeEnd(libName, extension), "." + extension); file.deleteOnExit(); URL res = SandBoxLibraryLoader.class.getResource("/" + libName); if (res == null) throw new FileNotFoundException("can't extract: " + libName); try (InputStream in = res.openStream(); OutputStream to = new BufferedOutputStream(new FileOutputStream(file))) { ByteStreams.copy(in, to); } catch (IOException e) { System.err.println("can't extract: " + libName); e.printStackTrace(); throw new FileNotFoundException("can't extract: " + libName); } return file; }
From source file:org.caleydo.view.bicluster.internal.loading.BiClusterStartupAddon.java
private String getProjectName() { String xFileName = xFile.getName(); String name = xFileName.substring(0, xFileName.lastIndexOf(".")); name = StringUtils.removeEnd(name, "_X"); return name;// w ww.j a va 2s .c o m }
From source file:org.caleydo.view.bicluster.internal.loading.BiClusterStartupAddon.java
/** *//* w ww.j a v a2s. c o m*/ private void inferFromX() { final File p = xFile.getParentFile(); final String base = StringUtils.removeEnd(xFile.getName(), "_X.csv"); if (!isValid(xFile)) lFile = new File(p, base + "_X.csv"); if (!isValid(lFile)) lFile = new File(p, base + "_L.csv"); if (!isValid(zFile)) zFile = new File(p, base + "_Z.csv"); if (!isValid(chemicalFile)) chemicalFile = new File(p, base + "_chemicalClusters.csv"); if (!isValid(thresholdsFile)) thresholdsFile = new File(p, base + "_thresholds.csv"); }