Changeset 5947
- Timestamp:
- 2003-11-24T14:28:07+13:00 (20 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util/GS3SQLConnection.java
r5800 r5947 117 117 return true; 118 118 } 119 120 public Statement createStatement() 121 { try { 122 return this.connection.createStatement(); 123 } 124 catch (SQLException ex) 125 { 126 return null; 127 } 128 } 119 129 120 130 public Statement getStatement() … … 132 142 } 133 143 134 public void initCollection(String collectionName) 144 /** 145 * Initialise a collection for use. 146 * 147 * @return <code>boolean</code> <code>true</code> if the collection successfully initialised. 148 */ 149 public boolean initCollection(String collectionName) 135 150 { 151 /* 136 152 // Check if the collection already exists 137 153 // if so, abort 138 // else 154 155 // do a sample query to check if the collection exists 156 GS3SQLSelect select = new GS3SQLSelect("document"); 157 select.addField("*"); 158 if (this.execute(select.toString())) { 159 return true; 160 } 161 162 // if there is an error, assume that the database doesn't exist... 163 // and reconnect to a "test" database for now... 164 this.connection = GS3SQLConnectionFactory.reconnect("test"); 165 */ 166 139 167 // create database 140 168 String command = "CREATE DATABASE " + collectionName; 141 169 142 170 try { 143 this.statement = this.connection.createStatement(); 144 this.statement.execute(command); 145 146 // TODO: reconnect with the new database 147 this.connection = GS3SQLConnectionFactory.reconnect(collectionName); 148 149 // create document table 150 GS3SQLCreateTable docTable = new GS3SQLCreateTable("document"); 151 docTable.addProperty("DocID", 64); 152 docTable.setPrimaryKey("DocID"); 153 statement = this.connection.createStatement(); 154 System.out.println(docTable.toString()); 155 statement.execute(docTable.toString()); 156 157 // create structure table 158 GS3SQLCreateTable structureMap = new GS3SQLCreateTable("structure"); 159 structureMap.addAutoPrimaryKey("StructureRef"); 160 structureMap.addProperty("DocID", 64); // a 'foreign key' in effect - but not treated 161 // as such for efficiency reasons 162 structureMap.addProperty("StructureID", 64); // this identifier 163 structureMap.addProperty("Type", 64); // the type of the structure 164 structureMap.addProperty("Label", 128); // the label of the structure 165 statement.execute(structureMap.toString()); 166 167 // create section table 168 GS3SQLCreateTable sectionMap = new GS3SQLCreateTable("divisions"); 169 sectionMap.addAutoPrimaryKey("divisionRef"); 170 sectionMap.addProperty("StructureRef", GS3SQLField.INTEGER_TYPE); 171 sectionMap.addProperty("DocID", 64); // a 'foreign key' in effect - but not treated 172 // as such for efficiency reasons 173 sectionMap.addProperty("ParentType", 64); // the type of the parent - document or section 174 sectionMap.addProperty("ParentRef", 64); // the parent sql reference identifier 175 sectionMap.addProperty("SectionID", 64); // this identifier 176 sectionMap.addProperty("Type", 64); // the type of the section 177 sectionMap.addProperty("LabelOrder", 64); // the order of the section 178 sectionMap.addProperty("ShortLabel", 128); // the short label of the section 179 sectionMap.addProperty("UserLabel", 255); // the long label of the section 180 System.out.println(sectionMap.toString()); 181 statement.execute(sectionMap.toString()); 182 183 // a division->metadata reference mapping 184 GS3SQLCreateTable metaRefs = new GS3SQLCreateTable("divisionmetarefs"); 185 metaRefs.addProperty("divisionRef", GS3SQLField.INTEGER_TYPE); 186 metaRefs.addProperty("Type", 16); // whether a namespace or meta ref 187 metaRefs.addProperty("metadataRef", 32); // the metadata reference itself, as a string 188 statement.execute(metaRefs.toString()); 189 190 // a division->file reference mapping 191 GS3SQLCreateTable fileRefs = new GS3SQLCreateTable("divisionfilerefs"); 192 fileRefs.addProperty("divisionRef", GS3SQLField.INTEGER_TYPE); 193 fileRefs.addProperty("Type", 16); // whether section, group or file 194 fileRefs.addProperty("fileRef", 32); 195 statement.execute(fileRefs.toString()); 196 197 // create metadata table section table 198 GS3SQLCreateTable metadataSection = new GS3SQLCreateTable("metadata"); 199 metadataSection.addAutoPrimaryKey("MetadataRef"); 200 metadataSection.addProperty("DocID", 64); // this table isn't actually used for much 201 metadataSection.addProperty("MetaID", 64); // in and of itself... 202 System.out.println(metadataSection.toString()); 203 statement.execute(metadataSection.toString()); 204 205 // create namespace table 206 GS3SQLCreateTable namespaces = new GS3SQLCreateTable("namespaces"); 207 namespaces.addAutoPrimaryKey("NamespaceRef"); 208 namespaces.addProperty("MetadataRef", GS3SQLField.INTEGER_TYPE); 209 namespaces.addProperty("DocID", 64); // these three fields are the primary key 210 namespaces.addProperty("MetaID", 64); 211 namespaces.addProperty("NamespaceID", 64); 212 namespaces.addProperty("NamespaceType", 64); 213 namespaces.addProperty("fileType", 64); 214 namespaces.addProperty("fileLoc"); 215 namespaces.addProperty("creator", 128); 216 statement.execute(namespaces.toString()); 217 218 // create metadata values table 219 GS3SQLCreateTable metadata = new GS3SQLCreateTable("mdvalues"); 220 // todo: some unique id for the namespaces item 221 metadata.addProperty("NamespaceRef", GS3SQLField.INTEGER_TYPE); 222 metadata.addProperty("label", 256); 223 metadata.addProperty("value"); 224 statement.execute(metadata.toString()); 225 226 // create file section table 227 GS3SQLCreateTable filesec = new GS3SQLCreateTable("filesection"); 228 filesec.addProperty("DocID", 64); 229 filesec.addProperty("FileSecID", 64); 230 statement.execute(filesec.toString()); 231 232 // create file groups table 233 GS3SQLCreateTable filegroups = new GS3SQLCreateTable("filegroups"); 234 // TODO: some unique identifier 235 filegroups.addProperty("DocID", 64); 236 filegroups.addProperty("FileGroupID", 64); 237 filegroups.addProperty("ParentGroup", 64); 238 statement.execute(filegroups.toString()); 239 240 // create file table 241 GS3SQLCreateTable files = new GS3SQLCreateTable("files"); 242 // TODO: the unique identifier from file groups table 243 files.addProperty("FileLocType", 64); 244 files.addProperty("FileLocation"); 245 files.addProperty("MIMEType", 64); 246 files.addProperty("ID", 32); 247 statement.execute(files.toString()); 248 249 // create admin table...etc. 171 this.statement = this.connection.createStatement(); 172 this.statement.execute(command); 173 174 // reconnect with the new database 175 this.connection = GS3SQLConnectionFactory.reconnect(collectionName); 176 177 // create document table 178 GS3SQLCreateTable docTable = new GS3SQLCreateTable("document"); 179 docTable.addProperty("DocID", 64); 180 docTable.setPrimaryKey("DocID"); 181 docTable.addProperty("DocType", 64); 182 statement = this.connection.createStatement(); 183 System.out.println(docTable.toString()); 184 statement.execute(docTable.toString()); 185 186 // create structure table 187 GS3SQLCreateTable structureMap = new GS3SQLCreateTable("structure"); 188 structureMap.addAutoPrimaryKey("StructureRef"); 189 structureMap.addProperty("DocID", 64); // a 'foreign key' in effect - but not treated 190 // as such for efficiency reasons 191 structureMap.addProperty("StructureID", 64); // this identifier 192 structureMap.addProperty("Type", 64); // the type of the structure 193 structureMap.addProperty("Label", 128); // the label of the structure 194 statement.execute(structureMap.toString()); 195 196 // create section table 197 GS3SQLCreateTable sectionMap = new GS3SQLCreateTable("divisions"); 198 sectionMap.addAutoPrimaryKey("divisionRef"); 199 sectionMap.addProperty("StructureRef", GS3SQLField.INTEGER_TYPE); 200 sectionMap.addProperty("DocID", 64); // a 'foreign key' in effect - but not treated 201 // as such for efficiency reasons 202 sectionMap.addProperty("ParentType", 64); // the type of the parent - document or section 203 sectionMap.addProperty("ParentRef", 64); // the parent sql reference identifier 204 sectionMap.addProperty("SectionID", 64); // this identifier 205 sectionMap.addProperty("Type", 64); // the type of the section 206 sectionMap.addProperty("LabelOrder", 64); // the order of the section 207 sectionMap.addProperty("ShortLabel", 128); // the short label of the section 208 sectionMap.addProperty("UserLabel", 255); // the long label of the section 209 System.out.println(sectionMap.toString()); 210 statement.execute(sectionMap.toString()); 211 212 // a division->metadata reference mapping 213 GS3SQLCreateTable metaRefs = new GS3SQLCreateTable("divisionmetarefs"); 214 metaRefs.addProperty("divisionRef", GS3SQLField.INTEGER_TYPE); 215 metaRefs.addProperty("Type", 16); // whether a namespace or meta ref 216 metaRefs.addProperty("metadataRef", 32); // the metadata reference itself, as a string 217 statement.execute(metaRefs.toString()); 218 219 // a division->file reference mapping 220 GS3SQLCreateTable fileRefs = new GS3SQLCreateTable("divisionfilerefs"); 221 fileRefs.addProperty("divisionRef", GS3SQLField.INTEGER_TYPE); 222 fileRefs.addProperty("Type", 16); // whether section, group or file 223 fileRefs.addProperty("fileRef", 32); 224 statement.execute(fileRefs.toString()); 225 226 // create metadata table section table 227 GS3SQLCreateTable metadataSection = new GS3SQLCreateTable("metadata"); 228 metadataSection.addAutoPrimaryKey("MetadataRef"); 229 metadataSection.addProperty("DocID", 64); // this table isn't actually used for much 230 metadataSection.addProperty("MetaID", 64); // in and of itself... 231 metadataSection.addProperty("GroupID", 64); // the 'name' property 232 System.out.println(metadataSection.toString()); 233 statement.execute(metadataSection.toString()); 234 235 // create namespace table 236 GS3SQLCreateTable namespaces = new GS3SQLCreateTable("namespaces"); 237 namespaces.addAutoPrimaryKey("NamespaceRef"); 238 namespaces.addProperty("MetadataRef", GS3SQLField.INTEGER_TYPE); 239 namespaces.addProperty("DocID", 64); // these three fields are the primary key 240 namespaces.addProperty("MetaID", 64); 241 namespaces.addProperty("NamespaceID", 64); 242 namespaces.addProperty("NamespaceType", 64); 243 namespaces.addProperty("fileType", 64); 244 namespaces.addProperty("fileLoc"); 245 namespaces.addProperty("creator", 128); 246 statement.execute(namespaces.toString()); 247 248 // create metadata values table 249 GS3SQLCreateTable metadata = new GS3SQLCreateTable("mdvalues"); 250 // todo: some unique id for the namespaces item 251 metadata.addProperty("NamespaceRef", GS3SQLField.INTEGER_TYPE); 252 metadata.addProperty("label", 256); 253 metadata.addProperty("value"); 254 statement.execute(metadata.toString()); 255 256 // create file section table 257 GS3SQLCreateTable filesec = new GS3SQLCreateTable("filesection"); 258 filesec.addAutoPrimaryKey("FileSectionRef"); 259 filesec.addProperty("DocID", 64); 260 filesec.addProperty("FileSecID", 64); 261 statement.execute(filesec.toString()); 262 263 // create file groups table 264 GS3SQLCreateTable filegroups = new GS3SQLCreateTable("filegroups"); 265 // TODO: some unique identifier 266 filegroups.addAutoPrimaryKey("FileGroupRef"); 267 filegroups.addProperty("DocID", 64); 268 filegroups.addProperty("FileGroupID", 64); 269 filegroups.addProperty("ParentRef", GS3SQLField.INTEGER_TYPE); 270 filegroups.addProperty("ParentType", 16); 271 statement.execute(filegroups.toString()); 272 273 // create file table 274 GS3SQLCreateTable files = new GS3SQLCreateTable("files"); 275 // TODO: the unique identifier from file groups table 276 files.addProperty("FileGroupRef", GS3SQLField.INTEGER_TYPE); 277 files.addProperty("FileLocType", 64); 278 files.addProperty("FileLocation"); 279 files.addProperty("MIMEType", 64); 280 files.addProperty("ID", 32); 281 statement.execute(files.toString()); 282 283 // create admin table...etc. 250 284 } 251 285 catch (SQLException ex) 252 { 253 System.out.println(ex.toString()); 254 } 286 { 287 System.out.println(ex.toString()); 288 return false; 289 } 290 return true; 255 291 } 256 292 … … 258 294 { 259 295 try { 260 261 296 statement = this.connection.createStatement(); 297 statement.execute("DROP DATABASE "+collection+";"); 262 298 } 263 299 catch (SQLException ex) 264 265 300 { 301 } 266 302 } 267 303 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/util/HTMLParser.java
r5800 r5947 27 27 } 28 28 29 // do a full text/tag parse 30 public String fullParse() 31 { String reply = null; 32 int end; 33 int start; 34 35 this.lastpos = this.pos; 36 37 if (this.pos >= this.document.getContent().length()) 38 { return reply; 39 } 40 41 if (this.document.getContent().charAt(this.pos) == '<') 42 { 43 // if we're not at the end of the document, 44 // read the rest of the tag 45 if (this.pos == this.document.getContent().length() - 1) 46 { this.pos = this.document.getContent().length(); 47 return reply; 48 } 49 50 // read up to the end of the tag 51 end = this.pos + 1; 52 while ( end < this.document.getContent().length() && 53 this.document.getContent().charAt(end) != '>') 54 { end ++; 55 } 56 57 // get the whole of the tag into 'reply', and 58 // set the current pos to immediately after the tag 59 if (end < this.document.getContent().length()) 60 { reply = this.document.getContent().substring(this.pos, end + 1); 61 this.pos = end + 1; 62 } 63 // patch the trailing > onto the tag string 64 else 65 { reply = this.document.getContent().substring(this.pos, end) + ">"; 66 this.pos = end; 67 } 68 } 69 else 70 { // hunt for the beginning of the next tag 71 start = this.pos; 72 while ((this.pos < this.document.getContent().length()) && 73 (this.document.getContent().charAt(this.pos) != '<')) 74 { this.pos ++; 75 } 76 77 // return everything up to that tag 78 reply = this.document.getContent().substring(start, this.pos); 79 } 80 return reply; 81 } 29 // do a full text/tag parse 30 public String fullParse() 31 { String reply = null; 32 int end; 33 int start; 34 35 this.lastpos = this.pos; 36 37 if (this.pos >= this.document.getContent().length()) 38 { return reply; 39 } 40 41 if (this.document.getContent().charAt(this.pos) == '<') 42 { 43 start = this.pos; 44 45 // if we're not at the end of the document, 46 // read the rest of the tag 47 if (this.pos == this.document.getContent().length() - 1) 48 { this.pos = this.document.getContent().length(); 49 return reply; 50 } 51 52 // if the tag is a comment 53 if (this.pos < this.document.getContent().length() - 3 && 54 this.document.getContent().substring(this.pos, this.pos+4).equals("<!--")) 55 { end = this.document.getContent().substring(this.pos).indexOf("-->") + 3 + this.pos; 56 reply = this.document.getContent().substring(this.pos, end); 57 this.pos = end; 58 } 59 else 60 { // read up to the end of the tag 61 end = this.pos + 1; 62 while (end < this.document.getContent().length() && 63 this.document.getContent().charAt(end) != '>') 64 { end ++; 65 } 66 67 // get the whole of the tag into 'reply', and 68 // set the current pos to immediately after the tag 69 if (end < this.document.getContent().length()) 70 { reply = this.document.getContent().substring(this.pos, end + 1); 71 this.pos = end + 1; 72 } 73 // patch the trailing > onto the tag string 74 else 75 { reply = this.document.getContent().substring(this.pos, end) + ">"; 76 this.pos = end; 77 } 78 } 79 } 80 else 81 { // hunt for the beginning of the next tag 82 start = this.pos; 83 while ((this.pos < this.document.getContent().length()) && 84 (this.document.getContent().charAt(this.pos) != '<')) 85 { this.pos ++; 86 } 87 88 // return everything up to that tag 89 reply = this.document.getContent().substring(start, this.pos); 90 } 91 return reply; 92 } 82 93 83 94 // Get the next tag to parse
Note:
See TracChangeset
for help on using the changeset viewer.