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

« back to all changes in this revision

Viewing changes to src/freeguide/plugins/grabber/hallmark/HallmarkParserSchedule.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:
3
3
import freeguide.common.lib.fgspecific.Application;
4
4
import freeguide.common.lib.fgspecific.data.TVChannel;
5
5
import freeguide.common.lib.fgspecific.data.TVProgramme;
 
6
import freeguide.common.lib.general.StringHelper;
6
7
import freeguide.common.lib.general.Time;
7
8
import freeguide.common.lib.grabber.HtmlHelper;
8
9
import freeguide.common.lib.grabber.LineProgrammeHelper;
9
10
import freeguide.common.lib.grabber.TimeHelper;
10
11
 
 
12
import freeguide.common.plugininterfaces.ILogger;
 
13
 
11
14
import org.xml.sax.Attributes;
12
15
import org.xml.sax.SAXException;
13
16
 
14
17
import java.io.IOException;
15
18
 
 
19
import java.text.MessageFormat;
16
20
import java.text.ParseException;
17
21
 
18
22
import java.util.ArrayList;
19
23
import java.util.List;
20
24
import java.util.Map;
21
25
import java.util.Properties;
 
26
import java.util.ResourceBundle;
22
27
import java.util.TimeZone;
23
28
import java.util.regex.Matcher;
24
29
import java.util.regex.Pattern;
30
35
 */
31
36
public class HallmarkParserSchedule extends HtmlHelper.DefaultContentHandler
32
37
{
 
38
    protected static final String TAG_A = "a";
 
39
    protected static final String TAG_TABLE = "table";
 
40
    protected static final String TAG_TR = "tr";
 
41
    protected static final String TAG_TD = "td";
 
42
    protected static final String ATTR_HREF = "href";
 
43
    protected static final String ATTR_ONMOUSEOVER = "onmouseover";
 
44
    protected static final String LINK_TO_ADOBE_COM = "http://www.adobe.com/";
 
45
    protected static final String TIMEZONES_FILE =
 
46
        "resources/plugins/grabber/hallmark/timezones.properties";
33
47
    protected static final Pattern RE_DATE =
34
48
        Pattern.compile( "\\s+(\\d{2})/(\\d{2})" );
35
49
    protected static final Pattern RE_DESCKEY =
50
64
    protected long[] prevTimes = new long[7];
51
65
    protected Time currentTime;
52
66
    protected final TVChannel channel;
53
 
    protected final Map descriptionsMap;
 
67
    protected final Map<String, List<TVProgramme>> descriptionsMap;
54
68
    protected final boolean isUS;
 
69
    protected final ResourceBundle i18n;
 
70
    protected final ILogger logger;
55
71
 
56
72
/**
57
73
     * Creates a new HallmarkScheduleParser object.
63
79
     * @throws SAXException DOCUMENT ME!
64
80
     */
65
81
    public HallmarkParserSchedule( 
66
 
        final TVChannel channel, final Map descriptionsMap, final boolean isUS )
 
82
        final TVChannel channel,
 
83
        final Map<String, List<TVProgramme>> descriptionsMap,
 
84
        final boolean isUS, final ResourceBundle i18n, final ILogger logger )
67
85
        throws SAXException
68
86
    {
69
87
        this.channel = channel;
 
88
        this.logger = logger;
 
89
        this.i18n = i18n;
70
90
 
71
91
        this.descriptionsMap = descriptionsMap;
72
92
        this.isUS = isUS;
108
128
            parseStart( qName, atts );
109
129
        }
110
130
        else if( 
111
 
            "a".equals( qName ) && ( atts.getValue( "href" ) != null )
112
 
                && atts.getValue( "href" ).startsWith( 
113
 
                    "http://www.adobe.com/" ) )
 
131
            TAG_A.equals( qName ) && ( atts.getValue( ATTR_HREF ) != null )
 
132
                && atts.getValue( ATTR_HREF ).startsWith( LINK_TO_ADOBE_COM ) )
114
133
        {
115
134
            foundAcrobat = true;
116
135
        }
117
 
        else if( "table".equals( qName ) && foundAcrobat )
 
136
        else if( TAG_TABLE.equals( qName ) && foundAcrobat )
118
137
        {
119
138
            parse = true;
120
139
            foundAcrobat = false;
152
171
    public void parseStart( String qName, Attributes atts )
153
172
        throws SAXException
154
173
    {
155
 
        if( parse && "tr".equals( qName ) )
 
174
        if( parse && TAG_TR.equals( qName ) )
156
175
        {
157
176
            row++;
158
177
            col = -1;
159
178
        }
160
 
        else if( parse && "td".equals( qName ) )
 
179
        else if( parse && TAG_TD.equals( qName ) )
161
180
        {
162
181
            col++;
163
182
            descriptionKey = null;
164
183
            descriptionText = null;
165
184
 
166
 
            String onMouseOver = atts.getValue( "onmouseover" );
 
185
            String onMouseOver = atts.getValue( ATTR_ONMOUSEOVER );
167
186
 
168
187
            if( onMouseOver != null )
169
188
            {
175
194
                }
176
195
            }
177
196
        }
178
 
        else if( "a".equals( qName ) && ( row > 0 ) && ( col > 0 ) )
 
197
        else if( TAG_A.equals( qName ) && ( row > 0 ) && ( col > 0 ) )
179
198
        {
180
 
            String ref = atts.getValue( "href" );
 
199
            String ref = atts.getValue( ATTR_HREF );
181
200
 
182
201
            if( ref != null )
183
202
            {
200
219
     */
201
220
    public void parseEnd( String qName ) throws SAXException
202
221
    {
203
 
        if( "tr".equals( qName ) )
 
222
        if( TAG_TR.equals( qName ) )
204
223
        {
205
224
            return;
206
225
        }
207
226
 
208
 
        if( "table".equals( qName ) )
 
227
        if( TAG_TABLE.equals( qName ) )
209
228
        {
210
229
            parse = false;
211
230
        }
222
241
                if( col == 0 )
223
242
                { // timezone
224
243
                    timeZoneName = text.toString(  ).trim(  );
225
 
                    timeZone = getTimeZone( timeZoneName );
 
244
                    timeZone = getTimeZone( timeZoneName, i18n, logger );
226
245
 
227
246
                    if( timeZone == null )
228
247
                    {
229
 
                        System.out.println( 
 
248
                        Application.getInstance(  ).getLogger(  )
 
249
                                   .warning( 
230
250
                            "Invalid timezone: " + text.toString(  ).trim(  ) );
231
251
                        timeZone = TimeZone.getDefault(  );
232
252
                    }
288
308
                {
289
309
                    String title = HtmlHelper.strongTrim( text.toString(  ) );
290
310
 
291
 
                    if( !"".equals( title ) && ( channel != null ) )
 
311
                    if( 
 
312
                        !StringHelper.EMPTY_STRING.equals( title )
 
313
                            && ( channel != null ) )
292
314
                    {
293
315
                        TVProgramme prog = new TVProgramme(  );
294
316
                        prog.setStart( 
324
346
 
325
347
        if( descriptionKey != null )
326
348
        {
327
 
            List list = (List)descriptionsMap.get( key );
 
349
            List<TVProgramme> list = descriptionsMap.get( key );
328
350
 
329
351
            if( list == null )
330
352
            {
331
 
                list = new ArrayList(  );
 
353
                list = new ArrayList<TVProgramme>(  );
332
354
                descriptionsMap.put( key, list );
333
355
            }
334
356
 
340
362
     * DOCUMENT_ME!
341
363
     *
342
364
     * @param hallmarkTimezone DOCUMENT_ME!
 
365
     * @param i18n DOCUMENT ME!
 
366
     * @param logger DOCUMENT ME!
343
367
     *
344
368
     * @return DOCUMENT_ME!
345
369
     */
346
370
    public synchronized static TimeZone getTimeZone( 
347
 
        final String hallmarkTimezone )
 
371
        final String hallmarkTimezone, final ResourceBundle i18n,
 
372
        final ILogger logger )
348
373
    {
349
374
        if( TIMEZONES.size(  ) == 0 )
350
375
        {
353
378
                TIMEZONES.load( 
354
379
                    HallmarkParserSchedule.class.getClassLoader(  )
355
380
                                                .getResourceAsStream( 
356
 
                        "resources/plugins/grabber/hallmark/timezones.properties" ) );
 
381
                        TIMEZONES_FILE ) );
357
382
            }
358
383
            catch( IOException ex )
359
384
            {
367
392
 
368
393
        if( tzName == null )
369
394
        {
370
 
            Application.getInstance(  ).getLogger(  )
371
 
                       .warning( "Unknown timezone: " + tzName );
 
395
            if( logger != null )
 
396
            {
 
397
                logger.warning( 
 
398
                    MessageFormat.format( 
 
399
                        i18n.getString( "Logging.UnknownTimeZone" ), tzName ) );
 
400
            }
372
401
 
373
402
            return TimeZone.getDefault(  );
374
403
        }