Changeset 11525 in josm for trunk/src/com/kitfox/svg/SVGLoader.java
- Timestamp:
- 2017-02-02T00:08:08+01:00 (9 years ago)
- File:
-
- 1 edited
-
trunk/src/com/kitfox/svg/SVGLoader.java (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/SVGLoader.java
r8084 r11525 4 4 * All rights reserved. 5 5 * 6 * Redistribution and use in source and binary forms, with or 6 * Redistribution and use in source and binary forms, with or 7 7 * without modification, are permitted provided that the following 8 8 * conditions are met: 9 9 * 10 * - Redistributions of source code must retain the above 10 * - Redistributions of source code must retain the above 11 11 * copyright notice, this list of conditions and the following 12 12 * disclaimer. 13 13 * - Redistributions in binary form must reproduce the above 14 14 * copyright notice, this list of conditions and the following 15 * disclaimer in the documentation and/or other materials 15 * disclaimer in the documentation and/or other materials 16 16 * provided with the distribution. 17 17 * … … 27 27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 29 * OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 31 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other 32 32 * projects can be found at http://www.kitfox.com … … 38 38 39 39 40 import java.util.*; 41 import java.net.*; 42 import org.xml.sax.*; 43 import org.xml.sax.helpers.DefaultHandler; 44 40 import java.net.URI; 41 import java.util.HashMap; 42 import java.util.HashSet; 43 import java.util.LinkedList; 45 44 import java.util.logging.Level; 46 45 import java.util.logging.Logger; 46 47 import org.xml.sax.Attributes; 48 import org.xml.sax.SAXException; 49 import org.xml.sax.helpers.DefaultHandler; 47 50 48 51 /** … … 52 55 public class SVGLoader extends DefaultHandler 53 56 { 54 final HashMap nodeClasses = new HashMap(); 57 final HashMap<String, Class<?>> nodeClasses = new HashMap<>(); 55 58 //final HashMap attribClasses = new HashMap(); 56 final LinkedList buildStack = new LinkedList(); 57 58 final HashSet ignoreClasses = new HashSet(); 59 final LinkedList<SVGElement> buildStack = new LinkedList<>(); 60 61 final HashSet<String> ignoreClasses = new HashSet<>(); 59 62 60 63 final SVGLoaderHelper helper; … … 73 76 74 77 final boolean verbose; 75 78 76 79 /** Creates a new instance of SVGLoader */ 77 80 public SVGLoader(URI xmlBase, SVGUniverse universe) … … 79 82 this(xmlBase, universe, false); 80 83 } 81 84 82 85 public SVGLoader(URI xmlBase, SVGUniverse universe, boolean verbose) 83 86 { 84 87 this.verbose = verbose; 85 88 86 89 diagram = new SVGDiagram(xmlBase, universe); 87 90 … … 138 141 return sb.toString(); 139 142 } 140 143 144 @Override 141 145 public void startDocument() throws SAXException 142 146 { … … 146 150 } 147 151 152 @Override 148 153 public void endDocument() throws SAXException 149 154 { … … 151 156 } 152 157 158 @Override 153 159 public void startElement(String namespaceURI, String sName, String qName, Attributes attrs) throws SAXException 154 160 { … … 158 164 } 159 165 indent++; 160 166 161 167 if (skipNonSVGTagDepth != 0 || (!namespaceURI.equals("") && !namespaceURI.equals(SVGElement.SVG_NS))) 162 168 { … … 164 170 return; 165 171 } 166 172 167 173 sName = sName.toLowerCase(); 168 174 … … 187 193 188 194 try { 189 Class cls = (Class)obj; 195 Class<?> cls = (Class<?>)obj; 190 196 SVGElement svgEle = (SVGElement)cls.newInstance(); 191 197 192 198 SVGElement parent = null; 193 if (buildStack.size() != 0) parent = (SVGElement)buildStack.getLast();199 if (buildStack.size() != 0) parent = buildStack.getLast(); 194 200 svgEle.loaderStartElement(helper, attrs, parent); 195 201 … … 198 204 catch (Exception e) 199 205 { 200 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 206 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 201 207 "Could not load", e); 202 208 throw new SAXException(e); … … 205 211 } 206 212 213 @Override 207 214 public void endElement(String namespaceURI, String sName, String qName) 208 215 throws SAXException … … 213 220 System.err.println(printIndent(indent, " ") + "Ending parse of tag " + sName+ ": " + namespaceURI); 214 221 } 215 222 216 223 if (skipNonSVGTagDepth != 0) 217 224 { … … 219 226 return; 220 227 } 221 228 222 229 sName = sName.toLowerCase(); 223 230 … … 230 237 231 238 try { 232 SVGElement svgEle = (SVGElement)buildStack.removeLast();239 SVGElement svgEle = buildStack.removeLast(); 233 240 234 241 svgEle.loaderEndElement(helper); … … 237 244 if (buildStack.size() != 0) 238 245 { 239 parent = (SVGElement)buildStack.getLast();246 parent = buildStack.getLast(); 240 247 } 241 248 //else loadRoot = (SVGElement)svgEle; … … 253 260 catch (Exception e) 254 261 { 255 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 262 Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 256 263 "Could not parse", e); 257 264 throw new SAXException(e); … … 259 266 } 260 267 268 @Override 261 269 public void characters(char buf[], int offset, int len) 262 270 throws SAXException … … 269 277 if (buildStack.size() != 0) 270 278 { 271 SVGElement parent = (SVGElement)buildStack.getLast();279 SVGElement parent = buildStack.getLast(); 272 280 String s = new String(buf, offset, len); 273 281 parent.loaderAddText(helper, s); … … 275 283 } 276 284 285 @Override 277 286 public void processingInstruction(String target, String data) 278 287 throws SAXException … … 280 289 //Check for external style sheet 281 290 } 282 291 283 292 // public SVGElement getLoadRoot() { return loadRoot; } 284 293 public SVGDiagram getLoadedDiagram() { return diagram; }
Note:
See TracChangeset
for help on using the changeset viewer.
