Example usage for com.liferay.portal.kernel.util LocalizationUtil getDefaultLanguageId

List of usage examples for com.liferay.portal.kernel.util LocalizationUtil getDefaultLanguageId

Introduction

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

Prototype

public static String getDefaultLanguageId(String xml) 

Source Link

Usage

From source file:com.ankit.service.model.impl.LegacyRoleModelImpl.java

License:Open Source License

@Override
public String getDefaultLanguageId() {
    String xml = getTitle();/*from w ww. ja  v  a  2  s  .c  o  m*/

    if (xml == null) {
        return StringPool.BLANK;
    }

    return LocalizationUtil.getDefaultLanguageId(xml);
}

From source file:com.liferay.calendar.service.test.CalendarBookingLocalServiceTest.java

License:Open Source License

@Test
public void testAddCalendarBooking() throws Exception {
    ServiceContext serviceContext = createServiceContext();

    Calendar calendar = CalendarTestUtil.addCalendar(_user, serviceContext);

    long startTime = System.currentTimeMillis();

    serviceContext.setLanguageId("fr_FR");

    CalendarBooking calendarBooking = CalendarBookingTestUtil.addRegularCalendarBooking(_user, calendar,
            startTime, startTime + (Time.HOUR * 10), serviceContext);

    Assert.assertEquals("fr_FR", LocalizationUtil.getDefaultLanguageId(calendarBooking.getTitle()));
}

From source file:com.liferay.calendar.util.CalendarBookingIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    CalendarBooking calendarBooking = (CalendarBooking) obj;

    Document document = getBaseModelDocument(PORTLET_ID, calendarBooking);

    Locale defaultLocale = LocaleUtil.getSiteDefault();

    String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

    String descriptionDefaultLanguageId = LocalizationUtil
            .getDefaultLanguageId(calendarBooking.getDescription());

    String[] descriptionLanguageIds = getLanguageIds(defaultLanguageId, calendarBooking.getDescription());

    for (String descriptionLanguageId : descriptionLanguageIds) {
        String description = calendarBooking.getDescription(descriptionLanguageId);

        if (descriptionLanguageId.equals(descriptionDefaultLanguageId)) {
            document.addText(Field.DESCRIPTION, description);
        }//w w  w.  ja v  a  2  s  .  c om

        document.addText(Field.DESCRIPTION.concat(StringPool.UNDERLINE).concat(descriptionLanguageId),
                description);
    }

    String titleDefaultLanguageId = LocalizationUtil.getDefaultLanguageId(calendarBooking.getTitle());

    String[] titleLanguageIds = getLanguageIds(defaultLanguageId, calendarBooking.getTitle());

    for (String titleLanguageId : titleLanguageIds) {
        String title = calendarBooking.getTitle(titleLanguageId);

        if (titleLanguageId.equals(titleDefaultLanguageId)) {
            document.addText(Field.TITLE, title);
        }

        document.addText(Field.TITLE.concat(StringPool.UNDERLINE).concat(titleLanguageId), title);
    }

    String calendarBookingId = String.valueOf(calendarBooking.getCalendarBookingId());

    if (calendarBooking.isInTrash()) {
        calendarBookingId = TrashUtil.getOriginalTitle(calendarBookingId);
    }

    document.addKeyword("calendarBookingId", calendarBookingId);

    document.addText("defaultLanguageId", defaultLanguageId);
    document.addNumber("endTime", calendarBooking.getEndTime());
    document.addText("location", calendarBooking.getLocation());
    document.addNumber("startTime", calendarBooking.getStartTime());

    return document;
}

From source file:com.liferay.contenttargeting.model.CampaignClp.java

License:Open Source License

@Override
public String getDefaultLanguageId() {
    String xml = getName();/*www.j  a  v a 2 s  . c  om*/

    if (xml == null) {
        return StringPool.BLANK;
    }

    return LocalizationUtil.getDefaultLanguageId(xml);
}

From source file:com.liferay.dynamic.data.mapping.internal.upgrade.v1_0_0.UpgradeDynamicDataMapping.java

License:Open Source License

protected String toXML(Map<String, String> expandoValuesMap) {
    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("root");

    for (Map.Entry<String, String> entry : expandoValuesMap.entrySet()) {
        Element dynamicElementElement = rootElement.addElement("dynamic-element");

        String name = entry.getKey();
        String data = entry.getValue();

        dynamicElementElement.addAttribute("name", name);
        dynamicElementElement.addAttribute("default-language-id", LocalizationUtil.getDefaultLanguageId(data));

        addDynamicContentElements(dynamicElementElement, name, data);
    }/*from  w  ww .  j  a v  a2s .  co m*/

    return document.asXML();
}

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

License:Open Source License

protected void addJournalArticles(String ddmStructureKey, String ddmTemplateKey, String fileName, long folderId,
        InputStream inputStream) throws Exception {

    String title = FileUtil.stripExtension(fileName);

    JSONObject assetJSONObject = _assetJSONObjectMap.get(fileName);

    Map<Locale, String> descriptionMap = null;

    boolean indexable = true;

    if (assetJSONObject != null) {
        String abstractSummary = assetJSONObject.getString("abstractSummary");

        descriptionMap = getMap(abstractSummary);

        indexable = GetterUtil.getBoolean(assetJSONObject.getString("indexable"), true);
    }//from ww w  .  ja v a 2  s .co m

    String content = StringUtil.read(inputStream);

    content = replaceFileEntryURL(content);
    content = replaceLinksToLayouts(content);

    Locale articleDefaultLocale = LocaleUtil.fromLanguageId(LocalizationUtil.getDefaultLanguageId(content));

    boolean smallImage = false;
    String smallImageURL = StringPool.BLANK;

    if (assetJSONObject != null) {
        String smallImageFileName = assetJSONObject.getString("smallImage");

        if (Validator.isNotNull(smallImageFileName)) {
            smallImage = true;

            FileEntry fileEntry = _fileEntries.get(smallImageFileName);

            if (fileEntry != null) {
                smallImageURL = DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), null,
                        StringPool.BLANK);
            }
        }
    }

    setServiceContext(fileName);

    String journalArticleId = getJournalId(fileName);

    JournalArticle journalArticle = journalArticleLocalService.fetchLatestArticle(groupId, journalArticleId,
            WorkflowConstants.STATUS_ANY);

    try {
        if (journalArticle == null) {
            journalArticle = journalArticleLocalService.addArticle(userId, groupId, folderId, 0, 0,
                    journalArticleId, false, JournalArticleConstants.VERSION_DEFAULT,
                    getMap(articleDefaultLocale, title), descriptionMap, content, ddmStructureKey,
                    ddmTemplateKey, StringPool.BLANK, 1, 1, 2010, 0, 0, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0,
                    true, indexable, smallImage, smallImageURL, null, new HashMap<String, byte[]>(),
                    StringPool.BLANK, serviceContext);
        } else {
            journalArticle = journalArticleLocalService.updateArticle(userId, groupId, folderId,
                    journalArticleId, journalArticle.getVersion(), getMap(articleDefaultLocale, title),
                    descriptionMap, content, ddmStructureKey, ddmTemplateKey, StringPool.BLANK, 1, 1, 2010, 0,
                    0, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, true, indexable, smallImage, smallImageURL, null,
                    new HashMap<String, byte[]>(), StringPool.BLANK, serviceContext);
        }

        journalArticleLocalService.updateStatus(userId, groupId, journalArticle.getArticleId(),
                journalArticle.getVersion(), WorkflowConstants.STATUS_APPROVED, StringPool.BLANK,
                new HashMap<String, Serializable>(), serviceContext);
    } catch (PortalException pe) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to import journal article " + fileName, pe);
        }

        throw pe;
    }

    addPrimaryKey(JournalArticle.class.getName(), journalArticle.getPrimaryKey());
}

From source file:com.liferay.journal.search.JournalArticleIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(JournalArticle journalArticle) throws Exception {

    Document document = getBaseModelDocument(CLASS_NAME, journalArticle);

    long classPK = journalArticle.getId();

    if (!isIndexAllArticleVersions()) {
        classPK = journalArticle.getResourcePrimKey();
    }//w  w  w. j ava  2s  . c  o m

    document.addUID(CLASS_NAME, classPK);

    String articleDefaultLanguageId = LocalizationUtil.getDefaultLanguageId(journalArticle.getDocument());

    String[] languageIds = LocalizationUtil.getAvailableLanguageIds(journalArticle.getDocument());

    for (String languageId : languageIds) {
        String content = extractDDMContent(journalArticle, languageId);

        String description = journalArticle.getDescription(languageId);

        String title = journalArticle.getTitle(languageId);

        if (languageId.equals(articleDefaultLanguageId)) {
            document.addText(Field.CONTENT, content);
            document.addText(Field.DESCRIPTION, description);
            document.addText("defaultLanguageId", languageId);
        }

        document.addText(LocalizationUtil.getLocalizedName(Field.CONTENT, languageId), content);
        document.addText(LocalizationUtil.getLocalizedName(Field.DESCRIPTION, languageId), description);
        document.addText(LocalizationUtil.getLocalizedName(Field.TITLE, languageId), title);
    }

    document.addKeyword(Field.FOLDER_ID, journalArticle.getFolderId());

    String articleId = journalArticle.getArticleId();

    if (journalArticle.isInTrash()) {
        articleId = TrashUtil.getOriginalTitle(articleId);
    }

    document.addKeywordSortable(Field.ARTICLE_ID, articleId);

    document.addKeyword(Field.LAYOUT_UUID, journalArticle.getLayoutUuid());
    document.addKeyword(Field.TREE_PATH, StringUtil.split(journalArticle.getTreePath(), CharPool.SLASH));
    document.addKeyword(Field.VERSION, journalArticle.getVersion());

    document.addKeyword("ddmStructureKey", journalArticle.getDDMStructureKey());
    document.addKeyword("ddmTemplateKey", journalArticle.getDDMTemplateKey());
    document.addDate("displayDate", journalArticle.getDisplayDate());
    document.addKeyword("head", JournalUtil.isHead(journalArticle));

    boolean headListable = JournalUtil.isHeadListable(journalArticle);

    document.addKeyword("headListable", headListable);

    // Scheduled listable articles should be visible in asset browser

    if (journalArticle.isScheduled() && headListable) {
        boolean visible = GetterUtil.getBoolean(document.get("visible"));

        if (!visible) {
            document.addKeyword("visible", true);
        }
    }

    addDDMStructureAttributes(document, journalArticle);

    return document;
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected Locale getArticleDefaultLocale(String content) {
    String defaultLanguageId = LocalizationUtil.getDefaultLanguageId(content);

    if (Validator.isNotNull(defaultLanguageId)) {
        return LocaleUtil.fromLanguageId(defaultLanguageId);
    }// w  w  w  .j av a 2s.  com

    return LocaleUtil.getSiteDefault();
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected void validate(long companyId, long groupId, long classNameId, Map<Locale, String> titleMap,
        String content, String ddmStructureKey, String ddmTemplateKey, Date displayDate, Date expirationDate,
        boolean smallImage, String smallImageURL, File smallImageFile, byte[] smallImageBytes,
        ServiceContext serviceContext) throws PortalException {

    Locale articleDefaultLocale = LocaleUtil.fromLanguageId(LocalizationUtil.getDefaultLanguageId(content));

    if (!ExportImportThreadLocal.isImportInProcess()) {
        if (!LanguageUtil.isAvailableLocale(groupId, articleDefaultLocale)) {

            LocaleException le = new LocaleException(LocaleException.TYPE_CONTENT,
                    "The locale " + articleDefaultLocale + " is not available in site with groupId" + groupId);

            le.setSourceAvailableLocales(Collections.singleton(articleDefaultLocale));
            le.setTargetAvailableLocales(LanguageUtil.getAvailableLocales(groupId));

            throw le;
        }/*from  w w w. j a  va  2  s .  co  m*/

        if ((expirationDate != null) && (expirationDate.before(new Date())
                || ((displayDate != null) && expirationDate.before(displayDate)))) {

            throw new ArticleExpirationDateException("Expiration date " + expirationDate + " is in the past");
        }
    }

    if ((classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT)
            && (titleMap.isEmpty() || Validator.isNull(titleMap.get(articleDefaultLocale)))) {

        throw new ArticleTitleException("Title is null");
    }

    validateContent(content);

    DDMStructure ddmStructure = ddmStructureLocalService.getStructure(PortalUtil.getSiteGroupId(groupId),
            classNameLocalService.getClassNameId(JournalArticle.class), ddmStructureKey, true);

    validateDDMStructureFields(ddmStructure, classNameId, content, articleDefaultLocale);

    if (Validator.isNotNull(ddmTemplateKey)) {
        DDMTemplate ddmTemplate = ddmTemplateLocalService.getTemplate(PortalUtil.getSiteGroupId(groupId),
                classNameLocalService.getClassNameId(DDMStructure.class), ddmTemplateKey, true);

        if (ddmTemplate.getClassPK() != ddmStructure.getStructureId()) {
            throw new NoSuchTemplateException("{templateKey=" + ddmTemplateKey + "}");
        }
    } else if (classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT) {
        throw new NoSuchTemplateException("DDM template key is null");
    }

    if (!smallImage || Validator.isNotNull(smallImageURL) || (smallImageFile == null)
            || (smallImageBytes == null)) {

        return;
    }

    String smallImageName = smallImageFile.getName();

    boolean validSmallImageExtension = false;

    for (String imageExtension : _journalFileUploadsConfiguration.imageExtensions()) {

        if (StringPool.STAR.equals(imageExtension) || StringUtil.endsWith(smallImageName, imageExtension)) {

            validSmallImageExtension = true;

            break;
        }
    }

    if (!validSmallImageExtension) {
        throw new ArticleSmallImageNameException(smallImageName);
    }

    long smallImageMaxSize = _journalFileUploadsConfiguration.smallImageMaxSize();

    if ((smallImageMaxSize > 0) && (smallImageBytes.length > smallImageMaxSize)) {

        throw new ArticleSmallImageSizeException(smallImageBytes.length + " exceeds " + smallImageMaxSize);
    }
}

From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    JournalArticle article = (JournalArticle) obj;

    Document document = getBaseModelDocument(PORTLET_ID, article);

    long classPK = article.getId();

    if (!PropsValues.JOURNAL_ARTICLE_INDEX_ALL_VERSIONS) {
        classPK = article.getResourcePrimKey();
    }//from   ww w  .  j a va 2 s .  c  o  m

    document.addUID(PORTLET_ID, classPK);

    String articleDefaultLanguageId = LocalizationUtil.getDefaultLanguageId(article.getContent());

    Locale defaultLocale = LocaleUtil.getSiteDefault();

    String defaultLanguageId = LocaleUtil.toLanguageId(defaultLocale);

    String[] languageIds = getLanguageIds(defaultLanguageId, article.getContent());

    for (String languageId : languageIds) {
        String content = extractContent(article, languageId);

        String description = article.getDescription(languageId);

        String title = article.getTitle(languageId);

        if (languageId.equals(articleDefaultLanguageId)) {
            document.addText(Field.CONTENT, content);
            document.addText(Field.DESCRIPTION, description);
            document.addText(Field.TITLE, title);
            document.addText("defaultLanguageId", languageId);
        }

        document.addText(Field.CONTENT.concat(StringPool.UNDERLINE).concat(languageId), content);
        document.addText(Field.DESCRIPTION.concat(StringPool.UNDERLINE).concat(languageId), description);
        document.addText(Field.TITLE.concat(StringPool.UNDERLINE).concat(languageId), title);
    }

    document.addKeyword(Field.FOLDER_ID, article.getFolderId());
    document.addKeyword(Field.LAYOUT_UUID, article.getLayoutUuid());
    document.addKeyword(Field.TREE_PATH, StringUtil.split(article.getTreePath(), CharPool.SLASH));
    document.addKeyword(Field.TYPE, article.getType());
    document.addKeyword(Field.VERSION, article.getVersion());

    String articleId = article.getArticleId();

    if (article.isInTrash()) {
        articleId = TrashUtil.getOriginalTitle(articleId);
    }

    document.addKeyword("articleId", articleId);
    document.addKeyword("ddmStructureKey", article.getStructureId());
    document.addKeyword("ddmTemplateKey", article.getTemplateId());
    document.addDate("displayDate", article.getDisplayDate());

    addDDMStructureAttributes(document, article);

    addStatusHeads(document, article);

    return document;
}