List of usage examples for org.apache.commons.lang StringUtils removeStart
public static String removeStart(String str, String remove)
Removes a substring only if it is at the begining of a source string, otherwise returns the source string.
From source file:org.artifactory.rest.common.util.RestUtils.java
/** * For backward compatability, if the build info version is less or equals to 2.0.11 * then we need to decode the request parameters since we used a different encoding technique in the past, * otherwise we simply let Jersey do the decoding for us * * @return True if we need to manually decode the request params, false otherwise *///from w ww .j av a 2 s .c o m public static boolean shouldDecodeParams(HttpServletRequest request) { String userAgent = request.getHeader(HttpHeaders.USER_AGENT); // If the request didn't come from build info let Jersey do the work if (StringUtils.isBlank(userAgent) || !userAgent.startsWith("ArtifactoryBuildClient/")) { return false; } String buildInfoVersion = StringUtils.removeStart(userAgent, "ArtifactoryBuildClient/"); boolean snapshotCondition = StringUtils.contains(buildInfoVersion, "SNAPSHOT"); boolean newVersionCondition = new DefaultArtifactVersion("2.0.11") .compareTo(new DefaultArtifactVersion(buildInfoVersion)) < 0; // Build info version is SNAPSHOT or newer than 2.0.11 we also let Jersey do the work if (snapshotCondition || newVersionCondition) { return false; } // If we got here it means client is using an old build-info (<= 2.0.11) we must manually decode the http params return true; }
From source file:org.artifactory.security.crypto.ArtifactoryBase64.java
public static byte[] extractBytes(String encrypted) { String stripped;/*from www . ja va 2s. c o m*/ if (encrypted.startsWith(ESCAPED_DEFAULT_ENCRYPTION_PREFIX)) { stripped = StringUtils.removeStart(encrypted, ESCAPED_DEFAULT_ENCRYPTION_PREFIX); } else if (encrypted.startsWith(getEncryptionPrefix())) { stripped = StringUtils.removeStart(encrypted, getEncryptionPrefix()); } else if (encrypted.length() > 125) { // The private and public key are big and have no {DESede} in the front but are full base64 stripped = encrypted; } else { return null; } if (Base64.isBase64(stripped)) { return fromBase64(stripped); } return null; }
From source file:org.artifactory.security.CryptoHelper.java
public static String decrypt(String encrypted, PrivateKey privateKey) { if (!isEncrypted(encrypted)) { throw new IllegalArgumentException("Input string is not encrypted"); }//from ww w. j ava2s . c o m String stripped = StringUtils.removeStart(encrypted, getEncryptionPrefix()); byte[] decoded = fromBase64(stripped); return bytesToString(cleanDecrypt((decoded), privateKey)); }
From source file:org.artifactory.security.CryptoHelper.java
public static String decryptSymmetric(String encrypted, SecretKey pbeKey) { try {//from www. j av a 2 s. c o m String stripped; if (encrypted.startsWith(ESCAPED_DEFAULT_ENCRYPTION_PREFIX)) { stripped = StringUtils.removeStart(encrypted, ESCAPED_DEFAULT_ENCRYPTION_PREFIX); } else { stripped = StringUtils.removeStart(encrypted, getEncryptionPrefix()); } byte[] decoded = fromBase64(stripped); Cipher pbeCipher = Cipher.getInstance(SYM_ALGORITHM); PBEParameterSpec pbeParamSpec = new PBEParameterSpec(PBE_SALT, PBE_ITERATION_COUNT); pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec); byte[] decryptedBytes = pbeCipher.doFinal(decoded); return bytesToString(decryptedBytes); } catch (Exception e) { throw new UnsupportedOperationException(e); } }
From source file:org.betaconceptframework.astroboa.configuration.RepositoryRegistry.java
private void loadConfigurationXml() throws MalformedURLException, IOException, Exception { if (StringUtils.isNotBlank(CmsConstants.ASTROBOA_CONFIGURATION_HOME_DIRECTORY)) { String configurationHomeDir = new String(CmsConstants.ASTROBOA_CONFIGURATION_HOME_DIRECTORY); if (CmsConstants.ASTROBOA_CONFIGURATION_HOME_DIRECTORY.startsWith("file:")) { configurationHomeDir = StringUtils.removeStart(configurationHomeDir, "file:"); }/* w w w . j a va 2s . c om*/ configuration = new File(configurationHomeDir + File.separator + ASTROBOA_CONFIGURATION_FILE); if (!configuration.exists()) { throw new Exception( "Astroboa Configuration " + ASTROBOA_CONFIGURATION_FILE + " could not be located in path " + configurationHomeDir + File.separator + ASTROBOA_CONFIGURATION_FILE); } } else { throw new Exception("Astroboa Configuration Home Directory is null. System property '" + CmsConstants.ASTROBOA_CONFIGURATION_HOME_DIRECTORY_SYSTEM_PROPERTY_NAME + "' does not exist or has no value "); } lastModified = configuration.lastModified(); }
From source file:org.betaconceptframework.astroboa.engine.jcr.renderer.ContentObjectFolderRenderer.java
private String getFullPath(Node contentObjectFolderNode, Type type) throws RepositoryException { if (type == null) { return ""; }//w w w .ja v a 2 s . co m switch (type) { case CONTENT_TYPE: case YEAR: return contentObjectFolderNode.getName(); case MONTH: case DAY: case HOUR: case MINUTE: case SECOND: //locate contentTypeFolder folder Node contentTypeFolder = contentObjectFolderNode.getParent(); while (contentTypeFolder != null && !contentTypeFolder.isNodeType(CmsBuiltInItem.GenericContentTypeFolder.getJcrName())) { contentTypeFolder = contentTypeFolder.getParent(); } if (contentTypeFolder == null) { return contentObjectFolderNode.getName(); } String path = StringUtils.remove(contentObjectFolderNode.getPath(), contentTypeFolder.getPath()); if (path != null && path.startsWith("/")) { return StringUtils.removeStart(path, "/"); } return path; default: break; } if (Type.MONTH == type) { return getMonthName(contentObjectFolderNode) + "/" + contentObjectFolderNode.getName(); } else if (Type.DAY == type) { return getDayPath(contentObjectFolderNode) + "/" + getMonthName(contentObjectFolderNode) + "/" + contentObjectFolderNode.getName(); } else if (Type.HOUR == type) { return getHourPath(contentObjectFolderNode) + "/" + getDayPath(contentObjectFolderNode) + "/" + getMonthName(contentObjectFolderNode) + "/" + contentObjectFolderNode.getName(); } else if (Type.MINUTE == type) { return getMinutePath(contentObjectFolderNode) + "/" + getHourPath(contentObjectFolderNode) + "/" + getDayPath(contentObjectFolderNode) + "/" + getMonthName(contentObjectFolderNode) + "/" + contentObjectFolderNode.getName(); } else if (Type.SECOND == type) { return contentObjectFolderNode.getParent().getParent().getParent().getParent().getParent().getName() + "/" + getMinutePath(contentObjectFolderNode) + "/" + getHourPath(contentObjectFolderNode) + "/" + getDayPath(contentObjectFolderNode) + "/" + getMonthName(contentObjectFolderNode) + "/" + contentObjectFolderNode.getName(); } // Type.YEAR == type || Type.CONTENT_TYPE == type return contentObjectFolderNode.getName(); }
From source file:org.betaconceptframework.astroboa.model.impl.query.criteria.TopicCriteriaImpl.java
@Override public void addOrderProperty(String propertyPath, Order order) { if (StringUtils.isNotBlank(propertyPath)) { //Reserved words //Label corresponds to CmsBuiltInItem.Localization.getJcrName() property if (StringUtils.equals("label", propertyPath)) { super.addOrderProperty(CmsBuiltInItem.Localization.getJcrName(), order); } else if (propertyPath.startsWith("label.")) { //user may have provided specific lang in order, for example label.en //Remove label prefix and use only lang code addOrderByLocale(StringUtils.removeStart(propertyPath, "label."), order); } else if (StringUtils.equals("name", propertyPath)) { //user requested ordering by topic name super.addOrderProperty(CmsBuiltInItem.Name.getJcrName(), order); } else if (StringUtils.equals("id", propertyPath)) { //user requested ordering by topic name super.addOrderProperty(CmsBuiltInItem.CmsIdentifier.getJcrName(), order); } else {/*from ww w . j av a 2s. c o m*/ super.addOrderProperty(propertyPath, order); } } }
From source file:org.betaconceptframework.astroboa.test.engine.service.RepositoryServiceTest.java
private File retrieveConfigurationFile() { String configurationHomeDir = new String(CmsConstants.ASTROBOA_CONFIGURATION_HOME_DIRECTORY); if (configurationHomeDir.startsWith("file:")) { configurationHomeDir = StringUtils.removeStart(configurationHomeDir, "file:"); }//w w w . j av a 2s . co m File configuration = new File(configurationHomeDir + File.separator + "repositories-conf.xml"); return configuration; }
From source file:org.bigmouth.nvwa.utils.xml.Dom4jEncoder.java
/** * ???XML<br>/*from www . j a v a 2 s . c o m*/ * ?{@linkplain org.bigmouth.nvwa.utils.Argument}?? * * <pre> * e.g. * * List<Object> list = new ArrayList<Object>(); * * Object obj1 = new Object(); * obj1.setName("Allen"); * obj1.setOld(18); * obj1.setHomeAddr("Hangzhou"); * obj1.setCellphon_no("10086"); * * Object obj2 = new Object(); * obj2.setName("Lulu"); * obj2.setOld(16); * obj2.setHomeAddr("Hangzhou"); * obj2.setCellphon_no("10086-1"); * * list.add(obj1); * list.add(obj2); * * String xml = Dom4jEncoder.encode(list, "/class", "student"); * System.out.println(xml); * * ------------------------- * | XML Result: * ------------------------- * * <class> * <student> * <name>Allen</Name> * <old>18</old> * <home_addr>Hangzhou</home_addr> * <cellphone__no>10086</cellphone__no> * </student> * <student> * <name>Lulu</Name> * <old>16</old> * <home_addr>Hangzhou</home_addr> * <cellphone__no>10086-1</cellphone__no> * </student> * </class> * * </pre> * * @param <T> * @param objs ??? * @param xpath * @param itemNodeName ?? * @return * @see org.bigmouth.nvwa.utils.Argument */ public static <T> String encode(List<T> objs, String xpath, String itemNodeName) { if (CollectionUtils.isEmpty(objs)) return null; if (StringUtils.isBlank(xpath) || StringUtils.equals(xpath, "/")) { throw new IllegalArgumentException("xpath cannot be blank or '/'!"); } Document doc = DocumentHelper.createDocument(); Element root = null; if (StringUtils.split(xpath, "/").length > 2) { root = DocumentHelper.makeElement(doc, xpath); } else { xpath = StringUtils.removeStart(xpath, "/"); root = doc.addElement(xpath); } for (Object obj : objs) { addElement(itemNodeName, root, obj); } return doc.asXML(); }
From source file:org.bigmouth.nvwa.zookeeper.addrs.file.FileAddressReader.java
@Override public String read() throws ReaderException { String filename = path;//from w w w. j a v a 2s . c o m if (StringUtils.isBlank(filename)) { filename = StringUtils .join(new String[] { PathUtils.appendEndFileSeparator(USER_HOME), DEFAULT_FILENAME }); } try { filename = StringUtils.removeStart(filename, PREFIX); String addrs = FileUtils.readFileToString(new File(filename)); if (StringUtils.isBlank(addrs)) throw new ReaderException("empty!"); return StringUtils.trim(addrs); } catch (FileNotFoundException e) { return null; } catch (IOException e) { throw new ReaderException(e); } }