com.objectplanet.survey.plugin.api
Class XMLHandler

java.lang.Object
  extended by com.objectplanet.survey.plugin.api.XMLHandler

public class XMLHandler
extends java.lang.Object

Handles translation to/from XML from/to business objects.

Author:
Irina Brun

Constructor Summary
XMLHandler()
           
 
Method Summary
static void addQuestion(User user, long surveyId, java.lang.String questionXMLString)
          Creates a Question object from an XML string, and adds it at the end of the survey.
static long createSurvey(User user, java.lang.String surveyXMLString, long surveyGroupId)
          Creates a survey object from an XML string, stores it in the database, and puts the survey in a folder.
static java.lang.StringBuffer getQuestion(User user, long surveyId, int questionNo)
          Gets the XML representation of a Question object.
static java.lang.String getQuestionXMLHeader(java.lang.String encoding)
          Gets the XML header for an XML file containing a question.
static java.lang.StringBuffer getSurvey(User user, long surveyId)
          Gets the XML representation of a survey, by surveyId.
static java.lang.StringBuffer getSurveyDTD()
          Gets the internal Survey DTD to be included in the XML file when exporting a survey.
static java.lang.String getSurveyXMLHeader(java.lang.String encoding)
          Gets the XML header for an XML file containing a survey.
static java.lang.String getXMLVersionHeader(java.lang.String encoding)
          Gets the XML header for XML file where DTD is included.
static void insertQuestion(User user, long surveyId, int questionNo, java.lang.String questionXMLString)
          Creates a Question object from an XML string, and inserts it in a survey.
static void writeSurvey(User user, long surveyId, boolean includeReports, boolean includeResponses, java.io.OutputStream out)
          Writes XML representation of a survey to the output steam.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLHandler

public XMLHandler()
Method Detail

getQuestion

public static java.lang.StringBuffer getQuestion(User user,
                                                 long surveyId,
                                                 int questionNo)
                                          throws SurveySecurityException,
                                                 SurveySystemException
Gets the XML representation of a Question object. Returns XML without header (first line in XML file, with XML version number and the character encoding). Use method getQuestionXMLHeader() to get the header.

Parameters:
user - User with access to the survey
surveyId - Id of the survey
questionNo - The question number
Returns:
XML representation of the question
Throws:
SurveySecurityException - Thrown if the user is not authorized to call this method.
SurveySystemException - If an error occurs in the system.

getQuestionXMLHeader

public static java.lang.String getQuestionXMLHeader(java.lang.String encoding)
Gets the XML header for an XML file containing a question. The header is the tags <?xml version=... plus the <!DOCTYPE... (for DTD).

Parameters:
encoding - The encoding used. If null, default encoding will be used (ISO-8859-1)
Returns:
The XML header for question content type

getSurvey

public static java.lang.StringBuffer getSurvey(User user,
                                               long surveyId)
                                        throws SurveySecurityException,
                                               SurveySystemException
Gets the XML representation of a survey, by surveyId. Returns XML without header (first line in XML file, with XML version number and the character encoding). Use method getSurveyXMLHeader() to get the header. Reports are not included.

Parameters:
user - User with access to the survey
surveyId - The survey id
Returns:
The XML representing the survey object
Throws:
SurveySecurityException - Thrown if the user is not authorized to call this method.
SurveySystemException - If an error occurs in the system.

writeSurvey

public static void writeSurvey(User user,
                               long surveyId,
                               boolean includeReports,
                               boolean includeResponses,
                               java.io.OutputStream out)
                        throws SurveySecurityException,
                               SurveySystemException,
                               java.io.IOException
Writes XML representation of a survey to the output steam. Writes XML without header (first line in XML file, with XML version number and the character encoding). Use method getSurveyXMLHeader() to get the header.

Parameters:
user - User with access to the survey
surveyId - The survey id
includeReports - True if include reports in the XML
includeResponses - True if include responses in the XML
out - Output stream
Throws:
SurveySecurityException - Thrown if the user is not authorized to call this method.
SurveySystemException - If an error occurs in the system.
java.io.IOException

getSurveyXMLHeader

public static java.lang.String getSurveyXMLHeader(java.lang.String encoding)
Gets the XML header for an XML file containing a survey. The header is the tags <?xml version=... plus the <!DOCTYPE... (for DTD).

Parameters:
encoding - The encoding used. If null, default encoding will be used (ISO-8859-1)
Returns:
The XML header for survey content type

getXMLVersionHeader

public static java.lang.String getXMLVersionHeader(java.lang.String encoding)
Gets the XML header for XML file where DTD is included. The header is the tag <?xml version=...

Parameters:
encoding - The encoding used. If null, default encoding will be used (ISO-8859-1)
Returns:
The XML header

getSurveyDTD

public static java.lang.StringBuffer getSurveyDTD()
                                           throws java.io.FileNotFoundException,
                                                  java.io.IOException
Gets the internal Survey DTD to be included in the XML file when exporting a survey.

Returns:
The Survey DTD
Throws:
java.io.FileNotFoundException
java.io.IOException

addQuestion

public static void addQuestion(User user,
                               long surveyId,
                               java.lang.String questionXMLString)
                        throws ParsingException,
                               SurveySystemException
Creates a Question object from an XML string, and adds it at the end of the survey.

Parameters:
questionXMLString - XML representation of the question
user - User with access to the survey
surveyId - Survey id
Throws:
ParsingException - If an error occurred while parsing
SurveySystemException - If an error occurs in the system.

createSurvey

public static long createSurvey(User user,
                                java.lang.String surveyXMLString,
                                long surveyGroupId)
                         throws ParsingException,
                                SurveySystemException
Creates a survey object from an XML string, stores it in the database, and puts the survey in a folder.

Parameters:
surveyXMLString - XML representing a Survey
user - User with access to the survey
surveyGroupId - Survey group to put the survey in
Returns:
Id of the newly created survey.
Throws:
ParsingException - If an error occurred while parsing
SurveySystemException - If an error occurs in the system.

insertQuestion

public static void insertQuestion(User user,
                                  long surveyId,
                                  int questionNo,
                                  java.lang.String questionXMLString)
                           throws ParsingException,
                                  SurveySystemException
Creates a Question object from an XML string, and inserts it in a survey.

Parameters:
questionXMLString - XML representation of the question
user - User with access to the survey
surveyId - Survey id
questionNo - Position of the new question
Throws:
ParsingException - If an error occurred while parsing
SurveySystemException - If an error occurs in the system.

Copyright ? ObjectPlanet Inc. All Rights Reserved.

Built on December 20 2016