public String getDDMStructureName() throws PortalException {
    if (_ddmStructureName != null) {
      return _ddmStructureName;
    }

    _ddmStructureName = LanguageUtil.get(_request, "basic-web-content");

    if (Validator.isNull(getDDMStructureKey())) {
      return _ddmStructureName;
    }

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

    DDMStructure ddmStructure =
        DDMStructureLocalServiceUtil.fetchStructure(
            themeDisplay.getSiteGroupId(),
            PortalUtil.getClassNameId(JournalArticle.class),
            getDDMStructureKey(),
            true);

    if (ddmStructure != null) {
      _ddmStructureName = ddmStructure.getName(themeDisplay.getLocale());
    }

    return _ddmStructureName;
  }
  public void restoreArchivedSetup(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

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

    Settings portletInstanceSettings =
        SettingsFactoryUtil.getSettings(
            new PortletInstanceSettingsLocator(themeDisplay.getLayout(), portlet.getPortletId()));

    ModifiableSettings portletInstanceModifiableSettings =
        portletInstanceSettings.getModifiableSettings();

    String name = ParamUtil.getString(actionRequest, "name");

    ArchivedSettings archivedSettings =
        SettingsFactoryUtil.getPortletInstanceArchivedSettings(
            themeDisplay.getSiteGroupId(), portlet.getRootPortletId(), name);

    portletInstanceModifiableSettings.reset();

    portletInstanceModifiableSettings.setValues(archivedSettings);

    portletInstanceModifiableSettings.store();

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    SessionMessages.add(
        actionRequest,
        PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
        portletResource);
  }
  public void deleteArchivedSetups(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

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

    String[] names = null;

    String name = ParamUtil.getString(actionRequest, "name");

    if (Validator.isNotNull(name)) {
      names = new String[] {name};
    } else {
      names = ParamUtil.getStringValues(actionRequest, "rowIds");
    }

    for (String curName : names) {
      ArchivedSettings archivedSettings =
          SettingsFactoryUtil.getPortletInstanceArchivedSettings(
              themeDisplay.getSiteGroupId(), portlet.getRootPortletId(), curName);

      archivedSettings.delete();
    }
  }
  public AssetEntryQuery(long[] classNameIds, SearchContainer<?> searchContainer) {

    this();

    setClassNameIds(classNameIds);
    _start = searchContainer.getStart();
    _end = searchContainer.getEnd();

    if (Validator.isNotNull(searchContainer.getOrderByCol())) {
      setOrderByCol1(searchContainer.getOrderByCol());
      setOrderByType1(searchContainer.getOrderByType());
    }

    PortletRequest portletRequest = searchContainer.getPortletRequest();

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

    _groupIds = new long[] {themeDisplay.getScopeGroupId()};

    long categoryId = ParamUtil.getLong(portletRequest, "categoryId");

    if (categoryId > 0) {
      _allCategoryIds = new long[] {categoryId};
    }

    String tagName = ParamUtil.getString(portletRequest, "tag");

    if (Validator.isNotNull(tagName)) {
      _allTagIds =
          AssetTagLocalServiceUtil.getTagIds(themeDisplay.getSiteGroupId(), new String[] {tagName});

      _allTagIdsArray = new long[][] {_allTagIds};
    }
  }
Example #5
0
  @Override
  protected boolean isRSSFeedsEnabled(HttpServletRequest request) throws Exception {

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

    BlogsGroupServiceOverriddenConfiguration blogsGroupServiceOverridenConfiguration =
        _configurationProvider.getConfiguration(
            BlogsGroupServiceOverriddenConfiguration.class,
            new GroupServiceSettingsLocator(
                themeDisplay.getSiteGroupId(), BlogsConstants.SERVICE_NAME));

    return blogsGroupServiceOverridenConfiguration.enableRss();
  }
  public Group getGroup() throws PortalException {
    if (_group != null) {
      return _group;
    }

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

    long groupId = ParamUtil.getLong(_request, "groupId", themeDisplay.getSiteGroupId());

    _group = GroupLocalServiceUtil.getGroup(groupId);

    if (_group != null) {
      _group = StagingUtil.getLiveGroup(_group.getGroupId());
    }

    return _group;
  }
  public void updateArchivedSetup(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    Portlet portlet = ActionUtil.getPortlet(actionRequest);

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

    String name = ParamUtil.getString(actionRequest, "name");

    ArchivedSettings archivedSettings =
        SettingsFactoryUtil.getPortletInstanceArchivedSettings(
            themeDisplay.getSiteGroupId(), portlet.getRootPortletId(), name);

    Settings portletInstanceSettings =
        SettingsFactoryUtil.getSettings(
            new PortletInstanceSettingsLocator(themeDisplay.getLayout(), portlet.getPortletId()));

    ModifiableSettings portletInstanceModifiableSettings =
        portletInstanceSettings.getModifiableSettings();

    archivedSettings.setValues(portletInstanceModifiableSettings);

    archivedSettings.store();
  }
  @Override
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    HttpSession session = request.getSession();

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

    String languageId = ParamUtil.getString(request, "languageId");

    Locale locale = LocaleUtil.fromLanguageId(languageId);

    if (LanguageUtil.isAvailableLocale(themeDisplay.getSiteGroupId(), locale)) {

      boolean persistState = ParamUtil.getBoolean(request, "persistState", true);

      if (themeDisplay.isSignedIn() && persistState) {
        User user = themeDisplay.getUser();

        Contact contact = user.getContact();

        AdminUtil.updateUser(
            request,
            user.getUserId(),
            user.getScreenName(),
            user.getEmailAddress(),
            user.getFacebookId(),
            user.getOpenId(),
            languageId,
            user.getTimeZoneId(),
            user.getGreeting(),
            user.getComments(),
            contact.getSmsSn(),
            contact.getFacebookSn(),
            contact.getJabberSn(),
            contact.getSkypeSn(),
            contact.getTwitterSn());
      }

      session.setAttribute(Globals.LOCALE_KEY, locale);

      LanguageUtil.updateCookie(request, response, locale);
    }

    // Send redirect

    String redirect = ParamUtil.getString(request, "redirect");

    String layoutURL = StringPool.BLANK;
    String queryString = StringPool.BLANK;

    int pos = redirect.indexOf(Portal.FRIENDLY_URL_SEPARATOR);

    if (pos == -1) {
      pos = redirect.indexOf(StringPool.QUESTION);
    }

    if (pos != -1) {
      layoutURL = redirect.substring(0, pos);
      queryString = redirect.substring(pos);
    } else {
      layoutURL = redirect;
    }

    Layout layout = themeDisplay.getLayout();

    if (isGroupFriendlyURL(layout.getGroup(), layout, layoutURL, locale)) {
      if (PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 0) {
        redirect = layoutURL;
      } else {
        redirect = PortalUtil.getGroupFriendlyURL(layout.getLayoutSet(), themeDisplay, locale);
      }
    } else {
      if (PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 0) {
        if (themeDisplay.isI18n()) {
          redirect = layout.getFriendlyURL(locale);
        } else {
          redirect = PortalUtil.getLayoutURL(layout, themeDisplay, locale);
        }
      } else {
        redirect = PortalUtil.getLayoutFriendlyURL(layout, themeDisplay, locale);
      }
    }

    if (layout.isTypeControlPanel()) {
      redirect = redirect + queryString;
    }

    response.sendRedirect(redirect);

    return null;
  }
Example #9
0
  protected String doTransform(
      ThemeDisplay themeDisplay,
      Map<String, Object> contextObjects,
      Map<String, String> tokens,
      String viewMode,
      String languageId,
      Document document,
      PortletRequestModel portletRequestModel,
      String script,
      String langType,
      boolean propagateException)
      throws Exception {

    // Setup listeners

    if (_log.isDebugEnabled()) {
      _log.debug("Language " + languageId);
    }

    if (Validator.isNull(viewMode)) {
      viewMode = Constants.VIEW;
    }

    if (_logTokens.isDebugEnabled()) {
      String tokensString = PropertiesUtil.list(tokens);

      _logTokens.debug(tokensString);
    }

    if (_logTransformBefore.isDebugEnabled()) {
      _logTransformBefore.debug(document);
    }

    List<TransformerListener> transformerListeners =
        JournalTransformerListenerRegistryUtil.getTransformerListeners();

    for (TransformerListener transformerListener : transformerListeners) {

      // Modify XML

      if (_logXmlBeforeListener.isDebugEnabled()) {
        _logXmlBeforeListener.debug(document);
      }

      if (transformerListener != null) {
        document = transformerListener.onXml(document, languageId, tokens);

        if (_logXmlAfterListener.isDebugEnabled()) {
          _logXmlAfterListener.debug(document);
        }
      }

      // Modify script

      if (_logScriptBeforeListener.isDebugEnabled()) {
        _logScriptBeforeListener.debug(script);
      }

      if (transformerListener != null) {
        script = transformerListener.onScript(script, document, languageId, tokens);

        if (_logScriptAfterListener.isDebugEnabled()) {
          _logScriptAfterListener.debug(script);
        }
      }
    }

    // Transform

    String output = null;

    if (Validator.isNull(langType)) {
      output = LocalizationUtil.getLocalization(document.asXML(), languageId);
    } else {
      long companyId = 0;
      long companyGroupId = 0;
      long articleGroupId = 0;
      long classNameId = 0;

      if (tokens != null) {
        companyId = GetterUtil.getLong(tokens.get("company_id"));
        companyGroupId = GetterUtil.getLong(tokens.get("company_group_id"));
        articleGroupId = GetterUtil.getLong(tokens.get("article_group_id"));
        classNameId = GetterUtil.getLong(tokens.get(TemplateConstants.CLASS_NAME_ID));
      }

      long scopeGroupId = 0;
      long siteGroupId = 0;

      if (themeDisplay != null) {
        companyId = themeDisplay.getCompanyId();
        companyGroupId = themeDisplay.getCompanyGroupId();
        scopeGroupId = themeDisplay.getScopeGroupId();
        siteGroupId = themeDisplay.getSiteGroupId();
      }

      String templateId = tokens.get("template_id");

      templateId = getTemplateId(templateId, companyId, companyGroupId, articleGroupId);

      Template template = getTemplate(templateId, tokens, languageId, document, script, langType);

      if (contextObjects != null) {
        template.putAll(contextObjects);
      }

      UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();

      try {
        if (document != null) {
          Element rootElement = document.getRootElement();

          List<TemplateNode> templateNodes =
              getTemplateNodes(
                  themeDisplay, rootElement, Long.valueOf(tokens.get("ddm_structure_id")));

          if (templateNodes != null) {
            for (TemplateNode templateNode : templateNodes) {
              template.put(templateNode.getName(), templateNode);
            }
          }

          if (portletRequestModel != null) {
            template.put("request", portletRequestModel.toMap());

            if (langType.equals(TemplateConstants.LANG_TYPE_XSL)) {
              Document requestDocument = SAXReaderUtil.read(portletRequestModel.toXML());

              Element requestElement = requestDocument.getRootElement();

              template.put("xmlRequest", requestElement.asXML());
            }
          } else {
            Element requestElement = rootElement.element("request");

            template.put("request", insertRequestVariables(requestElement));

            if (langType.equals(TemplateConstants.LANG_TYPE_XSL)) {
              template.put("xmlRequest", requestElement.asXML());
            }
          }
        }

        template.put("articleGroupId", articleGroupId);
        template.put("company", getCompany(themeDisplay, companyId));
        template.put("companyId", companyId);
        template.put("device", getDevice(themeDisplay));

        String templatesPath = getTemplatesPath(companyId, articleGroupId, classNameId);

        Locale locale = LocaleUtil.fromLanguageId(languageId);

        template.put("locale", locale);

        template.put("permissionChecker", PermissionThreadLocal.getPermissionChecker());
        template.put("randomNamespace", StringUtil.randomId() + StringPool.UNDERLINE);
        template.put("scopeGroupId", scopeGroupId);
        template.put("siteGroupId", siteGroupId);
        template.put("templatesPath", templatesPath);
        template.put("viewMode", viewMode);

        if (themeDisplay != null) {
          TemplateManager templateManager = TemplateManagerUtil.getTemplateManager(langType);

          HttpServletRequest request = themeDisplay.getRequest();

          templateManager.addTaglibSupport(template, request, themeDisplay.getResponse());
          templateManager.addTaglibTheme(
              template,
              "taglibLiferay",
              request,
              new PipingServletResponse(themeDisplay.getResponse(), unsyncStringWriter));
        }

        // Deprecated variables

        template.put("groupId", articleGroupId);
        template.put("journalTemplatesPath", templatesPath);

        mergeTemplate(template, unsyncStringWriter, propagateException);
      } catch (Exception e) {
        if (e instanceof DocumentException) {
          throw new TransformException("Unable to read XML document", e);
        } else if (e instanceof IOException) {
          throw new TransformException("Error reading template", e);
        } else if (e instanceof TransformException) {
          throw (TransformException) e;
        } else {
          throw new TransformException("Unhandled exception", e);
        }
      }

      output = unsyncStringWriter.toString();
    }

    // Postprocess output

    for (TransformerListener transformerListener : transformerListeners) {

      // Modify output

      if (_logOutputBeforeListener.isDebugEnabled()) {
        _logOutputBeforeListener.debug(output);
      }

      output = transformerListener.onOutput(output, languageId, tokens);

      if (_logOutputAfterListener.isDebugEnabled()) {
        _logOutputAfterListener.debug(output);
      }
    }

    if (_logTransfromAfter.isDebugEnabled()) {
      _logTransfromAfter.debug(output);
    }

    return output;
  }