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

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

Introduction

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

Prototype

public static String getPath(String fullFileName) 

Source Link

Usage

From source file:com.liferay.dynamic.data.mapping.internal.util.DefaultDDMStructureHelperImpl.java

License:Open Source License

@Override
public void addDDMStructures(long userId, long groupId, long classNameId, ClassLoader classLoader,
        String fileName, ServiceContext serviceContext) throws Exception {

    Locale locale = _portal.getSiteDefaultLocale(groupId);

    List<Element> structureElements = getDDMStructures(classLoader, fileName, locale);

    for (Element structureElement : structureElements) {
        boolean dynamicStructure = GetterUtil.getBoolean(structureElement.elementText("dynamic-structure"));

        if (dynamicStructure) {
            continue;
        }/*from w  ww.ja v  a 2s  .  c om*/

        String name = structureElement.elementText("name");

        String description = structureElement.elementText("description");

        String ddmStructureKey = name;

        DDMStructure ddmStructure = _ddmStructureLocalService.fetchStructure(groupId, classNameId,
                ddmStructureKey);

        if (ddmStructure != null) {
            continue;
        }

        if (name.equals(DLFileEntryTypeConstants.NAME_IG_IMAGE)
                && !UpgradeProcessUtil.isCreateIGImageDocumentType()) {

            continue;
        }

        String ddmTemplateKey = name;

        Map<Locale, String> nameMap = new HashMap<>();
        Map<Locale, String> descriptionMap = new HashMap<>();

        for (Locale curLocale : LanguageUtil.getAvailableLocales(groupId)) {
            nameMap.put(curLocale, LanguageUtil.get(curLocale, name));
            descriptionMap.put(curLocale, LanguageUtil.get(curLocale, description));
        }

        DDMForm ddmForm = getDDMForm(structureElement, locale);

        DDMFormLayout ddmFormLayout = getDDMFormLayout(structureElement, ddmForm);

        serviceContext.setAttribute("status", WorkflowConstants.STATUS_APPROVED);

        ddmStructure = _ddmStructureLocalService.addStructure(userId, groupId,
                DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID, classNameId, ddmStructureKey, nameMap,
                descriptionMap, ddmForm, ddmFormLayout, StorageType.JSON.toString(),
                DDMStructureConstants.TYPE_DEFAULT, serviceContext);

        Element templateElement = structureElement.element("template");

        if (templateElement == null) {
            continue;
        }

        String templateFileName = templateElement.elementText("file-name");

        String script = StringUtil.read(classLoader,
                FileUtil.getPath(fileName) + StringPool.SLASH + templateFileName);

        boolean cacheable = GetterUtil.getBoolean(templateElement.elementText("cacheable"));

        _ddmTemplateLocalService.addTemplate(userId, groupId, _portal.getClassNameId(DDMStructure.class),
                ddmStructure.getStructureId(), ddmStructure.getClassNameId(), ddmTemplateKey, nameMap, null,
                DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY, DDMTemplateConstants.TEMPLATE_MODE_CREATE,
                TemplateConstants.LANG_TYPE_FTL, script, cacheable, false, StringPool.BLANK, null,
                serviceContext);
    }
}

From source file:com.liferay.exportimport.resources.importer.internal.util.ResourceImporter.java

License:Open Source License

protected void addDLFileEntry(String resourcePath) throws Exception {
    Long parentFolderId = _folderIds.get(FileUtil.getPath(resourcePath) + StringPool.SLASH);

    if (parentFolderId == null) {
        parentFolderId = 0L;//from  ww w  .j  a va  2  s  .  co m
    }

    URL url = servletContext.getResource(resourcePath);

    URLConnection urlConnection = url.openConnection();

    addDLFileEntry(parentFolderId, FileUtil.getShortFileName(resourcePath), urlConnection.getInputStream(),
            urlConnection.getContentLength());
}

From source file:com.liferay.exportimport.resources.importer.internal.util.ResourceImporter.java

License:Open Source License

@Override
protected long addDLFolder(long parentFolderId, String resourcePath) throws Exception {

    long folderId = super.addDLFolder(parentFolderId,
            FileUtil.getShortFileName(FileUtil.getPath(resourcePath)));

    _folderIds.put(resourcePath, folderId);

    Set<String> resourcePaths = servletContext.getResourcePaths(resourcePath);

    if ((resourcePaths == null) || resourcePaths.isEmpty()) {
        return folderId;
    }/*from  w  ww . jav  a  2  s .co  m*/

    for (String curResourcePath : resourcePaths) {
        if (curResourcePath.endsWith(StringPool.SLASH)) {
            addDLFolder(folderId, curResourcePath);
        } else {
            addDLFileEntry(curResourcePath);
        }
    }

    return folderId;
}