Example usage for org.apache.commons.lang StringUtils substringAfterLast

List of usage examples for org.apache.commons.lang StringUtils substringAfterLast

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringAfterLast.

Prototype

public static String substringAfterLast(String str, String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:org.betaconceptframework.astroboa.engine.definition.ContentDefinitionConfiguration.java

private void feedParserWithUserDefinedSchemas(XSOMParser xsomParser,
        List<FileConfiguration> repositoryDefinitionFileConfigurations) {

    List<String> absolutePathsOfFilesToExclude = new ArrayList<String>();

    boolean feedParser = true;

    while (feedParser) {

        feedParser = false;/*  w  ww . j  a va2s.  c  om*/

        //Create XSOM Parser
        if (xsomParser == null) {
            xsomParser = createXsomParser();
        }

        for (FileConfiguration fileConf : repositoryDefinitionFileConfigurations) {
            if (fileConf.getFile() == null) {
                logger.warn(
                        "Found empty file configuration. This means that one of the XSD provided is not a valid xml. Parsing will continue for the rest of the xsds");
            } else {

                String absolutePath = fileConf.getFile().getAbsolutePath();

                if (!absolutePathsOfFilesToExclude.contains(absolutePath)) {

                    logger.debug("Reloadding and parsing file {}", absolutePath);

                    try {
                        fileConf.reload();
                        xsomParser.parse(fileConf.getFile());
                        definitionVisitor.addXMLSchemaDefinitionForFileName(
                                FileUtils.readFileToByteArray(fileConf.getFile()),
                                StringUtils.substringAfterLast(absolutePath, File.separator));
                    } catch (Exception e) {
                        //Just issue a warning
                        logger.warn("Parse error for definition file " + absolutePath
                                + " This file is excluded from building Astroboa Definitions", e);

                        //we need to feed parser again since it sets an error flag to true 
                        //and does not produce any schemas at all.
                        feedParser = true;
                        absolutePathsOfFilesToExclude.add(absolutePath);
                        xsomParser = null;
                        definitionVisitor.clear();
                        break;
                    }
                }
            }
        }
    }

}

From source file:org.betaconceptframework.astroboa.engine.definition.RepositoryEntityResolver.java

private byte[] getSchema(String systemId) {
    if (StringUtils.isBlank(systemId)) {
        return null;
    }//  ww w .  j  a  v  a2  s  .c o m

    //We are only interested in content type name or path.
    String schemaFilename = systemId;

    //We expect URL of the form
    //http://<server>/resource-api/<repository-id>/model/multilingualStringPropertyType?output=xsd
    //Definition name is located after the last forward slash
    if (schemaFilename.contains(CmsConstants.FORWARD_SLASH)) {
        schemaFilename = StringUtils.substringAfterLast(schemaFilename, CmsConstants.FORWARD_SLASH);
    }

    if (schemaFilename.contains("?")) {
        schemaFilename = StringUtils.substringBefore(schemaFilename, "?");
    }

    byte[] schema = contentDefinitionDao.getXMLSchemaFileForDefinition(schemaFilename);

    if (schema == null || schema.length == 0) {
        return null;
    }

    return schema;
}

From source file:org.betaconceptframework.astroboa.engine.definition.visitor.CmsDefinitionVisitor.java

public void addXMLSchemaDefinitionForFileName(URL definitionURL) {

    InputStream builtInStream = null;
    try {//  w  w w .j  a  va 2 s .co  m
        if (definitionURL == null) {
            logger.warn("Found no XML schema file for definition ");
            return;
        }

        String filename = StringUtils.substringAfterLast(definitionURL.toExternalForm(),
                CmsConstants.FORWARD_SLASH);

        builtInStream = definitionURL.openStream();

        logger.debug("Adding schema content for file {}", filename);
        xmlSchemaDefinitionsPerFilename.put(filename, IOUtils.toByteArray(builtInStream));

    } catch (Exception e) {
        logger.error("", e);
        throw new CmsException(e.getMessage());
    } finally {
        IOUtils.closeQuietly(builtInStream);
    }

}

From source file:org.betaconceptframework.astroboa.engine.definition.visitor.CmsPropertyVisitor.java

private QName generatedQNameForDefinition() {
    if (parentDefinition != null && parentDefinition.getQualifiedName() != null
            && parentDefinition.getQualifiedName().getPrefix() != null) {
        return new QName(namespaceUri, name, parentDefinition.getQualifiedName().getPrefix());
    } else {//w  w w  .j  av  a2s .c o m
        //Qualified names with the same namespace 
        //for example one XSD file which contains 
        //two content types and one global complex type
        //must have the same prefix.  Therefore 
        //prefix originates from namespaceUri.
        //Otherwise definition name will be used for prefix
        String prefix = StringUtils.substringAfterLast(namespaceUri, CmsConstants.FORWARD_SLASH);

        if (StringUtils.isNotBlank(prefix)) {
            return new QName(namespaceUri, name, prefix);
        } else {
            return new QName(namespaceUri, name, name);
        }
    }
}

From source file:org.betaconceptframework.astroboa.engine.definition.xsom.CmsEntityResolverForValidation.java

@Override
/**/*from ww  w  .j av a2 s .  c  om*/
 * According to XSOM library 
 * By setting EntityResolver to XSOMParser, you can redirect <xs:include>s and <xs:import>s to different resources.
 * For imports, the namespace URI of the target schema is passed as the public ID,
 * and the absolutized value of the schemaLocation attribute will be passed as the system ID. 
 */
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {

    if (systemId != null) {

        try {

            String schemaFilename = systemId;

            //We are only interested in file name
            if (schemaFilename.contains(File.separator)) {
                schemaFilename = StringUtils.substringAfterLast(systemId, File.separator);
            } else if (!File.separator.equals(schemaFilename.contains(CmsConstants.FORWARD_SLASH))
                    && schemaFilename.contains(CmsConstants.FORWARD_SLASH)) {
                //Perform the extra check in case File.separator is not '/' and it 
                //does not exist in the schema filename.
                //This case usually appears in a windows environment.
                schemaFilename = StringUtils.substringAfterLast(systemId, CmsConstants.FORWARD_SLASH);
            }

            if (definitionSources.containsKey(schemaFilename)) {
                InputStream inputStream = IOUtils.toInputStream(definitionSources.get(schemaFilename), "UTF-8");
                openStreams.add(inputStream);

                InputSource inputSource = new InputSource(inputStream);

                inputSource.setPublicId(publicId);
                inputSource.setSystemId(schemaFilename);

                return inputSource;
            }

            return entityResolverForBuiltInSchemas.resolveEntity(publicId, systemId);

        } catch (Exception e) {
            throw new IOException(e);
        }
    }

    //Returning null allow XSD Parser to continue with default behavior
    //and will try to resolve entity using its own implementation
    return null;
}

From source file:org.betaconceptframework.astroboa.engine.definition.xsom.CmsEntityResolverForValidation.java

public void addDefinition(String definitionName, String definition) throws IOException {
    if (definitionName != null && definition != null) {

        if (definitionName.contains(CmsConstants.FORWARD_SLASH)) {
            definitionSources.put(StringUtils.substringAfterLast(definitionName, CmsConstants.FORWARD_SLASH),
                    definition);//from  w w w  . ja  v  a2s  . c o  m
        } else {
            definitionSources.put(definitionName, definition);
        }
    }

}

From source file:org.betaconceptframework.astroboa.engine.definition.xsom.EntityResolverForBuiltInSchemas.java

@Override
/**//from   w w  w  .j ava  2s.c  om
 * According to XSOM library 
 * By setting EntityResolver to XSOMParser, you can redirect <xs:include>s and <xs:import>s to different resources.
 * For imports, the namespace URI of the target schema is passed as the public ID,
 * and the absolutized value of the schemaLocation attribute will be passed as the system ID. 
 */
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {

    if (publicId != null && publicId.startsWith(BetaConceptNamespaceConstants.ASTROBOA_SCHEMA_URI)
            && systemId != null) {

        try {

            String schemaFilename = systemId;

            //We are only interested in file name
            if (schemaFilename.contains(CmsConstants.FORWARD_SLASH)) {
                schemaFilename = StringUtils.substringAfterLast(systemId, CmsConstants.FORWARD_SLASH);
            }

            URL definitionFileURL = locateBuiltinDefinitionURL(schemaFilename);

            if (definitionFileURL != null) {

                InputSource is = new InputSource(definitionFileURL.openStream());

                /*
                 * SystemId is actual the path to the resource
                 * although its content has been loaded to input source.
                 * Provided value (sustemId) is not set because if in XSD file in the corresponding import's
                 * schemaLocation contains only the schema filename, then XSOM parser will
                 * consider it as a relative path and will prefix it with the correct absolute path.
                 * 
                 * For example, in cases where two different schemas, located in two different directories (portal-1.0.xsd and basicText-1.0.xsd),
                 * import schema astroboa-model-1.2.xsd, xs import will look like
                 * 
                 * <xs:import
                      namespace="http://www.betaconceptframework.org/schema/astroboa/model"
                      schemaLocation="astroboa-model-1.2.xsd" />
                 * 
                 * When XSOM parser will try to load astroboa-model-1.2.xsd, it will append
                 * schemaLocation with the path of the directory where each of the parent XSDs are located. 
                 * 
                 * SchemaLocation value refers to systemId and if it is provided in this input source, XSOM parser
                 * will have two different instances of InputSource referring to the same xsd file  (definitionFileURL),
                 * having the same publiId (namespace) but different systemIds (appended schemaLocation).
                 * 
                 * This situation causes XSOM parser to throw an exception when the second input source is loaded
                 * complaining that it found the same type(s) defined already, which is true since as far as XSOM parser
                 * concerns these input sources are not the same.
                 * 
                 * To overcome this, we set as system id the URL of the XSD file which is the same
                 * in both situations.
                 */
                is.setSystemId(definitionFileURL.toString());
                is.setPublicId(publicId);

                if (systemId.startsWith(BetaConceptNamespaceConstants.ASTROBOA_SCHEMA_URI)) {
                    logger.warn("Schema Location for XSD Schema " + schemaFilename
                            + ", which contains built in Astroboa model, is not relative but absolute."
                            + " Unless this absolute location really 'serves' XSD, there will be a problem "
                            + " when importing XML which contain xml elements derived from this Schema If this location is not real, then you are advised to delete it and leave only"
                            + "the schema file name. Nevertheless the contents of " + schemaFilename
                            + " have been found internally and have been successfully loaded to Astroboa");
                }

                return is;
            }

        } catch (Exception e) {
            throw new IOException(e);
        }
    }

    //Returning null allow XSD Parser to continue with default behavior
    //and will try to resolve entity using its own implementation
    return resolveXmlSchemaRelatedToW3C(publicId, systemId);
}

From source file:org.betaconceptframework.astroboa.model.impl.BinaryChannelImpl.java

/**
 * @return Returns the sourceFilename suffix.
 */
public String getSourceFilenameSuffix() {
    return StringUtils.substringAfterLast(sourceFilename, ".");
}

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 {/*from   www.j  a v  a  2 s.c  om*/

        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 {/* ww w. ja v a  2  s  .  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);
    }

}