Beispiel #1
0
  /**
   * this action allows you to give the path of a track on disk, and it will be resolved to the
   * tracks internal ID. this can then be used normally for playing music. the path coming in is
   * assumed to have forward slashes to delimit path components, but this needs to be converted to
   * whatever the actual path separator is for the current system BEFORE we try and query the
   * database, otherwise, well, it just won't work.
   *
   * <p>NB! ATM, this feature is only here for the the folder browsing stuff, so if that's not
   * turned on this this won't work.
   */
  protected void resolvePath() throws BadRequestException, SQLException, IOException {

    // check folder browsing is enabled
    Utils.checkFeatureEnabled(getProperties(), "browse.folders.enabled");

    ResultSet rs = null;
    PreparedStatement st = null;

    try {

      final Database db = getDatabase();
      final Locale locale = getLocale();
      final Request req = getRequest();
      final String path = convertPath(req.getArgument("path"));
      final String sql = Track.getSelectFromSql() + " where t.path = ? ";

      st = db.prepare(sql);
      st.setString(1, path);
      rs = st.executeQuery();

      if (!rs.next())
        throw new BadRequestException(locale.getString("www.error.trackNotFound"), 404);

      final Track track = Track.createFromResultSet(rs);
      final TResolvePath tpl = new TResolvePath();

      tpl.setTrack(track);
      getResponse().showJson(tpl.makeRenderer());

    } finally {
      Utils.close(rs);
      Utils.close(st);
    }
  }