KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > savant > AbstractURLBuilder


1 /*
2  * Copyright (c) 2003-2004, Inversoft, All Rights Reserved
3  */

4 package com.inversoft.savant;
5
6
7 import java.io.File JavaDoc;
8 import java.io.FileInputStream JavaDoc;
9 import java.io.IOException JavaDoc;
10 import java.util.MissingResourceException JavaDoc;
11 import java.util.PropertyResourceBundle JavaDoc;
12
13
14 /**
15  * <p>
16  * This class is the abstract base class for all implementors
17  * of the {@link URLBuilder} interface.
18  * </p>
19  *
20  * @author Brian Pontarelli
21  */

22 public abstract class AbstractURLBuilder implements URLBuilder {
23
24     /**
25      * Builds either the base URL specification for the given artifact by figuring
26      * out the domain (either default or something from the mapping).
27      *
28      * @param defaultDomain The default domain URL specification to use as the
29      * base URL
30      * @param mapping (optional) A file that contains group to URL mappings that
31      * can be used to override the defaultDomain base URL
32      * @param artifact The artifact to fetch the group from if mapping is not
33      * null
34      * @return The base URL
35      */

36     protected String JavaDoc makeBaseURLSpec(String JavaDoc defaultDomain, File JavaDoc mapping,
37             Artifact artifact)
38     throws SavantException {
39         String JavaDoc domain = defaultDomain;
40         if (mapping != null && mapping.exists() && mapping.isFile()) {
41             try {
42                 FileInputStream JavaDoc fis = new FileInputStream JavaDoc(mapping);
43                 PropertyResourceBundle JavaDoc bundle = new PropertyResourceBundle JavaDoc(fis);
44                 domain = bundle.getString(artifact.getGroup());
45             } catch (IOException JavaDoc ioe) {
46                 throw new SavantException(ioe);
47             } catch (MissingResourceException JavaDoc mre) {
48                 // this is okay
49
}
50         } else if (mapping != null) {
51             throw new SavantException("Unable to locate mapping file [" +
52                 mapping.getAbsolutePath() + "]");
53         }
54
55         return domain;
56     }
57 }
Popular Tags