Example usage for com.liferay.portal.kernel.util FileUtil getShortFileName

List of usage examples for com.liferay.portal.kernel.util FileUtil getShortFileName

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util FileUtil getShortFileName.

Prototype

public static String getShortFileName(String fullFileName) 

Source Link

Usage

From source file:com.liferay.portlet.calendar.service.impl.CalEventLocalServiceImpl.java

License:Open Source License

protected File exportICal4j(net.fortuna.ical4j.model.Calendar cal, String fileName) throws SystemException {

    OutputStream os = null;/*from www .j  a v  a  2 s .c  o  m*/

    try {
        String extension = ".ics";

        if (Validator.isNull(fileName)) {
            fileName = "liferay.";
        } else {
            int pos = fileName.lastIndexOf(CharPool.PERIOD);

            if (pos != -1) {
                extension = fileName.substring(pos);
                fileName = fileName.substring(0, pos);
            }
        }

        fileName = FileUtil.getShortFileName(fileName);

        File file = File.createTempFile(fileName, extension);

        os = new UnsyncBufferedOutputStream(new FileOutputStream(file.getPath()));

        CalendarOutputter calOutput = new CalendarOutputter();

        if (cal.getComponents().isEmpty()) {
            calOutput.setValidating(false);
        }

        calOutput.output(cal, os);

        return file;
    } catch (Exception e) {
        _log.error(e, e);

        throw new SystemException(e);
    } finally {
        StreamUtil.cleanUp(os);
    }
}

From source file:com.liferay.portlet.documentlibrary.store.AdvancedFileSystemStore.java

License:Open Source License

protected List<String> getAdvancedFileNames(long companyId, long repositoryId, String fileName) {

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

    String shortFileName = FileUtil.getShortFileName(fileName);

    if (shortFileName.equals("DLFE") || Validator.isNumber(shortFileName)) {
        String[] curFileNames = FileUtil.listDirs(fileName);

        for (String curFileName : curFileNames) {
            fileNames.addAll(/*www.ja  v  a 2 s  . c om*/
                    getAdvancedFileNames(companyId, repositoryId, fileName + StringPool.SLASH + curFileName));
        }
    } else {
        if (shortFileName.endsWith(_HOOK_EXTENSION)) {
            shortFileName = FileUtil.stripExtension(shortFileName);
        }

        fileNames.add(shortFileName);
    }

    return fileNames;
}

From source file:com.liferay.portlet.wiki.engines.jspwiki.LiferayAttachmentProvider.java

License:Open Source License

public Attachment getAttachmentInfo(WikiPage page, String name, int version) throws ProviderException {

    com.liferay.portlet.wiki.model.WikiPage wikiPage = null;

    try {//from ww w.ja v  a 2 s  . c o m
        wikiPage = WikiPageLocalServiceUtil.getPage(_nodeId, page.getName());

        String[] attachments = wikiPage.getAttachmentsFiles();

        for (int i = 0; i < attachments.length; i++) {
            String fileName = FileUtil.getShortFileName(attachments[i]);

            if (fileName.equals(name)) {
                return new Attachment(_engine, page.getName(), name);
            }
        }

        return null;
    } catch (Exception e) {
        throw new ProviderException(e.toString());
    }
}

From source file:com.liferay.resourcesimporter.util.FileSystemImporter.java

License:Open Source License

protected void addDDMTemplate(long templateGroupId, long ddmStructureId, String fileName, String language,
        String script, String type, String mode) throws Exception {

    fileName = FileUtil.getShortFileName(fileName);

    fileName = FileUtil.stripExtension(fileName);

    String name = getName(fileName);

    DDMTemplate ddmTemplate = DDMTemplateLocalServiceUtil.fetchTemplate(groupId,
            PortalUtil.getClassNameId(DDMStructure.class), getKey(fileName));

    if (ddmTemplate != null) {
        if (!developerModeEnabled) {
            if (_log.isInfoEnabled()) {
                _log.info("DDM template with name " + name + " and version " + version + " already exists");
            }//  www .j  a va  2 s . co  m

            return;
        }

        if (!updateModeEnabled) {
            DDMTemplateLocalServiceUtil.deleteTemplate(ddmTemplate);
        }
    }

    try {
        if (!updateModeEnabled || (ddmTemplate == null)) {
            DDMTemplateLocalServiceUtil.addTemplate(userId, templateGroupId,
                    PortalUtil.getClassNameId(DDMStructure.class), ddmStructureId, getKey(fileName),
                    getMap(name), null, type, mode, language, script, false, false, StringPool.BLANK, null,
                    serviceContext);
        } else {
            DDMTemplateLocalServiceUtil.updateTemplate(ddmTemplate.getTemplateId(),
                    PortalUtil.getClassNameId(DDMStructure.class), getMap(name), null,
                    DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY, null, language, script, false, false, null,
                    null, serviceContext);
        }
    } catch (PortalException e) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to import DDM template " + fileName, e);
        }

        throw e;
    }
}

From source file:com.liferay.resourcesimporter.util.ResourceImporter.java

License:Open Source License

@Override
protected void addDDMStructures(String parentStructureId, String dirName) throws Exception {

    Set<String> resourcePaths = servletContext.getResourcePaths(resourcesDir.concat(dirName));

    if (resourcePaths == null) {
        return;/*from   w  w w  . ja va  2s.  c  o  m*/
    }

    for (String resourcePath : resourcePaths) {
        if (resourcePath.endsWith(StringPool.SLASH)) {
            continue;
        }

        String name = FileUtil.getShortFileName(resourcePath);

        URL url = servletContext.getResource(resourcePath);

        URLConnection urlConnection = url.openConnection();

        addDDMStructures(parentStructureId, name, urlConnection.getInputStream());
    }
}

From source file:com.liferay.resourcesimporter.util.ResourceImporter.java

License:Open Source License

@Override
protected void addDDMTemplates(String ddmStructureKey, String dirName) throws Exception {

    Set<String> resourcePaths = servletContext.getResourcePaths(resourcesDir.concat(dirName));

    if (resourcePaths == null) {
        return;/* w w w .  j a v  a 2  s.  c  o m*/
    }

    for (String resourcePath : resourcePaths) {
        if (resourcePath.endsWith(StringPool.SLASH)) {
            continue;
        }

        String name = FileUtil.getShortFileName(resourcePath);

        URL url = servletContext.getResource(resourcePath);

        URLConnection urlConnection = url.openConnection();

        addDDMTemplates(ddmStructureKey, name, urlConnection.getInputStream());
    }
}

From source file:com.liferay.resourcesimporter.util.ResourceImporter.java

License:Open Source License

@Override
protected void addJournalArticles(String ddmStructureKey, String ddmTemplateKey, String dirName)
        throws Exception {

    Set<String> resourcePaths = servletContext.getResourcePaths(resourcesDir.concat(dirName));

    if (resourcePaths == null) {
        return;/*from  w  ww .  j a v a2s .  c  o m*/
    }

    for (String resourcePath : resourcePaths) {
        if (resourcePath.endsWith(StringPool.SLASH)) {
            continue;
        }

        String name = FileUtil.getShortFileName(resourcePath);

        URL url = servletContext.getResource(resourcePath);

        URLConnection urlConnection = url.openConnection();

        addJournalArticles(ddmStructureKey, ddmTemplateKey, name, urlConnection.getInputStream());
    }
}

From source file:eu.citadel.liferay.portlet.converter.controller.ContrSaveFileCitadel.java

public ExtViewResult publish(ActionRequest request, ActionResponse response) {
    String title = ParamUtil.getString(request, CONTR_PARAM_TITLE);
    String description = ParamUtil.getString(request, CONTR_PARAM_DESCRIPTION);
    long locationId = ParamUtil.getLong(request, CONTR_PARAM_LOCATION);
    int type = ParamUtil.getInteger(request, CONTR_PARAM_TYPE);
    String publisher = ParamUtil.getString(request, CONTR_PARAM_PUBLISHER);
    String source = ParamUtil.getString(request, CONTR_PARAM_SOURCE);
    String license = ParamUtil.getString(request, CONTR_PARAM_LICENSE);
    String language = ParamUtil.getString(request, CONTR_PARAM_LANGUAGE);

    if (Validator.isNull(getUserId(request)) || getUserId(request) <= 0) {
        getLog(request).error("Invalid id");
        setErrorMessage(request, "save-file-citadel-invalid-id");
        return new ExtViewResult(ConverterPortlet.CONTR_SAVE_FILE_CITADEL);
    }/*from   ww  w.  j ava 2s.  c o  m*/

    if (Validator.isNull(title)) {
        getLog(request).error("Invalid title");
        setErrorMessage(request, "Invalid title");
        return new ExtViewResult(ConverterPortlet.CONTR_SAVE_FILE_CITADEL);
    }
    if (Validator.isNull(publisher)) {
        getLog(request).error("Invalid publisher");
        setErrorMessage(request, "Invalid publisher");
        return new ExtViewResult(ConverterPortlet.CONTR_SAVE_FILE_CITADEL);
    }
    if (Validator.isNull(source)) {
        getLog(request).error("Invalid source");
        setErrorMessage(request, "Invalid source");
        return new ExtViewResult(ConverterPortlet.CONTR_SAVE_FILE_CITADEL);
    }
    if (!LICENCE_LIST.contains(license)) {
        getLog(request).error("Invalid license");
        setErrorMessage(request, "Invalid license");
        return new ExtViewResult(ConverterPortlet.CONTR_SAVE_FILE_CITADEL);
    }
    try {
        CitadelCityInfo selectedCity = null;
        List<CitadelCityInfo> listCity = null;
        listCity = CitadelIndexUtil.getCitadelCityInfo(CITY_INFO_URL);
        for (CitadelCityInfo info : listCity) {
            if (info.getId() == locationId) {
                selectedCity = info;
                break;
            }
        }
        if (selectedCity == null) {
            getLog(request).error("Invalid location");
            setErrorMessage(request, "Invalid location");
            return new ExtViewResult(ConverterPortlet.CONTR_SAVE_FILE_CITADEL);
        }
        CitadelIndexConfig config = new CitadelIndexConfig();
        config.setCharset(CHARSET_UTF_8);
        config.setSaveFileUrl(SAVE_FILE_URL);
        config.setSaveIndexUrl(SAVE_INDEX_URL);
        config.setDatasetFile(FileUtil.getShortFileName(getResultFilePath(request)));
        config.setDescription(description);
        config.setTitle(title);
        config.setLanguage(language);
        config.setLocation(selectedCity.getName());
        config.setLatitude(selectedCity.getLat());
        config.setLongitude(selectedCity.getLon());
        config.setLicence(license);
        config.setPublisher(publisher);
        config.setReleaseDate(new Date());
        config.setType(type);
        config.setSource(source);
        config.setUserId(getUserId(request));

        CitadelIndexUtil.uploadToCitadelIndex(config, new File(getResultFilePath(request)));
        SessionMessages.add(request, "success");
    } catch (ConverterException e) {
        getLog(request).error(e);
        setErrorMessage(request, e.getMessage());
    }
    return new ExtViewResult(ConverterPortlet.CONTR_SAVE_FILE_CITADEL);
}