List of usage examples for org.apache.commons.lang StringUtils substringBeforeLast
public static String substringBeforeLast(String str, String separator)
Gets the substring before the last occurrence of a separator.
From source file:org.betaconceptframework.astroboa.model.factory.CriterionFactory.java
private static void processValueAndAddItToCriterion(String referenceIdOrSystemName, SimpleCriterion referenceCriterion, String expectedPrefix) { if (referenceIdOrSystemName != null && referenceCriterion != null) { //1. Reference Id or system name may end with /* // This is taken into account only when criterion // corresponds to a Topic Reference if (referenceCriterion instanceof TopicReferenceCriterion && referenceIdOrSystemName.endsWith(CmsConstants.INCLUDE_CHILDREN_EXPRESSION)) { ((TopicReferenceCriterion) referenceCriterion).expandCriterionToIncludeSubTopics(); //Remove suffix and continue processing referenceIdOrSystemName = StringUtils.substringBeforeLast(referenceIdOrSystemName, CmsConstants.INCLUDE_CHILDREN_EXPRESSION); }//from w ww .j a v a 2s .co m //2. In all other cases, add value as is if (!referenceIdOrSystemName.startsWith(expectedPrefix)) { if (CmsConstants.UUIDPattern.matcher(referenceIdOrSystemName).matches()) { referenceCriterion.addValue(referenceIdOrSystemName); } //3. If value represents a system name , add the proper prefix else { referenceCriterion.addValue(expectedPrefix + referenceIdOrSystemName); } } else { referenceCriterion.addValue(referenceIdOrSystemName); } } }
From source file:org.betaconceptframework.astroboa.model.impl.query.criteria.CmsCriteriaImpl.java
public String getXPathQuery() { //XPathQuery has been calculated once. if (StringUtils.isNotBlank(xpathQuery)) return xpathQuery; String xpathselect = XPathUtils.createXPathSelect(null, nodeType, isNodeTypeAChildNode); //Add to xpath select ancestor xpath OR path criterion String ancestorXPathQuery = getAncestorQuery(); if (StringUtils.isNotBlank(ancestorXPathQuery)) { //Due to the automatic addition of order by clause we have to remove any //order by clause created if (ancestorXPathQuery.contains(CmsConstants.ORDER_BY)) { ancestorXPathQuery = StringUtils.substringBeforeLast(ancestorXPathQuery, CmsConstants.ORDER_BY); }//from ww w . jav a 2 s. c o m xpathselect = ancestorXPathQuery + xpathselect; } else if (StringUtils.isNotBlank(pathCriterion)) { xpathselect = pathCriterion + xpathselect; } // Connect each criterion with AND condition //Add default criterion for system built in entity Criterion currentCriterion = null; if (CollectionUtils.isNotEmpty(getCriteria())) { for (Criterion criterion : getCriteria()) { if (currentCriterion == null) { currentCriterion = criterion; } else { currentCriterion = CriterionFactory.and(currentCriterion, criterion); } } } String orderBy = ""; if (MapUtils.isNotEmpty(getOrderProperties())) { OrderByClauseHelper orderByClauseHelper = new OrderByClauseHelper(getOrderProperties()); orderBy = orderByClauseHelper.generateOrderBy(); } else { //Special case. Due to the fact that the JCR spec does not provide a method //for retrieving the total number of hits regardless of the limit, //we have to use the method provided by Jackrabbit (the JCR reference implementation). //Unfortunately, since version 2.x , this method returns -1 in cases where the size //is unknown even when the queries do not match any object at all. In order to //force the implementation to return the number of total hits we have to provide //an order by property. Therefore, in criteria where no order by property is provided //we explicitly instruct Jackrabbit to order the results by the jcr:score property. OrderByClauseHelper orderByClauseHelper = new OrderByClauseHelper(JcrBuiltInItem.JcrScore.getJcrName(), Order.descending); orderBy = orderByClauseHelper.generateOrderBy(); } String criteriaPath = (currentCriterion == null) ? "" : currentCriterion.getXPath(); xpathQuery = xpathselect + ((StringUtils.isBlank(criteriaPath) ? "" : CmsConstants.LEFT_BRACKET_WITH_LEADING_AND_TRAILING_SPACE + criteriaPath + CmsConstants.RIGHT_BRACKET_WITH_LEADING_AND_TRAILING_SPACE) + CmsConstants.EMPTY_SPACE + orderBy); return xpathQuery; }
From source file:org.betaconceptframework.astroboa.model.impl.query.criteria.TopicReferenceCriterionImpl.java
@Override public void addValue(Object value) { if (value != null) { if (value instanceof Topic) { addTopicAsAValue((Topic) value); } else {// w ww . j a v a 2s .c om if (value instanceof String && ((String) value).endsWith(CmsConstants.INCLUDE_CHILDREN_EXPRESSION)) { expandCriterionToIncludeSubTopics(); super.addValue(StringUtils.substringBeforeLast((String) value, CmsConstants.INCLUDE_CHILDREN_EXPRESSION)); } else { super.addValue(value); } } } }
From source file:org.betaconceptframework.astroboa.resourceapi.resource.ContentObjectResource.java
@Path("/{contentObjectIdOrName: " + CmsConstants.UUID_OR_SYSTEM_NAME_REG_EXP_FOR_RESTEASY + "}" + "/{propertyPath: " + CmsConstants.PROPERTY_PATH_WITH_ID_REG_EXP_FOR_RESTEASY + "}") public AstroboaResource getContentObjectPropertyUsingIdentifierInsteadOfIndex( @PathParam("contentObjectIdOrName") String contentObjectIdOrName, @PathParam("propertyPath") String propertyPath) { try {/* w ww .j a v a2 s . co m*/ ContentObject contentObject = retrieveContentObjectByIdOrSystemName(contentObjectIdOrName, FetchLevel.ENTITY, null); if (contentObject == null) { logger.warn( "The provided content object id / system name {} does not correspond to a content object or you do not have permission to access the requested object", contentObjectIdOrName); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } // We allow to put a mime type suffix (i.e. .jpg, .png, .doc) at the end of the property path // This is required when accessing binary properties and the programs which consume the // URL binary outcome do not read the mime type and filename from the header but rather depend on the mime type suffix at // the end of the URL in order to determine how to treat the binary content. // Additionally we may utilize this suffix in latter version of the API to support the delivery of different representations // of the property contents. // So we need to check if the property path contains a mime type suffix and remove it // This may cause problems if a requested property itself is named under the name of a mime type suffix. // To resolve this potential problem it is required to always put a mime type suffix at the end of URLs that read property values // if the requested property is named under the name of a mime type suffix // (i.e. .../objects/{contentObjectId}/myImageWithMultipleFormats.jpg.jpg this will result in removing the last "jpg" suffix but keep the previous one which corresponds to a // property named "jpg") if (propertyPath != null && !propertyPath.endsWith("]")) { String candidateMimeTypeSuffix = StringUtils.substringAfterLast(propertyPath, "."); if (ContentApiUtils.isKnownMimeTypeSuffix(candidateMimeTypeSuffix)) { propertyPath = StringUtils.substringBeforeLast(propertyPath, "."); } } //Extract property along with the value identifier or the value index PropertyExtractor propertyExtractor = null; //Load Property according to property path CmsProperty property = null; try { propertyExtractor = new PropertyExtractor(contentObject, propertyPath); property = propertyExtractor.getProperty(); } catch (Exception e) { logger.warn("Could not load provided property using path '" + propertyPath + "' from contentObject " + contentObjectIdOrName, e); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } if (property == null) { logger.warn( "The provided property '{}' for content object with id or system name '{}' does not exist", propertyPath, contentObjectIdOrName); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } switch (property.getValueType()) { case Complex: logger.warn( "The provided property '{}' for content object with id or system name '{}' is complex. Currently only simple type property values or binary channel content can be returned through this API call", propertyPath, contentObjectIdOrName); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); case Binary: if (propertyExtractor.getIdentifierOfTheValueOfTheProperty() == null) { return new BinaryChannelResource(astroboaClient, contentObject, (BinaryProperty) property, propertyExtractor.getIndexOfTheValueOfTheProperty()); } else { return new BinaryChannelResource(astroboaClient, contentObject, (BinaryProperty) property, propertyExtractor.getIdentifierOfTheValueOfTheProperty()); } case ContentType: logger.error("Astroboa returned value type '" + ValueType.ContentType + "' for property '{}' for content object with id or system name '{}'. This should never happen", propertyPath, contentObjectIdOrName); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); default: if (propertyExtractor.getIdentifierOfTheValueOfTheProperty() != null) { logger.warn( "The provided property '{}' for content object with id or system name '{}' is a simple non-binary property but user has provided an identifier instead of an index.", propertyPath, contentObjectIdOrName); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } return new SimplePropertyResource(astroboaClient, contentObject, (SimpleCmsProperty) property, propertyExtractor.getIndexOfTheValueOfTheProperty()); } } catch (WebApplicationException e) { throw e; } catch (Exception e) { logger.error("A problem occured while retrieving property: '" + propertyPath + "' for content object with id or system name: " + contentObjectIdOrName, e); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } }
From source file:org.betaconceptframework.astroboa.resourceapi.resource.ContentObjectResource.java
@Path("/{contentObjectIdOrName: " + CmsConstants.UUID_OR_SYSTEM_NAME_REG_EXP_FOR_RESTEASY + "}" + "/{propertyPath: " + CmsConstants.PROPERTY_PATH_REG_EXP_FOR_RESTEASY + "}") public AstroboaResource getContentObjectProperty( @PathParam("contentObjectIdOrName") String contentObjectIdOrName, @PathParam("propertyPath") String propertyPath) { try {/* w ww . j av a 2s . c o m*/ ContentObject contentObject = retrieveContentObjectByIdOrSystemName(contentObjectIdOrName, FetchLevel.ENTITY, null); if (contentObject == null) { logger.warn( "The provided content object id / system name {} does not correspond to a content object or you do not have permission to access the requested object", contentObjectIdOrName); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } // We allow to put a mime type suffix (i.e. .jpg, .png, .doc) at the end of the property path // This is required when accessing binary properties and the programs which consume the // URL binary outcome do not read the mime type and filename from the header but rather depend on the mime type suffix at // the end of the URL in order to determine how to treat the binary content. // Additionally we may utilize this suffix in latter version of the API to support the delivery of different representations // of the property contents. // So we need to check if the property path contains a mime type suffix and remove it // This may cause problems if a requested property itself is named under the name of a mime type suffix. // To resolve this potential problem it is required to always put a mime type suffix at the end of URLs that read property values // if the requested property is named under the name of a mime type suffix // (i.e. .../objects/{contentObjectId}/myImageWithMultipleFormats.jpg.jpg this will result in removing the last "jpg" suffix but keep the previous one which corresponds to a // property named "jpg") if (propertyPath != null && !propertyPath.endsWith("]")) { String candidateMimeTypeSuffix = StringUtils.substringAfterLast(propertyPath, "."); if (ContentApiUtils.isKnownMimeTypeSuffix(candidateMimeTypeSuffix)) { propertyPath = StringUtils.substringBeforeLast(propertyPath, "."); } } //Check if a value index exists and extract it IndexExtractor indexExtractor = new IndexExtractor(propertyPath); String propertyPathWithoutIndex = indexExtractor.getPropertyPathWithoutIndex(); int valueIndex = indexExtractor.getIndex(); //Load Property according to property path CmsProperty property = null; try { property = contentObject.getCmsProperty(propertyPathWithoutIndex); } catch (Exception e) { logger.warn("Could not load provided property using path '" + propertyPathWithoutIndex + "' from contentObject " + contentObjectIdOrName, e); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } if (property == null) { logger.warn( "The provided property '{}' for content object with id or system name '{}' does not exist", propertyPathWithoutIndex, contentObjectIdOrName); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } switch (property.getValueType()) { case Complex: logger.warn( "The provided property '{}' for content object with id or system name '{}' is complex. Currently only simple type property values or binary channel content can be returned through this API call", propertyPathWithoutIndex, contentObjectIdOrName); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); case Binary: return new BinaryChannelResource(astroboaClient, contentObject, (BinaryProperty) property, valueIndex); case ContentType: logger.error("Astroboa returned value type '" + ValueType.ContentType + "' for property '{}' for content object with id or system name '{}'. This should never happen", propertyPathWithoutIndex, contentObjectIdOrName); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); default: return new SimplePropertyResource(astroboaClient, contentObject, (SimpleCmsProperty) property, valueIndex); } } catch (WebApplicationException e) { throw e; } catch (Exception e) { logger.error("A problem occured while retrieving property: '" + propertyPath + "' for content object with id or system name: " + contentObjectIdOrName, e); throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } }
From source file:org.betaconceptframework.astroboa.test.model.ContentObjectTest.java
private ContentObject createMultipleComplexCmsProperty(ContentObject contentObject, String propertyPath, String simpleChildPropertyName, String propertyNameOfTypeContentObjectReference, ContentObject referencedContentObject) { if (contentObject.hasValueForProperty(propertyPath)) { ComplexCmsProperty<?, ?> property = (ComplexCmsProperty<?, ?>) contentObject .getCmsProperty(propertyPath); if (property.getPropertyDefinition().isMandatory()) { contentObject.removeCmsProperty(StringUtils.substringBeforeLast(propertyPath, ".")); } else {/* w w w. j av a2 s . c o m*/ contentObject.removeCmsProperty(propertyPath); } contentObject = contentService.save(contentObject, false, true, null); } //Add complex cms property for (int i = 0; i < 5; i++) { ComplexCmsProperty<?, ?> property = (ComplexCmsProperty<?, ?>) contentObject .getCmsProperty(propertyPath + "[" + i + "]"); ((StringProperty) property.getChildProperty(simpleChildPropertyName)) .setSimpleTypeValue("comment-" + i); ((ObjectReferenceProperty) property.getChildProperty(propertyNameOfTypeContentObjectReference)) .setSimpleTypeValue(referencedContentObject); } contentObject = contentService.save(contentObject, false, true, null); //Assert save for (int i = 0; i < 5; i++) { String complexPropertyPath = propertyPath + "[" + i + "]"; assertPropertyExistence(contentObject, complexPropertyPath, simpleChildPropertyName, "comment-" + i); } return contentObject; }
From source file:org.betaconceptframework.astroboa.util.PropertyExtractor.java
public PropertyExtractor(ContentObject contentObject, String propertyPath) throws Exception { if (StringUtils.isNotBlank(propertyPath) && contentObject != null) { property = contentObject.getComplexCmsRootProperty(); String[] pathParts = StringUtils.split(propertyPath, CmsConstants.PERIOD_DELIM); int count = 0; for (String pathPart : pathParts) { boolean lastPart = ++count == pathParts.length; String parentPropertyPermanentPath = property.getFullPath(); String childPropertyName = StringUtils.substringBeforeLast(pathPart, CmsConstants.LEFT_BRACKET); if (lastPart) { String identifierOrIndexOfTheValue = retrieveIdentifierOrIndexFromPath(pathPart); property = ((ComplexCmsProperty) property).getChildProperty(childPropertyName); if (property == null) { throw new CmsException("Cannot retrieve property " + pathPart + " from parent property " + parentPropertyPermanentPath); }/* ww w . j a va 2s. co m*/ if (identifierOrIndexOfTheValue != null) { if (CmsConstants.UUIDPattern.matcher(identifierOrIndexOfTheValue).matches()) { identifierOfTheValueOfTheProperty = identifierOrIndexOfTheValue; } else { indexOfTheValueOfTheProperty = Integer.parseInt(identifierOrIndexOfTheValue); } } } else { //We are in the middle of the path. String identifierOfTheChildProperty = retrieveIdentifierOrIndexFromPath(pathPart); boolean childPropertyIsDefined = ((ComplexCmsProperty) property) .isChildPropertyDefined(childPropertyName); if (!childPropertyIsDefined) { throw new Exception("Could not locate definition for property " + childPropertyName); } //Retrieve definition CmsPropertyDefinition childPropertyDefinition = ((ComplexCmsProperty) property) .getPropertyDefinition().getChildCmsPropertyDefinition(childPropertyName); if (childPropertyDefinition == null) { //Property has been defined. Since no definition is found check if this property is an aspect if (property instanceof ComplexCmsRootProperty && ((ComplexCmsRootProperty) property).hasAspect(childPropertyName)) { childPropertyDefinition = ((ComplexCmsRootProperty) property).getAspectDefinitions() .get(childPropertyName); } } if (childPropertyDefinition == null) { throw new Exception("Could not locate definition for property " + childPropertyName); } if (childPropertyDefinition.getValueType() == ValueType.Complex) { //Child property is a multiple value property //Iterate through the returned properties to //match the property with the provided identifier if any if (childPropertyDefinition.isMultiple()) { property = retrieveChildComplexCmsPropertyFromAListOfProperties( identifierOfTheChildProperty, childPropertyName); } else { //Child property is a single value property CmsProperty<?, ?> childProperty = ((ComplexCmsProperty) property) .getChildProperty(childPropertyName); if (identifierOfTheChildProperty != null) { //User has an identifier. Check that this is valid if (StringUtils.equals(identifierOfTheChildProperty, childProperty.getId())) { property = childProperty; } else { throw new Exception("Property " + childPropertyName + " has been retrieved from parent property " + parentPropertyPermanentPath + " but its identifier " + childProperty.getId() + " does not match with the one provided " + identifierOfTheChildProperty); } } else { property = childProperty; } } } else { throw new CmsException("Property " + pathPart + " does not correspond to a complex property of the property " + parentPropertyPermanentPath); } } } } }
From source file:org.betaconceptframework.astroboa.util.PropertyPath.java
public static int extractIndexFromPath(String propertyPath) { if (StringUtils.isBlank(propertyPath) || !propertyPath.endsWith(CmsConstants.RIGHT_BRACKET)) return NO_INDEX; try {//from ww w . j a v a 2s . c o m //Get everything after last '[' String index = StringUtils.substringAfterLast(propertyPath, CmsConstants.LEFT_BRACKET); //Normally what is left is a number followed by a right bracket index = StringUtils.substringBeforeLast(index, CmsConstants.RIGHT_BRACKET); if (StringUtils.isBlank(index)) return NO_INDEX; return Integer.parseInt(index); } catch (Exception e) { throw new CmsException(e); } }
From source file:org.betaconceptframework.astroboa.util.PropertyPath.java
public static String removeLastIndexFromPath(String propertyPath) { if (StringUtils.isBlank(propertyPath) || !propertyPath.endsWith(CmsConstants.RIGHT_BRACKET)) return propertyPath; return StringUtils.substringBeforeLast(propertyPath, CmsConstants.LEFT_BRACKET); }
From source file:org.bigmouth.nvwa.utils.PathUtils.java
/** * ?WebInf//from w w w. j a va 2s . c om * * @return WebInf */ public static String getWebInfPath() { return StringUtils.substringBeforeLast(StringUtils.substringBeforeLast(getClassPath(), "/"), "/"); }