示例#1
0
  public ActionForward execute(
      ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    try {
      GpsImportForm gpsForm = (GpsImportForm) form;
      User user = (User) req.getSession().getAttribute("user");
      int entryId = gpsForm.getEntryId();
      String fileName = gpsForm.getFileName();
      String title = gpsForm.getTitle();
      String activityId = gpsForm.getActivityId();
      String xml = gpsForm.getXml();
      log.debug(xml);

      List<GpsTrack> tracks = new TcxParser().parse(xml.getBytes());
      GpsTrack track = tracks.get(0); // Horrible hack.
      createAttachment(user, entryId, fileName, title, activityId, track);
      createGeotag(fileName, track);

      req.setAttribute("status", "success");
      req.setAttribute("message", "");
      log.debug("Returning status: success.");
      return mapping.findForward("results");
    } catch (Exception e) {
      log.fatal("Error processing incoming Garmin XML", e);
      req.setAttribute("status", "failure");
      req.setAttribute("message", e.toString());
      return mapping.findForward("results");
    }
  }
示例#2
0
  /**
   * Creates a GPX-formatted file attachment for the given entry.
   *
   * @param user
   * @param entryId
   * @param fileName
   * @param activityId
   * @param track
   * @param track
   */
  public void createAttachment(
      User user, int entryId, String fileName, String title, String activityId, GpsTrack track)
      throws DataAccessException, IOException {
    Attachment a = new Attachment();
    a.setUserName(user.getUserName());
    a.setUserId(user.getUserId());
    a.setEntryId(entryId);
    a.setFileType("map");
    a.setFileName(fileName);
    a.setActivityId(activityId);
    a.setTitle(title);

    GpxFormatter formatter = new GpxFormatter();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    List<GpsTrack> tracks = new ArrayList<GpsTrack>();
    tracks.add(track);

    formatter.format(tracks, baos);
    log.debug(new String(baos.toByteArray()));
    a.setBytes(baos.toByteArray());

    new AttachmentDao().create(a);
  }