Changeset 7268
- Timestamp:
- 2004-05-04T17:04:47+12:00 (20 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AbstractHierarchyNode.java
r7188 r7268 51 51 */ 52 52 public AbstractHierarchyNode() 53 { this.descriptor = null;54 this.name = null;55 this.id = null;56 this.prefix = null;53 { this.descriptor = ""; 54 this.name = ""; 55 this.id = ""; 56 this.prefix = ""; 57 57 this.childNodes = new ArrayList(); 58 58 this.childDocs = new ArrayList(); … … 78 78 child.setParent(this); 79 79 80 /* 80 /** 81 81 if (this.id == null) { 82 82 System.out.println(child.id.toString() + " added to root"); … … 89 89 90 90 public boolean add(AbstractHierarchyNode child) 91 { if (this.id != null && 91 { if (this.id != null && this.id.length() > 0 && 92 92 !child.id.startsWith(this.id + ".")) 93 93 { return false; … … 256 256 { 257 257 int classifyRef; 258 GS3SQLAction action ;258 GS3SQLAction action = null; 259 259 GS3SQLSelect select; 260 260 GS3SQLInsert insert; 261 262 // Get own full id 263 String fullId = this.id.length() > 0 ? this.prefix+"."+this.id : this.prefix; 261 264 262 265 // check for an existing instance of this classifier 263 266 select = new GS3SQLSelect("classifiers"); 264 267 select.addField("ClassifyRef"); 265 GS3SQLWhereItem whereItem = new GS3SQLWhereItem("ClassifyID", "=", this.prefix+"."+this.id);268 GS3SQLWhereItem whereItem = new GS3SQLWhereItem("ClassifyID", "=", fullId); 266 269 GS3SQLWhere where = new GS3SQLWhere(whereItem); 267 270 select.setWhere(where); … … 282 285 insert = new GS3SQLInsert("classifiers"); 283 286 284 String parentId = this.getParentId(); 285 286 if (parentId.length() > 0) { 287 insert.addValue("ParentID", this.prefix+"."+this.getParentId()); 287 if (this.id == null || this.id.length() == 0) { 288 insert.addValue("ParentID", ""); 288 289 } 289 290 else { 290 insert.addValue("ParentID", this.prefix); 291 String parentId = this.getParentId(); 292 293 if (parentId.length() > 0) { 294 insert.addValue("ParentID", this.prefix+"."+this.getParentId()); 295 } 296 else { 297 insert.addValue("ParentID", this.prefix); 298 } 291 299 } 292 300 293 301 action = insert; 294 302 } 295 action.addValue("ClassifyID", this.prefix+"."+this.id);303 action.addValue("ClassifyID", fullId); 296 304 action.addValue("Name", this.name); 297 305 action.addValue("Description", this.descriptor); 298 action.addValue("ClassifyOrder", this.id, GS3SQLField.INTEGER_TYPE); 306 307 String tailId = "0"; 308 if (this.id.length() > 0) { 309 int lastDot = this.id.lastIndexOf('.'); 310 if (lastDot >= 0) { 311 tailId = this.id.substring(lastDot+1); 312 } 313 else { 314 tailId = this.id; 315 } 316 } 317 action.addValue("ClassifyOrder", tailId, GS3SQLField.INTEGER_TYPE); 299 318 action.addValue("NumLeafDocs", Integer.toString(this.noOfLeafDocs()), GS3SQLField.INTEGER_TYPE); 300 319 … … 303 322 } 304 323 catch (SQLException sqlEx) { 305 System.err.println(sqlEx); 324 if (action == null) { 325 System.err.println(sqlEx); 326 } 327 else { 328 System.err.println(sqlEx + " " + action.toString()); 329 } 306 330 return false; 307 331 } … … 341 365 342 366 if (!childNode.writeSQL(connection)) { 367 System.out.println("Failed to write " ); 343 368 return false; 344 369 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/GS2HierarchyClassifier.java
r6496 r7268 97 97 { super(content); 98 98 99 this.rootNode = new GS2HierarchyNode();100 99 String prefix = "CL"+hierarchyName; 100 this.rootNode = new GS2HierarchyNode(prefix, hierarchyName, "", hierarchyName); 101 101 102 102 while (this.hasMoreLines()) { -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/HierarchyClassifier.java
r7188 r7268 47 47 public HierarchyNode() 48 48 { super(); 49 } 50 51 public HierarchyNode(String prefix, String name, String id, String descriptor) 52 { super(prefix, name, id, descriptor); 49 53 } 50 54 … … 77 81 StringBuffer path; 78 82 StringBuffer match; 83 String prefix; 79 84 boolean inElement; 80 85 AbstractHierarchyNode rootNode = null; 81 86 AbstractHierarchyNode currentNode = null; 82 List rootNodes = null; 83 84 HierarchyHandler() 87 88 HierarchyHandler(String classifierName) 85 89 { super(); 86 90 … … 89 93 this.path = null; 90 94 this.match = null; 91 this. rootNodes = new ArrayList();95 this.prefix = classifierName; 92 96 } 93 97 94 98 public void startElement(String URI, String localName, String qName, Attributes attributes) 95 { if (localName.equals(" Classification"))99 { if (localName.equals("Hierarchy")) 96 100 { // create a new node in the hierarchy 97 HierarchyNode node = new HierarchyNode(); 101 HierarchyNode node = new HierarchyNode(prefix, "", "", "Classifier"); 102 103 this.rootNode = node; 104 this.currentNode = node; 105 } 106 else if (localName.equals("Classification")) 107 { // create a new node in the hierarchy 108 HierarchyNode node = new HierarchyNode(this.prefix, "", "", ""); 98 109 99 110 // Initialise the tree … … 127 138 { if (localName.equals("Classification")) 128 139 { if (this.currentNode.getParent() == null) { 129 this.rootNodes.add(this.currentNode); 140 // TODO: Error state 141 // this.rootNodes.add(this.currentNode); 130 142 } 131 143 this.currentNode = this.currentNode.getParent(); … … 133 145 else if (localName.equals("Name")) 134 146 { this.currentNode.setName(XMLTools.cleanString(this.name.toString())); 147 System.out.println("Name is " + this.name); 135 148 this.name = null; 136 149 } … … 177 190 private List fields; 178 191 private String sortBy; 179 180 public HierarchyClassifier(URL basefile, List fields, String sortBy) 192 private String name; 193 194 public HierarchyClassifier(String name, URL basefile, List fields, String sortBy) 181 195 { 182 196 try 183 184 HierarchyHandler handler = new HierarchyHandler( );197 { SAXParser parser = new SAXParser(); 198 HierarchyHandler handler = new HierarchyHandler(name); 185 199 /* 186 200 XMLReader reader = XMLReaderFactory.createXMLReader();
Note:
See TracChangeset
for help on using the changeset viewer.