1 | /*
|
---|
2 | * LibraryOfCongressClassificationSystem.java
|
---|
3 | * Copyright (C) 2000 Stuart Yeates
|
---|
4 | *
|
---|
5 | * This program is free software; you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
18 | */
|
---|
19 |
|
---|
20 | // the package we're in
|
---|
21 | package org.nzdl.gsdl.classification;
|
---|
22 |
|
---|
23 | // java standard library classes used
|
---|
24 | import java.io.File;
|
---|
25 | import java.io.FileInputStream;
|
---|
26 | import java.io.FileOutputStream;
|
---|
27 | import java.io.IOException;
|
---|
28 | import java.io.Serializable;
|
---|
29 | import java.lang.Cloneable;
|
---|
30 | import java.util.Vector;
|
---|
31 | import java.util.Hashtable;
|
---|
32 | import java.util.Enumeration;
|
---|
33 | import java.util.Properties;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * The Library of Congress Classification System
|
---|
37 | *
|
---|
38 | * @author stuart yeates ([email protected])
|
---|
39 | * @version $Revision: 2194 $
|
---|
40 | * @see org.nzdl.gsdl.classification.Classification
|
---|
41 | * @see org.nzdl.gsdl.classification.ClassificationSystem
|
---|
42 | * @see org.nzdl.gsdl.classification.LibraryOfCongressClassification
|
---|
43 | * @see java.io.Serializable
|
---|
44 | * @see java.lang.Cloneable
|
---|
45 | */
|
---|
46 |
|
---|
47 | public class LibraryOfCongressClassificationSystem
|
---|
48 | implements ClassificationSystem {
|
---|
49 |
|
---|
50 | static LibraryOfCongressClassificationSystem instance = null;
|
---|
51 |
|
---|
52 | static final protected String name = "Dewey Decimal Classification System";
|
---|
53 | LibraryOfCongressClassification root = null;
|
---|
54 |
|
---|
55 | protected LibraryOfCongressClassificationSystem() {
|
---|
56 | root = new LibraryOfCongressClassification(this, null,0,"",getName());
|
---|
57 | init();
|
---|
58 | root.clean();
|
---|
59 | }
|
---|
60 | static public LibraryOfCongressClassificationSystem getInstance() {
|
---|
61 | if (instance == null)
|
---|
62 | instance = new LibraryOfCongressClassificationSystem();
|
---|
63 | return instance;
|
---|
64 | }
|
---|
65 |
|
---|
66 | protected boolean add (String key, String value) {
|
---|
67 | return root.add(key,value);
|
---|
68 | }
|
---|
69 |
|
---|
70 | protected void init() {
|
---|
71 | }
|
---|
72 | /** */
|
---|
73 | public Classification getClassificationFor(String string) {
|
---|
74 | return root.getClassificationFor(string);
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | /** Returns the name of the ClassificationSystem*/
|
---|
79 | public String getName() { return name; };
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Returns an enumeration of all top-level Classifications
|
---|
83 | * (or all Classifications if this is a non-heirarchical
|
---|
84 | * ClassificationSystem)
|
---|
85 | */
|
---|
86 | public Enumeration getClassifications() {return root.getSubClassifications();};
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Parse a string containing one or more Classifications and
|
---|
90 | * return an Enumeration of them.
|
---|
91 | */
|
---|
92 | public Enumeration parse(String rawDesc) {
|
---|
93 | Vector vec = new Vector();
|
---|
94 | StringBuffer tmp = new StringBuffer();
|
---|
95 | for(int i = 0; i <rawDesc.length();i++) {
|
---|
96 | if (Character.isDigit((char)i) || i == '.') {
|
---|
97 | tmp.append(i);
|
---|
98 | } else {
|
---|
99 | if (tmp.length() != 0)
|
---|
100 | vec.add(getClassificationFor(tmp.toString()));
|
---|
101 | tmp.delete(0,tmp.length());
|
---|
102 | }
|
---|
103 | }
|
---|
104 | return vec.elements();
|
---|
105 |
|
---|
106 | };
|
---|
107 |
|
---|
108 | public static void main(String args[]) throws IOException
|
---|
109 | {
|
---|
110 | LibraryOfCongressClassificationSystem system =
|
---|
111 | new LibraryOfCongressClassificationSystem();
|
---|
112 | }
|
---|
113 |
|
---|
114 | }
|
---|