List of usage examples for org.apache.commons.lang StringUtils lowerCase
public static String lowerCase(String str)
Converts a String to lower case as per String#toLowerCase() .
From source file:org.dspace.statistics.util.SpiderDetectorServiceImpl.java
/** * Service Method for testing spiders against existing spider files. * <p>/*w ww. j a va2 s . c o m*/ * In future spiders HashSet may be optimized as byte offset array to * improve performance and memory footprint further. * * @param clientIP address of the client. * @param proxyIPs comma-list of X-Forwarded-For addresses, or null. * @param hostname domain name of host, or null. * @param agent User-Agent header value, or null. * @return true if the client matches any spider characteristics list. */ public boolean isSpider(String clientIP, String proxyIPs, String hostname, String agent) { // See if any agent patterns match if (null != agent) { synchronized (agents) { if (agents.isEmpty()) loadPatterns("agents", agents); } if (isUseCaseInsensitiveMatching()) { agent = StringUtils.lowerCase(agent); hostname = StringUtils.lowerCase(hostname); } for (Pattern candidate : agents) { // prevent matcher() invocation from a null Pattern object if (null != candidate && candidate.matcher(agent).find()) { return true; } } } // No. See if any IP addresses match if (isUseProxies() && proxyIPs != null) { /* This header is a comma delimited list */ for (String xfip : proxyIPs.split(",")) { if (isSpider(xfip)) { return true; } } } if (isSpider(clientIP)) return true; // No. See if any DNS names match if (null != hostname) { synchronized (domains) { if (domains.isEmpty()) loadPatterns("domains", domains); } for (Pattern candidate : domains) { // prevent matcher() invocation from a null Pattern object if (null != candidate && candidate.matcher(hostname).find()) { return true; } } } // Not a known spider. return false; }
From source file:org.dspace.statistics.util.SpiderDetectorServiceImpl.java
/** * Load agent name patterns from all files in a single subdirectory of config/spiders. * * @param directory simple directory name (e.g. "agents"). * "${dspace.dir}/config/spiders" will be prepended to yield the path to * the directory of pattern files./*ww w. j a v a2 s .c om*/ * @param patternList patterns read from the files in {@code directory} will * be added to this List. */ private void loadPatterns(String directory, List<Pattern> patternList) { String dspaceHome = configurationService.getProperty("dspace.dir"); File spidersDir = new File(dspaceHome, "config/spiders"); File patternsDir = new File(spidersDir, directory); if (patternsDir.exists() && patternsDir.isDirectory()) { for (File file : patternsDir.listFiles()) { Set<String> patterns; try { patterns = readPatterns(file); } catch (IOException ex) { log.error("Patterns not read from {}: {}", file.getPath(), ex.getMessage()); continue; } //If case insensitive matching is enabled, lowercase the patterns so they can be lowercase matched for (String pattern : patterns) { if (isUseCaseInsensitiveMatching()) { pattern = StringUtils.lowerCase(pattern); } patternList.add(Pattern.compile(pattern)); } log.info("Loaded pattern file: {}", file.getPath()); } } else { log.info("No patterns loaded from {}", patternsDir.getPath()); } }
From source file:org.dspace.storage.rdbms.DatabaseUtils.java
/** * Return the canonical name for a database identifier based on whether this * database defaults to storing identifiers in uppercase or lowercase. * * @param connection //from w w w . jav a 2 s. co m * Current Database Connection * @param dbIdentifier * Identifier to canonicalize (may be a table name, column name, etc) * @return The canonical name of the identifier. * @throws SQLException * An exception that provides information on a database access error or other errors. */ public static String canonicalize(Connection connection, String dbIdentifier) throws SQLException { // Avoid any null pointers if (dbIdentifier == null) return null; DatabaseMetaData meta = connection.getMetaData(); // Check how this database stores its identifiers, etc. // i.e. lowercase vs uppercase (by default we assume mixed case) if (meta.storesLowerCaseIdentifiers()) { return StringUtils.lowerCase(dbIdentifier); } else if (meta.storesUpperCaseIdentifiers()) { return StringUtils.upperCase(dbIdentifier); } else // Otherwise DB doesn't care about case { return dbIdentifier; } }
From source file:org.dspace.storage.rdbms.migration.MigrationUtils.java
/** * Drop a given Database Constraint (based on the current database type). * Returns a "checksum" for this migration which can be used as part of * a Flyway Java migration/*from w w w . ja v a 2s. com*/ * * @param connection the current Database connection * @param tableName the name of the table the constraint applies to * @param columnName the name of the column the constraint applies to * @param constraintSuffix Only used for PostgreSQL, whose constraint naming convention depends on a suffix (key, fkey, etc) * @return migration checksum as an Integer * @throws SQLException if a database error occurs */ protected static Integer dropDBConstraint(Connection connection, String tableName, String columnName, String constraintSuffix) throws SQLException { Integer checksum = -1; // First, in order to drop the appropriate Database constraint, we // must determine the unique name of the constraint. As constraint // naming is DB specific, this is dependent on our DB Type String dbtype = connection.getMetaData().getDatabaseProductName(); String constraintName = null; String constraintNameSQL = null; boolean cascade = false; switch (dbtype.toLowerCase()) { case "postgres": case "postgresql": // In Postgres, constraints are always named: // {tablename}_{columnname(s)}_{suffix} // see: http://stackoverflow.com/a/4108266/3750035 constraintName = StringUtils.lowerCase(tableName); if (!StringUtils.equals(constraintSuffix, "pkey")) { constraintName += "_" + StringUtils.lowerCase(columnName); } constraintName += "_" + StringUtils.lowerCase(constraintSuffix); cascade = true; break; case "oracle": // In Oracle, constraints are listed in the USER_CONS_COLUMNS table constraintNameSQL = "SELECT CONSTRAINT_NAME " + "FROM USER_CONS_COLUMNS " + "WHERE TABLE_NAME = ? AND COLUMN_NAME = ?"; cascade = true; break; case "h2": // In H2, constraints are listed in the "information_schema.constraints" table constraintNameSQL = "SELECT DISTINCT CONSTRAINT_NAME " + "FROM information_schema.constraints " + "WHERE table_name = ? AND column_list = ?"; break; default: throw new SQLException("DBMS " + dbtype + " is unsupported in this migration."); } // If we have a SQL query to run for the constraint name, then run it if (constraintNameSQL != null) { // Run the query to obtain the constraint name, passing it the parameters PreparedStatement statement = connection.prepareStatement(constraintNameSQL); statement.setString(1, StringUtils.upperCase(tableName)); statement.setString(2, StringUtils.upperCase(columnName)); try { ResultSet results = statement.executeQuery(); if (results.next()) { constraintName = results.getString("CONSTRAINT_NAME"); } results.close(); } finally { statement.close(); } } // As long as we have a constraint name, drop it if (constraintName != null && !constraintName.isEmpty()) { // This drop constaint SQL should be the same in all databases String dropConstraintSQL = "ALTER TABLE " + tableName + " DROP CONSTRAINT " + constraintName; if (cascade) { dropConstraintSQL += " CASCADE"; } try (PreparedStatement statement = connection.prepareStatement(dropConstraintSQL)) { statement.execute(); } // Return the size of the query we just ran // This will be our "checksum" for this Flyway migration (see getChecksum()) checksum = dropConstraintSQL.length(); } return checksum; }
From source file:org.dspace.storage.rdbms.MigrationUtils.java
/** * Drop a given Database Constraint (based on the current database type). * Returns a "checksum" for this migration which can be used as part of * a Flyway Java migration//from www . j a v a2 s . c om * * @param connection the current Database connection * @param tableName the name of the table the constraint applies to * @param columnName the name of the column the constraint applies to * @param constraintSuffix Only used for PostgreSQL, whose constraint naming convention depends on a suffix (key, fkey, etc) * @return migration checksum as an Integer * @throws SQLException if a database error occurs */ public static Integer dropDBConstraint(Connection connection, String tableName, String columnName, String constraintSuffix) throws SQLException { Integer checksum = -1; // First, in order to drop the appropriate Database constraint, we // must determine the unique name of the constraint. As constraint // naming is DB specific, this is dependent on our DB Type DatabaseMetaData meta = connection.getMetaData(); // NOTE: We use "findDbKeyword()" here as it won't cause // DatabaseManager.initialize() to be called (which in turn re-calls Flyway) String dbtype = DatabaseManager.findDbKeyword(meta); String constraintName = null; String constraintNameSQL = null; switch (dbtype) { case DatabaseManager.DBMS_POSTGRES: // In Postgres, constraints are always named: // {tablename}_{columnname(s)}_{suffix} // see: http://stackoverflow.com/a/4108266/3750035 constraintName = StringUtils.lowerCase(tableName) + "_" + StringUtils.lowerCase(columnName) + "_" + StringUtils.lowerCase(constraintSuffix); break; case DatabaseManager.DBMS_ORACLE: // In Oracle, constraints are listed in the USER_CONS_COLUMNS table constraintNameSQL = "SELECT CONSTRAINT_NAME " + "FROM USER_CONS_COLUMNS " + "WHERE TABLE_NAME = ? AND COLUMN_NAME = ?"; break; case DatabaseManager.DBMS_H2: // In H2, constraints are listed in the "information_schema.constraints" table constraintNameSQL = "SELECT DISTINCT CONSTRAINT_NAME " + "FROM information_schema.constraints " + "WHERE table_name = ? AND column_list = ?"; break; default: throw new SQLException("DBMS " + dbtype + " is unsupported in this migration."); } // If we have a SQL query to run for the constraint name, then run it if (constraintNameSQL != null) { // Run the query to obtain the constraint name, passing it the parameters PreparedStatement statement = connection.prepareStatement(constraintNameSQL); statement.setString(1, StringUtils.upperCase(tableName)); statement.setString(2, StringUtils.upperCase(columnName)); try { ResultSet results = statement.executeQuery(); if (results.next()) { constraintName = results.getString("CONSTRAINT_NAME"); } results.close(); } finally { statement.close(); } } // As long as we have a constraint name, drop it if (constraintName != null && !constraintName.isEmpty()) { // This drop constaint SQL should be the same in all databases String dropConstraintSQL = "ALTER TABLE " + tableName + " DROP CONSTRAINT " + constraintName; PreparedStatement statement = connection.prepareStatement(dropConstraintSQL); try { statement.execute(); } finally { statement.close(); } // Return the size of the query we just ran // This will be our "checksum" for this Flyway migration (see getChecksum()) checksum = dropConstraintSQL.length(); } return checksum; }
From source file:org.ebayopensource.turmeric.eclipse.soatools.configtool.ConfigTool.java
/** * Gets the type package name from namespace. * * @param namespace the namespace/*from w w w.j a va 2s. c om*/ * @param serviceName the service name * @return the type package name from namespace */ public static String getTypePackageNameFromNamespace(final String namespace, final String serviceName) { final String defaultPkgName = getDefaultPackageNameFromNamespace(namespace); return new StringBuilder(defaultPkgName).append(".").append(StringUtils.lowerCase(serviceName)).toString(); }
From source file:org.ebayopensource.turmeric.eclipse.test.utils.ServicesUtil.java
/** * Creates the new svc frm wsdl.//from w ww . ja v a2s. c o m * * @param name the name * @param location the location * @param domainClassifier the domain classifier * @return true, if successful */ public static boolean createNewSvcFrmWsdl(String name, String location, String domainClassifier) { try { final ServiceFromTemplateWsdlParamModel model = new ServiceFromTemplateWsdlParamModel(); final String v3ViewRoot = JavaCore.getClasspathVariable("V3_VIEW_ROOT").toString(); final URL templateFile = new URL(v3ViewRoot + "\\nexustools\\com.ebay.tools\\com.ebay.tools.soa\\plugins\\com.ebay.tools.soa.config\\templates\\wsdl\\marketplace\\Marketplace_NoOperationTemplate.wsdl"); String publicServiceName = getPublicServiceName(name, domainClassifier); String nsPart = StringUtils.lowerCase(domainClassifier); String targetNamespace = getTargetNamespace(domainClassifier); String interfacePackage = getInterfacePackage(name, targetNamespace); String implClass = SOAServiceUtil.generateServiceImplClassName(publicServiceName, name, targetNamespace); List<Operation> operations = new ArrayList<Operation>(); final Operation op = ServiceFromTemplateWsdlParamModel.createOperation("getVersion"); op.getOutputParameter().getElements().get(0).setName("version"); operations.add(op); final Set<Binding> bindings = new LinkedHashSet<Binding>(); final Binding binding0 = new Binding(SOAProjectConstants.TemplateBinding.values()[0]); final Binding binding1 = new Binding(SOAProjectConstants.TemplateBinding.values()[1]); bindings.add(binding0); bindings.add(binding1); model.setTemplateFile(templateFile); model.setTargetNamespace(targetNamespace); model.setServiceName(name); model.setServiceInterface(interfacePackage); model.setWorkspaceRootDirectory(location); model.setServiceImpl(implClass); model.setServiceVersion("1.0.0"); model.setImplName(name + "Impl"); model.setWSDLSourceType(SOAProjectConstants.InterfaceWsdlSourceType.NEW); model.setPublicServiceName(publicServiceName); model.setServiceLayer("COMMON"); model.setServiceDomain(domainClassifier); model.setNamespacePart(nsPart); model.setOperations(operations); model.setBindings(bindings); model.setTypeFolding(true); model.setTypeNamespace(targetNamespace); SimpleTestUtil.setAutoBuilding(false); ServiceCreator.createServiceFromBlankWSDL(model, ProgressUtil.getDefaultMonitor(null)); WorkspaceUtil.getProject(model.getServiceName()).build(IncrementalProjectBuilder.FULL_BUILD, ProgressUtil.getDefaultMonitor(null)); WorkspaceUtil.getProject(model.getImplName() + "Impl").build(IncrementalProjectBuilder.FULL_BUILD, ProgressUtil.getDefaultMonitor(null)); SimpleTestUtil.setAutoBuilding(true); return true; } catch (Exception e) { return false; } }
From source file:org.ebayopensource.turmeric.eclipse.test.utils.ServicesUtil.java
/** * Gets the target namespace./*from w ww . j a v a 2 s. c om*/ * * @param domainClassifier the domain classifier * @return the target namespace */ public static String getTargetNamespace(String domainClassifier) { String nsPart = StringUtils.lowerCase(domainClassifier); String targetNS = TurmericConstants.DEFAULT_SERVICE_NAMESPACE_PREFIX + "/" + nsPart + "/" + MAJOR_VERSION_PREFIX.toLowerCase() + SERVICE_MAJOR_VERSION + TurmericConstants.DEFAULT_SERVICE_NAMESPACE_SUFFIX; return targetNS; }
From source file:org.ebayopensource.turmeric.eclipse.test.utils.TLUtil.java
/** * Gets the target namespace.//from w w w. java 2s .c o m * * @param domainClassifier the domain classifier * @return the target namespace */ public static String getTargetNamespace(String domainClassifier) { return TurmericOrganizationProvider.INSTANCE.generateTypeLibraryTargetNamespace(domainClassifier, StringUtils.lowerCase(domainClassifier), "1.0.0"); }
From source file:org.eclipse.gyrex.admin.ui.jobs.internal.TimeZoneProposals.java
@Override public IContentProposal[] getProposals(final String contents, final int position) { final List<IContentProposal> resultList = new ArrayList<IContentProposal>(); final String patternString = StringUtils.trimToNull(StringUtils.substring(contents, 0, position)); final String[] availableIDs = TimeZone.getAvailableIDs(); Arrays.sort(availableIDs);//from w w w .j a v a 2 s .co m for (final String id : availableIDs) { final TimeZone timeZone = TimeZone.getTimeZone(id); if ((null == patternString) || StringUtils.contains(StringUtils.lowerCase(timeZone.getID()), StringUtils.lowerCase(patternString))) { resultList.add( new ContentProposal(timeZone.getID(), id + " - " + timeZone.getDisplayName(Locale.US))); } } return resultList.toArray(new IContentProposal[resultList.size()]); }