List of usage examples for org.apache.commons.lang StringUtils startsWithIgnoreCase
public static boolean startsWithIgnoreCase(String str, String prefix)
Case insensitive check if a String starts with a specified prefix.
From source file:org.diffkit.diff.sns.DKPoiSheet.java
/** * map the "builtin" formats to Types/* w w w . ja v a 2s . c om*/ */ private static Type mapTypeForFormatString(String format_) { if (format_ == null) return null; if (format_.equalsIgnoreCase("general")) return Type.DECIMAL; else if (format_.equals("0")) return Type.INTEGER; else if (format_.equals("0.00")) return Type.DECIMAL; else if (format_.equals("#,##0")) return Type.INTEGER; else if (format_.equals("#,##0.00")) return Type.DECIMAL; else if (format_.equals("0%")) return Type.INTEGER; else if (format_.equals("0.00%")) return Type.DECIMAL; else if (format_.equalsIgnoreCase("mm/dd/yy")) return Type.DATE; else if (format_.equalsIgnoreCase("YYYY\\-MM\\-DD")) return Type.DATE; else if (StringUtils.startsWithIgnoreCase(format_, "hh:mm:ss")) return Type.TIME; else if (StringUtils.startsWithIgnoreCase(format_, "hh:mm")) return Type.TIME; else if (StringUtils.startsWithIgnoreCase(format_, "h:mm")) return Type.TIME; else if (StringUtils.startsWithIgnoreCase(format_, "h:mm:ss")) return Type.TIME; else if (StringUtils.containsIgnoreCase(format_, "dd/yy") && StringUtils.containsIgnoreCase(format_, "hh:mm")) return Type.TIMESTAMP; else if (format_.equalsIgnoreCase("m/d/yy")) return Type.DATE; else if (format_.equalsIgnoreCase("d-mmm-yy")) return Type.DATE; else if (format_.equalsIgnoreCase("d-mmm")) return Type.DATE; else if (format_.equalsIgnoreCase("mmm-yy")) return Type.DATE; else if (format_.equalsIgnoreCase("m/d/yy h:mm")) return Type.TIMESTAMP; else if (format_.equals("$#,##0_);($#,##0)")) return Type.INTEGER; else if (format_.equals("$#,##0_);[Red]($#,##0)")) return Type.INTEGER; else if (format_.equals("$#,##0.00);($#,##0.00)")) return Type.DECIMAL; else if (format_.equals("$#,##0.00_);[Red]($#,##0.00)")) return Type.DECIMAL; else if (format_.equals("0.00E+00")) return Type.DECIMAL; else if (format_.equals("# ?/?")) return Type.REAL; else if (format_.equals("# ??/??")) return Type.REAL; else if (format_.equals("#,##0_);[Red](#,##0)")) return Type.INTEGER; else if (format_.equals("#,##0.00_);(#,##0.00)")) return Type.DECIMAL; else if (format_.equals("#,##0.00_);[Red](#,##0.00)")) return Type.DECIMAL; else if (format_.equalsIgnoreCase("mm:ss")) return Type.TIME; else if (format_.equalsIgnoreCase("[h]:mm:ss")) return Type.TIME; else if (format_.equalsIgnoreCase("mm:ss.0")) return Type.TIME; else if (format_.equals("##0.0E+0")) return Type.INTEGER; else return Type.DECIMAL; }
From source file:org.dspace.authority.AuthorityValueServiceImpl.java
@Override public AuthorityValue getAuthorityValueType(String metadataString) { AuthorityValue fromAuthority = null; for (AuthorityValue type : authorityTypes.getTypes()) { if (StringUtils.startsWithIgnoreCase(metadataString, type.getAuthorityType())) { fromAuthority = type;/* www . j a v a2s . c o m*/ } } return fromAuthority; }
From source file:org.dspace.identifier.VersionedDOIIdentifierProvider.java
void removePreviousVersionDOIsOutOfObject(Context c, Item item, String oldDoi) throws IdentifierException, AuthorizeException { if (StringUtils.isEmpty(oldDoi)) { throw new IllegalArgumentException("Old DOI must be neither empty nor null!"); }// w w w . ja v a 2s.c o m String bareDoi = getBareDOI(doiService.formatIdentifier(oldDoi)); String bareDoiRef = doiService.DOIToExternalForm(bareDoi); List<MetadataValue> identifiers = itemService.getMetadata(item, MD_SCHEMA, DOI_ELEMENT, DOI_QUALIFIER, Item.ANY); // We have to remove all DOIs referencing previous versions. To do that, // we store all identifiers we do not know in an array list, clear // dc.identifier.uri and add the safed identifiers. // The list of identifiers to safe won't get larger then the number of // existing identifiers. ArrayList<String> newIdentifiers = new ArrayList<String>(identifiers.size()); boolean changed = false; for (MetadataValue identifier : identifiers) { if (!StringUtils.startsWithIgnoreCase(identifier.getValue(), bareDoiRef)) { newIdentifiers.add(identifier.getValue()); } else { changed = true; } } // reset the metadata if neccessary. if (changed) { try { itemService.clearMetadata(c, item, MD_SCHEMA, DOI_ELEMENT, DOI_QUALIFIER, Item.ANY); itemService.addMetadata(c, item, MD_SCHEMA, DOI_ELEMENT, DOI_QUALIFIER, null, newIdentifiers); itemService.update(c, item); } catch (SQLException ex) { throw new RuntimeException("A problem with the database connection occured.", ex); } } }
From source file:org.dspace.submit.step.UploadStep.java
/** * Do any processing of the information input by the user, and/or perform * step processing (if no user interaction required) * <P>/*from w w w . j av a 2 s .c om*/ * It is this method's job to save any data to the underlying database, as * necessary, and return error messages (if any) which can then be processed * by the appropriate user interface (JSP-UI or XML-UI) * <P> * NOTE: If this step is a non-interactive step (i.e. requires no UI), then * it should perform *all* of its processing in this method! * * @param context * The relevant DSpace Context. * @param request * Servlet's HTTP request object. * @param response * Servlet's HTTP response object. * @param subInfo * submission info object * @return Status or error flag which will be processed by * doPostProcessing() below! (if STATUS_COMPLETE or 0 is returned, * no errors occurred!) * @throws ServletException * A general exception a servlet can throw when it encounters difficulty. * @throws IOException * A general class of exceptions produced by failed or interrupted I/O operations. * @throws SQLException * An exception that provides information on a database access error or other errors. * @throws AuthorizeException * Exception indicating the current user of the context does not have permission * to perform a particular action. */ @Override public int doProcessing(Context context, HttpServletRequest request, HttpServletResponse response, SubmissionInfo subInfo) throws ServletException, IOException, SQLException, AuthorizeException { // get button user pressed String buttonPressed = Util.getSubmitButton(request, NEXT_BUTTON); // get reference to item Item item = subInfo.getSubmissionItem().getItem(); // ----------------------------------- // Step #0: Upload new files (if any) // ----------------------------------- String contentType = request.getContentType(); // if multipart form, then we are uploading a file if ((contentType != null) && (contentType.indexOf("multipart/form-data") != -1)) { // This is a multipart request, so it's a file upload // (return any status messages or errors reported) int status = processUploadFile(context, request, response, subInfo); // if error occurred, return immediately if (status != STATUS_COMPLETE) { return status; } } // if user pressed jump-to button in process bar, // return success (so that jump will occur) if (buttonPressed.startsWith(PROGRESS_BAR_PREFIX) || buttonPressed.startsWith(PREVIOUS_BUTTON)) { // check if a file is required to be uploaded if (fileRequired && !itemService.hasUploadedFiles(item)) { return STATUS_NO_FILES_ERROR; } else { return STATUS_COMPLETE; } } // --------------------------------------------- // Step #1: Check if this was just a request to // edit file information. // (or canceled editing information) // --------------------------------------------- // check if we're already editing a specific bitstream if (request.getParameter("bitstream_id") != null) { if (buttonPressed.equals(CANCEL_EDIT_BUTTON)) { // canceled an edit bitstream request subInfo.setBitstream(null); // this flag will just return us to the normal upload screen return STATUS_EDIT_COMPLETE; } else { // load info for bitstream we are editing Bitstream b = bitstreamService.find(context, Util.getUUIDParameter(request, "bitstream_id")); // save bitstream to submission info subInfo.setBitstream(b); } } else if (buttonPressed.startsWith("submit_edit_")) { // get ID of bitstream that was requested for editing String bitstreamID = buttonPressed.substring("submit_edit_".length()); Bitstream b = bitstreamService.find(context, UUID.fromString(bitstreamID)); // save bitstream to submission info subInfo.setBitstream(b); // return appropriate status flag to say we are now editing the // bitstream return STATUS_EDIT_BITSTREAM; } // --------------------------------------------- // Step #2: Process any remove file request(s) // --------------------------------------------- // Remove-selected requests come from Manakin if (buttonPressed.equalsIgnoreCase("submit_remove_selected")) { // this is a remove multiple request! if (request.getParameter("remove") != null) { // get all files to be removed String[] removeIDs = request.getParameterValues("remove"); // remove each file in the list for (int i = 0; i < removeIDs.length; i++) { UUID id = UUID.fromString(removeIDs[i]); int status = processRemoveFile(context, item, id); // if error occurred, return immediately if (status != STATUS_COMPLETE) { return status; } } // remove current bitstream from Submission Info subInfo.setBitstream(null); } } else if (buttonPressed.startsWith("submit_remove_")) { // A single file "remove" button must have been pressed UUID id = UUID.fromString(buttonPressed.substring(14)); int status = processRemoveFile(context, item, id); // if error occurred, return immediately if (status != STATUS_COMPLETE) { return status; } // remove current bitstream from Submission Info subInfo.setBitstream(null); } // ------------------------------------------------- // Step #3: Check for a change in file description // ------------------------------------------------- // We have to check for descriptions from users using the resumable upload // and from users using the simple upload. // Beginning with the resumable ones. Enumeration<String> parameterNames = request.getParameterNames(); Map<String, String> descriptions = new HashMap<>(); while (parameterNames.hasMoreElements()) { String name = parameterNames.nextElement(); if (StringUtils.startsWithIgnoreCase(name, "description[")) { descriptions.put(name.substring("description[".length(), name.length() - 1), request.getParameter(name)); } } if (!descriptions.isEmpty()) { // we got descriptions from the resumable upload if (item != null) { List<Bundle> bundles = itemService.getBundles(item, "ORIGINAL"); for (Bundle bundle : bundles) { List<Bitstream> bitstreams = bundle.getBitstreams(); for (Bitstream bitstream : bitstreams) { if (descriptions.containsKey(bitstream.getName())) { bitstream.setDescription(context, descriptions.get(bitstream.getName())); bitstreamService.update(context, bitstream); } } } } return STATUS_COMPLETE; } // Going on with descriptions from the simple upload String fileDescription = request.getParameter("description"); if (fileDescription != null && fileDescription.length() > 0) { // save this file description int status = processSaveFileDescription(context, request, response, subInfo); // if error occurred, return immediately if (status != STATUS_COMPLETE) { return status; } } // ------------------------------------------ // Step #4: Check for a file format change // (if user had to manually specify format) // ------------------------------------------ int formatTypeID = Util.getIntParameter(request, "format"); String formatDesc = request.getParameter("format_description"); // if a format id or description was found, then save this format! if (formatTypeID >= 0 || (formatDesc != null && formatDesc.length() > 0)) { // save this specified format int status = processSaveFileFormat(context, request, response, subInfo); // if error occurred, return immediately if (status != STATUS_COMPLETE) { return status; } } // --------------------------------------------------- // Step #5: Check if primary bitstream has changed // ------------------------------------------------- if (request.getParameter("primary_bitstream_id") != null) { List<Bundle> bundles = itemService.getBundles(item, "ORIGINAL"); if (bundles.size() > 0) { bundles.get(0).setPrimaryBitstreamID( bitstreamService.find(context, Util.getUUIDParameter(request, "primary_bitstream_id"))); bundleService.update(context, bundles.get(0)); } } // --------------------------------------------------- // Step #6: Determine if there is an error because no // files have been uploaded. // --------------------------------------------------- //check if a file is required to be uploaded if (fileRequired && !itemService.hasUploadedFiles(item) && !buttonPressed.equals(SUBMIT_MORE_BUTTON)) { return STATUS_NO_FILES_ERROR; } context.dispatchEvents(); return STATUS_COMPLETE; }
From source file:org.eclipse.gyrex.cloud.internal.console.ListNodesCmd.java
@Override protected void doExecute() throws Exception { final ICloudManager cloudManager = CloudActivator.getInstance().getService(ICloudManager.class); // collect all nodes final Collection<String> onlineNodes = cloudManager.getOnlineNodes(); final Map<String, INodeDescriptor> nodes = new HashMap<String, INodeDescriptor>(); collectedNodes(nodes, cloudManager.getApprovedNodes()); collectedNodes(nodes, cloudManager.getPendingNodes()); // build result list final Collection<INodeDescriptor> result = new TreeSet<INodeDescriptor>(new Comparator<INodeDescriptor>() { @Override//from www . j a v a2 s .c o m public int compare(final INodeDescriptor o1, final INodeDescriptor o2) { return o1.getId().compareTo(o2.getId()); } }); if (StringUtils.isBlank(what)) { result.addAll(nodes.values()); } else if (StringUtils.startsWithIgnoreCase(APPROVED, what)) { for (final INodeDescriptor node : nodes.values()) { if (node.isApproved()) { result.add(node); } } } else if (StringUtils.startsWithIgnoreCase(PENDING, what)) { for (final INodeDescriptor node : nodes.values()) { if (!node.isApproved()) { result.add(node); } } } else if (StringUtils.startsWith(ONLINE, what)) { for (final String onlineNode : onlineNodes) { final INodeDescriptor node = nodes.get(onlineNode); if (null != node) { result.add(node); } } } for (final INodeDescriptor node : result) { if (matchesFilter(filter, node)) { final String name = StringUtils.isNotBlank(node.getName()) ? node.getName() : "<unnamed>"; final String location = StringUtils.isNotBlank(node.getLocation()) ? node.getLocation() : "<unknown>"; final String tags = StringUtils.join(node.getTags(), ", "); final String approved = node.isApproved() ? "approved" : "not approved"; if (onlineNodes.contains(node.getId())) { printf("%s - %s @ %s [%s, online] %s", node.getId(), name, location, approved, tags); } else { printf("%s - %s @ %s [%s] %s", node.getId(), name, location, approved, tags); } } } }
From source file:org.eclipse.gyrex.jobs.internal.commands.LsCmd.java
@Override protected void doExecute() throws Exception { if (StringUtils.isBlank(what)) { printf("ERROR: please specify what to list"); return;/* www.ja v a2 s .c o m*/ } if (StringUtils.startsWithIgnoreCase("providers", what)) { printProviders(); } else if (StringUtils.startsWithIgnoreCase("schedules", what)) { printSchedules(); } else if (StringUtils.startsWithIgnoreCase("running", what)) { printJobs(JobState.RUNNING); } else if (StringUtils.startsWithIgnoreCase("waiting", what)) { printJobs(JobState.WAITING); } else if (StringUtils.startsWithIgnoreCase("all", what)) { printJobs(null); } else if (StringUtils.startsWithIgnoreCase("job", what)) { printJobs(null); } else if (StringUtils.startsWithIgnoreCase("queues", what)) { printJobsQueue(); } }
From source file:org.eclipse.gyrex.jobs.internal.externalprocess.ExternalProcessJob.java
@Override protected IStatus run(final IProgressMonitor monitor) { final ProcessBuilder builder = new ProcessBuilder(); log.debug("Command: {}", command); builder.command(command);/*from w ww .j a v a 2 s.c o m*/ if (workingDirectory != null) { log.debug("Using working directory: {}", workingDirectory); builder.directory(workingDirectory); } if (clearEnvironment) { builder.environment().clear(); log.debug("Cleared environment!"); } else { // remove all Gyrex specific settings for security reasons final Iterator<Entry<String, String>> entries = builder.environment().entrySet().iterator(); while (entries.hasNext()) { final Map.Entry<java.lang.String, java.lang.String> e = entries.next(); if (StringUtils.startsWithIgnoreCase(e.getKey(), "gyrex")) { log.debug("Removing Gyrex specific environment variable: {}", e.getKey()); entries.remove(); } } } setEnvironmentVariable(builder, "WORKSPACE", Platform.getInstanceLocation().toOSString()); setEnvironmentVariable(builder, "JOB_ID", jobId); if (additionalEnvironment != null) { for (final Entry<String, String> e : additionalEnvironment.entrySet()) { log.debug("Additional environment variable: {} = {}", e.getKey(), e.getValue()); builder.environment().put(e.getKey(), e.getValue()); } } AsyncLoggingInputStreamReader inputStreamReader = null, errorStreamReader = null; try { final Process p = builder.start(); inputStreamReader = new AsyncLoggingInputStreamReader(jobId + " [OUT Reader]", p.getInputStream(), log, Level.INFO); errorStreamReader = new AsyncLoggingInputStreamReader(jobId + " [ERR Reader]", p.getErrorStream(), log, Level.ERROR); final int result = p.waitFor(); if (result != exitValue) return new Status(IStatus.ERROR, JobsActivator.SYMBOLIC_NAME, "Process finished with unexpected exit value: " + result); } catch (final InterruptedException e) { log.warn("Interrupted while waiting for the process to finish.", e); Thread.currentThread().interrupt(); return Status.CANCEL_STATUS; } catch (final Exception | AssertionError | LinkageError e) { log.error("Error starting process. {} ", e.getMessage(), e); return new Status(IStatus.ERROR, JobsActivator.SYMBOLIC_NAME, "Error starting process: " + e.getMessage(), e); } finally { if (inputStreamReader != null) { inputStreamReader.close(); } if (errorStreamReader != null) { errorStreamReader.close(); } } if (StringUtils.isNotBlank(inputStreamReader.getLastLine())) return new Status(IStatus.OK, JobsActivator.SYMBOLIC_NAME, inputStreamReader.getLastLine()); return Status.OK_STATUS; }
From source file:org.eclipse.gyrex.p2.internal.commands.ListCommand.java
@Override protected void doExecute() throws Exception { if (StringUtils.isBlank(what)) { printf("ERROR: please specify what to list"); return;/* w w w. j av a 2s.co m*/ } if (StringUtils.startsWithIgnoreCase("repos", what)) { final Collection<RepositoryDefinition> repos = getRepositoryManager().getRepositories(); for (final RepositoryDefinition repo : repos) { if ((null == filterString) || StringUtils.contains(repo.getId(), filterString) || ((null != repo.getLocation()) && StringUtils.contains(repo.getLocation().toString(), filterString))) { ci.println(String.format("%s [%s]", repo.getId(), repo.toString())); } } } else if (StringUtils.startsWithIgnoreCase("packages", what)) { listPackages(); } else if (StringUtils.startsWithIgnoreCase("artifacts", what)) { listArtifacts(); } else { printf("ERROR: repos|packages expected"); return; } }
From source file:org.eclipse.jubula.client.ui.rcp.contentassist.TestDataCubeRefContentProposalProvider.java
/** * Checks whether the name of a Test Data Cube starts with a given prefix. * This check is case <b>in</b>sensitive. * //from w w w . ja v a2s . c o m * @param dataCube The Test Data Cube to check. * @param prefixToMatch The prefix with which the Test Data Cube name * should begin. * @return <code>true</code> if <code>dataCube</code>'s name starts with * <code>prefixToMatch</code> (<b>not</b> case sensitive). * Otherwise <code>false</code>. */ private static boolean dataCubeFulfillsNameRequirements(IParameterInterfacePO dataCube, String prefixToMatch) { return StringUtils.startsWithIgnoreCase(dataCube.getName(), prefixToMatch); }
From source file:org.eclipse.skalli.core.storage.Historian.java
Collection<File> getHistoryFiles(final File file) { String prefix = FilenameUtils.getBaseName(file.getAbsolutePath()); IOFileFilter fileFilter = FileFilterUtils.andFileFilter(FileFilterUtils.prefixFileFilter(prefix), FileFilterUtils.suffixFileFilter("history")); //$NON-NLS-1$ fileFilter = new IOFileFilter() { @Override// w ww .ja v a 2 s . c om public boolean accept(File arg0, String arg1) { return false; } @Override public boolean accept(File historyFile) { boolean ret = StringUtils.startsWithIgnoreCase(historyFile.getAbsolutePath(), file.getAbsolutePath()); ret &= StringUtils.endsWithIgnoreCase(historyFile.getAbsolutePath(), ".history"); //$NON-NLS-1$ return ret; } }; @SuppressWarnings("unchecked") Collection<File> files = FileUtils.listFiles(file.getParentFile(), fileFilter, null); return files; }