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:com.hangum.tadpole.engine.sql.util.SQLUtil.java
private static String makeFullyTableName(String tableName, String strIdentifier) { String retStr = ""; for (String chunk : StringUtils.split(tableName, '.')) { retStr += strIdentifier + chunk + strIdentifier + "."; }/*from ww w . j a v a2 s . c om*/ retStr = StringUtils.removeEnd(retStr, "."); return retStr; }
From source file:com.google.gdt.eclipse.designer.builders.participant.MyCompilationParticipant.java
/** * Adds error markers for types that are not visible in inherited "source" packages. *///from w w w.j a va 2s. co m private void addMarkers_notImportedTypes(final List<MarkerInfo> newMarkers, final IResourcesProvider resourcesProvider, ModuleDescription moduleDescription, CompilationUnit astUnit, final IFile file, final IDocument document) throws Exception { final IJavaProject javaProject = JavaCore.create(file.getProject()); // prepare list of source packages final List<SourcePackageDescriptor> sourcePackages = Lists.newArrayList(); ModuleVisitor.accept(moduleDescription, new ModuleVisitor() { @Override public void visitSourcePackage(ModuleElement module, String packageName, boolean superSource) throws Exception { sourcePackages.add(new SourcePackageDescriptor(packageName, superSource)); } }); // validate all types in CompilationUnit astUnit.accept(new ASTVisitor() { private final Set<String> m_validClasses = Sets.newTreeSet(); private final Set<String> m_invalidClasses = Sets.newTreeSet(); @Override public boolean visit(SingleMemberAnnotation node) { return false; } @Override public boolean visit(NormalAnnotation node) { return false; } @Override public void postVisit(final ASTNode node) { ExecutionUtils.runIgnore(new RunnableEx() { public void run() throws Exception { postVisitEx(node); } }); } private void postVisitEx(ASTNode node) throws Exception { // ignore imports if (AstNodeUtils.getEnclosingNode(node, ImportDeclaration.class) != null) { return; } // check known cases if (node instanceof SimpleType) { SimpleType simpleType = (SimpleType) node; ITypeBinding typeBinding = simpleType.resolveBinding(); checkNode(node, typeBinding); } else if (node instanceof SimpleName) { SimpleName simpleName = (SimpleName) node; if (simpleName.resolveBinding().getKind() == IBinding.TYPE && node.getLocationInParent() == MethodInvocation.EXPRESSION_PROPERTY) { ITypeBinding typeBinding = simpleName.resolveTypeBinding(); checkNode(node, typeBinding); } } } private void checkNode(ASTNode node, ITypeBinding typeBinding) throws Exception { if (typeBinding != null) { // ignore generics type variable if (typeBinding.isTypeVariable()) { return; } // only top level types can be found as source while (typeBinding.getDeclaringClass() != null) { typeBinding = typeBinding.getDeclaringClass(); } // check this type String typeName = AstNodeUtils.getFullyQualifiedName(typeBinding, true); if (isSecondarySourceType(typeName)) { return; } checkClass(node, typeName); } } private boolean isSecondarySourceType(String typeName) throws Exception { // usually secondary type can not be found using this way IType type = javaProject.findType(typeName); if (type == null) { return true; } // "secondary source type" has compilation unit ICompilationUnit compilationUnit = type.getCompilationUnit(); if (compilationUnit == null) { return false; } // check if type name in same as unit name String unitName = compilationUnit.getElementName(); unitName = StringUtils.removeEnd(unitName, ".java"); return !typeName.endsWith("." + unitName); } /** * Check that class with given name is defined in this or inherited module. */ private void checkClass(ASTNode node, String className) throws Exception { if (!isValid(className)) { markAsInvalid(node, className); } } /** * @return <code>true</code> if given class is valid. */ private boolean isValid(String className) { // check cached valid classes if (m_validClasses.contains(className)) { return true; } // check cached invalid classes if (m_invalidClasses.contains(className)) { return false; } // no information in caches, do checks for (SourcePackageDescriptor sourcePackageDescriptor : sourcePackages) { if (sourcePackageDescriptor.isValidClass(resourcesProvider, className)) { m_validClasses.add(className); return true; } } // mark as invalid m_invalidClasses.add(className); return false; } private void markAsInvalid(ASTNode node, String className) throws Exception { String message = className + " can not be found in source packages. " + "Check the inheritance chain from your module; " + "it may not be inheriting a required module or a module " + "may not be adding its source path entries properly."; String moduleNameToImport = getEnclosingModule(resourcesProvider, className); newMarkers.add(createMarkerInfo_importModule(file, document, node.getStartPosition(), node.getLength(), message, moduleNameToImport)); } }); }
From source file:com.hangum.tadpole.rdb.core.dialog.restfulapi.MainSQLEditorAPIServiceDialog.java
private void executeQuery(String strSQL, String strArgument) { try {/*from ww w . ja v a2s.c o m*/ String strReturnResult = ""; //$NON-NLS-1$ // velocity if else . String strSQLs = RESTfulAPIUtils.makeTemplateTOSQL("APIServiceDialog", strSQL, strArgument); //$NON-NLS-1$ // ? ? . for (String strTmpSQL : strSQLs.split(PublicTadpoleDefine.SQL_DELIMITER)) { if (StringUtils.trim(strTmpSQL).equals("")) continue; NamedParameterDAO dao = NamedParameterUtil.parseParameterUtils(userDB, strTmpSQL, strArgument); if (QueryUtils.RESULT_TYPE.JSON.name().equalsIgnoreCase(comboResultType.getText())) { strReturnResult += getSelect(userDB, dao.getStrSQL(), dao.getListParam()) + ","; //$NON-NLS-1$ } else { strReturnResult += getSelect(userDB, dao.getStrSQL(), dao.getListParam()); } } if (QueryUtils.RESULT_TYPE.JSON.name().equalsIgnoreCase(comboResultType.getText())) { strReturnResult = "[" + StringUtils.removeEnd(strReturnResult, ",") + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } textResult.setText(strReturnResult); } catch (Exception e) { logger.error("api exception", e); //$NON-NLS-1$ MessageDialog.openError(getShell(), CommonMessages.get().Error, e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ } }
From source file:com.dp2345.Setting.java
/** * ?// www .j av a2s . co m * * @param siteUrl * ? */ public void setSiteUrl(String siteUrl) { this.siteUrl = StringUtils.removeEnd(siteUrl, "/"); }
From source file:com.qualogy.qafe.business.resource.rdb.query.QueryToStringCreator.java
/** * Remove clause in case it is the last key in sql statement * @return/*from w w w . j ava 2 s . c o m*/ */ private static String removeFromEnd(String sql, String clause) { return StringUtils.removeEnd(sql.trim(), clause).concat(" "); }
From source file:com.hangum.tadpole.rdb.core.viewers.object.sub.utils.TadpoleObjectQuery.java
/** * Table ? /* w w w .jav a2 s . c om*/ * * @param showTables * @param userDB * @return */ private static List<TableDAO> getTableAfterwork(List<TableDAO> showTables, final UserDBDAO userDB) { /** filter . */ showTables = DBAccessCtlManager.getInstance().getTableFilter(showTables, userDB); // ? ?? . ' " ???. StringBuffer strViewList = new StringBuffer(); for (TableDAO td : showTables) { td.setSysName(SQLUtil.makeIdentifierName(userDB, td.getName())); strViewList .append(MakeContentAssistUtil.makeObjectPattern(td.getSchema_name(), td.getSysName(), "Table")); //$NON-NLS-1$ } userDB.setTableListSeparator( StringUtils.removeEnd(strViewList.toString(), MakeContentAssistUtil._PRE_GROUP)); //$NON-NLS-1$ // setting UserDBDAO userDB.setListTable(showTables); return showTables; }
From source file:com.cimmyt.model.dao.impl.AbstractDAO.java
/** * Find single by values/*from www . java 2 s. c o m*/ * @param clazz * @param properties * @param values * @return * @throws Exception */ public T findSingleByValues(T clazz, Object[] properties, Object[] values) throws Exception { if (properties.length != values.length) { throw new Exception("The number of properties must be the same than the number of values"); } String strClazz = type.getSimpleName(); StringBuilder builder = new StringBuilder("SELECT DISTINCT a FROM " + strClazz + " a" + " WHERE "); for (int i = 0; i < values.length; i++) { if (values[i] instanceof String) { builder.append("a." + properties[i] + " LIKE ?"); } else { builder.append("a." + properties[i] + " = ?"); } builder.append(" AND "); } String query = builder.toString().trim(); if (StringUtils.endsWith(query, "AND")) { query = StringUtils.removeEnd(query, "AND"); } @SuppressWarnings("unchecked") List<T> list = (List<T>) getHibernateTemplate().find(query, values); if (list != null && !list.isEmpty()) { return list.get(0); } else { return null; } }
From source file:com.hangum.tadpole.rdb.core.editors.main.utils.ExtMakeContentAssistUtil.java
/** * List of assist table column name/*from w w w .j av a2 s . c o m*/ * * @param userDB * @param tableName * @return */ public String getAssistColumnList(final UserDBDAO userDB, final String tableName) { String strColumnlist = ""; //$NON-NLS-1$ String strSchemaName = ""; String strTableName = tableName; if (userDB.getDBDefine() != DBDefine.ALTIBASE_DEFAULT) { if (StringUtils.contains(tableName, '.')) { String[] arrTblInfo = StringUtils.split(tableName, "."); strSchemaName = arrTblInfo[0]; strTableName = arrTblInfo[1]; } } // ? ? ?? ? ? ? . TadpoleMetaData tadpoleMetaData = TadpoleSQLManager.getDbMetadata(userDB); if (tadpoleMetaData.getSTORE_TYPE() == TadpoleMetaData.STORES_FIELD_TYPE.LOWCASE_BLANK) { strSchemaName = StringUtils.upperCase(strSchemaName); strTableName = StringUtils.upperCase(strTableName); } else if (tadpoleMetaData.getSTORE_TYPE() == TadpoleMetaData.STORES_FIELD_TYPE.UPPERCASE_BLANK) { strSchemaName = StringUtils.lowerCase(strSchemaName); strTableName = StringUtils.lowerCase(strTableName); } try { TableDAO table = new TableDAO(strTableName, ""); table.setSysName(strTableName); table.setSchema_name(strSchemaName); table.setName(strTableName); List<TableColumnDAO> showTableColumns = TadpoleObjectQuery.getTableColumns(userDB, table); for (TableColumnDAO tableDao : showTableColumns) { strColumnlist += tableDao.getSysName() + _PRE_DEFAULT + tableDao.getType() + _PRE_GROUP; //$NON-NLS-1$ } strColumnlist = StringUtils.removeEnd(strColumnlist, _PRE_GROUP); //$NON-NLS-1$ } catch (Exception e) { logger.error("MainEditor get the table column list", e); //$NON-NLS-1$ } return strColumnlist; }
From source file:com.photon.phresco.util.Utility.java
private static String getEclipseHome() { IPath location = null;//from ww w .jav a 2 s. com String workingPath = ""; ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getSelection(); if (!selection.isEmpty() && selection instanceof IStructuredSelection) { Object[] selectedObjects = ((IStructuredSelection) selection).toArray(); for (Object object : selectedObjects) { if (object instanceof IProject) { IProject iProject = (IProject) object; location = iProject.getLocation(); } if (object instanceof IJavaProject) { IJavaProject project = (IJavaProject) object; project.getJavaModel().getPath(); location = project.getProject().getLocation(); } } String dir = location.toOSString(); workingPath = StringUtils.removeEnd(dir, location.lastSegment()); } else { String workingDir = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() + File.separatorChar + "projects"; File filePath = new File(workingDir); if (!filePath.isDirectory()) { filePath.mkdir(); } workingPath = filePath.getPath() + File.separatorChar; } return workingPath; }
From source file:gobblin.compaction.dataset.Dataset.java
private Path simplifyOutputPath() { Path simplifiedPath = new Path(StringUtils.removeEnd(this.outputPath.toString(), this.jobProps().getProp(MRCompactor.COMPACTION_JOB_DEST_PARTITION, StringUtils.EMPTY))); simplifiedPath = new Path(StringUtils.removeEnd(simplifiedPath.toString(), this.jobProps() .getProp(MRCompactor.COMPACTION_DEST_SUBDIR, MRCompactor.DEFAULT_COMPACTION_DEST_SUBDIR))); return simplifiedPath; }