List of usage examples for org.apache.commons.lang StringUtils substringAfter
public static String substringAfter(String str, String separator)
Gets the substring after the first occurrence of a separator.
From source file:com.hs.mail.container.config.Config.java
public void afterPropertiesSet() throws Exception { dataDirectory = getFileProperty("data_directory", "${app.home}" + File.separator + "data"); console.info("Data directory is: " + dataDirectory.getCanonicalPath()); tempDirectory = getFileProperty("temp_directory", "${app.home}" + File.separator + "temp"); console.info("Temp directory is: " + tempDirectory.getCanonicalPath()); spoolDirectory = getFileProperty("queue_directory", "${app.home}" + File.separator + "spool"); console.info("Spool directory is: " + spoolDirectory.getCanonicalPath()); authScheme = getProperty("auth_scheme", null); console.info("Authentication scheme is " + ((authScheme != null) ? authScheme : "not specified")); String fields = getProperty("default_cache_fields", DEF_CACHE_FIELDS); defaultCacheFields = buildDefaultCacheFields(StringUtils.split(fields, ',')); long quota = getNumberProperty("default_quota", 0); defaultQuota = quota * 1024 * 1024;/*from ww w . ja v a 2 s. c o m*/ console.info("Default quota is: " + quota + "MB"); hostName = getProperty("myhostname", null); if (null == hostName) { try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException ex) { hostName = "localhost"; } } console.info("Local host is: " + hostName); String domain = getProperty("mydomain", null); if (null == domain) { domains = new String[] { StringUtils.substringAfter(hostName, ".") }; } else { domains = StringUtils.split(domain, ","); } for (int i = 0; i < domains.length; i++) { console.info("Handling mail for: " + domains[i]); } String networks = getProperty("mynetworks", "0.0.0.0/0.0.0.0"); authorizedNetworks = new InetAddressMatcher(networks); console.info("SMTP relaying is allowded to: " + networks); helloName = getProperty("smtp_helo_name", hostName); postmaster = getProperty("postmaster", "postmaster"); if (postmaster.indexOf('@') < 0) { String domainName = null; for (int i = 0; i < domains.length; i++) { String serverName = domains[i].toLowerCase(Locale.US); if (!"localhost".equals(serverName)) { domainName = serverName; } } postmaster = postmaster + "@" + (domainName != null ? domainName : hostName); } console.info("Postmaster address is: " + postmaster); maxMessageSize = getNumberProperty("message_size_limit", 10240000); console.info("Maximum message size is: " + maxMessageSize); maxRcpt = (int) getNumberProperty("smtp_recipient_limit", 0); console.info("Maximun recipients count is: " + maxRcpt); saslAuthEnabled = getBooleanProperty("smtp_sasl_auth_enable", false); if (initData) { FileUtils.forceMkdir(dataDirectory); FileUtils.forceMkdir(tempDirectory); FileUtils.forceMkdir(spoolDirectory); FileUtils.forceMkdir(getSnapshotDirectory()); buildSSLContext(); } }
From source file:jp.ac.tokushima_u.is.ll.common.orm.hibernate.HibernateDao.java
/** * count???HQL???????/*from w ww . j a v a2s . co m*/ * * ?????HQL????????HQL??count??????? */ protected long countHqlResult(final String hql, final Map<String, Object> values) { String fromHql = hql; //select?order by?count????,??? fromHql = "from " + StringUtils.substringAfter(fromHql, "from"); fromHql = StringUtils.substringBefore(fromHql, "order by"); String countHql = "select count(*) " + fromHql; try { Long count = findUnique(countHql, values); return count; } catch (Exception e) { throw new RuntimeException("hql can't be auto count, hql is:" + countHql, e); } }
From source file:edu.monash.merc.system.remote.FTPFileGetter.java
/** * Issue the FTP MDTM command (not supported by all servers to retrieve the last modification time of a file. * The modification string should be in the ISO 3077 form "YYYYMMDDhhmmss(.xxx)?". * The timestamp represented should also be in GMT, but not all FTP servers honour this. * * @param remoteFile The file path to query. * @return A string representing the last file modification time in YYYYMMDDhhmmss format. *///from w w w .ja v a2 s. c om public String getLastModifiedTime(String remoteFile) { try { String replyCode = getModificationTime(remoteFile); String tempTime = StringUtils.substringAfter(replyCode, String.valueOf(FTPReply.FILE_STATUS)); return StringUtils.trim(tempTime); } catch (Exception ex) { throw new DMFTPException(ex); } }
From source file:adalid.util.velocity.BaseBuilder.java
private void createBinaryFilePropertiesFile(String source, String target) { List<String> lines = new ArrayList<>(); String properties = source.replace(projectFolderPath, velocityPlatformsTargetFolderPath) + ".properties"; String folder = StringUtils.substringBeforeLast(properties, FS); String template = StringUtils.substringAfter(target, velocityFolderPath + FS).replace(FS, "/"); String path = StringUtils.substringBeforeLast(StringUtils.substringAfter(source, projectFolderPath), FS) .replace(FS, "/").replace(project, PROJECT_ALIAS); path = replaceAliasWithRootFolderName(path); path = finalisePath(path);//from w w w .ja v a 2 s . c o m String file = StringUtils.substringAfterLast(source, FS).replace(project, PROJECT_ALIAS); lines.add("template = " + template); lines.add("template-type = document"); lines.add("path = " + path); lines.add("file = " + file); lines.add("preserve = true"); FilUtils.mkdirs(folder); if (write(properties, lines, WINDOWS_CHARSET)) { propertiesFilesCreated++; } }
From source file:com.google.gdt.eclipse.designer.util.Utils.java
/** * Get absolute path to the gwt-dev-windows.jar or gwt-dev-linux.jar * //from ww w. jav a 2s .c o m * @param project * optional GWT {@link IProject}, if not <code>null</code>, then project-specific * gwt-user.jar may be returned; if <code>null</code>, then workspace-global one. */ public static IPath getDevLibPath(IProject project) { // try to use location of gwt-user.jar { String gwtLocation = getGWTLocation(project); // Maven if (gwtLocation.contains("/gwt/gwt-user/")) { String gwtFolder = StringUtils.substringBefore(gwtLocation, "/gwt-user/"); String versionString = StringUtils.substringAfter(gwtLocation, "/gwt/gwt-user/"); String devFolder = gwtFolder + "/gwt-dev/" + versionString; String devFileName = "gwt-dev-" + versionString + ".jar"; Path path = new Path(devFolder + "/" + devFileName); if (path.toFile().exists()) { return path; } } // gwt-dev in same folder as gwt-user.jar { IPath path = getDevLibPath(gwtLocation); if (path.toFile().exists()) { return path; } } } // use gwt-dev.jar from default GWT location { String gwtLocation = Activator.getGWTLocation(); return getDevLibPath(gwtLocation); } }
From source file:com.amalto.core.metadata.ClassRepository.java
private TypeMetadata loadClass(Class clazz) { String typeName = getTypeName(clazz); if (getType(typeName) != null) { // If already defined return it. return getType(typeName); } else if (getNonInstantiableType(StringUtils.EMPTY, typeName) != null) { return getNonInstantiableType(StringUtils.EMPTY, typeName); }/*from www .ja v a 2 s .com*/ entityToJavaClass.put(typeName, clazz); if (Map.class.isAssignableFrom(clazz)) { return MAP_TYPE; } if (ArrayListHolder.class.equals(clazz)) { typeName = typeName + listCounter++; } boolean isEntity = typeStack.isEmpty(); ComplexTypeMetadata classType = new ComplexTypeMetadataImpl(StringUtils.EMPTY, typeName, isEntity); addTypeMetadata(classType); typeStack.push(classType); String keyFieldName = ""; //$NON-NLS-1$ if (isEntity && ObjectPOJO.class.isAssignableFrom(clazz)) { SimpleTypeFieldMetadata keyField = new SimpleTypeFieldMetadata(typeStack.peek(), true, false, true, "unique-id", //$NON-NLS-1$ STRING, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), StringUtils.EMPTY); keyField.setData(LINK, "PK/unique-id"); //$NON-NLS-1$ classType.addField(keyField); } else if (isEntity) { keyFieldName = "unique-id"; //$NON-NLS-1$ } // Class is abstract / interface: load sub classes if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) { Iterable<Class> subClasses = getSubclasses(clazz); ComplexTypeMetadata superType = typeStack.peek(); if (superType.isInstantiable()) { typeStack.clear(); } for (Class subClass : subClasses) { TypeMetadata typeMetadata = loadClass(subClass); typeMetadata.setInstantiable(superType.isInstantiable()); typeMetadata.addSuperType(superType); } if (superType.isInstantiable()) { typeStack.push(superType); } } // Analyze methods Method[] classMethods = getMethods(clazz); for (Method declaredMethod : classMethods) { if (!Modifier.isStatic(declaredMethod.getModifiers())) { if (isBeanMethod(declaredMethod) && isClassMethod(clazz, declaredMethod)) { String fieldName = getName(declaredMethod); if (typeStack.peek().hasField(fieldName)) { continue; // TODO Avoid override of fields (like PK) } Class<?> returnType = declaredMethod.getReturnType(); FieldMetadata newField; boolean isMany = false; boolean isKey = keyFieldName.equals(fieldName); if (Iterable.class.isAssignableFrom(returnType)) { returnType = listItemType != null ? listItemType : getListItemClass(declaredMethod, returnType); listItemType = null; isMany = true; } else if (ArrayListHolder.class.isAssignableFrom(returnType)) { listItemType = getListItemClass(declaredMethod, returnType); isMany = false; } else if (Map.class.isAssignableFrom(returnType)) { isMany = true; } else if (returnType.isArray()) { isMany = true; returnType = ((Class) returnType.getComponentType()); } else if (returnType.getName().startsWith("org.w3c.")) { //$NON-NLS-1$ // TODO Serialized XML to string column continue; } else if (Class.class.equals(returnType)) { continue; } else if (returnType.getPackage() != null && returnType.getPackage().getName().startsWith("java.io")) { //$NON-NLS-1$ continue; } if (returnType.isPrimitive() || returnType.getName().startsWith(JAVA_LANG_PREFIX)) { String fieldTypeName = returnType.getName().toLowerCase(); if (fieldTypeName.startsWith(JAVA_LANG_PREFIX)) { fieldTypeName = StringUtils.substringAfter(fieldTypeName, JAVA_LANG_PREFIX); } TypeMetadata fieldType; if (Types.BYTE.equals(fieldTypeName) && isMany) { fieldType = new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, Types.BASE64_BINARY); } else { fieldType = new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, fieldTypeName); } newField = new SimpleTypeFieldMetadata(typeStack.peek(), isKey, isMany, isKey, fieldName, fieldType, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), StringUtils.EMPTY); LongString annotation = declaredMethod.getAnnotation(LongString.class); if (Types.STRING.equals(fieldTypeName) && annotation != null) { fieldType.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(Integer.MAX_VALUE)); if (annotation.preferLongVarchar()) { fieldType.setData(LongString.PREFER_LONGVARCHAR, Boolean.TRUE); } } } else { ComplexTypeMetadata fieldType; if (Map.class.isAssignableFrom(returnType)) { fieldType = MAP_TYPE; } else { fieldType = (ComplexTypeMetadata) loadClass(returnType); } if (!isEntity || !fieldType.isInstantiable()) { newField = new ContainedTypeFieldMetadata(typeStack.peek(), isMany, false, fieldName, new SoftTypeRef(this, StringUtils.EMPTY, fieldType.getName(), false), Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), StringUtils.EMPTY); } else { newField = new ReferenceFieldMetadata(typeStack.peek(), false, isMany, false, fieldName, fieldType, fieldType.getField("unique-id"), //$NON-NLS-1$ Collections.<FieldMetadata>emptyList(), StringUtils.EMPTY, true, false, STRING, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), StringUtils.EMPTY, StringUtils.EMPTY); } } typeStack.peek().addField(newField); } } } typeStack.peek().addField(new SimpleTypeFieldMetadata(typeStack.peek(), false, false, false, "digest", //$NON-NLS-1$ new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, Types.STRING), Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList(), StringUtils.EMPTY)); return typeStack.pop(); }
From source file:eionet.cr.util.FolderUtil.java
/** * Returns the path after the app home URL. For example if uri is "http://127.0.0.1:8080/cr/abc" the result is "abc". * * @param uri/*from ww w .j a v a 2 s . c om*/ * @return String */ public static String extractAclPath(String uri) { String appHome = GeneralConfig.getRequiredProperty(GeneralConfig.APPLICATION_HOME_URL); return StringUtils.substringAfter(uri, appHome); }
From source file:com.prowidesoftware.swift.model.field.SwiftParseUtils.java
/** * Split components of a line using the parameter separator and returns the third token found or <code>null</code> if * third component is missing. Two adjacent separators are NOT treated as one. The third component is assumed as the * last one so its content may have additional separators if present.<br /> * Examples with slash as separator:<ul> * <li>for the literal "abc/def//ghi" will return null.</li> * <li>for the literal "abc/foo" will return "null".</li> * <li>for the literal "abc/def/foo" will return "foo".</li> * <li>for the literal "abc/def/foo/ghi" will return "foo/ghi".</li> * </ul>// ww w . j a v a 2 s .c o m * * @param line * @param separator * @return s */ public static String getTokenThirdLast(final String line, final String separator) { String result = null; final String s1 = getTokenSecondLast(line, separator); if (StringUtils.isNotBlank(s1)) { result = StringUtils.substringAfter(s1, separator); if (StringUtils.isBlank(result)) { result = null; } } return result; }
From source file:com.amalto.core.delegator.IItemCtrlDelegator.java
public ArrayList<String> viewSearch(DataClusterPOJOPK dataClusterPOJOPK, ViewPOJOPK viewPOJOPK, IWhereItem whereItem, String orderBy, String direction, int start, int limit) throws XtentisException { try {/*from w w w .j av a 2 s.c o m*/ ViewPOJO view = getViewPOJO(viewPOJOPK); whereItem = Util.fixWebConditions(whereItem, getLocalUser().getUserXML()); // Create an ItemWhere which combines the search and and view wheres ArrayList<IWhereItem> conditions = view.getWhereConditions().getList(); // fix conditions: value of condition do not generate xquery. Util.fixConditions(conditions); // Set User Property conditions. if (Util.isContainUserProperty(conditions)) { Util.updateUserPropertyCondition(conditions, getLocalUser().getUserXML()); } IWhereItem fullWhere = getFullWhereCondition(whereItem, conditions); // Add Filters from the Roles ILocalUser user = getLocalUser(); HashSet<String> roleNames = user.getRoles(); String objectType = "View"; //$NON-NLS-1$ ArrayList<IWhereItem> roleWhereConditions = new ArrayList<IWhereItem>(); for (String roleName : roleNames) { if (SecurityConfig.isSecurityPermission(roleName)) { continue; } // load Role RolePOJO role = ObjectPOJO.load(RolePOJO.class, new RolePOJOPK(roleName)); // get Specifications for the View Object RoleSpecification specification = role.getRoleSpecifications().get(objectType); if (specification != null) { if (!specification.isAdmin()) { Set<String> regexIds = specification.getInstances().keySet(); for (String regexId : regexIds) { if (viewPOJOPK.getIds()[0].matches(regexId)) { HashSet<String> parameters = specification.getInstances().get(regexId) .getParameters(); for (String marshaledWhereCondition : parameters) { if (marshaledWhereCondition == null || marshaledWhereCondition.trim().length() == 0) { continue; } WhereCondition whereCondition = RoleWhereCondition .parse(marshaledWhereCondition).toWhereCondition(); String conditionValue = whereCondition.getRightValueOrPath(); if ((conditionValue != null && conditionValue.length() > 0) || WhereCondition.EMPTY_NULL.equals(whereCondition.getOperator())) { roleWhereConditions.add(whereCondition); } } } } } } } // add collected additional conditions if (roleWhereConditions.size() > 0) { // Set User Property conditions. if (Util.isContainUserProperty(roleWhereConditions)) { Util.updateUserPropertyCondition(roleWhereConditions, getLocalUser().getUserXML()); } IWhereItem normalizedRolesConditions = normalizeConditions(roleWhereConditions); if (fullWhere == null) { fullWhere = normalizedRolesConditions; } else { WhereAnd wAnd = new WhereAnd(); wAnd.add(fullWhere); wAnd.add(normalizedRolesConditions); fullWhere = wAnd; } } // Find revision id for type String typeName = view.getSearchableBusinessElements().getList().get(0).split("/")[0]; //$NON-NLS-1$ // Try to get storage for revision Server server = ServerContext.INSTANCE.get(); String dataModelName = dataClusterPOJOPK.getUniqueId(); StorageAdmin storageAdmin = server.getStorageAdmin(); Storage storage = storageAdmin.get(dataModelName, storageAdmin.getType(dataModelName)); MetadataRepository repository = storage.getMetadataRepository(); boolean isStaging = storage.getType() == StorageType.STAGING; // Build query (from 'main' type) ComplexTypeMetadata type = repository.getComplexType(typeName); if (type == null) { throw new IllegalArgumentException( "Type '" + typeName + "' does not exist in data cluster '" + dataModelName //$NON-NLS-1$ //$NON-NLS-2$ + "'."); //$NON-NLS-1$ } UserQueryBuilder qb = UserQueryBuilder.from(type); // Select fields ArrayListHolder<String> viewableBusinessElements = view.getViewableBusinessElements(); for (String viewableBusinessElement : viewableBusinessElements.getList()) { String viewableTypeName = StringUtils.substringBefore(viewableBusinessElement, "/"); //$NON-NLS-1$ String viewablePath = StringUtils.substringAfter(viewableBusinessElement, "/"); //$NON-NLS-1$ if (viewablePath.isEmpty()) { throw new IllegalArgumentException("View element '" + viewableBusinessElement //$NON-NLS-1$ + "' is invalid: no path to element."); //$NON-NLS-1$ } ComplexTypeMetadata viewableType = repository.getComplexType(viewableTypeName); List<TypedExpression> fields = UserQueryHelper.getFields(viewableType, viewablePath); for (TypedExpression field : fields) { if (isNeedToAddExplicitly(isStaging, field)) { qb.select(field); } } } qb.select(repository.getComplexType(typeName), "../../taskId"); //$NON-NLS-1$ if (isStaging) { qb.select(repository.getComplexType(typeName), "$staging_status$"); //$NON-NLS-1$ qb.select(repository.getComplexType(typeName), "$staging_error$"); //$NON-NLS-1$ qb.select(repository.getComplexType(typeName), "$staging_source$"); //$NON-NLS-1$ } // Condition and paging qb.where(UserQueryHelper.buildCondition(qb, fullWhere, repository)); qb.start(start < 0 ? 0 : start); // UI can send negative start index qb.limit(limit); // Order by if (orderBy != null) { ComplexTypeMetadata orderByType = repository .getComplexType(StringUtils.substringBefore(orderBy, "/")); //$NON-NLS-1$ String orderByFieldName = StringUtils.substringAfter(orderBy, "/"); //$NON-NLS-1$ List<TypedExpression> fields = UserQueryHelper.getFields(orderByType, orderByFieldName); OrderBy.Direction queryDirection; if ("ascending".equals(direction) //$NON-NLS-1$ || "NUMBER:ascending".equals(direction) //$NON-NLS-1$ || "ASC".equals(direction)) { //$NON-NLS-1$ queryDirection = OrderBy.Direction.ASC; } else { queryDirection = OrderBy.Direction.DESC; } for (TypedExpression field : fields) { qb.orderBy(field, queryDirection); } } // Get records ArrayList<String> resultsAsString = new ArrayList<String>(); try { storage.begin(); StorageResults results = storage.fetch(qb.getSelect()); resultsAsString.add("<totalCount>" + results.getCount() + "</totalCount>"); //$NON-NLS-1$ //$NON-NLS-2$ DataRecordWriter writer = new ViewSearchResultsWriter(); ByteArrayOutputStream output = new ByteArrayOutputStream(); for (DataRecord result : results) { try { writer.write(result, output); } catch (IOException e) { throw new XmlServerException(e); } String document = new String(output.toByteArray(), Charset.forName("UTF-8")); //$NON-NLS-1$ resultsAsString.add(document); output.reset(); } storage.commit(); } catch (Exception e) { storage.rollback(); throw new XmlServerException(e); } return resultsAsString; } catch (XtentisException e) { throw (e); } catch (Exception e) { String err = "Unable to single search: " + ": " + e.getClass().getName() + ": " //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + e.getLocalizedMessage(); LOGGER.error(err, e); throw new XtentisException(err, e); } }
From source file:info.magnolia.cms.servlets.EntryServlet.java
/** * Redirect based on the mapping in config/server/.node.xml * @param request HttpServletRequest/* ww w . ja va 2 s .c o m*/ * @param response HttpServletResponse * @return <code>true</code> if request has been redirected, <code>false</code> otherwise */ private boolean redirect(HttpServletRequest request, HttpServletResponse response) { String uri = this.getURIMap(request); if (StringUtils.isNotEmpty(uri)) { if (!response.isCommitted()) { if (uri.startsWith("redirect:")) { try { response.sendRedirect( request.getContextPath() + StringUtils.substringAfter(uri, "redirect:")); } catch (IOException e) { log.error("Failed to redirect to {}:{}", //$NON-NLS-1$ new Object[] { uri, e.getMessage() }); } } else { try { request.getRequestDispatcher(uri).forward(request, response); } catch (Exception e) { log.error("Failed to forward to {} - {}:{}", //$NON-NLS-1$ new Object[] { uri, ClassUtils.getShortClassName(e.getClass()), e.getMessage() }); } } } else { log.warn("Response is already committed, cannot forward to {} (original URI was {})", //$NON-NLS-1$ uri, request.getRequestURI()); } return true; } return false; }