List of usage examples for org.apache.commons.lang StringUtils startsWith
public static boolean startsWith(String str, String prefix)
Check if a String starts with a specified prefix.
From source file:org.apache.sling.dynamicinclude.ConfigurationWhiteboard.java
private boolean isEnabled(Configuration config, SlingHttpServletRequest request) { final String requestPath = request.getRequestPathInfo().getResourcePath(); return config.isEnabled() && StringUtils.startsWith(requestPath, config.getBasePath()); }
From source file:org.apache.sling.superimposing.impl.SuperimposingManagerImpl.java
/** * @param superimposingResource/*from w ww . j av a 2 s . c om*/ * @return true if registration was done, false if skipped (already registered) * @throws RepositoryException */ private boolean registerProvider(Resource superimposingResource) { String superimposePath = superimposingResource.getPath(); // use JCR API to get properties from superimposing resource to make sure superimposing does not delivery values from source node final String sourcePath = getJcrStringProperty(superimposePath, PROP_SUPERIMPOSE_SOURCE_PATH); final boolean registerParent = getJcrBooleanProperty(superimposePath, PROP_SUPERIMPOSE_REGISTER_PARENT); final boolean overlayable = getJcrBooleanProperty(superimposePath, PROP_SUPERIMPOSE_OVERLAYABLE); // check if superimposing definition is valid boolean valid = true; if (StringUtils.isBlank(sourcePath)) { valid = false; } else { // check whether the parent of the node should be registered as superimposing provider if (registerParent) { superimposePath = ResourceUtil.getParent(superimposePath); } // target path is not valid if it equals to a parent or child of the superimposing path, or to the superimposing path itself if (StringUtils.equals(sourcePath, superimposePath) || StringUtils.startsWith(sourcePath, superimposePath + "/") || StringUtils.startsWith(superimposePath, sourcePath + "/")) { valid = false; } } // register valid superimposing if (valid) { final SuperimposingResourceProviderImpl srp = new SuperimposingResourceProviderImpl(superimposePath, sourcePath, overlayable); final SuperimposingResourceProviderImpl oldSrp = superimposingProviders.put(superimposePath, srp); // unregister in case there was a provider registered before if (!srp.equals(oldSrp)) { log.debug("(Re-)registering resource provider {}.", superimposePath); if (null != oldSrp) { oldSrp.unregisterService(); } srp.registerService(bundleContext); return true; } else { log.debug("Skipped re-registering resource provider {} because there were no relevant changes.", superimposePath); } } // otherwise remove previous superimposing resource provider if new superimposing definition is not valid else { final SuperimposingResourceProviderImpl oldSrp = superimposingProviders.remove(superimposePath); if (null != oldSrp) { log.debug("Unregistering resource provider {}.", superimposePath); oldSrp.unregisterService(); } log.warn("Superimposing definition '{}' pointing to '{}' is invalid.", superimposePath, sourcePath); } return false; }
From source file:org.apache.sling.superimposing.impl.SuperimposingResourceProviderImpl.java
/** * Maps a path below the superimposing root to the target resource's path with check for overlaying. * @param provider Superimposing resource provider * @param resolver Resource resolver/*from www. ja v a2s . c o m*/ * @param path Path to map * @return Mapped path or null if no mapping available */ static String mapPathWithOverlay(SuperimposingResourceProviderImpl provider, ResourceResolver resolver, String path) { if (StringUtils.equals(path, provider.rootPath)) { // Superimposing root path cannot be overlayed return mapPathWithoutOverlay(provider, resolver, path); } else if (StringUtils.startsWith(path, provider.rootPrefix)) { if (hasOverlayResource(resolver, path)) { // overlay item exists, allow underlying resource provider to step in return null; } else { // overlay item does not exist, overlay cannot be applied, fallback to mapped path without overlay return mapPathWithoutOverlay(provider, resolver, path); } } return null; }
From source file:org.apache.sling.superimposing.impl.SuperimposingResourceProviderImpl.java
/** * Maps a path below the superimposing root to the target resource's path without check for overlaying. * @param provider Superimposing resource provider * @param resolver Resource resolver// w w w . j a va2 s . c om * @param path Path to map * @return Mapped path or null if no mapping available */ static String mapPathWithoutOverlay(SuperimposingResourceProviderImpl provider, ResourceResolver resolver, String path) { final String mappedPath; if (StringUtils.equals(path, provider.rootPath)) { mappedPath = provider.sourcePath; } else if (StringUtils.startsWith(path, provider.rootPrefix)) { mappedPath = StringUtils.replaceOnce(path, provider.rootPrefix, provider.sourcePathPrefix); } else { mappedPath = null; } return mappedPath; }
From source file:org.apache.solr.cloud.ExclusiveSliceProperty.java
ExclusiveSliceProperty(ClusterState clusterState, ZkNodeProps message) { this.clusterState = clusterState; String tmp = message.getStr(ZkStateReader.PROPERTY_PROP); if (StringUtils.startsWith(tmp, OverseerCollectionMessageHandler.COLL_PROP_PREFIX) == false) { tmp = OverseerCollectionMessageHandler.COLL_PROP_PREFIX + tmp; }/* w w w. j av a2 s .c o m*/ this.property = tmp.toLowerCase(Locale.ROOT); collectionName = message.getStr(ZkStateReader.COLLECTION_PROP); if (StringUtils.isBlank(collectionName) || StringUtils.isBlank(property)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Overseer '" + message.getStr(Overseer.QUEUE_OPERATION) + "' requires both the '" + ZkStateReader.COLLECTION_PROP + "' and '" + ZkStateReader.PROPERTY_PROP + "' parameters. No action taken "); } Boolean shardUnique = Boolean.parseBoolean(message.getStr(SHARD_UNIQUE)); if (shardUnique == false && SliceMutator.SLICE_UNIQUE_BOOLEAN_PROPERTIES.contains(this.property) == false) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Balancing properties amongst replicas in a slice requires that" + " the property be a pre-defined property (e.g. 'preferredLeader') or that 'shardUnique' be set to 'true' " + " Property: " + this.property + " shardUnique: " + Boolean.toString(shardUnique)); } collection = clusterState.getCollection(collectionName); if (collection == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not find collection ' " + collectionName + "' for overseer operation '" + message.getStr(Overseer.QUEUE_OPERATION) + "'. No action taken."); } onlyActiveNodes = Boolean.parseBoolean(message.getStr(ONLY_ACTIVE_NODES, "true")); }
From source file:org.apache.solr.cloud.overseer.ReplicaMutator.java
public ZkWriteCommand addReplicaProperty(ClusterState clusterState, ZkNodeProps message) { if (checkKeyExistence(message, ZkStateReader.COLLECTION_PROP) == false || checkKeyExistence(message, ZkStateReader.SHARD_ID_PROP) == false || checkKeyExistence(message, ZkStateReader.REPLICA_PROP) == false || checkKeyExistence(message, ZkStateReader.PROPERTY_PROP) == false || checkKeyExistence(message, ZkStateReader.PROPERTY_VALUE_PROP) == false) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Overseer ADDREPLICAPROP requires " + ZkStateReader.COLLECTION_PROP + " and " + ZkStateReader.SHARD_ID_PROP + " and " + ZkStateReader.REPLICA_PROP + " and " + ZkStateReader.PROPERTY_PROP + " and " + ZkStateReader.PROPERTY_VALUE_PROP + " no action taken."); }//w w w . j a v a2 s .c om String collectionName = message.getStr(ZkStateReader.COLLECTION_PROP); String sliceName = message.getStr(ZkStateReader.SHARD_ID_PROP); String replicaName = message.getStr(ZkStateReader.REPLICA_PROP); String property = message.getStr(ZkStateReader.PROPERTY_PROP).toLowerCase(Locale.ROOT); if (StringUtils.startsWith(property, COLL_PROP_PREFIX) == false) { property = OverseerCollectionMessageHandler.COLL_PROP_PREFIX + property; } property = property.toLowerCase(Locale.ROOT); String propVal = message.getStr(ZkStateReader.PROPERTY_VALUE_PROP); String shardUnique = message.getStr(OverseerCollectionMessageHandler.SHARD_UNIQUE); boolean isUnique = false; if (SliceMutator.SLICE_UNIQUE_BOOLEAN_PROPERTIES.contains(property)) { if (StringUtils.isNotBlank(shardUnique) && Boolean.parseBoolean(shardUnique) == false) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Overseer ADDREPLICAPROP for " + property + " cannot have " + OverseerCollectionMessageHandler.SHARD_UNIQUE + " set to anything other than" + "'true'. No action taken"); } isUnique = true; } else { isUnique = Boolean.parseBoolean(shardUnique); } DocCollection collection = clusterState.getCollection(collectionName); Replica replica = collection.getReplica(replicaName); if (replica == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not find collection/slice/replica " + collectionName + "/" + sliceName + "/" + replicaName + " no action taken."); } log.info("Setting property {} with value {} for collection {}", property, propVal, collectionName); log.debug("Full message: {}", message); if (StringUtils.equalsIgnoreCase(replica.getStr(property), propVal)) return ZkStateWriter.NO_OP; // already the value we're going to set // OK, there's no way we won't change the cluster state now Map<String, Replica> replicas = collection.getSlice(sliceName).getReplicasCopy(); if (isUnique == false) { replicas.get(replicaName).getProperties().put(property, propVal); } else { // Set prop for this replica, but remove it for all others. for (Replica rep : replicas.values()) { if (rep.getName().equalsIgnoreCase(replicaName)) { rep.getProperties().put(property, propVal); } else { rep.getProperties().remove(property); } } } Slice newSlice = new Slice(sliceName, replicas, collection.getSlice(sliceName).shallowCopy()); DocCollection newCollection = CollectionMutator.updateSlice(collectionName, collection, newSlice); return new ZkWriteCommand(collectionName, newCollection); }
From source file:org.apache.solr.cloud.overseer.ReplicaMutator.java
public ZkWriteCommand deleteReplicaProperty(ClusterState clusterState, ZkNodeProps message) { if (checkKeyExistence(message, ZkStateReader.COLLECTION_PROP) == false || checkKeyExistence(message, ZkStateReader.SHARD_ID_PROP) == false || checkKeyExistence(message, ZkStateReader.REPLICA_PROP) == false || checkKeyExistence(message, ZkStateReader.PROPERTY_PROP) == false) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Overseer DELETEREPLICAPROP requires " + ZkStateReader.COLLECTION_PROP + " and " + ZkStateReader.SHARD_ID_PROP + " and " + ZkStateReader.REPLICA_PROP + " and " + ZkStateReader.PROPERTY_PROP + " no action taken."); }/*from ww w.j av a 2 s . c o m*/ String collectionName = message.getStr(ZkStateReader.COLLECTION_PROP); String sliceName = message.getStr(ZkStateReader.SHARD_ID_PROP); String replicaName = message.getStr(ZkStateReader.REPLICA_PROP); String property = message.getStr(ZkStateReader.PROPERTY_PROP).toLowerCase(Locale.ROOT); if (StringUtils.startsWith(property, COLL_PROP_PREFIX) == false) { property = OverseerCollectionMessageHandler.COLL_PROP_PREFIX + property; } DocCollection collection = clusterState.getCollection(collectionName); Replica replica = collection.getReplica(replicaName); if (replica == null) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Could not find collection/slice/replica " + collectionName + "/" + sliceName + "/" + replicaName + " no action taken."); } log.info("Deleting property {} for collection: {} slice: {} replica: {}", property, collectionName, sliceName, replicaName); log.debug("Full message: {}", message); String curProp = replica.getStr(property); if (curProp == null) return ZkStateWriter.NO_OP; // not there anyway, nothing to do. Slice slice = collection.getSlice(sliceName); DocCollection newCollection = SliceMutator.updateReplica(collection, slice, replicaName, unsetProperty(replica, property)); return new ZkWriteCommand(collectionName, newCollection); }
From source file:org.apache.solr.cloud.SSLMigrationTest.java
private void assertReplicaInformation(String urlScheme) throws Exception { List<Replica> replicas = getReplicas(); assertEquals("Wrong number of replicas found", 4, replicas.size()); for (Replica replica : replicas) { assertTrue("Replica didn't have the proper urlScheme in the ClusterState", StringUtils.startsWith(replica.getStr(ZkStateReader.BASE_URL_PROP), urlScheme)); }//from ww w . ja v a 2s.c o m }
From source file:org.apache.tika.server.resource.TikaResource.java
public static void fillParseContext(ParseContext parseContext, MultivaluedMap<String, String> httpHeaders, Parser embeddedParser) {/* w ww.j av a2 s . c o m*/ TesseractOCRConfig ocrConfig = new TesseractOCRConfig(); PDFParserConfig pdfParserConfig = new PDFParserConfig(); for (String key : httpHeaders.keySet()) { if (StringUtils.startsWith(key, X_TIKA_OCR_HEADER_PREFIX)) { processHeaderConfig(httpHeaders, ocrConfig, key, X_TIKA_OCR_HEADER_PREFIX); } else if (StringUtils.startsWith(key, X_TIKA_PDF_HEADER_PREFIX)) { processHeaderConfig(httpHeaders, pdfParserConfig, key, X_TIKA_PDF_HEADER_PREFIX); } } parseContext.set(TesseractOCRConfig.class, ocrConfig); parseContext.set(PDFParserConfig.class, pdfParserConfig); if (embeddedParser != null) { parseContext.set(Parser.class, embeddedParser); } }
From source file:org.apache.torque.util.ExceptionMapperImpl.java
@Override public TorqueException toTorqueException(SQLException sqlException) { if (StringUtils.startsWith(sqlException.getSQLState(), "23")) { return new ConstraintViolationException(sqlException); }/*from w w w. jav a2 s .co m*/ if (StringUtils.equals(sqlException.getSQLState(), "40001")) { // mysql, derby, mssql return new DeadlockException(sqlException); } if (StringUtils.equals(sqlException.getSQLState(), "40P01")) { // postgresql return new DeadlockException(sqlException); } if (StringUtils.equals(sqlException.getSQLState(), "61000") && sqlException.getErrorCode() == 60) { // oracle return new DeadlockException(sqlException); } return new TorqueException(sqlException); }