001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * Created on Jan 21, 2004
017: */
018: package org.geotools.validation.xml;
019:
020: import java.io.Writer;
021: import java.util.HashMap;
022: import java.util.Iterator;
023: import java.util.Map;
024:
025: import org.geotools.validation.dto.ArgumentDTO;
026: import org.geotools.validation.dto.PlugInDTO;
027: import org.geotools.validation.dto.TestDTO;
028: import org.geotools.validation.dto.TestSuiteDTO;
029:
030: /**
031: * XMLWriter purpose.
032: *
033: * <p>
034: * Description of XMLWriter ...
035: * </p>
036: *
037: * <p>
038: * Capabilities:
039: * </p>
040: *
041: * <ul>
042: * <li>
043: * Feature: description
044: * </li>
045: * </ul>
046: *
047: * <p>
048: * Example Use:
049: * </p>
050: * <pre><code>
051: * XMLWriter x = new XMLWriter(...);
052: * </code></pre>
053: *
054: * @author dzwiers, Refractions Research, Inc.
055: * @author $Author: dmzwiers $ (last modification)
056: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/main/java/org/geotools/validation/xml/XMLWriter.java $
057: * @version $Id: XMLWriter.java 20884 2006-08-07 14:10:46Z jgarnett $
058: */
059: public class XMLWriter {
060: public static void writePlugIn(PlugInDTO dto, Writer w) {
061: WriterUtils cw = new WriterUtils(w);
062: Map m = new HashMap();
063: m.put("xmlns", "pluginSchema");
064: m.put("xmlns:gml", "http://www.opengis.net/gml");
065: m.put("xmlns:ogc", "http://www.opengis.net/ogc");
066: m.put("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
067: m
068: .put("xsi:schemaLocation",
069: "pluginSchema /data/capabilities/validate/pluginSchema.xsd");
070:
071: try {
072: cw.openTag("plugin", m);
073:
074: try {
075: cw.textTag("name", dto.getName());
076: cw.textTag("description", dto.getDescription());
077: cw.textTag("class", dto.getClassName());
078:
079: Iterator i = dto.getArgs().keySet().iterator();
080:
081: while (i.hasNext()) {
082: writeArgument((ArgumentDTO) dto.getArgs().get(
083: i.next()), w);
084: }
085: } catch (Exception e) {
086: e.printStackTrace();
087:
088: // error log it;
089: }
090:
091: cw.closeTag("plugin");
092: } catch (Exception e) {
093: e.printStackTrace();
094:
095: // error log it;
096: }
097: }
098:
099: public static void writeTest(TestDTO dto, Writer w) {
100: WriterUtils cw = new WriterUtils(w);
101:
102: try {
103: cw.openTag("test");
104:
105: try {
106: cw.textTag("name", dto.getName());
107: cw.textTag("description", dto.getDescription());
108: cw.textTag("plugin", dto.getPlugIn().getName());
109:
110: Iterator i = dto.getArgs().keySet().iterator();
111:
112: while (i.hasNext()) {
113: writeArgument((ArgumentDTO) dto.getArgs().get(
114: i.next()), w);
115: }
116: } catch (Exception e) {
117: e.printStackTrace();
118:
119: // error log it;
120: }
121:
122: cw.closeTag("test");
123: } catch (Exception e) {
124: e.printStackTrace();
125:
126: // error log it;
127: }
128: }
129:
130: public static void writeTestSuite(TestSuiteDTO dto, Writer w) {
131: WriterUtils cw = new WriterUtils(w);
132: Map m = new HashMap();
133: m.put("xmlns", "testSuiteSchema");
134: m.put("xmlns:gml", "http://www.opengis.net/gml");
135: m.put("xmlns:ogc", "http://www.opengis.net/ogc");
136: m.put("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
137: m
138: .put("xsi:schemaLocation",
139: "testSuiteSchema /data/capabilities/validate/testSuiteSchema.xsd");
140:
141: try {
142: cw.openTag("suite", m);
143:
144: try {
145: cw.textTag("name", dto.getName());
146: cw.textTag("description", dto.getDescription());
147:
148: Iterator i = dto.getTests().keySet().iterator();
149:
150: while (i.hasNext()) {
151: writeTest((TestDTO) dto.getTests().get(i.next()), w);
152: }
153: } catch (Exception e) {
154: e.printStackTrace();
155:
156: // error log it;
157: }
158:
159: cw.closeTag("suite");
160: } catch (Exception e) {
161: e.printStackTrace();
162:
163: // error log it;
164: }
165: }
166:
167: public static void writeArgument(ArgumentDTO dto, Writer w) {
168: WriterUtils cw = new WriterUtils(w);
169: Map m = new HashMap();
170:
171: if (dto.isFinal()) {
172: m.put("final", new Boolean(true));
173: }
174:
175: try {
176: cw.openTag("argument", m);
177:
178: try {
179: cw.textTag("name", dto.getName());
180: cw.writeln(ArgHelper
181: .getArgumentEncoding(dto.getValue()));
182: } catch (Exception e) {
183: // do nothing, just don't write it out
184: e.printStackTrace();
185:
186: // error log it;
187: }
188:
189: cw.closeTag("argument");
190: } catch (Exception e) {
191: e.printStackTrace();
192:
193: // error log it;
194: }
195: }
196: }
|