org.topbraid.spin.model.print
Class StringPrintContext

java.lang.Object
  extended by org.topbraid.spin.model.print.StringPrintContext
All Implemented Interfaces:
PrintContext

public class StringPrintContext
extends java.lang.Object
implements PrintContext

A simple implementation of PrintContext that operates on a StringBuilder. By default this is using prefixes but not extra prefixes.

Author:
Holger Knublauch

Field Summary
protected  java.lang.String indentationString
           
 
Constructor Summary
StringPrintContext()
           
StringPrintContext(java.lang.StringBuilder sb)
           
 
Method Summary
 PrintContext clone()
          Creates a clone of this PrintContext so that it can be used recursively.
 int getIndentation()
          Gets the indentation level starting at 0.
 NodeToLabelMap getNodeToLabelMap()
          Gets the Jena NodeToLabelMap associated with this.
 boolean getPrintPrefixes()
          Checks whether prefix declarations shall be printed into the head of the query.
 java.lang.String getString()
           
 java.lang.StringBuilder getStringBuilder()
           
 boolean getUseExtraPrefixes()
          Checks if the extra prefixes (such as afn:) shall be used to resolve qnames, even if they are not imported by the current model.
 boolean getUsePrefixes()
          Checks if resource URIs shall be abbreviated with qnames at all.
 boolean isNested()
          Checks if we are inside braces such as a nested expression.
 void print(java.lang.String str)
          Prints a given string to the output stream.
 void printIndentation(int depth)
          Prints the indentation string depth times.
 void printKeyword(java.lang.String str)
          Prints a keyword to the output stream.
 void println()
          Prints a line break to the output stream.
 void printURIResource(Resource resource)
          Prints a URI to the output stream.
 void printVariable(java.lang.String str)
          Prints a variable to the output stream.
static java.lang.String qnameFor(Resource resource)
          Work-around for a bug in Jena: Jena would use the default namespace of an imported Graph in a MultiUnion.
 void setIndentation(int value)
          Changes the indentation level.
 void setIndentationString(java.lang.String value)
           
 void setNested(boolean value)
          Sets the nested flag.
 void setPrintPrefixes(boolean value)
          Sets the printPrefixes flag.
 void setUseExtraPrefixes(boolean value)
          Specifies whether the context shall use extra prefixes.
 void setUsePrefixes(boolean value)
          Specifies whether the context shall use any prefixes at all.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

indentationString

protected java.lang.String indentationString
Constructor Detail

StringPrintContext

public StringPrintContext()

StringPrintContext

public StringPrintContext(java.lang.StringBuilder sb)
Method Detail

clone

public PrintContext clone()
Description copied from interface: PrintContext
Creates a clone of this PrintContext so that it can be used recursively.

Specified by:
clone in interface PrintContext
Overrides:
clone in class java.lang.Object
Returns:
a clone

getIndentation

public int getIndentation()
Description copied from interface: PrintContext
Gets the indentation level starting at 0. Indentation increases in element groups.

Specified by:
getIndentation in interface PrintContext
Returns:
the indentation level
See Also:
PrintContext.setIndentation(int)

getNodeToLabelMap

public NodeToLabelMap getNodeToLabelMap()
Description copied from interface: PrintContext
Gets the Jena NodeToLabelMap associated with this.

Specified by:
getNodeToLabelMap in interface PrintContext
Returns:
the NodeToLabelMap

getPrintPrefixes

public boolean getPrintPrefixes()
Description copied from interface: PrintContext
Checks whether prefix declarations shall be printed into the head of the query. By default this is switched off, but if turned on then the system should print all used prefixes.

Specified by:
getPrintPrefixes in interface PrintContext
Returns:
true to print prefixes

getString

public java.lang.String getString()

getStringBuilder

public java.lang.StringBuilder getStringBuilder()

getUseExtraPrefixes

public boolean getUseExtraPrefixes()
Description copied from interface: PrintContext
Checks if the extra prefixes (such as afn:) shall be used to resolve qnames, even if they are not imported by the current model.

Specified by:
getUseExtraPrefixes in interface PrintContext
Returns:
true if the extra prefixes shall be used
See Also:
PrintContext.setUseExtraPrefixes(boolean)

getUsePrefixes

public boolean getUsePrefixes()
Description copied from interface: PrintContext
Checks if resource URIs shall be abbreviated with qnames at all. If not, then the URIs are rendered using the <...> notation.

Specified by:
getUsePrefixes in interface PrintContext
Returns:
true if this is using prefixes

isNested

public boolean isNested()
Description copied from interface: PrintContext
Checks if we are inside braces such as a nested expression.

Specified by:
isNested in interface PrintContext
Returns:
if the context is currently in nested mode

print

public void print(java.lang.String str)
Description copied from interface: PrintContext
Prints a given string to the output stream.

Specified by:
print in interface PrintContext
Parameters:
str - the String to print

printIndentation

public void printIndentation(int depth)
Description copied from interface: PrintContext
Prints the indentation string depth times. For example, for depth=2 this might print " ".

Specified by:
printIndentation in interface PrintContext
Parameters:
depth - the number of indentations to print

printKeyword

public void printKeyword(java.lang.String str)
Description copied from interface: PrintContext
Prints a keyword to the output stream. This can be overloaded by subclasses to do special rendering such as syntax highlighting.

Specified by:
printKeyword in interface PrintContext
Parameters:
str - the keyword string

println

public void println()
Description copied from interface: PrintContext
Prints a line break to the output stream. Typically this would be a /n but implementations may also do
.

Specified by:
println in interface PrintContext

printVariable

public void printVariable(java.lang.String str)
Description copied from interface: PrintContext
Prints a variable to the output stream. This can be overloaded by subclasses to do special rendering such as syntax highlighting.

Specified by:
printVariable in interface PrintContext
Parameters:
str - the variable string excluding the ?

printURIResource

public void printURIResource(Resource resource)
Description copied from interface: PrintContext
Prints a URI to the output stream. This can be overloaded by subclasses to do special rendering such as syntax highlighting.

Specified by:
printURIResource in interface PrintContext
Parameters:
resource - the URI of the resource to print

qnameFor

public static java.lang.String qnameFor(Resource resource)
Work-around for a bug in Jena: Jena would use the default namespace of an imported Graph in a MultiUnion.

Parameters:
resource - the Resource to get the qname for
Returns:
the qname or null

setIndentation

public void setIndentation(int value)
Description copied from interface: PrintContext
Changes the indentation level.

Specified by:
setIndentation in interface PrintContext
Parameters:
value - the new indentation level

setIndentationString

public void setIndentationString(java.lang.String value)

setNested

public void setNested(boolean value)
Description copied from interface: PrintContext
Sets the nested flag.

Specified by:
setNested in interface PrintContext
Parameters:
value - the new value
See Also:
PrintContext.isNested()

setPrintPrefixes

public void setPrintPrefixes(boolean value)
Description copied from interface: PrintContext
Sets the printPrefixes flag.

Specified by:
setPrintPrefixes in interface PrintContext
Parameters:
value - the new value
See Also:
PrintContext.getPrintPrefixes()

setUseExtraPrefixes

public void setUseExtraPrefixes(boolean value)
Description copied from interface: PrintContext
Specifies whether the context shall use extra prefixes.

Specified by:
setUseExtraPrefixes in interface PrintContext
Parameters:
value - the new value
See Also:
PrintContext.getUseExtraPrefixes()

setUsePrefixes

public void setUsePrefixes(boolean value)
Description copied from interface: PrintContext
Specifies whether the context shall use any prefixes at all.

Specified by:
setUsePrefixes in interface PrintContext
Parameters:
value - the new value
See Also:
PrintContext.getUsePrefixes()