Developer Area

root/apps/blackberry/branches/1.5/blackberry/src/org/telnic/blackberry/util/listcallbacks/LookupResultsListCallback.java @ 571

Revision 571, 30.4 kB (checked in by jonmaycock, 10 months ago)

Lookup display changes.

Line 
1/******************************************************************
2Copyright (c) 2008, Telnic Ltd.
3
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are
7met:
8
9*   Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11*   Redistributions in binary form must reproduce the above
12copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
13*   Neither the name of the Telnic Ltd. nor the names of its
14contributors may be used to endorse or promote products derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
18*****************************************************************/
19
20package org.telnic.blackberry.util.listcallbacks;
21
22import java.io.UnsupportedEncodingException;
23import java.util.Enumeration;
24import java.util.Vector;
25
26import net.rim.device.api.i18n.ResourceBundle;
27import net.rim.device.api.system.Bitmap;
28import net.rim.device.api.ui.Font;
29import net.rim.device.api.ui.Graphics;
30import net.rim.device.api.ui.component.ListField;
31import net.rim.device.api.ui.component.ListFieldCallback;
32
33import org.bouncycastle.util.encoders.Base64;
34import org.telnic.blackberry.TelnameApp;
35import org.telnic.blackberry.TelnameAppResource;
36import org.telnic.blackberry.dns.DNSLocResourceRecord;
37import org.telnic.blackberry.dns.DNSTelnameNaptrResourceRecord;
38import org.telnic.blackberry.options.Options;
39import org.telnic.blackberry.util.Logger;
40
41/**
42 * Provides drawing functionality for the list object displaying lookup results
43 *
44 * @author Ben Dowling, Jonathan Maycock
45 * @version $Id: LookupResultsListCallback.java,v 1.12 2009/11/06 11:54:16 jm2 Exp $
46 */
47public class LookupResultsListCallback implements ListFieldCallback
48{
49    /**
50     * Denotes the back item.
51     */
52    public static int NONE = 0;
53
54    /**
55     * Denotes the back item.
56     */
57    public static int BACK_ELEMENT = 1;
58
59    /**
60     *  Dentotes the keyword item.
61     */
62    public static int KEYWORD_ELEMENT = 2;
63
64    /** The tel icon. */
65    private Bitmap telIcon = Bitmap.getBitmapResource( "tel16.png" );
66   
67    /** The phone icon. */
68    private Bitmap phoneIcon = Bitmap.getBitmapResource( "phone_16x16.gif" );
69
70    /** The sms icon. */
71    private Bitmap smsIcon = Bitmap.getBitmapResource( "sms_16x16.gif" );
72   
73    /** The fax icon. */
74    private Bitmap faxIcon = Bitmap.getBitmapResource( "fax_16x16.gif" );
75   
76    /** The email icon. */
77    private Bitmap emailIcon = Bitmap.getBitmapResource( "email_16x16.gif" );
78   
79    /** The web icon. */
80    private Bitmap webIcon = Bitmap.getBitmapResource( "web_16x16.gif" );       
81
82    /** The gtalk im icon. */
83    private Bitmap gtalkIcon = Bitmap.getBitmapResource( "im_16x16.gif" );
84   
85    /** The xmppIcon im icon. */
86    private Bitmap xmppIcon = Bitmap.getBitmapResource( "im_16x16.gif" );
87
88    /** The xmppIcon im icon. */
89    private Bitmap xmppVoiceIcon = Bitmap.getBitmapResource( "voip_16x16.gif" );
90
91    /** The aim im icon. */
92    private Bitmap aimIcon = Bitmap.getBitmapResource( "im_16x16.gif" );
93
94    /** The aim im icon. */
95    private Bitmap aimVoiceIcon = Bitmap.getBitmapResource( "voip_16x16.gif" );
96   
97    /** The mobile icon. */
98    private Bitmap mobileIcon = Bitmap.getBitmapResource( "mobile_16x16.gif" );         
99
100    /** The ftp icon. */
101    private Bitmap ftpIcon = Bitmap.getBitmapResource( "ftp_16x16.gif" );
102
103    /** The sip icon. */
104    private Bitmap sipIcon = Bitmap.getBitmapResource( "voip_16x16.gif" );
105   
106    /** The h323 icon. */
107    private Bitmap h323Icon = Bitmap.getBitmapResource( "voip_16x16.gif" );
108
109    /** The msn im icon. */
110    private Bitmap msnInstantIcon = Bitmap.getBitmapResource( "im_16x16.gif" );
111   
112    /** The msn voice icon. */
113    private Bitmap msnVoiceIcon = Bitmap.getBitmapResource( "voip_16x16.gif" );
114   
115    /** The skype voice icon. */
116    private Bitmap skypeInstantIcon = Bitmap.getBitmapResource( "im_16x16.gif" );
117   
118    /** The skype voice icon. */
119    private Bitmap skypeVoiceIcon = Bitmap.getBitmapResource( "voip_16x16.gif" );
120
121    /** The yahoo icon. */
122    private Bitmap yahooIcon = Bitmap.getBitmapResource( "im_16x16.gif" );
123   
124    /** The icq icon. */
125    private Bitmap icqIcon = Bitmap.getBitmapResource( "im_16x16.gif" );
126
127    /** The ntn icon. */
128    private Bitmap ntnIcon = Bitmap.getBitmapResource( "link_16x16.gif" );
129
130    /** The ntn icon. */
131    private Bitmap ntnBackIcon = Bitmap.getBitmapResource( "link_16x16_rotated.gif" );
132
133    /** The world icon. */
134    private Bitmap worldIcon = Bitmap.getBitmapResource( "location_16x16.gif" );
135   
136    /** The note icon. */
137    private Bitmap noteIcon = Bitmap.getBitmapResource( "info_16x16.gif" );
138   
139    /** The user icon. */
140    private Bitmap userIcon = Bitmap.getBitmapResource( "personal_16x16.gif" );
141
142    /** The blank icon. */
143    private Bitmap blankIcon = Bitmap.getBitmapResource( "blank.gif" );
144
145    /**
146     * The keywords icon.
147     */
148    private Bitmap keyIcon = Bitmap.getBitmapResource( "keywords_16x16.gif" );
149
150    /**
151     * icon.
152     */
153    private Bitmap icon;
154
155    /**
156     * The element type.
157     */
158    private final Vector elementTypes = new Vector();
159
160    /** The list. */
161    private final Vector list = new Vector();
162
163    private Vector displayList = new Vector();
164
165    /** The parsed string. */
166    private String parsedString = "";
167
168    /** The service display string. */
169    private String serviceDisplayString = "";
170
171    /**
172     * Add.
173     *
174     * @param arg0 the arg0
175     * @param rr the rr
176     */
177    public void add (final ListField arg0, final DNSTelnameNaptrResourceRecord rr)
178    {
179        try
180        {
181            if (rr != null && !list.contains( rr ))
182            {
183                String val = parseNaptrString( rr );
184                arg0.insert( list.size() );
185                list.addElement( rr );           
186                displayList.addElement( val );           
187                elementTypes.addElement( new Integer( NONE ) );
188            }
189        }
190        catch (DiscardedNaptrException d)
191        {
192            //do nothing
193            return;
194        }
195    }
196
197
198    /**
199     * Add.
200     *
201     * @param arg0 the arg0
202     * @param rr the rr
203     */
204    public void add (final ListField arg0, final DNSLocResourceRecord rr)
205    {   
206        if (rr != null && !list.contains( rr ))
207        {
208            arg0.insert( list.size() );
209            list.addElement( rr );
210            displayList.addElement( rr.toString() );
211            elementTypes.addElement( new Integer( NONE ) );
212        }               
213    }
214
215    /**
216     * Add.  used to add the back option.
217     *
218     * @param arg0 the list field
219     * @param rr the string
220     */
221    public void add (final ListField arg0, final String rr, final int type)
222    {
223
224        if (rr != null && !list.contains( rr ))
225        {
226            arg0.insert( list.size() );
227            list.addElement( rr );
228            displayList.addElement( rr );
229            elementTypes.addElement( new Integer( type ) );
230
231        }
232    }
233
234    public boolean scrollingRequired(ListField arg0, int index)
235    {
236        String element = (String) displayList.elementAt( index );
237
238        if (index == arg0.getSelectedIndex() && (arg0.getFont().getAdvance( element ) > (arg0.getWidth() - telIcon.getWidth() - 2)))
239        {
240            return true;
241        }
242        return false;
243    }
244
245    public void updateText(ListField arg0, int index)
246    {
247        String element = (String) displayList.elementAt( index );
248
249        if (index == arg0.getSelectedIndex() && (arg0.getFont().getAdvance( element ) > (arg0.getWidth() - telIcon.getWidth() - 2)))
250        {
251            element = (String) displayList.elementAt( index );
252            displayList.setElementAt( element.substring( 1 ) + element.charAt( 0 ), index );
253        }
254    }
255
256    public void resetText(ListField arg0, int index)
257    {
258        displayList = new Vector();
259        for (int i = 0; i < list.size(); i++)
260        {
261            String element = "";
262            if (list.elementAt( i ) instanceof DNSTelnameNaptrResourceRecord)
263            {
264                final DNSTelnameNaptrResourceRecord rr = (DNSTelnameNaptrResourceRecord) list.elementAt( i );
265                try
266                {
267                    element = parseNaptrString( rr );
268                }
269                catch (DiscardedNaptrException e)
270                {
271                    Logger.logMessage( "Problem with naptr: " + e.getMessage(), Options.KEY_LOG_APPLICATION );
272                }
273            }
274            if (list.elementAt( i ) instanceof String)
275            {
276                element = (String) list.elementAt( i );
277            }
278            else if (list.elementAt( i ) instanceof DNSLocResourceRecord)
279            {
280                final DNSLocResourceRecord rr = (DNSLocResourceRecord) list.elementAt( i );
281                element = rr.toString();
282            }
283            displayList.addElement( element );
284        }
285
286
287        String element = (String) displayList.elementAt( index );
288        if ((arg0.getFont().getAdvance( element ) > (Graphics.getScreenWidth() - telIcon.getWidth() - 2)))
289        {
290            displayList.setElementAt( element + "  -----  ", index );
291        }
292    }
293
294    /*
295     * (non-Javadoc)
296     *
297     * @see net.rim.device.api.ui.component.ListFieldCallback#drawListRow(net.rim.device.api.ui.component.ListField,
298     *      net.rim.device.api.ui.Graphics, int, int, int)
299     */
300    public void drawListRow (final ListField arg0, final Graphics g, final int index, final int y,
301        final int w)
302    {
303        if (list.elementAt( index ) instanceof DNSTelnameNaptrResourceRecord)
304        {
305            final DNSTelnameNaptrResourceRecord rr = (DNSTelnameNaptrResourceRecord) list.elementAt( index );
306
307            final int space = 1;
308            try
309            {
310                Object[] vals = parseNaptrStringAndIcon( rr );
311                final String element = (String) vals[0];
312               
313                if (rr.isEncrypted())
314                {
315                    g.setFont( g.getFont().derive( Font.ITALIC ) );
316                }
317                else
318                {
319                    g.setFont( g.getFont().derive( Font.PLAIN ) );
320                }
321
322                g.drawBitmap( 0, y, icon.getWidth(), icon.getHeight(), icon, 0, 0 );
323                g.drawText( (String) displayList.elementAt( index ), icon.getWidth() + space, y, 0, w );
324            }
325            catch (DiscardedNaptrException e)
326            {
327                Logger.logMessage( "Problem with NAPTR: " + e.getMessage(), Options.KEY_LOG_APPLICATION );
328            }           
329        }
330        if (list.elementAt( index ) instanceof String)
331        {
332            final String rr = (String) list.elementAt( index );
333
334            final Integer x = (Integer) elementTypes.elementAt( index );
335
336            final int space = 1;
337            if (x.intValue() == BACK_ELEMENT)
338            {
339                icon = ntnBackIcon;
340            }
341            else if (x.intValue() == KEYWORD_ELEMENT)
342            {
343                icon = keyIcon;
344            }
345            else
346            {
347                icon = blankIcon;
348            }
349
350            g.drawBitmap( 0, y, icon.getWidth(), icon.getHeight(), icon, 0, 0 );
351            g.drawText( (String) displayList.elementAt( index ), icon.getWidth() + space, y, 0, w );
352        }
353        else if (list.elementAt( index ) instanceof DNSLocResourceRecord)
354        {
355            final DNSLocResourceRecord rr = (DNSLocResourceRecord) list.elementAt( index );
356            icon = worldIcon;
357            final int space = 1;
358            final String element = rr.toString();
359
360            g.drawBitmap( 0, y, icon.getWidth(), icon.getHeight(), icon, 0, 0 );
361            g.drawText( (String) displayList.elementAt( index ), icon.getWidth() + space, y, 0, w );
362        }
363    }
364
365    /**
366     * getLocIcon.
367     *
368     * @return loc icon
369     */
370    public Bitmap getLocIcon ()
371    {
372        return worldIcon;
373    }
374
375    /**
376     * returns the element type
377     */
378    public int getElementType(int index)
379    {
380        Integer x = (Integer) elementTypes.elementAt( index );
381        return x.intValue();
382    }
383
384
385    /**
386     * parse naptr string and icon.
387     *
388     * @param rr the rr
389     * @return object
390     */
391    public Object[] parseNaptrStringAndIcon (DNSTelnameNaptrResourceRecord rr)  throws DiscardedNaptrException
392    {
393        String element = "";
394        serviceDisplayString = "";
395
396        if (rr.isNonTerminal())
397        {
398            element = rr.getNTNDisplayName();
399            icon = ntnIcon;
400            serviceDisplayString = TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_NTN );
401        }
402        else
403        {           
404            String service = rr.getServiceType();
405           
406            element = rr.getUri();
407            Vector categories = rr.getCategories();
408           
409            //calculate LIH prefix
410            if (categories.size() > 0)
411            {
412                Enumeration e = categories.elements();
413                serviceDisplayString += parseLIH( (String) e.nextElement() );
414               
415                while (e.hasMoreElements())
416                {
417                    serviceDisplayString += " " + TelnameApp.getResourceBundle().getString( TelnameAppResource.AND ) + " ";
418                    serviceDisplayString += parseLIH( (String) e.nextElement() );
419                }
420               
421                serviceDisplayString += " ";               
422            }                                   
423                                                                           
424//          Phone**************************************************************************
425            if (service.indexOf( "voice:tel" ) >= 0)
426            {               
427                checkUriType( service, element );
428                icon = phoneIcon;
429                if (categories.contains( "x-mobile" ))
430                {
431                    icon = mobileIcon;
432                }
433                element = element.substring( element.indexOf( ":" ) + 1 );
434                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_PHONE );           
435            }
436            else if (service.indexOf( "fax:tel" ) >= 0)
437            {
438                checkUriType( service, element );
439                icon = faxIcon;
440                element = element.substring( element.indexOf( ":" ) + 1 );
441                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_FAX );               
442            }
443            else if (service.indexOf( "sms:tel" ) >= 0 || service.indexOf( "sms:mailto" ) >= 0)
444            {
445                checkUriType( service, element );
446                icon = smsIcon;
447                element = element.substring( element.indexOf( ":" ) + 1 );
448                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_SMS );
449            }
450            else if (service.indexOf( "ems:tel" ) >= 0 || service.indexOf( "ems:mailto" ) >= 0)
451            {
452                checkUriType( service, element );
453                icon = smsIcon;
454                element = element.substring( element.indexOf( ":" ) + 1 );
455                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_EMS );
456            }
457            else if (service.indexOf( "mms:tel" ) >= 0 || service.indexOf( "mms:mailto" ) >= 0)
458            {
459                checkUriType( service, element );
460                icon = smsIcon;
461                element = element.substring( element.indexOf( ":" ) + 1 );
462                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_MMS );
463            }
464
465            //AIM**************************************************************************
466            else if (service.indexOf( "x-im:aim" ) >= 0)
467            {
468                checkUriType( service, element );
469                icon = aimIcon;
470                element = element.substring( element.indexOf( ":" ) + 1 );
471                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_AIM_MESS );
472            }
473            else if (service.indexOf( "x-voice:aim" ) >= 0)
474            {
475                checkUriType( service, element );
476                icon = aimVoiceIcon;
477                element = element.substring( element.indexOf( ":" ) + 1 );
478                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_AIM_VOICE );
479            }           
480
481            // XMPP/GTALK*******************************************************************
482            else if (service.indexOf( "x-im:xmpp" ) >= 0)
483            {
484                checkUriType( service, element );
485                icon = xmppIcon;
486                element = element.substring( element.indexOf( ":" ) + 1 );
487                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_XMPP_MESS );
488            }
489            else if (service.indexOf( "x-voice:gtalk" ) >= 0)
490            {
491                checkUriType( service, element );
492                icon = xmppVoiceIcon;
493                element = element.substring( element.indexOf( ":" ) + 1 );
494                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_GTALK_VOICE );
495            }
496            else if (service.indexOf( "x-im:gtalk" ) >= 0)
497            {
498                checkUriType( service, element );
499                icon = gtalkIcon;
500                element = element.substring( element.indexOf( ":" ) + 1 );
501                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_GTALK_MESS );
502            }
503           
504//          SKYPE***************************************************************************           
505            else if (service.indexOf( "x-voice:skype" ) >= 0)
506            {
507                checkUriType( service, element );
508                icon = skypeVoiceIcon;
509                element = element.substring( element.indexOf( ":" ) + 1 );
510                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_SKYPE_VOICE );
511            }
512            else if (service.indexOf( "x-im:skype" ) >= 0)
513            {
514                checkUriType( service, element );
515                icon = skypeInstantIcon;
516                element = element.substring( element.indexOf( ":" ) + 1 );
517                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_SKYPE_IM );
518            }
519           
520//          MSN***************************************************************************
521            else if (service.indexOf( "x-im:msn" ) >= 0)
522            {
523                checkUriType( service, element );
524                icon = msnInstantIcon;
525                element = element.substring( element.indexOf( ":" ) + 1 );
526                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_MSN_MESS );
527            } 
528            else if (service.indexOf( "x-voice:msn" ) >= 0)
529            {
530                checkUriType( service, element );
531                icon = msnVoiceIcon;
532                element = element.substring( element.indexOf( ":" ) + 1 );
533                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_MSN_VOICE );
534            }
535//          YAHOO*******************************************************************
536            else if (service.indexOf( "x-im:ymsgr" ) >= 0)
537            {
538                checkUriType( service, element );
539                icon = yahooIcon;
540                element = element.substring( element.indexOf( ":" ) + 1 );
541                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_YAHOO_MESS );
542            }
543//          ICQ*******************************************************************
544            else if (service.indexOf( "x-im:icq" ) >= 0)
545            {
546                checkUriType( service, element );
547                icon = icqIcon;
548                element = element.substring( element.indexOf( ":" ) + 1 );
549                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_ICQ_MESS );
550            }           
551           
552//          OTHER*******************************************************************
553            else if (service.indexOf( "sip" )>= 0)
554            {
555                icon = sipIcon;
556                element = element.substring( element.indexOf( ":" ) + 1 );
557                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_SIP );
558            }
559            else if (service.indexOf( "h323" )>= 0)
560            {
561                icon = h323Icon;
562                element = element.substring( element.indexOf( ":" ) + 1 );
563                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_H323 );
564            }
565            else if (service.indexOf( "x-crypto" ) >= 0)
566            {
567                icon = telIcon;
568                element = "Encrypted";
569                serviceDisplayString = "";
570            }           
571            else if (service.indexOf( "email:mailto" ) >= 0)
572            {
573                checkUriType( service, element );
574                icon = emailIcon;
575                element = element.substring( element.indexOf( ":" ) + 1 );
576                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_EMAIL );
577            }
578            else if (service.indexOf( "web:http" ) >= 0)
579            {
580                checkUriType( service, element );
581                icon = webIcon;
582                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_WEB_SITE );
583            }
584            else if (service.indexOf( "web:https" ) >= 0)
585            {
586                checkUriType( service, element );
587                icon = webIcon;
588                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_SECURE_WEB_SITE );
589            }
590            else if (service.indexOf( "ft:ftp" ) >= 0)
591            {
592                checkUriType( service, element );
593                icon = ftpIcon;
594                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_FTP );
595            }
596            else if (service.indexOf( "note:data" ) >= 0)
597            {
598                checkUriType( service, element );
599                icon = noteIcon;
600                element = decodeDataUri( element );
601                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_NOTE );               
602            }
603            else if (service.indexOf( "user:data" ) >= 0)
604            {
605                checkUriType( service, element );
606                icon = userIcon;
607                element = decodeDataUri( element );
608                serviceDisplayString += TelnameApp.getResourceBundle().getString( TelnameAppResource.SERVICE_TYPE_USER );               
609            }
610            else
611            {
612                icon = blankIcon;
613                               
614                if( service.startsWith( "x-" ))
615                {
616                    service = ( service.substring( 2 ) );
617                }   
618                if (service.indexOf( ":data" ) >= 0)
619                {
620                    element = decodeDataUri( element );
621                }
622                serviceDisplayString += service;
623            }
624        }
625        parsedString = element;
626
627        Object[] returnvals = { element, icon };
628        return returnvals;
629    }
630
631    /**
632     * parse naptr string
633     *
634     * @param rr
635     * @return string
636     */
637    public String parseNaptrString (DNSTelnameNaptrResourceRecord rr) throws DiscardedNaptrException
638    {
639        parseNaptrStringAndIcon( rr );
640        String element = parsedString;
641        return element;
642    }
643   
644    /**
645     * parses a LIH and returns the display string.
646     *
647     * @param string the LIH
648     * @return the display string
649     */
650    public String parseLIH(String lih)
651    {       
652        ResourceBundle bundle = TelnameApp.getResourceBundle();
653       
654        if (lih.equals( "x-main" ))
655        {
656            return bundle.getString( TelnameAppResource.LIH_CATEGORY_MAIN );
657        }
658        else if (lih.equals( "x-home" ))
659        {
660            return bundle.getString( TelnameAppResource.LIH_CATEGORY_HOME );
661        }
662        else if (lih.equals( "x-mobile" ))
663        {
664            return bundle.getString( TelnameAppResource.LIH_CATEGORY_MOBILE );
665        } 
666        else if (lih.equals( "x-work" ))
667        {
668            return bundle.getString( TelnameAppResource.LIH_CATEGORY_WORK );
669        } 
670        else if (lih.equals( "x-transit" ))
671        {
672            return bundle.getString( TelnameAppResource.LIH_CATEGORY_TRANSIT );
673        } 
674        else if (lih.equals( "x-prs" ))
675        {
676            return bundle.getString( TelnameAppResource.LIH_CATEGORY_PRS );
677        } 
678           
679        return "";
680    }
681
682    public String getServiceString (int index)
683    {
684        if (!(list.elementAt( index ) instanceof DNSTelnameNaptrResourceRecord))
685        {
686            return "";
687        }
688        else
689        {
690            try
691            {
692                DNSTelnameNaptrResourceRecord rr = (DNSTelnameNaptrResourceRecord) list.elementAt( index );
693                parseNaptrStringAndIcon( rr );
694                return serviceDisplayString;
695            }
696            catch (DiscardedNaptrException e)
697            {
698                Logger.logMessage( "Problem with NAPTR: " + e.getMessage(), Options.KEY_LOG_APPLICATION );
699                return "";
700            }
701        }
702    }
703
704
705    /*
706     * (non-Javadoc)
707     *
708     * @see net.rim.device.api.ui.component.ListFieldCallback#get(net.rim.device.api.ui.component.ListField,
709     *      int)
710     */
711    public Object get (final ListField arg0, final int index)
712    {
713        return list.elementAt( index );
714    }
715
716    public String getString (final ListField arg0, final int index)
717    {
718        String element = "";
719        if (list.elementAt( index ) instanceof DNSTelnameNaptrResourceRecord)
720        {
721            final DNSTelnameNaptrResourceRecord rr = (DNSTelnameNaptrResourceRecord) list.elementAt( index );
722            try
723            {
724                element = parseNaptrString( rr );
725            }
726            catch (DiscardedNaptrException e)
727            {
728                Logger.logMessage( "Problem with NAPTR: " + e.getMessage(), Options.KEY_LOG_APPLICATION );
729            }
730        }
731        if (list.elementAt( index ) instanceof String)
732        {
733            element = (String) displayList.elementAt( index );
734        }
735        else if (list.elementAt( index ) instanceof DNSLocResourceRecord)
736        {
737            final DNSLocResourceRecord rr = (DNSLocResourceRecord) list.elementAt( index );
738            element = rr.toString();
739        }
740        return element;
741    }
742
743    /**
744     * size.
745     *
746     * @return size
747     */
748    public int size ()
749    {
750        return list.size();
751    }
752
753    /*
754     * (non-Javadoc)
755     *
756     * @see net.rim.device.api.ui.component.ListFieldCallback#getPreferredWidth(net.rim.device.api.ui.component.ListField)
757     */
758    public int getPreferredWidth (final ListField arg0)
759    {
760        return 0;
761    }
762
763    private String decodeDataUri(String uri) throws DiscardedNaptrException
764    {
765        String returnData = "";
766       
767        if (uri.startsWith( "data:," )  || uri.startsWith( "data:text/plain;charset=US-ASCII," ) )
768        {
769            returnData = uri.substring( uri.indexOf( "," ) + 1 );
770        }
771        else if (uri.startsWith( "data:;base64," ) || uri.startsWith( "data:text/plain;charset=US-ASCII;base64," ))
772        {
773            returnData = uri.substring( uri.indexOf( "," ) + 1 );           
774            try
775            {
776                returnData = new String (Base64.decode( returnData ), "US-ASCII");
777            }
778            catch (UnsupportedEncodingException e)
779            {   
780                throw new DiscardedNaptrException("Problem Unencoding data uri: " + e.getMessage());               
781            } 
782        }
783       
784        return returnData;
785    }
786   
787    private void checkUriType(String service, String uri) throws DiscardedNaptrException
788    {
789        String serviceType = service.substring( service.indexOf( ":" ) + 1 );
790        if (!uri.startsWith( serviceType ))
791        {
792            throw new DiscardedNaptrException("URI scheme does not match service.");
793        }       
794    }
795
796    /*
797     * (non-Javadoc)
798     *
799     * @see net.rim.device.api.ui.component.ListFieldCallback#indexOfList(net.rim.device.api.ui.component.ListField,
800     *      java.lang.String, int)
801     */
802    public int indexOfList (final ListField arg0, final String arg1, final int arg2)
803    {
804        return 0;
805    }
806}
Note: See TracBrowser for help on using the browser.
Telnic
Search This Site
Partners
Neustar
ICANN
Main site | WHOIS | Sell .tel | FAQ | Archived Site | About Telnic | Contact Us