This commit is contained in:
Hannes Janetzek 2013-02-23 02:01:35 +01:00
parent f658b6fbcf
commit 87ea877705

View File

@ -1,5 +1,6 @@
/* /*
* Copyright 2010, 2011, 2012 mapsforge.org * Copyright 2010, 2011, 2012 mapsforge.org
* Copyright 2013 Hannes Janetzek
* *
* This program is free software: you can redistribute it and/or modify it under the * This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software * terms of the GNU Lesser General Public License as published by the Free Software
@ -18,8 +19,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Stack; import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
@ -45,8 +44,7 @@ import android.util.Log;
* SAX2 handler to parse XML render theme files. * SAX2 handler to parse XML render theme files.
*/ */
public class RenderThemeHandler extends DefaultHandler { public class RenderThemeHandler extends DefaultHandler {
private static final Logger LOG = Logger private final static String TAG = RenderThemeHandler.class.getName();
.getLogger(RenderThemeHandler.class.getName());
private static enum Element { private static enum Element {
RENDER_THEME, RENDERING_INSTRUCTION, RULE, STYLE; RENDER_THEME, RENDERING_INSTRUCTION, RULE, STYLE;
@ -99,8 +97,8 @@ public class RenderThemeHandler extends DefaultHandler {
* @param attributeIndex * @param attributeIndex
* the XML attribute index position. * the XML attribute index position.
*/ */
public static void logUnknownAttribute(String element, String name, String value, public static void logUnknownAttribute(String element, String name,
int attributeIndex) { String value, int attributeIndex) {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("unknown attribute in element "); stringBuilder.append("unknown attribute in element ");
stringBuilder.append(element); stringBuilder.append(element);
@ -110,7 +108,7 @@ public class RenderThemeHandler extends DefaultHandler {
stringBuilder.append(name); stringBuilder.append(name);
stringBuilder.append('='); stringBuilder.append('=');
stringBuilder.append(value); stringBuilder.append(value);
LOG.info(stringBuilder.toString()); Log.d(TAG, stringBuilder.toString());
} }
private Rule mCurrentRule; private Rule mCurrentRule;
@ -146,11 +144,11 @@ public class RenderThemeHandler extends DefaultHandler {
@Override @Override
public void error(SAXParseException exception) { public void error(SAXParseException exception) {
LOG.log(Level.SEVERE, null, exception); Log.d(TAG, exception.getMessage());
} }
private static HashMap<String, RenderInstruction> tmpStyleHash = new HashMap<String, RenderInstruction>( private static HashMap<String, RenderInstruction> tmpStyleHash =
10); new HashMap<String, RenderInstruction>(10);
@Override @Override
public void startElement(String uri, String localName, String qName, public void startElement(String uri, String localName, String qName,
@ -175,14 +173,12 @@ public class RenderThemeHandler extends DefaultHandler {
checkState(localName, Element.STYLE); checkState(localName, Element.STYLE);
Text text = Text.create(localName, attributes, false); Text text = Text.create(localName, attributes, false);
tmpStyleHash.put("t" + text.style, text); tmpStyleHash.put("t" + text.style, text);
// System.out.println("add style: " + text.style);
} }
else if (ELEMENT_NAME_STYLE_AREA.equals(localName)) { else if (ELEMENT_NAME_STYLE_AREA.equals(localName)) {
checkState(localName, Element.STYLE); checkState(localName, Element.STYLE);
Area area = Area.create(localName, attributes, 0); Area area = Area.create(localName, attributes, 0);
tmpStyleHash.put("a" + area.style, area); tmpStyleHash.put("a" + area.style, area);
// System.out.println("add style: " + area.style);
} }
else if (ELEMENT_NAME_STYLE_LINE.equals(localName)) { else if (ELEMENT_NAME_STYLE_LINE.equals(localName)) {
@ -194,16 +190,13 @@ public class RenderThemeHandler extends DefaultHandler {
Line line = Line.create((Line) ri, localName, attributes, 0, Line line = Line.create((Line) ri, localName, attributes, 0,
false); false);
tmpStyleHash.put("l" + line.style, line); tmpStyleHash.put("l" + line.style, line);
// System.out.println("add style: " + line.style +
// " from " + style);
} }
else { else {
Log.d("...", "this aint no style! " + style); Log.d(TAG, "not a style: " + style);
} }
} else { } else {
Line line = Line.create(null, localName, attributes, 0, false); Line line = Line.create(null, localName, attributes, 0, false);
tmpStyleHash.put("l" + line.style, line); tmpStyleHash.put("l" + line.style, line);
// System.out.println("add style: " + line.style);
} }
} }
@ -266,15 +259,13 @@ public class RenderThemeHandler extends DefaultHandler {
if (style != null) { if (style != null) {
Line line = (Line) tmpStyleHash.get("l" + style); Line line = (Line) tmpStyleHash.get("l" + style);
if (line != null) { if (line != null) {
// System.out.println("found style line : " +
// line.style);
Line newLine = Line.create(line, localName, attributes, Line newLine = Line.create(line, localName, attributes,
mLevel++, false); mLevel++, false);
mCurrentRule.addRenderingInstruction(newLine); mCurrentRule.addRenderingInstruction(newLine);
} }
else else
Log.d("...", "styles not a line! " + style); Log.d(TAG, "BUG: not a line style: " + style);
} }
} else if (ELEMENT_NAME_USE_STYLE_OUTLINE.equals(localName)) { } else if (ELEMENT_NAME_USE_STYLE_OUTLINE.equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION); checkState(localName, Element.RENDERING_INSTRUCTION);
@ -284,7 +275,7 @@ public class RenderThemeHandler extends DefaultHandler {
if (line != null && line.outline) if (line != null && line.outline)
mCurrentRule.addRenderingInstruction(line); mCurrentRule.addRenderingInstruction(line);
else else
Log.d("...", "styles not bad, but this aint no outline! " + style); Log.d(TAG, "BUG not an outline style: " + style);
} }
} else if (ELEMENT_NAME_USE_STYLE_AREA.equals(localName)) { } else if (ELEMENT_NAME_USE_STYLE_AREA.equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION); checkState(localName, Element.RENDERING_INSTRUCTION);
@ -295,7 +286,7 @@ public class RenderThemeHandler extends DefaultHandler {
mCurrentRule.addRenderingInstruction(new AreaLevel(area, mCurrentRule.addRenderingInstruction(new AreaLevel(area,
mLevel++)); mLevel++));
else else
Log.d("...", "this aint no style inna d'area! " + style); Log.d(TAG, "BUG not an area style: " + style);
} }
} else if (ELEMENT_NAME_USE_STYLE_PATH_TEXT.equals(localName)) { } else if (ELEMENT_NAME_USE_STYLE_PATH_TEXT.equals(localName)) {
checkState(localName, Element.RENDERING_INSTRUCTION); checkState(localName, Element.RENDERING_INSTRUCTION);
@ -305,7 +296,7 @@ public class RenderThemeHandler extends DefaultHandler {
if (pt != null) if (pt != null)
mCurrentRule.addRenderingInstruction(pt); mCurrentRule.addRenderingInstruction(pt);
else else
Log.d("...", "this aint no path text style! " + style); Log.d(TAG, "BUG not a path text style: " + style);
} }
} else { } else {
throw new SAXException("unknown element: " + localName); throw new SAXException("unknown element: " + localName);
@ -319,7 +310,7 @@ public class RenderThemeHandler extends DefaultHandler {
@Override @Override
public void warning(SAXParseException exception) { public void warning(SAXParseException exception) {
LOG.log(Level.SEVERE, null, exception); Log.d(TAG, exception.getMessage());
} }
private void checkElement(String elementName, Element element) throws SAXException { private void checkElement(String elementName, Element element) throws SAXException {