Example usage for com.liferay.portal.kernel.util StringUtil read

List of usage examples for com.liferay.portal.kernel.util StringUtil read

Introduction

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

Prototype

public static String read(ClassLoader classLoader, String name) throws IOException 

Source Link

Usage

From source file:com.evolveum.liferay.usercreatehook.service.CustomUserLocalServiceImpl.java

License:Apache License

protected static void sendEmail(String wsCall, long companyId) {
    try {//w  ww.j av a  2  s  .c  o  m

        String fromName = PrefsPropsUtil.getString(companyId, "admin.email.from.name");
        String fromAddress = PrefsPropsUtil.getString(companyId, "admin.email.from.address");

        String toAddress = fromAddress;
        String toName = fromName;

        ClassLoader classLoader = CustomUserLocalServiceImpl.class.getClassLoader();

        SimpleDateFormat sdf = new SimpleDateFormat(TIME_PATTERN);
        String serverTime = sdf.format(new Date());

        String subject = StringUtil.read(classLoader, "content/email/email_ws_error_subject.tmpl");
        String body = StringUtil.read(classLoader, "content/email/email_ws_error_body.tmpl");

        subject = StringUtil.replace(subject,
                new String[] { "[$FROM_ADDRESS$]", "[$FROM_NAME$]", "[$TO_ADDRESS$]", "[$TO_NAME$]",
                        "[$WS_CALL$]", "[$SERVER_TIME$]" },
                new String[] { fromAddress, fromName, toAddress, toName, wsCall, serverTime });

        body = StringUtil.replace(body,
                new String[] { "[$FROM_ADDRESS$]", "[$FROM_NAME$]", "[$TO_ADDRESS$]", "[$TO_NAME$]",
                        "[$WS_CALL$]", "[$SERVER_TIME$]" },
                new String[] { fromAddress, fromName, toAddress, toName, wsCall, serverTime });

        InternetAddress from = new InternetAddress(fromAddress, fromName);

        InternetAddress to = new InternetAddress(toAddress, toName);

        MailMessage mailMessage = new MailMessage(from, to, subject, body, true);

        MailServiceUtil.sendEmail(mailMessage);
    } catch (Exception e) {
        LOG.error("Error while sending email: " + e.getMessage(), e);
    }
}

From source file:com.liferay.blogs.demo.data.creator.internal.LoremIpsumBlogsEntryDemoDataCreatorImpl.java

License:Open Source License

private static List<String> _read(String fileName) {
    return Arrays.asList(StringUtil.split(StringUtil.read(LoremIpsumBlogsEntryDemoDataCreatorImpl.class,
            "dependencies/lorem/ipsum/" + fileName + ".txt"), CharPool.NEW_LINE));
}

From source file:com.liferay.comment.demo.data.creator.internal.CommentDemoDataCreatorImpl.java

License:Open Source License

private static List<String> _read(String fileName) {
    String content = StringUtil.read(CommentDemoDataCreatorImpl.class, "dependencies/" + fileName + ".txt");

    return Arrays.asList(StringUtil.split(content, CharPool.NEW_LINE));
}

From source file:com.liferay.dynamic.data.lists.exporter.test.DDLExporterTest.java

License:Open Source License

protected String read(String fileName) throws Exception {
    Class<?> clazz = getClass();

    return StringUtil.read(clazz.getClassLoader(), "com/liferay/dynamic/data/lists/dependencies/" + fileName);
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.converter.BaseDDLDDMConverterTest.java

License:Open Source License

protected String read(String fileName) throws Exception {
    Class<?> clazz = getClass();

    return StringUtil.read(clazz.getClassLoader(), getBasePath() + fileName);
}

From source file:com.liferay.dynamic.data.lists.helper.DDLRecordTestUtil.java

License:Open Source License

public static String read(Class<?> testClass, String fileName) throws Exception {

    return StringUtil.read(testClass.getClassLoader(), getBasePath() + fileName);
}

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;
        }//  w ww.j a va2s .c  o m

        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.dynamic.data.mapping.internal.util.DefaultDDMStructureHelperImpl.java

License:Open Source License

protected List<Element> getDDMStructures(ClassLoader classLoader, String fileName, Locale locale)
        throws Exception {

    String xml = StringUtil.read(classLoader, fileName);

    xml = StringUtil.replace(xml, "[$LOCALE_DEFAULT$]", locale.toString());

    Document document = UnsecureSAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    return rootElement.elements("structure");
}

From source file:com.liferay.invitation.invite.members.service.impl.MemberRequestLocalServiceImpl.java

License:Open Source License

protected void sendEmail(String emailAddress, MemberRequest memberRequest, ServiceContext serviceContext)
        throws Exception {

    long companyId = memberRequest.getCompanyId();

    Group group = groupLocalService.getGroup(memberRequest.getGroupId());

    User user = userLocalService.getUser(memberRequest.getUserId());

    User receiverUser = null;// w  w w  .  j  a v  a 2 s . com

    if (memberRequest.getReceiverUserId() > 0) {
        receiverUser = userLocalService.getUser(memberRequest.getReceiverUserId());
    }

    String fromName = PrefsPropsUtil.getString(companyId, PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getString(companyId, PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    String toName = StringPool.BLANK;
    String toAddress = emailAddress;

    if (receiverUser != null) {
        toName = receiverUser.getFullName();
    }

    String subject = StringUtil.read(getClassLoader(),
            "com/liferay/invitation/invite/members/dependencies/subject.tmpl");

    String body = StringPool.BLANK;

    if (memberRequest.getReceiverUserId() > 0) {
        body = StringUtil.read(getClassLoader(),
                "com/liferay/invitation/invite/members/dependencies" + "/existing_user_body.tmpl");
    } else {
        body = StringUtil.read(getClassLoader(),
                "com/liferay/invitation/invite/members/dependencies" + "/new_user_body.tmpl");
    }

    subject = StringUtil.replace(subject,
            new String[] { "[$MEMBER_REQUEST_GROUP$]", "[$MEMBER_REQUEST_USER$]" },
            new String[] { group.getDescriptiveName(serviceContext.getLocale()), user.getFullName() });

    body = StringUtil.replace(body,
            new String[] { "[$ADMIN_ADDRESS$]", "[$ADMIN_NAME$]", "[$MEMBER_REQUEST_CREATE_ACCOUNT_URL$]",
                    "[$MEMBER_REQUEST_GROUP$]", "[$MEMBER_REQUEST_LOGIN_URL$]", "[$MEMBER_REQUEST_USER$]" },
            new String[] { fromAddress, fromName, getCreateAccountURL(memberRequest, serviceContext),
                    group.getDescriptiveName(serviceContext.getLocale()),
                    getLoginURL(memberRequest, serviceContext), user.getFullName() });

    InternetAddress from = new InternetAddress(fromAddress, fromName);

    InternetAddress to = new InternetAddress(toAddress, toName);

    MailMessage mailMessage = new MailMessage(from, to, subject, body, true);

    mailService.sendEmail(mailMessage);
}

From source file:com.liferay.journal.trash.test.JournalArticleTrashHandlerTest.java

License:Open Source License

@Test
public void testArticleImages() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId());

    Class<?> clazz = getClass();

    ClassLoader classLoader = clazz.getClassLoader();

    String definition = StringUtil.read(classLoader,
            "com/liferay/journal/dependencies" + "/test-ddm-structure-image-field.xml");

    DDMForm ddmForm = _ddmFormXSDDeserializer.deserialize(definition);

    DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(serviceContext.getScopeGroupId(),
            JournalArticle.class.getName(), ddmForm);

    DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(serviceContext.getScopeGroupId(),
            ddmStructure.getStructureId(), PortalUtil.getClassNameId(JournalArticle.class));

    InputStream inputStream = classLoader.getResourceAsStream("/com/liferay/journal/dependencies/liferay.png");

    FileEntry tempFileEntry = TempFileEntryUtil.addTempFileEntry(group.getGroupId(),
            TestPropsValues.getUserId(), JournalArticle.class.getName(), "liferay.png", inputStream,
            ContentTypes.IMAGE_PNG);// ww w  .  j a  v  a 2 s  .co  m

    String content = StringUtil.read(classLoader,
            "com/liferay/journal/dependencies/test-journal-content-image-" + "field.xml");

    Document document = SAXReaderUtil.read(content);

    Element dynamicContent = (Element) document.selectSingleNode("//dynamic-content");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("groupId", group.getGroupId());
    jsonObject.put("name", "liferay.png");
    jsonObject.put("tempFile", Boolean.TRUE.toString());
    jsonObject.put("title", "liferay.png");
    jsonObject.put("type", "journal");
    jsonObject.put("uuid", tempFileEntry.getUuid());

    dynamicContent.setText(jsonObject.toString());

    baseModel = JournalTestUtil.addArticleWithXMLContent(JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            document.asXML(), ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(), serviceContext);

    JournalArticle article = (JournalArticle) baseModel;

    long folderId = article.getImagesFolderId();

    Assert.assertEquals(1, PortletFileRepositoryUtil.getPortletFileEntriesCount(group.getGroupId(), folderId));

    moveBaseModelToTrash((Long) baseModel.getPrimaryKeyObj());

    Assert.assertEquals(0, PortletFileRepositoryUtil.getPortletFileEntriesCount(group.getGroupId(), folderId,
            WorkflowConstants.STATUS_APPROVED));
    Assert.assertEquals(1, PortletFileRepositoryUtil.getPortletFileEntriesCount(group.getGroupId(), folderId,
            WorkflowConstants.STATUS_IN_TRASH));

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(getBaseModelClassName());

    trashHandler.deleteTrashEntry(getTrashEntryClassPK(baseModel));

    Assert.assertEquals(0, PortletFileRepositoryUtil.getPortletFileEntriesCount(group.getGroupId(), folderId));
}