@Override public RenderTheme call() { if (xmlRenderTheme == null || this.displayModel == null) { return null; } try { return RenderThemeHandler.getRenderTheme(this.graphicFactory, displayModel, this.xmlRenderTheme); } catch (XmlPullParserException e) { throw new IllegalArgumentException("Parse error for XML rendertheme", e); } catch (IOException e) { throw new IllegalArgumentException("File error for XML rendertheme", e); } } }
public static RenderTheme getRenderTheme(GraphicFactory graphicFactory, DisplayModel displayModel, XmlRenderTheme xmlRenderTheme) throws IOException, XmlPullParserException { XmlPullParser pullParser = getXmlPullParserFactory().newPullParser(); RenderThemeHandler renderThemeHandler = new RenderThemeHandler(graphicFactory, displayModel, xmlRenderTheme.getRelativePathPrefix(), xmlRenderTheme, pullParser); InputStream inputStream = null; try { inputStream = xmlRenderTheme.getRenderThemeAsStream(); pullParser.setInput(inputStream, null); renderThemeHandler.processRenderTheme(); return renderThemeHandler.renderTheme; } finally { IOUtils.closeQuietly(inputStream); } }
private void checkState(String elementName, Element element) throws XmlPullParserException { checkElement(elementName, element); this.elementStack.push(element); }
public void processRenderTheme() throws XmlPullParserException, IOException { int eventType = pullParser.getEventType(); do { if (eventType == XmlPullParser.START_DOCUMENT) { // no-op } else if (eventType == XmlPullParser.START_TAG) { startElement(); } else if (eventType == XmlPullParser.END_TAG) { endElement(); } else if (eventType == XmlPullParser.TEXT) { // not implemented } eventType = pullParser.next(); } while (eventType != XmlPullParser.END_DOCUMENT); endDocument(); }
checkState(qName, Element.RENDER_THEME); this.renderTheme = new RenderThemeBuilder(this.graphicFactory, this.displayModel, qName, pullParser).build(); } else if (ELEMENT_NAME_RULE.equals(qName)) { checkState(qName, Element.RULE); Rule rule = new RuleBuilder(qName, pullParser, this.ruleStack).build(); if (!this.ruleStack.empty() && isVisible(rule)) { this.currentRule.addSubRule(rule); this.ruleStack.push(this.currentRule); } else if ("area".equals(qName)) { checkState(qName, Element.RENDERING_INSTRUCTION); Area area = new Area(this.graphicFactory, this.displayModel, qName, pullParser, this.level++, this.relativePathPrefix); if (isVisible(area)) { this.currentRule.addRenderingInstruction(area); checkState(qName, Element.RENDERING_INSTRUCTION); Caption caption = new Caption(this.graphicFactory, this.displayModel, qName, pullParser, symbols); if (isVisible(caption)) { this.currentRule.addRenderingInstruction(caption); checkState(qName, Element.RENDERING_STYLE); this.currentLayer.addCategory(getStringAttribute("id")); } else if ("circle".equals(qName)) { checkState(qName, Element.RENDERING_INSTRUCTION); Circle circle = new Circle(this.graphicFactory, this.displayModel, qName, pullParser, this.level++); if (isVisible(circle)) { this.currentRule.addRenderingInstruction(circle);
private void endElement() { qName = pullParser.getName(); this.elementStack.pop(); if (ELEMENT_NAME_RULE.equals(qName)) { this.ruleStack.pop(); if (this.ruleStack.empty()) { if (isVisible(this.currentRule)) { this.renderTheme.addRule(this.currentRule); } } else { this.currentRule = this.ruleStack.peek(); } } else if ("stylemenu".equals(qName)) { // when we are finished parsing the menu part of the file, we can get the // categories to render from the initiator. This allows the creating action // to select which of the menu options to choose if (null != this.xmlRenderTheme.getMenuCallback()) { // if there is no callback, there is no menu, so the categories will be null this.categories = this.xmlRenderTheme.getMenuCallback().getCategories(this.renderThemeStyleMenu); } return; } }
public void processRenderTheme() throws XmlPullParserException, IOException { int eventType = pullParser.getEventType(); do { if (eventType == XmlPullParser.START_DOCUMENT) { // no-op } else if (eventType == XmlPullParser.START_TAG) { startElement(); } else if (eventType == XmlPullParser.END_TAG) { endElement(); } else if (eventType == XmlPullParser.TEXT) { // not implemented } eventType = pullParser.next(); } while (eventType != XmlPullParser.END_DOCUMENT); endDocument(); }
checkState(qName, Element.RENDER_THEME); this.renderTheme = new RenderThemeBuilder(this.graphicFactory, this.displayModel, qName, pullParser).build(); } else if (ELEMENT_NAME_RULE.equals(qName)) { checkState(qName, Element.RULE); Rule rule = new RuleBuilder(qName, pullParser, this.ruleStack).build(); if (!this.ruleStack.empty() && isVisible(rule)) { this.currentRule.addSubRule(rule); this.ruleStack.push(this.currentRule); } else if ("area".equals(qName)) { checkState(qName, Element.RENDERING_INSTRUCTION); Area area = new Area(this.graphicFactory, this.displayModel, qName, pullParser, this.level++, this.relativePathPrefix); if (isVisible(area)) { this.currentRule.addRenderingInstruction(area); checkState(qName, Element.RENDERING_INSTRUCTION); Caption caption = new Caption(this.graphicFactory, this.displayModel, qName, pullParser, symbols); if (isVisible(caption)) { this.currentRule.addRenderingInstruction(caption); checkState(qName, Element.RENDERING_STYLE); this.currentLayer.addCategory(getStringAttribute("id")); } else if ("circle".equals(qName)) { checkState(qName, Element.RENDERING_INSTRUCTION); Circle circle = new Circle(this.graphicFactory, this.displayModel, qName, pullParser, this.level++); if (isVisible(circle)) { this.currentRule.addRenderingInstruction(circle);
private void endElement() { qName = pullParser.getName(); this.elementStack.pop(); if (ELEMENT_NAME_RULE.equals(qName)) { this.ruleStack.pop(); if (this.ruleStack.empty()) { if (isVisible(this.currentRule)) { this.renderTheme.addRule(this.currentRule); } } else { this.currentRule = this.ruleStack.peek(); } } else if ("stylemenu".equals(qName)) { // when we are finished parsing the menu part of the file, we can get the // categories to render from the initiator. This allows the creating action // to select which of the menu options to choose if (null != this.xmlRenderTheme.getMenuCallback()) { // if there is no callback, there is no menu, so the categories will be null this.categories = this.xmlRenderTheme.getMenuCallback().getCategories(this.renderThemeStyleMenu); } return; } }
public static RenderTheme getRenderTheme(GraphicFactory graphicFactory, DisplayModel displayModel, XmlRenderTheme xmlRenderTheme) throws IOException, XmlPullParserException { XmlPullParser pullParser = getXmlPullParserFactory().newPullParser(); RenderThemeHandler renderThemeHandler = new RenderThemeHandler(graphicFactory, displayModel, xmlRenderTheme.getRelativePathPrefix(), xmlRenderTheme, pullParser); InputStream inputStream = null; try { inputStream = xmlRenderTheme.getRenderThemeAsStream(); pullParser.setInput(inputStream, null); renderThemeHandler.processRenderTheme(); return renderThemeHandler.renderTheme; } finally { IOUtils.closeQuietly(inputStream); } }
private static void verifyInvalid(String pathname) throws XmlPullParserException, IOException { XmlRenderTheme xmlRenderTheme = new ExternalRenderTheme(new File(pathname)); try { RenderThemeHandler.getRenderTheme(GRAPHIC_FACTORY, new DisplayModel(), xmlRenderTheme); Assert.fail(); } catch (XmlPullParserException e) { Assert.assertTrue(true); } }
private void checkState(String elementName, Element element) throws XmlPullParserException { checkElement(elementName, element); this.elementStack.push(element); }
@Test public void validRenderThemeFileTest() throws XmlPullParserException, IOException { File renderThemeFile = new File(RESOURCE_FOLDER, "empty-render-theme.xml"); XmlRenderTheme xmlRenderTheme = new ExternalRenderTheme(renderThemeFile); Assert.assertNotNull(RenderThemeHandler.getRenderTheme(GRAPHIC_FACTORY, new DisplayModel(), xmlRenderTheme)); } }
@Test public void defaultTest() throws XmlPullParserException, IOException { XmlRenderTheme xmlRenderTheme = InternalRenderTheme.DEFAULT; Assert.assertNotNull(RenderThemeHandler.getRenderTheme(GRAPHIC_FACTORY, new DisplayModel(), xmlRenderTheme)); }
@Test public void osmarenderTest() throws XmlPullParserException, IOException { XmlRenderTheme xmlRenderTheme = InternalRenderTheme.OSMARENDER; Assert.assertNotNull(RenderThemeHandler.getRenderTheme(GRAPHIC_FACTORY, new DisplayModel(), xmlRenderTheme)); } }
@Test public void validRenderThemeTest() throws XmlPullParserException, IOException { XmlRenderTheme xmlRenderTheme = new ExternalRenderTheme(new File(RESOURCE_FOLDER, "test-render-theme.xml")); RenderTheme renderTheme = RenderThemeHandler .getRenderTheme(GRAPHIC_FACTORY, new DisplayModel(), xmlRenderTheme); Assert.assertEquals(3, renderTheme.getLevels()); renderTheme.scaleStrokeWidth(12.34f, (byte) 12); renderTheme.scaleTextSize(56.78f, (byte) 12); // RenderCallback renderCallback = new DummyRenderCallback(); // List<Tag> closedWayTags = Arrays.asList(new Tag("amenity", "parking")); // List<Tag> linearWayTags = Arrays.asList(new Tag("highway", "primary"), new Tag("oneway", "yes")); // List<Tag> nodeTags = Arrays.asList(new Tag("place", "city"), new Tag("highway", "turning_circle")); for (byte zoomLevel = 0; zoomLevel < 25; ++zoomLevel) { // renderTheme.matchClosedWay(renderCallback, closedWayTags, zoomLevel, 256); // renderTheme.matchLinearWay(renderCallback, linearWayTags, zoomLevel); // renderTheme.matchNode(renderCallback, nodeTags, zoomLevel); } renderTheme.destroy(); } }
@Override public RenderTheme call() { if (xmlRenderTheme == null || this.displayModel == null) { return null; } try { return RenderThemeHandler.getRenderTheme(this.graphicFactory, displayModel, this.xmlRenderTheme); } catch (XmlPullParserException e) { throw new IllegalArgumentException("Parse error for XML rendertheme", e); } catch (IOException e) { throw new IllegalArgumentException("File error for XML rendertheme", e); } } }