Changeset 6344


Ignore:
Timestamp:
2004-01-06T11:43:17+13:00 (20 years ago)
Author:
cs025
Message:

Improvements/changes to handling of HTML tidying

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util/GS3SQLConnection.java

    r6100 r6344  
    141141    }
    142142  }
     143
     144  public void clearCollection(String collectionName)
     145  {
     146    // strip the old database
     147    String killCommand = "DROP DATABASE " + collectionName;
     148
     149    try {
     150      if (/*makeClean*/true) {
     151    this.statement = this.connection.createStatement();
     152    this.statement.execute(killCommand);
     153    System.out.println("attempting: " + killCommand);
     154      }
     155    }
     156    catch (SQLException sqlEx) {
     157      System.out.println(sqlEx);
     158    }
     159  }
     160
    143161
    144162  /**
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util/HTMLTidy.java

    r6285 r6344  
    102102
    103103  public void startElement(String URI, String localName, String qName, Attributes attributes)
    104   { // System.out.println("Starting " + localName);
     104  { //System.out.println("<"+localName+">");
    105105 
    106106    if (localName.equals("html") == false) {
     
    123123    Comment comment = document.createComment(text);
    124124    this.currentElement.appendChild(comment);
     125    //System.out.println("<!-- "+text+" -->");
    125126  }
    126127
    127128  public void endElement(String URI, String localName, String qName)
    128129  { // System.out.println("Ending " + localName);
     130    // System.out.println("</"+localName+">");
    129131
    130132    if (localName.equals("html")) {
     
    139141    }
    140142
    141     this.currentElement = (Element) this.currentElement.getParentNode();
     143    // Optimisation: is this an empty tag?
     144    boolean isEmpty = false;
     145
     146    if (this.currentElement.getChildNodes().getLength() == 1)
     147    { Node child = this.currentElement.getFirstChild();
     148
     149      if (child.getNodeType() == Node.TEXT_NODE) {
     150    String text = child.getNodeValue();
     151   
     152    int i = 0;
     153    while (i < text.length())
     154    { if (text.charAt(i) > 32 && text.charAt(i) != 160) {
     155        break;
     156      }
     157      i++;
     158    }
     159    if (text.length() == i) {
     160      isEmpty = true;
     161    }
     162      }
     163    }
     164    else if (this.currentElement.getChildNodes().getLength() == 0)
     165    { isEmpty = true;
     166    }
     167
     168    boolean isSingleton = false;
     169    String tagName = this.currentElement.getTagName().toLowerCase();
     170
     171    if (tagName.equals("img") ||
     172    tagName.equals("br") ||
     173    tagName.equals("meta") ||
     174    tagName.equals("input") ||
     175    tagName.equals("area") ||
     176    tagName.equals("link") ||
     177    tagName.equals("base") ||
     178    tagName.equals("img") ||
     179    tagName.equals("hr")) {
     180      isSingleton = true;
     181    }
     182
     183    Element parent =  (Element) this.currentElement.getParentNode();
     184
     185    if (isEmpty == true && !isSingleton) {
     186      // trim the current child
     187      parent.removeChild(this.currentElement);
     188      //      System.out.println("***Removing child***");
     189    }
     190
     191    this.currentElement = parent;
    142192  }
    143193
     
    146196    Node text_node = this.document.createTextNode(string);
    147197    this.currentElement.appendChild(text_node);
     198    //    System.out.println(string);
    148199  }
    149200
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util/URLString.java

    r5800 r6344  
    11package org.greenstone.gsdl3.gs3build.util;
    22
    3 
    4 
    53import java.applet.*;
    6 
    74import java.net.*;
    85
    9 
    10 
    116public class URLString
    12 
    137{ private String url;
    148
    15 
    16 
    17     private String urlbase(String url)
    18 
    19     { int index;
    20 
    21         String tailString, bodyString;
    22 
    23         int body;
    24 
    25 
    26 
    27         index = url.indexOf("//");
    28 
    29         tailString = url.substring(index+2, url.length());
    30 
    31 
    32 
    33         body = tailString.indexOf('/');
    34 
    35         bodyString = tailString.substring(0, body+1);
    36 
    37 
    38 
    39         tailString = url.substring(0, index+2) + bodyString;
    40 
    41         return tailString;
    42 
    43     }
    44 
    45 
    46 
    47     public URLString(String s)
    48 
    49     {   this.url = s;
    50 
    51     }
    52 
    53 
    54 
    55     public URLString(String s, String target)
    56 
    57     { // reconcile
    58 
     9  private String urlbase(String url)
     10  { int index;
     11    String tailString, bodyString;
     12    int body;
     13
     14    index = url.indexOf("//");
     15    tailString = url.substring(index+2, url.length());
     16   
     17    body = tailString.indexOf('/');
     18    bodyString = tailString.substring(0, body+1);
     19   
     20    tailString = url.substring(0, index+2) + bodyString;
     21    return tailString;
     22  }
     23 
     24  public URLString(String s)
     25  { this.url = s;
     26  }
     27
     28  public URLString(String s, String target)
     29  { // reconcile
     30    int sref;
     31    int cref;
     32    int c;
     33
     34    // trim fragment identifiers
     35    target = noRef(target);
     36    if (target == null)
     37    { this.url = s;
     38      return;
     39    }
     40
     41    // test for absolute
     42    cref = target.indexOf(':');
     43    if (cref >= 0)
     44    { for (c = 0; c < cref; c ++)
     45      { if (target.charAt(c) != '+' &&
     46        target.charAt(c) != '-' &&
     47        target.charAt(c) != '.' &&
     48        Character.isLetterOrDigit(target.charAt(c)) == false)
     49    { break;
     50    }
     51      }
     52    }
     53    else
     54    { c = 0;
     55    }
     56
     57    if (c == cref)
     58    { // absolute reference
     59      String tmp;
     60
     61      tmp = target.substring(0, c);
     62      tmp = tmp.toLowerCase();
     63      if (target.indexOf("//") == cref + 1)
     64      { if (target.lastIndexOf('/') == cref + 2)
     65    { target = target + "/";
     66    }
     67      }
     68      /*            if (tmp.equals("http") == false)
     69                { this.url = null;
     70                return;
     71                }*/
     72      this.url = target;
     73    }
     74    else if (target.indexOf("//") == 0)
     75    { // absolute - implicit scheme (ie http).; also check for no trailing '/'
     76      if (target.lastIndexOf('/') == 1)
     77      { target = target + "/";
     78      }
     79      target = "http:" + target;
     80      this.url = target;
     81    }
     82    else
     83    { // relative - trim silly '/' at end
     84      if (target.charAt(0) == '/') 
     85      { // if we get a leading '/' then add it to the base of the url
     86    s = urlbase(s);
     87    target = target.substring(1);
     88    this.url = s + target;
     89//              System.out.println(this.url+"<"+s+"<"+target);
     90    return;
     91      }
     92
     93      while(target.length() >= 2 && target.charAt(0) == '.' && target.charAt(1) == '.')
     94      { // move up a level on the left
     95   
     96    sref = s.lastIndexOf('/');
     97    s = s.substring(0, sref);
     98
     99    target = target.substring(3);
     100      }
     101      // strip trailing leaf from s
     102      sref = s.lastIndexOf('/');
     103      s = s.substring(0, sref+1);
     104      // append s+target
     105      this.url = s + target;
     106    }
     107   
     108    // abandon the url if it is a call to a script
     109    if (this.url.indexOf('?') >= 0)
     110    { this.url = null;
     111    }
     112  }
     113
     114  public static boolean dirParent(String parent, String child)
     115  { while (child.length() >= parent.length())
     116    { child = child.substring(0, child.lastIndexOf('/'));
     117
     118      if (parent.equals(child))
     119      { return true;
     120      }
     121    }
     122    return false;
     123  }
     124
     125  public static int dirPos(String from, String to)
     126  { String fromdir;
     127    String todir;
     128
     129    fromdir = from.substring(0, from.lastIndexOf('/'));
     130    todir   = to.substring(0, to.lastIndexOf('/'));
     131
     132    if (fromdir.equals(todir))
     133    { return 0;
     134    }
     135    if (fromdir.length() > todir.length())
     136    { if (dirParent(todir, fromdir) == true)
     137      { return -1;
     138      }
     139    }
     140    else
     141    { if (dirParent(fromdir, todir) == true)
     142      { return 1;
     143      }
     144    }
     145    return -2;
     146  }
     147
     148  public static int commonLevels(String a, String b)
     149  { String  path_a, path_b;
     150    int         offset_a, offset_b;
     151    String  dir_a, dir_b;
     152    int         common;
     153
     154    path_a  = path(a);
     155    path_b  = path(b);
     156    common  = 0;
     157
     158    if (path_a == null || path_b == null)
     159    { return 0;
     160    }
     161
     162    do
     163    { offset_a = path_a.indexOf('/');
     164      offset_b = path_b.indexOf('/');
     165
     166      if (offset_a > 0)
     167      { dir_a       =   path_a.substring(0, offset_a);
     168        if (path_a.length() > offset_a + 1)
     169    {   path_a  = path_a.substring(offset_a+1);
     170    }
     171    else
     172    {   path_a  = null;
     173    }
     174      }
     175      else
     176      { dir_a       =   path_a;
     177        path_a  = null;
     178      }
     179
     180      if (offset_b > 0)
     181      { dir_b       =   path_b.substring(0, offset_b);
     182        if (path_b.length() > offset_b + 1)
     183    {   path_b  = path_b.substring(offset_b+1);
     184    }
     185    else
     186    {   path_b  = null;
     187    }
     188      }
     189      else
     190      { dir_b       =   path_b;
     191        path_b  = null;
     192      }
     193
     194      if (dir_a.length() != dir_b.length() ||
     195      dir_a.equals(dir_b) == false)
     196      { return common;
     197      }
     198      common ++;
     199    } while (path_a != null && path_b != null);
     200   
     201    return common;
     202  }
     203
     204    public static String dirLevelName(String url, int level)
     205    {   String  lpath;
     206        String  dir;
     207        int         thislevel = 0;
     208        int         offset;
     209
     210        lpath = path(url);
     211        if (lpath == null)
     212        { return null;
     213        }
     214        do
     215        { offset = lpath.indexOf('/');
     216
     217            if (offset >= 0)
     218            {   dir = lpath.substring(0, offset);
     219                lpath = lpath.substring(offset+1);
     220            }
     221            else
     222            {   dir = lpath;
     223            }
     224
     225            thislevel ++;
     226
     227            if (level == thislevel)
     228            { return dir;
     229            }
     230        } while (offset >= 0);
     231
     232        return null;
     233    }
     234
     235    public static int dirLevel(String url)
     236    {   String  lpath;
     237        int         level;
     238        int         offset;
     239
     240        lpath = path(url);
     241        if (lpath == null)
     242        {   return 0;
     243        }
     244        level = 0;
     245        do
     246        { offset = lpath.indexOf('/');
     247            if (offset >= 0)
     248            {   lpath = lpath.substring(offset+1);
     249            }
     250            level ++;
     251        } while (offset >= 0);
     252
     253        return level;
     254    }
     255
     256    public static String tidyURL(String urlString, boolean permitScript)
     257    {   int cref;
     258        int c;
    59259        int sref;
    60 
    61         int cref;
    62 
    63         int c;
    64 
    65 
    66 
    67         // trim fragment identifiers
    68 
    69         target = noRef(target);
    70 
    71         if (target == null)
    72 
    73         {   this.url = s;
    74 
    75             return;
    76 
    77         }
    78 
    79 
    80 
    81         // test for absolute
    82 
    83         cref = target.indexOf(':');
    84 
     260        String tmp, s;
     261
     262        s = urlString;
     263        cref = s.indexOf(':');
    85264        if (cref >= 0)
    86 
    87265        { for (c = 0; c < cref; c ++)
    88 
    89             { if (target.charAt(c) != '+' &&
    90 
    91                         target.charAt(c) != '-' &&
    92 
    93                         target.charAt(c) != '.' &&
    94 
    95                         Character.isLetterOrDigit(target.charAt(c)) == false)
    96 
     266            { if (s.charAt(c) != '+' &&
     267                        s.charAt(c) != '-' &&
     268                        s.charAt(c) != '.' &&
     269                        Character.isLetterOrDigit(s.charAt(c)) == false)
    97270                { break;
    98 
    99271                }
    100 
    101             }
    102 
    103         }
    104 
     272            }
     273        }
    105274        else
    106 
    107275        { c = 0;
    108 
    109         }
    110 
    111 
    112 
    113         if (c == cref)
    114 
    115         { // absolute reference
    116 
    117             String tmp;
    118 
    119 
    120 
    121             tmp = target.substring(0, c);
    122 
    123             tmp = tmp.toLowerCase();
    124 
    125             if (target.indexOf("//") == cref + 1)
    126 
    127             { if (target.lastIndexOf('/') == cref + 2)
    128 
    129                 { target = target + "/";
    130 
    131                 }
    132 
    133             }
    134 
    135 /*          if (tmp.equals("http") == false)
    136 
    137             { this.url = null;
    138 
    139                 return;
    140 
    141             }*/
    142 
    143             this.url = target;
    144 
    145         }
    146 
    147         else if (target.indexOf("//") == 0)
    148 
    149         { // absolute - implicit scheme (ie http).; also check for no trailing '/'
    150 
    151             if (target.lastIndexOf('/') == 1)
    152 
    153             { target = target + "/";
    154 
    155             }
    156 
    157             target = "http:" + target;
    158 
    159             this.url = target;
    160 
    161         }
    162 
     276        }
     277
     278        if (cref == c)
     279        { tmp = s.substring(0, c).toLowerCase();
     280            s = tmp + s.substring(c, s.length());
     281            if (s.lastIndexOf('/') == cref + 2)
     282            { s = s + "/";
     283            }
     284        }
    163285        else
    164 
    165         { // relative - trim silly '/' at end
    166 
    167             if (target.charAt(0) == '/')   
    168 
    169             { // if we get a leading '/' then add it to the base of the url
    170 
    171                 s = urlbase(s);
    172 
    173                 target = target.substring(1);
    174 
    175                 this.url = s + target;
    176 
    177 //              System.out.println(this.url+"<"+s+"<"+target);
    178 
    179                 return;
    180 
    181             }
    182 
    183 
    184 
    185             while(target.length() >= 2 && target.charAt(0) == '.' && target.charAt(1) == '.')
    186 
    187             { // move up a level on the left
    188 
    189 
    190 
    191                 sref = s.lastIndexOf('/');
    192 
    193                 s = s.substring(0, sref);
    194 
    195 
    196 
    197                 target = target.substring(3);
    198 
    199             }
    200 
    201             // strip trailing leaf from s
    202 
    203             sref = s.lastIndexOf('/');
    204 
    205             s = s.substring(0, sref+1);
    206 
    207             // append s+target
    208 
    209             this.url = s + target;
    210 
    211         }
    212 
    213 
    214 
    215         // abandon the url if it is a call to a script
    216 
    217         if (this.url.indexOf('?') >= 0)
    218 
    219         { this.url = null;
    220 
    221         }
    222 
    223     }
    224 
    225 
    226 
    227     public static boolean dirParent(String parent, String child)
    228 
    229     {   while (child.length() >= parent.length())
    230 
    231         { child = child.substring(0, child.lastIndexOf('/'));
    232 
    233 
    234 
    235             if (parent.equals(child))
    236 
    237             {   return true;
    238 
    239             }
    240 
    241         }
    242 
    243         return false;
    244 
    245     }
    246 
    247 
    248 
    249     public static int dirPos(String from, String to)
    250 
    251     {   String fromdir;
    252 
    253         String todir;
    254 
    255 
    256 
    257         fromdir = from.substring(0, from.lastIndexOf('/'));
    258 
    259         todir   = to.substring(0, to.lastIndexOf('/'));
    260 
    261 
    262 
    263         if (fromdir.equals(todir))
    264 
    265         {   return 0;
    266 
    267         }
    268 
    269         if (fromdir.length() > todir.length())
    270 
    271         { if (dirParent(todir, fromdir) == true)
    272 
    273             {   return -1;
    274 
    275             }
    276 
    277         }
    278 
    279         else
    280 
    281         {   if (dirParent(fromdir, todir) == true)
    282 
    283             { return 1;
    284 
    285             }
    286 
    287         }
    288 
    289         return -2;
    290 
    291     }
    292 
    293 
    294 
    295     public static int commonLevels(String a, String b)
    296 
    297     {   String  path_a, path_b;
    298 
    299         int         offset_a, offset_b;
    300 
    301         String  dir_a, dir_b;
    302 
    303         int         common;
    304 
    305 
    306 
    307         path_a  = path(a);
    308 
    309         path_b  = path(b);
    310 
    311         common  = 0;
    312 
    313 
    314 
    315         if (path_a == null || path_b == null)
    316 
    317         { return 0;
    318 
    319         }
    320 
    321 
    322 
    323         do
    324 
    325         { offset_a = path_a.indexOf('/');
    326 
    327             offset_b = path_b.indexOf('/');
    328 
    329 
    330 
    331             if (offset_a > 0)
    332 
    333             { dir_a     =   path_a.substring(0, offset_a);
    334 
    335                 if (path_a.length() > offset_a + 1)
    336 
    337                 {   path_a  = path_a.substring(offset_a+1);
    338 
    339                 }
    340 
    341                 else
    342 
    343                 {   path_a  = null;
    344 
    345                 }
    346 
    347             }
    348 
     286        { sref = s.indexOf("//");
     287            if (sref == 0)
     288            { s = "http:" + s;
     289            }
    349290            else
    350 
    351             {   dir_a       =   path_a;
    352 
    353                 path_a  = null;
    354 
    355             }
    356 
    357 
    358 
    359             if (offset_b > 0)
    360 
    361             {   dir_b       =   path_b.substring(0, offset_b);
    362 
    363                 if (path_b.length() > offset_b + 1)
    364 
    365                 {   path_b  = path_b.substring(offset_b+1);
    366 
    367                 }
    368 
    369                 else
    370 
    371                 {   path_b  = null;
    372 
    373                 }
    374 
    375             }
    376 
    377             else
    378 
    379             {   dir_b       =   path_b;
    380 
    381                 path_b  = null;
    382 
    383             }
    384 
    385 
    386 
    387             if (dir_a.length() != dir_b.length() ||
    388 
    389                     dir_a.equals(dir_b) == false)
    390 
    391             {   return common;
    392 
    393             }
    394 
    395             common ++;
    396 
    397         } while (path_a != null && path_b != null);
    398 
    399 
    400 
    401         return common;
    402 
    403     }
    404 
    405 
    406 
    407     public static String dirLevelName(String url, int level)
    408 
    409     {   String  lpath;
    410 
    411         String  dir;
    412 
    413         int         thislevel = 0;
    414 
    415         int         offset;
    416 
    417 
    418 
    419         lpath = path(url);
    420 
    421         if (lpath == null)
    422 
    423         { return null;
    424 
    425         }
    426 
    427         do
    428 
    429         { offset = lpath.indexOf('/');
    430 
    431 
    432 
    433             if (offset >= 0)
    434 
    435             {   dir = lpath.substring(0, offset);
    436 
    437                 lpath = lpath.substring(offset+1);
    438 
    439             }
    440 
    441             else
    442 
    443             {   dir = lpath;
    444 
    445             }
    446 
    447 
    448 
    449             thislevel ++;
    450 
    451 
    452 
    453             if (level == thislevel)
    454 
    455             { return dir;
    456 
    457             }
    458 
    459         } while (offset >= 0);
    460 
    461 
    462 
    463         return null;
    464 
    465     }
    466 
    467 
    468 
    469     public static int dirLevel(String url)
    470 
    471     {   String  lpath;
    472 
    473         int         level;
    474 
    475         int         offset;
    476 
    477 
    478 
    479         lpath = path(url);
    480 
    481         if (lpath == null)
    482 
    483         {   return 0;
    484 
    485         }
    486 
    487         level = 0;
    488 
    489         do
    490 
    491         { offset = lpath.indexOf('/');
    492 
    493             if (offset >= 0)
    494 
    495             {   lpath = lpath.substring(offset+1);
    496 
    497             }
    498 
    499             level ++;
    500 
    501         } while (offset >= 0);
    502 
    503 
    504 
    505         return level;
    506 
    507     }
    508 
    509 
    510 
    511     public static String tidyURL(String urlString, boolean permitScript)
    512 
    513     {   int cref;
    514 
    515         int c;
    516 
    517         int sref;
    518 
    519         String tmp, s;
    520 
    521 
    522 
    523         s = urlString;
    524 
    525         cref = s.indexOf(':');
    526 
    527         if (cref >= 0)
    528 
    529         { for (c = 0; c < cref; c ++)
    530 
    531             { if (s.charAt(c) != '+' &&
    532 
    533                         s.charAt(c) != '-' &&
    534 
    535                         s.charAt(c) != '.' &&
    536 
    537                         Character.isLetterOrDigit(s.charAt(c)) == false)
    538 
    539                 { break;
    540 
    541                 }
    542 
    543             }
    544 
    545         }
    546 
    547         else
    548 
    549         { c = 0;
    550 
    551         }
    552 
    553 
    554 
    555         if (cref == c)
    556 
    557         { tmp = s.substring(0, c).toLowerCase();
    558 
    559             s = tmp + s.substring(c, s.length());
    560 
    561             if (s.lastIndexOf('/') == cref + 2)
    562 
     291            { s = "http://" + s;
     292            }
     293            if (s.lastIndexOf('/') == 6)
    563294            { s = s + "/";
    564 
    565             }
    566 
    567         }
    568 
    569         else
    570 
    571         { sref = s.indexOf("//");
    572 
    573             if (sref == 0)
    574 
    575             { s = "http:" + s;
    576 
    577             }
    578 
    579             else
    580 
    581             { s = "http://" + s;
    582 
    583             }
    584 
    585             if (s.lastIndexOf('/') == 6)
    586 
    587             { s = s + "/";
    588 
    589             }
    590 
    591         }
    592 
     295            }
     296        }
    593297        return s;
    594 
    595298    }
    596299
     
    599302    }
    600303
    601 
    602 
    603304    public static URL toURL(String urlString)
    604 
    605305    { URL reply;
    606306
    607 
    608 
    609307      try
    610 
    611308        { reply = new URL(URLString.tidyURL(urlString));
    612 
    613         }
    614 
     309        }
    615310        catch (MalformedURLException ex)
    616 
    617         { return null;
    618 
    619         }
    620 
     311        { return null;
     312        }
    621313        return reply;
    622 
    623     }
    624 
    625 
     314    }
    626315
    627316  public void tidy()
    628 
    629317    { this.url = tidyURL(this.url);
    630 
    631     }
    632 
    633 
     318    }
    634319
    635320    public boolean isNull()
    636 
    637321    { if (this.url == null)
    638 
    639322        { return true;
    640 
    641323        }
    642 
    643324        return false;
    644 
    645     }
    646 
    647 
     325    }
    648326
    649327    public static boolean isForeign(String home, URL url)
    650 
    651328    { if (url.toString().length() < home.length())
    652 
    653329        { return true;
    654 
    655         }
    656 
    657 
     330        }
    658331
    659332        if (home.equals(url.toString().substring(0, home.length())))
    660 
    661333        { return false;
    662 
    663         }
    664 
     334        }
    665335        return true;
    666 
    667     }
    668 
     336    }
    669337
    670338    /**
     
    778446    }
    779447
    780 
    781448    /**
    782449     *  Provide the complete pathname in the given url
     
    787454     */
    788455    public static String pathName(String url)
    789 
    790456    {   int offset;
    791 
    792457        String remainder;
    793458
    794 
    795 
    796459        if (url == null)
    797 
    798         { return null;
    799 
    800         }
    801 
    802 
     460        { return null;
     461        }
    803462
    804463        offset = url.indexOf("//");
    805 
    806464        if (offset < 0)
    807 
    808         { return null;
    809 
    810         }
    811 
    812 
     465        { return null;
     466        }
    813467
    814468        remainder = url.substring(offset + 2);
    815 
    816469        offset = remainder.indexOf('/');
    817 
    818470        if (offset < 0)
    819 
    820         {   return null;
    821 
    822         }
    823 
     471        {   return null;
     472        }
    824473        return remainder.substring(offset + 1);
    825 
    826     }
    827 
    828 
     474    }
    829475
    830476    /**
     
    836482     */
    837483    public static String leafName(String url)
    838 
    839484    {   int offset;
    840 
    841485        int dot;
    842486
    843 
    844 
    845487        if (url == null)
    846 
    847         {   return null;
    848 
    849         }
    850 
     488        {   return null;
     489        }
    851490        offset = url.lastIndexOf('/');
    852 
    853491        if (offset < 0)
    854 
    855         { return null;
    856 
    857         }
    858 
     492        { return null;
     493        }
    859494        if (offset == url.length() - 1)
    860 
    861         { return null;
    862 
    863         }
    864 
     495        { return null;
     496        }
    865497        dot = url.lastIndexOf('/');
    866 
    867498        if (dot < offset)
    868 
    869         {   return null;
    870 
    871         }
    872 
     499        {   return null;
     500        }
    873501        return url.substring(offset+1);
    874 
    875     }
    876 
     502    }
    877503
    878504    /**
     
    883509     *  @return <code>String</code> host name
    884510     */
    885 
    886511    public static String host(String url)
    887 
    888512    {   String scheme, tail;
    889 
    890513        int      spos;
    891514
    892 
    893 
    894515        spos = url.indexOf("//");
    895 
    896516        if (spos >= 0)
    897 
    898517        { scheme = url.substring(0, spos + 2);
    899 
    900518            tail = url.substring(spos + 2, url.length());
    901 
    902519            // do sub-areas
    903 
    904520            spos = tail.indexOf('/');
    905 
    906521            if (spos >= 0)
    907 
    908522            { tail = tail.substring(0, spos+1);
    909 
    910             }
    911 
     523            }
    912524            scheme = scheme + tail;
    913 
    914525            return scheme;
    915 
    916         }
    917 
     526        }
    918527        return null;
    919 
    920     }
    921 
    922 
     528    }
    923529
    924530    /**
     
    930536     */
    931537    public static String path(String url)
    932 
    933538    { String tail;
    934 
    935539        int offset;
    936 
    937540        String leaf;
    938541
    939 
    940 
    941542        if (url == null)
    942 
    943         { return null;
    944 
    945         }
    946 
    947 
     543        { return null;
     544        }
    948545
    949546        offset  = url.indexOf("//");
    950 
    951547        if (offset < 0)
    952 
    953         {   return null;
    954 
    955         }
    956 
    957 
     548        {   return null;
     549        }
    958550
    959551        tail        = url.substring(offset+2);
    960 
    961552        offset  = tail.indexOf('/');
    962 
    963553        if (offset < 0)
    964 
    965         {   return null;
    966 
    967         }
    968 
    969 
     554        {   return null;
     555        }
    970556
    971557        tail        = tail.substring(offset+1);
    972 
    973558        if (tail == null || tail.length() == 0)
    974 
    975         {   return null;
    976 
    977         }
    978 
    979 
     559        {   return null;
     560        }
    980561
    981562        offset  = tail.lastIndexOf('/');
    982 
    983563        if (offset < 0)
    984 
    985         { return null;
    986 
    987         }
    988 
     564        { return null;
     565        }
    989566        else
    990 
    991567        {   tail = tail.substring(0, offset);
    992 
    993         }
    994 
     568        }
    995569        return tail;
    996 
    997     }
    998 
    999 
     570    }
    1000571
    1001572    /**
     
    1007578     */
    1008579    public static String extension(String url)
    1009 
    1010580    { int offset;
    1011 
    1012581        String leaf;
    1013582
    1014 
    1015 
    1016583        if (url == null)
    1017 
    1018         { return null;
    1019 
    1020         }
    1021 
    1022 
     584        { return null;
     585        }
    1023586
    1024587        offset = url.lastIndexOf('/');
    1025 
    1026588        if (offset >= 0 && offset < url.length() - 1)
    1027 
    1028589        { leaf = url.substring(offset+1, url.length());
    1029 
    1030590            offset = leaf.lastIndexOf('.');
    1031591
    1032592            // if we've got an extension then use it
    1033 
    1034593            if (offset >= 0)
    1035 
    1036594            { int poffset;
    1037595
     
    1044602                // give leaf value
    1045603                return leaf.substring(offset, poffset);
    1046 
    1047             }
    1048 
     604            }
    1049605            else
    1050 
    1051606            { return null;
    1052 
    1053             }
    1054 
    1055         }
    1056 
     607            }
     608        }
    1057609        return null;
    1058 
    1059     }
    1060 
    1061 
     610    }
    1062611
    1063612    public static String extension(URL url)
    1064 
    1065613    { return extension(url.toString());
    1066 
    1067     }
    1068 
    1069 
     614    }
    1070615
    1071616    public String toString()
    1072 
    1073617    { return this.url;
    1074 
    1075     }
    1076 
     618    }
    1077619}
Note: See TracChangeset for help on using the changeset viewer.