Java Code Examples for org.apache.commons.lang.StringUtils#startsWith()

The following examples show how to use org.apache.commons.lang.StringUtils#startsWith() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModuleCfgProcessBuilder.java    From ymate-platform-v2 with Apache License 2.0 6 votes vote down vote up
public IModuleCfgProcessor build() {
    return new IModuleCfgProcessor() {
        @Override
        public Map<String, String> getModuleCfg(String moduleName) {
            Map<String, String> _cfgMap = __moduleCfgCaches.get(moduleName);
            if (_cfgMap == null) {
                _cfgMap = new HashMap<String, String>();
                if (__properties != null) {
                    // 提取模块配置
                    for (Object _key : __properties.keySet()) {
                        String _prefix = "ymp.configs." + moduleName + ".";
                        if (StringUtils.startsWith((String) _key, _prefix)) {
                            String _cfgKey = StringUtils.substring((String) _key, _prefix.length());
                            String _cfgValue = __properties.getProperty((String) _key);
                            //
                            _cfgMap.put(_cfgKey, _cfgValue);
                        }
                    }
                    __moduleCfgCaches.put(moduleName, _cfgMap);
                }
            }
            return _cfgMap;
        }
    };
}
 
Example 2
Source File: CommentCountParser.java    From sonar-ruby-plugin with MIT License 6 votes vote down vote up
public static int countLinesOfComment(File file) {
    int numComments = 0;
    LineIterator iterator = null;
    try {
        iterator = FileUtils.lineIterator(file);

        while (iterator.hasNext()) {
            String line = iterator.nextLine();
            if (StringUtils.startsWith(line.trim(), "#")) {
                numComments++;
            }
        }
    } catch (IOException e) {
        LOG.error("Error determining comment count for file " + file, e);
    } finally {
        LineIterator.closeQuietly(iterator);
    }

    return numComments;
}
 
Example 3
Source File: QuickFinder.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Adjusts the path on the field conversion to property to match the binding path prefix of the
 * given {@link org.kuali.rice.krad.uif.component.BindingInfo}.
 *
 * @param bindingInfo binding info instance to copy binding path prefix from
 */
protected void updateFieldConversions(BindingInfo bindingInfo) {
    Map<String, String> adjustedFieldConversions = new HashMap<String, String>();
    for (String fromField : fieldConversions.keySet()) {
        String toField = fieldConversions.get(fromField);

        if (!StringUtils.startsWith(toField, bindingInfo.getBindingPathPrefix())) {
            String adjustedToFieldPath = bindingInfo.getPropertyAdjustedBindingPath(toField);
            adjustedFieldConversions.put(fromField, adjustedToFieldPath);
        } else {
            adjustedFieldConversions.put(fromField, toField);
        }
    }

    this.fieldConversions = adjustedFieldConversions;
}
 
Example 4
Source File: AccountsReceivableLookupableHelperServiceImplBase.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Overridden to setup document number link for document number properties and add Rice Path prefix
 * to the URL where necessary (cases where the Lookupable is called from the KFS context instead of the Rice context).
 *
 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getInquiryUrl(org.kuali.rice.krad.bo.BusinessObject, java.lang.String)
 */
@Override
public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) {
    AnchorHtmlData inquiryHref = new AnchorHtmlData(KRADConstants.EMPTY_STRING, KRADConstants.EMPTY_STRING);

    if (KFSPropertyConstants.DOCUMENT_NUMBER.equals(propertyName) ){
        String baseUrl = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(KFSConstants.WORKFLOW_URL_KEY) + "/" + KFSConstants.DOC_HANDLER_ACTION;
        Properties parameters = new Properties();
        parameters.put(KFSConstants.PARAMETER_DOC_ID, ObjectUtils.getPropertyValue(bo, propertyName).toString());
        parameters.put(KFSConstants.PARAMETER_COMMAND, KFSConstants.METHOD_DISPLAY_DOC_SEARCH_VIEW);

        inquiryHref.setHref(UrlFactory.parameterizeUrl(baseUrl, parameters));
    } else {
        inquiryHref = (AnchorHtmlData)super.getInquiryUrl(bo, propertyName);
        if (StringUtils.startsWith(inquiryHref.getHref(), KRADConstants.INQUIRY_ACTION)) {
            inquiryHref.setHref(KFSConstants.RICE_PATH_PREFIX + inquiryHref.getHref());
        }
    }

    return inquiryHref;
}
 
Example 5
Source File: Purge.java    From APM with Apache License 2.0 6 votes vote down vote up
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);
      boolean isUsersPermission = parentPath.startsWith(context.getCurrentAuthorizable().getPath());
      if (StringUtils.startsWith(normalizedParentPath, normalizedPath) && !isUsersPermission) {
        RemoveAll removeAll = new RemoveAll(parentPath);
        ActionResult removeAllResult = removeAll.execute(context);
        if (Status.ERROR.equals(removeAllResult.getStatus())) {
          copyErrorMessages(removeAllResult, actionResult);
        }
      }
    }
  }
}
 
Example 6
Source File: CatMetricUtil.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * 根据metric的名字,返回写入cat上的key
 * @param spoutMetricName
 * @return
 */
public static String getCatMetricKey(String spoutMetricName){
    if(StringUtils.isBlank(spoutMetricName) 
            || !StringUtils.startsWith(spoutMetricName, CAT_METRIC_NAME_PREFIX)){
        return "default";
    }
    return StringUtils.substringAfter(spoutMetricName, CAT_METRIC_NAME_PREFIX);
    
}
 
Example 7
Source File: DateStampFilenameGenerator.java    From emissary with Apache License 2.0 5 votes vote down vote up
@Override
public String nextFileName() {
    String dateFileName = formatter.format(Instant.now());
    seq = StringUtils.startsWith(lastFileName, dateFileName) ? seq + 1 : 0;
    lastFileName = dateFileName;
    return dateFileName + String.format("%03d", seq) + identifier + fileSuffix;
}
 
Example 8
Source File: KimCommonUtils.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
public static boolean doesPropertyNameMatch(
        String requestedDetailsPropertyName,
        String permissionDetailsPropertyName) {
    if (StringUtils.isBlank(permissionDetailsPropertyName)) {
        return true;
    }
    return StringUtils.equals(requestedDetailsPropertyName, permissionDetailsPropertyName)
            || (StringUtils.startsWith(requestedDetailsPropertyName,permissionDetailsPropertyName+"."));
}
 
Example 9
Source File: TransLogUtil.java    From framework with Apache License 2.0 5 votes vote down vote up
/**
 * Description: <br>
 * 
 * @author 王伟<br>
 * @taskId <br>
 * @param target
 * @param method
 * @param e <br>
 */
public static void afterThrowing(final Object target, final Method method, final Throwable e) {
    NoTransLog noTransLog = target.getClass().getAnnotation(NoTransLog.class);
    if (noTransLog == null) {

        // 执行方法
        String methodName = getMethodSignature(method);
        if (!DEBUG_OPEN_FLAG || !StringUtils.startsWith(methodName, FRAMEWORK_PACKAGE)) {
            afterThrowing(methodName, e);
        }
    }
}
 
Example 10
Source File: LookupUtils.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Retrieves the value for the given parameter name to send as a lookup parameter.
 *
 * @param form form instance to retrieve values from
 * @param request request object to retrieve parameters from
 * @param lookupObjectClass data object class associated with the lookup, used to check whether the
 * value needs to be encyrpted
 * @param propertyName name of the property associated with the parameter, used to check whether the
 * value needs to be encrypted
 * @param parameterName name of the parameter to retrieve the value for
 * @return String parameter value or empty string if no value was found
 */
public static String retrieveLookupParameterValue(UifFormBase form, HttpServletRequest request,
        Class<?> lookupObjectClass, String propertyName, String parameterName) {
    // return a null value if it is secure
    if (KRADUtils.isSecure(propertyName, lookupObjectClass)) {
        LOG.warn("field name " + propertyName + " is a secure value and not returned in parameter result value");
        return null;
    }

    String parameterValue = "";

    // get literal parameter values first
    if (StringUtils.startsWith(parameterName, "'") && StringUtils.endsWith(parameterName, "'")) {
        parameterValue = StringUtils.substringBetween(parameterName, "'");
    } else if (parameterValue.startsWith(KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX
            + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER)) {
        parameterValue = StringUtils.removeStart(parameterValue, KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX
                + KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER);
    }
    // check if parameter is in request
    else if (request.getParameterMap().containsKey(parameterName)) {
        parameterValue = request.getParameter(parameterName);
    }
    // get parameter value from form object
    else {
        parameterValue = ObjectPropertyUtils.getPropertyValueAsText(form, parameterName);
    }

    return parameterValue;
}
 
Example 11
Source File: ServiceMappingContainer.java    From dubbo-plus with Apache License 2.0 5 votes vote down vote up
public void registerService(URL url, Class serviceType, Object impl) {
    String contextPath = url.getParameter(RestfulConstants.CONTEXT_PATH,"/");
    String path  =StringUtils.replaceOnce(url.getPath(),contextPath,"");
    if(StringUtils.startsWith(path,"/")){
        path = StringUtils.replaceOnce(path,"/","");
    }
    SERVICE_MAPPING.putIfAbsent(path,
            new ServiceHandler(url.getParameter(Constants.GROUP_KEY),
                    url.getParameter(Constants.VERSION_KEY),
                    serviceType,path,impl));
}
 
Example 12
Source File: CatMetricUtil.java    From jstorm with Apache License 2.0 5 votes vote down vote up
/**
 * 判断是否cat的metirc
 * @param dataPointName
 * @return
 */
public static boolean isCatMetric(String dataPointName){
    if(StringUtils.isBlank(dataPointName)){
        return false;
    }
    return StringUtils.startsWith(dataPointName, CAT_METRIC_NAME_PREFIX);
}
 
Example 13
Source File: DefaultGangliaMetricsReporter.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Looks up whether the metric name contains the given prefix keywords.
 * Note that the keywords are separated with comma as delimiter
 *
 * @param full the original metric name that to be compared with
 * @param prefixes the prefix keywords that are matched against with the metric name
 * @return boolean value that denotes whether the metric name starts with the given prefix
 */
protected boolean containsName(String full, String prefixes) {
    String[] prefixArray = StringUtils.split(prefixes, ",");
    for (String prefix : prefixArray) {
        if (StringUtils.startsWith(full, StringUtils.trimToEmpty(prefix))) {
            return true;
        }
    }
    return false;
}
 
Example 14
Source File: ClassWrapperRenderer.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
protected String abbreviatePackageUsingMappings(String clazz, SortedMap<String, String> abbreviations) {
  for (String s : abbreviations.keySet()) {
    if (StringUtils.startsWith(clazz,s)) {
      return StringUtils.replaceOnce(clazz, s, abbreviations.get(s));
    }
  }
  return clazz;
}
 
Example 15
Source File: GetDetailedWorkspaceCommand.java    From azure-devops-intellij with MIT License 4 votes vote down vote up
/**
 * Parses output for the workspace attributes
 * <p>
 * tf workspaces -format:detailed -collection:http://organization.visualstudio.com/ WorkspaceName
 * ===========================================================================================================================================================================================================
 * Workspace:   WorkspaceName
 * Owner:       John Smith
 * Computer:    computerName
 * Comment:     Workspace created through IntelliJ
 * Collection:  http://organization.visualstudio.com/
 * Permissions: Private
 * File Time:   Current
 * Location:    Local
 * File Time:   Current
 * <p>
 * Working folders:
 * <p>
 * $/WorkspaceName: /Users/JohnSmith/WorkspaceName
 *
 * @param stdout
 * @param stderr
 * @return
 */
@Override
public Workspace parseOutput(final String stdout, final String stderr) {
    super.throwIfError(stderr);

    // if for some reason no output is given return null
    if (StringUtils.isEmpty(stdout)) {
        return null;
    }

    final String[] output = getLines(stdout);
    String workspace = StringUtils.EMPTY;
    String owner = StringUtils.EMPTY;
    String computer = StringUtils.EMPTY;
    String comment = StringUtils.EMPTY;
    String location = StringUtils.EMPTY;
    String collection = StringUtils.EMPTY;
    final List<Workspace.Mapping> mappings = new ArrayList<Workspace.Mapping>();

    // the output should be in this order but just in case it changes we check the prefixes first
    int count = 0;
    while (count < output.length) {
        if (StringUtils.startsWith(output[count], WORKSPACE_PREFIX)) {
            workspace = StringUtils.removeStart(output[count], WORKSPACE_PREFIX).trim();
        } else if (StringUtils.startsWith(output[count], OWNER_PREFIX)) {
            owner = StringUtils.removeStart(output[count], OWNER_PREFIX).trim();
        } else if (StringUtils.startsWith(output[count], COMPUTER_PREFIX)) {
            computer = StringUtils.removeStart(output[count], COMPUTER_PREFIX).trim();
        } else if (StringUtils.startsWith(output[count], COMMENT_PREFIX)) {
            comment = StringUtils.removeStart(output[count], COMMENT_PREFIX).trim();
        } else if (StringUtils.startsWith(output[count], COLLECTION_PREFIX)) {
            collection = StringUtils.removeStart(output[count], COLLECTION_PREFIX).trim();
        } else if (StringUtils.startsWith(output[count], LOCATION_PREFIX)) {
            location = StringUtils.removeStart(output[count], LOCATION_PREFIX).trim();
        } else if (StringUtils.startsWith(output[count], MAPPING_PREFIX)) {
            count = count + 2;
            while (count < output.length && StringUtils.isNotEmpty(output[count])) {
                Workspace.Mapping mapping = getMapping(output[count]);
                if (mapping != null) {
                    mappings.add(mapping);
                }
                count++;
            }
        }
        count++;
    }
    return new Workspace(collection, workspace, computer, owner, comment, mappings, Workspace.Location.fromString(location));
}
 
Example 16
Source File: RangerPolicyRepository.java    From ranger with Apache License 2.0 4 votes vote down vote up
private List<? extends RangerPolicy.RangerPolicyItem> normalizeAndPrunePolicyItems(List<? extends RangerPolicy.RangerPolicyItem> policyItems, final String componentType) {
    if(CollectionUtils.isNotEmpty(policyItems)) {
        final String                        prefix       = componentType + AbstractServiceStore.COMPONENT_ACCESSTYPE_SEPARATOR;
        List<RangerPolicy.RangerPolicyItem> itemsToPrune = null;

        for (RangerPolicy.RangerPolicyItem policyItem : policyItems) {
            List<RangerPolicy.RangerPolicyItemAccess> policyItemAccesses = policyItem.getAccesses();

            if (CollectionUtils.isNotEmpty(policyItemAccesses)) {
                List<RangerPolicy.RangerPolicyItemAccess> accessesToPrune = null;

                for (RangerPolicy.RangerPolicyItemAccess access : policyItemAccesses) {
                    String accessType = access.getType();

                    if (StringUtils.startsWith(accessType, prefix)) {
                        String newAccessType = StringUtils.removeStart(accessType, prefix);

                        access.setType(newAccessType);
                    } else if (accessType.contains(AbstractServiceStore.COMPONENT_ACCESSTYPE_SEPARATOR)) {
                        if(accessesToPrune == null) {
                            accessesToPrune = new ArrayList<>();
                        }

                        accessesToPrune.add(access);
                    }
                }

                if(accessesToPrune != null) {
                    policyItemAccesses.removeAll(accessesToPrune);
                }

                if (policyItemAccesses.isEmpty() && !policyItem.getDelegateAdmin()) {
                    if(itemsToPrune == null) {
                        itemsToPrune = new ArrayList<>();
                    }

                    itemsToPrune.add(policyItem);

                    continue;
                }
            }

            if (policyItem instanceof RangerPolicy.RangerDataMaskPolicyItem) {
                RangerPolicyItemDataMaskInfo dataMaskInfo = ((RangerPolicy.RangerDataMaskPolicyItem) policyItem).getDataMaskInfo();
                String                       maskType     = dataMaskInfo.getDataMaskType();

                if (StringUtils.startsWith(maskType, prefix)) {
                    dataMaskInfo.setDataMaskType(StringUtils.removeStart(maskType, prefix));
                } else if (maskType.contains(AbstractServiceStore.COMPONENT_ACCESSTYPE_SEPARATOR)) {
                    if (itemsToPrune == null) {
                        itemsToPrune = new ArrayList<>();
                    }

                    itemsToPrune.add(policyItem);
                }
            }
        }

        if(itemsToPrune != null) {
            policyItems.removeAll(itemsToPrune);
        }
    }

    return policyItems;
}
 
Example 17
Source File: ScriptFinderImpl.java    From APM with Apache License 2.0 4 votes vote down vote up
private boolean isAbsolute(String path) {
  return StringUtils.startsWith(path, "/");
}
 
Example 18
Source File: AtlasTypeUtil.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
public static boolean isMapType(String typeName) {
    return StringUtils.startsWith(typeName, ATLAS_TYPE_MAP_PREFIX)
        && StringUtils.endsWith(typeName, ATLAS_TYPE_MAP_SUFFIX);
}
 
Example 19
Source File: UserProcessor.java    From symphonyx with Apache License 2.0 4 votes vote down vote up
/**
 * Updates user profiles.
 *
 * @param context the specified context
 * @param request the specified request
 * @param response the specified response
 * @throws Exception exception
 */
@RequestProcessing(value = "/settings/profiles", method = HTTPRequestMethod.POST)
@Before(adviceClass = {LoginCheck.class, CSRFCheck.class, UpdateProfilesValidation.class})
public void updateProfiles(final HTTPRequestContext context, final HttpServletRequest request, final HttpServletResponse response)
        throws Exception {
    context.renderJSON();

    final JSONObject requestJSONObject = (JSONObject) request.getAttribute(Keys.REQUEST);

    final String userRealName = requestJSONObject.optString(UserExt.USER_REAL_NAME);
    final String userTags = requestJSONObject.optString(UserExt.USER_TAGS);
    final String userURL = requestJSONObject.optString(User.USER_URL);
    final String userQQ = requestJSONObject.optString(UserExt.USER_QQ);
    final String userIntro = requestJSONObject.optString(UserExt.USER_INTRO);
    final String userAvatarURL = requestJSONObject.optString(UserExt.USER_AVATAR_URL);
    final String userTeam = requestJSONObject.optString(UserExt.USER_TEAM);
    final boolean userJoinPointRank = requestJSONObject.optBoolean(UserExt.USER_JOIN_POINT_RANK);
    final boolean userJoinUsedPointRank = requestJSONObject.optBoolean(UserExt.USER_JOIN_USED_POINT_RANK);

    final JSONObject user = userQueryService.getCurrentUser(request);

    user.put(UserExt.USER_REAL_NAME, userRealName);
    user.put(UserExt.USER_TAGS, userTags);
    user.put(User.USER_URL, userURL);
    user.put(UserExt.USER_QQ, userQQ);
    user.put(UserExt.USER_INTRO, userIntro.replace("<", "&lt;").replace(">", "&gt"));
    user.put(UserExt.USER_AVATAR_TYPE, UserExt.USER_AVATAR_TYPE_C_UPLOAD);
    user.put(UserExt.USER_TEAM, userTeam);
    user.put(UserExt.USER_JOIN_POINT_RANK,
            userJoinPointRank
                    ? UserExt.USER_JOIN_POINT_RANK_C_JOIN : UserExt.USER_JOIN_POINT_RANK_C_NOT_JOIN);
    user.put(UserExt.USER_JOIN_USED_POINT_RANK,
            userJoinUsedPointRank
                    ? UserExt.USER_JOIN_USED_POINT_RANK_C_JOIN : UserExt.USER_JOIN_USED_POINT_RANK_C_NOT_JOIN);

    if (Symphonys.getBoolean("qiniu.enabled")) {
        if (!StringUtils.startsWith(userAvatarURL, Symphonys.get("qiniu.domain"))) {
            user.put(UserExt.USER_AVATAR_URL, Symphonys.get("defaultThumbnailURL"));
        } else {
            user.put(UserExt.USER_AVATAR_URL, Symphonys.get("qiniu.domain") + "/avatar/" + user.optString(Keys.OBJECT_ID)
                    + "?" + new Date().getTime());
        }
    } else {
        user.put(UserExt.USER_AVATAR_URL, userAvatarURL);
    }

    try {
        userMgmtService.updateProfiles(user);

        context.renderTrueResult();
    } catch (final ServiceException e) {
        context.renderMsg(e.getMessage());
    }
}
 
Example 20
Source File: DefaultStellarAutoCompleter.java    From metron with Apache License 2.0 2 votes vote down vote up
/**
 * Is a given expression a built-in magic?
 * @param expression The expression.
 */
private boolean isMagic(String expression) {
  return StringUtils.startsWith(expression, "%");
}