1 package com.icl.saxon; 2 3 import java.io.*; 4 import java.net.URL ; 5 import java.net.MalformedURLException ; 6 import org.xml.sax.*; 7 11 24 25 public class ExtendedInputSource extends org.xml.sax.InputSource { 26 27 private int estimatedLength = -1; 28 29 32 33 public ExtendedInputSource() { 34 super(); 35 } 36 37 40 41 public ExtendedInputSource(String systemId) { 42 super(systemId); 43 } 44 45 48 49 public ExtendedInputSource(Reader reader) { 50 super(reader); 51 } 52 53 56 57 public ExtendedInputSource(InputStream stream) { 58 super(stream); 59 } 60 61 71 72 public ExtendedInputSource (File file) { 73 setFile(file); 74 } 75 76 79 80 public ExtendedInputSource (InputSource in) { 81 setSystemId(in.getSystemId()); 82 setPublicId(in.getPublicId()); 83 setByteStream(in.getByteStream()); 84 setEncoding(in.getEncoding()); 85 setCharacterStream(in.getCharacterStream()); 86 } 87 88 91 92 public void setFile(File file) { 93 super.setSystemId(createURL(file)); 94 } 95 96 99 100 public void setEstimatedLength(int length) { 101 estimatedLength = length; 102 } 103 104 107 108 public int getEstimatedLength() { 109 return estimatedLength; 110 } 111 112 115 116 public static String createURL(File file) 117 { 118 String path = file.getAbsolutePath(); 119 while (true) { 120 int special = path.indexOf('#'); 121 if (special >= 0) { 122 path = path.substring(0, special) + "%23" + path.substring(special+1); 123 } else { 124 break; 125 } 126 } 127 128 129 URL url = null; 131 try 132 { 133 url = new URL (path); 134 } 135 catch (MalformedURLException ex) 136 { 137 try 138 { 139 String fs = System.getProperty("file.separator"); 143 if (fs.length() == 1) 144 { 145 char sep = fs.charAt(0); 146 if (sep != '/') 147 path = path.replace(sep, '/'); 148 if (path.charAt(0) != '/') 149 path = '/' + path; 150 } 151 path = "file://" + path; 152 url = new URL (path); 153 } 154 catch (MalformedURLException e) 155 { 156 return null; 157 } 158 } 159 return( url.toString() ); 160 } 161 162 163 } 164 165 | Popular Tags |