List of usage examples for org.apache.commons.lang StringUtils removeEnd
public static String removeEnd(String str, String remove)
Removes a substring only if it is at the end of a source string, otherwise returns the source string.
From source file:adalid.core.Instance.java
@Override public String toString() { String claves = ""; for (String clave : _instanceFields.keySet()) { InstanceField field = _instanceFields.get(clave); claves += clave + '=' + field.getValue() + ", "; }//from w ww .ja v a 2 s .com return super.toString() + "{" + StringUtils.removeEnd(claves, ", ") + "}"; }
From source file:mvm.rya.indexing.accumulo.freetext.AccumuloFreeTextIndexer.java
private Set<String> unrollWildcard(String string, boolean reverse) throws IOException { Scanner termTableScan = getScanner(ConfigUtils.getFreeTextTermTablename(conf)); Set<String> unrolledTerms = new HashSet<String>(); Text queryTerm;// ww w.j av a2s . c o m if (reverse) { String t = StringUtils.removeStart(string, "*").toLowerCase(); queryTerm = ColumnPrefixes.getRevTermListColFam(t); } else { String t = StringUtils.removeEnd(string, "*").toLowerCase(); queryTerm = ColumnPrefixes.getTermListColFam(t); } // perform query and read results termTableScan.setRange(Range.prefix(queryTerm)); for (Entry<Key, Value> e : termTableScan) { String term = ColumnPrefixes.removePrefix(e.getKey().getRow()).toString(); if (reverse) { unrolledTerms.add(StringUtils.reverse(term)); } else { unrolledTerms.add(term); } } if (unrolledTerms.isEmpty()) { // put in a placeholder term that will never be in the index. unrolledTerms.add("\1\1\1"); } return unrolledTerms; }
From source file:de.iteratec.iteraplan.presentation.dialog.ExcelImport.ExportFrontendServiceImpl.java
private String getElasticMiType(TypeOfBuildingBlock typeOfBuildingBlock) { String classicClassName = typeOfBuildingBlock.getAssociatedClass().getSimpleName(); return StringUtils.removeEnd(classicClassName, "Release"); }
From source file:com.hangum.tadpole.mongodb.core.composite.result.MongodbResultComposite.java
/** * //from w w w . j a v a 2s .c o m * @param parent * @param style * @param userDB * @param collectionName */ public MongodbResultComposite(Composite parent, int style, final UserDBDAO userDB, final String collectionName, final boolean isUserAction) { super(parent, style); GridLayout gridLayout = new GridLayout(1, false); gridLayout.verticalSpacing = 1; gridLayout.horizontalSpacing = 1; gridLayout.marginHeight = 1; gridLayout.marginWidth = 1; setLayout(gridLayout); this.userDB = userDB; this.collectionName = collectionName; this.isUserAction = isUserAction; Composite compositeResult = new Composite(this, SWT.NONE); compositeResult.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); GridLayout gl_compositeResult = new GridLayout(1, false); gl_compositeResult.verticalSpacing = 1; gl_compositeResult.horizontalSpacing = 1; gl_compositeResult.marginHeight = 1; gl_compositeResult.marginWidth = 1; compositeResult.setLayout(gl_compositeResult); tabFolderMongoDB = new CTabFolder(compositeResult, SWT.NONE); tabFolderMongoDB.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (treeViewerMongo == null) return; selectData(); } }); tabFolderMongoDB.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); tabFolderMongoDB.setSelectionBackground(TadpoleWidgetUtils.getTabFolderBackgroundColor(), TadpoleWidgetUtils.getTabFolderPercents()); CTabItem tbtmTreeView = new CTabItem(tabFolderMongoDB, SWT.NONE); tbtmTreeView.setText(Messages.get().MongodbResultComposite_3); Composite compositeTreeView = new Composite(tabFolderMongoDB, SWT.NONE); tbtmTreeView.setControl(compositeTreeView); GridLayout gl_compositeTreeView = new GridLayout(1, false); gl_compositeTreeView.verticalSpacing = 2; gl_compositeTreeView.horizontalSpacing = 2; gl_compositeTreeView.marginHeight = 2; gl_compositeTreeView.marginWidth = 2; compositeTreeView.setLayout(gl_compositeTreeView); treeViewerMongo = new TreeViewer(compositeTreeView, SWT.BORDER | SWT.VIRTUAL | SWT.FULL_SELECTION); treeViewerMongo.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IStructuredSelection iss = (IStructuredSelection) treeViewerMongo.getSelection(); if (!iss.isEmpty()) { MongodbTreeViewDTO rsResult = (MongodbTreeViewDTO) iss.getFirstElement(); String strKey = rsResult.getKey(); TadpoleSimpleMessageDialog dlg = new TadpoleSimpleMessageDialog( Display.getCurrent().getActiveShell(), collectionName + " [ " + strKey + " ]", //$NON-NLS-1$//$NON-NLS-2$ JSONUtil.getPretty(rsResult.getDbObject().toString())); dlg.open(); } } }); Tree tree = treeViewerMongo.getTree(); tree.setHeaderVisible(true); tree.setLinesVisible(true); tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); createTreeColumn(); treeViewerMongo.setContentProvider(new TreeMongoContentProvider()); treeViewerMongo.setLabelProvider(new TreeMongoLabelProvider()); Composite compositeTreeViewTail = new Composite(compositeTreeView, SWT.NONE); compositeTreeViewTail.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); compositeTreeViewTail.setLayout(new GridLayout(6, false)); if (isUserAction) { Button btnTreeInsertDocument = new Button(compositeTreeViewTail, SWT.NONE); btnTreeInsertDocument.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { newDocument(); } }); btnTreeInsertDocument.setText(Messages.get().MongodbResultComposite_4); Button btnTreeDeleteDocument = new Button(compositeTreeViewTail, SWT.NONE); btnTreeDeleteDocument.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { deleteDocumentTree(); } }); btnTreeDeleteDocument.setText(Messages.get().MongodbResultComposite_5); Button btnTreeCreateIndex = new Button(compositeTreeViewTail, SWT.NONE); btnTreeCreateIndex.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { createIndex(); } }); btnTreeCreateIndex.setText(Messages.get().MongodbResultComposite_6); Label labelTreeViewDumy = new Label(compositeTreeViewTail, SWT.NONE); labelTreeViewDumy.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); } lblTreeViewCount = new Label(compositeTreeViewTail, SWT.NONE); lblTreeViewCount.setText(Messages.get().MongodbResultComposite_7); CTabItem tbtmTableView = new CTabItem(tabFolderMongoDB, SWT.NONE); tbtmTableView.setText(Messages.get().MongodbResultComposite_8); sashFormCollectionResult = new SashForm(tabFolderMongoDB, SWT.VERTICAL); tbtmTableView.setControl(sashFormCollectionResult); Composite compositeBodyTable = new Composite(sashFormCollectionResult, SWT.VERTICAL); GridLayout gl_compositeBodyTable = new GridLayout(2, false); gl_compositeBodyTable.marginWidth = 2; gl_compositeBodyTable.marginHeight = 2; gl_compositeBodyTable.verticalSpacing = 2; gl_compositeBodyTable.horizontalSpacing = 2; compositeBodyTable.setLayout(gl_compositeBodyTable); Label lblFilter = new Label(compositeBodyTable, SWT.NONE); lblFilter.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); lblFilter.setText(Messages.get().Filter); textFilter = new Text(compositeBodyTable, SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL); textFilter.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.Selection) setFilter(); } }); textFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); resultTableViewer = new TableViewer(compositeBodyTable, SWT.BORDER | SWT.VIRTUAL | SWT.FULL_SELECTION); resultTableViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IStructuredSelection iss = (IStructuredSelection) resultTableViewer.getSelection(); if (!iss.isEmpty()) { HashMap<Integer, Object> rsResult = (HashMap<Integer, Object>) iss.getFirstElement(); // String jsonString = rsResult.get(MongoDBDefine.PRIMARY_ID_KEY).toString(); DBObject dbObject = (DBObject) rsResult.get(MongoDBDefine.PRIMARY_ID_KEY); FindOneDetailDialog dlg = new FindOneDetailDialog(null, userDB, collectionName, dbObject); dlg.open(); } } }); Table table = resultTableViewer.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); sqlFilter.setTable(table); Composite compositeTail = new Composite(compositeBodyTable, SWT.NONE); compositeTail.setLayout(new GridLayout(10, false)); compositeTail.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); if (isUserAction) { Button btnInsertDocument = new Button(compositeTail, SWT.NONE); btnInsertDocument.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { newDocument(); } }); btnInsertDocument.setText(Messages.get().MongodbResultComposite_13); Button btnDeleteDocument = new Button(compositeTail, SWT.NONE); btnDeleteDocument.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { deleteDocumentTable(); } }); btnDeleteDocument.setText(Messages.get().MongodbResultComposite_14); Button btnCreateIndex = new Button(compositeTail, SWT.NONE); btnCreateIndex.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { createIndex(); } }); btnCreateIndex.setText(Messages.get().MongodbResultComposite_15); Label labelTableDumy = new Label(compositeTail, SWT.NONE); GridData gd_labelTableDumy = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); gd_labelTableDumy.widthHint = 5; labelTableDumy.setLayoutData(gd_labelTableDumy); } Button btnExportCSV = new Button(compositeTail, SWT.NONE); btnExportCSV.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StringBuffer sbExportDataBody = new StringBuffer(); // fixed : https://github.com/hangum/TadpoleForDBTools/issues/284 // column ?. String tmpStrHead = ""; TableColumn[] tcs = resultTableViewer.getTable().getColumns(); for (TableColumn tableColumn : tcs) { tmpStrHead += tableColumn.getText() + ", "; //$NON-NLS-1$ } tmpStrHead = StringUtils.removeEnd(tmpStrHead, ", "); tmpStrHead += PublicTadpoleDefine.LINE_SEPARATOR; //$NON-NLS-1$ // column ?? . for (int i = 0; i < sourceDataList.size(); i++) { String tmpData = ""; Map<Integer, Object> mapColumns = sourceDataList.get(i); for (int j = 0; j < tcs.length; j++) { tmpData += mapColumns.get(j) + ", "; //$NON-NLS-1$ } tmpData = StringUtils.removeEnd(tmpData, ", "); tmpData += PublicTadpoleDefine.LINE_SEPARATOR; sbExportDataBody.append(tmpData); //$NON-NLS-1$ } downloadServiceHandler.setName(userDB.getDisplay_name() + "_ResultSetExport.csv"); //$NON-NLS-1$ downloadServiceHandler.setByteContent((tmpStrHead + sbExportDataBody.toString()).getBytes()); DownloadUtils.provideDownload(compositeExternal, downloadServiceHandler.getId()); } }); btnExportCSV.setText(Messages.get().MongodbResultComposite_16); compositeExternal = new Composite(compositeTail, SWT.NONE); compositeExternal.setLayout(new GridLayout(1, false)); compositeExternal.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); Label lblNewLabel_1 = new Label(compositeTail, SWT.NONE); lblNewLabel_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); lblTableViewCount = new Label(compositeTail, SWT.NONE); // JSON View CTabItem tbtmJSONView = new CTabItem(tabFolderMongoDB, SWT.NONE); tbtmJSONView.setText("JSON View"); Composite compositeJSONView = new Composite(tabFolderMongoDB, SWT.NONE); tbtmJSONView.setControl(compositeJSONView); compositeJSONView.setLayout(new GridLayout(1, false)); tadpoleEditor = new TadpoleEditorWidget(compositeJSONView, SWT.BORDER, EditorDefine.EXT_JSON, "", ""); tadpoleEditor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); // tabpole message CTabItem tbtmTadpoleMessage = new CTabItem(tabFolderMongoDB, SWT.NONE); tbtmTadpoleMessage.setText(Messages.get().MongodbResultComposite_17); Composite compositeTadpoleMsg = new Composite(tabFolderMongoDB, SWT.NONE); tbtmTadpoleMessage.setControl(compositeTadpoleMsg); compositeTadpoleMsg.setLayout(new GridLayout(1, false)); tableViewerMessage = new TableViewer(compositeTadpoleMsg, SWT.BORDER | SWT.FULL_SELECTION); tableViewerMessage.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IStructuredSelection is = (IStructuredSelection) event.getSelection(); Object selElement = is.getFirstElement(); if (selElement instanceof TadpoleMessageDAO) { TadpoleMessageDAO tmd = (TadpoleMessageDAO) selElement; TadpoleMessageDialog dlg = new TadpoleMessageDialog(null, "Message", //$NON-NLS-1$ SQLHistoryLabelProvider.dateToStr(tmd.getDateExecute()), tmd.getStrMessage()); dlg.open(); } } }); tableTadpoleMsg = tableViewerMessage.getTable(); tableTadpoleMsg.setHeaderVisible(true); tableTadpoleMsg.setLinesVisible(true); tableTadpoleMsg.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); tableTadpoleMsg.setSortDirection(SWT.DOWN); SQLHistorySorter sorterMessage = new SQLHistorySorter(); TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewerMessage, SWT.NONE); TableColumn tblclmnDate = tableViewerColumn.getColumn(); tblclmnDate.setWidth(140); tblclmnDate.setText(Messages.get().Date); tblclmnDate.addSelectionListener(getSelectionAdapter(tableViewerMessage, sorterMessage, tblclmnDate, 0)); TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(tableViewerMessage, SWT.NONE); TableColumn tblclmnSql = tableViewerColumn_1.getColumn(); tblclmnSql.setWidth(500); tblclmnSql.setText(Messages.get().MongodbResultComposite_19); tblclmnSql.addSelectionListener(getSelectionAdapter(tableViewerMessage, sorterMessage, tblclmnSql, 1)); tableViewerMessage.setLabelProvider(new SQLHistoryLabelProvider()); tableViewerMessage.setContentProvider(new ArrayContentProvider()); tableViewerMessage.setInput(listMessage); tableViewerMessage.setComparator(sorterMessage); Composite composite = new Composite(compositeTadpoleMsg, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); composite.setLayout(new GridLayout(3, false)); Button btnExportTadpoleMessage = new Button(composite, SWT.NONE); btnExportTadpoleMessage.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { StringBuffer sbExportData = new StringBuffer(); for (TadpoleMessageDAO dao : listMessage) { sbExportData.append(dao.getStrMessage()).append(PublicTadpoleDefine.LINE_SEPARATOR); //$NON-NLS-1$ } downloadServiceHandler.setName(userDB.getDisplay_name() + "_Message.txt"); //$NON-NLS-1$ downloadServiceHandler.setByteContent(sbExportData.toString().getBytes()); DownloadUtils.provideDownload(compositeExternal, downloadServiceHandler.getId()); } }); btnExportTadpoleMessage.setText(Messages.get().MongodbResultComposite_20); Label label = new Label(composite, SWT.NONE); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Button btnClear = new Button(composite, SWT.NONE); btnClear.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { listMessage.clear(); tableViewerMessage.refresh(); } }); btnClear.setText(Messages.get().MongodbResultComposite_21); registerServiceHandler(); firstTabInit(); }
From source file:gobblin.aws.AWSSdkClient.java
/*** * Download a S3 object to local directory * * @param s3ObjectSummary S3 object summary for the object to download * @param targetDirectory Local target directory to download the object to * @throws IOException If any errors were encountered in downloading the object *//*from w ww .j a v a 2 s . c o m*/ public void downloadS3Object(S3ObjectSummary s3ObjectSummary, String targetDirectory) throws IOException { final AmazonS3 amazonS3 = getS3Client(); final GetObjectRequest getObjectRequest = new GetObjectRequest(s3ObjectSummary.getBucketName(), s3ObjectSummary.getKey()); final S3Object s3Object = amazonS3.getObject(getObjectRequest); final String targetFile = StringUtils.removeEnd(targetDirectory, File.separator) + File.separator + s3Object.getKey(); FileUtils.copyInputStreamToFile(s3Object.getObjectContent(), new File(targetFile)); LOGGER.info("S3 object downloaded to file: " + targetFile); }
From source file:adalid.util.velocity.BaseBuilder.java
private void createTextFilePropertiesFile(String source, String target) { boolean java = StringUtils.endsWithIgnoreCase(source, ".java"); boolean bundle = StringUtils.endsWithIgnoreCase(source, ".properties"); File sourceFile = new File(source); String sourceFileName = sourceFile.getName(); String sourceFileSimpleName = StringUtils.substringBeforeLast(sourceFileName, "."); String sourceFolderName = sourceFile.getParentFile().getName(); String sourceFolderSimpleName = StringUtils.substringBeforeLast(sourceFolderName, "."); String sourceEntityName = getOptionalEntityName(sourceFileSimpleName, sourceFolderSimpleName); 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).replace("eclipse.settings", ".settings"); path = replaceAliasWithRootFolderName(path); String pack = null;/* w ww . ja v a2 s . co m*/ if (java || bundle) { String s1 = StringUtils.substringAfter(path, SRC); if (StringUtils.contains(s1, PROJECT_ALIAS)) { String s2 = StringUtils.substringBefore(s1, PROJECT_ALIAS); String s3 = SRC + s2; String s4 = StringUtils.substringBefore(path, s3) + s3; String s5 = StringUtils.substringAfter(s1, PROJECT_ALIAS).replace("/", "."); path = StringUtils.removeEnd(s4, "/"); pack = ROOT_PACKAGE_NAME + s5; } } path = finalisePath(path); String file = StringUtils.substringAfterLast(source, FS).replace(project, PROJECT_ALIAS) .replace("eclipse.project", ".project"); List<String> lines = new ArrayList<>(); lines.add("template = " + template); // lines.add("template-type = velocity"); lines.add("path = " + path); if (StringUtils.isNotBlank(pack)) { lines.add("package = " + pack); } lines.add("file = " + file); if (sourceFileSimpleName.equals("eclipse") || sourceFolderSimpleName.equals("eclipse") || sourceFolderSimpleName.equals("nbproject")) { lines.add("disabled = true"); } else if (sourceEntityName != null) { lines.add("disabled-when-missing = " + sourceEntityName); } if (source.endsWith(".css") || source.endsWith(".jrtx")) { lines.add("preserve = true"); } else if (ArrayUtils.contains(preservableFiles, sourceFileName)) { lines.add("preserve = true"); } lines.add("dollar.string = $"); lines.add("pound.string = #"); lines.add("backslash.string = \\\\"); FilUtils.mkdirs(folder); if (write(properties, lines, WINDOWS_CHARSET)) { propertiesFilesCreated++; } }
From source file:com.gemstone.gemfire.management.internal.cli.GfshParser.java
private int completeParameters(CommandTarget commandTarget, int cursorStart, String remainingBuffer, int cursor, List<Completion> completionCandidates) { int desiredCursorPosition = cursorStart; // Factor for remainingBuffer boolean sizeReduced = false; // We need to work modify the flow according to the CliException // generated. For that we will need a reference to the Exception // CliException reference CliCommandOptionException coe = null; OptionSet userOptionSet = null;//from www . j av a2s .co m try { // We need to remove the space which separates command from the // parameters if (remainingBuffer.length() > 0) { remainingBuffer = remainingBuffer.substring(1); sizeReduced = true; } userOptionSet = commandTarget.getOptionParser().parse(remainingBuffer); } catch (CliException ce) { if (ce instanceof CliCommandOptionException) { coe = (CliCommandOptionException) ce; coe.setCommandTarget(commandTarget); userOptionSet = coe.getOptionSet(); } } // Contains mandatory options which have not been specified List<Option> mandatoryOptions = new ArrayList<Option>(); // Contains non-mandatory options which have not been specified List<Option> unspecifiedOptions = new ArrayList<Option>(); // First we need a list to create a list of all the options specified Map<String, Option> optionsPresentMap = new LinkedHashMap<String, Option>(); if (userOptionSet != null) { // Start with the arguments String argumentSeparator = " "; for (Argument argument : commandTarget.getOptionParser().getArguments()) { if (completionCandidates.size() == 0) { boolean warning = false; if (userOptionSet.hasArgument(argument)) { boolean incrementCursor = true; // Here we need to get all the possible values for this // argument if (getAllPossibleValuesForParameter(completionCandidates, argument, userOptionSet.getValue(argument), commandTarget.getGfshMethodTarget())) { // Check whether the list of completionCandidates is // not empty if (completionCandidates.size() > 0) { // First check whether the argument value // matches with any // of the completionCandidates if (perfectMatch(completionCandidates, userOptionSet.getValue(argument))) { // Remove all the completionCandidates completionCandidates.clear(); } else { modifyCompletionCandidates(completionCandidates, argumentSeparator, userOptionSet.getValue(argument)); // For this case also we should not // increment the // cursorPosition if (completionCandidates.size() > 0) { incrementCursor = false; } } } } else { // The completion candidates should be cleared if the Converter has // populated it with some values completionCandidates.clear(); } if (incrementCursor) { desiredCursorPosition += userOptionSet.getValue(argument).length() + argumentSeparator.length(); } } else { if (argument.isRequired()) { // Here the converter will come in handy // to get suggestion for arguments if (getAllPossibleValuesForParameter(completionCandidates, argument, null, commandTarget.getGfshMethodTarget())) { if (completionCandidates.size() == 0) { // Enable warning if nothing is returned warning = true; } } else { // The completion candidates should be cleared if the Converter has // populated it with some values completionCandidates.clear(); warning = true; } } else { boolean checkForPossibleValues = true; // This means that the argument is not mandatory // Now here we need to check whether user wants to // enter an option. if (endsWithOptionSpecifiers(userOptionSet.getUserInput()) || hasOptionSpecified(userOptionSet.getUserInput())) { // This means options have started, and we // cannot have arguments after options // So, we just skip checking for possible // values checkForPossibleValues = false; } // Just try getting the PossibleValues without // aiming if (checkForPossibleValues) { getAllPossibleValuesForParameter(completionCandidates, argument, null, commandTarget.getGfshMethodTarget()); } } if (completionCandidates.size() > 0) { modifyCompletionCandidates(completionCandidates, argumentSeparator, (String[]) null); } } if (warning) { String argMessage = argument.getArgumentName() + ((argument.getHelp() != null && !argument.getHelp().equals("")) ? ": " + argument.getHelp() : ""); logWarning(CliStrings.format(CliStrings.GFSHPARSER__MSG__REQUIRED_ARGUMENT_0, argMessage)); return desiredCursorPosition + userOptionSet.getNoOfSpacesRemoved(); } } argumentSeparator = SyntaxConstants.ARGUMENT_SEPARATOR; } if (completionCandidates.size() > 0) { return desiredCursorPosition + userOptionSet.getNoOfSpacesRemoved(); } // Now process options boolean warningValueRequired = false; Option warningOption = null; for (Option option : commandTarget.getOptionParser().getOptions()) { if (userOptionSet.hasOption(option)) { // We are supporting option synonyms, // so we need to check that here for (String string : userOptionSet.getSplit()) { if (string.startsWith(SyntaxConstants.LONG_OPTION_SPECIFIER)) { // Remove option prefix string = StringUtils.removeStart(string, SyntaxConstants.LONG_OPTION_SPECIFIER); // Remove value specifier string = StringUtils.removeEnd(string, SyntaxConstants.OPTION_VALUE_SPECIFIER); if (!string.equals("")) { if (option.getLongOption().equals(string)) { // This means that user has entered the whole option and // Increment desiredCursorPostion by the length of the // option and the option specifier, including space desiredCursorPosition += /* space */1 + SyntaxConstants.LONG_OPTION_SPECIFIER.length() + option.getLongOption().length(); break; } else { // This is only possible if the user has // entered one of the synonyms of the options // which wasn't displayed initially for (String optionSynonym : option.getSynonyms()) { if (optionSynonym.equals(string)) { // This means that what the user has // entered is actually a // synonym for the option desiredCursorPosition += /* space */1 + SyntaxConstants.LONG_OPTION_SPECIFIER.length() + optionSynonym.length(); break; } } } } } } optionsPresentMap.put(option.getLongOption(), option); // For option value if (userOptionSet.hasValue(option)) { String value = userOptionSet.getValue(option); boolean valueActuallySpecified = false; String valueSeparator = SyntaxConstants.VALUE_SEPARATOR; if (option.getValueSeparator() != null) { valueSeparator = option.getValueSeparator(); } // JOpt doesn't maintain trailing comma (separator), hence reading it from buffer. boolean bufferEndsWithValueSeparator = remainingBuffer.endsWith(valueSeparator); // Check whether the value assigned to the option is // actually part of the split array or has been // assigned using the specifiedDefaultValue attribute // userOptionElement can be option name or value of that option. // E.g. "--opt=val" has elements "opt" & "val" for (String userOptionElement : userOptionSet.getSplit()) { if (userOptionElement.equals(value) || (userOptionElement).equals(value + valueSeparator)) { valueActuallySpecified = true; } } if (!valueActuallySpecified) { continue; } boolean incrementCursor = true; boolean considerLastValue = false; int lengthToBeAdded = 0; int lastIndexOf = 0; // This should only be invoked if we don't have any // completionCandidates beforeHand if (completionCandidates.size() == 0) { // Here also we might need to invoke converter to // get values apt for the option if (!endsWithOptionSpecifiers(userOptionSet.getUserInput()) && getAllPossibleValuesForParameter(completionCandidates, option, value, commandTarget.getGfshMethodTarget())) { // If the value returned by getAllPossibleValues // is the same as that entered by the // user we need to remove it from the // completionCandidates and move forward String prefix = ""; String[] split = ParserUtils.splitValues(value, valueSeparator); if (completionCandidates.size() > 0) { if (PreprocessorUtils.isSyntaxValid(value) && bufferEndsWithValueSeparator) { // This means that the user wants to // enter more values, prefix = valueSeparator; } else if (perfectMatch(completionCandidates, split)) { // If the user does not want to enter // more values, and it matches one // of the values then we do not // need to suggest anything for // this option completionCandidates.clear(); considerLastValue = true; } else if (ParserUtils.contains(value, valueSeparator)) { prefix = valueSeparator; } else { incrementCursor = false; if (value.startsWith(" ")) { prefix = " "; } else if (value.startsWith("\n")) { prefix = "\n"; } else { prefix = SyntaxConstants.OPTION_VALUE_SPECIFIER; } } } modifyCompletionCandidates(completionCandidates, prefix, bufferEndsWithValueSeparator, split); if (completionCandidates.size() == 0) { incrementCursor = true; considerLastValue = true; } } else { // The completion candidates should be cleared if the Converter has // populated it with some values completionCandidates.clear(); considerLastValue = true; } } else { // Make everything true considerLastValue = true; } // FIX for: 46265 // if bufferEndsWithValueSeparator, append a valueSeparator to get the real lastIndexOd // e.g. Let's say remainingBuffer is: cmd --opt1=val1,val2, // value would be: cmd --opt1=val1,val2 ---> not there's no comma in the end. // This doesn't give us the real last index of valueSeparator, hence add extra valueSeparator. lastIndexOf = ParserUtils.lastIndexOf( bufferEndsWithValueSeparator ? value + valueSeparator : value, valueSeparator); lengthToBeAdded = value.substring(0, (lastIndexOf > 0 ? lastIndexOf : value.length())) .length(); // Increment desiredCursorPosition if (incrementCursor) { desiredCursorPosition += /* value specifier length */SyntaxConstants.OPTION_VALUE_SPECIFIER .length() + lengthToBeAdded + ((considerLastValue) ? value.length() - lengthToBeAdded : 0); if (value.endsWith(" ") && considerLastValue) { desiredCursorPosition--; } } if (completionCandidates.size() == 0) { if (!PreprocessorUtils.isSyntaxValid(value)) { return desiredCursorPosition + userOptionSet.getNoOfSpacesRemoved(); } else { // Check whether the value ends with // VALUE_SEPARATOR, // if yes then we need to return if (value.endsWith(valueSeparator)) { return desiredCursorPosition + userOptionSet.getNoOfSpacesRemoved(); } } } } else { // Here the converter is useful to invoke // auto-suggestion, get Values from Converter if (completionCandidates.size() == 0) { if (getAllPossibleValuesForParameter(completionCandidates, option, null, commandTarget.getGfshMethodTarget())) { if (completionCandidates.size() == 0) { warningValueRequired = true; } else { modifyCompletionCandidates(completionCandidates, SyntaxConstants.OPTION_VALUE_SPECIFIER, new String[] { null }); } } else { // The completion candidates should be cleared if the Converter // has populated it with some values completionCandidates.clear(); warningValueRequired = true; } } } } else { // As we have reached here, the OptionParser was not able to // detect anything which proves that the option is present // So, we check with what the user provided and add only // that to the list of options to prompt for for (String userOptString : userOptionSet.getSplit()) { // Now to determine whether what the user specified was // an option, we need to check whether it starts // with an option specifier if (userOptString.startsWith(SyntaxConstants.LONG_OPTION_SPECIFIER)) { // Now remove the option specifier part userOptString = StringUtils.removeStart(userOptString, SyntaxConstants.LONG_OPTION_SPECIFIER); if (option.getLongOption().startsWith(userOptString) && !userOptString.equals("") && !option.getLongOption().equals(userOptString) && !optionsPresentMap.containsKey(userOptString)) { completionCandidates.add(new Completion( " " + SyntaxConstants.LONG_OPTION_SPECIFIER + option.getLongOption(), option.getLongOption(), "", 0)); } else { for (String optionSynonym : option.getSynonyms()) { if (optionSynonym.startsWith(userOptString) && !userOptString.equals("") && !optionSynonym.equals(userOptString)) { completionCandidates.add(new Completion( " " + SyntaxConstants.LONG_OPTION_SPECIFIER + optionSynonym, optionSynonym, "", 0)); break; } } } } } if (completionCandidates.size() == 0) { if (option.isRequired()) { mandatoryOptions.add(option); } else { unspecifiedOptions.add(option); } } } if (warningValueRequired/* || warningMultipleValuesNotSupported */) { warningOption = option; warningValueRequired = false; } } // Display warning if something not specified if (warningOption != null) { String optionMsg = warningOption.getLongOption() + ((warningOption.getHelp() != null && !warningOption.getHelp().equals("")) ? ": " + warningOption.getHelp() : ""); logWarning(CliStrings.format(CliStrings.GFSHPARSER__MSG__VALUE_REQUIRED_FOR_OPTION_0, optionMsg)); desiredCursorPosition += userOptionSet.getNoOfSpacesRemoved(); completionCandidates.add(new Completion(SyntaxConstants.OPTION_VALUE_SPECIFIER, "", null, 0)); return desiredCursorPosition; } } // Calculate the cursor position int newCursor = desiredCursorPosition + ((userOptionSet != null) ? userOptionSet.getNoOfSpacesRemoved() : 0); String subString = remainingBuffer; if (newCursor != cursorStart) { subString = remainingBuffer.substring(newCursor + (sizeReduced ? -1 : 0) - cursorStart).trim(); } // Exception handling if (coe != null && newCursor < cursor && completionCandidates.size() == 0 && !(PreprocessorUtils.containsOnlyWhiteSpaces(subString) || ((subString.endsWith(SyntaxConstants.LONG_OPTION_SPECIFIER) && subString.startsWith(SyntaxConstants.LONG_OPTION_SPECIFIER)) || (subString.startsWith(SyntaxConstants.SHORT_OPTION_SPECIFIER) && subString.endsWith(SyntaxConstants.SHORT_OPTION_SPECIFIER))))) { ExceptionHandler.handleException(coe); return cursor; } // If nothing has been specified for auto-completion then we need to suggest options if (completionCandidates.size() == 0) { if (mandatoryOptions.size() > 0) { for (Option option : mandatoryOptions) { completionCandidates.add( new Completion(" " + SyntaxConstants.LONG_OPTION_SPECIFIER + option.getLongOption(), option.getLongOption(), "", 0)); } } else { // As all the mandatory options have been specified we can prompt the // user for optional options. unspecifiedOptions = getUnspecifiedOptionsWithMode(unspecifiedOptions, commandTarget, optionsPresentMap); for (Option option : unspecifiedOptions) { completionCandidates.add( new Completion(" " + SyntaxConstants.LONG_OPTION_SPECIFIER + option.getLongOption(), option.getLongOption(), "", 0)); } } } return newCursor; }
From source file:edu.mayo.cts2.framework.webapp.rest.controller.AbstractMessageWrappingController.java
@SuppressWarnings("unchecked") protected <R> ModelAndView forward(HttpServletRequest httpServletRequest, UrlTemplateBinder<R> urlBinder, String urlTemplate, R resource, String byUriTemplate, boolean redirect) { String url = this.urlTemplateBindingCreator.bindResourceToUrlTemplate(urlBinder, resource, urlTemplate); String extraUrlPath = StringUtils.substringAfter(httpServletRequest.getRequestURI(), StringUtils.removeEnd(byUriTemplate, ALL_WILDCARD)); if (StringUtils.isNotBlank(extraUrlPath)) { url = url + "/" + extraUrlPath; }/* w w w . j av a 2s.c o m*/ ModelAndView mav; if (redirect) { Map<String, Object> parameters = new HashMap<String, Object>(httpServletRequest.getParameterMap()); parameters.remove(PARAM_REDIRECT); parameters.remove(PARAM_URI); mav = new ModelAndView("redirect:" + url + this.mapToQueryString(parameters)); } else { mav = new ModelAndView("forward:" + url); } return mav; }
From source file:adalid.util.velocity.SecondBaseBuilder.java
private void createTextFilePropertiesFile(String source, String target) { boolean java = StringUtils.endsWithIgnoreCase(source, ".java"); boolean bundle = StringUtils.endsWithIgnoreCase(source, ".properties"); File sourceFile = new File(source); String sourceFileName = sourceFile.getName(); String sourceFileSimpleName = StringUtils.substringBeforeLast(sourceFileName, "."); String sourceFolderName = sourceFile.getParentFile().getName(); String sourceFolderSimpleName = StringUtils.substringBeforeLast(sourceFolderName, "."); String sourceEntityName = getOptionalEntityName(sourceFileSimpleName, sourceFolderSimpleName); 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).replace("eclipse.settings", ".settings"); path = replaceAliasWithRootFolderName(path); String pack = null;// w w w. ja v a2s. com if (java || bundle) { String s1 = StringUtils.substringAfter(path, SRC); if (StringUtils.contains(s1, PROJECT_ALIAS)) { String s2 = StringUtils.substringBefore(s1, PROJECT_ALIAS); String s3 = SRC + s2; String s4 = StringUtils.substringBefore(path, s3) + s3; String s5 = StringUtils.substringAfter(s1, PROJECT_ALIAS).replace("/", "."); path = StringUtils.removeEnd(s4, "/"); pack = ROOT_PACKAGE_NAME + s5; } } path = finalisePath(path); String file = StringUtils.substringAfterLast(source, FS).replace(project, PROJECT_ALIAS) .replace("eclipse.project", ".project"); List<String> lines = new ArrayList<>(); lines.add("template = " + template); // lines.add("template-type = velocity"); lines.add("path = " + path); if (StringUtils.isNotBlank(pack)) { lines.add("package = " + pack); } lines.add("file = " + file); if (sourceFileSimpleName.equals("eclipse") || sourceFolderSimpleName.equals("eclipse") || sourceFolderSimpleName.equals("nbproject")) { lines.add("disabled = true"); } else if (sourceEntityName != null) { lines.add("disabled-when-missing = " + sourceEntityName); } if (preservable(sourceFile)) { lines.add("preserve = true"); } lines.add("dollar.string = $"); lines.add("pound.string = #"); lines.add("backslash.string = \\\\"); FilUtils.mkdirs(folder); if (write(properties, lines, WINDOWS_CHARSET)) { propertiesFilesCreated++; } }
From source file:adalid.util.velocity.BaseBuilder.java
private String replaceAliasWithRootFolderName(String path) { String p = path + "/"; if (StringUtils.startsWithIgnoreCase(p, SOURCE_PROJECT_ALIAS)) { p = SOURCE_PROJECT_ROOT_FOLDER_NAME + StringUtils.removeStartIgnoreCase(p, SOURCE_PROJECT_ALIAS); p = StringUtils.removeEnd(p, "/"); return p; }/*from ww w. ja va 2s . com*/ return path; }