Example usage for org.springframework.util StringUtils stripFilenameExtension

List of usage examples for org.springframework.util StringUtils stripFilenameExtension

Introduction

In this page you can find the example usage for org.springframework.util StringUtils stripFilenameExtension.

Prototype

public static String stripFilenameExtension(String path) 

Source Link

Document

Strip the filename extension from the given Java resource path, e.g.

Usage

From source file:net.sourceforge.subsonic.command.SavePlaylistCommand.java

public SavePlaylistCommand(Playlist playlist) {
    this.playlist = playlist;
    name = StringUtils.stripFilenameExtension(playlist.getName());
    suffix = StringUtils.getFilenameExtension(playlist.getName());
    formats = new String[] { "m3u", "pls", "xspf" };
}

From source file:com.asual.summer.core.spring.ViewNameTranslator.java

public String getViewName(HttpServletRequest request) {

    String uri = StringUtils
            .stripFilenameExtension(/* w  w  w .  ja  v a  2  s .c o  m*/
                    RequestUtils.contextRelative(request.getRequestURI().replaceAll("/+", "/"), false))
            .replaceFirst("/$", "");

    ExtendedInternalResourceViewResolver pagesResolver = null;

    ViewResolverConfiguration viewResolverConfiguraton = BeanUtils
            .getBeanOfType(ViewResolverConfiguration.class);
    List<ViewResolver> viewResolvers = viewResolverConfiguraton.getViewResolvers();

    for (ViewResolver vr : viewResolvers) {
        if (vr instanceof ExtendedInternalResourceViewResolver) {
            ExtendedInternalResourceViewResolver resolver = (ExtendedInternalResourceViewResolver) vr;
            if (resolver.getPrefix().endsWith("/pages")) {
                pagesResolver = resolver;
            }
        }
    }

    String prefix = pagesResolver.getPrefix().replaceAll("/$", "");
    String suffix = pagesResolver.getSuffix();

    String viewName = findViewName(prefix, uri, suffix, false);
    if (viewName != null) {
        return viewName;
    }

    throw new ViewNotFoundException();
}

From source file:de.codecentric.boot.admin.web.servlet.resource.PreferMinifiedFilteringResourceResolver.java

private Resource findMinified(Resource resource) {
    try {//from  ww w  .  j a  va2 s .co  m
        String basename = StringUtils.stripFilenameExtension(resource.getFilename());
        String extension = StringUtils.getFilenameExtension(resource.getFilename());
        Resource minified = resource.createRelative(basename + extensionPrefix + '.' + extension);
        if (minified.exists()) {
            return minified;
        }
    } catch (IOException ex) {
        logger.trace("No minified resource for [" + resource.getFilename() + "]", ex);
    }
    return null;
}

From source file:org.geomajas.sld.editor.expert.common.server.service.InMemorySldServiceImpl.java

@PostConstruct
void init() throws SldException {
    if (getDirectory() != null) {
        try {//from   w  ww .j  a v a 2s.  co m
            if (getDirectory().getFile().exists()) {
                if (getDirectory().getFile().isDirectory()) {
                    File[] sldFiles = getDirectory().getFile().listFiles(new FilenameFilter() {
                        public boolean accept(File dir, String name) {
                            return name.endsWith(".sld") || name.endsWith(".xml");
                        }
                    });
                    for (File file : sldFiles) {
                        RawSld raw = new RawSld();
                        raw.setXml(FileUtils.readFileToString(file, FILE_ENCODING));
                        String fileName = StringUtils.stripFilenameExtension(file.getName());
                        StyledLayerDescriptorInfo tmp = parseXml(fileName, raw.getXml());
                        raw.setName(fileName);
                        raw.setTitle(tmp.getTitle());
                        raw.setVersion(tmp.getVersion());
                        log.info("added sld '{}' to service", fileName);
                        allSlds.put(raw.getName(), raw);
                    }
                }
            }
        } catch (Exception e) { // NOSONAR
            log.warn("Error while initilizing SLD service.", e);
        }
    }
}

From source file:com.agileapes.couteau.maven.resource.ClassPathScanningClassProvider.java

private Class resolveClass(Resource resource, String basePackage) throws IOException, ClassNotFoundException {
    final String clazzCleanPath = StringUtils.cleanPath(resource.getURL().getPath());
    final String clazzPathWithoutExtension = StringUtils.stripFilenameExtension(clazzCleanPath);
    final String resourcePackageLikeStr = ClassUtils.convertResourcePathToClassName(clazzPathWithoutExtension);
    final String className = resourcePackageLikeStr.substring(resourcePackageLikeStr.lastIndexOf(basePackage));
    return ClassUtils.forName(className, classLoader);
}

From source file:se.alingsas.alfresco.repo.workflow.CompleteDocumentServiceTaskDelegate.java

/**
 * CompleteDocumentServiceTaskDelegate will handle completion of document in
 * workflow/*ww  w. j  a va  2s. c  o  m*/
 */
@Override
public void execute(final DelegateExecution execution) throws Exception {
    LOG.debug("Entering CompleteDocumentServiceTaskDelegate");

    final ServiceRegistry serviceRegistry = WorkflowUtil.getServiceRegistry();
    final LockService lockService = serviceRegistry.getLockService();

    final NodeService nodeService = serviceRegistry.getNodeService();
    final FileFolderService fileFolderService = serviceRegistry.getFileFolderService();

    final CheckOutCheckInService checkOutCheckInService = serviceRegistry.getCheckOutCheckInService();
    final PermissionService permissionService = serviceRegistry.getPermissionService();

    ActivitiScriptNode akwfTargetFolder = (ActivitiScriptNode) execution
            .getVariable(CommonWorkflowModel.TARGET_FOLDER);
    final NodeRef targetFolderNodeRef = akwfTargetFolder.getNodeRef();
    final OwnableService ownableService = serviceRegistry.getOwnableService();
    AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {
        public Object doWork() throws Exception {

            List<ChildAssociationRef> childAssocs = WorkflowUtil.getBpmPackageFiles(execution, nodeService);
            if (childAssocs != null && childAssocs.size() > 0) {
                for (ChildAssociationRef childAssoc : childAssocs) {
                    NodeRef fileNodeRef = childAssoc.getChildRef();
                    String akwfApprover = (String) execution.getVariable("akwf_approver");

                    LOG.debug("Unlocking document");
                    lockService.unlock(fileNodeRef);

                    String readPermSiteRoleGroup = (String) execution
                            .getVariable(CommonWorkflowModel.SITE_GROUP);
                    LOG.debug("Removing temporary read permission on file for " + readPermSiteRoleGroup);
                    permissionService.deletePermission(fileNodeRef, readPermSiteRoleGroup,
                            PermissionService.READ);
                    execution.setVariable(CommonWorkflowModel.REMOVE_PERMISSIONS_DONE, "true");
                    if (!nodeService.getPrimaryParent(fileNodeRef).getParentRef().equals(targetFolderNodeRef)) {
                        LOG.debug("Moving document");
                        String name = (String) nodeService.getProperty(fileNodeRef, ContentModel.PROP_NAME);
                        NodeRef childByName = nodeService.getChildByName(targetFolderNodeRef,
                                ContentModel.ASSOC_CONTAINS, name);
                        if (childByName != null) {
                            String strippedFileName = StringUtils.stripFilenameExtension(name);
                            String filenameExtension = StringUtils.getFilenameExtension(name);
                            name = strippedFileName + "_" + System.currentTimeMillis() + "."
                                    + filenameExtension;
                            LOG.info("File exists, renaming to " + name);
                        }
                        fileFolderService.move(fileNodeRef, targetFolderNodeRef, name);
                    }
                    /*
                     * try { fileFolderService.move(fileNodeRef, targetFolderNodeRef,
                     * null); } catch (FileExistsException e) {
                     * 
                     * 
                     * 
                     * }
                     */
                    ownableService.setOwner(fileNodeRef, akwfApprover);
                    LOG.debug("Checking in document");
                    NodeRef workingCopy = checkOutCheckInService.checkout(fileNodeRef);
                    nodeService.setProperty(workingCopy, AkDmModel.PROP_AKDM_DOC_STATUS,
                            CommonWorkflowModel.DOC_STATUS_DONE);
                    Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
                    versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);

                    versionProperties.put(VersionModel.PROP_DESCRIPTION,
                            "Dokumentet frdigstlldes av " + akwfApprover);
                    checkOutCheckInService.checkin(workingCopy, versionProperties);

                }
            }
            return "";
        }
    }, AuthenticationUtil.getSystemUserName());
}

From source file:se.alingsas.alfresco.repo.workflow.RevertDocumentServiceTaskDelegate.java

@Override
public void execute(final DelegateExecution execution) throws Exception {
    LOG.debug("Entering RevertDocumentServiceTaskDelegate");

    final ServiceRegistry serviceRegistry = WorkflowUtil.getServiceRegistry();
    final LockService lockService = serviceRegistry.getLockService();

    final NodeService nodeService = serviceRegistry.getNodeService();
    final FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    final PermissionService permissionService = serviceRegistry.getPermissionService();
    final CheckOutCheckInService checkOutCheckInService = serviceRegistry.getCheckOutCheckInService();

    ActivitiScriptNode akwfTargetFolder = (ActivitiScriptNode) execution
            .getVariable(CommonWorkflowModel.TARGET_FOLDER);
    final NodeRef targetFolderNodeRef = akwfTargetFolder.getNodeRef();
    final OwnableService ownableService = serviceRegistry.getOwnableService();
    AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() {
        public Object doWork() throws Exception {

            List<ChildAssociationRef> childAssocs = WorkflowUtil.getBpmPackageFiles(execution, nodeService);
            if (childAssocs != null && childAssocs.size() > 0) {
                for (ChildAssociationRef childAssoc : childAssocs) {
                    NodeRef fileNodeRef = childAssoc.getChildRef();
                    String akwfApprover = (String) execution.getVariable("akwf_approver");

                    LOG.debug("Unlocking document.");
                    lockService.unlock(fileNodeRef);

                    String readPermSiteRoleGroup = (String) execution
                            .getVariable(CommonWorkflowModel.SITE_GROUP);
                    if (readPermSiteRoleGroup != null) {
                        LOG.debug("Removing temporary read permission on file for " + readPermSiteRoleGroup);
                        permissionService.deletePermission(fileNodeRef, readPermSiteRoleGroup,
                                PermissionService.READ);
                        execution.setVariable(CommonWorkflowModel.REMOVE_PERMISSIONS_DONE, "true");
                    }/*from   w w  w.j a  va2  s.  com*/
                    ChildAssociationRef primaryParent = nodeService.getPrimaryParent(fileNodeRef);

                    if (!targetFolderNodeRef.equals(primaryParent.getParentRef())) {
                        LOG.debug("Moving document.");
                        try {
                            fileFolderService.move(fileNodeRef, targetFolderNodeRef, null);
                        } catch (FileExistsException e) {
                            LOG.info("File exists, renaming...");
                            String name = (String) nodeService.getProperty(fileNodeRef, ContentModel.PROP_NAME);
                            String strippedFileName = StringUtils.stripFilenameExtension(name);
                            String filenameExtension = StringUtils.getFilenameExtension(name);
                            name = strippedFileName + "_" + System.currentTimeMillis() + "."
                                    + filenameExtension;
                            fileFolderService.move(fileNodeRef, targetFolderNodeRef, name);
                        }
                    } else {
                        LOG.debug("Target folder is the same as source folder. Will not move the file.");
                    }
                    ownableService.setOwner(fileNodeRef, akwfApprover);
                    LOG.debug("Checking in document");
                    NodeRef workingCopy = checkOutCheckInService.checkout(fileNodeRef);
                    nodeService.setProperty(workingCopy, AkDmModel.PROP_AKDM_DOC_STATUS,
                            CommonWorkflowModel.DOC_STATUS_WORKING);
                    Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
                    versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);

                    versionProperties.put(VersionModel.PROP_DESCRIPTION,
                            "Dokumentets status ndrades till arbetsdokument av " + akwfApprover);
                    checkOutCheckInService.checkin(workingCopy, versionProperties);

                }
            }
            return "";
        }
    }, AuthenticationUtil.getSystemUserName());
}

From source file:mvctest.web.TestController.java

private String getFlowIdFromFileName(Resource flowResource) {
    return StringUtils.stripFilenameExtension(flowResource.getFilename());
}

From source file:org.broadleafcommerce.common.resource.service.ResourceBundlingServiceImpl.java

/**
 * Copied from Spring 4.1 AbstractVersionStrategy
 * @param requestPath/* w w  w.ja v a2s  .c o m*/
 * @param version
 * @return
 */
protected String addVersion(String requestPath, String version) {
    String baseFilename = StringUtils.stripFilenameExtension(requestPath);
    String extension = StringUtils.getFilenameExtension(requestPath);
    return baseFilename + version + "." + extension;
}

From source file:org.broadleafcommerce.common.web.resource.resolver.BLCJSResourceResolver.java

protected String addVersion(String requestPath, String version) {
    String baseFilename = StringUtils.stripFilenameExtension(requestPath);
    String extension = StringUtils.getFilenameExtension(requestPath);
    return baseFilename + version + "." + extension;
}