Example usage for com.liferay.portal.kernel.util StringPool SLASH

List of usage examples for com.liferay.portal.kernel.util StringPool SLASH

Introduction

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

Prototype

String SLASH

To view the source code for com.liferay.portal.kernel.util StringPool SLASH.

Click Source Link

Usage

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

License:Open Source License

protected void addDDLFormTemplates(String ddmStructureKey, String dirName, String fileName) throws Exception {

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.getStructure(groupId,
            PortalUtil.getClassNameId(DDLRecordSet.class), ddmStructureKey);

    File dir = new File(_resourcesDir, dirName + StringPool.SLASH + fileName);

    if (!dir.isDirectory() || !dir.canRead()) {
        return;/*  w  ww  .j a  va 2s  .  c o  m*/
    }

    File[] files = listFiles(dir);

    for (File file : files) {
        String script = StringUtil.read(getInputStream(file));

        if (Validator.isNull(script)) {
            return;
        }

        addDDMTemplate(groupId, ddmStructure.getStructureId(), file.getName(), "xsd", script,
                DDMTemplateConstants.TEMPLATE_TYPE_FORM, DDMTemplateConstants.TEMPLATE_MODE_CREATE);
    }
}

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

License:Open Source License

protected void addLayout(boolean privateLayout, long parentLayoutId, JSONObject layoutJSONObject)
        throws Exception {

    if (targetClassName.equals(LayoutSetPrototype.class.getName())) {
        privateLayout = true;/*from  ww w.  j a  v  a  2 s .co m*/
    }

    Map<Locale, String> nameMap = getMap(layoutJSONObject, "name");
    Map<Locale, String> titleMap = getMap(layoutJSONObject, "title");

    String type = layoutJSONObject.getString("type");

    if (Validator.isNull(type)) {
        type = LayoutConstants.TYPE_PORTLET;
    }

    String typeSettings = layoutJSONObject.getString("typeSettings");

    boolean hidden = layoutJSONObject.getBoolean("hidden");

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

    String friendlyURL = layoutJSONObject.getString("friendlyURL");

    if (Validator.isNotNull(friendlyURL) && !friendlyURL.startsWith(StringPool.SLASH)) {

        friendlyURL = StringPool.SLASH + friendlyURL;
    }

    friendlyURLMap.put(LocaleUtil.getDefault(), friendlyURL);

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setCompanyId(companyId);
    serviceContext.setScopeGroupId(groupId);
    serviceContext.setUserId(userId);

    ServiceContextThreadLocal.pushServiceContext(serviceContext);

    try {
        String layoutPrototypeName = layoutJSONObject.getString("layoutPrototypeName");

        String layoutPrototypeUuid = null;

        if (Validator.isNotNull(layoutPrototypeName)) {
            LayoutPrototype layoutPrototype = getLayoutPrototype(companyId, layoutPrototypeName);

            layoutPrototypeUuid = layoutPrototype.getUuid();
        } else {
            layoutPrototypeUuid = layoutJSONObject.getString("layoutPrototypeUuid");
        }

        if (Validator.isNotNull(layoutPrototypeUuid)) {
            boolean layoutPrototypeLinkEnabled = GetterUtil
                    .getBoolean(layoutJSONObject.getString("layoutPrototypeLinkEnabled"), false);

            serviceContext.setAttribute("layoutPrototypeLinkEnabled", layoutPrototypeLinkEnabled);

            serviceContext.setAttribute("layoutPrototypeUuid", layoutPrototypeUuid);
        }

        Layout layout = LayoutLocalServiceUtil.addLayout(userId, groupId, privateLayout, parentLayoutId,
                nameMap, titleMap, null, null, null, type, typeSettings, hidden, friendlyURLMap,
                serviceContext);

        LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

        String layoutTemplateId = layoutJSONObject.getString("layoutTemplateId", _defaultLayoutTemplateId);

        if (Validator.isNotNull(layoutTemplateId)) {
            layoutTypePortlet.setLayoutTemplateId(userId, layoutTemplateId, false);
        }

        JSONArray columnsJSONArray = layoutJSONObject.getJSONArray("columns");

        addLayoutColumns(layout, LayoutTypePortletConstants.COLUMN_PREFIX, columnsJSONArray);

        LayoutLocalServiceUtil.updateLayout(groupId, layout.isPrivateLayout(), layout.getLayoutId(),
                layout.getTypeSettings());

        JSONArray layoutsJSONArray = layoutJSONObject.getJSONArray("layouts");

        addLayouts(privateLayout, layout.getLayoutId(), layoutsJSONArray);
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to import layout " + layoutJSONObject, e);
        }

        throw e;
    } finally {
        ServiceContextThreadLocal.popServiceContext();
    }
}

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

License:Open Source License

public PluginPackageProperties(ServletContext servletContext) throws IOException {

    String propertiesString = StringUtil
            .read(servletContext.getResourceAsStream("/WEB-INF/liferay-plugin-package.properties"));

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

    String contextPath = servletContext.getRealPath(StringPool.SLASH);

    contextPath = StringUtil.replace(contextPath, StringPool.BACK_SLASH, StringPool.SLASH);

    propertiesString = propertiesString.replace("${context.path}", contextPath);

    PropertiesUtil.load(_properties, propertiesString);
}

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

License:Open Source License

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

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.getStructure(groupId,
            PortalUtil.getClassNameId(DDLRecordSet.class), ddmStructureKey);

    StringBundler sb = new StringBundler(4);

    sb.append(resourcesDir);/*from   ww  w.j  av a  2  s.c om*/
    sb.append(dirName);
    sb.append(StringPool.SLASH);
    sb.append(fileName);

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

    if (resourcePaths == null) {
        return;
    }

    for (String resourcePath : resourcePaths) {
        URL url = servletContext.getResource(resourcePath);

        URLConnection urlConnection = url.openConnection();

        String script = StringUtil.read(urlConnection.getInputStream());

        if (Validator.isNull(script)) {
            return;
        }

        addDDMTemplate(groupId, ddmStructure.getStructureId(), resourcePath,
                getDDMTemplateLanguage(resourcePath), script, DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY,
                StringPool.BLANK);
    }
}

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

License:Open Source License

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

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.getStructure(groupId,
            PortalUtil.getClassNameId(DDLRecordSet.class), ddmStructureKey);

    StringBundler sb = new StringBundler(4);

    sb.append(resourcesDir);//from   w  w w. j a  v a  2  s .c  o  m
    sb.append(dirName);
    sb.append(StringPool.SLASH);
    sb.append(fileName);

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

    if (resourcePaths == null) {
        return;
    }

    for (String resourcePath : resourcePaths) {
        URL url = servletContext.getResource(resourcePath);

        URLConnection urlConnection = url.openConnection();

        String script = StringUtil.read(urlConnection.getInputStream());

        if (Validator.isNull(script)) {
            return;
        }

        addDDMTemplate(groupId, ddmStructure.getStructureId(), resourcePath, "xsd", script,
                DDMTemplateConstants.TEMPLATE_TYPE_FORM, DDMTemplateConstants.TEMPLATE_MODE_CREATE);
    }
}

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 .  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();

        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;//from   w  w w.ja  v  a  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();

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

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

License:Open Source License

@Override
protected void addDLFileEntries(String dirName) throws Exception {
    Set<String> resourcePaths = servletContext.getResourcePaths(resourcesDir.concat(dirName));

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

    for (String resourcePath : resourcePaths) {
        if (resourcePath.endsWith(StringPool.SLASH)) {
            addDLFolder(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, resourcePath);
        } else {
            addDLFileEntry(resourcePath);
        }
    }
}

From source file:com.liferay.resourcesimporter.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;//w w w. j ava  2 s . c  om
    }

    URL url = servletContext.getResource(resourcePath);

    URLConnection urlConnection = url.openConnection();

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

From source file:com.liferay.resourcesimporter.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 w  w. j  a  va  2  s. co m*/

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

    return folderId;
}