public void applyAction(
      MDRAction mdrAction, HttpServletRequest request, HttpServletResponse response) {

    long companyId = PortalUtil.getCompanyId(request);

    UnicodeProperties typeSettingsProperties = mdrAction.getTypeSettingsProperties();

    String themeId = GetterUtil.getString(typeSettingsProperties.getProperty("themeId"));

    Theme theme = _themeLocalService.fetchTheme(companyId, themeId);

    if (theme == null) {
      return;
    }

    request.setAttribute(WebKeys.THEME, theme);

    String colorSchemeId =
        GetterUtil.getString(typeSettingsProperties.getProperty("colorSchemeId"));

    ColorScheme colorScheme =
        _themeLocalService.fetchColorScheme(companyId, themeId, colorSchemeId);

    if (colorScheme == null) {
      colorScheme = ColorSchemeImpl.getNullColorScheme();
    }

    request.setAttribute(WebKeys.COLOR_SCHEME, colorScheme);

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    String contextPath = PortalUtil.getPathContext();

    themeDisplay.setLookAndFeel(contextPath, theme, colorScheme);
  }
Exemplo n.º 2
0
  protected void mergePortlets(Layout layout, String newTypeSettings, String portletsMergeMode) {

    try {
      UnicodeProperties previousTypeSettingsProperties = layout.getTypeSettingsProperties();

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

      LayoutTemplate previousLayoutTemplate = previousLayoutType.getLayoutTemplate();

      List<String> previousColumns = previousLayoutTemplate.getColumns();

      UnicodeProperties newTypeSettingsProperties = new UnicodeProperties(true);

      newTypeSettingsProperties.load(newTypeSettings);

      String layoutTemplateId =
          newTypeSettingsProperties.getProperty(LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID);

      previousTypeSettingsProperties.setProperty(
          LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID, layoutTemplateId);

      LayoutTemplate newLayoutTemplate =
          LayoutTemplateLocalServiceUtil.getLayoutTemplate(layoutTemplateId, false, null);

      String[] newPortletIds = new String[0];

      for (String columnId : newLayoutTemplate.getColumns()) {
        String columnValue = newTypeSettingsProperties.getProperty(columnId);

        String[] portletIds = StringUtil.split(columnValue);

        if (!previousColumns.contains(columnId)) {
          newPortletIds = ArrayUtil.append(newPortletIds, portletIds);
        } else {
          String[] previousPortletIds =
              StringUtil.split(previousTypeSettingsProperties.getProperty(columnId));

          portletIds = appendPortletIds(previousPortletIds, portletIds, portletsMergeMode);

          previousTypeSettingsProperties.setProperty(columnId, StringUtil.merge(portletIds));
        }
      }

      // Add portlets in non-existent column to the first column

      String columnId = previousColumns.get(0);

      String[] portletIds = StringUtil.split(previousTypeSettingsProperties.getProperty(columnId));

      appendPortletIds(portletIds, newPortletIds, portletsMergeMode);

      previousTypeSettingsProperties.setProperty(columnId, StringUtil.merge(portletIds));

      layout.setTypeSettings(previousTypeSettingsProperties.toString());
    } catch (IOException ioe) {
      layout.setTypeSettings(newTypeSettings);
    }
  }
Exemplo n.º 3
0
  protected boolean isCacheableData(long companyId, HttpServletRequest request) {

    try {
      if (_pattern == _PATTERN_RESOURCE) {
        return true;
      }

      long plid =
          getPlid(
              companyId,
              request.getPathInfo(),
              request.getServletPath(),
              ParamUtil.getLong(request, "p_l_id"));

      if (plid <= 0) {
        return false;
      }

      Layout layout = LayoutLocalServiceUtil.getLayout(plid);

      if (!layout.isTypePortlet()) {
        return false;
      }

      UnicodeProperties properties = layout.getTypeSettingsProperties();

      for (int i = 0; i < 10; i++) {
        String columnId = "column-" + i;

        String settings = properties.getProperty(columnId, StringPool.BLANK);

        if (!isCacheableColumn(companyId, settings)) {
          return false;
        }
      }

      String columnIdsString = properties.get(LayoutTypePortletConstants.NESTED_COLUMN_IDS);

      if (columnIdsString != null) {
        String[] columnIds = StringUtil.split(columnIdsString);

        for (String columnId : columnIds) {
          String settings = properties.getProperty(columnId, StringPool.BLANK);

          if (!isCacheableColumn(companyId, settings)) {
            return false;
          }
        }
      }

      return true;
    } catch (Exception e) {
      return false;
    }
  }
Exemplo n.º 4
0
  private LayoutTypePortlet _getLayoutTypePortletClone(HttpServletRequest request)
      throws IOException {

    LayoutTypePortlet layoutTypePortlet = null;

    LayoutClone layoutClone = LayoutCloneFactory.getInstance();

    if (layoutClone != null) {
      String typeSettings = layoutClone.get(request, getPlid());

      if (typeSettings != null) {
        UnicodeProperties typeSettingsProperties = new UnicodeProperties(true);

        typeSettingsProperties.load(typeSettings);

        String stateMax = typeSettingsProperties.getProperty(LayoutTypePortletConstants.STATE_MAX);
        String stateMin = typeSettingsProperties.getProperty(LayoutTypePortletConstants.STATE_MIN);

        Layout layout = (Layout) this.clone();

        layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

        layoutTypePortlet.setStateMax(stateMax);
        layoutTypePortlet.setStateMin(stateMin);
      }
    }

    if (layoutTypePortlet == null) {
      layoutTypePortlet = (LayoutTypePortlet) getLayoutType();
    }

    return layoutTypePortlet;
  }
  protected void exportJournalArticle(
      PortletDataContext portletDataContext, Layout layout, Element layoutElement)
      throws Exception {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    String articleId = typeSettingsProperties.getProperty("article-id", StringPool.BLANK);

    long articleGroupId = layout.getGroupId();

    if (Validator.isNull(articleId)) {
      if (_log.isWarnEnabled()) {
        _log.warn("No article id found in typeSettings of layout " + layout.getPlid());
      }
    }

    JournalArticle article = null;

    try {
      article =
          JournalArticleLocalServiceUtil.getLatestArticle(
              articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED);
    } catch (NoSuchArticleException nsae) {
      if (_log.isWarnEnabled()) {
        _log.warn(
            "No approved article found with group id "
                + articleGroupId
                + " and article id "
                + articleId);
      }
    }

    if (article == null) {
      return;
    }

    String path = JournalPortletDataHandlerImpl.getArticlePath(portletDataContext, article);

    Element articleElement = layoutElement.addElement("article");

    articleElement.addAttribute("path", path);

    Element dlFileEntryTypesElement = layoutElement.addElement("dl-file-entry-types");
    Element dlFoldersElement = layoutElement.addElement("dl-folders");
    Element dlFilesElement = layoutElement.addElement("dl-file-entries");
    Element dlFileRanksElement = layoutElement.addElement("dl-file-ranks");

    JournalPortletDataHandlerImpl.exportArticle(
        portletDataContext,
        layoutElement,
        layoutElement,
        layoutElement,
        dlFileEntryTypesElement,
        dlFoldersElement,
        dlFilesElement,
        dlFileRanksElement,
        article,
        false);
  }
  @Override
  protected String getURL(
      MDRAction mdrAction, HttpServletRequest request, HttpServletResponse response) {

    UnicodeProperties typeSettingsProperties = mdrAction.getTypeSettingsProperties();

    return GetterUtil.getString(typeSettingsProperties.getProperty("url"));
  }
  public String getSourcePrototypeLayoutProperty(String key) {
    if (_sourcePrototypeLayout == null) {
      return StringPool.BLANK;
    }

    UnicodeProperties typeSettingsProperties = _sourcePrototypeLayout.getTypeSettingsProperties();

    return typeSettingsProperties.getProperty(key);
  }
  public static String getTypeSettingsValue(
      UnicodeProperties typeSettingsProperties, String typeSettingsKey)
      throws InvalidRepositoryException {

    String value = typeSettingsProperties.getProperty(typeSettingsKey);

    if (Validator.isNull(value)) {
      throw new InvalidRepositoryException();
    }

    return value;
  }
Exemplo n.º 9
0
  @Override
  public int getMaxAge(Group group) {
    int trashEntriesMaxAge =
        PrefsPropsUtil.getInteger(
            group.getCompanyId(),
            PropsKeys.TRASH_ENTRIES_MAX_AGE,
            PropsValues.TRASH_ENTRIES_MAX_AGE);

    UnicodeProperties typeSettingsProperties = group.getParentLiveGroupTypeSettingsProperties();

    return GetterUtil.getInteger(
        typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAge);
  }
Exemplo n.º 10
0
  @Override
  public boolean isTrashEnabled(Group group) {
    boolean companyTrashEnabled =
        PrefsPropsUtil.getBoolean(group.getCompanyId(), PropsKeys.TRASH_ENABLED);

    if (!companyTrashEnabled) {
      return false;
    }

    UnicodeProperties typeSettingsProperties = group.getParentLiveGroupTypeSettingsProperties();

    return GetterUtil.getBoolean(typeSettingsProperties.getProperty("trashEnabled"), true);
  }
Exemplo n.º 11
0
  @Override
  public String getThemeSetting(String key, String device, boolean inheritLookAndFeel) {

    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();

    String value =
        typeSettingsProperties.getProperty(ThemeSettingImpl.namespaceProperty(device, key));

    if (value != null) {
      return value;
    }

    return getDefaultThemeSetting(key, device, inheritLookAndFeel);
  }
Exemplo n.º 12
0
  @Override
  public boolean isContentDisplayPage() {
    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();

    String defaultAssetPublisherPortletId =
        typeSettingsProperties.getProperty(
            LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID);

    if (Validator.isNotNull(defaultAssetPublisherPortletId)) {
      return true;
    }

    return false;
  }
Exemplo n.º 13
0
  public boolean isTrashEnabled(long groupId) throws PortalException, SystemException {

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    UnicodeProperties typeSettingsProperties = group.getParentLiveGroupTypeSettingsProperties();

    boolean companyTrashEnabled =
        PrefsPropsUtil.getBoolean(group.getCompanyId(), PropsKeys.TRASH_ENABLED);

    if (!companyTrashEnabled) {
      return false;
    }

    return GetterUtil.getBoolean(typeSettingsProperties.getProperty("trashEnabled"), true);
  }
Exemplo n.º 14
0
  protected void importJournalArticle(
      PortletDataContext portletDataContext, Layout layout, Element layoutElement)
      throws Exception {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    String articleId = typeSettingsProperties.getProperty("article-id", StringPool.BLANK);

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

    JournalPortletDataHandlerImpl.importReferencedData(portletDataContext, layoutElement);

    Element structureElement = layoutElement.element("structure");

    if (structureElement != null) {
      JournalPortletDataHandlerImpl.importStructure(portletDataContext, structureElement);
    }

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

    if (templateElement != null) {
      JournalPortletDataHandlerImpl.importTemplate(portletDataContext, templateElement);
    }

    Element articleElement = layoutElement.element("article");

    if (articleElement != null) {
      JournalPortletDataHandlerImpl.importArticle(portletDataContext, articleElement);
    }

    Map<String, String> articleIds =
        (Map<String, String>)
            portletDataContext.getNewPrimaryKeysMap(JournalArticle.class + ".articleId");

    articleId = MapUtil.getString(articleIds, articleId, articleId);

    typeSettingsProperties.setProperty("article-id", articleId);

    JournalContentSearchLocalServiceUtil.updateContentSearch(
        portletDataContext.getScopeGroupId(),
        layout.isPrivateLayout(),
        layout.getLayoutId(),
        StringPool.BLANK,
        articleId,
        true);
  }
Exemplo n.º 15
0
  public int getMaxAge(Group group) throws PortalException, SystemException {
    if (group.isLayout()) {
      group = group.getParentGroup();
    }

    int trashEntriesMaxAge =
        PrefsPropsUtil.getInteger(
            group.getCompanyId(),
            PropsKeys.TRASH_ENTRIES_MAX_AGE,
            GetterUtil.getInteger(PropsUtil.get(PropsKeys.TRASH_ENTRIES_MAX_AGE)));

    UnicodeProperties typeSettingsProperties = group.getTypeSettingsProperties();

    return GetterUtil.getInteger(
        typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAge);
  }
Exemplo n.º 16
0
  protected void visitLayout(Element element, Layout layout, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    if (!PortalUtil.isLayoutSitemapable(layout)
        || !GetterUtil.getBoolean(typeSettingsProperties.getProperty("sitemap-include"), true)) {

      return;
    }

    String layoutFullURL = PortalUtil.getLayoutFullURL(layout, themeDisplay);

    layoutFullURL = PortalUtil.getCanonicalURL(layoutFullURL, themeDisplay, layout);

    addURLElement(
        element,
        layoutFullURL,
        typeSettingsProperties,
        layout.getModifiedDate(),
        layoutFullURL,
        getAlternateURLs(layoutFullURL, themeDisplay, layout));

    Locale[] availableLocales = LanguageUtil.getAvailableLocales(layout.getGroupId());

    if (availableLocales.length > 1) {
      Locale defaultLocale = LocaleUtil.getSiteDefault();

      for (Locale availableLocale : availableLocales) {
        if (availableLocale.equals(defaultLocale)) {
          continue;
        }

        String alternateURL =
            PortalUtil.getAlternateURL(layoutFullURL, themeDisplay, availableLocale, layout);

        addURLElement(
            element,
            alternateURL,
            typeSettingsProperties,
            layout.getModifiedDate(),
            layoutFullURL,
            getAlternateURLs(layoutFullURL, themeDisplay, layout));
      }
    }
  }
Exemplo n.º 17
0
  protected void fixTypeSettings(Layout layout) throws Exception {
    if (!layout.isTypeURL()) {
      return;
    }

    UnicodeProperties typeSettings = layout.getTypeSettingsProperties();

    String url = GetterUtil.getString(typeSettings.getProperty("url"));

    String friendlyURLPrivateGroupPath =
        PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING;
    String friendlyURLPrivateUserPath =
        PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING;
    String friendlyURLPublicPath = PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING;

    if (!url.startsWith(friendlyURLPrivateGroupPath)
        && !url.startsWith(friendlyURLPrivateUserPath)
        && !url.startsWith(friendlyURLPublicPath)) {

      return;
    }

    int x = url.indexOf(CharPool.SLASH, 1);

    if (x == -1) {
      return;
    }

    int y = url.indexOf(CharPool.SLASH, x + 1);

    if (y == -1) {
      return;
    }

    String friendlyURL = url.substring(x, y);

    if (!friendlyURL.equals(LayoutExporter.SAME_GROUP_FRIENDLY_URL)) {
      return;
    }

    Group group = layout.getGroup();

    typeSettings.setProperty(
        "url", url.substring(0, x) + group.getFriendlyURL() + url.substring(y));
  }
Exemplo n.º 18
0
  @Override
  public boolean isStagedPortlet(String portletId) {
    UnicodeProperties typeSettingsProperties = getParentLiveGroupTypeSettingsProperties();

    portletId = PortletConstants.getRootPortletId(portletId);

    String typeSettingsProperty =
        typeSettingsProperties.getProperty(StagingUtil.getStagedPortletId(portletId));

    if (Validator.isNotNull(typeSettingsProperty)) {
      return GetterUtil.getBoolean(typeSettingsProperty);
    }

    try {
      Portlet portlet = PortletLocalServiceUtil.getPortletById(portletId);

      String portletDataHandlerClass = portlet.getPortletDataHandlerClass();

      if (Validator.isNull(portletDataHandlerClass)) {
        return true;
      }

      for (Map.Entry<String, String> entry : typeSettingsProperties.entrySet()) {

        String key = entry.getKey();

        if (!key.contains(StagingConstants.STAGED_PORTLET)) {
          continue;
        }

        String stagedPortletId =
            StringUtil.replace(key, StagingConstants.STAGED_PORTLET, StringPool.BLANK);

        Portlet stagedPortlet = PortletLocalServiceUtil.getPortletById(stagedPortletId);

        if (portletDataHandlerClass.equals(stagedPortlet.getPortletDataHandlerClass())) {

          return GetterUtil.getBoolean(entry.getValue());
        }
      }
    } catch (Exception e) {
    }

    return true;
  }
  public String getThemeSetting(String key, String device) {
    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();

    String value =
        typeSettingsProperties.getProperty(ThemeSettingImpl.namespaceProperty(device, key));

    if (value != null) {
      return value;
    }

    try {
      LayoutSet layoutSet = getLayoutSet();

      value = layoutSet.getThemeSetting(key, device);
    } catch (Exception e) {
    }

    return value;
  }
  public void applyAction(
      MDRAction mdrAction, HttpServletRequest request, HttpServletResponse response) {

    UnicodeProperties mdrActionTypeSettingsProperties = mdrAction.getTypeSettingsProperties();

    String layoutTemplateId =
        GetterUtil.getString(mdrActionTypeSettingsProperties.getProperty("layoutTemplateId"));

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    UnicodeProperties layoutTypeSettingsProperties = layout.getTypeSettingsProperties();

    layoutTypeSettingsProperties.setProperty(
        LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID, layoutTemplateId);

    layout.setTypeSettingsProperties(layoutTypeSettingsProperties);
  }
Exemplo n.º 21
0
  private ObjectValuePair<Map<String, Locale>, Map<String, Locale>> _createGroupLocales(
      long groupId) {

    String[] languageIds = PropsValues.LOCALES_ENABLED;

    try {
      Group group = GroupLocalServiceUtil.getGroup(groupId);

      UnicodeProperties typeSettingsProperties = group.getTypeSettingsProperties();

      languageIds = StringUtil.split(typeSettingsProperties.getProperty(PropsKeys.LOCALES));
    } catch (Exception e) {
    }

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

    for (String languageId : languageIds) {
      Locale locale = LocaleUtil.fromLanguageId(languageId, false);

      String languageCode = languageId;

      int pos = languageId.indexOf(CharPool.UNDERLINE);

      if (pos > 0) {
        languageCode = languageId.substring(0, pos);
      }

      if (!groupLanguageCodeLocalesMap.containsKey(languageCode)) {
        groupLanguageCodeLocalesMap.put(languageCode, locale);
      }

      groupLanguageIdLocalesMap.put(languageId, locale);
    }

    _groupLanguageCodeLocalesMapMap.put(groupId, groupLanguageCodeLocalesMap);
    _groupLanguageIdLocalesMap.put(groupId, groupLanguageIdLocalesMap);

    return new ObjectValuePair<>(groupLanguageCodeLocalesMap, groupLanguageIdLocalesMap);
  }
  protected void exportLinkedLayout(
      PortletDataContext portletDataContext, Layout layout, Element layoutElement)
      throws Exception {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    long linkToLayoutId =
        GetterUtil.getLong(typeSettingsProperties.getProperty("linkToLayoutId", StringPool.BLANK));

    if (linkToLayoutId > 0) {
      try {
        Layout linkedToLayout =
            _layoutLocalService.getLayout(
                portletDataContext.getScopeGroupId(), layout.isPrivateLayout(), linkToLayoutId);

        StagedModelDataHandlerUtil.exportReferenceStagedModel(
            portletDataContext, layout, linkedToLayout, PortletDataContext.REFERENCE_TYPE_STRONG);

        layoutElement.addAttribute("linked-to-layout-uuid", linkedToLayout.getUuid());
      } catch (NoSuchLayoutException nsle) {
      }
    }
  }
  protected void validateLayout(Element actionElement, MDRAction action) {
    String type = action.getType();

    if (!type.equals(SiteRedirectActionHandler.class.getName())) {
      return;
    }

    String layoutUuid = actionElement.attributeValue("layout-uuid");

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

    UnicodeProperties typeSettingsProperties = action.getTypeSettingsProperties();

    long groupId = GetterUtil.getLong(typeSettingsProperties.getProperty("groupId"));
    boolean privateLayout = GetterUtil.getBoolean(actionElement.attributeValue("private-layout"));

    try {
      Layout layout =
          _layoutLocalService.getLayoutByUuidAndGroupId(layoutUuid, groupId, privateLayout);

      typeSettingsProperties.setProperty("plid", String.valueOf(layout.getPlid()));
    } catch (Exception e) {
      if (_log.isWarnEnabled()) {
        StringBundler sb = new StringBundler(5);

        sb.append("Unable to find layout with uuid ");
        sb.append(layoutUuid);
        sb.append(" in group ");
        sb.append(groupId);
        sb.append(". Site redirect may not match the target layout.");

        _log.warn(sb.toString(), e);
      }
    }
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, MDRAction action)
      throws Exception {

    MDRRuleGroupInstance ruleGroupInstance =
        _mdrRuleGroupInstanceLocalService.getRuleGroupInstance(action.getRuleGroupInstanceId());

    StagedModelDataHandlerUtil.exportReferenceStagedModel(
        portletDataContext, action, ruleGroupInstance, PortletDataContext.REFERENCE_TYPE_PARENT);

    Element actionElement = portletDataContext.getExportDataElement(action);

    String type = action.getType();

    if (type.equals(SiteRedirectActionHandler.class.getName())) {
      UnicodeProperties typeSettingsProperties = action.getTypeSettingsProperties();

      long plid = GetterUtil.getLong(typeSettingsProperties.getProperty("plid"));

      try {
        Layout layout = _layoutLocalService.getLayout(plid);

        actionElement.addAttribute("layout-uuid", layout.getUuid());
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(
              "Unable to set the layout uuid of layout "
                  + plid
                  + ". Site redirect may not match after import.",
              e);
        }
      }
    }

    portletDataContext.addClassedModel(
        actionElement, ExportImportPathUtil.getModelPath(action), action);
  }
  protected Object[] extractFriendlyURLInfo(Layout layout) {
    if (!layout.isTypeURL()) {
      return null;
    }

    UnicodeProperties typeSettings = layout.getTypeSettingsProperties();

    String url = GetterUtil.getString(typeSettings.getProperty("url"));

    String friendlyURLPrivateGroupPath =
        PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING;
    String friendlyURLPrivateUserPath =
        PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING;
    String friendlyURLPublicPath = PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING;

    if (!url.startsWith(friendlyURLPrivateGroupPath)
        && !url.startsWith(friendlyURLPrivateUserPath)
        && !url.startsWith(friendlyURLPublicPath)) {

      return null;
    }

    int x = url.indexOf(CharPool.SLASH, 1);

    if (x == -1) {
      return null;
    }

    int y = url.indexOf(CharPool.SLASH, x + 1);

    if (y == -1) {
      return null;
    }

    return new Object[] {url.substring(x, y), url, x, y};
  }
Exemplo n.º 26
0
  protected LinkedHashMap<String, Object> getUserParams(long companyId, String keywords) {

    LinkedHashMap<String, Object> userParams = new LinkedHashMap<String, Object>();

    ExpandoBridge expandoBridge =
        ExpandoBridgeFactoryUtil.getExpandoBridge(companyId, User.class.getName());

    Enumeration<String> enu = expandoBridge.getAttributeNames();

    while (enu.hasMoreElements()) {
      String attributeName = enu.nextElement();

      UnicodeProperties properties = expandoBridge.getAttributeProperties(attributeName);

      int indexType =
          GetterUtil.getInteger(properties.getProperty(ExpandoColumnConstants.INDEX_TYPE));

      if (indexType != ExpandoColumnConstants.INDEX_TYPE_NONE) {
        userParams.put(attributeName, keywords);
      }
    }

    return userParams;
  }
  /**
   * Returns an export layout settings map if the type is {@link
   * ExportImportConfigurationConstants#TYPE_EXPORT_LAYOUT}; otherwise, returns either a local or
   * remote publish layout settings map, depending on the staging type.
   *
   * @param portletRequest the portlet request
   * @param groupId the primary key of the group
   * @param type the export/import option type
   * @return an export layout settings map if the type is an export layout; otherwise, returns
   *     either a local or remote publish layout settings map, depending on the staging type
   */
  public static Map<String, Serializable> buildSettingsMap(
      PortletRequest portletRequest, long groupId, int type) throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    boolean privateLayout = ParamUtil.getBoolean(portletRequest, "privateLayout");

    Map<Long, Boolean> layoutIdMap = ExportImportHelperUtil.getLayoutIdMap(portletRequest);

    if (type == ExportImportConfigurationConstants.TYPE_EXPORT_LAYOUT) {
      long[] layoutIds = ExportImportHelperUtil.getLayoutIds(layoutIdMap);

      return buildExportLayoutSettingsMap(
          themeDisplay.getUserId(),
          groupId,
          privateLayout,
          layoutIds,
          portletRequest.getParameterMap(),
          themeDisplay.getLocale(),
          themeDisplay.getTimeZone());
    }

    Group stagingGroup = GroupLocalServiceUtil.getGroup(groupId);

    Group liveGroup = stagingGroup.getLiveGroup();

    Map<String, String[]> parameterMap =
        ExportImportConfigurationParameterMapFactory.buildParameterMap(portletRequest);

    if (liveGroup != null) {
      long[] layoutIds = ExportImportHelperUtil.getLayoutIds(layoutIdMap, liveGroup.getGroupId());

      return buildPublishLayoutLocalSettingsMap(
          themeDisplay.getUserId(),
          stagingGroup.getGroupId(),
          liveGroup.getGroupId(),
          privateLayout,
          layoutIds,
          parameterMap,
          themeDisplay.getLocale(),
          themeDisplay.getTimeZone());
    }

    UnicodeProperties groupTypeSettingsProperties = stagingGroup.getTypeSettingsProperties();

    String remoteAddress =
        ParamUtil.getString(
            portletRequest,
            "remoteAddress",
            groupTypeSettingsProperties.getProperty("remoteAddress"));

    remoteAddress = StagingUtil.stripProtocolFromRemoteAddress(remoteAddress);

    int remotePort =
        ParamUtil.getInteger(
            portletRequest,
            "remotePort",
            GetterUtil.getInteger(groupTypeSettingsProperties.getProperty("remotePort")));
    String remotePathContext =
        ParamUtil.getString(
            portletRequest,
            "remotePathContext",
            groupTypeSettingsProperties.getProperty("remotePathContext"));
    boolean secureConnection =
        ParamUtil.getBoolean(
            portletRequest,
            "secureConnection",
            GetterUtil.getBoolean(groupTypeSettingsProperties.getProperty("secureConnection")));
    long remoteGroupId =
        ParamUtil.getLong(
            portletRequest,
            "remoteGroupId",
            GetterUtil.getLong(groupTypeSettingsProperties.getProperty("remoteGroupId")));
    boolean remotePrivateLayout = ParamUtil.getBoolean(portletRequest, "remotePrivateLayout");

    StagingUtil.validateRemote(
        groupId, remoteAddress, remotePort, remotePathContext, secureConnection, remoteGroupId);

    return buildPublishLayoutRemoteSettingsMap(
        themeDisplay.getUserId(),
        groupId,
        privateLayout,
        layoutIdMap,
        parameterMap,
        remoteAddress,
        remotePort,
        remotePathContext,
        secureConnection,
        remoteGroupId,
        remotePrivateLayout,
        themeDisplay.getLocale(),
        themeDisplay.getTimeZone());
  }
Exemplo n.º 28
0
  protected void addURLElement(
      Element element,
      String url,
      UnicodeProperties typeSettingsProperties,
      Date modifiedDate,
      String canonicalURL,
      Map<Locale, String> alternateURLs) {

    Element urlElement = element.addElement("url");

    Element locElement = urlElement.addElement("loc");

    locElement.addText(encodeXML(url));

    if (typeSettingsProperties == null) {
      if (Validator.isNotNull(PropsValues.SITES_SITEMAP_DEFAULT_CHANGE_FREQUENCY)) {

        Element changefreqElement = urlElement.addElement("changefreq");

        changefreqElement.addText(PropsValues.SITES_SITEMAP_DEFAULT_CHANGE_FREQUENCY);
      }

      if (Validator.isNotNull(PropsValues.SITES_SITEMAP_DEFAULT_PRIORITY)) {

        Element priorityElement = urlElement.addElement("priority");

        priorityElement.addText(PropsValues.SITES_SITEMAP_DEFAULT_PRIORITY);
      }
    } else {
      String changefreq = typeSettingsProperties.getProperty("sitemap-changefreq");

      if (Validator.isNotNull(changefreq)) {
        Element changefreqElement = urlElement.addElement("changefreq");

        changefreqElement.addText(changefreq);
      } else if (Validator.isNotNull(PropsValues.SITES_SITEMAP_DEFAULT_CHANGE_FREQUENCY)) {

        Element changefreqElement = urlElement.addElement("changefreq");

        changefreqElement.addText(PropsValues.SITES_SITEMAP_DEFAULT_CHANGE_FREQUENCY);
      }

      String priority = typeSettingsProperties.getProperty("sitemap-priority");

      if (Validator.isNotNull(priority)) {
        Element priorityElement = urlElement.addElement("priority");

        priorityElement.addText(priority);
      } else if (Validator.isNotNull(PropsValues.SITES_SITEMAP_DEFAULT_PRIORITY)) {

        Element priorityElement = urlElement.addElement("priority");

        priorityElement.addText(PropsValues.SITES_SITEMAP_DEFAULT_PRIORITY);
      }
    }

    if (modifiedDate != null) {
      Element modifiedDateElement = urlElement.addElement("lastmod");

      DateFormat iso8601DateFormat = DateUtil.getISO8601Format();

      modifiedDateElement.addText(iso8601DateFormat.format(modifiedDate));
    }

    if (alternateURLs != null) {
      for (Map.Entry<Locale, String> entry : alternateURLs.entrySet()) {
        Locale locale = entry.getKey();
        String href = entry.getValue();

        Element alternateURLElement =
            urlElement.addElement("xhtml:link", "http://www.w3.org/1999/xhtml");

        alternateURLElement.addAttribute("href", href);
        alternateURLElement.addAttribute("hreflang", LocaleUtil.toW3cLanguageId(locale));
        alternateURLElement.addAttribute("rel", "alternate");
      }

      Element alternateURLElement =
          urlElement.addElement("xhtml:link", "http://www.w3.org/1999/xhtml");

      alternateURLElement.addAttribute("rel", "alternate");
      alternateURLElement.addAttribute("hreflang", "x-default");
      alternateURLElement.addAttribute("href", canonicalURL);
    }
  }
Exemplo n.º 29
0
  @Override
  public String getTypeSettingsProperty(String key, String defaultValue) {
    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();

    return typeSettingsProperties.getProperty(key, defaultValue);
  }
Exemplo n.º 30
0
  @Override
  public String getTypeSettingsProperty(String key) {
    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();

    return typeSettingsProperties.getProperty(key);
  }