@Override
  protected Summary doGetSummary(
      Document document,
      Locale locale,
      String snippet,
      PortletURL portletURL,
      PortletRequest portletRequest,
      PortletResponse portletResponse) {

    String title = document.get(Field.TITLE);

    String content = snippet;

    if (Validator.isNull(snippet)) {
      content = document.get(Field.DESCRIPTION);

      if (Validator.isNull(content)) {
        content = StringUtil.shorten(document.get(Field.CONTENT), 200);
      }
    }

    String resourcePrimKey = document.get(Field.ENTRY_CLASS_PK);

    portletURL.setParameter("mvcPath", "/admin/view_article.jsp");
    portletURL.setParameter("resourcePrimKey", resourcePrimKey);

    return new Summary(title, content, portletURL);
  }
  private static void _populateThreadLocalsFromContext(Map<String, Serializable> context) {

    long companyId = GetterUtil.getLong(context.get("companyId"));

    if (companyId > 0) {
      CompanyThreadLocal.setCompanyId(companyId);
    }

    Locale defaultLocale = (Locale) context.get("defaultLocale");

    if (defaultLocale != null) {
      LocaleThreadLocal.setDefaultLocale(defaultLocale);
    }

    long groupId = GetterUtil.getLong(context.get("groupId"));

    if (groupId > 0) {
      GroupThreadLocal.setGroupId(groupId);
    }

    String principalName = GetterUtil.getString(context.get("principalName"));

    if (Validator.isNotNull(principalName)) {
      PrincipalThreadLocal.setName(principalName);
    }

    PermissionChecker permissionChecker = null;

    if (Validator.isNotNull(principalName)) {
      try {
        User user = UserLocalServiceUtil.fetchUser(PrincipalThreadLocal.getUserId());

        permissionChecker = PermissionCheckerFactoryUtil.create(user);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }

    if (permissionChecker != null) {
      PermissionThreadLocal.setPermissionChecker(permissionChecker);
    }

    String principalPassword = GetterUtil.getString(context.get("principalPassword"));

    if (Validator.isNotNull(principalPassword)) {
      PrincipalThreadLocal.setPassword(principalPassword);
    }

    Locale siteDefaultLocale = (Locale) context.get("siteDefaultLocale");

    if (siteDefaultLocale != null) {
      LocaleThreadLocal.setSiteDefaultLocale(siteDefaultLocale);
    }

    Locale themeDisplayLocale = (Locale) context.get("themeDisplayLocale");

    if (themeDisplayLocale != null) {
      LocaleThreadLocal.setThemeDisplayLocale(themeDisplayLocale);
    }
  }
  public String[] getAvailableLanguageIds() {
    Set<String> availableLanguageIds = new TreeSet<String>();

    Map<Locale, String> nameMap = getNameMap();

    for (Map.Entry<Locale, String> entry : nameMap.entrySet()) {
      Locale locale = entry.getKey();
      String value = entry.getValue();

      if (Validator.isNotNull(value)) {
        availableLanguageIds.add(LocaleUtil.toLanguageId(locale));
      }
    }

    Map<Locale, String> descriptionMap = getDescriptionMap();

    for (Map.Entry<Locale, String> entry : descriptionMap.entrySet()) {
      Locale locale = entry.getKey();
      String value = entry.getValue();

      if (Validator.isNotNull(value)) {
        availableLanguageIds.add(LocaleUtil.toLanguageId(locale));
      }
    }

    return availableLanguageIds.toArray(new String[availableLanguageIds.size()]);
  }
  @Test
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    DLFileVersion newDLFileVersion = addDLFileVersion();

    _persistence.clearCache();

    DLFileVersionModelImpl existingDLFileVersionModelImpl =
        (DLFileVersionModelImpl) _persistence.findByPrimaryKey(newDLFileVersion.getPrimaryKey());

    Assert.assertTrue(
        Validator.equals(
            existingDLFileVersionModelImpl.getUuid(),
            existingDLFileVersionModelImpl.getOriginalUuid()));
    Assert.assertEquals(
        existingDLFileVersionModelImpl.getGroupId(),
        existingDLFileVersionModelImpl.getOriginalGroupId());

    Assert.assertEquals(
        existingDLFileVersionModelImpl.getFileEntryId(),
        existingDLFileVersionModelImpl.getOriginalFileEntryId());
    Assert.assertTrue(
        Validator.equals(
            existingDLFileVersionModelImpl.getVersion(),
            existingDLFileVersionModelImpl.getOriginalVersion()));
  }
  @Override
  protected String getTitlePattern(String groupName, SocialActivity activity) {

    int activityType = activity.getType();

    long receiverUserId = activity.getReceiverUserId();

    if (activityType == MBActivityKeys.ADD_MESSAGE) {
      if (receiverUserId == 0) {
        if (Validator.isNull(groupName)) {
          return "activity-message-boards-message-add-message";
        } else {
          return "activity-message-boards-message-add-message-in";
        }
      } else {
        if (Validator.isNull(groupName)) {
          return "activity-message-boards-message-reply-message";
        } else {
          return "activity-message-boards-message-reply-message-in";
        }
      }
    } else if ((activityType == MBActivityKeys.REPLY_MESSAGE) && (receiverUserId > 0)) {

      if (Validator.isNull(groupName)) {
        return "activity-message-boards-message-reply-message";
      } else {
        return "activity-message-boards-message-reply-message-in";
      }
    }

    return null;
  }
  @Override
  protected String getTitlePattern(String groupName, SocialActivity activity) {

    int activityType = activity.getType();

    if (activityType == JournalActivityKeys.ADD_ARTICLE) {
      if (Validator.isNull(groupName)) {
        return "activity-journal-article-add-web-content";
      } else {
        return "activity-journal-article-add-web-content-in";
      }
    } else if (activityType == JournalActivityKeys.UPDATE_ARTICLE) {
      if (Validator.isNull(groupName)) {
        return "activity-journal-article-update-web-content";
      } else {
        return "activity-journal-article-update-web-content-in";
      }
    } else if (activityType == SocialActivityConstants.TYPE_MOVE_TO_TRASH) {
      if (Validator.isNull(groupName)) {
        return "activity-journal-article-move-to-trash";
      } else {
        return "activity-journal-article-move-to-trash-in";
      }
    } else if (activityType == SocialActivityConstants.TYPE_RESTORE_FROM_TRASH) {

      if (Validator.isNull(groupName)) {
        return "activity-journal-article-restore-from-trash";
      } else {
        return "activity-journal-article-restore-from-trash-in";
      }
    }

    return null;
  }
  protected void validate(String name, String description, String xsd) throws PortalException {

    if (Validator.isNull(name)) {
      throw new StructureNameException();
    } else if (Validator.isNull(description)) {
      throw new StructureDescriptionException();
    }

    if (Validator.isNull(xsd)) {
      throw new StructureXsdException();
    } else {
      try {
        Document doc = SAXReaderUtil.read(xsd);

        Element root = doc.getRootElement();

        List<Element> children = root.elements();

        if (children.size() == 0) {
          throw new StructureXsdException();
        }

        Set<String> elNames = new HashSet<String>();

        validate(children, elNames);
      } catch (Exception e) {
        throw new StructureXsdException();
      }
    }
  }
  protected boolean validateUniqueFieldNames(ActionRequest actionRequest) {
    Locale defaultLocale = LocaleUtil.getDefault();

    Set<String> localizedUniqueFieldNames = new HashSet<String>();

    int[] formFieldsIndexes =
        StringUtil.split(ParamUtil.getString(actionRequest, "formFieldsIndexes"), 0);

    for (int formFieldsIndex : formFieldsIndexes) {
      Map<Locale, String> fieldLabelMap =
          LocalizationUtil.getLocalizationMap(actionRequest, "fieldLabel" + formFieldsIndex);

      if (Validator.isNull(fieldLabelMap.get(defaultLocale))) {
        continue;
      }

      for (Locale locale : fieldLabelMap.keySet()) {
        String fieldLabelValue = fieldLabelMap.get(locale);

        if (Validator.isNull(fieldLabelValue)) {
          continue;
        }

        String languageId = LocaleUtil.toLanguageId(locale);

        if (!localizedUniqueFieldNames.add(languageId + "_" + fieldLabelValue)) {

          return false;
        }
      }
    }

    return true;
  }
  private List<ThemeCompanyId> _getCompanyLimitExcludes(Element el) {
    List<ThemeCompanyId> includes = new ArrayList<ThemeCompanyId>();

    if (el != null) {
      List<Element> companyIds = el.elements("company-id");

      for (int i = 0; i < companyIds.size(); i++) {
        Element companyIdEl = companyIds.get(i);

        String name = companyIdEl.attributeValue("name");
        String pattern = companyIdEl.attributeValue("pattern");

        ThemeCompanyId themeCompanyId = null;

        if (Validator.isNotNull(name)) {
          themeCompanyId = new ThemeCompanyId(name, false);
        } else if (Validator.isNotNull(pattern)) {
          themeCompanyId = new ThemeCompanyId(pattern, true);
        }

        if (themeCompanyId != null) {
          includes.add(themeCompanyId);
        }
      }
    }

    return includes;
  }
示例#10
0
  public String getDigest(String password) {
    if (Validator.isNull(getScreenName())) {
      throw new IllegalStateException("Screen name cannot be null");
    } else if (Validator.isNull(getEmailAddress())) {
      throw new IllegalStateException("Email address cannot be null");
    }

    StringBundler sb = new StringBundler(5);

    String digest1 =
        DigesterUtil.digestHex(Digester.MD5, getEmailAddress(), Portal.PORTAL_REALM, password);

    sb.append(digest1);
    sb.append(StringPool.COMMA);

    String digest2 =
        DigesterUtil.digestHex(Digester.MD5, getScreenName(), Portal.PORTAL_REALM, password);

    sb.append(digest2);
    sb.append(StringPool.COMMA);

    String digest3 =
        DigesterUtil.digestHex(
            Digester.MD5, String.valueOf(getUserId()), Portal.PORTAL_REALM, password);

    sb.append(digest3);

    return sb.toString();
  }
  public static int validateFriendlyURL(String friendlyURL) {
    if (friendlyURL.length() < 2) {
      return LayoutFriendlyURLException.TOO_SHORT;
    }

    if (!friendlyURL.startsWith(StringPool.SLASH)) {
      return LayoutFriendlyURLException.DOES_NOT_START_WITH_SLASH;
    }

    if (friendlyURL.endsWith(StringPool.SLASH)) {
      return LayoutFriendlyURLException.ENDS_WITH_SLASH;
    }

    if (friendlyURL.indexOf(StringPool.DOUBLE_SLASH) != -1) {
      return LayoutFriendlyURLException.ADJACENT_SLASHES;
    }

    for (char c : friendlyURL.toCharArray()) {
      if ((!Validator.isChar(c))
          && (!Validator.isDigit(c))
          && (c != CharPool.DASH)
          && (c != CharPool.PERCENT)
          && (c != CharPool.PERIOD)
          && (c != CharPool.PLUS)
          && (c != CharPool.SLASH)
          && (c != CharPool.STAR)
          && (c != CharPool.UNDERLINE)) {

        return LayoutFriendlyURLException.INVALID_CHARACTERS;
      }
    }

    return -1;
  }
示例#12
0
  private String _getJavaClassComment(Element rootElement, JavaClass javaClass) {

    StringBundler sb = new StringBundler();

    String indent = StringPool.BLANK;

    sb.append("/**\n");

    String comment = rootElement.elementText("comment");

    if (Validator.isNotNull(comment)) {
      sb.append(_wrapText(comment, indent + " * "));
    }

    String docletTags =
        _addDocletTags(
            rootElement,
            new String[] {"author", "version", "see", "since", "serial", "deprecated"},
            indent + " * ",
            _hasPublicModifier(javaClass));

    if (Validator.isNotNull(docletTags)) {
      if (_initializeMissingJavadocs || Validator.isNotNull(comment)) {
        sb.append(" *\n");
      }

      sb.append(docletTags);
    }

    sb.append(" */\n");

    return sb.toString();
  }
  protected int authenticateOmniadmin(
      long companyId, String emailAddress, String screenName, long userId) throws Exception {

    // Only allow omniadmin if Liferay password checking is enabled

    if (PropsValues.AUTH_PIPELINE_ENABLE_LIFERAY_CHECK) {
      if (userId > 0) {
        if (OmniadminUtil.isOmniadmin(userId)) {
          return SUCCESS;
        }
      } else if (Validator.isNotNull(emailAddress)) {
        try {
          User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, emailAddress);

          if (OmniadminUtil.isOmniadmin(user.getUserId())) {
            return SUCCESS;
          }
        } catch (NoSuchUserException nsue) {
        }
      } else if (Validator.isNotNull(screenName)) {
        try {
          User user = UserLocalServiceUtil.getUserByScreenName(companyId, screenName);

          if (OmniadminUtil.isOmniadmin(user.getUserId())) {
            return SUCCESS;
          }
        } catch (NoSuchUserException nsue) {
        }
      }
    }

    return FAILURE;
  }
    protected void addTrigger(
        SchedulerEntry schedulerEntry, ServiceReference<SchedulerEntry> serviceReference) {

      String propertyKey = schedulerEntry.getPropertyKey();

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

      long bundleId = GetterUtil.getLong(serviceReference.getProperty("bundle.id"), -1);

      String triggerValue = null;

      if (bundleId != 0) {
        Class<?> clazz = schedulerEntry.getClass();

        ClassLoader classloader = clazz.getClassLoader();

        triggerValue = getPluginPropertyValue(classloader, propertyKey);
      } else {
        triggerValue = PrefsPropsUtil.getString(propertyKey);
      }

      if (_log.isDebugEnabled()) {
        _log.debug("Scheduler property key " + propertyKey + " has trigger value " + triggerValue);
      }

      if (Validator.isNotNull(triggerValue)) {
        schedulerEntry.setTriggerValue(triggerValue);
      }
    }
  @Test
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    Country newCountry = addCountry();

    _persistence.clearCache();

    CountryModelImpl existingCountryModelImpl =
        (CountryModelImpl) _persistence.findByPrimaryKey(newCountry.getPrimaryKey());

    Assert.assertTrue(
        Validator.equals(
            existingCountryModelImpl.getName(), existingCountryModelImpl.getOriginalName()));

    Assert.assertTrue(
        Validator.equals(
            existingCountryModelImpl.getA2(), existingCountryModelImpl.getOriginalA2()));

    Assert.assertTrue(
        Validator.equals(
            existingCountryModelImpl.getA3(), existingCountryModelImpl.getOriginalA3()));
  }
  private List<ThemeGroupId> _getGroupLimitExcludes(Element element) {
    List<ThemeGroupId> includes = new ArrayList<ThemeGroupId>();

    if (element == null) {
      return includes;
    }

    List<Element> groupIdsElements = element.elements("group-id");

    for (int i = 0; i < groupIdsElements.size(); i++) {
      Element groupIdElement = groupIdsElements.get(i);

      String name = groupIdElement.attributeValue("name");
      String pattern = groupIdElement.attributeValue("pattern");

      ThemeGroupId themeGroupId = null;

      if (Validator.isNotNull(name)) {
        themeGroupId = new ThemeGroupId(name, false);
      } else if (Validator.isNotNull(pattern)) {
        themeGroupId = new ThemeGroupId(pattern, true);
      }

      if (themeGroupId != null) {
        includes.add(themeGroupId);
      }
    }

    return includes;
  }
  @Override
  public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect)
      throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    if (Validator.isNotNull(_article.getLayoutUuid())) {
      layout =
          LayoutLocalServiceUtil.getLayoutByUuidAndCompanyId(
              _article.getLayoutUuid(), _article.getCompanyId());
    }

    String portletId = (String) liferayPortletRequest.getAttribute(WebKeys.PORTLET_ID);

    PortletPreferences portletSetup =
        PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletId);

    String linkToLayoutUuid =
        GetterUtil.getString(portletSetup.getValue("portletSetupLinkToLayoutUuid", null));

    if (Validator.isNotNull(_article.getLayoutUuid()) && Validator.isNull(linkToLayoutUuid)) {

      Group group = themeDisplay.getScopeGroup();

      if (group.getGroupId() != _article.getGroupId()) {
        group = GroupLocalServiceUtil.getGroup(_article.getGroupId());
      }

      String groupFriendlyURL =
          PortalUtil.getGroupFriendlyURL(group, layout.isPrivateLayout(), themeDisplay);

      return PortalUtil.addPreservedParameters(
          themeDisplay,
          groupFriendlyURL
              .concat(JournalArticleConstants.CANONICAL_URL_SEPARATOR)
              .concat(_article.getUrlTitle()));
    }

    List<Long> hitLayoutIds =
        JournalContentSearchLocalServiceUtil.getLayoutIds(
            _article.getGroupId(), layout.isPrivateLayout(), _article.getArticleId());

    if (!hitLayoutIds.isEmpty()) {
      Long hitLayoutId = hitLayoutIds.get(0);

      Layout hitLayout =
          LayoutLocalServiceUtil.getLayout(
              _article.getGroupId(), layout.isPrivateLayout(), hitLayoutId.longValue());

      return PortalUtil.getLayoutURL(hitLayout, themeDisplay);
    }

    return noSuchEntryRedirect;
  }
  protected Map<String, String> readUsersFile(InputStream usersInputStream) throws IOException {

    if (usersInputStream == null) {
      return Collections.emptyMap();
    }

    Map<String, String> usersMap = new HashMap<String, String>();

    UnsyncBufferedReader unsyncBufferedReader =
        new UnsyncBufferedReader(new InputStreamReader(usersInputStream));

    String line = unsyncBufferedReader.readLine();

    while (line != null) {
      String[] array = StringUtil.split(line);

      if ((array.length == 2) && Validator.isNotNull(array[0]) && Validator.isNotNull(array[1])) {

        usersMap.put(array[0], array[1]);
      } else {
        if (_log.isInfoEnabled()) {
          _log.info("Ignoring line " + line + " because it does not contain exactly 2 columns");
        }
      }

      line = unsyncBufferedReader.readLine();
    }

    return usersMap;
  }
  @Test
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    ResourceBlock newResourceBlock = addResourceBlock();

    _persistence.clearCache();

    ResourceBlockModelImpl existingResourceBlockModelImpl =
        (ResourceBlockModelImpl) _persistence.findByPrimaryKey(newResourceBlock.getPrimaryKey());

    Assert.assertEquals(
        existingResourceBlockModelImpl.getCompanyId(),
        existingResourceBlockModelImpl.getOriginalCompanyId());
    Assert.assertEquals(
        existingResourceBlockModelImpl.getGroupId(),
        existingResourceBlockModelImpl.getOriginalGroupId());
    Assert.assertTrue(
        Validator.equals(
            existingResourceBlockModelImpl.getName(),
            existingResourceBlockModelImpl.getOriginalName()));
    Assert.assertTrue(
        Validator.equals(
            existingResourceBlockModelImpl.getPermissionsHash(),
            existingResourceBlockModelImpl.getOriginalPermissionsHash()));
  }
  public String[] splitFullName(String fullName) {
    String firstName = StringPool.BLANK;
    String middleName = StringPool.BLANK;
    String lastName = StringPool.BLANK;

    if (Validator.isNotNull(fullName)) {
      String[] name = StringUtil.split(fullName, StringPool.SPACE);

      firstName = name[0];
      middleName = StringPool.BLANK;
      lastName = name[name.length - 1];

      if (name.length > 2) {
        for (int i = 1; i < name.length - 1; i++) {
          if (Validator.isNull(name[i].trim())) {
            continue;
          }

          if (i != 1) {
            middleName += StringPool.SPACE;
          }

          middleName += name[i].trim();
        }
      }
    } else {
      firstName = GetterUtil.getString(firstName, lastName);
      lastName = firstName;
    }

    return new String[] {firstName, middleName, lastName};
  }
  protected void validateActionDocument(String fileName, Element rootElement) {

    if (!Validator.equals(rootElement.getName(), "definition")) {
      throwValidationException(1000, fileName, rootElement);
    }

    List<Element> elements = rootElement.elements();

    if (elements.isEmpty()) {
      throwValidationException(1001, fileName, rootElement, new String[] {"command"});
    }

    for (Element element : elements) {
      String elementName = element.getName();

      if (elementName.equals("command")) {
        String attributeValue = element.attributeValue("name");

        if (attributeValue == null) {
          throwValidationException(1003, fileName, element, "name");
        } else if (Validator.isNull(attributeValue)) {
          throwValidationException(1006, fileName, element, "name");
        }

        validateActionCommandElement(
            fileName, element, new String[] {"execute"}, new String[] {"function"}, new String[0]);
      } else {
        throwValidationException(1002, fileName, element, elementName);
      }
    }
  }
  @Test
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    DLFolder newDLFolder = addDLFolder();

    _persistence.clearCache();

    DLFolderModelImpl existingDLFolderModelImpl =
        (DLFolderModelImpl) _persistence.findByPrimaryKey(newDLFolder.getPrimaryKey());

    Assert.assertTrue(
        Validator.equals(
            existingDLFolderModelImpl.getUuid(), existingDLFolderModelImpl.getOriginalUuid()));
    Assert.assertEquals(
        existingDLFolderModelImpl.getGroupId(), existingDLFolderModelImpl.getOriginalGroupId());

    Assert.assertEquals(
        existingDLFolderModelImpl.getRepositoryId(),
        existingDLFolderModelImpl.getOriginalRepositoryId());

    Assert.assertEquals(
        existingDLFolderModelImpl.getGroupId(), existingDLFolderModelImpl.getOriginalGroupId());
    Assert.assertEquals(
        existingDLFolderModelImpl.getParentFolderId(),
        existingDLFolderModelImpl.getOriginalParentFolderId());
    Assert.assertTrue(
        Validator.equals(
            existingDLFolderModelImpl.getName(), existingDLFolderModelImpl.getOriginalName()));
  }
示例#23
0
  @Override
  public String getPortalURL(long groupId) throws PortalException, SystemException {

    String portalURL = PortalUtil.getPortalURL(getVirtualHostname(), Http.HTTP_PORT, false);

    if (groupId <= 0) {
      return portalURL;
    }

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    if (group.hasPublicLayouts()) {
      LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, false);

      if (Validator.isNotNull(layoutSet.getVirtualHostname())) {
        portalURL = PortalUtil.getPortalURL(layoutSet.getVirtualHostname(), Http.HTTP_PORT, false);
      }
    } else if (group.hasPrivateLayouts()) {
      LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, true);

      if (Validator.isNotNull(layoutSet.getVirtualHostname())) {
        portalURL = PortalUtil.getPortalURL(layoutSet.getVirtualHostname(), Http.HTTP_PORT, false);
      }
    }

    return portalURL;
  }
  protected boolean isCacheableRequest(HttpServletRequest request) {
    String portletId = ParamUtil.getString(request, "p_p_id");

    if (Validator.isNotNull(portletId)) {
      return false;
    }

    if ((_pattern == _PATTERN_FRIENDLY) || (_pattern == _PATTERN_LAYOUT)) {
      long userId = PortalUtil.getUserId(request);
      String remoteUser = request.getRemoteUser();

      if ((userId > 0) || Validator.isNotNull(remoteUser)) {
        return false;
      }
    }

    if (_pattern == _PATTERN_LAYOUT) {
      String plid = ParamUtil.getString(request, "p_l_id");

      if (Validator.isNull(plid)) {
        return false;
      }
    }

    return true;
  }
示例#25
0
  protected void configureSubtypeFieldFilter(AssetEntryQuery assetEntryQuery, Locale locale)
      throws Exception {

    long[] classNameIds = getClassNameIds();
    long[] classTypeIds = getClassTypeIds();

    if (!isSubtypeFieldsFilterEnabled()
        || (classNameIds.length != 1)
        || (classTypeIds.length != 1)
        || Validator.isNull(getDDMStructureFieldName())
        || Validator.isNull(getDDMStructureFieldValue())) {

      return;
    }

    AssetRendererFactory<?> assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassNameId(classNameIds[0]);

    ClassTypeReader classTypeReader = assetRendererFactory.getClassTypeReader();

    ClassType classType = classTypeReader.getClassType(classTypeIds[0], locale);

    ClassTypeField classTypeField = classType.getClassTypeField(getDDMStructureFieldName());

    assetEntryQuery.setAttribute(
        "ddmStructureFieldName",
        AssetPublisherUtil.encodeName(
            classTypeField.getClassTypeId(), getDDMStructureFieldName(), locale));
    assetEntryQuery.setAttribute("ddmStructureFieldValue", getDDMStructureFieldValue());
  }
  public void execute() throws BuildException {
    try {
      InetAddress localHost = InetAddress.getLocalHost();

      if (Validator.isNotNull(_hostAddressProperty)) {
        getProject().setUserProperty(_hostAddressProperty, localHost.getHostAddress());
      }

      if (Validator.isNotNull(_hostNameProperty)) {
        getProject().setUserProperty(_hostNameProperty, localHost.getHostName());
      }

      if (Validator.isNotNull(_vmId1Property)) {
        int id = GetterUtil.getInteger(StringUtil.extractDigits(localHost.getHostName()));

        getProject().setUserProperty(_vmId1Property, String.valueOf((id * 2) - 1));
      }

      if (Validator.isNotNull(_vmId2Property)) {
        int id = GetterUtil.getInteger(StringUtil.extractDigits(localHost.getHostName()));

        getProject().setUserProperty(_vmId2Property, String.valueOf((id * 2)));
      }
    } catch (UnknownHostException uhe) {
      throw new BuildException(uhe);
    }
  }
  @Override
  public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext)
      throws Exception {

    String keywords = searchContext.getKeywords();

    if (Validator.isNull(keywords)) {
      addSearchTerm(searchQuery, searchContext, Field.DESCRIPTION, false);
      addSearchTerm(searchQuery, searchContext, Field.TITLE, false);
      addSearchTerm(searchQuery, searchContext, Field.USER_NAME, false);
    }

    addSearchTerm(searchQuery, searchContext, "ddmContent", false);
    addSearchTerm(searchQuery, searchContext, "extension", false);
    addSearchTerm(searchQuery, searchContext, "fileEntryTypeId", false);
    addSearchTerm(searchQuery, searchContext, "path", false);

    LinkedHashMap<String, Object> params =
        (LinkedHashMap<String, Object>) searchContext.getAttribute("params");

    if (params != null) {
      String expandoAttributes = (String) params.get("expandoAttributes");

      if (Validator.isNotNull(expandoAttributes)) {
        addSearchExpando(searchQuery, searchContext, expandoAttributes);
      }
    }
  }
  @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;
  }
  @Override
  public String getFirstNumber(String locator) {
    WebElement webElement = getWebElement(locator);

    String text = webElement.getText();

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

    StringBundler sb = new StringBundler();

    char[] chars = text.toCharArray();

    for (char c : chars) {
      boolean digit = false;

      if (Validator.isDigit(c)) {
        sb.append(c);

        digit = true;
      }

      String s = sb.toString();

      if (Validator.isNotNull(s) && !digit) {
        return s;
      }
    }

    return sb.toString();
  }
  protected String getGroupURL(
      Group group, PortletRequest portletRequest, boolean includeStagingGroup) {

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

    String groupDisplayURL = group.getDisplayURL(themeDisplay, false);

    if (Validator.isNotNull(groupDisplayURL)) {
      return HttpUtil.removeParameter(groupDisplayURL, "p_p_id");
    }

    groupDisplayURL = group.getDisplayURL(themeDisplay, true);

    if (Validator.isNotNull(groupDisplayURL)) {
      return HttpUtil.removeParameter(groupDisplayURL, "p_p_id");
    }

    if (includeStagingGroup && group.hasStagingGroup()) {
      try {
        if (GroupPermissionUtil.contains(
            themeDisplay.getPermissionChecker(), group, ActionKeys.VIEW_STAGING)) {

          return getGroupURL(group.getStagingGroup(), portletRequest);
        }
      } catch (PortalException pe) {
        _log.error("Unable to check permission on group " + group.getGroupId(), pe);
      }
    }

    return getGroupAdministrationURL(group, portletRequest);
  }