Changeset 6939 for FCSSimpleEndpoint
- Timestamp:
- 02/04/16 14:26:04 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/AdvancedDataViewWriter.java
r6937 r6939 28 28 29 29 /** 30 * Helper class for serializing Advanced data views. It can be used for writing 31 * more than one, but it is <em>not thread-save</em>. 30 * Helper class for serializing Advanced Data Views. It can be used for writing 31 * more than one, but it is <em>not thread-save</em>. This helper can also 32 * serialize HITS Data Views. 32 33 */ 33 34 public class AdvancedDataViewWriter { … … 38 39 public static final int NO_HIGHLIGHT = -1; 39 40 private static final String ADV_PREFIX = "adv"; 40 private static final String ADV_NS = "http://clarin.eu/fcs/dataview/advanced"; 41 private static final String ADV_MIME_TYPE = "application/x-clarin-fcs-adv+xml"; 41 private static final String ADV_NS = 42 "http://clarin.eu/fcs/dataview/advanced"; 43 private static final String ADV_MIME_TYPE = 44 "application/x-clarin-fcs-adv+xml"; 45 private static final String HITS_MIME_TYPE = 46 "application/x-clarin-fcs-hits+xml"; 47 private static final String FCS_HITS_PREFIX = "hits"; 48 private static final String FCS_HITS_NS = 49 "http://clarin.eu/fcs/dataview/hits"; 42 50 private final Unit unit; 43 51 private final List<Segment> segments = new ArrayList<Segment>(); … … 198 206 199 207 /** 200 * Write the Advanced data view to the output stream.208 * Write the Advanced Data View to the output stream. 201 209 * 202 210 * @param writer 203 211 * the writer to write to 204 212 * @throws XMLStreamException 205 * if an error occur s213 * if an error occurred 206 214 */ 207 215 public void writeAdvancedDataView(XMLStreamWriter writer) … … 271 279 } 272 280 281 282 /** 283 * Convenience method to write HITS Data View. 284 * 285 * @param writer 286 * the writer to write to 287 * @param layerId 288 * the layer id of the layer to be serialized as HITS Data View 289 * @throws XMLStreamException 290 * if an error occurred 291 * @throws IllegalArgumentException 292 * if an invalid layer id was provided 293 */ 294 public void writeHitsDataView(XMLStreamWriter writer, URI layerId) 295 throws XMLStreamException { 296 if (writer == null) { 297 throw new NullPointerException("writer == null"); 298 } 299 if (layerId == null) { 300 throw new NullPointerException("layerId == null"); 301 } 302 303 final List<Span> spans = layers.get(layerId); 304 if (spans == null) { 305 throw new IllegalArgumentException( 306 "layer with id'" + layerId + "' does not exist"); 307 } 308 XMLStreamWriterHelper.writeStartDataView(writer, HITS_MIME_TYPE); 309 writer.setPrefix(FCS_HITS_PREFIX, FCS_HITS_NS); 310 writer.writeStartElement(FCS_HITS_NS, "Result"); 311 writer.writeNamespace(FCS_HITS_PREFIX, FCS_HITS_NS); 312 boolean needSpace = false; 313 for (Span span : spans) { 314 if (span.value.length() > 0) { 315 if (needSpace) { 316 writer.writeCharacters(" "); 317 needSpace = false; 318 } 319 if (span.highlight != null) { 320 writer.writeStartElement(FCS_HITS_NS, "Hit"); 321 writer.writeCharacters(span.value); 322 writer.writeEndElement(); // "Hit" element 323 needSpace = true; 324 } else { 325 writer.writeCharacters(span.value); 326 if (!Character.isWhitespace( 327 (span.value.charAt(span.value.length() - 1)))) { 328 needSpace = true; 329 } 330 } 331 } 332 } 333 writer.writeEndElement(); // "Result" element 334 XMLStreamWriterHelper.writeEndDataView(writer); 335 } 336 273 337 private static final class Segment { 274 338 private final String id; … … 282 346 this.start = start; 283 347 this.end = end; 348 /* 349 * FIXME: add API to set reference 350 */ 284 351 this.ref = null; 285 352 } … … 306 373 } 307 374 308 } // class AdvancedDataView Helper375 } // class AdvancedDataViewWriter
Note: See TracChangeset
for help on using the changeset viewer.