Package com.pugh.sockso.resources

Examples of com.pugh.sockso.resources.Locale


   
    public void login() throws IOException, SQLException, BadRequestException {
       
        final Request req = getRequest();
        final User user = getUser();
        final Locale locale = getLocale();
       
        if ( user != null ) {
            log.debug( "User appears logged in: " +user.getId()+ " = '" +user.getName()+ "'" );
            throw new BadRequestException( locale.getString("www.error.alreadyLoggedIn"), 403 );
        }

        final String todo = req.getArgument( "todo" );
       
        if ( todo.equals("login") )
View Full Code Here


   
    protected void deletePlaylist() throws BadRequestException, SQLException, IOException {

        final Request req = getRequest();
        final User user = getUser();
        final Locale locale = getLocale();

        if ( user == null ) throw new BadRequestException( locale.getString("www.json.error.notLoggedIn"), 403 );

        final Database db = getDatabase();
        final int id = Integer.parseInt( req.getUrlParam(2) );
        final String sql = " select 1 " +
                           " from playlists p " +
View Full Code Here

        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 );
View Full Code Here

     */
   
    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( "\\/\\/", "\\/" );

        }
       
View Full Code Here

   
    protected void savePlaylist() throws IOException, SQLException, BadRequestException {
       
        final Request req = getRequest();
        final User user = getUser();
        final Locale locale = getLocale();
        final String name = req.getUrlParam( 2 ).trim();
        final String[] args = req.getPlayParams( 2 );

        String result = locale.getString("www.json.error.unknown");

        // make sure data is ok first
        if ( name.equals("") )
            result = locale.getString("www.json.error.noName");
        else if ( args.length == 0 )
            result = locale.getString("www.json.error.noArguments");
        else if ( user == null )
            result = locale.getString("www.json.error.notLoggedIn");
        else {
           
            final Database db = getDatabase();
            final List<Track> vTracks = Track.getTracksFromPlayArgs( db, args );
            final Track[] tracks = new Track[ vTracks.size() ];
View Full Code Here

   
    public void handleRequest() throws SQLException, IOException, BadRequestException {

        final Request req = getRequest();
        final Response res = getResponse();
        final Locale locale = getLocale();
        final Properties p = getProperties();

        if ( p.get(Constants.WWW_DOWNLOADS_DISABLE).equals(Properties.YES) )
            throw new BadRequestException( locale.getString("www.error.downloadsDisabled"), 403 );
       
        final Database db = getDatabase();
        final String[] args = req.getPlayParams( false );
        final List<Track> tracks = Track.getTracksFromPlayArgs( db, args );
        final String fileName = getFileName( tracks );
View Full Code Here

       
    }
   
    public void testGetErrors() {
       
        final Locale loc = createMock( Locale.class );
        expect( loc.getString("errMyKey") ).andReturn( "foo" ).times( 1 );
        replay( loc );
       
        final Request req = createMock( Request.class );
        expect( req.getArgument("theDate") ).andReturn( "NOT A DATE" ).times( 1 );
        replay( req );
View Full Code Here

    public void testLogout() throws IOException {
       
        Database db = createMock( Database.class );
        Request req = new TestRequest( "/" );
        Response res = createMock( Response.class );
        Locale locale = createNiceMock( Locale.class );

        Userer u = new Userer();
        u.setRequest( req );
        u.setResponse( res );
        u.setLocale( locale );
View Full Code Here

     *
     */
   
    public static Locale getLocale() {
       
        final Locale locale = createNiceMock( Locale.class );
        expect( locale.getString((String)anyObject()) ).andReturn( "" ).anyTimes();
        replay( locale );
       
        return locale;
       
    }
View Full Code Here

TOP

Related Classes of com.pugh.sockso.resources.Locale

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.