Elexis API documentation
Version 2.1.6 as of December 11 2011

ch.elexis.text.model
Class SimpleStructuredDocument

java.lang.Object
  extended by Document
      extended by ch.elexis.text.model.SimpleStructuredDocument

public class SimpleStructuredDocument
extends Document

SimpleStructuredText is an XML format to define structured texts. To simplify interpretation for different readers with different capabilities, text and structure are strictly separated. For backward compatibility, SSD will read the earlier Samdas format transparently

Author:
gerry

Field Summary
static java.lang.String ELEM_RECORD
           
static java.lang.String ELEM_ROOT
           
static java.lang.String ELEM_TEXT
           
static java.lang.String GENERATOR
           
static Namespace ns
           
static Namespace nsschema
           
static Namespace nsxsi
           
static java.lang.String VERSION
           
 
Constructor Summary
SimpleStructuredDocument()
           
SimpleStructuredDocument(boolean bUseLegacyMode)
          Constructor for full backward compatibility.
 
Method Summary
 void addRange(SSDRange range)
          Ad a new Range.
 int checkPosition(int pos)
          check where near the given position an insert is possible
 SSDRange findRange(int position)
          Find a range that lives at a given position
 java.lang.String[] getLegalLineDelimiters()
           
 java.lang.String getPlaintext()
          Return the contents as plaintext (i.e. without any markups or xrefs)
 java.util.List<SSDRange> getRanges()
          Return all ranges
 java.lang.String getSubstring(GenericRange r)
          Return a portion of Text without formatting
 void load(java.lang.Object param)
          load the contents through a predefined IPersistenceProvider
 void loadText(java.lang.String input, boolean bAppend)
          Parse an input String.
 boolean removeRange(int pos)
           
 void replace(int pos, int len, java.lang.String replacement)
          Insert or replace or remove some text
 boolean save(boolean bCreateHeader, java.lang.Object param)
          save the contents through a predefined IPersistenceProvider.
 void setPersistenceProvider(IPersistenceProvider ipp)
          Set a custom IPersistenceProvider.
 java.lang.String toXML(boolean bCreateHeader)
          Convert the contents to a SimpleStructuredDocument XML file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
See Also:
Constant Field Values

GENERATOR

public static final java.lang.String GENERATOR
See Also:
Constant Field Values

ELEM_ROOT

public static final java.lang.String ELEM_ROOT
See Also:
Constant Field Values

ELEM_TEXT

public static final java.lang.String ELEM_TEXT
See Also:
Constant Field Values

ELEM_RECORD

public static final java.lang.String ELEM_RECORD
See Also:
Constant Field Values

ns

public static final Namespace ns

nsxsi

public static final Namespace nsxsi

nsschema

public static final Namespace nsschema
Constructor Detail

SimpleStructuredDocument

public SimpleStructuredDocument()

SimpleStructuredDocument

public SimpleStructuredDocument(boolean bUseLegacyMode)
Constructor for full backward compatibility.

Parameters:
bUseLegacyMode - if true, will write Samdas. If false: Will read SSD and Samdas, but always write SSD.
Method Detail

setPersistenceProvider

public void setPersistenceProvider(IPersistenceProvider ipp)
Set a custom IPersistenceProvider. This method must be called bevore any call to load() or save()

Parameters:
ipp - The IPersistenceProvider

load

public void load(java.lang.Object param)
          throws PersistenceException,
                 ElexisException
load the contents through a predefined IPersistenceProvider

Parameters:
param - Parameter for the IPersistenceProvider (implementation dependent; can be null)
Throws:
PersistenceException - if no IPersistencProvider is present or the IPersistenceProvider fails
ElexisException - if the contents from the IPersistenceProvider could not be parsed correctly

save

public boolean save(boolean bCreateHeader,
                    java.lang.Object param)
             throws PersistenceException
save the contents through a predefined IPersistenceProvider. Will only save if the document has changed since last save.

Parameters:
bCreateHeader - create heaxer information in the XML
param - parameter for the IPersistenceProvider (implementation dependent, can be null)
Returns:
true if the contents was saved, false if it was not saved (because it was not modified)
Throws:
PersistenceException - if the IPersistenceProvider is not present or fails

loadText

public void loadText(java.lang.String input,
                     boolean bAppend)
              throws ElexisException
Parse an input String. Can parse plain text, Samdas or SimpleStructuredDocument

Parameters:
input -
bAppend - if true, new input will appended. If false, current contents will be erased first.
Throws:
ElexisException - if an XML input could not be parsed

getPlaintext

public java.lang.String getPlaintext()
Return the contents as plaintext (i.e. without any markups or xrefs)

Returns:
a String containing only text

getSubstring

public java.lang.String getSubstring(GenericRange r)
Return a portion of Text without formatting

Parameters:
r - a GenericRange describing the text range to retrieve. If the GenericRange extends beyond the Text end, it will be adjusted. If the Range start is less than zero, an empty String is returned.
Returns:
a substring matching the GenericRange or the rest of the text starting at the Position of the GenericRange

toXML

public java.lang.String toXML(boolean bCreateHeader)
Convert the contents to a SimpleStructuredDocument XML file.

Parameters:
bCreateHeader - if false, a representation without header information is created
Returns:

replace

public void replace(int pos,
                    int len,
                    java.lang.String replacement)
Insert or replace or remove some text

Parameters:
replacement - the text to insert. if ins is null, nothing will be inserted
pos - start position for insert. If pos is larger than text length, it will be appended at the end. if pos is negative, nothing will be inserted.
len - length of the text to remove before inserting. if len is 0, nothing will be removed.

addRange

public void addRange(SSDRange range)
Ad a new Range. If tha range has a caption, the capion will be inserted in the text if it does not exist there already

Parameters:
range -

removeRange

public boolean removeRange(int pos)

getRanges

public java.util.List<SSDRange> getRanges()
Return all ranges

Returns:
a Collection of ranges

findRange

public SSDRange findRange(int position)
Find a range that lives at a given position

Parameters:
position - an offset in the raw text
Returns:
a range existing there or null if no range is at that position

checkPosition

public int checkPosition(int pos)
check where near the given position an insert is possible

Returns:
the place where an insert is possible. This might be the parameter itself or a different offset. If return is -1 no insert is possible at all.

getLegalLineDelimiters

public java.lang.String[] getLegalLineDelimiters()

Elexis API documentation
Version 2.1.6 as of December 11 2011

Copyright 2005-2011 by Gerry Weirich, Elexis