| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package net.sf.antcontrib.antclipse; |
| 17 |
import java.io.File; |
| 18 |
import java.io.FileInputStream; |
| 19 |
import java.io.FileNotFoundException; |
| 20 |
import java.io.IOException; |
| 21 |
import javax.xml.parsers.ParserConfigurationException; |
| 22 |
import javax.xml.parsers.SAXParser; |
| 23 |
import javax.xml.parsers.SAXParserFactory; |
| 24 |
|
| 25 |
import org.apache.tools.ant.BuildException; |
| 26 |
import org.apache.tools.ant.Location; |
| 27 |
import org.xml.sax.HandlerBase; |
| 28 |
import org.xml.sax.InputSource; |
| 29 |
import org.xml.sax.SAXException; |
| 30 |
import org.xml.sax.SAXParseException; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class ClassPathParser |
| 42 |
{ |
| 43 |
void parse(File file, HandlerBase handler) throws BuildException |
| 44 |
{ |
| 45 |
String fName = file.getName(); |
| 46 |
FileInputStream fileInputStream = null; |
| 47 |
InputSource inputSource = null; |
| 48 |
try |
| 49 |
{ |
| 50 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
| 51 |
|
| 52 |
String uri = "file:" + fName.replace('\\', '/'); |
| 53 |
fileInputStream = new FileInputStream(file); |
| 54 |
inputSource = new InputSource(fileInputStream); |
| 55 |
inputSource.setSystemId(uri); |
| 56 |
saxParser.parse(inputSource, handler); |
| 57 |
} |
| 58 |
catch (ParserConfigurationException pceException) |
| 59 |
{ |
| 60 |
throw new BuildException("Parser configuration failed", pceException); |
| 61 |
} |
| 62 |
catch (SAXParseException exc) |
| 63 |
{ |
| 64 |
Location location = new Location(fName.toString(), exc.getLineNumber(), exc.getColumnNumber()); |
| 65 |
Throwable throwable = exc.getException(); |
| 66 |
if ((Object) throwable instanceof BuildException) |
| 67 |
{ |
| 68 |
BuildException be = (BuildException) (Object) throwable; |
| 69 |
if (be.getLocation() == Location.UNKNOWN_LOCATION) |
| 70 |
be.setLocation(location); |
| 71 |
throw be; |
| 72 |
} |
| 73 |
throw new BuildException(exc.getMessage(), throwable, location); |
| 74 |
} |
| 75 |
catch (SAXException exc) |
| 76 |
{ |
| 77 |
Throwable throwable = exc.getException(); |
| 78 |
if ((Object) throwable instanceof BuildException) |
| 79 |
throw (BuildException) (Object) throwable; |
| 80 |
throw new BuildException(exc.getMessage(), throwable); |
| 81 |
} |
| 82 |
catch (FileNotFoundException exc) |
| 83 |
{ |
| 84 |
throw new BuildException(exc); |
| 85 |
} |
| 86 |
catch (IOException exc) |
| 87 |
{ |
| 88 |
throw new BuildException("Error reading file", exc); |
| 89 |
} |
| 90 |
finally |
| 91 |
{ |
| 92 |
if (fileInputStream != null) |
| 93 |
{ |
| 94 |
try |
| 95 |
{ |
| 96 |
fileInputStream.close(); |
| 97 |
} |
| 98 |
catch (IOException ioexception) |
| 99 |
{ |
| 100 |
|
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
} |