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);
  }
示例#2
0
  protected Field createField(
      DDMStructure ddmStructure,
      String fieldName,
      List<Serializable> fieldValues,
      ServiceContext serviceContext) {

    Field field = new Field();

    field.setDDMStructureId(ddmStructure.getStructureId());

    String languageId =
        GetterUtil.getString(
            serviceContext.getAttribute("languageId"), serviceContext.getLanguageId());

    Locale locale = LocaleUtil.fromLanguageId(languageId);

    String defaultLanguageId =
        GetterUtil.getString(serviceContext.getAttribute("defaultLanguageId"));

    Locale defaultLocale = LocaleUtil.fromLanguageId(defaultLanguageId);

    if (fieldName.startsWith(StringPool.UNDERLINE)) {
      locale = LocaleUtil.getSiteDefault();

      defaultLocale = LocaleUtil.getSiteDefault();
    }

    field.setDefaultLocale(defaultLocale);

    field.setName(fieldName);
    field.setValues(locale, fieldValues);

    return field;
  }
  protected void sendDDMRecordFile(
      HttpServletRequest request, HttpServletResponse response, String[] pathArray)
      throws Exception {

    if (pathArray.length == 4) {
      String className = GetterUtil.getString(pathArray[1]);
      long classPK = GetterUtil.getLong(pathArray[2]);
      String fieldName = GetterUtil.getString(pathArray[3]);

      Field field = null;

      if (className.equals(DDLRecord.class.getName())) {
        DDLRecord ddlRecord = DDLRecordLocalServiceUtil.getRecord(classPK);

        field = ddlRecord.getField(fieldName);
      } else if (className.equals(DLFileEntryMetadata.class.getName())) {
        DLFileEntryMetadata fileEntryMetadata =
            DLFileEntryMetadataLocalServiceUtil.getDLFileEntryMetadata(classPK);

        Fields fields = StorageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId());

        field = fields.get(fieldName);
      }

      DDMUtil.sendFieldFile(request, response, field);
    }
  }
  protected void updateFileVersionFileNames() throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getUpgradeOptimizedConnection();

      ps = con.prepareStatement("select fileVersionId, extension, title from DLFileVersion");

      rs = ps.executeQuery();

      while (rs.next()) {
        long fileVersionId = rs.getLong("fileVersionId");
        String extension = GetterUtil.getString(rs.getString("extension"));
        String title = GetterUtil.getString(rs.getString("title"));

        String fileName = DLUtil.getSanitizedFileName(title, extension);

        updateFileVersionFileName(fileVersionId, fileName);
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
示例#5
0
  public static String getLockUuid(HttpServletRequest request) throws WebDAVException {

    String token = StringPool.BLANK;

    String value = GetterUtil.getString(request.getHeader("If"));

    if (_log.isDebugEnabled()) {
      _log.debug("\"If\" header is " + value);
    }

    if (value.contains("(<DAV:no-lock>)")) {
      if (_log.isWarnEnabled()) {
        _log.warn("Lock tokens can never be <DAV:no-lock>");
      }

      throw new WebDAVException();
    }

    int beg = value.indexOf(TOKEN_PREFIX);

    if (beg >= 0) {
      beg += TOKEN_PREFIX.length();

      if (beg < value.length()) {
        int end = value.indexOf(CharPool.GREATER_THAN, beg);

        token = GetterUtil.getString(value.substring(beg, end));
      }
    }

    return token;
  }
  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);
    }
  }
  protected String getOldScopeName(ActionRequest actionRequest, Portlet portlet) throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    PortletPreferences portletPreferences = actionRequest.getPreferences();

    String scopeType = GetterUtil.getString(portletPreferences.getValue("lfrScopeType", null));

    if (Validator.isNull(scopeType)) {
      return null;
    }

    String scopeName = null;

    if (scopeType.equals("company")) {
      scopeName = themeDisplay.translate("global");
    } else if (scopeType.equals("layout")) {
      String scopeLayoutUuid =
          GetterUtil.getString(portletPreferences.getValue("lfrScopeLayoutUuid", null));

      Layout scopeLayout =
          _layoutLocalService.fetchLayoutByUuidAndGroupId(
              scopeLayoutUuid, layout.getGroupId(), layout.isPrivateLayout());

      if (scopeLayout != null) {
        scopeName = scopeLayout.getName(themeDisplay.getLocale());
      }
    } else {
      throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
    }

    return scopeName;
  }
  public void receive(Message message) throws MessageListenerException {
    String destinationName =
        GetterUtil.getString(message.getString(SchedulerEngine.DESTINATION_NAME));

    if (destinationName.equals(DestinationNames.SCHEDULER_DISPATCH)) {
      String receiverKey = GetterUtil.getString(message.getString(SchedulerEngine.RECEIVER_KEY));

      if (!receiverKey.equals(_key)) {
        return;
      }
    }

    try {
      _messageListener.receive(message);
    } catch (Exception e) {
      handleException(message, e);

      if (e instanceof MessageListenerException) {
        throw (MessageListenerException) e;
      } else {
        throw new MessageListenerException(e);
      }
    } finally {
      if (message.getBoolean(SchedulerEngine.DISABLE)
          && destinationName.equals(DestinationNames.SCHEDULER_DISPATCH)) {

        MessageBusUtil.unregisterMessageListener(destinationName, this);
      }
    }
  }
  protected void updateFileEntryFileNames() throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getUpgradeOptimizedConnection();

      ps =
          con.prepareStatement(
              "select fileEntryId, groupId, folderId, extension, title, "
                  + "version from DLFileEntry");

      rs = ps.executeQuery();

      while (rs.next()) {
        long fileEntryId = rs.getLong("fileEntryId");
        long groupId = rs.getLong("groupId");
        long folderId = rs.getLong("folderId");
        String extension = GetterUtil.getString(rs.getString("extension"));
        String title = GetterUtil.getString(rs.getString("title"));
        String version = rs.getString("version");

        String uniqueFileName = DLUtil.getSanitizedFileName(title, extension);

        String titleExtension = StringPool.BLANK;
        String titleWithoutExtension = title;

        if (title.endsWith(StringPool.PERIOD + extension)) {
          titleExtension = extension;
          titleWithoutExtension = FileUtil.stripExtension(title);
        }

        String uniqueTitle = StringPool.BLANK;

        for (int i = 1; ; i++) {
          if (!hasFileEntry(groupId, folderId, uniqueFileName)) {
            break;
          }

          uniqueTitle = titleWithoutExtension + StringPool.UNDERLINE + String.valueOf(i);

          if (Validator.isNotNull(titleExtension)) {
            uniqueTitle += StringPool.PERIOD.concat(titleExtension);
          }

          uniqueFileName = DLUtil.getSanitizedFileName(uniqueTitle, extension);
        }

        updateFileEntryFileName(fileEntryId, uniqueFileName);

        if (Validator.isNotNull(uniqueTitle)) {
          updateFileEntryTitle(fileEntryId, uniqueTitle, version);
        }
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
  protected void indexField(Document document, Element element, String elType, String elIndexType) {

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

    com.liferay.portal.kernel.xml.Document structureDocument = element.getDocument();

    Element rootElement = structureDocument.getRootElement();

    String defaultLocale = GetterUtil.getString(rootElement.attributeValue("default-locale"));

    String name = encodeFieldName(element.attributeValue("name"));

    List<Element> dynamicContentElements = element.elements("dynamic-content");

    for (Element dynamicContentElement : dynamicContentElements) {
      String contentLocale =
          GetterUtil.getString(dynamicContentElement.attributeValue("language-id"));

      String[] value = new String[] {dynamicContentElement.getText()};

      if (elType.equals("multi-list")) {
        List<Element> optionElements = dynamicContentElement.elements("option");

        value = new String[optionElements.size()];

        for (int i = 0; i < optionElements.size(); i++) {
          value[i] = optionElements.get(i).getText();
        }
      }

      if (elIndexType.equals("keyword")) {
        if (Validator.isNull(contentLocale)) {
          document.addKeyword(name, value);
        } else {
          if (defaultLocale.equals(contentLocale)) {
            document.addKeyword(name, value);
          }

          document.addKeyword(name.concat(StringPool.UNDERLINE).concat(contentLocale), value);
        }
      } else if (elIndexType.equals("text")) {
        if (Validator.isNull(contentLocale)) {
          document.addText(name, StringUtil.merge(value, StringPool.SPACE));
        } else {
          if (defaultLocale.equals(contentLocale)) {
            document.addText(name, StringUtil.merge(value, StringPool.SPACE));
          }

          document.addText(
              name.concat(StringPool.UNDERLINE).concat(contentLocale),
              StringUtil.merge(value, StringPool.SPACE));
        }
      }
    }
  }
  private void _readColorSchemes(
      Element themeElement,
      Map<String, ColorScheme> colorSchemes,
      ContextReplace themeContextReplace) {

    List<Element> colorSchemeElements = themeElement.elements("color-scheme");

    for (Element colorSchemeElement : colorSchemeElements) {
      ContextReplace colorSchemeContextReplace = (ContextReplace) themeContextReplace.clone();

      String id = colorSchemeElement.attributeValue("id");

      colorSchemeContextReplace.addValue("color-scheme-id", id);

      ColorScheme colorSchemeModel = colorSchemes.get(id);

      if (colorSchemeModel == null) {
        colorSchemeModel = new ColorSchemeImpl(id);
      }

      String name =
          GetterUtil.getString(
              colorSchemeElement.attributeValue("name"), colorSchemeModel.getName());

      name = colorSchemeContextReplace.replace(name);

      boolean defaultCs =
          GetterUtil.getBoolean(
              colorSchemeElement.elementText("default-cs"), colorSchemeModel.isDefaultCs());

      String cssClass =
          GetterUtil.getString(
              colorSchemeElement.elementText("css-class"), colorSchemeModel.getCssClass());

      cssClass = colorSchemeContextReplace.replace(cssClass);

      colorSchemeContextReplace.addValue("css-class", cssClass);

      String colorSchemeImagesPath =
          GetterUtil.getString(
              colorSchemeElement.elementText("color-scheme-images-path"),
              colorSchemeModel.getColorSchemeImagesPath());

      colorSchemeImagesPath = colorSchemeContextReplace.replace(colorSchemeImagesPath);

      colorSchemeContextReplace.addValue("color-scheme-images-path", colorSchemeImagesPath);

      colorSchemeModel.setName(name);
      colorSchemeModel.setDefaultCs(defaultCs);
      colorSchemeModel.setCssClass(cssClass);
      colorSchemeModel.setColorSchemeImagesPath(colorSchemeImagesPath);

      colorSchemes.put(id, colorSchemeModel);
    }
  }
  protected GoogleDriveSession buildGoogleDriveSession() throws IOException, PortalException {

    long userId = PrincipalThreadLocal.getUserId();

    User user = UserLocalServiceUtil.getUser(userId);

    if (user.isDefaultUser()) {
      throw new PrincipalException("User is not authenticated");
    }

    GoogleCredential.Builder builder = new GoogleCredential.Builder();

    String googleClientId = PrefsPropsUtil.getString(user.getCompanyId(), "google-client-id");
    String googleClientSecret =
        PrefsPropsUtil.getString(user.getCompanyId(), "google-client-secret");

    builder.setClientSecrets(googleClientId, googleClientSecret);

    JacksonFactory jsonFactory = new JacksonFactory();

    builder.setJsonFactory(jsonFactory);

    HttpTransport httpTransport = new NetHttpTransport();

    builder.setTransport(httpTransport);

    GoogleCredential googleCredential = builder.build();

    ExpandoBridge expandoBridge = user.getExpandoBridge();

    String googleAccessToken =
        GetterUtil.getString(expandoBridge.getAttribute("googleAccessToken", false));

    googleCredential.setAccessToken(googleAccessToken);

    String googleRefreshToken =
        GetterUtil.getString(expandoBridge.getAttribute("googleRefreshToken", false));

    googleCredential.setRefreshToken(googleRefreshToken);

    Drive.Builder driveBuilder = new Drive.Builder(httpTransport, jsonFactory, googleCredential);

    Drive drive = driveBuilder.build();

    Drive.About driveAbout = drive.about();

    Drive.About.Get driveAboutGet = driveAbout.get();

    About about = driveAboutGet.execute();

    return new GoogleDriveSession(drive, about.getRootFolderId());
  }
示例#13
0
  protected void readAssetLinks(PortletDataContext portletDataContext) throws Exception {

    String xml =
        portletDataContext.getZipEntryAsString(
            portletDataContext.getSourceRootPath() + "/links.xml");

    if (xml == null) {
      return;
    }

    Document document = SAXReaderUtil.read(xml);

    Element rootElement = document.getRootElement();

    List<Element> assetLinkElements = rootElement.elements("asset-link");

    for (Element assetLinkElement : assetLinkElements) {
      String sourceUuid = GetterUtil.getString(assetLinkElement.attributeValue("source-uuid"));
      String[] assetEntryUuidArray =
          StringUtil.split(GetterUtil.getString(assetLinkElement.attributeValue("target-uuids")));
      int assetLinkType = GetterUtil.getInteger(assetLinkElement.attributeValue("type"));

      List<Long> assetEntryIds = new ArrayList<Long>();

      for (String assetEntryUuid : assetEntryUuidArray) {
        try {
          AssetEntry assetEntry =
              AssetEntryLocalServiceUtil.getEntry(
                  portletDataContext.getScopeGroupId(), assetEntryUuid);

          assetEntryIds.add(assetEntry.getEntryId());
        } catch (NoSuchEntryException nsee) {
        }
      }

      if (assetEntryIds.isEmpty()) {
        continue;
      }

      long[] assetEntryIdsArray =
          ArrayUtil.toArray(assetEntryIds.toArray(new Long[assetEntryIds.size()]));

      try {
        AssetEntry assetEntry =
            AssetEntryLocalServiceUtil.getEntry(portletDataContext.getScopeGroupId(), sourceUuid);

        AssetLinkLocalServiceUtil.updateLinks(
            assetEntry.getUserId(), assetEntry.getEntryId(), assetEntryIdsArray, assetLinkType);
      } catch (NoSuchEntryException nsee) {
      }
    }
  }
示例#14
0
  @Override
  public List<TrashEntry> getEntries(Hits hits) {
    List<TrashEntry> entries = new ArrayList<>();

    for (Document document : hits.getDocs()) {
      String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME));
      long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      try {
        TrashEntry entry = TrashEntryLocalServiceUtil.fetchEntry(entryClassName, classPK);

        if (entry == null) {
          String userName = GetterUtil.getString(document.get(Field.REMOVED_BY_USER_NAME));

          Date removedDate = document.getDate(Field.REMOVED_DATE);

          entry = new TrashEntryImpl();

          entry.setUserName(userName);
          entry.setCreateDate(removedDate);

          TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(entryClassName);

          TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

          entry.setClassName(trashRenderer.getClassName());
          entry.setClassPK(trashRenderer.getClassPK());

          String rootEntryClassName =
              GetterUtil.getString(document.get(Field.ROOT_ENTRY_CLASS_NAME));
          long rootEntryClassPK = GetterUtil.getLong(document.get(Field.ROOT_ENTRY_CLASS_PK));

          TrashEntry rootTrashEntry =
              TrashEntryLocalServiceUtil.fetchEntry(rootEntryClassName, rootEntryClassPK);

          if (rootTrashEntry != null) {
            entry.setRootEntry(rootTrashEntry);
          }
        }

        entries.add(entry);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(
              "Unable to find trash entry for " + entryClassName + " with primary key " + classPK);
        }
      }
    }

    return entries;
  }
  public JSONWebServiceAction getJSONWebServiceAction(HttpServletRequest request) {

    String path = GetterUtil.getString(request.getPathInfo());

    String method = GetterUtil.getString(request.getMethod());

    String pathParameters = null;

    JSONRPCRequest jsonRpcRequest = null;

    int pathParametersIndex = _getPathParametersIndex(path);

    if (pathParametersIndex != -1) {
      pathParameters = path.substring(pathParametersIndex);

      path = path.substring(0, pathParametersIndex);
    } else {
      if (method.equals(HttpMethods.POST) && !PortalUtil.isMultipartRequest(request)) {

        jsonRpcRequest = JSONRPCRequest.detectJSONRPCRequest(request);

        if (jsonRpcRequest != null) {
          path += StringPool.SLASH + jsonRpcRequest.getMethod();

          method = null;
        }
      }
    }

    JSONWebServiceActionParameters jsonWebServiceActionParameters =
        new JSONWebServiceActionParameters();

    jsonWebServiceActionParameters.collectAll(request, pathParameters, jsonRpcRequest);

    String[] parameterNames = jsonWebServiceActionParameters.getParameterNames();

    int jsonWebServiceActionConfigIndex =
        _getJSONWebServiceActionConfigIndex(path, method, parameterNames);

    if (jsonWebServiceActionConfigIndex == -1) {
      throw new RuntimeException(
          "No JSON web service action associated with path " + path + " and method " + method);
    }

    JSONWebServiceActionConfig jsonWebServiceActionConfig =
        _jsonWebServiceActionConfigs.get(jsonWebServiceActionConfigIndex);

    return new JSONWebServiceActionImpl(jsonWebServiceActionConfig, jsonWebServiceActionParameters);
  }
示例#16
0
  public String getOrderByType2() {
    if (_orderByType2 == null) {
      _orderByType2 = GetterUtil.getString(_portletPreferences.getValue("orderByType2", "ASC"));
    }

    return _orderByType2;
  }
示例#17
0
  public String getOrderByType1() {
    if (_orderByType1 == null) {
      _orderByType1 = GetterUtil.getString(_portletPreferences.getValue("orderByType1", "DESC"));
    }

    return _orderByType1;
  }
示例#18
0
  protected String getAssetPublisherURL(PortletRequest portletRequest) throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    StringBundler sb = new StringBundler(7);

    String layoutFriendlyURL =
        GetterUtil.getString(PortalUtil.getLayoutFriendlyURL(layout, themeDisplay));

    if (!layoutFriendlyURL.startsWith(Http.HTTP_WITH_SLASH)
        && !layoutFriendlyURL.startsWith(Http.HTTPS_WITH_SLASH)) {

      sb.append(themeDisplay.getPortalURL());
    }

    sb.append(layoutFriendlyURL);
    sb.append(Portal.FRIENDLY_URL_SEPARATOR);
    sb.append("asset_publisher/");
    sb.append(portletDisplay.getInstanceId());
    sb.append(StringPool.SLASH);

    return sb.toString();
  }
  @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;
  }
示例#20
0
  private static Map<String, Cookie> _getCookieMap(HttpServletRequest request) {

    Map<String, Cookie> cookieMap =
        (Map<String, Cookie>) request.getAttribute(CookieKeys.class.getName());

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

    Cookie[] cookies = request.getCookies();

    if (cookies == null) {
      cookieMap = Collections.emptyMap();
    } else {
      cookieMap = new HashMap<String, Cookie>(cookies.length * 4 / 3);

      for (Cookie cookie : cookies) {
        String cookieName = GetterUtil.getString(cookie.getName());

        cookieName = StringUtil.toUpperCase(cookieName);

        cookieMap.put(cookieName, cookie);
      }
    }

    request.setAttribute(CookieKeys.class.getName(), cookieMap);

    return cookieMap;
  }
  @Override
  public void removeNestedColumns(String portletNamespace) {
    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();

    UnicodeProperties newTypeSettingsProperties = new UnicodeProperties();

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

      String key = entry.getKey();

      if (!key.startsWith(portletNamespace)) {
        newTypeSettingsProperties.setProperty(key, entry.getValue());
      }
    }

    Layout layout = getLayout();

    layout.setTypeSettingsProperties(newTypeSettingsProperties);

    String nestedColumnIds =
        GetterUtil.getString(getTypeSettingsProperty(LayoutTypePortletConstants.NESTED_COLUMN_IDS));

    String[] nestedColumnIdsArray =
        ArrayUtil.removeByPrefix(StringUtil.split(nestedColumnIds), portletNamespace);

    setTypeSettingsProperty(
        LayoutTypePortletConstants.NESTED_COLUMN_IDS, StringUtil.merge(nestedColumnIdsArray));
  }
  protected void deleteInstance(ActionRequest actionRequest) throws Exception {

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

    long workflowInstanceId = ParamUtil.getLong(actionRequest, "workflowInstanceId");

    WorkflowInstance workflowInstance =
        WorkflowInstanceManagerUtil.getWorkflowInstance(
            themeDisplay.getCompanyId(), workflowInstanceId);

    Map<String, Serializable> workflowContext = workflowInstance.getWorkflowContext();

    long companyId = GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_COMPANY_ID));
    long groupId = GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_GROUP_ID));
    String className =
        GetterUtil.getString(workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME));
    long classPK =
        GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));

    WorkflowHandler workflowHandler = WorkflowHandlerRegistryUtil.getWorkflowHandler(className);

    workflowHandler.updateStatus(WorkflowConstants.STATUS_DRAFT, workflowContext);

    WorkflowInstanceLinkLocalServiceUtil.deleteWorkflowInstanceLink(
        companyId, groupId, className, classPK);
  }
  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};
  }
  public Theme fetchTheme(long companyId, String themeId) {
    themeId = GetterUtil.getString(themeId);

    Map<String, Theme> themes = _getThemes(companyId);

    return themes.get(themeId);
  }
  @Override
  protected void processTemplates(List<TemplateResource> templateResources, Writer writer)
      throws Exception {

    try {
      String namespace = GetterUtil.getString(get(TemplateConstants.NAMESPACE));

      if (Validator.isNull(namespace)) {
        throw new TemplateException("No namespace specified.");
      }

      SoyFileSet soyFileSet = getSoyFileSet(templateResources);

      SoyTofu soyTofu = soyFileSet.compileToTofu();

      Renderer renderer = soyTofu.newRenderer(namespace);

      renderer.setData(getSoyMapData());

      boolean renderStrict = GetterUtil.getBoolean(get(TemplateConstants.RENDER_STRICT), true);

      if (renderStrict) {
        SanitizedContent sanitizedContent = renderer.renderStrict();

        writer.write(sanitizedContent.stringValue());
      } else {
        writer.write(renderer.render());
      }
    } catch (PrivilegedActionException pae) {
      throw pae.getException();
    }
  }
示例#26
0
  private void _addReturnElement(Element methodElement, JavaMethod javaMethod) throws Exception {

    Type returns = javaMethod.getReturns();

    if (returns == null) {
      return;
    }

    String returnsValue = returns.getValue();

    if (returnsValue.equals("void")) {
      return;
    }

    Element returnElement = methodElement.addElement("return");

    DocletTag[] returnDocletTags = javaMethod.getTagsByName("return");

    String comment = StringPool.BLANK;

    if (returnDocletTags.length > 0) {
      DocletTag returnDocletTag = returnDocletTags[0];

      comment = GetterUtil.getString(returnDocletTag.getValue());

      DocUtil.add(returnElement, "required", true);
    }

    comment = _trimMultilineText(comment);

    Element commentElement = returnElement.addElement("comment");

    commentElement.addCDATA(comment);
  }
/** @author Shuyang Zhou */
public class IntrabandFactoryUtil {

  public static Intraband createIntraband() throws IOException {
    if (Validator.isNotNull(_INTRABAND_IMPL)) {
      try {
        Class<? extends Intraband> intraBandClass =
            (Class<? extends Intraband>) Class.forName(_INTRABAND_IMPL);

        Constructor<? extends Intraband> constructor = intraBandClass.getConstructor(long.class);

        return constructor.newInstance(_INTRABAND_TIMEOUT_DEFAULT);
      } catch (Exception e) {
        throw new RuntimeException("Unable to instantiate " + _INTRABAND_IMPL, e);
      }
    } else {
      Class<? extends Welder> welderClass = WelderFactoryUtil.getWelderClass();

      if (welderClass.equals(SocketWelder.class)) {
        return new SelectorIntraband(_INTRABAND_TIMEOUT_DEFAULT);
      } else {
        return new ExecutorIntraband(_INTRABAND_TIMEOUT_DEFAULT);
      }
    }
  }

  private static final String _INTRABAND_IMPL =
      GetterUtil.getString(System.getProperty(PropsKeys.INTRABAND_IMPL));

  private static final long _INTRABAND_TIMEOUT_DEFAULT =
      GetterUtil.getLong(System.getProperty(PropsKeys.INTRABAND_TIMEOUT_DEFAULT));
}
  /** Initializes the h r office persistence. */
  public void afterPropertiesSet() {
    String[] listenerClassNames =
        StringUtil.split(
            GetterUtil.getString(
                com.liferay.util.service.ServiceProps.get(
                    "value.object.listener.com.liferay.hr.model.HROffice")));

    if (listenerClassNames.length > 0) {
      try {
        List<ModelListener<HROffice>> listenersList = new ArrayList<ModelListener<HROffice>>();

        for (String listenerClassName : listenerClassNames) {
          listenersList.add(
              (ModelListener<HROffice>) InstanceFactory.newInstance(listenerClassName));
        }

        listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
      } catch (Exception e) {
        _log.error(e);
      }
    }

    containsHRHoliday = new ContainsHRHoliday(this);

    addHRHoliday = new AddHRHoliday(this);
    clearHRHolidaies = new ClearHRHolidaies(this);
    removeHRHoliday = new RemoveHRHoliday(this);
  }
示例#29
0
  protected void verifyURLTitle() throws Exception {
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      con = DataAccess.getUpgradeOptimizedConnection();

      ps =
          con.prepareStatement(
              "select distinct groupId, articleId, urlTitle from " + "JournalArticle");

      rs = ps.executeQuery();

      while (rs.next()) {
        long groupId = rs.getLong("groupId");
        String articleId = rs.getString("articleId");
        String urlTitle = GetterUtil.getString(rs.getString("urlTitle"));

        updateURLTitle(groupId, articleId, urlTitle);
      }
    } finally {
      DataAccess.cleanUp(con, ps, rs);
    }
  }
示例#30
0
  @Override
  public void deleteDirectory(long companyId, long repositoryId, String dirName)
      throws PortalException {

    Session session = null;

    try {
      session = JCRFactoryUtil.createSession();

      Node rootNode = getRootNode(session, companyId);

      Node repositoryNode = getFolderNode(rootNode, repositoryId);

      Node dirNode = repositoryNode.getNode(dirName);

      dirNode.remove();

      session.save();
    } catch (PathNotFoundException pnfe) {
      throw new NoSuchDirectoryException(dirName);
    } catch (RepositoryException re) {
      String message = GetterUtil.getString(re.getMessage());

      if (message.contains("failed to resolve path")) {
        throw new NoSuchDirectoryException(dirName);
      } else {
        throw new PortalException(re);
      }
    } finally {
      JCRFactoryUtil.closeSession(session);
    }
  }