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:eu.esdihumboldt.hale.io.haleconnect.internal.HaleConnectServiceImpl.java
/** * @see eu.esdihumboldt.hale.io.haleconnect.BasePathManager#setBasePath(String, * String)// w ww .ja v a 2 s .com */ @Override public void setBasePath(String service, String basePath) { if (service == null || basePath == null) { throw new NullPointerException("service and basePath must not be null"); } while (basePath.endsWith("/")) { basePath = StringUtils.removeEnd(basePath, "/"); } basePaths.put(service, basePath); }
From source file:idontwant2see.IDontWant2See.java
private AbstractAction getActionInputTitle(final Program p, final String part) { return new AbstractAction(mLocalizer.msg("menu.userEntered", "User entered value")) { public void actionPerformed(final ActionEvent e) { final JCheckBox caseSensitive = new JCheckBox(mLocalizer.msg("caseSensitive", "case sensitive")); String title = p.getTitle(); ArrayList<String> items = new ArrayList<String>(); if (!StringUtils.isEmpty(part)) { String shortTitle = title.trim().substring(0, title.length() - part.length()).trim(); shortTitle = StringUtils.removeEnd(shortTitle, "-").trim(); shortTitle = StringUtils.removeEnd(shortTitle, "(").trim(); items.add(shortTitle + "*"); }/* ww w . j av a 2 s .c o m*/ int index = title.indexOf(" - "); if (index > 0) { items.add(title.substring(0, index).trim() + "*"); } items.add(title); index = title.lastIndexOf(':'); if (index > 0) { items.add(title.substring(0, index).trim() + "*"); } final JComboBox input = new JComboBox(items.toArray(new String[items.size()])); input.setEditable(true); input.addAncestorListener(new AncestorListener() { public void ancestorAdded(final AncestorEvent event) { event.getComponent().requestFocus(); } public void ancestorMoved(final AncestorEvent event) { } public void ancestorRemoved(final AncestorEvent event) { } }); if (JOptionPane.showConfirmDialog(UiUtilities.getLastModalChildOf(getParentFrame()), new Object[] { mLocalizer.msg("exclusionText", "What should be excluded? (You can use the wildcard *)"), input, caseSensitive }, mLocalizer.msg("exclusionTitle", "Exclusion value entering"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { String test = ""; String result = (String) input.getSelectedItem(); if (result != null) { test = result.replaceAll("\\*+", "\\*").trim(); if (test.length() >= 0 && !test.equals("*")) { mSettings.getSearchList() .add(new IDontWant2SeeListEntry(result, caseSensitive.isSelected())); mSettings.setLastEnteredExclusionString(result); updateFilter(!mSettings.isSwitchToMyFilter()); } } if (test.trim().length() <= 1) { JOptionPane.showMessageDialog(UiUtilities.getLastModalChildOf(getParentFrame()), mLocalizer.msg("notValid", "The entered text is not valid."), Localizer.getLocalization(Localizer.I18N_ERROR), JOptionPane.ERROR_MESSAGE); } } } }; }
From source file:com.hangum.tadpole.rdb.core.dialog.export.sqltoapplication.composites.axisj.AxisjComposite.java
/** * sql to str/*from ww w . j av a 2s .c o m*/ */ private void sqlToStr() { StringBuffer sbStr = new StringBuffer(); String[] sqls = parseSQL(); if (StringUtils.isEmpty(textVariable.getText())) { textVariable.setText(textVariable.getText()); } HashMap<String, String> options = new HashMap<String, String>(); options.put("name", textVariable.getText()); options.put("theme", textTheme.getText()); if (StringUtils.isEmpty(spinnerFixedCol.getText())) { options.put("fixedColSeq", "0"); } else { options.put("fixedColSeq", spinnerFixedCol.getText()); } options.put("fitToWidth", btnCheckFit2Width.getSelection() ? "true" : "false"); options.put("colHeadAlign", comboHeadAlign.getText().toLowerCase()); if (StringUtils.containsIgnoreCase(comboMergeCell.getText(), "true")) {// options.put("mergeCells", "true"); } else if (StringUtils.containsIgnoreCase(comboMergeCell.getText(), "false")) {// . options.put("mergeCells", "false"); } else {//? ?? try { String[] array = StringUtils.split(comboMergeCell.getText(), ','); if (array.length > 0) { StringBuffer sb = new StringBuffer(); for (String idx : array) { sb.append(Integer.valueOf(idx) + ","); // ?? ? ?. } options.put("mergeCells", "[" + StringUtils.removeEnd(sb.toString(), ",") + "]"); } else { // ? ?? ?. options.put("mergeCells", "false"); } } catch (Exception e) { options.put("mergeCells", "false"); } } if (StringUtils.containsIgnoreCase(comboHeight.getText(), "auto")) { options.put("height", "\"auto\""); } else { options.put("height", comboHeight.getText()); } options.put("sort", comboSort.getText().toLowerCase()); options.put("colHeadTool", comboHeadTool.getText().toLowerCase()); options.put("viewMode", comboViewMode.getText().toLowerCase()); for (int i = 0; i < sqls.length; i++) { if ("".equals(StringUtils.trimToEmpty(sqls[i]))) //$NON-NLS-1$ continue; if (i == 0) { sbStr.append(slt.sqlToString(sqls[i], options, listAxisjHeader)); } else { options.put("name", textVariable.getText() + "_" + i); sbStr.append(slt.sqlToString(sqls[i], options, listAxisjHeader)); } // ? . sbStr.append("\r\n"); //$NON-NLS-1$ } textConvert.setText(sbStr.toString()); }
From source file:com.google.gdt.eclipse.designer.uibinder.parser.UiBinderContext.java
private void prepareBinderNames() throws Exception { // template// ww w . jav a 2 s.c o m IPath templatePath = m_file.getFullPath(); String templatePathString = templatePath.toPortableString(); // package IPackageFragment uiPackage; { if (!(m_file.getParent() instanceof IFolder)) { throw new DesignerException(IExceptionConstants.NO_FORM_PACKAGE, templatePathString); } // prepare package IFolder uiFolder = (IFolder) m_file.getParent(); IJavaElement uiElement = JavaCore.create(uiFolder); if (!(uiElement instanceof IPackageFragment)) { throw new DesignerException(IExceptionConstants.NO_FORM_PACKAGE, templatePathString); } uiPackage = (IPackageFragment) uiElement; // has client package if (!Utils.isModuleSourcePackage(uiPackage)) { throw new DesignerException(IExceptionConstants.NOT_CLIENT_PACKAGE, templatePathString); } } // binder resource m_binderResourceName = uiPackage.getElementName().replace('.', '/') + "/" + m_file.getName(); // try current package { String formName = StringUtils.removeEnd(m_file.getName(), ".ui.xml"); m_formClassName = uiPackage.getElementName() + "." + formName; m_formType = m_javaProject.findType(m_formClassName); if (m_formType != null) { m_formFile = (IFile) m_formType.getCompilationUnit().getUnderlyingResource(); prepareBinderClass(); if (m_binderClassName != null) { return; } } } // try @UiTemplate IType uiTemplateType = m_javaProject.findType("com.google.gwt.uibinder.client.UiTemplate"); List<IJavaElement> references = CodeUtils.searchReferences(uiTemplateType); for (IJavaElement reference : references) { if (reference instanceof IAnnotation) { IAnnotation annotation = (IAnnotation) reference; IMemberValuePair[] valuePairs = annotation.getMemberValuePairs(); if (valuePairs.length == 1 && valuePairs[0].getValue() instanceof String) { String templateName = (String) valuePairs[0].getValue(); // prepare ICompilationUnit ICompilationUnit compilationUnit = (ICompilationUnit) annotation .getAncestor(IJavaElement.COMPILATION_UNIT); // prepare qualified template name templateName = StringUtils.removeEnd(templateName, ".ui.xml"); if (templateName.contains(".")) { templateName = templateName.replace('.', '/'); } else { String packageName = compilationUnit.getPackageDeclarations()[0].getElementName(); templateName = packageName.replace('.', '/') + "/" + templateName; } templateName += ".ui.xml"; // if found, initialize "form" element if (m_binderResourceName.equals(templateName)) { m_formType = (IType) annotation.getParent().getParent(); m_formClassName = m_formType.getFullyQualifiedName(); m_formFile = (IFile) m_formType.getCompilationUnit().getUnderlyingResource(); prepareBinderClass(); if (m_binderClassName != null) { return; } } } } } // no Java form throw new DesignerException(IExceptionConstants.NO_FORM_TYPE, m_binderResourceName); }
From source file:com.hangum.tadpole.rdb.core.editors.main.composite.resultdetail.ResultTableComposite.java
/** * select table column to editor//from w ww. j ava2s . c o m */ private TableColumnDAO selectColumnToEditor() { if (eventTableSelect == null) return null; final Table tableResult = tvQueryResult.getTable(); TableItem[] selection = tableResult.getSelection(); if (selection.length != 1) return null; TableColumnDAO columnDao = new TableColumnDAO(); TableItem item = tableResult.getSelection()[0]; for (int i = 0; i < tableResult.getColumnCount(); i++) { if (item.getBounds(i).contains(eventTableSelect.x, eventTableSelect.y)) { Map<Integer, Object> mapColumns = getRsDAO().getDataList().getData() .get(tableResult.getSelectionIndex()); // execute extension start =============================== IMainEditorExtension[] extensions = getRdbResultComposite().getRdbResultComposite().getMainEditor() .getMainEditorExtions(); for (IMainEditorExtension iMainEditorExtension : extensions) { iMainEditorExtension.resultSetDoubleClick(i, mapColumns); } // execute extension stop =============================== // ? ? ?? ? ? if (i == 0) { columnDao.setName(PublicTadpoleDefine.DEFINE_TABLE_COLUMN_BASE_ZERO); columnDao.setType(PublicTadpoleDefine.DEFINE_TABLE_COLUMN_BASE_ZERO_TYPE); for (int j = 1; j < tableResult.getColumnCount(); j++) { Object columnObject = mapColumns.get(j); boolean isNumberType = RDBTypeToJavaTypeUtils .isNumberType(getRsDAO().getColumnType().get(j)); if (isNumberType) { String strText = ""; //$NON-NLS-1$ // if select value is null can if (columnObject == null) strText = "0"; //$NON-NLS-1$ else strText = columnObject.toString(); columnDao.setCol_value(columnDao.getCol_value() + strText + ", "); } else if ("BLOB".equalsIgnoreCase(columnDao.getData_type())) { //$NON-NLS-1$ // ignore blob type } else { String strText = ""; //$NON-NLS-1$ // if select value is null can if (columnObject == null) strText = ""; //$NON-NLS-1$ else strText = columnObject.toString(); columnDao.setCol_value(columnDao.getCol_value() + SQLUtil.makeQuote(strText) + ", "); } } columnDao.setCol_value(StringUtils.removeEnd("" + columnDao.getCol_value(), ", ")); break; } else { // ? ?? ? ?? ? ? ? . Object columnObject = mapColumns.get(i); Integer intType = getRsDAO().getColumnType().get(i); if (intType == null) intType = java.sql.Types.VARCHAR; String strType = RDBTypeToJavaTypeUtils.getRDBType(intType); columnDao.setName(getRsDAO().getColumnName().get(i)); columnDao.setType(strType); if (columnObject != null) { // ? ?? clob?? ? ?. if (columnObject instanceof java.sql.Clob) { Clob cl = (Clob) columnObject; StringBuffer clobContent = new StringBuffer(); String readBuffer = new String(); // ? ? clob ? ? ? ? . BufferedReader bufferedReader; try { bufferedReader = new java.io.BufferedReader(cl.getCharacterStream()); while ((readBuffer = bufferedReader.readLine()) != null) { clobContent.append(readBuffer); } columnDao.setCol_value(clobContent.toString()); } catch (Exception e) { logger.error("Clob column echeck", e); //$NON-NLS-1$ } } else if (columnObject instanceof java.sql.Blob) { try { Blob blob = (Blob) columnObject; columnDao.setCol_value(blob.getBinaryStream()); } catch (Exception e) { logger.error("Blob column echeck", e); //$NON-NLS-1$ } } else if (columnObject instanceof byte[]) {// (columnObject.getClass().getCanonicalName().startsWith("byte[]")) ){ byte[] b = (byte[]) columnObject; StringBuffer str = new StringBuffer(); try { for (byte buf : b) { str.append(buf); } str.append("\n\nHex : " + new BigInteger(str.toString(), 2).toString(16)); //$NON-NLS-1$ columnDao.setCol_value(str.toString()); } catch (Exception e) { logger.error("Clob column echeck", e); //$NON-NLS-1$ } } else { String strText = ""; //$NON-NLS-1$ // if select value is null can if (columnObject == null) strText = ""; //$NON-NLS-1$ else strText = columnObject.toString(); columnDao.setCol_value(strText); } } // end object null } // end if first column break; } // for column index } // end for return columnDao; }
From source file:com.adobe.acs.tools.test_page_generator.impl.TestPageGeneratorServlet.java
private Object eval(final ScriptEngine scriptEngine, final Object value) { if (scriptEngine == null) { log.warn("ScriptEngine is null; cannot evaluate"); return value; } else if (value instanceof String[]) { final List<String> scripts = new ArrayList<String>(); final String[] values = (String[]) value; for (final String val : values) { scripts.add(String.valueOf(this.eval(scriptEngine, val))); }/*from w ww. j a va 2 s . com*/ return scripts.toArray(new String[scripts.size()]); } else if (!(value instanceof String)) { return value; } final String stringValue = StringUtils.stripToEmpty((String) value); String script; if (StringUtils.startsWith(stringValue, "{{") && StringUtils.endsWith(stringValue, "}}")) { script = StringUtils.removeStart(stringValue, "{{"); script = StringUtils.removeEnd(script, "}}"); script = StringUtils.stripToEmpty(script); try { return scriptEngine.eval(script); } catch (ScriptException e) { log.error("Could not evaluation the test page property ecma [ {} ]", script); } } return value; }
From source file:eionet.cr.web.util.JstlFunctions.java
/** * * @param factsheetActionBean// www . j av a 2 s.c o m * @param predicateUri * @return */ public static String predicateCollapseLink(FactsheetActionBean factsheetActionBean, String predicateUri) { StringBuilder link = new StringBuilder(); link.append(FactsheetActionBean.class.getAnnotation(UrlBinding.class).value()).append("?"); HttpServletRequest request = factsheetActionBean.getContext().getRequest(); Map<String, String[]> paramsMap = request.getParameterMap(); if (paramsMap != null && !paramsMap.isEmpty()) { for (Map.Entry<String, String[]> entry : paramsMap.entrySet()) { String paramName = entry.getKey(); String[] paramValues = entry.getValue(); if (paramValues == null || paramValues.length == 0) { try { link.append(URLEncoder.encode(paramName, "UTF-8")).append("&"); } catch (UnsupportedEncodingException e) { throw new CRRuntimeException("Unsupported encoding", e); } } else { boolean isPageParam = factsheetActionBean.isPredicatePageParam(paramName); for (String paramValue : paramValues) { if (!isPageParam || !paramValue.equals(predicateUri)) { try { link.append(URLEncoder.encode(paramName, "UTF-8")).append("=") .append(URLEncoder.encode(paramValue, "UTF-8")).append("&"); } catch (UnsupportedEncodingException e) { throw new CRRuntimeException("Unsupported encoding", e); } } } } } } return StringUtils.removeEnd(link.toString(), "&"); }
From source file:info.magnolia.cms.security.SecurityUtil.java
public static String stripPasswordFromUrl(String url) { if (StringUtils.isBlank(url)) { return null; }/* w w w. j av a2 s . c o m*/ String value = null; value = StringUtils.substringBefore(url, "mgnlUserPSWD"); value = value + StringUtils.substringAfter(StringUtils.substringAfter(url, "mgnlUserPSWD"), "&"); return StringUtils.removeEnd(value, "&"); }
From source file:com.egt.core.util.EA.java
private static String coalesceToUserDir(String... folders) { String sep = System.getProperties().getProperty("file.separator"); for (String folder : folders) { if (Utils.isDirectory(folder)) { return StringUtils.removeEnd(folder, sep); }/*from ww w . j a v a2 s.com*/ } String folder = System.getProperties().getProperty("user.dir"); return StringUtils.removeEnd(folder, sep); }
From source file:net.sf.groovyMonkey.ScriptMetadata.java
public static String stripIllegalChars(final String string) { if (StringUtils.isBlank(string)) return ""; if (StringUtils.equals(string.trim(), ">")) return "_"; final boolean prefix = string.trim().startsWith(">"); final boolean postfix = string.trim().endsWith(">"); final String processed = StringUtils.removeEnd(StringUtils.removeStart(string.trim(), ">"), ">"); final StringBuffer buffer = new StringBuffer(); if (processed.contains(">")) { for (final String str : StringUtils.stripAll(StringUtils.split(processed, ">"))) { final StringBuffer stripped = new StringBuffer( compile("[^\\p{Alnum}_-]").matcher(str).replaceAll("")); buffer.append("__").append("" + stripped); }/*from w w w. j av a 2s . co m*/ } else buffer.append(compile("[^\\p{Alnum}_-]").matcher(processed).replaceAll("")); if (prefix) buffer.insert(0, "_"); if (postfix) buffer.append("_"); return "" + buffer; }