java/src/main/java/com/genexus/filters/ExpiresFilter.java
/**
     * Parse configuration lines like '
     * <tt>access plus 1 month 15 days 2 hours</tt>' or '
     * <tt>modification 1 day 2 hours 5 seconds</tt>'
     * 
     * @param line
     */
Parse configuration lines like '
access plus 1 month 15 days 2 hours' or '
modification 1 day 2 hours 5 seconds'

@param line
Parse configuration lines like ' access plus 1 month 15 days 2 hours ' or ' modification 1 day 2 hours 5 seconds ' @param line
protected ExpiresConfiguration parseExpiresConfiguration(String line) {
        line = line.trim();
        StringTokenizer tokenizer = new StringTokenizer(line, " ");
        String currentToken;
        try {
            currentToken = tokenizer.nextToken();
        } catch (NoSuchElementException e) {
            throw new IllegalStateException("Starting point (access|now|modification|a<seconds>|m<seconds>) not found in directive '"
                    + line + "'");
        }
        StartingPoint startingPoint;
        if ("access".equalsIgnoreCase(currentToken) || "now".equalsIgnoreCase(currentToken)) {
            startingPoint = StartingPoint.ACCESS_TIME;
        } else if ("modification".equalsIgnoreCase(currentToken)) {
            startingPoint = StartingPoint.LAST_MODIFICATION_TIME;
        } else if (!tokenizer.hasMoreTokens() && startsWithIgnoreCase(currentToken, "a")) {
            startingPoint = StartingPoint.ACCESS_TIME;
            tokenizer = new StringTokenizer(currentToken.substring(1) + " seconds", " ");
        } else if (!tokenizer.hasMoreTokens() && startsWithIgnoreCase(currentToken, "m")) {
            startingPoint = StartingPoint.LAST_MODIFICATION_TIME;
            tokenizer = new StringTokenizer(currentToken.substring(1) + " seconds", " ");
        } else {
            throw new IllegalStateException("Invalid starting point (access|now|modification|a<seconds>|m<seconds>) '" + currentToken
                    + "' in directive '" + line + "'");
        }
        try {
            currentToken = tokenizer.nextToken();
        } catch (NoSuchElementException e) {
            throw new IllegalStateException("Duration not found in directive '" + line + "'");
        }
        if ("plus".equalsIgnoreCase(currentToken)) {
            try {
                currentToken = tokenizer.nextToken();
            } catch (NoSuchElementException e) {
                throw new IllegalStateException("Duration not found in directive '" + line + "'");
            }
        }
        List<Duration> durations = new ArrayList<Duration>();
        while (currentToken != null) {
            int amount;
            try {
                amount = Integer.parseInt(currentToken);
            } catch (NumberFormatException e) {
                throw new IllegalStateException("Invalid duration (number) '" + currentToken + "' in directive '" + line + "'");
            }
            try {
                currentToken = tokenizer.nextToken();
            } catch (NoSuchElementException e) {
                throw new IllegalStateException("Duration unit not found after amount " + amount + " in directive '" + line + "'");
            }
            DurationUnit durationUnit;
            if ("years".equalsIgnoreCase(currentToken)) {
                durationUnit = DurationUnit.YEAR;
            } else if ("month".equalsIgnoreCase(currentToken) || "months".equalsIgnoreCase(currentToken)) {
                durationUnit = DurationUnit.MONTH;
            } else if ("week".equalsIgnoreCase(currentToken) || "weeks".equalsIgnoreCase(currentToken)) {
                durationUnit = DurationUnit.WEEK;
            } else if ("day".equalsIgnoreCase(currentToken) || "days".equalsIgnoreCase(currentToken)) {
                durationUnit = DurationUnit.DAY;
            } else if ("hour".equalsIgnoreCase(currentToken) || "hours".equalsIgnoreCase(currentToken)) {
                durationUnit = DurationUnit.HOUR;
            } else if ("minute".equalsIgnoreCase(currentToken) || "minutes".equalsIgnoreCase(currentToken)) {
                durationUnit = DurationUnit.MINUTE;
            } else if ("second".equalsIgnoreCase(currentToken) || "seconds".equalsIgnoreCase(currentToken)) {
                durationUnit = DurationUnit.SECOND;
            } else {
                throw new IllegalStateException("Invalid duration unit (years|months|weeks|days|hours|minutes|seconds) '" + currentToken
                        + "' in directive '" + line + "'");
            }
            Duration duration = new Duration(amount, durationUnit);
            durations.add(duration);
            if (tokenizer.hasMoreTokens()) {
                currentToken = tokenizer.nextToken();
            } else {
                currentToken = null;
            }
        }
        return new ExpiresConfiguration(startingPoint, durations);
    }
protected ExpiresConfiguration parseExpiresConfiguration ( String line ) { line = line . trim ( ) ; StringTokenizer tokenizer = new StringTokenizer ( line , " " ) ; String currentToken ; try { currentToken = tokenizer . nextToken ( ) ; } catch ( NoSuchElementException e ) { throw new IllegalStateException ( "Starting point (access|now|modification|a<seconds>|m<seconds>) not found in directive '" + line + "'" ) ; } StartingPoint startingPoint ; if ( "access" . equalsIgnoreCase ( currentToken ) || "now" . equalsIgnoreCase ( currentToken ) ) { startingPoint = StartingPoint . ACCESS_TIME ; } else if ( "modification" . equalsIgnoreCase ( currentToken ) ) { startingPoint = StartingPoint . LAST_MODIFICATION_TIME ; } else if ( ! tokenizer . hasMoreTokens ( ) && startsWithIgnoreCase ( currentToken , "a" ) ) { startingPoint = StartingPoint . ACCESS_TIME ; tokenizer = new StringTokenizer ( currentToken . substring ( 1 ) + " seconds" , " " ) ; } else if ( ! tokenizer . hasMoreTokens ( ) && startsWithIgnoreCase ( currentToken , "m" ) ) { startingPoint = StartingPoint . LAST_MODIFICATION_TIME ; tokenizer = new StringTokenizer ( currentToken . substring ( 1 ) + " seconds" , " " ) ; } else { throw new IllegalStateException ( "Invalid starting point (access|now|modification|a<seconds>|m<seconds>) '" + currentToken + "' in directive '" + line + "'" ) ; } try { currentToken = tokenizer . nextToken ( ) ; } catch ( NoSuchElementException e ) { throw new IllegalStateException ( "Duration not found in directive '" + line + "'" ) ; } if ( "plus" . equalsIgnoreCase ( currentToken ) ) { try { currentToken = tokenizer . nextToken ( ) ; } catch ( NoSuchElementException e ) { throw new IllegalStateException ( "Duration not found in directive '" + line + "'" ) ; } } List < Duration > durations = new ArrayList < Duration > ( ) ; while ( currentToken != null ) { int amount ; try { amount = Integer . parseInt ( currentToken ) ; } catch ( NumberFormatException e ) { throw new IllegalStateException ( "Invalid duration (number) '" + currentToken + "' in directive '" + line + "'" ) ; } try { currentToken = tokenizer . nextToken ( ) ; } catch ( NoSuchElementException e ) { throw new IllegalStateException ( "Duration unit not found after amount " + amount + " in directive '" + line + "'" ) ; } DurationUnit durationUnit ; if ( "years" . equalsIgnoreCase ( currentToken ) ) { durationUnit = DurationUnit . YEAR ; } else if ( "month" . equalsIgnoreCase ( currentToken ) || "months" . equalsIgnoreCase ( currentToken ) ) { durationUnit = DurationUnit . MONTH ; } else if ( "week" . equalsIgnoreCase ( currentToken ) || "weeks" . equalsIgnoreCase ( currentToken ) ) { durationUnit = DurationUnit . WEEK ; } else if ( "day" . equalsIgnoreCase ( currentToken ) || "days" . equalsIgnoreCase ( currentToken ) ) { durationUnit = DurationUnit . DAY ; } else if ( "hour" . equalsIgnoreCase ( currentToken ) || "hours" . equalsIgnoreCase ( currentToken ) ) { durationUnit = DurationUnit . HOUR ; } else if ( "minute" . equalsIgnoreCase ( currentToken ) || "minutes" . equalsIgnoreCase ( currentToken ) ) { durationUnit = DurationUnit . MINUTE ; } else if ( "second" . equalsIgnoreCase ( currentToken ) || "seconds" . equalsIgnoreCase ( currentToken ) ) { durationUnit = DurationUnit . SECOND ; } else { throw new IllegalStateException ( "Invalid duration unit (years|months|weeks|days|hours|minutes|seconds) '" + currentToken + "' in directive '" + line + "'" ) ; } Duration duration = new Duration ( amount , durationUnit ) ; durations . add ( duration ) ; if ( tokenizer . hasMoreTokens ( ) ) { currentToken = tokenizer . nextToken ( ) ; } else { currentToken = null ; } } return new ExpiresConfiguration ( startingPoint , durations ) ; }
Parse configuration lines like '
 <tt>access plus 1 month 15 days 2 hours</tt>' or '
 <tt>modification 1 day 2 hours 5 seconds</tt>'
Parse configuration lines like ' <tt > access plus 1 month 15 days 2 hours< / tt > ' or ' <tt > modification 1 day 2 hours 5 seconds< / tt > '
// trick : convert duration configuration from old to new style // trick : convert duration configuration from old to new style // skip