Package org.javarosa.xform.parse
Class XFormParser
java.lang.Object
org.javarosa.xform.parse.XFormParser
- All Implemented Interfaces:
IXFormParserFunctions
public class XFormParser extends Object implements IXFormParserFunctions
Provides conversion from xform to epihandy object model and vice vasa.
- Author:
- Daniel Kayiwa, Drew Roos
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceXFormParser.ErrorCallbackstatic interfaceXFormParser.WarningCallback -
Field Summary
Fields Modifier and Type Field Description static StringEVENT_ATTRstatic StringITEXT_CLOSEstatic StringITEXT_OPENstatic StringNAMESPACE_JAVAROSAstatic StringNAMESPACE_ODK -
Constructor Summary
Constructors Constructor Description XFormParser(Reader reader)XFormParser(Reader form, Reader instance)XFormParser(org.kxml2.kdom.Document doc)XFormParser(org.kxml2.kdom.Document form, org.kxml2.kdom.Document instance) -
Method Summary
Modifier and Type Method Description static TreeElementbuildInstanceStructure(org.kxml2.kdom.Element node, TreeElement parent, String instanceName, String docnamespace, Map<String,String> namespacePrefixesByUri, Integer multiplicityFromGroup)Parses instance hierarchy and turns into a skeleton model; ignoring data content, but respecting repeated nodes and 'template' flagsstatic TreeElementbuildInstanceStructure(org.kxml2.kdom.Element node, TreeElement parent, Map<String,String> namespacePrefixesByUri, Integer multiplicityFromGroup)IDataReferencegetAbsRef(IDataReference ref, IFormElement parent)static IAnswerResolvergetAnswerResolver()static StringgetVagueLocation(org.kxml2.kdom.Element e)static List<String>getValidEventNames(String eventsString)static org.kxml2.kdom.DocumentgetXMLDocument(Reader reader)static org.kxml2.kdom.DocumentgetXMLDocument(Reader reader, CacheTable<String> stringCache)Deprecated.The InterningKXmlParser is not used.static StringgetXMLText(org.kxml2.kdom.Node n, boolean trim)static StringgetXMLText(org.kxml2.kdom.Node node, int i, boolean trim)reads all subsequent text nodes and returns the combined string needed because escape sequences are parsed into consecutive text nodes e.g.static QuestionDefghettoGetQuestionDef(int dataType, FormDef f, TreeReference ref)Finds a questiondef that binds to ref, if the data type is a 'select' question typevoidonError(XFormParser.ErrorCallback callback)voidonWarning(XFormParser.WarningCallback callback)FormDefparse()FormDefparse(String lastSavedSrc)FormDefparse(String formXmlSrc, String lastSavedSrc)voidparseSetValueAction(ActionController source, org.kxml2.kdom.Element e)protected QuestionDefparseUpload(IFormElement parent, org.kxml2.kdom.Element e, int controlUpload)static voidrecordInstanceFunctionCall(String instanceId)Records that the given instance ID was used as the argument to an instance() function call.static voidregisterActionHandler(String name, IElementHandler specificHandler)Let the parser know how to handle a given action -- All actions are first parsed by the generic parseAction() method, which is passed another handler to invoke after the generic handler is donevoidregisterActionTarget(TreeReference target)Notify parser about a node that will later be relevant to an action.static FormInstancerestoreDataModel(byte[] data, Class restorableType)static FormInstancerestoreDataModel(InputStream input, Class restorableType)static FormInstancerestoreDataModel(org.kxml2.kdom.Document doc, Class restorableType)static voidsetAnswerResolver(IAnswerResolver answerResolver)
-
Field Details
-
NAMESPACE_JAVAROSA
- See Also:
- Constant Field Values
-
NAMESPACE_ODK
- See Also:
- Constant Field Values
-
ITEXT_CLOSE
- See Also:
- Constant Field Values
-
ITEXT_OPEN
- See Also:
- Constant Field Values
-
EVENT_ATTR
- See Also:
- Constant Field Values
-
-
Constructor Details
-
XFormParser
-
XFormParser
public XFormParser(org.kxml2.kdom.Document doc) -
XFormParser
-
XFormParser
public XFormParser(org.kxml2.kdom.Document form, org.kxml2.kdom.Document instance)
-
-
Method Details
-
getAnswerResolver
-
setAnswerResolver
-
parse
- Throws:
IOException
-
parse
- Throws:
IOException
-
parse
- Parameters:
formXmlSrc- The path of the form definition.lastSavedSrc- The src of the last-saved instance of this form (for auto-filling). If null, no data will be loaded and the instance will be blank.- Throws:
IOException
-
getXMLDocument
- Throws:
IOException
-
getXMLDocument
@Deprecated public static org.kxml2.kdom.Document getXMLDocument(Reader reader, CacheTable<String> stringCache) throws IOExceptionDeprecated.The InterningKXmlParser is not used.Uses xkml to parse the provided XML content, and then consolidates text elements.- Parameters:
reader- the XML content providerstringCache- an optional string cache, whose presence will cause the use ofInterningKXmlParserrather thanKXmlParser.- Returns:
- the parsed document
- Throws:
IOException
-
recordInstanceFunctionCall
Records that the given instance ID was used as the argument to an instance() function call. -
getValidEventNames
-
parseSetValueAction
-
parseUpload
protected QuestionDef parseUpload(IFormElement parent, org.kxml2.kdom.Element e, int controlUpload) -
getAbsRef
- Specified by:
getAbsRefin interfaceIXFormParserFunctions
-
buildInstanceStructure
public static TreeElement buildInstanceStructure(org.kxml2.kdom.Element node, TreeElement parent, Map<String,String> namespacePrefixesByUri, Integer multiplicityFromGroup) -
buildInstanceStructure
public static TreeElement buildInstanceStructure(org.kxml2.kdom.Element node, TreeElement parent, String instanceName, String docnamespace, Map<String,String> namespacePrefixesByUri, Integer multiplicityFromGroup)Parses instance hierarchy and turns into a skeleton model; ignoring data content, but respecting repeated nodes and 'template' flags- Parameters:
node- the input nodeparent- the parentinstanceName- the name of the instancedocnamespace-namespacePrefixesByUri- namespace prefixes, by URImultiplicityFromGroup- if not null, the multiplicity to use. If present, a potentially expensive search can be avoided.- Returns:
- a new TreeElement
-
ghettoGetQuestionDef
Finds a questiondef that binds to ref, if the data type is a 'select' question type -
registerActionHandler
Let the parser know how to handle a given action -- All actions are first parsed by the generic parseAction() method, which is passed another handler to invoke after the generic handler is done- Parameters:
specificHandler- the handler for the specific action indicated by name, which is passed to and invoked by the generic parseAction() handler
-
registerActionTarget
Notify parser about a node that will later be relevant to an action. -
getXMLText
-
getXMLText
reads all subsequent text nodes and returns the combined string needed because escape sequences are parsed into consecutive text nodes e.g. "abc&123" --> (abc)(&)(123) -
restoreDataModel
public static FormInstance restoreDataModel(InputStream input, Class restorableType) throws IOException- Throws:
IOException
-
restoreDataModel
-
restoreDataModel
-
getVagueLocation
-
onWarning
-
onError
-