org.sakaiproject.tool.assessment.qti.helper
Class AuthoringXml

java.lang.Object
  extended byorg.sakaiproject.tool.assessment.qti.helper.AuthoringXml

public class AuthoringXml
extends Object

Utility to load XML templates from Faces context or local file system.

Copyright: Copyright (c) 2005 Sakai

Version:
$Id: AuthoringXml.java 1827 2005-09-19 19:43:48Z esmiley@stanford.edu $
Author:
Ed Smiley esmiley@stanford.edu

Field Summary
static String ASSESSMENT
           
static String ITEM_AUDIO
           
static String ITEM_ESSAY
           
static String ITEM_FIB
           
static String ITEM_FILE
           
static String ITEM_MATCH
           
static String ITEM_MATCHING
           
static String ITEM_MCMC
           
static String ITEM_MCSC
           
static String ITEM_SURVEY
           
static String ITEM_TF
           
static String SECTION
           
static String SETTINGS_FILE
           
static String SURVEY_10
           
static String SURVEY_5
           
static String SURVEY_AGREE
           
static String SURVEY_AVERAGE
           
static String SURVEY_EXCELLENT
           
static String SURVEY_PATH
           
static String SURVEY_STRONGLY
           
static String SURVEY_UNDECIDED
           
static String SURVEY_YES
           
static String TEMPLATE_PATH
           
 Map validTemplates
           
 
Constructor Summary
AuthoringXml(int qtiVersion)
           
 
Method Summary
 Document addAttribute(Document document, String elementXpath, String attributeName)
          Based on method in XmlStringBuffer
 Document addElement(Document document, String parentXpath, Element element)
          Based on method in XmlStringBuffer
 String getQtiPath()
           
 int getQtiVersion()
           
 String getTemplateAsString(InputStream templateStream)
          get a template as a string from its input stream
 InputStream getTemplateInputStream(String templateName)
          get template as stream using local context this presupposes a path of TEMPLATE_PATH off of / this is useful for unit testing
 InputStream getTemplateInputStream(String templateName, FacesContext context)
          get template as stream using faces context
 boolean isAssessment(String documentType)
           
 boolean isItem(String documentType)
           
 boolean isSection(String documentType)
           
 boolean isSurveyFragment(String documentType)
           
static Document readDocumentFromString(String in)
          Read a DOM Document from xml in a string.
 Document readXMLDocument(InputStream inputStream)
          read in XML document from input stream
 List selectNodes(Document document, String xpath)
          Based on method in XmlStringBuffer
 void setQtiPath(String qtiPath)
           
 void setQtiVersion(int qtiVersion)
           
 Document update(Document document, String xpath, Element element)
          Based on method in XmlStringBuffer
 Document update(Document document, String xpath, String value)
          perform Update on this object Based on method originally in XmlStringBuffer
 boolean valid(String s)
          test that a String is a valid template key
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SETTINGS_FILE

public static final String SETTINGS_FILE
See Also:
Constant Field Values

TEMPLATE_PATH

public static final String TEMPLATE_PATH
See Also:
Constant Field Values

SURVEY_PATH

public static final String SURVEY_PATH
See Also:
Constant Field Values

ASSESSMENT

public static final String ASSESSMENT
See Also:
Constant Field Values

SECTION

public static final String SECTION
See Also:
Constant Field Values

ITEM_AUDIO

public static final String ITEM_AUDIO
See Also:
Constant Field Values

ITEM_ESSAY

public static final String ITEM_ESSAY
See Also:
Constant Field Values

ITEM_FIB

public static final String ITEM_FIB
See Also:
Constant Field Values

ITEM_FILE

public static final String ITEM_FILE
See Also:
Constant Field Values

ITEM_MATCH

public static final String ITEM_MATCH
See Also:
Constant Field Values

ITEM_MCMC

public static final String ITEM_MCMC
See Also:
Constant Field Values

ITEM_MCSC

public static final String ITEM_MCSC
See Also:
Constant Field Values

ITEM_SURVEY

public static final String ITEM_SURVEY
See Also:
Constant Field Values

ITEM_TF

public static final String ITEM_TF
See Also:
Constant Field Values

ITEM_MATCHING

public static final String ITEM_MATCHING
See Also:
Constant Field Values

SURVEY_10

public static final String SURVEY_10
See Also:
Constant Field Values

SURVEY_5

public static final String SURVEY_5
See Also:
Constant Field Values

SURVEY_AGREE

public static final String SURVEY_AGREE
See Also:
Constant Field Values

SURVEY_AVERAGE

public static final String SURVEY_AVERAGE
See Also:
Constant Field Values

SURVEY_EXCELLENT

public static final String SURVEY_EXCELLENT
See Also:
Constant Field Values

SURVEY_STRONGLY

public static final String SURVEY_STRONGLY
See Also:
Constant Field Values

SURVEY_UNDECIDED

public static final String SURVEY_UNDECIDED
See Also:
Constant Field Values

SURVEY_YES

public static final String SURVEY_YES
See Also:
Constant Field Values

validTemplates

public Map validTemplates
Constructor Detail

AuthoringXml

public AuthoringXml(int qtiVersion)
Method Detail

valid

public boolean valid(String s)
test that a String is a valid template key

Parameters:
s - a key
Returns:
true if it is a valid key

getTemplateInputStream

public InputStream getTemplateInputStream(String templateName,
                                          FacesContext context)
get template as stream using faces context

Parameters:
templateName -
context -
Returns:

getTemplateInputStream

public InputStream getTemplateInputStream(String templateName)
get template as stream using local context this presupposes a path of TEMPLATE_PATH off of / this is useful for unit testing

Parameters:
templateName -
Returns:
the input stream

getTemplateAsString

public String getTemplateAsString(InputStream templateStream)
get a template as a string from its input stream

Returns:
the xml string

isAssessment

public boolean isAssessment(String documentType)

isSection

public boolean isSection(String documentType)

isItem

public boolean isItem(String documentType)

isSurveyFragment

public boolean isSurveyFragment(String documentType)

update

public Document update(Document document,
                       String xpath,
                       Element element)
Based on method in XmlStringBuffer

Parameters:
document - Document
xpath -
element -
Returns:
modified Document

update

public Document update(Document document,
                       String xpath,
                       String value)
                throws DOMException,
                       Exception
perform Update on this object Based on method originally in XmlStringBuffer

Parameters:
document - Document
xpath - :- xpath and
value - :- Value of xpath
Returns:
modified Document
Throws:
DOMException - DOCUMENTATION PENDING
Exception - DOCUMENTATION PENDING

addElement

public Document addElement(Document document,
                           String parentXpath,
                           Element element)
Based on method in XmlStringBuffer

Parameters:
document - Document
parentXpath -
element -
Returns:
modified Document

addAttribute

public Document addAttribute(Document document,
                             String elementXpath,
                             String attributeName)
Based on method in XmlStringBuffer

Parameters:
document - Document
elementXpath -
attributeName -
Returns:
modified Document

selectNodes

public final List selectNodes(Document document,
                              String xpath)
Based on method in XmlStringBuffer

Returns:
a List of Nodes

readXMLDocument

public Document readXMLDocument(InputStream inputStream)
read in XML document from input stream

Parameters:
inputStream - source for XML document
Returns:
the Document

readDocumentFromString

public static Document readDocumentFromString(String in)
Read a DOM Document from xml in a string.

Parameters:
in - The string containing the XML
Returns:
A new DOM Document with the xml contents.

getQtiVersion

public int getQtiVersion()

setQtiVersion

public void setQtiVersion(int qtiVersion)

getQtiPath

public String getQtiPath()

setQtiPath

public void setQtiPath(String qtiPath)