~ubuntu-branches/ubuntu/trusty/freeguide/trusty

« back to all changes in this revision

Viewing changes to src/freeguide/plugins/grabber/vsetv/HandlerParseProg.java

  • Committer: Bazaar Package Importer
  • Author(s): Shaun Jackman
  • Date: 2007-09-11 16:52:59 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070911165259-4r32oke21i1ezbmv
Tags: 0.10.5-1
* New upstream release.
* Update the watch file.
* Change Debian policy to version 3.7.2.2. No changes necessary.
* Add ant-optional to build dependencies. Closes: #441762.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import java.io.IOException;
18
18
 
 
19
import java.text.MessageFormat;
19
20
import java.text.ParseException;
20
21
 
 
22
import java.util.ResourceBundle;
21
23
import java.util.TimeZone;
22
24
import java.util.regex.Matcher;
23
25
import java.util.regex.Pattern;
26
28
 * DOCUMENT ME!
27
29
 *
28
30
 * @author $author$
29
 
 * @version $Revision: 1425 $
 
31
 * @version $Revision: 1561 $
30
32
 */
31
33
public class HandlerParseProg extends HtmlHelper.DefaultContentHandler
32
34
{
 
35
    protected static final String TAG_A = "a";
 
36
    protected static final String TAG_BR = "br";
 
37
    protected static final String TAG_TD = "td";
 
38
    protected static final String TAG_SPAN = "span";
 
39
    protected static final String TAG_TABLE = "table";
 
40
    protected static final String ATTR_CLASS = "class";
 
41
    protected static final String LINE_BREAK_IN_STORAGE = "<br>";
33
42
    protected static final int MODES_NONE = 0;
34
43
    protected static final int MODES_TITLE = 1;
35
44
    protected static final int MODES_CHANNEL_NAME = 2;
37
46
    protected static final int MODES_PROG_TITLE = 4;
38
47
    protected static final int MODES_ANON_TIME = 5;
39
48
    protected static final int MODES_ANON_TEXT = 6;
 
49
    protected static final String CLASS_CHANNEL = "channeltitle";
 
50
    protected static final String CLASS_DATE = "pagedate2";
 
51
    protected static final String CLASS_TIME = "progtime";
 
52
    protected static final String CLASS_ANTIME = "anonstime";
 
53
    protected static final String CLASS_DESCR = "descr1";
40
54
    protected static final Pattern DATE_PATTERN =
41
55
        Pattern.compile( "(\\S+)\\s*,\\s*(\\d{1,2})\\s+(\\S+)\\s+(\\d{4})" );
42
56
    protected static final Pattern FILM_ID_PATTERN =
48
62
    protected TVProgramme currentProg;
49
63
    protected final TVData data;
50
64
    protected final TimeZone tz;
 
65
    protected final ResourceBundle i18n;
51
66
    protected boolean isAnnounces;
52
67
    protected ILogger logger;
53
68
    protected final StringBuffer currentText = new StringBuffer(  );
58
73
     * @param logger DOCUMENT ME!
59
74
     * @param tz DOCUMENT ME!
60
75
     */
61
 
    public HandlerParseProg( ILogger logger, TimeZone tz )
 
76
    public HandlerParseProg( 
 
77
        ILogger logger, TimeZone tz, final ResourceBundle i18n )
62
78
    {
63
79
        mode = MODES_NONE;
64
80
        isAnnounces = false;
65
81
        this.logger = logger;
66
82
        this.data = new TVData(  );
67
83
        this.tz = tz;
 
84
        this.i18n = i18n;
68
85
    }
69
86
 
70
87
    /**
102
119
        case MODES_NONE:
103
120
 
104
121
            if( 
105
 
                "td".equals( qName )
106
 
                    && "channeltitle".equals( atts.getValue( "class" ) ) )
 
122
                TAG_TD.equals( qName )
 
123
                    && CLASS_CHANNEL.equals( atts.getValue( ATTR_CLASS ) ) )
107
124
            {
108
125
                mode = MODES_CHANNEL_NAME;
109
126
                prevTime = 0;
110
127
                currentProg = null;
111
128
            }
112
129
            else if( 
113
 
                "span".equals( qName )
114
 
                    && "pagedate".equals( atts.getValue( "class" ) ) )
 
130
                TAG_SPAN.equals( qName )
 
131
                    && CLASS_DATE.equals( atts.getValue( ATTR_CLASS ) ) )
115
132
            {
116
133
                mode = MODES_TITLE;
117
134
                prevTime = 0;
118
135
            }
119
136
            else if( 
120
 
                "td".equals( qName )
121
 
                    && "progtime".equals( atts.getValue( "class" ) ) )
 
137
                TAG_TD.equals( qName )
 
138
                    && CLASS_TIME.equals( atts.getValue( ATTR_CLASS ) ) )
122
139
            {
123
140
                mode = MODES_PROG_TIME;
124
141
            }
125
142
            else if( 
126
 
                "td".equals( qName )
127
 
                    && "anonstime".equals( atts.getValue( "class" ) ) )
 
143
                TAG_TD.equals( qName )
 
144
                    && CLASS_ANTIME.equals( atts.getValue( ATTR_CLASS ) ) )
128
145
            {
129
146
                mode = MODES_ANON_TIME;
130
147
            }
131
148
            else if( 
132
 
                "span".equals( qName )
133
 
                    && "descr1".equals( atts.getValue( "class" ) ) )
 
149
                TAG_SPAN.equals( qName )
 
150
                    && CLASS_DESCR.equals( atts.getValue( ATTR_CLASS ) ) )
134
151
            {
135
152
                mode = MODES_ANON_TEXT;
136
153
            }
143
160
            {
144
161
                currentProg.addDesc( text );
145
162
 
146
 
                if( "br".equals( qName ) )
 
163
                if( TAG_BR.equals( qName ) )
147
164
                {
148
 
                    currentProg.addDesc( "<br>" );
 
165
                    currentProg.addDesc( LINE_BREAK_IN_STORAGE );
149
166
                }
150
167
            }
151
168
 
174
191
 
175
192
            Matcher titleMatcher = DATE_PATTERN.matcher( text );
176
193
 
177
 
            if( !titleMatcher.matches(  ) )
178
 
            {
179
 
                throw new SAXException( 
180
 
                    "Error in page format: invalid title format" );
181
 
            }
182
 
 
183
 
            try
184
 
            {
185
 
                currentDate = TimeHelper.getBaseDate( 
186
 
                        tz, titleMatcher.group( 2 ), titleMatcher.group( 3 ),
187
 
                        titleMatcher.group( 4 ), titleMatcher.group( 1 ) );
188
 
                prevTime = 0;
189
 
            }
190
 
            catch( ParseException ex )
191
 
            {
192
 
                logger.warning( "Error parse : " + text );
 
194
            if( titleMatcher.matches(  ) )
 
195
            {
 
196
                try
 
197
                {
 
198
                    currentDate = TimeHelper.getBaseDate( 
 
199
                            tz, titleMatcher.group( 2 ),
 
200
                            titleMatcher.group( 3 ), titleMatcher.group( 4 ),
 
201
                            titleMatcher.group( 1 ) );
 
202
                    prevTime = 0;
 
203
                }
 
204
                catch( ParseException ex )
 
205
                {
 
206
                    logger.warning( 
 
207
                        MessageFormat.format( 
 
208
                            i18n.getString( "Logging.ErrorParse" ), text ) );
 
209
                }
193
210
            }
194
211
 
195
212
            mode = MODES_NONE;
206
223
 
207
224
            String channelName = text;
208
225
            currentChannel = data.get( 
209
 
                    "vsetv/" + channelName.replace( '/', '_' ) );
 
226
                    GrabberVsetv.CHANNEL_PREFIX
 
227
                    + channelName.replace( '/', '_' ) );
210
228
            currentChannel.setDisplayName( channelName );
211
229
 
212
230
            mode = MODES_NONE;
251
269
 
252
270
            if( currentProg != null )
253
271
            {
254
 
                if( "td".equals( qName ) || "a".equals( qName ) )
 
272
                if( TAG_TD.equals( qName ) || TAG_A.equals( qName ) )
255
273
                {
256
274
                    currentProg.setTitle( text );
257
275
                    mode = MODES_NONE;
320
338
            break;
321
339
        }
322
340
 
323
 
        if( "table".equals( qName ) )
 
341
        if( TAG_TABLE.equals( qName ) )
324
342
        {
325
343
            mode = MODES_NONE;
326
344
        }