Package com.pugh.sockso.resources

Examples of com.pugh.sockso.resources.Locale


     */

    private void serveResource( final String path ) throws IOException, BadRequestException {

        DataInputStream in = null;
        final Locale locale = getLocale();

        // only gzip for certain file types
        final String ext = Utils.getExt( path ).toLowerCase();
        for ( final String gzipExt : new String[] { "css", "js" } )
            if ( gzipExt.equals(ext) )
                getResponse().enableGzip();

        try {
           
            in = new DataInputStream( r.getResourceAsStream(path) );
           
            sendHeaders( path );
            getResponse().sendData( in );
           
        }

        catch ( final FileNotFoundException e ) {
            throw new BadRequestException( locale.getString("www.error.fileNotFound"), 404 );
        }
       
        finally {
            Utils.close( in );
        }
View Full Code Here


        try {

            req = new HttpRequest( sv );
            req.process( new BufferedInputStream(client.getInputStream()) );

            Locale locale = localeFactory.getLocale( req.getPreferredLangCode() );

            final WebAction action = dispatcher.getAction( req );
            action.setRequest( req );
            action.setLocale( locale );
View Full Code Here

     *
     */

    public boolean serveCover( final String itemName ) throws IOException, CacheException {
       
        final Locale locale = getLocale();
        final String noCoverId = "nocover-" + locale.getLangCode();
        final boolean coverIsCached = coverCache.isCached( noCoverId );
        final CoverArt cover = getNoCoverArt( noCoverId );

        serveCover( cover, "noCover", coverIsCached );

View Full Code Here

     *
     */

    protected CoverArt getNoCoverArt( String noCoverId ) throws IOException, CacheException {

        final Locale locale = getLocale();
        final Properties properties = getProperties();
       
        return coverCache.isCached( noCoverId )
                ? coverCache.getCoverArt(noCoverId)
                : new CoverArt(noCoverId, CoverArt.createNoCoverImage(properties, locale));
View Full Code Here

        checkUploadLooksOk();

        final Properties p = getProperties();
        final Request req = getRequest();
        final Locale locale = getLocale();
        final UploadFile file = req.getFile( "musicFile" );
        final String artist = req.getArgument( "artist" );
        final String album = req.getArgument( "album" );
        final String track = req.getArgument( "title" );

        // if we get here everything looks good, so lets try and save the file
        try {

            // make sure we've a directory to put the track in
            final Database db = getDatabase();
            final File dir = new File( Utils.getUploadsPath(db,p) + "/"+artist+" - "+album );
            if ( !dir.exists() )
                if ( !dir.mkdir() )
                    throw new BadRequestException( locale.getString("www.error.cantCreateTrackFolder"), 500 );

            // write the track to disk
            final File tempFile = file.getTemporaryFile();
            final File newFile = new File( getNewUploadFilename(dir,track,Utils.getExt(file.getFilename())) );
View Full Code Here

     */
   
    private void checkUploadLooksOk() throws BadRequestException {

        final Request req = getRequest();
        final Locale locale = getLocale();
        final UploadFile file = req.getFile( "musicFile" );

        if ( file == null )
            throw new BadRequestException( locale.getString("www.error.noFileUploaded") );

        // check mime type to see if it looks ok
        final String contentType = file.getContentType();
        log.debug( "File content type: " + contentType );
        if ( !Files.isValidMimeType(contentType) )
            throw new BadRequestException( locale.getString("www.error.unsupportedAudioFormat") );
       
        // check required fields
        final Database db = getDatabase();
        final Validater v = new Validater( db );
        final String artist = req.getArgument( "artist" );
        final String album = req.getArgument( "album" );
        final String track = req.getArgument( "title" );
        if ( !v.checkRequiredFields( new String[] { artist, album, track }) )
            throw new BadRequestException( locale.getString("www.error.missingField") );

    }
View Full Code Here

     *
     */
   
    private String getNewUploadFilename( final File dir, final String track, final String ext ) throws BadRequestException {
       
        final Locale locale = getLocale();
       
        int i = -1;
       
        // only try 100 times to avoid infinite loop, is 100 enough?  probably.
        while ( i++ < 100 ) {
            final File file = new File(
                dir.getAbsolutePath() + "/" + track + (i==0?"":i) + "." + ext
            );
            if ( !file.exists() )
                return file.getAbsolutePath();
        }
       
        throw new BadRequestException( locale.getString("www.error.couldNotCreateUniqueFilename"), 500 );

    }
View Full Code Here

     */
   
    private void checkPermissions() throws BadRequestException {
       
        final User user = getUser();
        final Locale locale = getLocale();
        final Properties p = getProperties();

        // check uploads are enabled
        Utils.checkFeatureEnabled( p, "uploads.enabled" );
       
        // if the user isn't logged in then make sure that anonymous
        // uploads have been enabled
        if ( user == null )
            if ( !p.get(Constants.WWW_UPLOADS_ALLOW_ANONYMOUS).equals(Properties.YES) )
                throw new BadRequestException( locale.getString("www.error.noAnonymousUploads"), 403 );

        // check there is a valid collection set for uploads
        final Database db = getDatabase();
        final String uploadsPath = Utils.getUploadsPath( db, p );
        if ( uploadsPath.equals("") )
            throw new BadRequestException( locale.getString("www.error.noUploadsDirectory"), 500 );
        final File uploadsDir = new File( uploadsPath );
        if ( !uploadsDir.canWrite() )
            throw new BadRequestException( locale.getString("www.error.uploadsDirNotWritable"), 500 );

    }
View Full Code Here

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

        final Properties p = getProperties();
        final Request req = getRequest();
        final User user = getUser();
        final Locale locale = getLocale();
       
        if ( p.get(Constants.WWW_USERS_DISABLE_REGISTRATION).equals(Properties.YES) )
            throw new BadRequestException( locale.getString("www.error.registrationDisabled"), 403 );
        if ( user != null )
            throw new BadRequestException( locale.getString("www.error.alreadyLoggedIn"), 403 );

        final String todo = req.getArgument( "todo" );
       
        // try and register the user?
        if ( todo.equals("register") )           
View Full Code Here

     */

    protected void registerUser() throws BadRequestException, SQLException, IOException {
   
        final Request req = getRequest();
        final Locale locale = getLocale();
        final Properties p = getProperties();
       
        final String name = req.getArgument( "name" ).trim();
        final String pass1 = req.getArgument( "pass1" );
        final String pass2 = req.getArgument( "pass2" );
        final String email = req.getArgument( "email" ).trim();
       
        final Database db = getDatabase();
        final Validater v = new Validater( db );
       
        if ( !v.checkRequiredFields(new String[]{name,pass1,email}) )
            throw new BadRequestException( locale.getString("www.error.missingField") );
        if ( !pass1.equals(pass2) )
            throw new BadRequestException( locale.getString("www.error.passwordsDontMatch") );
        if ( !v.isValidEmail(email) )
            throw new BadRequestException( locale.getString("www.error.invalidEmail") );
        if ( v.usernameExists(name) )
            throw new BadRequestException( locale.getString("www.error.duplicateUsername") );
        if ( v.emailExists(email) )
            throw new BadRequestException( locale.getString("www.error.duplicateEmail") );

        User newUser = new User( -1, name, pass1, email );
        newUser.setActive( !p.get(Constants.WWW_USERS_REQUIRE_ACTIVATION).equals(Properties.YES) );
        newUser.save( db );

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.