Example usage for com.liferay.portal.kernel.xml Element addElement

List of usage examples for com.liferay.portal.kernel.xml Element addElement

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.xml Element addElement.

Prototype

public Element addElement(QName qName);

Source Link

Usage

From source file:com.custom.portal.verify.CustomVerifyDynamicDataMapping.java

License:Open Source License

protected boolean createDefaultMetadataElement(Element dynamicElementElement, String defaultLanguageId) {

    boolean hasDefaultMetadataElement = hasDefaultMetadataElement(dynamicElementElement, defaultLanguageId);

    if (hasDefaultMetadataElement) {
        return false;
    }/* w  w  w.  j  av a2  s  . com*/

    Element metadataElement = dynamicElementElement.addElement("meta-data");

    metadataElement.addAttribute("locale", defaultLanguageId);

    Element entryElement = metadataElement.addElement("entry");

    entryElement.addAttribute("name", "label");
    entryElement.addCDATA(StringPool.BLANK);

    return true;
}

From source file:com.liferay.adaptive.media.journal.internal.exportimport.data.handler.test.AMJournalArticleStagedModelDataHandlerTest.java

License:Open Source License

private String _getContent(String html) throws Exception {
    Document document = SAXReaderUtil.createDocument();

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

    Element dynamicElementElement = rootElement.addElement("dynamic-element");

    dynamicElementElement.addAttribute("name", "content");
    dynamicElementElement.addAttribute("type", "text_area");

    Element element = dynamicElementElement.addElement("dynamic-content");

    element.addCDATA(html);/* w w w .  j  a v a 2  s.  c o m*/

    return document.asXML();
}

From source file:com.liferay.asset.categories.admin.web.internal.exportimport.data.handler.AssetCategoryStagedModelDataHandler.java

License:Open Source License

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, AssetCategory category)
        throws Exception {

    if (category.getParentCategoryId() != AssetCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

        AssetCategory parentCategory = _assetCategoryLocalService
                .fetchAssetCategory(category.getParentCategoryId());

        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, category, parentCategory,
                PortletDataContext.REFERENCE_TYPE_PARENT);
    } else {/*from   ww w .ja  va  2 s .c o  m*/
        AssetVocabulary vocabulary = _assetVocabularyLocalService
                .fetchAssetVocabulary(category.getVocabularyId());

        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, category, vocabulary,
                PortletDataContext.REFERENCE_TYPE_PARENT);
    }

    Element categoryElement = portletDataContext.getExportDataElement(category);

    category.setUserUuid(category.getUserUuid());

    List<AssetCategoryProperty> categoryProperties = _assetCategoryPropertyLocalService
            .getCategoryProperties(category.getCategoryId());

    for (AssetCategoryProperty categoryProperty : categoryProperties) {
        Element propertyElement = categoryElement.addElement("property");

        propertyElement.addAttribute("userUuid", categoryProperty.getUserUuid());
        propertyElement.addAttribute("key", categoryProperty.getKey());
        propertyElement.addAttribute("value", categoryProperty.getValue());
    }

    String categoryPath = ExportImportPathUtil.getModelPath(category);

    categoryElement.addAttribute("path", categoryPath);

    portletDataContext.addReferenceElement(category, categoryElement, category,
            PortletDataContext.REFERENCE_TYPE_DEPENDENCY, false);

    portletDataContext.addPermissions(AssetCategory.class, category.getCategoryId());

    portletDataContext.addZipEntry(categoryPath, category);
}

From source file:com.liferay.asset.publisher.web.internal.exportimport.portlet.preferences.processor.AssetPublisherExportImportPortletPreferencesProcessor.java

License:Open Source License

protected void updateExportScopeIds(PortletDataContext portletDataContext,
        PortletPreferences portletPreferences, String key, long plid) throws Exception {

    String[] oldValues = portletPreferences.getValues(key, null);

    if (oldValues == null) {
        return;/*from   w ww  . j  av  a 2s  .com*/
    }

    Layout layout = _layoutLocalService.getLayout(plid);

    String companyGroupScopeId = AssetPublisherUtil.SCOPE_ID_GROUP_PREFIX
            + portletDataContext.getCompanyGroupId();

    String[] newValues = new String[oldValues.length];

    Element rootElement = portletDataContext.getExportDataRootElement();

    Element groupIdMappingsElement = rootElement.addElement("group-id-mappings");

    for (int i = 0; i < oldValues.length; i++) {
        String oldValue = oldValues[i];

        if (oldValue.startsWith(AssetPublisherUtil.SCOPE_ID_GROUP_PREFIX)) {
            newValues[i] = StringUtil.replace(oldValue, companyGroupScopeId, "[$COMPANY_GROUP_SCOPE_ID$]");

            if (newValues[i].contains("[$COMPANY_GROUP_SCOPE_ID$]")) {
                continue;
            }
        } else if (oldValue.startsWith(AssetPublisherUtil.SCOPE_ID_LAYOUT_PREFIX)) {

            // Legacy preferences

            String scopeIdSuffix = oldValue.substring(AssetPublisherUtil.SCOPE_ID_LAYOUT_PREFIX.length());

            long scopeIdLayoutId = GetterUtil.getLong(scopeIdSuffix);

            Layout scopeIdLayout = _layoutLocalService.getLayout(layout.getGroupId(), layout.isPrivateLayout(),
                    scopeIdLayoutId);

            if (plid != scopeIdLayout.getPlid()) {
                StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext,
                        portletDataContext.getPortletId(), scopeIdLayout);
            }

            newValues[i] = AssetPublisherUtil.SCOPE_ID_LAYOUT_UUID_PREFIX + scopeIdLayout.getUuid();
        } else if (oldValue.startsWith(AssetPublisherUtil.SCOPE_ID_LAYOUT_UUID_PREFIX)) {

            String scopeLayoutUuid = oldValue
                    .substring(AssetPublisherUtil.SCOPE_ID_LAYOUT_UUID_PREFIX.length());

            Layout scopeUuidLayout = _layoutLocalService.getLayoutByUuidAndGroupId(scopeLayoutUuid,
                    portletDataContext.getGroupId(), portletDataContext.isPrivateLayout());

            if (plid != scopeUuidLayout.getPlid()) {
                StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext,
                        portletDataContext.getPortletId(), scopeUuidLayout);
            }

            newValues[i] = oldValue;
        } else {
            newValues[i] = oldValue;
        }

        long groupId = AssetPublisherUtil.getGroupIdFromScopeId(newValues[i], portletDataContext.getGroupId(),
                portletDataContext.isPrivateLayout());

        Group group = _groupLocalService.fetchGroup(groupId);

        long liveGroupId = 0;

        if (group != null) {
            liveGroupId = group.getLiveGroupId();

            if (group.isStagedRemotely()) {
                liveGroupId = group.getRemoteLiveGroupId();
            }
        }

        if ((groupId == 0) || (liveGroupId == 0)) {
            continue;
        }

        newValues[i] = String.valueOf(groupId);

        Element groupIdMappingElement = groupIdMappingsElement.addElement("group-id-mapping");

        groupIdMappingElement.addAttribute("group-id", String.valueOf(groupId));
        groupIdMappingElement.addAttribute("live-group-id", String.valueOf(liveGroupId));
    }

    portletPreferences.setValues(key, newValues);
}

From source file:com.liferay.asset.publisher.web.internal.util.AssetPublisherWebUtil.java

License:Open Source License

private String _getAssetEntryXml(String assetEntryType, String assetEntryUuid) {

    String xml = null;/*ww  w .j  av a2 s  . c  o m*/

    try {
        Document document = SAXReaderUtil.createDocument(StringPool.UTF8);

        Element assetEntryElement = document.addElement("asset-entry");

        Element assetEntryTypeElement = assetEntryElement.addElement("asset-entry-type");

        assetEntryTypeElement.addText(assetEntryType);

        Element assetEntryUuidElement = assetEntryElement.addElement("asset-entry-uuid");

        assetEntryUuidElement.addText(assetEntryUuid);

        xml = document.formattedString(StringPool.BLANK);
    } catch (IOException ioe) {
        if (_log.isWarnEnabled()) {
            _log.warn(ioe);
        }
    }

    return xml;
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

private static String _getAssetEntryXml(String assetEntryType, String assetEntryUuid) {

    String xml = null;/*from   w  ww  .  j  a v  a2s  . c  o  m*/

    try {
        Document document = SAXReaderUtil.createDocument(StringPool.UTF8);

        Element assetEntryElement = document.addElement("asset-entry");

        Element assetEntryTypeElement = assetEntryElement.addElement("asset-entry-type");

        assetEntryTypeElement.addText(assetEntryType);

        Element assetEntryUuidElement = assetEntryElement.addElement("asset-entry-uuid");

        assetEntryUuidElement.addText(assetEntryUuid);

        xml = document.formattedString(StringPool.BLANK);
    } catch (IOException ioe) {
        if (_log.isWarnEnabled()) {
            _log.warn(ioe);
        }
    }

    return xml;
}

From source file:com.liferay.calendar.lar.CalendarPortletDataHandlerImpl.java

License:Open Source License

@Override
protected String doExportData(PortletDataContext portletDataContext, String portletId,
        PortletPreferences portletPreferences) throws Exception {

    portletDataContext.addPermissions("com.liferay.portlet.calendar", portletDataContext.getScopeGroupId());

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("calendar-data");

    rootElement.addAttribute("group-id", String.valueOf(portletDataContext.getScopeGroupId()));

    Element calendarsElement = rootElement.addElement("calendars");
    Element calendarBookingsElement = rootElement.addElement("calendar-bookings");
    Element calendarResourcesElement = rootElement.addElement("calendar-resources");

    List<CalendarResource> calendarResources = CalendarResourceLocalServiceUtil
            .getCalendarResources(portletDataContext.getScopeGroupId());

    for (CalendarResource calendarResource : calendarResources) {
        if (portletDataContext.isWithinDateRange(calendarResource.getModifiedDate())) {

            exportCalendarResource(portletDataContext, calendarsElement, calendarBookingsElement,
                    calendarResourcesElement, calendarResource);
        }/*w ww.j  a va 2s .c  o m*/
    }

    return document.formattedString();
}

From source file:com.liferay.calendar.lar.CalendarPortletDataHandlerImpl.java

License:Open Source License

protected void exportCalendar(PortletDataContext portletDataContext, Element calendarsElement,
        Element calendarBookingsElement, Calendar calendar) throws Exception {

    String path = getCalendarPath(portletDataContext, calendar);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;/* ww w . j av  a2s  .  c om*/
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "bookings")) {
        List<CalendarBooking> calendarBookings = CalendarBookingLocalServiceUtil
                .getCalendarBookings(calendar.getCalendarId());

        for (CalendarBooking calendarBooking : calendarBookings) {
            exportCalendarBooking(portletDataContext, calendarBookingsElement, calendarBooking);
        }
    }

    Element calendarElement = calendarsElement.addElement("calendar");

    portletDataContext.addClassedModel(calendarElement, path, calendar, _NAMESPACE);
}

From source file:com.liferay.calendar.lar.CalendarPortletDataHandlerImpl.java

License:Open Source License

protected void exportCalendarBooking(PortletDataContext portletDataContext, Element calendarBookingsElement,
        CalendarBooking calendarBooking) throws Exception {

    String path = getCalendarBookingPath(portletDataContext, calendarBooking);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;//from  w  w  w .j av a 2 s .c o m
    }

    Element bookingElement = calendarBookingsElement.addElement("calendar-booking");

    portletDataContext.addClassedModel(bookingElement, path, calendarBooking, _NAMESPACE);
}

From source file:com.liferay.calendar.lar.CalendarPortletDataHandlerImpl.java

License:Open Source License

protected void exportCalendarResource(PortletDataContext portletDataContext, Element calendarsElement,
        Element calendarBookingsElement, Element calendarResourcesElement, CalendarResource calendarResource)
        throws Exception {

    String path = getCalendarResourcePath(portletDataContext, calendarResource);

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;/*from www  .  j a  v a  2s  .  c  om*/
    }

    List<Calendar> calendars = calendarResource.getCalendars();

    for (Calendar calendar : calendars) {
        exportCalendar(portletDataContext, calendarsElement, calendarBookingsElement, calendar);
    }

    Element resourceElement = calendarResourcesElement.addElement("calendar-resource");

    portletDataContext.addClassedModel(resourceElement, path, calendarResource, _NAMESPACE);
}