nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
amywu | ecebb04 | 2007-04-10 20:07:35 +0000 | [diff] [blame] | 2 | * Copyright (c) 2001, 2005 IBM Corporation and others. |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
amywu | ecebb04 | 2007-04-10 20:07:35 +0000 | [diff] [blame] | 7 | * |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | *******************************************************************************/ |
| 11 | |
| 12 | package org.eclipse.wst.dtd.core.internal.emf.util; |
| 13 | |
| 14 | import java.io.File; |
| 15 | import java.io.FileWriter; |
| 16 | import java.io.IOException; |
| 17 | import java.io.PrintWriter; |
| 18 | import java.util.Collection; |
| 19 | import java.util.HashMap; |
| 20 | import java.util.Hashtable; |
| 21 | import java.util.Iterator; |
| 22 | import java.util.Map; |
| 23 | import java.util.Vector; |
| 24 | |
| 25 | import org.eclipse.core.runtime.IPath; |
| 26 | import org.eclipse.core.runtime.Path; |
| 27 | import org.eclipse.emf.common.util.BasicEList; |
| 28 | import org.eclipse.emf.common.util.EList; |
| 29 | import org.eclipse.emf.common.util.URI; |
| 30 | import org.eclipse.emf.ecore.resource.Resource; |
| 31 | import org.eclipse.emf.ecore.resource.ResourceSet; |
| 32 | import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; |
| 33 | import org.eclipse.wst.dtd.core.internal.emf.DTDConstants; |
| 34 | import org.eclipse.wst.dtd.core.internal.emf.DTDElement; |
| 35 | import org.eclipse.wst.dtd.core.internal.emf.DTDElementContent; |
| 36 | import org.eclipse.wst.dtd.core.internal.emf.DTDEntity; |
| 37 | import org.eclipse.wst.dtd.core.internal.emf.DTDFactory; |
| 38 | import org.eclipse.wst.dtd.core.internal.emf.DTDFile; |
| 39 | import org.eclipse.wst.dtd.core.internal.emf.DTDGroupKind; |
| 40 | import org.eclipse.wst.dtd.core.internal.emf.DTDObject; |
| 41 | import org.eclipse.wst.dtd.core.internal.emf.impl.DTDFactoryImpl; |
| 42 | import org.eclipse.wst.dtd.core.internal.saxparser.DTD; |
| 43 | import org.eclipse.wst.dtd.core.internal.saxparser.DTDParser; |
| 44 | import org.eclipse.wst.dtd.core.internal.saxparser.ErrorMessage; |
| 45 | |
| 46 | /** |
| 47 | * Create MOF objects from the parsed DTD If no DTD file is specifed, create |
| 48 | * the root MOF object |
| 49 | */ |
| 50 | public class DTDUtil { |
| 51 | DTDFactory factory; |
| 52 | EList extent; |
| 53 | Resource resource; |
| 54 | DTDFile dtdFile; |
| 55 | String dtdModelFile; |
| 56 | boolean expandEntityReferences; |
| 57 | |
| 58 | private Hashtable externalDTDModels = new Hashtable(); |
| 59 | private Hashtable pePool = new Hashtable(); |
| 60 | private Hashtable elementPool = new Hashtable(); |
| 61 | |
| 62 | private DTDParser parser; |
| 63 | |
| 64 | private Vector errorMsgs = new Vector(); |
| 65 | |
| 66 | private static Hashtable utilCache = new Hashtable(); |
| 67 | |
| 68 | static public DTDUtil getDTDUtilFor(String filename) { |
| 69 | DTDUtil util = (DTDUtil) utilCache.get(filename); |
| 70 | if (util == null) { |
| 71 | util = new DTDUtil(); |
| 72 | utilCache.put(filename, util); |
| 73 | } |
| 74 | |
| 75 | return util; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | public void parse(String uri) { |
| 80 | parse(new ResourceSetImpl(), uri); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Invoke parse to parse a .dtd file into a MOF object model This is |
| 85 | * invoked by the RegisteredDTDParser that registers this parser for MOF |
| 86 | * to use against the .dtd type |
| 87 | * |
| 88 | * @param filename - |
| 89 | * the fully qualifed name of a .dtd file |
| 90 | */ |
| 91 | public void parse(ResourceSet resources, String filename) { |
| 92 | // Get the dtd name from the file name |
| 93 | Path path = new Path(filename); |
| 94 | IPath iPath = path.removeFileExtension(); |
| 95 | String dtdName = iPath.toFile().getName(); |
| 96 | |
| 97 | try { |
| 98 | parser = new DTDParser(false); |
| 99 | if (expandEntityReferences) { |
| 100 | parser.setExpandEntityReferences(expandEntityReferences); |
| 101 | } |
| 102 | parser.parse(filename); |
| 103 | } |
| 104 | catch (IOException ex) { |
| 105 | ex.printStackTrace(System.err); |
| 106 | } |
| 107 | |
| 108 | dtdModelFile = filename; |
| 109 | |
| 110 | factory = DTDFactoryImpl.instance(); |
| 111 | |
| 112 | extent = new BasicEList(); |
| 113 | |
| 114 | dtdFile = factory.createDTDFile(); |
| 115 | extent.add(dtdFile); |
| 116 | |
| 117 | dtdFile.setName(dtdName); |
| 118 | |
| 119 | populateDTD(resources, expandEntityReferences); |
| 120 | } |
| 121 | |
| 122 | public DTDFactory getFactory() { |
| 123 | return factory; |
| 124 | } |
| 125 | |
| 126 | public DTDFile getDTDFile() { |
| 127 | return dtdFile; |
| 128 | } |
| 129 | |
| 130 | public Hashtable getPEPool() { |
| 131 | return pePool; |
| 132 | } |
| 133 | |
| 134 | public Hashtable getElementPool() { |
| 135 | return elementPool; |
| 136 | } |
| 137 | |
| 138 | public EList getContents() { |
| 139 | return extent; |
| 140 | } |
| 141 | |
| 142 | public void setResource(Resource resource) { |
| 143 | this.resource = resource; |
| 144 | } |
| 145 | |
| 146 | public Resource getResource(Resource resource) { |
| 147 | return resource; |
| 148 | } |
| 149 | |
| 150 | public void setexpandEntityReferences(boolean expandEntityReferences) { |
| 151 | this.expandEntityReferences = expandEntityReferences; |
| 152 | } |
| 153 | |
| 154 | public boolean getExpandEntityReferences() { |
| 155 | return expandEntityReferences; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Return true if the model has been modified |
| 160 | */ |
| 161 | public boolean isModelDirty() { |
| 162 | if (resource != null) { |
| 163 | return resource.isModified(); |
| 164 | } |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Save the .dtd file |
| 170 | */ |
| 171 | public boolean save() { |
| 172 | try { |
| 173 | Map options = new HashMap(); |
| 174 | resource.save(options); |
| 175 | return true; |
| 176 | } |
| 177 | catch (Exception ex) { |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 178 | System.out.println("Save model exception " + ex); //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 179 | ex.printStackTrace(); |
| 180 | return false; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | public boolean saveAs(String newFilename) { |
| 185 | resource.setURI(URI.createURI(newFilename)); |
| 186 | boolean ok = save(); |
| 187 | |
| 188 | if (ok) { |
| 189 | Path path = new Path(newFilename); |
| 190 | IPath iPath = path.removeFileExtension(); |
| 191 | String dtdName = iPath.toFile().getName(); |
| 192 | |
| 193 | dtdFile.setName(dtdName); |
| 194 | } |
| 195 | return ok; |
| 196 | } |
| 197 | |
| 198 | public boolean saveDTDFile(String filename) { |
| 199 | boolean result = true; |
| 200 | try { |
| 201 | PrintWriter pw = new PrintWriter(new FileWriter(filename), true); |
| 202 | DTDPrinter printer = new DTDPrinter(true); |
| 203 | printer.visitDTDFile(dtdFile); |
| 204 | |
| 205 | String s = printer.getBuffer().toString(); |
| 206 | pw.println(s); |
| 207 | pw.close(); |
| 208 | } |
| 209 | |
| 210 | catch (Exception e) { |
| 211 | result = false; |
| 212 | } |
| 213 | return result; |
| 214 | } |
| 215 | |
| 216 | public String getDTDSource(boolean includeError) { |
| 217 | return dtdFile.unparse(includeError); // true = include error lines |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Create MOF objects from DTD |
| 222 | */ |
| 223 | private void populateDTD(ResourceSet resources, boolean expandEntityReferences) { |
| 224 | Vector dtdList = parser.getDTDList(); |
| 225 | |
| 226 | // create XMIModel for the included DTDs |
| 227 | if (dtdList.size() > 0) { |
| 228 | if (!expandEntityReferences) { |
| 229 | for (int i = dtdList.size() - 1; i > 0; i--) { |
| 230 | DTD dtd = (DTD) dtdList.elementAt(i); |
| 231 | loadIncludedDTD(resources, dtd); |
| 232 | } |
| 233 | |
| 234 | DTD dtd = (DTD) dtdList.elementAt(0); |
| 235 | populateDTD(resources, dtd, dtdFile); // populate the main |
| 236 | // DTD |
| 237 | // validateWithModel(dtd); |
| 238 | } |
| 239 | else { |
| 240 | for (int i = dtdList.size() - 1; i >= 0; i--) { |
| 241 | DTD dtd = (DTD) dtdList.elementAt(i); |
| 242 | populateDTD(resources, dtd, dtdFile); |
| 243 | // validateWithModel(dtd); |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | // return the instance unique to this DTDUtil file that represents an |
| 250 | // externally loaded dtd (will create if one doesn't exist yet) |
| 251 | public ExternalDTDModel getExternalDTDModel(ResourceSet resources, String uri) { |
| 252 | if (expandEntityReferences) { |
| 253 | return null; |
| 254 | } |
| 255 | |
| 256 | // DefaultMsgLogger.write("External DTD name: " + uri); |
| 257 | |
| 258 | if (externalDTDModels.containsKey(uri)) { |
| 259 | return (ExternalDTDModel) externalDTDModels.get(uri); |
| 260 | } |
| 261 | else { |
| 262 | ExternalDTDModel extModel = new ExternalDTDModel(); |
| 263 | if (extModel.loadModel(resources, uri)) { |
| 264 | externalDTDModels.put(uri, extModel); |
| 265 | return extModel; |
| 266 | } |
| 267 | } |
| 268 | return null; |
| 269 | } |
| 270 | |
| 271 | // load xmiModels for included DTDs |
| 272 | private void loadIncludedDTD(ResourceSet resources, DTD dtd) { |
| 273 | ExternalDTDModel extModel = getExternalDTDModel(resources, dtd.getName()); |
| 274 | if (extModel != null) { |
| 275 | // now fill our hash tables for elements and parameter entities |
| 276 | // so that we know what can be referenced by our main dtd |
| 277 | DTDFile file = extModel.getExternalDTDFile(); |
| 278 | Collection elementList = file.listDTDElement(); |
| 279 | Collection entityList = file.listDTDEntity(); |
| 280 | |
| 281 | Iterator i = elementList.iterator(); |
| 282 | while (i.hasNext()) { |
| 283 | DTDObject object = (DTDObject) i.next(); |
| 284 | elementPool.put(getBaseName(object), object); |
| 285 | } |
| 286 | |
| 287 | i = entityList.iterator(); |
| 288 | while (i.hasNext()) { |
| 289 | DTDEntity entity = (DTDEntity) i.next(); |
| 290 | if (entity.isParameterEntity()) { |
| 291 | pePool.put(getBaseName(entity), entity); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Create MOF objects from DTD |
| 299 | * |
| 300 | * 1) will create the corresponding DTD Mof object for EntityDecl, |
| 301 | * NotationDecl and ElementDecl declarations during the 1st pass 2) During |
| 302 | * the 2nd pass, it will add the contentModel and Attlist to all |
| 303 | * ElementDecl. |
| 304 | * |
| 305 | */ |
| 306 | private void populateDTD(ResourceSet resources, DTD dtd, DTDFile dFile) { |
| 307 | DTDModelBuilder modelBuilder = new DTDModelBuilder(resources, this, dtd, dFile); |
| 308 | |
| 309 | modelBuilder.visitDTD(dtd); |
| 310 | } |
| 311 | |
| 312 | |
| 313 | public void emptyErrorMessages() { |
| 314 | errorMsgs.removeAllElements(); |
| 315 | } |
| 316 | |
| 317 | public void addErrorMessage(ErrorMessage error) { |
| 318 | int vectorSize = errorMsgs.size(); |
| 319 | boolean add = true; |
| 320 | |
| 321 | if (vectorSize != 0) { |
| 322 | int index = 0; |
| 323 | |
| 324 | while (add == true && index < vectorSize) { |
| 325 | if (((ErrorMessage) errorMsgs.elementAt(index)).equals(error)) { |
| 326 | add = false; |
| 327 | } |
| 328 | else { |
| 329 | index++; |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | if (add) { |
| 335 | errorMsgs.addElement(error); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | public Vector getErrors() { |
| 340 | return errorMsgs; |
| 341 | } |
| 342 | |
| 343 | // This gets the name without any pseudo namespace prefix |
| 344 | public static String getBaseName(DTDObject obj) { |
| 345 | return getName(obj, null); |
| 346 | } |
| 347 | |
| 348 | // This gets the name with pseudo namespace prefixes if dtdFile is not |
| 349 | // null |
| 350 | public static String getName(DTDObject obj, DTDFile dtdFile) { |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 351 | String name = ""; //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 352 | if (obj instanceof DTDEntity) { |
| 353 | DTDEntity entity = (DTDEntity) obj; |
| 354 | if (dtdFile != null && !entity.getDTDFile().equals(dtdFile)) { |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 355 | name = new Path(entity.getDTDFile().getName()).lastSegment() + ": "; //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 356 | } |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 357 | name += "%" + ((DTDEntity) obj).getName() + ";"; //$NON-NLS-1$ //$NON-NLS-2$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 358 | } |
| 359 | else if (obj instanceof DTDElement) { |
| 360 | DTDElement element = (DTDElement) obj; |
| 361 | if (dtdFile != null && !element.getDTDFile().equals(dtdFile)) { |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 362 | name = new Path(element.getDTDFile().getName()).lastSegment() + ": "; //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 363 | } |
| 364 | name += ((DTDElement) obj).getName(); |
| 365 | } |
| 366 | else if (obj instanceof DTDElementContent) { |
| 367 | return ((DTDElementContent) obj).getContentName(); |
| 368 | } |
| 369 | return name; |
| 370 | } |
| 371 | |
| 372 | public static String getGroupType(int groupKind, int occurrence) { |
| 373 | String type = null; |
| 374 | |
| 375 | switch (groupKind) { |
| 376 | case DTDGroupKind.SEQUENCE : |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 377 | type = "DTDSequence"; //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 378 | break; |
| 379 | case DTDGroupKind.CHOICE : |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 380 | type = "DTDChoice"; //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 381 | break; |
| 382 | } |
| 383 | |
| 384 | type += getRepeatableTypeSuffix(occurrence); |
| 385 | return type; |
| 386 | } |
| 387 | |
| 388 | public static String getReferenceType(int occurrence) { |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 389 | String type = "DTDReference"; //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 390 | type += getRepeatableTypeSuffix(occurrence); |
| 391 | return type; |
| 392 | } |
| 393 | |
| 394 | private static String getRepeatableTypeSuffix(int occurrence) { |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 395 | return "(" + (char) occurrence + ")"; //$NON-NLS-1$ //$NON-NLS-2$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | public static void main(String args[]) { |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 399 | System.out.println("\nStarting ..."); //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 400 | |
| 401 | if (args.length != 1) |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 402 | System.out.println("usage: DtdUtil inputfile.dtd"); //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 403 | |
| 404 | java.io.File inputFile = new File(args[0]); |
| 405 | |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 406 | String dtdFileName = ""; //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 407 | try { |
| 408 | dtdFileName = inputFile.getCanonicalPath(); |
| 409 | } |
| 410 | catch (IOException ex) { |
| 411 | } |
| 412 | |
| 413 | String dtdModelName = dtdFileName; |
| 414 | |
| 415 | if (DTDConstants.DTD_EXTENSION.equals(new Path(dtdFileName).getFileExtension())) { |
| 416 | dtdModelName = new Path(dtdFileName).removeFileExtension().lastSegment(); |
| 417 | } |
| 418 | DTDUtil d2m = new DTDUtil(); |
| 419 | // TODO: fix port |
| 420 | // d2m.parse(dtdFileName); |
| 421 | try { |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 422 | d2m.saveAs(dtdModelName + "." + DTDConstants.DTD_XMI_EXTENSION); //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 423 | } |
| 424 | catch (Exception e) { |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 425 | System.out.println("Exception thrown during model save: " + e); //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 426 | } |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 427 | System.out.println("Done."); //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | public org.eclipse.core.runtime.IPath getPath() { |
| 431 | Path currentDTDPath = new Path(dtdModelFile); |
| 432 | if (currentDTDPath.segmentCount() > 1) { |
| 433 | return currentDTDPath.removeLastSegments(1).addTrailingSeparator(); |
| 434 | } |
| 435 | |
david_williams | 3804601 | 2005-04-08 19:04:29 +0000 | [diff] [blame] | 436 | return new Path(""); //$NON-NLS-1$ |
nitind | d6e591d | 2005-03-14 22:21:57 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | // /** |
| 440 | // * @generated |
| 441 | // */ |
| 442 | // protected static DTDUtil getDTDUtilForGen(String filename) { |
| 443 | // |
| 444 | // DTDUtil util = (DTDUtil) utilCache.get(filename); |
| 445 | // if (util == null) |
| 446 | // { |
| 447 | // util = new DTDUtil(); |
| 448 | // utilCache.put(filename, util); |
| 449 | // } |
| 450 | // |
| 451 | // return util; |
| 452 | // } |
| 453 | // /** |
| 454 | // * @generated |
| 455 | // */ |
| 456 | // protected void parseGen(String uri) { |
| 457 | // |
| 458 | // parse(new ResourceSetImpl(), uri); |
| 459 | // } |
| 460 | // /** |
| 461 | // * Invoke parse to parse a .dtd file into a MOF object model |
| 462 | // * This is invoked by the RegisteredDTDParser that registers this parser |
| 463 | // for MOF to use |
| 464 | // * against the .dtd type |
| 465 | // * @param filename - the fully qualifed name of a .dtd file |
| 466 | // */ |
| 467 | // protected void parseGen(ResourceSet resources, String filename) { |
| 468 | // |
| 469 | // // Get the dtd name from the file name |
| 470 | // Path path = new Path(filename); |
| 471 | // IPath iPath = path.removeFileExtension(); |
| 472 | // String dtdName = iPath.toFile().getName(); |
| 473 | // |
| 474 | // |
| 475 | // try |
| 476 | // { |
| 477 | // parser = new DTDParser(false); |
| 478 | // if (expandEntityReferences) |
| 479 | // { |
| 480 | // parser.setExpandEntityReferences(expandEntityReferences); |
| 481 | // } |
| 482 | // parser.parse(filename); |
| 483 | // } |
| 484 | // catch(IOException ex) |
| 485 | // { |
| 486 | // ex.printStackTrace(System.err); |
| 487 | // } |
| 488 | // |
| 489 | // |
| 490 | // dtdModelFile = filename; |
| 491 | // |
| 492 | // |
| 493 | // factory = DTDFactoryImpl.instance(); |
| 494 | // |
| 495 | // |
| 496 | // extent = new BasicEList(); |
| 497 | // |
| 498 | // |
| 499 | // dtdFile = factory.createDTDFile(); |
| 500 | // extent.add(dtdFile); |
| 501 | // |
| 502 | // |
| 503 | // dtdFile.setName(dtdName); |
| 504 | // |
| 505 | // |
| 506 | // populateDTD(resources, expandEntityReferences); |
| 507 | // } |
| 508 | // /** |
| 509 | // * @generated |
| 510 | // */ |
| 511 | // protected DTDFactory getFactoryGen() { |
| 512 | // |
| 513 | // return factory; |
| 514 | // } |
| 515 | // /** |
| 516 | // * @generated |
| 517 | // */ |
| 518 | // protected DTDFile getDTDFileGen() { |
| 519 | // |
| 520 | // return dtdFile; |
| 521 | // } |
| 522 | // /** |
| 523 | // * @generated |
| 524 | // */ |
| 525 | // protected Hashtable getPEPoolGen() { |
| 526 | // |
| 527 | // return pePool; |
| 528 | // } |
| 529 | // /** |
| 530 | // * @generated |
| 531 | // */ |
| 532 | // protected Hashtable getElementPoolGen() { |
| 533 | // |
| 534 | // return elementPool; |
| 535 | // } |
| 536 | // /** |
| 537 | // * @generated |
| 538 | // */ |
| 539 | // protected EList getExtentGen() { |
| 540 | // |
| 541 | // return extent; |
| 542 | // } |
| 543 | // /** |
| 544 | // * @generated |
| 545 | // */ |
| 546 | // protected void setResourceGen(Resource resource) { |
| 547 | // |
| 548 | // this.resource = resource; |
| 549 | // } |
| 550 | // /** |
| 551 | // * @generated |
| 552 | // */ |
| 553 | // protected Resource getResourceGen(Resource resource) { |
| 554 | // |
| 555 | // return resource; |
| 556 | // } |
| 557 | // /** |
| 558 | // * @generated |
| 559 | // */ |
| 560 | // protected void setexpandEntityReferencesGen(boolean |
| 561 | // expandEntityReferences) { |
| 562 | // |
| 563 | // this.expandEntityReferences = expandEntityReferences; |
| 564 | // } |
| 565 | // /** |
| 566 | // * @generated |
| 567 | // */ |
| 568 | // protected boolean getExpandEntityReferencesGen() { |
| 569 | // |
| 570 | // return expandEntityReferences; |
| 571 | // } |
| 572 | // /** |
| 573 | // * Return true if the model has been modified |
| 574 | // */ |
| 575 | // protected boolean isModelDirtyGen() { |
| 576 | // |
| 577 | // if (resource != null) |
| 578 | // { |
| 579 | // return resource.isModified(); |
| 580 | // } |
| 581 | // return false; |
| 582 | // } |
| 583 | // /** |
| 584 | // * Save the .dtd file |
| 585 | // */ |
| 586 | // protected boolean saveGen() { |
| 587 | // |
| 588 | // try |
| 589 | // { |
| 590 | // resource.save(); |
| 591 | // return true; |
| 592 | // } |
| 593 | // catch (Exception ex) |
| 594 | // { |
| 595 | // System.out.println("Save model exception " + ex); |
| 596 | // ex.printStackTrace(); |
| 597 | // return false; |
| 598 | // } |
| 599 | // } |
| 600 | // /** |
| 601 | // * @generated |
| 602 | // */ |
| 603 | // protected boolean saveAsGen(String newFilename) { |
| 604 | // |
| 605 | // resource.setURI(newFilename); |
| 606 | // boolean ok = save(); |
| 607 | // |
| 608 | // |
| 609 | // if (ok) |
| 610 | // { |
| 611 | // Path path = new Path(newFilename); |
| 612 | // IPath iPath = path.removeFileExtension(); |
| 613 | // String dtdName = iPath.toFile().getName(); |
| 614 | // |
| 615 | // |
| 616 | // dtdFile.setName(dtdName); |
| 617 | // } |
| 618 | // return ok; |
| 619 | // } |
| 620 | // /** |
| 621 | // * @generated |
| 622 | // */ |
| 623 | // protected boolean saveDTDFileGen(String filename) { |
| 624 | // |
| 625 | // boolean result=true; |
| 626 | // try |
| 627 | // { |
| 628 | // PrintWriter pw = new PrintWriter(new FileWriter(filename),true); |
| 629 | // DTDPrinter printer = new DTDPrinter(true); |
| 630 | // printer.visitDTDFile(dtdFile); |
| 631 | // |
| 632 | // |
| 633 | // String s = printer.getBuffer().getName().toString(); |
| 634 | // pw.println(s); |
| 635 | // pw.close(); |
| 636 | // } |
| 637 | // |
| 638 | // |
| 639 | // catch (Exception e) |
| 640 | // { |
| 641 | // result = false; |
| 642 | // } |
| 643 | // return result; |
| 644 | // } |
| 645 | // /** |
| 646 | // * @generated |
| 647 | // */ |
| 648 | // protected String getDTDSourceGen(boolean includeError) { |
| 649 | // |
| 650 | // return dtdFile.unparse(includeError); // true = include error lines |
| 651 | // } |
| 652 | // /** |
| 653 | // * Create MOF objects from DTD |
| 654 | // */ |
| 655 | // protected void populateDTDGen(ResourceSet resources, boolean |
| 656 | // expandEntityReferences) { |
| 657 | // |
| 658 | // Vector dtdList = parser.getDTDList(); |
| 659 | // |
| 660 | // |
| 661 | // // create XMIModel for the included DTDs |
| 662 | // if ( dtdList.size() > 0) |
| 663 | // { |
| 664 | // if (!expandEntityReferences) |
| 665 | // { |
| 666 | // for (int i=dtdList.size() - 1; i > 0; i--) |
| 667 | // { |
| 668 | // DTD dtd = (DTD) dtdList.elementAt(i); |
| 669 | // loadIncludedDTD(resources, dtd); |
| 670 | // } |
| 671 | // |
| 672 | // |
| 673 | // DTD dtd = (DTD) dtdList.elementAt(0); |
| 674 | // populateDTD(resources, dtd, dtdFile); // populate the main DTD |
| 675 | // // validateWithModel(dtd); |
| 676 | // } |
| 677 | // else |
| 678 | // { |
| 679 | // for (int i = dtdList.size() - 1; i >= 0; i--) |
| 680 | // { |
| 681 | // DTD dtd = (DTD) dtdList.elementAt(i); |
| 682 | // populateDTD(resources, dtd, dtdFile); |
| 683 | // // validateWithModel(dtd); |
| 684 | // } |
| 685 | // } |
| 686 | // } |
| 687 | // } |
| 688 | // /** |
| 689 | // * @generated |
| 690 | // */ |
| 691 | // protected ExternalDTDModel getExternalDTDModelGen(ResourceSet |
| 692 | // resources, String uri) { |
| 693 | // |
| 694 | // if (expandEntityReferences) |
| 695 | // { |
| 696 | // return null; |
| 697 | // } |
| 698 | // |
| 699 | // DefaultMsgLogger.write("External DTD name: " + uri); |
| 700 | // |
| 701 | // |
| 702 | // if (externalDTDModels.containsKey(uri)) |
| 703 | // { |
| 704 | // return (ExternalDTDModel) externalDTDModels.get(uri); |
| 705 | // } |
| 706 | // else |
| 707 | // { |
| 708 | // ExternalDTDModel extModel = new ExternalDTDModel(); |
| 709 | // if (extModel.loadModel(resources, uri)) |
| 710 | // { |
| 711 | // externalDTDModels.put(uri, extModel); |
| 712 | // return extModel; |
| 713 | // } |
| 714 | // } |
| 715 | // return null; |
| 716 | // } |
| 717 | // /** |
| 718 | // * @generated |
| 719 | // */ |
| 720 | // protected void loadIncludedDTDGen(ResourceSet resources, DTD dtd) { |
| 721 | // |
| 722 | // ExternalDTDModel extModel = getExternalDTDModel(resources, |
| 723 | // dtd.getName()); |
| 724 | // if (extModel != null) |
| 725 | // { |
| 726 | // // now fill our hash tables for elements and parameter entities |
| 727 | // // so that we know what can be referenced by our main dtd |
| 728 | // DTDFile file = extModel.getExternalDTDFile(); |
| 729 | // Collection elementList = file.listDTDElement(); |
| 730 | // Collection entityList = file.listDTDEntity(); |
| 731 | // |
| 732 | // |
| 733 | // Iterator i = elementList.iterator(); |
| 734 | // while (i.hasNext()) |
| 735 | // { |
| 736 | // DTDObject object = (DTDObject) i.next(); |
| 737 | // elementPool.put(getBaseName(object), object); |
| 738 | // } |
| 739 | // |
| 740 | // i = entityList.iterator(); |
| 741 | // while (i.hasNext()) |
| 742 | // { |
| 743 | // DTDEntity entity = (DTDEntity) i.next(); |
| 744 | // if (entity.isParameterEntity()) |
| 745 | // { |
| 746 | // pePool.put(getBaseName(entity), entity); |
| 747 | // } |
| 748 | // } |
| 749 | // } |
| 750 | // } |
| 751 | // /** |
| 752 | // * Create MOF objects from DTD |
| 753 | // * |
| 754 | // * 1) will create the corresponding DTD Mof object for EntityDecl, |
| 755 | // NotationDecl |
| 756 | // * and ElementDecl declarations during the 1st pass |
| 757 | // * 2) During the 2nd pass, it will add the contentModel and Attlist to |
| 758 | // all |
| 759 | // * ElementDecl. |
| 760 | // * |
| 761 | // */ |
| 762 | // protected void populateDTDGen(ResourceSet resources, DTD dtd, DTDFile |
| 763 | // dFile) { |
| 764 | // |
| 765 | // DTDModelBuilder modelBuilder = new DTDModelBuilder(resources, this, |
| 766 | // dtd, dFile); |
| 767 | // |
| 768 | // |
| 769 | // modelBuilder.visitDTD(dtd); |
| 770 | // } |
| 771 | // /** |
| 772 | // * @generated |
| 773 | // */ |
| 774 | // protected void emptyErrorMessagesGen() { |
| 775 | // |
| 776 | // errorMsgs.removeAllElements(); |
| 777 | // } |
| 778 | // /** |
| 779 | // * @generated |
| 780 | // */ |
| 781 | // protected void addErrorMessageGen(ErrorMessage error) { |
| 782 | // |
| 783 | // int vectorSize = errorMsgs.size(); |
| 784 | // boolean add = true; |
| 785 | // |
| 786 | // |
| 787 | // if (vectorSize != 0) |
| 788 | // { |
| 789 | // int index = 0; |
| 790 | // |
| 791 | // |
| 792 | // while (add == true && index < vectorSize) |
| 793 | // { |
| 794 | // if (((ErrorMessage) errorMsgs.elementAt(index)).equals(error)) |
| 795 | // { |
| 796 | // add =false; |
| 797 | // } |
| 798 | // else |
| 799 | // { |
| 800 | // index++; |
| 801 | // } |
| 802 | // } |
| 803 | // } |
| 804 | // |
| 805 | // |
| 806 | // if (add) |
| 807 | // { |
| 808 | // errorMsgs.addElement(error); |
| 809 | // } |
| 810 | // } |
| 811 | // /** |
| 812 | // * @generated |
| 813 | // */ |
| 814 | // protected Vector getErrorsGen() { |
| 815 | // |
| 816 | // return errorMsgs; |
| 817 | // } |
| 818 | // /** |
| 819 | // * @generated |
| 820 | // */ |
| 821 | // protected boolean validateDTDGen() { |
| 822 | // |
| 823 | // String tempDTDFile=getPath().toOSString()+"tempValidatingFileName.dtd"; |
| 824 | // try |
| 825 | // { |
| 826 | // saveDTDFile(tempDTDFile); |
| 827 | // |
| 828 | // |
| 829 | // parser = new DTDParser(false); |
| 830 | // if (FileUtility.fileExists(tempDTDFile)) |
| 831 | // { |
| 832 | // parser.parse(tempDTDFile); |
| 833 | // } |
| 834 | // Vector dtdList = parser.getDTDList(); |
| 835 | // if ( dtdList.size() > 0) |
| 836 | // { |
| 837 | // // reset the errors and update what we have in the element pool |
| 838 | // emptyErrorMessages(); |
| 839 | // updateElementHashtable(); |
| 840 | // |
| 841 | // |
| 842 | // // TODO: do we just validate the current one? |
| 843 | // validateWithModel((DTD)dtdList.elementAt(0)); |
| 844 | // } |
| 845 | // } |
| 846 | // catch(IOException ex) |
| 847 | // { |
| 848 | // ex.printStackTrace(System.err); |
| 849 | // FileUtility.delete(tempDTDFile); |
| 850 | // } |
| 851 | // FileUtility.delete(tempDTDFile); |
| 852 | // |
| 853 | // |
| 854 | // return dtdFile.isParseError(); |
| 855 | // } |
| 856 | // /** |
| 857 | // * @generated |
| 858 | // */ |
| 859 | // protected void validateWithModelGen(DTD dtd) { |
| 860 | // |
| 861 | // Enumeration en = dtd.externalElements(); |
| 862 | // while (en.hasMoreElements()) |
| 863 | // { |
| 864 | // Object e = en.nextElement(); |
| 865 | // |
| 866 | // |
| 867 | // if ( e instanceof EntityDecl ) |
| 868 | // { |
| 869 | // EntityDecl entity = (EntityDecl) e; |
| 870 | // ErrorMessage errMsg = entity.getErrorMessage(); |
| 871 | // if ( errMsg!= null) |
| 872 | // { |
| 873 | // addErrorMessage(errMsg); |
| 874 | // // dtdFile.setParseError(true); |
| 875 | // } |
| 876 | // } |
| 877 | // else if ( e instanceof ElementDecl ) |
| 878 | // { |
| 879 | // ElementDecl elem = (ElementDecl) e; |
| 880 | // ErrorMessage errMsg = elem.getErrorMessage(); |
| 881 | // DTDElement dtdelement = (DTDElement) |
| 882 | // getElementPool().get(elem.getNodeName()); |
| 883 | // |
| 884 | // |
| 885 | // if ( errMsg!= null) |
| 886 | // { |
| 887 | // addErrorMessage(errMsg); |
| 888 | // } |
| 889 | // checkForMissingElementReferences(dtdelement); |
| 890 | // } |
| 891 | // else if ( e instanceof NotationDecl ) |
| 892 | // { |
| 893 | // NotationDecl notation = (NotationDecl) e; |
| 894 | // ErrorMessage errMsg = notation.getErrorMessage(); |
| 895 | // if ( errMsg!= null) |
| 896 | // { |
| 897 | // addErrorMessage(errMsg); |
| 898 | // } |
| 899 | // } |
| 900 | // else if ( e instanceof Attlist ) |
| 901 | // { |
| 902 | // Attlist attList = (Attlist) e; |
| 903 | // ErrorMessage errMsg = attList.getErrorMessage(); |
| 904 | // if ( errMsg!= null) |
| 905 | // { |
| 906 | // addErrorMessage(errMsg); |
| 907 | // } |
| 908 | // } |
| 909 | // } |
| 910 | // |
| 911 | // |
| 912 | // checkForDuplicateIDAttribute(); |
| 913 | // } |
| 914 | // /** |
| 915 | // * @generated |
| 916 | // */ |
| 917 | // protected void updateElementHashtableGen() { |
| 918 | // |
| 919 | // elementPool.clear(); |
| 920 | // CreateListItems itemsHelper = new CreateListItems(dtdFile); |
| 921 | // |
| 922 | // |
| 923 | // Vector allElements = itemsHelper.getElements(); |
| 924 | // // go through all the dtdFiles and list the elements |
| 925 | // int numElements = allElements.size(); |
| 926 | // |
| 927 | // |
| 928 | // for (int i = 0; i < numElements; i++) |
| 929 | // { |
| 930 | // DTDElement element = (DTDElement) allElements.elementAt(i); |
| 931 | // elementPool.put(getBaseName(element), element); |
| 932 | // } |
| 933 | // } |
| 934 | // /** |
| 935 | // * @generated |
| 936 | // */ |
| 937 | // protected void updateEntityHashtableGen() { |
| 938 | // |
| 939 | // updateHashTable(pePool, dtdFile.listDTDEntity()); |
| 940 | // } |
| 941 | // /** |
| 942 | // * @generated |
| 943 | // */ |
| 944 | // protected void updateHashTableGen(Hashtable h, Collection dtdObjects) { |
| 945 | // |
| 946 | // h.clear(); |
| 947 | // Iterator i = dtdObjects.iterator(); |
| 948 | // while (i.hasNext()) |
| 949 | // { |
| 950 | // String name = ""; |
| 951 | // DTDObject o = (DTDObject) i.next(); |
| 952 | // name = getBaseName(o); |
| 953 | // h.put(name,o); |
| 954 | // } |
| 955 | // } |
| 956 | // /** |
| 957 | // * @generated |
| 958 | // */ |
| 959 | // protected static String getBaseNameGen(DTDObject obj) { |
| 960 | // |
| 961 | // return getName(obj, null); |
| 962 | // } |
| 963 | // /** |
| 964 | // * @generated |
| 965 | // */ |
| 966 | // protected static String getNameGen(DTDObject obj, DTDFile dtdFile) { |
| 967 | // |
| 968 | // String name = ""; |
| 969 | // if (obj instanceof DTDEntity) |
| 970 | // { |
| 971 | // DTDEntity entity = (DTDEntity) obj; |
| 972 | // if (dtdFile != null && |
| 973 | // !entity.getDTDFile().equals(dtdFile)) |
| 974 | // { |
| 975 | // name = new Path(entity.getDTDFile().getName()).lastSegment() + ": "; |
| 976 | // } |
| 977 | // name += "%" + ((DTDEntity)obj).getName() + ";"; |
| 978 | // } |
| 979 | // else if (obj instanceof DTDElement) |
| 980 | // { |
| 981 | // DTDElement element = (DTDElement) obj; |
| 982 | // if (dtdFile != null && |
| 983 | // !element.getDTDFile().equals(dtdFile)) |
| 984 | // { |
| 985 | // name = new Path(element.getDTDFile().getName()).lastSegment() + ": "; |
| 986 | // } |
| 987 | // name += ((DTDElement)obj).getName(); |
| 988 | // } |
| 989 | // else if (obj instanceof DTDElementContent) |
| 990 | // { |
| 991 | // return ((DTDElementContent) obj).getContentName(); |
| 992 | // } |
| 993 | // return name; |
| 994 | // } |
| 995 | // /** |
| 996 | // * @generated |
| 997 | // */ |
| 998 | // protected void checkForMissingElementReferencesGen(DTDElement element) |
| 999 | // { |
| 1000 | // |
| 1001 | // String dtdString = null; |
| 1002 | // if ( element == null ) |
| 1003 | // return; |
| 1004 | // |
| 1005 | // |
| 1006 | // Vector elementRefs = new Vector(); |
| 1007 | // findElementReferences(element.getContent(),elementRefs); |
| 1008 | // |
| 1009 | // |
| 1010 | // Enumeration en = elementRefs.elements(); |
| 1011 | // while (en.hasMoreElements()) |
| 1012 | // { |
| 1013 | // String elementRefName = ""; |
| 1014 | // DTDObject dtdObject = (DTDObject) en.nextElement(); |
| 1015 | // |
| 1016 | // |
| 1017 | // if ( dtdObject instanceof DTDElement) |
| 1018 | // { |
| 1019 | // elementRefName = ((DTDElement)dtdObject).getName(); |
| 1020 | // if ( getElementPool().get(elementRefName) == null) |
| 1021 | // { |
| 1022 | // if (dtdString == null) |
| 1023 | // { |
| 1024 | // dtdString = getDTDSource(false); |
| 1025 | // } |
| 1026 | // String errorMsg = "Element \"" + element.getName() + "\", refers to |
| 1027 | // undeclared element " |
| 1028 | // + "\"" + elementRefName + "\", in content model.\n"; |
| 1029 | // ErrorMessage dtdError = new ErrorMessage(); |
| 1030 | // dtdError.setErrorMessage(errorMsg); |
| 1031 | // SourceLocationHelper.LineColumn lineColumn = |
| 1032 | // SourceLocationHelper.offsetToLineColumn(dtdString, |
| 1033 | // element.getStartOffset()); |
| 1034 | // dtdError.setErrorLine(lineColumn.getLine()); |
| 1035 | // dtdError.setErrorColumn(lineColumn.getColumn()); |
| 1036 | // addErrorMessage(dtdError); |
| 1037 | // } |
| 1038 | // } |
| 1039 | // } |
| 1040 | // } |
| 1041 | // /** |
| 1042 | // * @generated |
| 1043 | // */ |
| 1044 | // protected void findElementReferencesGen(DTDElementContent content, |
| 1045 | // Vector result) { |
| 1046 | // |
| 1047 | // |
| 1048 | // if (content instanceof DTDElementReferenceContent) |
| 1049 | // { |
| 1050 | // result.addElement(((DTDElementReferenceContent)content).getReferencedElement()); |
| 1051 | // } |
| 1052 | // else if (content instanceof DTDEntityReferenceContent) |
| 1053 | // { |
| 1054 | // result.addElement(((DTDEntityReferenceContent)content).getElementReferencedEntity()); |
| 1055 | // } |
| 1056 | // else if (content instanceof DTDGroupContent) |
| 1057 | // { |
| 1058 | // DTDGroupContent group = (DTDGroupContent)content; |
| 1059 | // EList contents = group.getContent(); |
| 1060 | // Iterator i = contents.iterator(); |
| 1061 | // while (i.hasNext()) |
| 1062 | // { |
| 1063 | // findElementReferences((DTDElementContent) i.next(), result); |
| 1064 | // } |
| 1065 | // } |
| 1066 | // } |
| 1067 | // /** |
| 1068 | // * @generated |
| 1069 | // */ |
| 1070 | // protected void checkForDuplicateIDAttributeGen() { |
| 1071 | // |
| 1072 | // String dtdString = null; |
| 1073 | // Collection elements = dtdFile.listDTDElement(); |
| 1074 | // Iterator i = elements.iterator(); |
| 1075 | // while (i.hasNext()) |
| 1076 | // { |
| 1077 | // DTDElement element = (DTDElement) i.next(); |
| 1078 | // Iterator k = element.getDTDAttribute().iterator(); |
| 1079 | // boolean saw1stID = false; |
| 1080 | // while (k.hasNext()) |
| 1081 | // { |
| 1082 | // DTDAttribute attr = (DTDAttribute) k.next(); |
| 1083 | // DTDType dType = attr.getDTDType(); |
| 1084 | // if (dType instanceof DTDBasicType) |
| 1085 | // { |
| 1086 | // if ( ((DTDBasicType)dType).getKind().intValue() == DTDBasicTypeKind.ID) |
| 1087 | // { |
| 1088 | // if (saw1stID) |
| 1089 | // { |
| 1090 | // if (dtdString == null) |
| 1091 | // { |
| 1092 | // dtdString = getDTDSource(false); |
| 1093 | // } |
| 1094 | // String errMsg = DTDPlugin.getDTDString("_ERROR_DUP_ID_ATTRIBUTE_1"); |
| 1095 | // errMsg += attr.getName() + |
| 1096 | // DTDPlugin.getDTDString("_UI_ERRORPART_DUP_ID_ATTRIBUTE_2"); |
| 1097 | // |
| 1098 | // ErrorMessage dtdError = new ErrorMessage(); |
| 1099 | // dtdError.setErrorMessage(errMsg); |
| 1100 | // SourceLocationHelper.LineColumn lineColumn = |
| 1101 | // SourceLocationHelper.offsetToLineColumn(dtdString, |
| 1102 | // attr.getStartOffset()); |
| 1103 | // dtdError.setErrorLine(lineColumn.getLine()); |
| 1104 | // dtdError.setErrorColumn(lineColumn.getColumn()); |
| 1105 | // dtdError.setObject(attr); |
| 1106 | // addErrorMessage(dtdError); |
| 1107 | // // dtdFile.setParseError(true); |
| 1108 | // break; |
| 1109 | // } |
| 1110 | // else |
| 1111 | // { |
| 1112 | // saw1stID = true; |
| 1113 | // } |
| 1114 | // } |
| 1115 | // } |
| 1116 | // } |
| 1117 | // } |
| 1118 | // } |
| 1119 | // /** |
| 1120 | // * @generated |
| 1121 | // */ |
| 1122 | // protected static String getGroupTypeGen(int groupKind, int occurrence) |
| 1123 | // { |
| 1124 | // |
| 1125 | // String type = null; |
| 1126 | // |
| 1127 | // |
| 1128 | // switch (groupKind) |
| 1129 | // { |
| 1130 | // case DTDGroupKind.SEQUENCE: |
| 1131 | // type = "DTDSequence"; |
| 1132 | // break; |
| 1133 | // case DTDGroupKind.CHOICE: |
| 1134 | // type = "DTDChoice"; |
| 1135 | // break; |
| 1136 | // } |
| 1137 | // |
| 1138 | // |
| 1139 | // type += getRepeatableTypeSuffix(occurrence); |
| 1140 | // return type; |
| 1141 | // } |
| 1142 | // /** |
| 1143 | // * @generated |
| 1144 | // */ |
| 1145 | // protected static String getReferenceTypeGen(int occurrence) { |
| 1146 | // |
| 1147 | // String type = "DTDReference"; |
| 1148 | // type += getRepeatableTypeSuffix(occurrence); |
| 1149 | // return type; |
| 1150 | // } |
| 1151 | // /** |
| 1152 | // * @generated |
| 1153 | // */ |
| 1154 | // protected static String getRepeatableTypeSuffixGen(int occurrence) { |
| 1155 | // |
| 1156 | // return "(" + (char)occurrence + ")"; |
| 1157 | // } |
| 1158 | // /** |
| 1159 | // * @generated |
| 1160 | // */ |
| 1161 | // protected static void mainGen(String[] args) { |
| 1162 | // |
| 1163 | // System.out.println("\nStarting ..."); |
| 1164 | // |
| 1165 | // |
| 1166 | // if (args.length != 1) |
| 1167 | // System.out.println("usage: DtdUtil inputfile.dtd"); |
| 1168 | // |
| 1169 | // |
| 1170 | // java.io.File inputFile = new File(args[0]); |
| 1171 | // |
| 1172 | // |
| 1173 | // String dtdFileName = ""; |
| 1174 | // try |
| 1175 | // { |
| 1176 | // dtdFileName = inputFile.getCanonicalPath(); |
| 1177 | // } |
| 1178 | // catch(IOException ex) |
| 1179 | // {} |
| 1180 | // |
| 1181 | // |
| 1182 | // String dtdModelName = dtdFileName; |
| 1183 | // |
| 1184 | // |
| 1185 | // if (DTDConstants.DTD_EXTENSION.equals(new |
| 1186 | // Path(dtdFileName).getFileExtension())) |
| 1187 | // { |
| 1188 | // dtdModelName= new |
| 1189 | // Path(dtdFileName).removeFileExtension().lastSegment(); |
| 1190 | // } |
| 1191 | // DTDUtil d2m = new DTDUtil(); |
| 1192 | // // TODO: fix port |
| 1193 | // // d2m.parse(dtdFileName); |
| 1194 | // try |
| 1195 | // { |
| 1196 | // d2m.saveAs(dtdModelName + "." + DTDConstants.DTD_XMI_EXTENSION); |
| 1197 | // } |
| 1198 | // catch (Exception e) |
| 1199 | // { |
| 1200 | // System.out.println("Exception thrown during model save: " + e); |
| 1201 | // } |
| 1202 | // System.out.println("Done."); |
| 1203 | // } |
| 1204 | // /** |
| 1205 | // * @generated |
| 1206 | // */ |
| 1207 | // protected org.eclipse.core.runtime.IPath getPathGen() { |
| 1208 | // |
| 1209 | // Path currentDTDPath = new Path(dtdModelFile); |
| 1210 | // if (currentDTDPath.segmentCount() > 1) |
| 1211 | // { |
| 1212 | // return currentDTDPath.removeLastSegments(1).addTrailingSeparator(); |
| 1213 | // } |
| 1214 | // |
| 1215 | // return new Path(""); |
| 1216 | // } |
| 1217 | } |