public static int validate(String friendlyURL) {
    if (friendlyURL.length() < 2) {
      return TOO_SHORT;
    }

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

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

    if (friendlyURL.indexOf("//") != -1) {
      return ADJACENT_SLASHES;
    }

    char[] c = friendlyURL.toCharArray();

    for (int i = 0; i < c.length; i++) {
      if ((!Validator.isChar(c[i]))
          && (!Validator.isDigit(c[i]))
          && (c[i] != '/')
          && (c[i] != '-')
          && (c[i] != '_')) {

        return INVALID_CHARACTERS;
      }
    }

    return -1;
  }
Exemplo n.º 2
0
  protected static com.liferay.portlet.polls.model.PollsDisplay remove(
      com.liferay.portlet.polls.ejb.PollsDisplayPK pollsDisplayPK)
      throws com.liferay.portlet.polls.NoSuchDisplayException, com.liferay.portal.SystemException {
    PollsDisplayPersistence persistence = (PollsDisplayPersistence) InstancePool.get(PERSISTENCE);
    ModelListener listener = null;

    if (Validator.isNotNull(LISTENER)) {
      try {
        listener = (ModelListener) Class.forName(LISTENER).newInstance();
      } catch (Exception e) {
        Logger.error(PollsDisplayUtil.class, e.getMessage(), e);
      }
    }

    if (listener != null) {
      listener.onBeforeRemove(findByPrimaryKey(pollsDisplayPK));
    }

    com.liferay.portlet.polls.model.PollsDisplay pollsDisplay = persistence.remove(pollsDisplayPK);

    if (listener != null) {
      listener.onAfterRemove(pollsDisplay);
    }

    return pollsDisplay;
  }
Exemplo n.º 3
0
  public static com.liferay.portal.model.Address update(com.liferay.portal.model.Address address)
      throws com.liferay.portal.SystemException {
    AddressPersistence persistence = (AddressPersistence) InstancePool.get(PERSISTENCE);
    ModelListener listener = null;

    if (Validator.isNotNull(LISTENER)) {
      try {
        listener = (ModelListener) Class.forName(LISTENER).newInstance();
      } catch (Exception e) {
        _log.error(e.getMessage());
      }
    }

    boolean isNew = address.isNew();

    if (listener != null) {
      if (isNew) {
        listener.onBeforeCreate(address);
      } else {
        listener.onBeforeUpdate(address);
      }
    }

    address = persistence.update(address);

    if (listener != null) {
      if (isNew) {
        listener.onAfterCreate(address);
      } else {
        listener.onAfterUpdate(address);
      }
    }

    return address;
  }
Exemplo n.º 4
0
  public static com.liferay.portal.model.Address remove(java.lang.String addressId)
      throws com.liferay.portal.NoSuchAddressException, com.liferay.portal.SystemException {
    AddressPersistence persistence = (AddressPersistence) InstancePool.get(PERSISTENCE);
    ModelListener listener = null;

    if (Validator.isNotNull(LISTENER)) {
      try {
        listener = (ModelListener) Class.forName(LISTENER).newInstance();
      } catch (Exception e) {
        _log.error(e.getMessage());
      }
    }

    if (listener != null) {
      listener.onBeforeRemove(findByPrimaryKey(addressId));
    }

    com.liferay.portal.model.Address address = persistence.remove(addressId);

    if (listener != null) {
      listener.onAfterRemove(address);
    }

    return address;
  }
Exemplo n.º 5
0
  private ShoppingOrder _get(String orderId) {
    if (!_cacheable) {
      return null;
    } else if (orderId == null) {
      return null;
    } else {
      ShoppingOrder obj = null;
      String key = orderId.toString();

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

      try {
        obj = (ShoppingOrder) _cache.getFromCache(key);
      } catch (NeedsRefreshException nfe) {
      } finally {
        if (obj == null) {
          _cache.cancelUpdate(key);
        }
      }

      return obj;
    }
  }
Exemplo n.º 6
0
  public void processAction(ActionRequest req, ActionResponse res)
      throws IOException, PortletException {

    try {
      String cmd = ParamUtil.getString(req, Constants.CMD);

      if (cmd.equals(Constants.SEND)) {
        String selectTo = req.getParameter("select_to");
        String to = req.getParameter("to");
        String subject = ParamUtil.getString(req, "subject");
        String message = ParamUtil.getString(req, "message");

        if (!Validator.isEmailAddress(selectTo) && !Validator.isEmailAddress(to)) {

          SessionErrors.add(req, "to_invalid");
        } else if (!Validator.isEmailAddress(to)) {
          to = selectTo;
        }

        if (SessionErrors.isEmpty(req)) {
          User user = PortalUtil.getUser(req);

          MailServiceUtil.sendEmail(
              new MailMessage(
                  new InternetAddress(user.getEmailAddress(), user.getFullName()),
                  new InternetAddress(to),
                  subject,
                  message));

          res.setRenderParameter("select_to", StringPool.BLANK);
          res.setRenderParameter("to", StringPool.BLANK);
          res.setRenderParameter("subject", StringPool.BLANK);
          res.setRenderParameter("message", StringPool.BLANK);

          SessionMessages.add(req, getPortletConfig().getPortletName() + ".send", to);
        } else {
          res.setRenderParameter("select_to", selectTo);
          res.setRenderParameter("to", to);
          res.setRenderParameter("subject", subject);
          res.setRenderParameter("message", message);
        }
      }
    } catch (Exception e) {
      throw new PortletException(e);
    }
  }
Exemplo n.º 7
0
  private PollsQuestion _put(String questionId, PollsQuestion obj) {
    if (!_cacheable) {
      return obj;
    } else if (questionId == null) {
      return obj;
    } else {
      String key = questionId.toString();

      if (Validator.isNotNull(key)) {
        _cache.put(key, obj, primaryGroup);
      }

      return obj;
    }
  }
Exemplo n.º 8
0
  private ShoppingOrder _put(String orderId, ShoppingOrder obj) {
    if (!_cacheable) {
      return obj;
    } else if (orderId == null) {
      return obj;
    } else {
      String key = orderId.toString();

      if (Validator.isNotNull(key)) {
        _cache.flushEntry(key);
        _cache.putInCache(key, obj);
      }

      return obj;
    }
  }
Exemplo n.º 9
0
  private PollsQuestion _get(String questionId) {
    if (!_cacheable) {
      return null;
    } else if (questionId == null) {
      return null;
    } else {
      PollsQuestion obj = null;
      String key = questionId.toString();

      if (Validator.isNull(key)) {
        return null;
      }
      try {
        obj = (PollsQuestion) _cache.get(key, primaryGroup);
      } catch (DotCacheException e) {
        Logger.debug(this, "Cache Entry not found", e);
      }
      return obj;
    }
  }
Exemplo n.º 10
0
  protected static com.liferay.portlet.polls.model.PollsDisplay update(
      com.liferay.portlet.polls.model.PollsDisplay pollsDisplay)
      throws com.liferay.portal.SystemException {
    PollsDisplayPersistence persistence = (PollsDisplayPersistence) InstancePool.get(PERSISTENCE);
    ModelListener listener = null;

    if (Validator.isNotNull(LISTENER)) {
      try {
        listener = (ModelListener) Class.forName(LISTENER).newInstance();
      } catch (Exception e) {
        Logger.error(PollsDisplayUtil.class, e.getMessage(), e);
      }
    }

    boolean isNew = pollsDisplay.isNew();

    if (listener != null) {
      if (isNew) {
        listener.onBeforeCreate(pollsDisplay);
      } else {
        listener.onBeforeUpdate(pollsDisplay);
      }
    }

    pollsDisplay = persistence.update(pollsDisplay);

    if (listener != null) {
      if (isNew) {
        listener.onAfterCreate(pollsDisplay);
      } else {
        listener.onAfterUpdate(pollsDisplay);
      }
    }

    return pollsDisplay;
  }