Revision 12504 trunk/libraries/libRaster/src/org/gvsig/raster/datastruct/serializer/ColorTableRmfSerializer.java

View differences:

ColorTableRmfSerializer.java
32 32
/**
33 33
 * <P>
34 34
 * Clase para convertir a XML una tabla de color y obtener la tabla desde XML.
35
 * Esta clase implementa el interfaz IRmfBlock con los m?todos de escritura y 
35
 * Esta clase implementa el interfaz IRmfBlock con los m?todos de escritura y
36 36
 * lectura. Estos ser?n utilizados por el gestor de ficheros RMF para escribir y
37 37
 * leer datos.
38 38
 * </P>
......
53 53
 *
54 54
 */
55 55
public class ColorTableRmfSerializer extends ClassSerializer {
56
	
56

  
57 57
	//TAGS
58 58
	public static final String MAIN_TAG = "ColorTable";
59 59
	public static final String TYPE = "Type";
......
61 61
	public static final String NAMES = "Names";
62 62
	public static final String RANGE = "Range";
63 63
	public static final String NAME = "PaletteName";
64
		
64

  
65 65
	private ColorTable  colorTable = null;
66 66

  
67 67
	/**
......
71 71
	public ColorTableRmfSerializer(ColorTable colorTable) {
72 72
		this.colorTable = colorTable;
73 73
	}
74
	
74

  
75 75
	/**
76
	 * Constructor. 
76
	 * Constructor.
77 77
	 */
78 78
	public ColorTableRmfSerializer() {
79 79
	}
80
			
80

  
81 81
	/*
82 82
	 * (non-Javadoc)
83 83
	 * @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#read(java.lang.String)
......
88 88
		int[] rgb = null;
89 89
		double[] range = null;
90 90
		String[] names = null;
91
		
91

  
92 92
		KXmlParser parser = new KXmlParser();
93 93
		Reader reader = new StringReader(xml);
94 94
		try {
......
98 98
		}
99 99
		try {
100 100
			int tag = parser.nextTag();
101
			
102
			if ( parser.getEventType() != KXmlParser.END_DOCUMENT ){    		
103
				parser.require(KXmlParser.START_TAG, null, MAIN_TAG);    			
101

  
102
			if ( parser.getEventType() != KXmlParser.END_DOCUMENT ){
103
				parser.require(KXmlParser.START_TAG, null, MAIN_TAG);
104 104
				while(tag != KXmlParser.END_DOCUMENT) {
105 105
					switch(tag) {
106 106
						case KXmlParser.START_TAG:
107
							if(parser.getName() != null) { 	
107
							if(parser.getName() != null) {
108 108
								if (parser.getName().compareTo(MAIN_TAG) == 0) {
109 109
									type = Integer.parseInt(parserString(parser, TYPE, null));
110 110
									paletteName = parserString(parser, NAME, null);
......
124 124
										rangeList = null;
125 125
									}
126 126
								}
127
							}	
127
							}
128 128
							break;
129
						case KXmlParser.END_TAG:								
129
						case KXmlParser.END_TAG:
130 130
							break;
131
						case KXmlParser.TEXT:							
131
						case KXmlParser.TEXT:
132 132
							break;
133 133
					}
134 134
					tag = parser.next();
135 135
				}
136 136
				parser.require(KXmlParser.END_DOCUMENT, null, null);
137 137
			}
138
			
138

  
139 139
		} catch (XmlPullParserException e) {
140 140
			throw new ParsingException(xml);
141 141
		} catch (IOException e) {
142 142
			throw new ParsingException(xml);
143 143
		}
144
		
144

  
145 145
		colorTable = new ColorTable(paletteName);
146 146
		colorTable.setNameClass(names);
147 147
		colorTable.setColorTable(rgb);
148
		/*
148 149
		colorTable.setType(type);
149 150
		if(colorTable.getType() == IBuffer.TYPE_FLOAT || colorTable.getType() == IBuffer.TYPE_DOUBLE)
150 151
			colorTable.setDoubleRange(range);
......
154 155
				r[i] = (int)range[i];
155 156
			colorTable.setIntRange(r);
156 157
		}
158
		*/
157 159
	}
158 160

  
159 161
	/*
......
161 163
	 * @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#write()
162 164
	 */
163 165
	public String write() {
166

  
164 167
		StringBuffer b = new StringBuffer();
165
				
168

  
166 169
		b.append("<" + MAIN_TAG + ">\n");
167
		
170

  
171
		/*
168 172
		putProperty(b, TYPE, colorTable.getType(), 1);
169 173
		putProperty(b, NAME, colorTable.getName(), 1);
170
		
174

  
171 175
		b.append("\t<" + RGB + ">");
172 176
		if(colorTable.getType() == IBuffer.TYPE_BYTE || colorTable.getType() == IBuffer.TYPE_SHORT || colorTable.getType() == IBuffer.TYPE_INT) {
173 177
			for (int rgb = 0; rgb < colorTable.getColorTable().length; rgb++)
......
178 182
				b.append(colorTable.getColorTable()[rgb] + " ");
179 183
		}
180 184
		b.append("</" + RGB + ">\n");
181
		
185

  
182 186
		b.append("\t<" + NAMES + ">");
183 187
		for (int rgb = 0; rgb < colorTable.getNameClass().length; rgb++)
184 188
			b.append(colorTable.getNameClass()[rgb] + " ");
185 189
		b.append("</" + NAMES + ">\n");
186
		
190

  
187 191
		b.append("\t<" + RANGE + ">");
188 192
		if(colorTable.getType() == IBuffer.TYPE_BYTE || colorTable.getType() == IBuffer.TYPE_SHORT || colorTable.getType() == IBuffer.TYPE_INT) {
189 193
			for (int rgb = 0; rgb < colorTable.getIntRange().length; rgb++)
......
193 197
			for (int rgb = 0; rgb < colorTable.getDoubleRange().length; rgb++)
194 198
				b.append(colorTable.getDoubleRange()[rgb] + " ");
195 199
		}
200
		*/
196 201
		b.append("</" + RANGE + ">\n");
197
		
202

  
198 203
		b.append("</" + MAIN_TAG + ">");
204

  
199 205
		return b.toString();
200 206
	}
201
	
207

  
202 208
	/*
203 209
	 * (non-Javadoc)
204 210
	 * @see org.gvsig.raster.dataset.io.rmf.IRmfBlock#getResult()

Also available in: Unified diff