KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > catalog > CatalogEntry


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.catalog;
9
10 /**
11  * <p>Represents an OASIS Open Catalog entry.</p>
12  *
13  * Instances of this class represent individual entries from an <a
14  * HREF="http://www.oasis-open.org/html/a401.htm">OASIS Open Catalog</a> file.
15  * </p><p>
16  *
17  * While this could have been implemented as a base class with a separate
18  * subclass for each type of catalog entry, it didn't seem to be worth the extra
19  * overhead.</p>
20  *
21  * @author Arbortext, Inc.
22  * @author <a HREF="mailto:nwalsh@arbortext.com">Norman Walsh</a>
23  * @version 1.0
24  * @see Catalog
25  */

26 public class CatalogEntry
27 {
28     // These have one argument in the catalog file
29

30     /**
31      * The entry type for a BASE entry
32      */

33     public final static int BASE = 1;
34     // BASE fsispec
35
/**
36      * The entry type for a CATALOG entry
37      */

38     public final static int CATALOG = 2;
39     // CATALOG fsispec
40
/**
41      * The entry type for a DOCUMENT entry
42      */

43     public final static int DOCUMENT = 3;
44     // DOCUMENT fsispec
45
/**
46      * The entry type for a OVERRIDE entry
47      */

48     public final static int OVERRIDE = 4;
49     // OVERRIDE (yes|no)
50
/**
51      * The entry type for a SGMLDECL entry
52      */

53     public final static int SGMLDECL = 5;
54     // SGMLDECL fsispec
55

56     // These have two arguments in the catalog file
57
/**
58      * The entry type for a DELEGATE entry
59      */

60     public final static int DELEGATE = 6;
61     // DELEGATE partialpublic fsispec
62
/**
63      * The entry type for a DOCTYPE entry
64      */

65     public final static int DOCTYPE = 7;
66     // DOCTYPE entityname fsispec
67
/**
68      * The entry type for a DTDDECL entry
69      */

70     public final static int DTDDECL = 8;
71     // DTDDECL publicid fsispec
72
/**
73      * The entry type for a ENTITY entry
74      */

75     public final static int ENTITY = 9;
76     // ENTITY entityname fsispec
77
/**
78      * The entry type for a LINKTYPE entry
79      */

80     public final static int LINKTYPE = 10;
81     // LINKTYPE entityname fsispec
82
/**
83      * The entry type for a NOTATION entry
84      */

85     public final static int NOTATION = 11;
86     // NOTATION entityname fsispec
87
/**
88      * The entry type for a PUBLIC entry
89      */

90     public final static int PUBLIC = 12;
91     // PUBLIC publicid fsispec
92
/**
93      * The entry type for a SYSTEM entry
94      */

95     public final static int SYSTEM = 13;
96     // SYSTEM systemid fsispec
97

98     /**
99      * The entry type (one of BASE..SYSTEM)
100      */

101     private int entryType = 0;
102
103     /**
104      * The first argument in a catalog entry
105      */

106     private String JavaDoc spec1 = "";
107
108     /**
109      * The second argument in a catalog entry (usually an fsispec)
110      */

111     private String JavaDoc spec2 = "";
112
113     /**
114      * <p>
115      *
116      * Construct a catalog entry of the specified type. The two-argument form of
117      * the constructor can be used for BASE, CATALOG, DOCUMENT, OVERRIDE, and
118      * SGMLDECL entries.</p>
119      *
120      * @param type The entry type.
121      * @param spec The argument to the entry, a formal system identifier in all
122      * cases except OVERRIDE when it must be either "yes" or "no".
123      * @exception InvalidCatalogEntryTypeException DOC: Insert Description of
124      * Exception
125      * @exception InvalidCatalogEntryException DOC: Insert Description of
126      * Exception
127      */

128     public CatalogEntry( int type, String JavaDoc spec )
129         throws InvalidCatalogEntryTypeException,
130         InvalidCatalogEntryException
131     {
132
133         if( type < BASE || type > SYSTEM )
134         {
135             throw new InvalidCatalogEntryTypeException();
136         }
137
138         if( type > SGMLDECL )
139         {
140             throw new InvalidCatalogEntryException();
141         }
142
143         if( type == OVERRIDE
144              && !( spec.equalsIgnoreCase( "YES" )
145              || spec.equalsIgnoreCase( "NO" ) ) )
146         {
147             throw new InvalidCatalogEntryException();
148         }
149
150         entryType = type;
151         spec1 = spec;
152     }
153
154     /**
155      * <p>
156      *
157      * Construct a catalog entry of the specified type. The three-argument form
158      * of the constructor can be used for DELEGATE, DOCTYPE, DTDDECL, ENTITY,
159      * LINKTYPE, NOTATION, PUBLIC, and SYSTEM entries.</p>
160      *
161      * @param type The entry type.
162      * @param spec DOC: Insert Description of Parameter
163      * @param fsispec DOC: Insert Description of Parameter
164      * @exception InvalidCatalogEntryTypeException DOC: Insert Description of
165      * Exception
166      * @exception InvalidCatalogEntryException DOC: Insert Description of
167      * Exception
168      */

169     public CatalogEntry( int type, String JavaDoc spec, String JavaDoc fsispec )
170         throws InvalidCatalogEntryTypeException,
171         InvalidCatalogEntryException
172     {
173
174         if( type < BASE || type > SYSTEM )
175         {
176             throw new InvalidCatalogEntryTypeException();
177         }
178
179         if( type < DELEGATE )
180         {
181             throw new InvalidCatalogEntryException();
182         }
183
184         entryType = type;
185         spec1 = spec;
186         spec2 = fsispec;
187     }
188
189     /**
190      * <p>
191      *
192      * The entry type</p>
193      *
194      * @return The entry type
195      */

196     public int entryType()
197     {
198         return entryType;
199     }
200
201     /**
202      * <p>
203      *
204      * The formal system identifier of the entry, if appropriate</p>
205      *
206      * @return The FSI for the entry, or null if it has no FSI.
207      */

208     public String JavaDoc formalSystemIdentifier()
209     {
210         if( entryType > SGMLDECL )
211         {
212             return spec2;
213         }
214         else
215         {
216             if( entryType != OVERRIDE )
217             {
218                 return spec1;
219             }
220             else
221             {
222                 return null;
223             }
224         }
225     }
226
227     /**
228      * <p>
229      *
230      * The argument, YES or NO, of an OVERRIDE entry.</p>
231      *
232      * @return The YES or NO setting of an OVERRIDE entry, null otherwise.
233      */

234     public String JavaDoc yes_or_no()
235     {
236         if( entryType != OVERRIDE )
237         {
238             return null;
239         }
240         else
241         {
242             return spec1;
243         }
244     }
245
246     /**
247      * <p>
248      *
249      * The partial public identifier of a DELEGATE entry.</p>
250      *
251      * @return The partial public identifier of a DELEGATE entry, null
252      * otherwise.
253      */

254     public String JavaDoc partialPublicId()
255     {
256         if( entryType != DELEGATE )
257         {
258             return null;
259         }
260         else
261         {
262             return spec1;
263         }
264     }
265
266     /**
267      * <p>
268      *
269      * The entity name</p>
270      *
271      * @return The entity name of a DOCTYPE, ENTITY, LINKTYPE, or NOTATION
272      * entry, null otherwise.
273      */

274     public String JavaDoc entityName()
275     {
276         if( entryType == DOCTYPE
277              || entryType == ENTITY
278              || entryType == LINKTYPE
279              || entryType == NOTATION )
280         {
281             return spec1;
282         }
283         else
284         {
285             return null;
286         }
287     }
288
289     /**
290      * <p>
291      *
292      * The public identifier</p>
293      *
294      * @return The public identifier of a DTDDECL or PUBLIC entry, null
295      * otherwise.
296      */

297     public String JavaDoc publicId()
298     {
299         if( entryType == DTDDECL
300              || entryType == PUBLIC )
301         {
302             return spec1;
303         }
304         else
305         {
306             return null;
307         }
308     }
309
310     /**
311      * <p>
312      *
313      * The system identifier</p>
314      *
315      * @return The system identifier of a SYSTEM entry, null otherwise.
316      */

317     public String JavaDoc systemId()
318     {
319         if( entryType != SYSTEM )
320         {
321             return null;
322         }
323         else
324         {
325             return spec1;
326         }
327     }
328
329     /**
330      * <p>
331      *
332      * Update the formal system identifier</p> <p>
333      *
334      * The FSI initial specified in an entry may be relative (to the location of
335      * the catalog file or as modified by a BASE entry). A system processing
336      * catalog files (e.g. {@link com.arbortext.catalog.Catalog}), must be able
337      * to update the FSI in order to change it from a relative location to an
338      * absolute one.</p>
339      *
340      * @param newspec The new FSI
341      */

342     public void updateFormalSystemIdentifier( String JavaDoc newspec )
343     {
344         if( entryType > SGMLDECL )
345         {
346             spec2 = newspec;
347         }
348         else
349         {
350             spec1 = newspec;
351         }
352     }
353 }
354
Popular Tags