*/
private String getPathFromRequest() throws SQLException, BadRequestException {
final Request req = getRequest();
final Locale locale = getLocale();
final int collectionId = Integer.parseInt( req.getArgument("collectionId") );
String path = "";
ResultSet rs = null;
PreparedStatement st = null;
for ( int i=2; i<req.getParamCount(); i++ ) {
final String pathElement = req.getUrlParam( i );
// don't allow going up directories
if ( !pathElement.equals("..") )
path += "/" + req.getUrlParam( i );
}
try {
final Database db = getDatabase();
final String sql = " select c.path " +
" from collection c " +
" where c.id = ? ";
st = db.prepare( sql );
st.setInt( 1, collectionId );
rs = st.executeQuery();
// check the collection exists and we got it's root path
if ( rs.next() ) {
// we need to trim the trailing slash off the collection path
final String collPath = rs.getString( "path" );
path = collPath.substring(0,collPath.length()-1) + path;
}
else
throw new BadRequestException( locale.getString("www.error.invalidCollectionId"), 404 );
path = path.replaceAll( "\\/\\/", "\\/" );
}