| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package net.sf.antcontrib.walls; |
| 17 |
|
| 18 |
import java.io.File; |
| 19 |
|
| 20 |
import org.apache.tools.ant.Project; |
| 21 |
import org.xml.sax.*; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
class WallsFileHandler extends HandlerBase { |
| 28 |
|
| 29 |
private final CompileWithWalls compilewithwalls; |
| 30 |
private File file = null; |
| 31 |
private Walls walls = null; |
| 32 |
private Locator locator = null; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
WallsFileHandler(CompileWithWalls walls, File file) { |
| 38 |
this.compilewithwalls = walls; |
| 39 |
this.file = file; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public InputSource resolveEntity(String publicId, |
| 52 |
String systemId) { |
| 53 |
compilewithwalls.log("publicId="+publicId+" systemId="+systemId, |
| 54 |
Project.MSG_VERBOSE); |
| 55 |
return null; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
public void startElement(String name, AttributeList attrs) throws SAXParseException { |
| 71 |
if (name.equals("walls")) { |
| 72 |
if(attrs.getLength() > 0) |
| 73 |
throw new SAXParseException("Error in file="+file.getAbsolutePath() |
| 74 |
+", no attributes allowed for walls element", locator); |
| 75 |
walls = this.compilewithwalls.createWalls(); |
| 76 |
} else if (name.equals("package")) { |
| 77 |
handlePackage(attrs); |
| 78 |
} else { |
| 79 |
throw new SAXParseException("Error in file="+file.getAbsolutePath() |
| 80 |
+", Unexpected element \"" + name + "\"", locator); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
private void handlePackage(AttributeList attrs) throws SAXParseException { |
| 85 |
if(walls == null) |
| 86 |
throw new SAXParseException("Error in file="+file.getAbsolutePath() |
| 87 |
+", package element must be nested in a walls element", locator); |
| 88 |
|
| 89 |
String name = attrs.getValue("name"); |
| 90 |
String thePackage = attrs.getValue("package"); |
| 91 |
String depends = attrs.getValue("depends"); |
| 92 |
if(name == null) |
| 93 |
throw new SAXParseException("Error in file="+file.getAbsolutePath() |
| 94 |
+", package element must contain the 'name' attribute", locator); |
| 95 |
else if(thePackage == null) |
| 96 |
throw new SAXParseException("Error in file="+file.getAbsolutePath() |
| 97 |
+", package element must contain the 'package' attribute", locator); |
| 98 |
|
| 99 |
Package p = new Package(); |
| 100 |
p.setName(name); |
| 101 |
p.setPackage(thePackage); |
| 102 |
if(depends != null) |
| 103 |
p.setDepends(depends); |
| 104 |
|
| 105 |
walls.addConfiguredPackage(p); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public void setDocumentLocator(Locator locator) { |
| 114 |
this.locator = locator; |
| 115 |
} |
| 116 |
} |