private void _buildPortletBreadcrumb(HttpServletRequest request, StringBundler sb)
      throws Exception {
    List<KeyValuePair> portletBreadcrumbList = PortalUtil.getPortletBreadcrumbList(request);

    if (portletBreadcrumbList == null) {
      return;
    }

    for (KeyValuePair kvp : portletBreadcrumbList) {
      String breadcrumbText = kvp.getKey();
      String breadcrumbURL = kvp.getValue();

      sb.append("<li><span>");

      if (Validator.isNotNull(breadcrumbURL)) {
        sb.append("<a href=\"");
        sb.append(HtmlUtil.escape(breadcrumbURL));
        sb.append("\">");
      }

      sb.append(HtmlUtil.escape(breadcrumbText));

      if (Validator.isNotNull(breadcrumbURL)) {
        sb.append("</a>");
      }

      sb.append("</span></li>");
    }
  }
  public ViewPerformanceAppraisalLevels toEscapedModel() {
    if (isEscapedModel()) {
      return (ViewPerformanceAppraisalLevels) this;
    } else {
      ViewPerformanceAppraisalLevels model = new ViewPerformanceAppraisalLevelsImpl();

      model.setNew(isNew());
      model.setEscapedModel(true);

      model.setId(HtmlUtil.escape(getId()));
      model.setLevelId(getLevelId());
      model.setNumberOrder(getNumberOrder());
      model.setCompetencyId(getCompetencyId());
      model.setRootId(getRootId());
      model.setLevelName(HtmlUtil.escape(getLevelName()));
      model.setPaId(getPaId());
      model.setUserId(getUserId());
      model.setPeriodId(getPeriodId());
      model.setTotalLevelPoint(getTotalLevelPoint());
      model.setIsPassed(getIsPassed());

      model =
          (ViewPerformanceAppraisalLevels)
              Proxy.newProxyInstance(
                  ViewPerformanceAppraisalLevels.class.getClassLoader(),
                  new Class[] {ViewPerformanceAppraisalLevels.class},
                  new ReadOnlyBeanHandler(model));

      return model;
    }
  }
  @Override
  public String getScopeDescriptiveName(ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    if (getGroupId() == themeDisplay.getScopeGroupId()) {
      StringBundler sb = new StringBundler(5);

      sb.append(themeDisplay.translate("current-site"));
      sb.append(StringPool.SPACE);
      sb.append(StringPool.OPEN_PARENTHESIS);
      sb.append(HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
      sb.append(StringPool.CLOSE_PARENTHESIS);

      return sb.toString();
    } else if (isLayout() && (getClassPK() == themeDisplay.getPlid())) {
      StringBundler sb = new StringBundler(5);

      sb.append(themeDisplay.translate("current-page"));
      sb.append(StringPool.SPACE);
      sb.append(StringPool.OPEN_PARENTHESIS);
      sb.append(HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
      sb.append(StringPool.CLOSE_PARENTHESIS);

      return sb.toString();
    } else if (isLayoutPrototype()) {
      return themeDisplay.translate("default");
    } else {
      return HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale()));
    }
  }
  public LmisViewStaffRootOrg toEscapedModel() {
    if (isEscapedModel()) {
      return this;
    } else {
      LmisViewStaffRootOrg model = new LmisViewStaffRootOrgClp();

      model.setEscapedModel(true);

      model.setUser_id(getUser_id());
      model.setRootId(getRootId());
      model.setOrgId(getOrgId());
      model.setBodId(getBodId());
      model.setScreenName(HtmlUtil.escape(getScreenName()));
      model.setEmailAddress(HtmlUtil.escape(getEmailAddress()));

      model =
          (LmisViewStaffRootOrg)
              Proxy.newProxyInstance(
                  LmisViewStaffRootOrg.class.getClassLoader(),
                  new Class[] {LmisViewStaffRootOrg.class},
                  new ReadOnlyBeanHandler(model));

      return model;
    }
  }
  @Override
  protected String getBody(SocialActivity activity, ServiceContext serviceContext)
      throws Exception {

    String link = getLink(activity, serviceContext);

    String text = StringPool.BLANK;

    int activityType = activity.getType();

    if (activityType == JIRAActivityKeys.ADD_CHANGE) {
      JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(activity.getExtraData());

      text =
          interpretJIRAChangeItems(
              extraDataJSONObject.getJSONArray("jiraChangeItems"), serviceContext);
    } else if (activityType == JIRAActivityKeys.ADD_COMMENT) {
      long jiraActionId = GetterUtil.getLong(getJSONValue(activity.getExtraData(), "jiraActionId"));

      JIRAAction jiraAction = JIRAActionLocalServiceUtil.getJIRAAction(jiraActionId);

      text = HtmlUtil.escape(jiraAction.getBody());
    } else if (activityType == JIRAActivityKeys.ADD_ISSUE) {
      JIRAIssue jiraIssue = JIRAIssueLocalServiceUtil.getJIRAIssue(activity.getClassPK());

      text = HtmlUtil.escape(jiraIssue.getSummary());
    }

    return wrapLink(link, text);
  }
  protected String getWindowJS(PortletRequest portletRequest, JournalArticle article) {

    StringBundler sb = new StringBundler(13);

    sb.append("Liferay.Util.Window.getWindow({bodyCssClass: ");
    sb.append("'dialog-with-footer', destroyOnHide: true, dialog: ");
    sb.append(getDialogJS(article));
    sb.append(", id: '");

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

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    sb.append(HtmlUtil.escape(portletDisplay.getNamespace()));
    sb.append("viewSource', namespace: '");
    sb.append(portletDisplay.getNamespace());
    sb.append("', portlet: '#p_p_id_");
    sb.append(portletDisplay.getId());
    sb.append("_', portletId: '");
    sb.append(portletDisplay.getId());
    sb.append("', title: '");
    sb.append(HtmlUtil.escapeJS(HtmlUtil.escape(article.getTitle(themeDisplay.getLocale()))));
    sb.append("'});");

    return sb.toString();
  }
  @Override
  protected String getTitle(
      JSONObject jsonObject, AssetRenderer<?> assetRenderer, ServiceContext serviceContext) {

    MBMessage mbMessage = MBMessageLocalServiceUtil.fetchMBMessage(jsonObject.getLong("classPK"));

    AssetRendererFactory<?> assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
            assetRenderer.getClassName());

    String typeName = assetRendererFactory.getTypeName(serviceContext.getLocale());

    ResourceBundle resourceBundle =
        ResourceBundle.getBundle("content.Language", serviceContext.getLocale());

    if ((mbMessage != null) && mbMessage.isDiscussion()) {
      return LanguageUtil.format(
          resourceBundle,
          "x-mentioned-you-in-a-comment-in-a-x",
          new String[] {
            HtmlUtil.escape(assetRenderer.getUserName()),
            StringUtil.toLowerCase(HtmlUtil.escape(typeName))
          },
          false);
    } else {
      return LanguageUtil.format(
          resourceBundle,
          "x-mentioned-you-in-a-x",
          new String[] {
            HtmlUtil.escape(assetRenderer.getUserName()),
            StringUtil.toLowerCase(HtmlUtil.escape(typeName))
          },
          false);
    }
  }
Пример #8
0
  /** @deprecated As of 6.2.0, replaced by {@link #getUserName(long, ServiceContext)} */
  protected String getUserName(long userId, ThemeDisplay themeDisplay) {
    try {
      if (userId <= 0) {
        return StringPool.BLANK;
      }

      User user = UserLocalServiceUtil.getUserById(userId);

      if (user.getUserId() == themeDisplay.getUserId()) {
        return HtmlUtil.escape(user.getFirstName());
      }

      String userName = user.getFullName();

      Group group = user.getGroup();

      if (group.getGroupId() == themeDisplay.getScopeGroupId()) {
        return HtmlUtil.escape(userName);
      }

      String userDisplayURL = user.getDisplayURL(themeDisplay);

      userName =
          "******"user\" href=\"" + userDisplayURL + "\">" + HtmlUtil.escape(userName) + "</a>";

      return userName;
    } catch (Exception e) {
      return StringPool.BLANK;
    }
  }
  @Before
  public void setUp() {
    HtmlUtil htmlUtil = new HtmlUtil();

    htmlUtil.setHtml(new HtmlImpl());

    _wikiServiceSettingsProvider = CreoleTestUtil.getWikiSettingsProvider();
  }
Пример #10
0
  protected void getRootFolders(CommandArgument argument, Document doc, Element foldersEl)
      throws Exception {

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

    groupParams.put("usersGroups", new Long(argument.getUserId()));

    List<Group> groups =
        GroupLocalServiceUtil.search(
            argument.getCompanyId(), null, null, groupParams, QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    List<Organization> userOrgs =
        OrganizationLocalServiceUtil.getUserOrganizations(argument.getUserId(), true);

    for (Organization organization : userOrgs) {
      groups.add(0, organization.getGroup());
    }

    if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED
        || PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) {

      Group userGroup =
          GroupLocalServiceUtil.getUserGroup(argument.getCompanyId(), argument.getUserId());

      groups.add(0, userGroup);
    }

    ThemeDisplay themeDisplay = argument.getThemeDisplay();

    long scopeGroupId = themeDisplay.getScopeGroupId();

    for (Group group : groups) {
      Element folderEl = doc.createElement("Folder");

      foldersEl.appendChild(folderEl);

      boolean setNameAttribute = false;

      if (group.hasStagingGroup()) {
        Group stagingGroup = group.getStagingGroup();

        if (stagingGroup.getGroupId() == scopeGroupId) {
          folderEl.setAttribute(
              "name",
              stagingGroup.getGroupId()
                  + " - "
                  + HtmlUtil.escape(stagingGroup.getDescriptiveName()));

          setNameAttribute = true;
        }
      }

      if (!setNameAttribute) {
        folderEl.setAttribute(
            "name", group.getGroupId() + " - " + HtmlUtil.escape(group.getDescriptiveName()));
      }
    }
  }
Пример #11
0
  protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay)
      throws Exception {

    String creatorUserName = getUserName(activity.getUserId(), themeDisplay);
    String receiverUserName = getUserName(activity.getReceiverUserId(), themeDisplay);

    User receiverUser = UserLocalServiceUtil.getUserById(activity.getReceiverUserId());

    if (!SocialRelationLocalServiceUtil.hasRelation(
            themeDisplay.getUserId(),
            activity.getReceiverUserId(),
            SocialRelationConstants.TYPE_BI_FRIEND)
        && (themeDisplay.getUserId() != activity.getReceiverUserId())) {

      return null;
    }

    int activityType = activity.getType();

    // Link

    WallEntry wallEntry = WallEntryLocalServiceUtil.getWallEntry(activity.getClassPK());

    String link =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathFriendlyURLPublic()
            + StringPool.SLASH
            + HtmlUtil.escapeURL(receiverUser.getScreenName())
            + "/profile/-/wall/"
            + activity.getClassPK();

    // Title

    String title = StringPool.BLANK;

    if (activityType == WallActivityKeys.ADD_ENTRY) {
      title =
          themeDisplay.translate(
              "activity-social-networking-wall-add-entry",
              new Object[] {creatorUserName, receiverUserName});
    }

    // Body

    StringBuilder sb = new StringBuilder();

    sb.append("<a href=\"");
    sb.append(link);
    sb.append("\">");
    sb.append(HtmlUtil.escape(cleanContent(wallEntry.getComments())));
    sb.append("</a>");

    String body = sb.toString();

    return new SocialActivityFeedEntry(link, title, body);
  }
  protected String getDialogJS(JournalArticle article) {
    StringBundler sb = new StringBundler(6);

    sb.append("{bodyContent: '<pre>");
    sb.append(HtmlUtil.escapeJS(HtmlUtil.escape(article.getContent())));
    sb.append("</pre>', modal: true, toolbars: {footer: ");
    sb.append("[{label:Liferay.Language.get('close'), on: {click: ");
    sb.append("function(event) {event.domEvent.preventDefault(); ");
    sb.append("sourceModal.hide();}}}]}}");

    return sb.toString();
  }
  protected void compareVersions(RenderRequest renderRequest) throws Exception {

    long fileEntryId = ParamUtil.getLong(renderRequest, "fileEntryId");

    String sourceVersion = ParamUtil.getString(renderRequest, "sourceVersion");
    String targetVersion = ParamUtil.getString(renderRequest, "targetVersion");

    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);

    String extension = fileEntry.getExtension();

    FileVersion sourceFileVersion = fileEntry.getFileVersion(sourceVersion);

    String sourceTitle = sourceFileVersion.getTitle();

    FileVersion targetFileVersion = fileEntry.getFileVersion(targetVersion);

    String targetTitle = targetFileVersion.getTitle();

    InputStream sourceIs = fileEntry.getContentStream(sourceVersion);
    InputStream targetIs = fileEntry.getContentStream(targetVersion);

    if (extension.equals("htm") || extension.equals("html") || extension.equals("xml")) {

      String escapedSource = HtmlUtil.escape(StringUtil.read(sourceIs));
      String escapedTarget = HtmlUtil.escape(StringUtil.read(targetIs));

      sourceIs = new UnsyncByteArrayInputStream(escapedSource.getBytes(StringPool.UTF8));
      targetIs = new UnsyncByteArrayInputStream(escapedTarget.getBytes(StringPool.UTF8));
    }

    if (DocumentConversionUtil.isEnabled()
        && DocumentConversionUtil.isConvertBeforeCompare(extension)) {

      String sourceTempFileId = DLUtil.getTempFileId(fileEntryId, sourceVersion);
      String targetTempFileId = DLUtil.getTempFileId(fileEntryId, targetVersion);

      sourceIs =
          new FileInputStream(
              DocumentConversionUtil.convert(sourceTempFileId, sourceIs, extension, "txt"));
      targetIs =
          new FileInputStream(
              DocumentConversionUtil.convert(targetTempFileId, targetIs, extension, "txt"));
    }

    List<DiffResult>[] diffResults =
        DiffUtil.diff(new InputStreamReader(sourceIs), new InputStreamReader(targetIs));

    renderRequest.setAttribute(WebKeys.SOURCE_NAME, sourceTitle + StringPool.SPACE + sourceVersion);
    renderRequest.setAttribute(WebKeys.TARGET_NAME, targetTitle + StringPool.SPACE + targetVersion);
    renderRequest.setAttribute(WebKeys.DIFF_RESULTS, diffResults);
  }
  public void visit(LinkNode linkNode) {
    append("<a href=\"");
    append(HtmlUtil.escape(linkNode.getLink()));
    append("\">");

    if (linkNode.hasAltCollectionNode()) {
      CollectionNode altCollectionNode = linkNode.getAltCollectionNode();

      traverse(altCollectionNode.getASTNodes());
    } else {
      append(HtmlUtil.escape(linkNode.getLink()));
    }

    append("</a>");
  }
  @Override
  public Object invoke(Object proxy, Method method, Object[] arguments) throws Throwable {

    String methodName = method.getName();

    if (methodName.startsWith("set")) {
      throw new IllegalAccessException("Setter methods cannot be called on an escaped bean");
    }

    if (methodName.endsWith("isEscapedModel")) {
      return true;
    } else if (methodName.endsWith("toEscapedModel")) {
      return proxy;
    }

    Object result = null;

    try {
      result = method.invoke(_bean, arguments);
    } catch (InvocationTargetException ite) {
      throw ite.getTargetException();
    }

    if (method.getAnnotation(AutoEscape.class) != null) {
      result = HtmlUtil.escape((String) result);
    }

    return result;
  }
 public void visit(FormattedTextNode formattedTextNode) {
   if (formattedTextNode.getContent() != null) {
     append(HtmlUtil.escape(formattedTextNode.getContent()));
   } else {
     traverse(formattedTextNode.getChildASTNodes());
   }
 }
 public void visit(UnformattedTextNode unformattedTextNode) {
   if (unformattedTextNode.hasContent()) {
     append(HtmlUtil.escape(unformattedTextNode.getContent()));
   } else {
     traverse(unformattedTextNode.getChildASTNodes());
   }
 }
  public CdsPerformanceAppraisalSlotComments toEscapedModel() {
    if (isEscapedModel()) {
      return (CdsPerformanceAppraisalSlotComments) this;
    } else {
      CdsPerformanceAppraisalSlotComments model = new CdsPerformanceAppraisalSlotCommentsImpl();

      model.setNew(isNew());
      model.setEscapedModel(true);

      model.setCdsPerformanceAppraisalSlotCommentsId(getCdsPerformanceAppraisalSlotCommentsId());
      model.setPaId(getPaId());
      model.setRootId(getRootId());
      model.setPeriodId(getPeriodId());
      model.setUserId(getUserId());
      model.setSlotId(getSlotId());
      model.setCommentBy(getCommentBy());
      model.setCommentAt(getCommentAt());
      model.setCommentContent(HtmlUtil.escape(getCommentContent()));

      model =
          (CdsPerformanceAppraisalSlotComments)
              Proxy.newProxyInstance(
                  CdsPerformanceAppraisalSlotComments.class.getClassLoader(),
                  new Class[] {CdsPerformanceAppraisalSlotComments.class},
                  new ReadOnlyBeanHandler(model));

      return model;
    }
  }
  public KBArticleMarkdownConverter(
      String markdown, String fileEntryName, Map<String, String> metadata)
      throws KBArticleImportException {

    MarkdownConverter markdownConverter = MarkdownConverterFactoryUtil.create();

    String html = null;

    try {
      html = markdownConverter.convert(markdown);
    } catch (IOException ioe) {
      throw new KBArticleImportException(
          "Unable to convert Markdown to HTML: " + ioe.getLocalizedMessage(), ioe);
    }

    String heading = getHeading(html);

    if (Validator.isNull(heading)) {
      throw new KBArticleImportException(
          "Unable to extract title heading from file: " + fileEntryName);
    }

    _urlTitle = getUrlTitle(heading);

    _title = HtmlUtil.unescape(stripIds(heading));

    html = stripIds(html);

    _html = stripHeading(html);

    String baseSourceURL = metadata.get(_METADATA_BASE_SOURCE_URL);

    _sourceURL = buildSourceURL(baseSourceURL, fileEntryName);
  }
Пример #20
0
  protected String getId() {
    if (Validator.isNotNull(_id)) {
      return _id;
    }

    String id = (String) request.getAttribute("liferay-ui:icon-menu:id");

    String message = _message;

    if (Validator.isNull(message)) {
      message = _image;
    }

    if (Validator.isNotNull(id) && Validator.isNotNull(message)) {
      id = id.concat(StringPool.UNDERLINE).concat(FriendlyURLNormalizerUtil.normalize(message));

      PortletResponse portletResponse =
          (PortletResponse) request.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);

      String namespace = StringPool.BLANK;

      if (portletResponse != null) {
        namespace = portletResponse.getNamespace();
      }

      id = PortalUtil.getUniqueElementId(getOriginalServletRequest(), namespace, id);
    } else {
      id = PortalUtil.generateRandomKey(request, IconTag.class.getName());
    }

    id = HtmlUtil.getAUICompatibleId(id);

    return id;
  }
  protected String sanitize(String message, String defaultResult) {
    if (message == null) {
      return null;
    }

    char[] chars = message.toCharArray();
    boolean sanitized = false;

    for (int i = 0; i < chars.length; i++) {
      int c = chars[i];

      if ((c >= 0) && (c < _whitelistCharacters.length) && (_whitelistCharacters[c] == 0)) {

        chars[i] = _LOG_SANITIZER_REPLACEMENT_CHARACTER;
        sanitized = true;
      }
    }

    if (sanitized) {
      String sanitizedMessage = new String(chars);

      sanitizedMessage = sanitizedMessage.concat(_SANITIZED);

      if (_LOG_SANITIZER_ESCAPE_HTML_ENABLED) {
        return HtmlUtil.escape(sanitizedMessage);
      }

      return sanitizedMessage;
    }

    return defaultResult;
  }
  public CdsPerformanceAppraisalSlotRating toEscapedModel() {
    if (isEscapedModel()) {
      return (CdsPerformanceAppraisalSlotRating) this;
    } else {
      CdsPerformanceAppraisalSlotRating model = new CdsPerformanceAppraisalSlotRatingImpl();

      model.setNew(isNew());
      model.setEscapedModel(true);

      model.setCdsPerformanceAppraisalSlotRatingId(getCdsPerformanceAppraisalSlotRatingId());
      model.setPaId(getPaId());
      model.setRootId(getRootId());
      model.setPeriodId(getPeriodId());
      model.setUserId(getUserId());
      model.setSlotId(getSlotId());
      model.setRatingBy(getRatingBy());
      model.setRatingAt(getRatingAt());
      model.setRatingStatus(getRatingStatus());
      model.setUserType(getUserType());
      model.setPointName(HtmlUtil.escape(getPointName()));
      model.setPointValue(getPointValue());
      model.setRatingOrgId(getRatingOrgId());

      model =
          (CdsPerformanceAppraisalSlotRating)
              Proxy.newProxyInstance(
                  CdsPerformanceAppraisalSlotRating.class.getClassLoader(),
                  new Class[] {CdsPerformanceAppraisalSlotRating.class},
                  new ReadOnlyBeanHandler(model));

      return model;
    }
  }
  public LmisWorkingTimes toEscapedModel() {
    if (isEscapedModel()) {
      return (LmisWorkingTimes) this;
    } else {
      LmisWorkingTimes model = new LmisWorkingTimesImpl();

      model.setNew(isNew());
      model.setEscapedModel(true);

      model.setLmisWorkingTimeId(getLmisWorkingTimeId());
      model.setRootId(getRootId());
      model.setSessionName(HtmlUtil.escape(getSessionName()));
      model.setStartTime(getStartTime());
      model.setEndTime(getEndTime());
      model.setLimitLate(getLimitLate());
      model.setMaxLate(getMaxLate());
      model.setCoefficientLate(getCoefficientLate());
      model.setLimitEarly(getLimitEarly());
      model.setMaxEarly(getMaxEarly());
      model.setCoefficientEarly(getCoefficientEarly());

      model =
          (LmisWorkingTimes)
              Proxy.newProxyInstance(
                  LmisWorkingTimes.class.getClassLoader(),
                  new Class[] {LmisWorkingTimes.class},
                  new ReadOnlyBeanHandler(model));

      return model;
    }
  }
  protected boolean isValidStructureField(long groupId, String structureId, String contentField) {

    if (contentField.equals(JournalFeedConstants.WEB_CONTENT_DESCRIPTION)
        || contentField.equals(JournalFeedConstants.RENDERED_WEB_CONTENT)) {

      return true;
    }

    try {
      DDMStructure ddmStructure =
          ddmStructureLocalService.getStructure(
              groupId, classNameLocalService.getClassNameId(JournalArticle.class), structureId);

      Document document = SAXReaderUtil.read(ddmStructure.getXsd());

      contentField = HtmlUtil.escapeXPathAttribute(contentField);

      XPath xPathSelector =
          SAXReaderUtil.createXPath("//dynamic-element[@name=" + contentField + "]");

      Node node = xPathSelector.selectSingleNode(document);

      if (node != null) {
        return true;
      }
    } catch (Exception e) {
      _log.error(e, e);
    }

    return false;
  }
Пример #25
0
  @Override
  public String process(ResourceBundle resourceBundle, Locale locale, String content) {

    StringBundler sb = new StringBundler();

    Matcher matcher = _pattern.matcher(content);

    int x = 0;

    while (matcher.find()) {
      int y = matcher.start(0);

      String key = matcher.group(1);

      sb.append(content.substring(x, y));
      sb.append(StringPool.APOSTROPHE);

      String value = get(resourceBundle, key);

      sb.append(HtmlUtil.escapeJS(value));
      sb.append(StringPool.APOSTROPHE);

      x = matcher.end(0);
    }

    sb.append(content.substring(x));

    return sb.toString();
  }
  @Override
  public String getRestoreLink(PortletRequest portletRequest, long classPK)
      throws PortalException, SystemException {

    String portletId = PortletKeys.WIKI;

    WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

    long plid = PortalUtil.getPlidFromPortletId(page.getGroupId(), PortletKeys.WIKI);

    if (plid == LayoutConstants.DEFAULT_PLID) {
      plid = PortalUtil.getControlPanelPlid(portletRequest);

      portletId = PortletKeys.WIKI_ADMIN;
    }

    PortletURL portletURL =
        PortletURLFactoryUtil.create(portletRequest, portletId, plid, PortletRequest.RENDER_PHASE);

    WikiNode node = page.getNode();

    portletURL.setParameter("struts_action", "/wiki/view");
    portletURL.setParameter("nodeName", node.getName());
    portletURL.setParameter("title", HtmlUtil.unescape(page.getTitle()));

    return portletURL.toString();
  }
  @Override
  public String getPortletFileEntryURL(
      ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString, boolean absoluteURL) {

    StringBundler sb = new StringBundler(10);

    if (themeDisplay != null) {
      if (absoluteURL) {
        sb.append(themeDisplay.getPortalURL());
      }
    }

    sb.append(PortalUtil.getPathContext());
    sb.append("/documents/");
    sb.append(WebServerServlet.PATH_PORTLET_FILE_ENTRY);
    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getGroupId());
    sb.append(StringPool.SLASH);

    String title = fileEntry.getTitle();

    if (fileEntry.isInTrash()) {
      title = TrashUtil.getOriginalTitle(fileEntry.getTitle());
    }

    sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(title)));

    sb.append(StringPool.SLASH);
    sb.append(HttpUtil.encodeURL(fileEntry.getUuid()));

    if (themeDisplay != null) {
      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      if (portletDisplay != null) {
        String portletId = portletDisplay.getId();

        if (portletId.equals(PortletKeys.TRASH) && !queryString.contains("status=")) {

          if (Validator.isNotNull(queryString)) {
            queryString += StringPool.AMPERSAND;
          }

          queryString += "status=" + WorkflowConstants.STATUS_IN_TRASH;
        }
      }
    }

    if (Validator.isNotNull(queryString)) {
      sb.append(StringPool.QUESTION);
      sb.append(queryString);
    }

    String portletFileEntryURL = sb.toString();

    if ((themeDisplay != null) && themeDisplay.isAddSessionIdToURL()) {
      return PortalUtil.getURLWithSessionId(portletFileEntryURL, themeDisplay.getSessionId());
    }

    return portletFileEntryURL;
  }
  protected String getDDMContentSummary(
      Document document,
      Locale snippetLocale,
      PortletRequest portletRequest,
      PortletResponse portletResponse) {

    String content = StringPool.BLANK;

    if ((portletRequest == null) || (portletResponse == null)) {
      return content;
    }

    try {
      String articleId = document.get(Field.ARTICLE_ID);
      long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
      double version = GetterUtil.getDouble(document.get(Field.VERSION));
      PortletRequestModel portletRequestModel =
          new PortletRequestModel(portletRequest, portletResponse);
      ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

      JournalArticleDisplay articleDisplay =
          _journalContent.getDisplay(
              groupId,
              articleId,
              version,
              null,
              Constants.VIEW,
              LocaleUtil.toLanguageId(snippetLocale),
              1,
              portletRequestModel,
              themeDisplay);

      content = articleDisplay.getDescription();

      content = HtmlUtil.replaceNewLine(content);

      if (Validator.isNull(content)) {
        content = HtmlUtil.extractText(articleDisplay.getContent());
      }
    } catch (Exception e) {
      if (_log.isDebugEnabled()) {
        _log.debug(e, e);
      }
    }

    return content;
  }
  @Override
  public String getSearchSummary(Locale locale) {
    if (_message.isFormatBBCode()) {
      return HtmlUtil.extractText(BBCodeTranslatorUtil.getHTML(_message.getBody()));
    }

    return getSummary(null, null);
  }
Пример #30
0
  protected List<Node> getElementsByName(Document document, String name) {
    name = HtmlUtil.escapeXPathAttribute(name);

    XPath xPathSelector =
        SAXReaderUtil.createXPath("//dynamic-element[@name=".concat(name).concat("]"));

    return xPathSelector.selectNodes(document);
  }