private void parseCapabilityTag(KXmlParser parser) throws IOException, XmlPullParserException { int currentTag; boolean end = false; parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.CAPABILITY); currentTag = parser.next(); while (!end) { switch (currentTag) { case KXmlParser.START_TAG: if (parser.getName().compareTo(CapabilitiesTags.REQUEST) == 0) { parseRequestTag(parser); } else if (parser.getName().compareTo(CapabilitiesTags.EXCEPTION) == 0) { // TODO Parse exception tags... parser.skipSubTree(); } else if ((parser.getName().compareTo(CapabilitiesTags.VENDORSPECIFICCAPABILITIES) == 0) || (parser.getName().compareTo(CapabilitiesTags.USERDEFINEDSYMBOLIZATION) == 0)) { parser.skipSubTree(); } break; case KXmlParser.END_TAG: if (parser.getName().compareTo(CapabilitiesTags.CAPABILITY) == 0) end = true; break; case KXmlParser.TEXT: break; } if (!end) { currentTag = parser.next(); } } }
private void parseItem(Feed feed, KXmlParser parser) throws IOException, XmlPullParserException { final Entry entry = new Entry(); feed.getEntries().add(entry); parser.nextTag(); while (parser.getEventType() != XmlPullParser.END_TAG) { final String nodeName = parser.getName(); if ("title".equals(nodeName)) { entry.setTitle(parser.nextText()); } else if ("link".equals(nodeName)) { entry.setLink(parser.nextText()); } else if ("description".equals(nodeName)) { entry.setDescription(parser.nextText()); } else if ("author".equals(nodeName)) { entry.setAuthor(parser.nextText()); } else if ("category".equals(nodeName)) { entry.setCategory(parser.nextText()); } else if ("comments".equals(nodeName)) { entry.setComments(parser.nextText()); } else if ("enclosure".equals(nodeName)) { entry.setEnclosure(parser.nextText()); } else if ("guid".equals(nodeName)) { entry.setGuid(parser.nextText()); } else if ("pubDate".equals(nodeName)) { entry.setPubDate(parser.nextText()); } else if ("source".equals(nodeName)) { entry.setSource(parser.nextText()); } else { parser.skipSubTree(); } parser.nextTag(); } }
private void parseChannel(Feed feed, KXmlParser parser) throws XmlPullParserException, IOException { while (parser.getEventType() != XmlPullParser.END_TAG) { final String nodeName = parser.getName(); if ("title".equals(nodeName)) { feed.setTitle(parser.nextText()); } else if ("link".equals(nodeName)) { feed.setLink(parser.nextText()); } else if ("description".equals(nodeName)) { feed.setDescription(parser.nextText()); } else if ("language".endsWith(nodeName)) { feed.setLanguage(parser.nextText()); } else if ("pubDate".endsWith(nodeName)) { feed.setPubDate(parser.nextText()); } else if ("lastBuildDate".endsWith(nodeName)) { feed.setLastBuildDate(parser.nextText()); } else if ("generator".endsWith(nodeName)) { feed.setGenerator(parser.nextText()); } else if ("managingEditor".endsWith(nodeName)) { feed.setManagingEditor(parser.nextText()); } else if ("webMaster".endsWith(nodeName)) { feed.setWebMaster(parser.nextText()); } else if ("item".endsWith(nodeName)) { parseItem(feed, parser); } else if ("image".endsWith(nodeName)) { feed.setImage(parser.nextText()); } else { parser.skipSubTree(); } parser.nextTag(); } }
/** * Crea los ficheros que forman la paleta de color de la version 1.1 a traves de un XML que se le * pasa por parametro * * @param palettesPath */ private static void createVersionFromXML(String palettesBasePath, String xml) { new File(palettesBasePath).mkdir(); KXmlParser parser = new KXmlParser(); StringReader reader = new StringReader(xml); try { parser.setInput(reader); int tag = parser.nextTag(); parser.require(KXmlParser.START_TAG, null, "palettes"); tag = parser.nextTag(); parser.require(KXmlParser.START_TAG, null, "palette_list"); parser.skipSubTree(); parser.require(KXmlParser.END_TAG, null, "palette_list"); tag = parser.nextTag(); while (tag == KXmlParser.START_TAG) { parser.require(KXmlParser.START_TAG, null, "palette"); if (parser.getAttributeCount() == 2) { // Generar nuevo fichero KXmlSerializer parserOutput = new KXmlSerializer(); FileOutputStream fileOutputStream = new FileOutputStream( palettesBasePath + File.separator + parser.getAttributeValue(0) + ".xml"); parserOutput.setOutput(fileOutputStream, null); parserOutput.startDocument("UTF-8", null); parserOutput.startTag(null, "ColorTable"); parserOutput.attribute(null, "name", parser.getAttributeValue(0)); parserOutput.attribute(null, "version", "1.1"); tag = parser.nextTag(); parser.require(KXmlParser.START_TAG, null, "table"); tag = parser.nextTag(); parserOutput.text("\n"); ArrayList items = new ArrayList(); while (tag == KXmlParser.START_TAG) { parser.require(KXmlParser.START_TAG, null, "entry"); if (parser.getAttributeCount() == 3) { String rgb = parser .getAttributeValue(1) .substring( parser.getAttributeValue(1).indexOf(",") + 1, parser.getAttributeValue(1).length()); int a = Integer.valueOf( parser .getAttributeValue(1) .substring(0, parser.getAttributeValue(1).indexOf(","))) .intValue(); int r = Integer.valueOf(rgb.substring(0, rgb.indexOf(","))).intValue(); int g = Integer.valueOf(rgb.substring(rgb.indexOf(",") + 1, rgb.lastIndexOf(","))) .intValue(); int b = Integer.valueOf(rgb.substring(rgb.lastIndexOf(",") + 1, rgb.length())).intValue(); ColorItem colorItem = new ColorItem(); colorItem.setColor(new Color(r, g, b, a)); colorItem.setInterpolated(50); colorItem.setNameClass(parser.getAttributeValue(0)); colorItem.setValue(Double.parseDouble(parser.getAttributeValue(2))); items.add(colorItem); } tag = parser.nextTag(); parser.require(KXmlParser.END_TAG, null, "entry"); tag = parser.nextTag(); } parser.require(KXmlParser.END_TAG, null, "table"); tag = parser.nextTag(); ColorTable colorTable = new ColorTable(); colorTable.createPaletteFromColorItems(items, true); items = colorTable.getColorItems(); for (int i = 0; i < items.size(); i++) { ColorItem colorItem = (ColorItem) items.get(i); parserOutput.startTag(null, "Color"); parserOutput.attribute(null, "value", String.valueOf(colorItem.getValue())); parserOutput.attribute(null, "name", String.valueOf(colorItem.getNameClass())); Color color = colorItem.getColor(); parserOutput.attribute( null, "rgb", String.valueOf(color.getRed() + "," + color.getGreen() + "," + color.getBlue())); parserOutput.attribute( null, "interpolated", String.valueOf(colorItem.getInterpolated())); parserOutput.endTag(null, "Color"); parserOutput.text("\n"); } for (int i = 0; i < items.size(); i++) { ColorItem colorItem = (ColorItem) items.get(i); parserOutput.startTag(null, "Alpha"); parserOutput.attribute(null, "value", String.valueOf(colorItem.getValue())); parserOutput.attribute(null, "alpha", String.valueOf(colorItem.getColor().getAlpha())); parserOutput.attribute( null, "interpolated", String.valueOf(colorItem.getInterpolated())); parserOutput.endTag(null, "Alpha"); parserOutput.text("\n"); } parserOutput.endTag(null, "ColorTable"); parserOutput.text("\n"); parserOutput.endDocument(); // Cerrar nuevo fichero fileOutputStream.close(); } parser.require(KXmlParser.END_TAG, null, "palette"); tag = parser.nextTag(); } parser.require(KXmlParser.END_TAG, null, "palettes"); } catch (XmlPullParserException xmlEx) { System.out.println( "El fichero de paletas predeterminadas no tiene la estructura correcta:\n " + xmlEx.getMessage()); } catch (IOException e) { } }