net.fortuna.ical4j.model.ValidationException Java Examples

The following examples show how to use net.fortuna.ical4j.model.ValidationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CalendarFeed.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException
{
  if (WebConfiguration.isUpAndRunning() == false) {
    log.error("System isn't up and running, CalendarFeed call denied. The system is may-be in start-up phase or in maintenance mode.");
    resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
    return;
  }
  PFUserDO user = null;
  String logMessage = null;
  try {
    MDC.put("ip", req.getRemoteAddr());
    MDC.put("session", req.getSession().getId());
    if (StringUtils.isBlank(req.getParameter("user")) || StringUtils.isBlank(req.getParameter("q"))) {
      resp.sendError(HttpStatus.SC_BAD_REQUEST);
      log.error("Bad request, parameters user and q not given. Query string is: " + req.getQueryString());
      return;
    }
    final String encryptedParams = req.getParameter("q");
    final Integer userId = NumberHelper.parseInteger(req.getParameter("user"));
    if (userId == null) {
      log.error("Bad request, parameter user is not an integer: " + req.getQueryString());
      return;
    }
    final Registry registry = Registry.instance();
    user = registry.getUserGroupCache().getUser(userId);
    if (user == null) {
      log.error("Bad request, user not found: " + req.getQueryString());
      return;
    }
    PFUserContext.setUser(user);
    MDC.put("user", user.getUsername());
    final String decryptedParams = registry.getDao(UserDao.class).decrypt(userId, encryptedParams);
    if (decryptedParams == null) {
      log.error("Bad request, can't decrypt parameter q (may-be the user's authentication token was changed): " + req.getQueryString());
      return;
    }
    final Map<String, String> params = StringHelper.getKeyValues(decryptedParams, "&");
    final Calendar calendar = createCal(params, userId, params.get("token"), params.get(PARAM_NAME_TIMESHEET_USER));
    final StringBuffer buf = new StringBuffer();
    boolean first = true;
    for (final Map.Entry<String, String> entry : params.entrySet()) {
      if ("token".equals(entry.getKey()) == true) {
        continue;
      }
      first = StringHelper.append(buf, first, entry.getKey(), ", ");
      buf.append("=").append(entry.getValue());
    }
    logMessage = buf.toString();
    log.info("Getting calendar entries for: " + logMessage);

    if (calendar == null) {
      resp.sendError(HttpStatus.SC_BAD_REQUEST);
      log.error("Bad request, can't find calendar.");
      return;
    }

    resp.setContentType("text/calendar");
    final CalendarOutputter output = new CalendarOutputter(false);
    try {
      output.output(calendar, resp.getOutputStream());
    } catch (final ValidationException ex) {
      ex.printStackTrace();
    }
  } finally {
    log.info("Finished request: " + logMessage);
    PFUserContext.setUser(null);
    MDC.remove("ip");
    MDC.remove("session");
    if (user != null) {
      MDC.remove("user");
    }
  }
}
 
Example #2
Source File: VCardItemElementHandler.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
public VCardItemElementHandler(final FileInputStream fis){
  final DataInputStream in = new DataInputStream(fis);
  final BufferedReader br = new BufferedReader(new InputStreamReader(in));
  itemList = new ArrayList<Property>();

  //Read File Line By Line
  try {
    String strLine;
    while ((strLine = br.readLine()) != null)   {
      // looking for a item entry
      if (strLine.startsWith("item") && !strLine.contains("X-AB")) {

        // dissect the line by char
        final String str[] = StringUtils.splitByCharacterType(strLine);

        /*
         * ignore "item" + "number" + "." (example: "item2.") cause is not needed.
         * at index = 3 is the GroupId
         */
        final int n = 3;

        // set Property.Id
        final Id id = getItemId(str[n]);

        final ArrayList<Parameter> param = new ArrayList<Parameter>();

        boolean startSignFound = false;

        String valueCache = "";
        for (int i = n; i < str.length; i++){
          // looking for parameters
          if (str[i].equals("WORK") || str[i].equals("HOME")){
            param.add(getParameter(str[i]));
          }

          /*
           * looking for start sign.
           * usually ":" but sometimes addresses starts with ":;;"
           */
          if (str[i].equals(":;;") || str[i].equals(":") || str[i].equals(":;") && !startSignFound){
            startSignFound = true;
          } else
            if (startSignFound) {
              // terminate unwanted signs.
              if(str[i].equals(";") || str[i].equals(";;") || str[i].equals(".;"))
                valueCache = valueCache + ";";
              else
                valueCache = valueCache + str[i];
            }
        }

        final String finalValue = valueCache;
        // set property with group at index = 3
        @SuppressWarnings("serial")
        final Property property = new Property(new Group(str[n]), id, param) {
          @Override
          public void validate() throws ValidationException
          {
          }

          @Override
          public String getValue()
          {
            return finalValue;
          }
        };
        itemList.add(property);

      }
    }
    //      for (final Property p : itemList){
    //        System.out.println("propterty val: " + p.getValue() + " ;;; id: " + p.getId() + " ;;; parameter: " + p.getParameters(Parameter.Id.TYPE));
    //      }

    in.close();
  } catch (final IOException ex) {
    //      log.fatal("Exception encountered " + ex, ex);
  }
}