172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project/*
272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project * Copyright (C) 2007-2008 Esmertec AG.
372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project * Copyright (C) 2007-2008 The Android Open Source Project
472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project *
572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project * you may not use this file except in compliance with the License.
772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project * You may obtain a copy of the License at
872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project *
972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
1072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project *
1172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project * Unless required by applicable law or agreed to in writing, software
1272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
1372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project * See the License for the specific language governing permissions and
1572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project * limitations under the License.
1672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project */
1772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
1872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Projectpackage com.android.mms.dom.smil;
1972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
2072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Projectimport org.w3c.dom.DOMException;
2172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Projectimport org.w3c.dom.Element;
2272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Projectimport org.w3c.dom.smil.Time;
2372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
2472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Projectpublic class TimeImpl implements Time {
2572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    static final int ALLOW_INDEFINITE_VALUE = (1 << 0);
2672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    static final int ALLOW_OFFSET_VALUE     = (1 << 1);
2772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    static final int ALLOW_SYNCBASE_VALUE   = (1 << 2);
2872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    static final int ALLOW_SYNCTOPREV_VALUE = (1 << 3);
2972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    static final int ALLOW_EVENT_VALUE      = (1 << 4);
3072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    static final int ALLOW_MARKER_VALUE     = (1 << 5);
3172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    static final int ALLOW_WALLCLOCK_VALUE  = (1 << 6);
3272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    static final int ALLOW_NEGATIVE_VALUE   = (1 << 7);
3372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    static final int ALLOW_ALL              = 0xFF;
3472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
3572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    short mTimeType;
3672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    boolean mResolved;
3772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    double mResolvedOffset;
3872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
3972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    /**
4072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Creates a TimeImpl representation of a time-value represented as a String.
4172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Time-values have the following syntax:
4272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * <p>
4372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * <pre>
4472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Time-val ::= ( smil-1.0-syncbase-value
4572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *                          | "indefinite"
4672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *                          | offset-value
4772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *                          | syncbase-value
4872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *                          | syncToPrev-value
4972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *                          | event-value
5072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *                          | media-marker-value
5172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *                          | wallclock-sync-value )
5272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Smil-1.0-syncbase-value ::=
5372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *          "id(" id-ref ")" ( "(" ( "begin" | "end" | clock-value ) ")" )?
5472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Offset-value         ::= ( "+" | "-" )? clock-value
5572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Syncbase-value       ::= ( id-ref "." ( "begin" | "end" ) ) ( ( "+" | "-" ) clock-value )?
5672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * SyncToPrev-value     ::= ( "prev.begin" | "prev.end" ) ( ( "+" | "-" ) clock-value )?
5772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Event-value          ::= ( id-ref "." )? ( event-ref  ) ( ( "+" | "-" ) clock-value )?
5872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Media-marker-value   ::= id-ref ".marker(" marker-name ")"
5972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Wallclock-sync-value ::= "wallclock(" wallclock-value ")"
6072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * </pre>
6172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *
6272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @param timeValue A String in the representation specified above
6372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @param constraints Any combination of the #ALLOW_* flags
6472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @return  A TimeImpl instance representing
6572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @exception java.lang.IllegalArgumentException if the timeValue input
6672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *          parameter does not comply with the defined syntax
6772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @exception java.lang.NullPointerException if the timekValue string is
6872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *          <code>null</code>
6972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     */
7072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    TimeImpl(String timeValue, int constraints) {
7172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        /*
7272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project         * We do not support yet:
7372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project         *      - smil-1.0-syncbase-value
7472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project         *      - syncbase-value
7572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project         *      - syncToPrev-value
7672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project         *      - event-value
7772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project         *      - Media-marker-value
7872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project         *      - Wallclock-sync-value
7972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project         */
8072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        // Will throw NullPointerException if timeValue is null
8172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        if (timeValue.equals("indefinite")
8272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                && ((constraints & ALLOW_INDEFINITE_VALUE) != 0) ) {
8372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            mTimeType = SMIL_TIME_INDEFINITE;
8472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        } else if ((constraints & ALLOW_OFFSET_VALUE) != 0) {
8572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            int sign = 1;
8672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            if (timeValue.startsWith("+")) {
8772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                timeValue = timeValue.substring(1);
8872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            } else if (timeValue.startsWith("-")) {
8972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                timeValue = timeValue.substring(1);
9072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                sign = -1;
9172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            }
9272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            mResolvedOffset = sign*parseClockValue(timeValue)/1000.0;
9372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            mResolved = true;
9472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            mTimeType = SMIL_TIME_OFFSET;
9572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        } else {
9672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            throw new IllegalArgumentException("Unsupported time value");
9772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        }
9872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
9972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
10072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    /**
10172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Converts a String representation of a clock value into the float
10272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * representation used in this API.
10372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * <p>
10472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Clock values have the following syntax:
10572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * </p>
10672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * <p>
10772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * <pre>
10872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Clock-val         ::= ( Full-clock-val | Partial-clock-val | Timecount-val )
10972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Full-clock-val    ::= Hours ":" Minutes ":" Seconds ("." Fraction)?
11072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Partial-clock-val ::= Minutes ":" Seconds ("." Fraction)?
11172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Timecount-val     ::= Timecount ("." Fraction)? (Metric)?
11272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Metric            ::= "h" | "min" | "s" | "ms"
11372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Hours             ::= DIGIT+; any positive number
11472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Minutes           ::= 2DIGIT; range from 00 to 59
11572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Seconds           ::= 2DIGIT; range from 00 to 59
11672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Fraction          ::= DIGIT+
11772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Timecount         ::= DIGIT+
11872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * 2DIGIT            ::= DIGIT DIGIT
11972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * DIGIT             ::= [0-9]
12072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * </pre>
12172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *
12272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @param clockValue A String in the representation specified above
12372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @return  A float value in milliseconds that matches the string
12472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *          representation given as the parameter
12572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @exception java.lang.IllegalArgumentException if the clockValue input
12672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *          parameter does not comply with the defined syntax
12772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @exception java.lang.NullPointerException if the clockValue string is
12872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     *          <code>null</code>
12972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     */
13072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public static float parseClockValue(String clockValue) {
13172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        try {
13272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            float result = 0;
13372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
13472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            // Will throw NullPointerException if clockValue is null
13572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            clockValue = clockValue.trim();
13672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
13772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            // Handle first 'Timecount-val' cases with metric
13872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            if (clockValue.endsWith("ms")) {
13972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                result = parseFloat(clockValue, 2, true);
14072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            } else if (clockValue.endsWith("s")) {
14172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                result = 1000*parseFloat(clockValue, 1, true);
14272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            } else if (clockValue.endsWith("min")) {
14372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                result = 60000*parseFloat(clockValue, 3, true);
14472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            } else if (clockValue.endsWith("h")) {
14572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                result = 3600000*parseFloat(clockValue, 1, true);
14672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            } else {
14772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                // Handle Timecount-val without metric
14872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                try {
14972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                    return parseFloat(clockValue, 0, true) * 1000;
15072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                } catch (NumberFormatException _) {
15172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                    // Ignore
15272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                }
15372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
15472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                // Split in {[Hours], Minutes, Seconds}
15572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                String[] timeValues = clockValue.split(":");
15672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
15772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                // Read Hours if present and remember location of Minutes
15872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                int indexOfMinutes;
15972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                if (timeValues.length == 2) {
16072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                    indexOfMinutes = 0;
16172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                } else if (timeValues.length == 3) {
16272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                    result = 3600000*(int)parseFloat(timeValues[0], 0, false);
16372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                    indexOfMinutes = 1;
16472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                } else {
16572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                    throw new IllegalArgumentException();
16672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                }
16772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
16872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                // Read Minutes
16972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                int minutes = (int)parseFloat(timeValues[indexOfMinutes], 0, false);
17072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                if ((minutes >= 00) && (minutes <= 59)) {
17172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                    result += 60000*minutes;
17272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                } else {
17372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                    throw new IllegalArgumentException();
17472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                }
17572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
17672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                // Read Seconds
17772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                float seconds = parseFloat(timeValues[indexOfMinutes + 1], 0, true);
17872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                if ((seconds >= 00) && (seconds < 60)) {
17972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                    result += 60000*seconds;
18072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                } else {
18172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                    throw new IllegalArgumentException();
18272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                }
18372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
18472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            }
18572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            return result;
18672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        } catch (NumberFormatException e) {
18772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            throw new IllegalArgumentException();
18872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        }
18972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
19072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
19172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    /**
19272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Parse a value formatted as follows:
19372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * <p>
19472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * <pre>
19572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Value    ::= Number ("." Decimal)? (Text)?
19672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Number   ::= DIGIT+; any positive number
19772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Decimal  ::= DIGIT+; any positive number
19872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Text     ::= CHAR*;   any sequence of chars
19972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * DIGIT    ::= [0-9]
20072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * </pre>
20172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @param value The Value to parse
20272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @param ignoreLast The size of Text to ignore
20372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @param parseDecimal Whether Decimal is expected
20472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @return The float value without Text, rounded to 3 digits after '.'
20572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * @throws IllegalArgumentException if Decimal was not expected but encountered
20672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     */
20772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    private static float parseFloat(String value, int ignoreLast, boolean parseDecimal) {
20872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        // Ignore last characters
20972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        value = value.substring(0, value.length() - ignoreLast);
21072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
21172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        float result;
21272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        int indexOfComma = value.indexOf('.');
21372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        if (indexOfComma != -1) {
21472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            if (!parseDecimal) {
21572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                throw new IllegalArgumentException("int value contains decimal");
21672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            }
21772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            // Ensure that there are at least 3 decimals
21872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            value = value + "000";
21972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            // Read value up to 3 decimals and cut the rest
22072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            result = Float.parseFloat(value.substring(0, indexOfComma));
22172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            result += Float.parseFloat(
22272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project                    value.substring(indexOfComma + 1, indexOfComma + 4))/1000;
22372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        } else {
22472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project            result = Integer.parseInt(value);
22572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        }
22672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
22772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        return result;
22872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
22972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
23072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    /*
23172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     * Time Interface
23272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project     */
23372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
23472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public boolean getBaseBegin() {
23572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        // TODO Auto-generated method stub
23672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        return false;
23772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
23872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
23972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public Element getBaseElement() {
24072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        // TODO Auto-generated method stub
24172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        return null;
24272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
24372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
24472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public String getEvent() {
24572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        // TODO Auto-generated method stub
24672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        return null;
24772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
24872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
24972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public String getMarker() {
25072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        // TODO Auto-generated method stub
25172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        return null;
25272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
25372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
25472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public double getOffset() {
25572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        // TODO Auto-generated method stub
25672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        return 0;
25772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
25872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
25972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public boolean getResolved() {
26072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        return mResolved;
26172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
26272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
26372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public double getResolvedOffset() {
26472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        return mResolvedOffset;
26572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
26672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
26772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public short getTimeType() {
26872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        return mTimeType;
26972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
27072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
27172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public void setBaseBegin(boolean baseBegin) throws DOMException {
27272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        // TODO Auto-generated method stub
27372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
27472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
27572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
27672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public void setBaseElement(Element baseElement) throws DOMException {
27772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        // TODO Auto-generated method stub
27872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
27972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
28072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
28172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public void setEvent(String event) throws DOMException {
28272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        // TODO Auto-generated method stub
28372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
28472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
28572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
28672735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public void setMarker(String marker) throws DOMException {
28772735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        // TODO Auto-generated method stub
28872735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
28972735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
29072735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
29172735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    public void setOffset(double offset) throws DOMException {
29272735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project        // TODO Auto-generated method stub
29372735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project
29472735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project    }
29572735c62aba8fd2a9420a0f9f83d22543e3c164fThe Android Open Source Project}
296