Package eu.clarin.sru.server.fcs
Class XMLStreamWriterHelper
- java.lang.Object
-
- eu.clarin.sru.server.fcs.XMLStreamWriterHelper
-
public class XMLStreamWriterHelper extends Object
This class provides several helper methods for writing records in the CLARIN-FCS record schema. These methods do not cover the full spectrum of all variations of records that are permitted by the CLARIN-FCS specification.
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringFCS_HITS_MIMETYPEprotected static StringFCS_HITS_NSprotected static StringFCS_HITS_PREFIXprotected static StringFCS_KWIC_MIMETYPEprotected static StringFCS_KWIC_NSprotected static StringFCS_KWIC_PREFIXprotected static StringFCS_NSprotected static StringFCS_PREFIX
-
Constructor Summary
Constructors Constructor Description XMLStreamWriterHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidwriteEndDataView(XMLStreamWriter writer)Write the end of a data view (i.e. the</DataView>element).static voidwriteEndResource(XMLStreamWriter writer)Write the end of a resource (i.e. the</Resource>element).static voidwriteEndResourceFragment(XMLStreamWriter writer)Write the end of a resource fragment (i.e. the</ResourceFragment>element).static voidwriteHitsDataView(XMLStreamWriter writer, String text, int[] hits, boolean secondIsLength)Convince method to write a simple HITS data view.static voidwriteHitsDataView(XMLStreamWriter writer, String left, String hit, String right)Convince method to write a simple HITS data view.static voidwriteKWICDataView(XMLStreamWriter writer, String left, String keyword, String right)Deprecated.Use the HITS data view instead.static voidwriteResourceWithHitsDataView(XMLStreamWriter writer, String pid, String ref, String text, int[] hits, boolean secondIsLength)Convince method to write a simple HITS data view.static voidwriteResourceWithHitsDataView(XMLStreamWriter writer, String pid, String ref, String left, String hit, String right)Convince method for writing a record with a HITS data view.static voidwriteResourceWithHitsDataViewLegacy(XMLStreamWriter writer, String pid, String ref, String left, String hit, String right)Deprecated.Only use, if you want compatability to legacy FCS applications.static voidwriteResourceWithKWICDataView(XMLStreamWriter writer, String pid, String ref, String left, String keyword, String right)Deprecated.The the HITS data view instead.static voidwriteStartDataView(XMLStreamWriter writer, String mimetype)Write the start of a data view (i.e. the<DataView>element).static voidwriteStartResource(XMLStreamWriter writer, String pid, String ref)Write the start of a resource (i.e. the<Resource>element).static voidwriteStartResourceFragment(XMLStreamWriter writer, String pid, String ref)Write the start of a resource fragment (i.e. the<ResourceFragment>element).
-
-
-
Field Detail
-
FCS_NS
protected static final String FCS_NS
- See Also:
- Constant Field Values
-
FCS_PREFIX
protected static final String FCS_PREFIX
- See Also:
- Constant Field Values
-
FCS_KWIC_NS
protected static final String FCS_KWIC_NS
- See Also:
- Constant Field Values
-
FCS_KWIC_PREFIX
protected static final String FCS_KWIC_PREFIX
- See Also:
- Constant Field Values
-
FCS_KWIC_MIMETYPE
protected static final String FCS_KWIC_MIMETYPE
- See Also:
- Constant Field Values
-
FCS_HITS_NS
protected static final String FCS_HITS_NS
- See Also:
- Constant Field Values
-
FCS_HITS_PREFIX
protected static final String FCS_HITS_PREFIX
- See Also:
- Constant Field Values
-
FCS_HITS_MIMETYPE
protected static final String FCS_HITS_MIMETYPE
- See Also:
- Constant Field Values
-
-
Method Detail
-
writeStartResource
public static void writeStartResource(XMLStreamWriter writer, String pid, String ref) throws XMLStreamException
Write the start of a resource (i.e. the<Resource>element). Calls to this method need to be balanced with calls to thewriteEndResource(XMLStreamWriter)method.- Parameters:
writer- theXMLStreamWriterto be usedpid- the persistent identifier of this resource ornull, if not applicableref- the reference of this resource ornull, if not applicable- Throws:
XMLStreamException- if an error occurred
-
writeEndResource
public static void writeEndResource(XMLStreamWriter writer) throws XMLStreamException
Write the end of a resource (i.e. the</Resource>element). Calls to this method need to be balanced with calls to thewriteStartResource(XMLStreamWriter, String, String)method.- Parameters:
writer- theXMLStreamWriterto be used- Throws:
XMLStreamException- if an error occurred
-
writeStartResourceFragment
public static void writeStartResourceFragment(XMLStreamWriter writer, String pid, String ref) throws XMLStreamException
Write the start of a resource fragment (i.e. the<ResourceFragment>element). Calls to this method need to be balanced with calls to thewriteEndResourceFragment(XMLStreamWriter)method.- Parameters:
writer- theXMLStreamWriterto be usedpid- the persistent identifier of this resource ornull, if not applicableref- the reference of this resource ornull, if not applicable- Throws:
XMLStreamException- if an error occurred
-
writeEndResourceFragment
public static void writeEndResourceFragment(XMLStreamWriter writer) throws XMLStreamException
Write the end of a resource fragment (i.e. the</ResourceFragment>element). Calls to this method need to be balanced with calls to thewriteStartResourceFragment(XMLStreamWriter, String, String)method.- Parameters:
writer- theXMLStreamWriterto be used- Throws:
XMLStreamException- if an error occurred
-
writeStartDataView
public static void writeStartDataView(XMLStreamWriter writer, String mimetype) throws XMLStreamException
Write the start of a data view (i.e. the<DataView>element). Calls to this method need to be balanced with calls to thewriteEndResource(XMLStreamWriter)method.- Parameters:
writer- theXMLStreamWriterto be usedmimetype- the MIME type of this data view applicable- Throws:
XMLStreamException- if an error occurred
-
writeEndDataView
public static void writeEndDataView(XMLStreamWriter writer) throws XMLStreamException
Write the end of a data view (i.e. the</DataView>element). Calls to this method need to be balanced with calls to thewriteStartDataView(XMLStreamWriter, String)method.- Parameters:
writer- theXMLStreamWriterto be used- Throws:
XMLStreamException- if an error occurred
-
writeKWICDataView
@Deprecated public static void writeKWICDataView(XMLStreamWriter writer, String left, String keyword, String right) throws XMLStreamException
Deprecated.Use the HITS data view instead.Convince method to write a KWIC data view. It automatically performs the calls towriteStartDataView(XMLStreamWriter, String)andwriteEndDataView(XMLStreamWriter).- Parameters:
writer- theXMLStreamWriterto be usedleft- the left context of the KWIC ornullif not applicablekeyword- the keyword of the KWICright- the right context of the KWIC ornullif not applicable- Throws:
XMLStreamException- if an error occurred
-
writeResourceWithKWICDataView
@Deprecated public static void writeResourceWithKWICDataView(XMLStreamWriter writer, String pid, String ref, String left, String keyword, String right) throws XMLStreamException
Deprecated.The the HITS data view instead.Convince method for writing a record with a KWIC data view. The following code (arguments omitted) would accomplish the same result:... writeStartResource(...); writeKWICDataView(...); writeEndResource(...); ...
- Parameters:
writer- theXMLStreamWriterto be usedpid- the persistent identifier of this resource ornull, if not applicableref- the reference of this resource ornull, if not applicableleft- the left context of the KWIC ornullif not applicablekeyword- the keyword of the KWICright- the right context of the KWIC ornullif not applicable- Throws:
XMLStreamException- if an error occurred
-
writeHitsDataView
public static void writeHitsDataView(XMLStreamWriter writer, String left, String hit, String right) throws XMLStreamException
Convince method to write a simple HITS data view. It automatically performs the calls towriteStartDataView(XMLStreamWriter, String)andwriteEndDataView(XMLStreamWriter).- Parameters:
writer- theXMLStreamWriterto be usedleft- the left context of the hit ornullif not applicablehit- the actual hit, that will be highlightedright- the right context of the hit ornullif not applicable- Throws:
XMLStreamException- if an error occurred
-
writeResourceWithHitsDataView
public static void writeResourceWithHitsDataView(XMLStreamWriter writer, String pid, String ref, String left, String hit, String right) throws XMLStreamException
Convince method for writing a record with a HITS data view. The following code (arguments omitted) would accomplish the same result:... writeStartResource(...); writeHitsDataView(...); writeEndResource(...); ...
- Parameters:
writer- theXMLStreamWriterto be usedpid- the persistent identifier of this resource ornull, if not applicableref- the reference of this resource ornull, if not applicableleft- the left context of the hit ornullif not applicablehit- the actual hit, that will be highlightedright- the right context of the hit ornullif not applicable- Throws:
XMLStreamException- if an error occurred
-
writeHitsDataView
public static void writeHitsDataView(XMLStreamWriter writer, String text, int[] hits, boolean secondIsLength) throws XMLStreamException
Convince method to write a simple HITS data view. It automatically performs the calls towriteStartDataView(XMLStreamWriter, String)andwriteEndDataView(XMLStreamWriter).- Parameters:
writer- theXMLStreamWriterto be usedtext- the text content of the hithits- an even-element array containing tuples for the hit markers in the text contentsecondIsLength- iftruethe second element of each tuple in thishitsarray is interpreted as an length; iffalseit is interpreted as an end-offset- Throws:
XMLStreamException- if an error occurred
-
writeResourceWithHitsDataView
public static void writeResourceWithHitsDataView(XMLStreamWriter writer, String pid, String ref, String text, int[] hits, boolean secondIsLength) throws XMLStreamException
Convince method to write a simple HITS data view. It automatically performs the calls towriteStartDataView(XMLStreamWriter, String)andwriteEndDataView(XMLStreamWriter).... writeStartResource(...); writeHitsDataView(...); writeEndResource(...); ...
- Parameters:
writer- theXMLStreamWriterto be usedpid- the persistent identifier of this resource ornull, if not applicableref- the reference of this resource ornull, if not applicabletext- the text content of the hithits- an even-element array containing tuples for the hit markers in the text contentsecondIsLength- iftruethe second element of each tuple in thishitsarray is interpreted as an length; iffalseit is interpreted as an end-offset- Throws:
XMLStreamException- if an error occurred
-
writeResourceWithHitsDataViewLegacy
@Deprecated public static void writeResourceWithHitsDataViewLegacy(XMLStreamWriter writer, String pid, String ref, String left, String hit, String right) throws XMLStreamException
Deprecated.Only use, if you want compatability to legacy FCS applications.Convince method for writing a record with a HITS and a KWIC data view. This method is intended for applications that want ensure computability to legacy CLARIN-FCS clients The following code (arguments omitted) would accomplish the same result:... writeStartResource(...); writeHitsDataView(...); writeKWICDataView(...); writeEndResource(...); ...
- Parameters:
writer- theXMLStreamWriterto be usedpid- the persistent identifier of this resource ornull, if not applicableref- the reference of this resource ornull, if not applicableleft- the left context of the hit ornullif not applicablehit- the actual hit, that will be highlightedright- the right context of the hit ornullif not applicable- Throws:
XMLStreamException- if an error occurred
-
-