List of usage examples for org.apache.commons.lang3 StringUtils startsWithIgnoreCase
public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix)
Case insensitive check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:org.auraframework.impl.clientlibrary.ClientLibraryDefImpl.java
/** * Client library must have name, type, and parent descriptor. * * @throws QuickFixException quick fix//from w w w . ja v a 2s . c o m */ @Override public void validateDefinition() throws QuickFixException { if (StringUtils.isBlank(this.name) && StringUtils.isBlank(this.url)) { throw new InvalidDefinitionException("Must have either a name or url", getLocation()); } if (this.type == null) { throw new InvalidDefinitionException("Missing required type", getLocation()); } if (this.parentDescriptor == null) { throw new InvalidDefinitionException("No parent for ClientLibraryDef", getLocation()); } if (StringUtils.isNotBlank(this.url)) { if (StringUtils.startsWithIgnoreCase(this.url, DefDescriptor.CSS_PREFIX + "://") || StringUtils.startsWithIgnoreCase(this.url, DefDescriptor.JAVASCRIPT_PREFIX + "://")) { if (!StringUtils.startsWithIgnoreCase(this.url, this.type.toString())) { throw new InvalidDefinitionException("ResourceDef type must match library type", getLocation()); } DefDescriptor<ResourceDef> resourceDesc = DefDescriptorImpl.getInstance(this.url, ResourceDef.class); if (!resourceDesc.exists()) { throw new InvalidDefinitionException("No resource named " + this.url + " found", getLocation()); } } else { // must have the same file extension as type if (!StringUtils.endsWithIgnoreCase(this.url, "." + this.type.toString())) { throw new InvalidDefinitionException("Url file extension must match type", getLocation()); } } } }
From source file:org.auraframework.impl.clientlibrary.ClientLibraryDefImpl.java
@Override public boolean shouldCombine() { // combine only when it's a readable resource return (StringUtils.startsWithIgnoreCase(this.url, DefDescriptor.CSS_PREFIX + "://") || StringUtils.startsWithIgnoreCase(this.url, DefDescriptor.JAVASCRIPT_PREFIX + "://")) || (StringUtils.isBlank(this.url) && this.combine); }
From source file:org.auraframework.impl.clientlibrary.ClientLibraryServiceImpl.java
/** * Get Combinable to allow getting contents * * @param clientLibrary client library/*from w w w . j a v a 2s . c om*/ * @return combinable * @throws QuickFixException */ private Combinable getCombinable(ClientLibraryDef clientLibrary) throws QuickFixException { String url = clientLibrary.getUrl(); Combinable combinable = null; if (StringUtils.isBlank(url)) { ClientLibraryResolver resolver = getResolver(clientLibrary); if (resolver != null && resolver.canCombine()) { // combinable resolver combinable = (Combinable) resolver; } } else if (StringUtils.startsWithIgnoreCase(url, DefDescriptor.CSS_PREFIX + "://") || StringUtils.startsWithIgnoreCase(url, DefDescriptor.JAVASCRIPT_PREFIX + "://")) { // if url is qualified name of DefDescriptor<ResourceDef> DefDescriptor<ResourceDef> descriptor = DefDescriptorImpl.getInstance(url, ResourceDef.class); if (descriptor.exists()) { ResourceDef def = descriptor.getDef(); if (def != null) { combinable = (Combinable) def; } } } return combinable; }
From source file:org.debux.webmotion.server.convention.DefaultConventionScan.java
/** * Scan the controllers by convention./*www . ja v a 2 s . c om*/ */ public List<ActionRule> scanControllers(Mapping mapping) { Collection<Class<?>> controllers = ReflectionUtils.getClassesBySuperClass(ConventionController.class); List<ActionRule> rules = new ArrayList<ActionRule>(controllers.size()); for (Class<?> controller : controllers) { Method[] methods = controller.getMethods(); for (Method method : methods) { Class<?> declaringClass = method.getDeclaringClass(); if (!declaringClass.equals(Object.class) && !declaringClass.equals(WebMotionController.class)) { ActionRule rule = new ActionRule(); rule.setMapping(mapping); rule.setLine(-1); rules.add(rule); String className = controller.getName(); String methodName = method.getName(); // Create action Action action = new Action(); action.setFullName(className + "." + methodName); action.setType(Action.Type.ACTION); rule.setAction(action); // Search http method String httpMethod = "*"; if (methodName.startsWith("create")) { httpMethod = HttpContext.METHOD_PUT; methodName = methodName.replaceFirst("create", ""); } else if (methodName.startsWith("get")) { httpMethod = HttpContext.METHOD_GET; methodName = methodName.replaceFirst("get", ""); } else if (methodName.startsWith("delete")) { httpMethod = HttpContext.METHOD_DELETE; methodName = methodName.replaceFirst("delete", ""); } else if (methodName.startsWith("update")) { httpMethod = HttpContext.METHOD_POST; methodName = methodName.replaceFirst("update", ""); } rule.setMethods(Arrays.asList(httpMethod)); // Create path List<FragmentUrl> url = new ArrayList<FragmentUrl>(); String simpleClassName = controller.getSimpleName(); Package controllerPackage = controller.getPackage(); if (controllerPackage != null) { String packageName = controllerPackage.getName(); String subPackageName = StringUtils.substringAfterLast(packageName, "."); if (!StringUtils.startsWithIgnoreCase(simpleClassName, subPackageName)) { url.addAll(createFragmentUrlList(subPackageName)); } } url.addAll(createFragmentUrlList(simpleClassName)); if (methodName.length() != 0) { url.addAll(createFragmentUrlList(methodName)); } rule.setRuleUrl(url); } } } return rules; }
From source file:org.dspace.rdf.RDFizer.java
protected void runCLI(String[] args) { // prepare CLI and parse arguments Options options = createOptions();//from www . j a v a 2 s. c o m CommandLineParser parser = new PosixParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (ParseException ex) { usage(options); System.err.println(); System.err.println(ex.getMessage()); log.fatal(ex); System.exit(1); } String[] remainingArgs = line.getArgs(); if (remainingArgs.length > 0) { this.usage(options); System.err.println(); StringBuilder builder = new StringBuilder(100); for (String argument : remainingArgs) { if (builder.length() > 0) builder.append(", "); builder.append(argument); } String argumentsLine = builder.toString().trim(); System.err.print("Cannot recognize the following argument"); if (remainingArgs.length >= 2) System.err.print("s"); System.err.println(": " + argumentsLine + "."); System.exit(1); } // set member variables depending on CLI arguments. if (line.hasOption("verbose")) { setVerbose(true); } if (line.hasOption("dry-run")) { setDryrun(true); } if (line.hasOption("stdout")) { setStdout(true); } // check mutual exclusive arguments if (line.hasOption("delete") && line.hasOption("delete-all")) { usage(options); System.err.println("\n\nYou cannot use the options --delete <handle> " + "and --delete-all together."); System.exit(1); } if (line.hasOption("convert-all") && (line.hasOption("delete") || line.hasOption("delete-all"))) { usage(options); System.err.println( "\n\nYou cannot use the option --convert-all " + "together with --delete or --delete-all."); System.exit(1); } if (line.hasOption("identifiers") && (line.hasOption("delete") || line.hasOption("delete-all"))) { usage(options); System.err.println("\n\nYou cannot use the option --identifiers <handle> " + "together with --delete or --delete-all."); System.exit(1); } if (line.hasOption("stdout") && (line.hasOption("delete") || line.hasOption("delete-all"))) { usage(options); System.err .println("\n\nYou cannot use the option --stdout together " + "with --delete or --deleta-all."); System.exit(1); } // Run commands depending on CLI arguments. // process help first to prevent further evaluation of given options. if (line.hasOption('h')) { usage(options); System.exit(0); } if (line.hasOption("delete")) { String[] identifiers = line.getOptionValues("delete"); for (String identifier : identifiers) { if (!StringUtils.startsWithIgnoreCase(identifier, "hdl:")) { if (!this.dryrun) { storage.delete(identifier); } if (this.verbose) { System.err.println("Deleted " + identifier + "."); } continue; } String handle = identifier.substring(4); log.debug("Trying to resolve identifier " + handle + "."); DSpaceObject dso = resolveHandle(handle); if (dso == null) { // resolveHandle reports problems and return null in case // of an error or an unresolvable handle. // Don't report it a second time, just continue... continue; } log.debug("Resolved identifier " + handle + " as " + contentServiceFactory.getDSpaceObjectService(dso).getTypeText(dso) + " " + dso.getID()); try { this.delete(dso, true); } catch (SQLException ex) { log.error(ex); System.err.println( "A problem with the database connection " + "occurred. Canceled pending actions."); System.err.println(ex.getMessage()); ex.printStackTrace(System.err); System.exit(1); } } System.exit(0); } if (line.hasOption("delete-all")) { this.deleteAll(); System.exit(0); } if (line.hasOption("identifiers")) { String[] identifiers = line.getOptionValues("identifiers"); report("Starting conversion of specified DSpaceObjects..."); this.processed.clear(); for (String handle : identifiers) { log.debug("Trying to resolve identifier " + handle + "."); DSpaceObject dso = resolveHandle(handle); if (dso == null) { // resolveHandle reports problems and return null in case // of an error or an unresolvable handle. // Don't report it a second time, just continue... continue; } try { this.convert(dso, false); } catch (SQLException ex) { log.error(ex); System.err.println( "A problem with the database connection " + "occurred. Canceled pending actions."); System.err.println(ex.getMessage()); ex.printStackTrace(System.err); System.exit(1); } } report("Conversion ended."); System.exit(0); } if (line.hasOption("convert-all")) { try { this.convertAll(); } catch (SQLException ex) { log.error(ex); System.err .println("A problem with the database connection " + "occurred. Canceled pending actions."); System.err.println(ex.getMessage()); ex.printStackTrace(System.err); System.exit(1); } System.exit(0); } this.usage(options); System.exit(0); }
From source file:org.eclipse.php.internal.core.codeassist.CodeAssistUtils.java
/** * @deprecated use/*w w w. j av a 2 s .com*/ * org.apache.commons.lang3.StringUtils.startsWithIgnoreCase() */ public static boolean startsWithIgnoreCase(String word, String prefix) { return StringUtils.startsWithIgnoreCase(word, prefix); }
From source file:org.eclipse.php.internal.core.codeassist.strategies.ClassDeclarationKeywordsStrategy.java
public void apply(ICompletionReporter reporter) throws BadLocationException { ICompletionContext context = getContext(); if (!(context instanceof ClassDeclarationKeywordContext)) { return;//from ww w.j av a 2 s.com } ClassDeclarationKeywordContext concreteContext = (ClassDeclarationKeywordContext) context; ISourceRange replaceRange = getReplacementRange(concreteContext); String prefix = concreteContext.getPrefix(); String statementText = concreteContext.getStatementText().toString(); if (StringUtils.startsWithIgnoreCase(EXTENDS, prefix) && statementText.indexOf(EXTENDS_WITH_BLANK) < 0) { reporter.reportKeyword(EXTENDS, getSuffix(concreteContext), replaceRange); } if (StringUtils.startsWithIgnoreCase(IMPLEMENTS, prefix) && statementText.indexOf(IMPLEMENTS_WITH_BLANK) < 0) { reporter.reportKeyword(IMPLEMENTS, getSuffix(concreteContext), replaceRange); } }
From source file:org.eclipse.php.internal.core.codeassist.strategies.GlobalTypesStrategy.java
/** * Adds the self function with the relevant data to the proposals array * /*from w ww .jav a 2 s .c o m*/ * @param context * @param reporter * @throws BadLocationException */ protected void addSelf(AbstractCompletionContext context, ICompletionReporter reporter) throws BadLocationException { String prefix = context.getPrefix(); ISourceRange replaceRange = getReplacementRange(context); if (StringUtils.startsWithIgnoreCase("self", prefix)) { //$NON-NLS-1$ if (!context.getCompletionRequestor().isContextInformationMode() || prefix.length() == 4) { // "self".length() String suffix = getSuffix(context); // get the class data for "self". In case of null, the self // function will not be added IType selfClassData = CodeAssistUtils.getSelfClassData(context.getSourceModule(), context.getOffset()); if (selfClassData != null) { try { IMethod ctor = null; for (IMethod method : selfClassData.getMethods()) { if (method.isConstructor()) { ctor = method; break; } } if (ctor != null) { ISourceRange sourceRange = selfClassData.getSourceRange(); FakeMethod ctorMethod = new FakeMethod((ModelElement) selfClassData, "self", //$NON-NLS-1$ sourceRange.getOffset(), sourceRange.getLength(), sourceRange.getOffset(), sourceRange.getLength()) { public boolean isConstructor() throws ModelException { return true; } }; ctorMethod.setParameters(ctor.getParameters()); reporter.reportMethod(ctorMethod, suffix, replaceRange); } else { ISourceRange sourceRange = selfClassData.getSourceRange(); reporter.reportMethod( new FakeMethod((ModelElement) selfClassData, "self", sourceRange.getOffset(), //$NON-NLS-1$ sourceRange.getLength(), sourceRange.getOffset(), sourceRange.getLength()), "()", //$NON-NLS-1$ replaceRange); } } catch (ModelException e) { PHPCorePlugin.log(e); } } } } }
From source file:org.eclipse.php.internal.core.codeassist.strategies.IncludeStatementStrategy.java
private boolean isLastSegmantPrefix(IPath prefixPath, IPath relative) { String lastCurrentSegment = relative.lastSegment(); String lastPrefixSegment = prefixPath.lastSegment(); if (lastCurrentSegment == null) { lastCurrentSegment = ""; //$NON-NLS-1$ }/*from w w w . j a va 2 s . c o m*/ if (lastPrefixSegment == null) { lastPrefixSegment = ""; //$NON-NLS-1$ } if (StringUtils.startsWithIgnoreCase(lastCurrentSegment, lastPrefixSegment)) { return true; } return false; }
From source file:org.eclipse.php.internal.core.codeassist.strategies.InUseTraitStrategy.java
public void apply(ICompletionReporter reporter) throws BadLocationException { ICompletionContext context = getContext(); if (!(context instanceof AbstractCompletionContext)) { return;// w w w .java2 s . c o m } AbstractCompletionContext abstractContext = (AbstractCompletionContext) context; int offset = abstractContext.getOffset(); ISourceModule sourceModule = abstractContext.getSourceModule(); List<String> useTypes = abstractContext.getUseTypes(); String prefix = abstractContext.getPrefix(); ModuleDeclaration moduleDeclaration = SourceParserUtil.getModuleDeclaration(sourceModule, null); FileContext fileContext = new FileContext(sourceModule, moduleDeclaration, offset); ISourceRange replacementRange = getReplacementRange(abstractContext); for (String useType : useTypes) { if (StringUtils.startsWithIgnoreCase(useType.trim(), prefix)) { IEvaluatedType type = PHPClassType.fromTraitName(useType, sourceModule, offset); IType[] modelElements = PHPTypeInferenceUtils.getModelElements(type, fileContext, offset); if (modelElements != null) { for (IType typeElement : modelElements) { reporter.reportType(typeElement, "", replacementRange, //$NON-NLS-1$ ProposalExtraInfo.TYPE_ONLY); } } } } }