|
From: <jo...@us...> - 2010-10-04 13:22:27
|
Revision: 2457
http://qtitools.svn.sourceforge.net/qtitools/?rev=2457&view=rev
Author: jonhare
Date: 2010-10-04 13:22:19 +0000 (Mon, 04 Oct 2010)
Log Message:
-----------
more updates for lifeguide
Modified Paths:
--------------
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/JQTISerializer.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/group/content/InlineStaticGroup.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/group/item/ItemBodyGroup.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/AbstractNode.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/XmlUtils.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/content/BodyElement.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/content/xhtml/object/Param.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/AbstractExpression.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/Expression.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/general/Variable.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/And.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/CustomOperator.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/item/AssessmentItem.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/shared/FieldValue.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/AssessmentItemRef.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/AssessmentSection.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/AssessmentTest.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/TimeRecord.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/flow/DefaultItemFlow.java
branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/value/FloatValue.java
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/JQTISerializer.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/JQTISerializer.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/JQTISerializer.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -29,8 +29,7 @@
public final class JQTISerializer {
public static void writeString(DataOutputStream dos, String s) {
try {
- dos.writeChars(s);
- dos.writeChar('\0');
+ dos.writeUTF(s);
}
catch(IOException e) {
throw new QTIEvaluationException(e);
@@ -39,14 +38,7 @@
public static String readString(DataInputStream dis) {
try {
- String s = "";
- char c = dis.readChar();
- while (c != '\0')
- {
- s = s+c;
- c = dis.readChar();
- }
- return s;
+ return dis.readUTF();
}
catch(IOException e) {
throw new QTIEvaluationException(e);
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/group/content/InlineStaticGroup.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/group/content/InlineStaticGroup.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/group/content/InlineStaticGroup.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -55,6 +55,8 @@
static {
for (ContentType type : ContentType.inlineStaticValues())
supportedClasses.add(type.getClassTag());
+
+ //supportedClasses.add(XInclude.CLASS_TAG);
}
/**
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/group/item/ItemBodyGroup.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/group/item/ItemBodyGroup.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/group/item/ItemBodyGroup.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -88,7 +88,7 @@
setChild(itemBody);
}
- @Override
+ /*@Override
public List<XmlNode> getChildren()
{
List<XmlNode> c = super.getChildren();
@@ -99,15 +99,13 @@
{
AssessmentItem ai = new AssessmentItem();
ai.loadWithoutClear(ib.getSourceFile());
- //c.clear();
- //c
List<XmlNode> realNodes = new ArrayList<XmlNode>(1);
realNodes.add((XmlNode)ai.getItemBody());
return realNodes;
}
}
return c;
- }
+ }*/
/**
* Creates child with given QTI class name.
@@ -126,17 +124,6 @@
public List<String> getAllSupportedClasses() {
return ItemBodyGroup.supportedClasses;
}
-
- /*@Override
- public String toXmlString(int depth, boolean printDefaultAttributes)
- {
- ItemBody ib = getItemBody();
- if (ib != null && ib.getSourceFile() != null)
- {
- AssessmentItem ai = new AssessmentItem();
- ai.loadWithoutClear(ib.getSourceFile());
- return ai.getItemBody().toXmlString(depth, printDefaultAttributes);
- }
- return super.toXmlString(depth, printDefaultAttributes);
- }*/
+
+
}
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/AbstractNode.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/AbstractNode.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/AbstractNode.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -45,6 +45,8 @@
import org.qtitools.qti.exception.QTIParseException;
import org.qtitools.qti.group.NodeGroup;
import org.qtitools.qti.group.NodeGroupList;
+import org.qtitools.qti.node.expression.AbstractExpression;
+import org.qtitools.qti.node.expression.operator.CustomOperator;
import org.qtitools.qti.validation.ValidationResult;
import org.w3c.dom.Node;
@@ -103,7 +105,7 @@
* @param parent new parent of this node
* @see #getParent
*/
- protected void setParent(XmlNode parent)
+ public void setParent(XmlNode parent)
{
this.parent = parent;
}
@@ -144,6 +146,20 @@
this.sourceUrl = sourceUrl;
}
+ public void loadIncludeUnaware(File sourceFile)
+ {
+ this.sourceFile = sourceFile;
+
+ load(getNodeIncludeUnaware(sourceFile));
+ }
+
+ public void loadIncludeUnaware(String sourceString)
+ {
+ this.sourceString = sourceString;
+
+ load(getNodeIncludeUnaware(sourceString));
+ }
+
public void load(File sourceFile)
{
this.sourceFile = sourceFile;
@@ -358,7 +374,7 @@
*/
public static Node getNode(URL url)
{
- return XmlUtils.getFirstElementNode(url, false);
+ return XmlUtils.getFirstElementNode(url, false, true);
}
/**
@@ -369,8 +385,13 @@
*/
public static Node getNode(File file)
{
- return XmlUtils.getFirstElementNode(file, false);
+ return XmlUtils.getFirstElementNode(file, false, true);
}
+
+ public static Node getNodeIncludeUnaware(File file)
+ {
+ return XmlUtils.getFirstElementNode(file, false, false);
+ }
/**
* Gets node from given source string.
@@ -380,8 +401,13 @@
*/
public static Node getNode(String string)
{
- return XmlUtils.getFirstElementNode(string, false);
+ return XmlUtils.getFirstElementNode(string, false, true);
}
+
+ public static Node getNodeIncludeUnaware(String string)
+ {
+ return XmlUtils.getFirstElementNode(string, false, false);
+ }
/**
* Prints indent into xml string.
@@ -418,7 +444,12 @@
private void writeClassMarker(DataOutputStream dos) {
JQTISerializer.writeString(dos, "__class__");
//System.out.println("CLASS: " + this.getClass().getName());
- JQTISerializer.writeString(dos, this.getClass().getName());
+
+ //String c = this.getClass().getName();
+ if (this.getClassTag().equals(CustomOperator.CLASS_TAG))
+ JQTISerializer.writeString(dos, "org.qtitools.qti.node.expression.operator.CustomOperator");
+ else
+ JQTISerializer.writeString(dos, this.getClass().getName());
}
protected abstract void writeInstanceVars(DataOutputStream dos);
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/XmlUtils.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/XmlUtils.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/XmlUtils.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -177,13 +177,13 @@
* @param validate whether validate document
* @return document builder factory
*/
- public static DocumentBuilderFactory getFactory(boolean validate)
+ public static DocumentBuilderFactory getFactory(boolean validate, boolean includeAware)
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(validate);
factory.setNamespaceAware(true);
- factory.setXIncludeAware(true);
+ factory.setXIncludeAware(includeAware);
factory.setExpandEntityReferences(false);
factory.setAttribute(ATTRIBUTE_SCHEMA_LANGUAGE_NAME, ATTRIBUTE_SCHEMA_LANGUAGE_VALUE);
@@ -199,11 +199,11 @@
* @return document builder
* @throws QTIParseException if any parsing error occurs
*/
- public static DocumentBuilder getBuilder(boolean validate) throws QTIParseException
+ public static DocumentBuilder getBuilder(boolean validate, boolean namespaceAware) throws QTIParseException
{
try
{
- DocumentBuilderFactory factory = getFactory(validate);
+ DocumentBuilderFactory factory = getFactory(validate, namespaceAware);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(new ErrorHandler()
@@ -240,7 +240,7 @@
* @return document from given source file
* @throws QTIParseException if any parsing error occurs
*/
- public static Document getDocument(File file, boolean validate) throws QTIParseException
+ public static Document getDocument(File file, boolean validate, boolean namespaceAware) throws QTIParseException
{
try {
BufferedReader reader = new BufferedReader(new UnicodeReader(new FileInputStream(file), "utf-8"));
@@ -252,7 +252,7 @@
reader.close();
- return getDocument(builder.toString(), validate, file.getParentFile().toURL().toString());
+ return getDocument(builder.toString(), validate, namespaceAware, file.getParentFile().toURL().toString());
// return getBuilder(validate).parse(file);
} catch (IOException ex) {
@@ -272,12 +272,12 @@
* @return document from given source string
* @throws QTIParseException if any parsing error occurs
*/
- public static Document getDocument(String string, boolean validate) throws QTIParseException
+ public static Document getDocument(String string, boolean validate, boolean namespaceAware) throws QTIParseException
{
- return getDocument(string, validate, null);
+ return getDocument(string, validate, namespaceAware, null);
}
- private static Document getDocument(String string, boolean validate, String systemId) throws QTIParseException
+ private static Document getDocument(String string, boolean validate, boolean namespaceAware, String systemId) throws QTIParseException
{
try
{
@@ -286,9 +286,9 @@
ByteArrayInputStream input = new ByteArrayInputStream(string.getBytes("UTF-8"));
Document document;
if (systemId != null)
- document = getBuilder(validate).parse(input, systemId);
+ document = getBuilder(validate, namespaceAware).parse(input, systemId);
else
- document = getBuilder(validate).parse(input);
+ document = getBuilder(validate, namespaceAware).parse(input);
input.close();
return document;
@@ -311,7 +311,7 @@
* @return first element node from given source url
* @throws QTIParseException if any parsing error occurs
*/
- public static Node getFirstElementNode(URL url, boolean validate) throws QTIParseException
+ public static Node getFirstElementNode(URL url, boolean validate, boolean includeAware) throws QTIParseException
{
try
{
@@ -325,7 +325,7 @@
input.close();
- return getFirstElementNode(builder.toString(), validate);
+ return getFirstElementNode(builder.toString(), validate, includeAware);
}
catch (IOException ex)
{
@@ -341,9 +341,9 @@
* @return first element node from given source file
* @throws QTIParseException if any parsing error occurs
*/
- public static Node getFirstElementNode(File file, boolean validate) throws QTIParseException
+ public static Node getFirstElementNode(File file, boolean validate, boolean includeAware) throws QTIParseException
{
- Document document = getDocument(file, validate);
+ Document document = getDocument(file, validate, includeAware);
return getFirstElementNode(document);
}
@@ -356,9 +356,9 @@
* @return first element node from given source string
* @throws QTIParseException if any parsing error occurs
*/
- public static Node getFirstElementNode(String string, boolean validate) throws QTIParseException
+ public static Node getFirstElementNode(String string, boolean validate, boolean includeAware) throws QTIParseException
{
- Document document = getDocument(string, validate);
+ Document document = getDocument(string, validate, includeAware);
return getFirstElementNode(document);
}
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/content/BodyElement.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/content/BodyElement.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/content/BodyElement.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -216,7 +216,7 @@
*/
public String getLabel()
{
- return getAttributes().getStringAttribute(ATTR_LANG_NAME).getValue();
+ return getAttributes().getStringAttribute(ATTR_LABEL_NAME).getValue();
}
/**
@@ -227,7 +227,7 @@
*/
public void setLabel(String label)
{
- getAttributes().getStringAttribute(ATTR_LANG_NAME).setValue(label);
+ getAttributes().getStringAttribute(ATTR_LABEL_NAME).setValue(label);
}
/**
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/content/xhtml/object/Param.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/content/xhtml/object/Param.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/content/xhtml/object/Param.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -91,7 +91,7 @@
public static final String ATTR_VALUE_NAME = "value";
/** Name of valuetype attribute in xml schema. */
- public static final String ATTR_VALUETYPE_NAME = "valuetype";
+ //public static final String ATTR_VALUETYPE_NAME = "valuetype";
/** Name of type attribute in xml schema. */
public static final String ATTR_TYPE_NAME = "type";
@@ -106,7 +106,7 @@
getAttributes().add(new StringAttribute(this, ATTR_NAME_NAME));
getAttributes().add(new StringAttribute(this, ATTR_VALUE_NAME));
- getAttributes().add(new ParamTypeAttribute(this, ATTR_VALUETYPE_NAME));
+ //getAttributes().add(new ParamTypeAttribute(this, ATTR_VALUETYPE_NAME));
getAttributes().add(new StringAttribute(this, ATTR_TYPE_NAME, null, null, false));
}
@@ -165,10 +165,10 @@
* @return value of valuetype attribute
* @see #setValuetype
*/
- public ParamType getValuetype()
+ /*public ParamType getValuetype()
{
return getAttributes().getParamTypeAttribute(ATTR_VALUETYPE_NAME).getValue();
- }
+ }*/
/**
* Sets new value of valuetype attribute.
@@ -176,10 +176,10 @@
* @param valuetype new value of valuetype attribute
* @see #getValuetype
*/
- public void setValuetype(ParamType valuetype)
+ /*public void setValuetype(ParamType valuetype)
{
getAttributes().getParamTypeAttribute(ATTR_VALUETYPE_NAME).setValue(valuetype);
- }
+ }*/
/**
* Gets value of type attribute.
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/AbstractExpression.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/AbstractExpression.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/AbstractExpression.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -406,13 +406,13 @@
logger.debug("{}Value of {} was already evaluated.", getIndent(depth), getClass().getSimpleName());
// Logs result of evaluation.
- String format = "{}{} -> {}({})";
- Object[] arguments = new Object[] {getIndent(depth), getClass().getSimpleName(), value.getBaseType(), value};
+// String format = "{}{} -> {}({})";
+// Object[] arguments = new Object[] {getIndent(depth), getClass().getSimpleName(), value.getBaseType(), value};
- if (!(getParent() instanceof Expression))
- logger.info(format, arguments);
- else
- logger.debug(format, arguments);
+// if (!(getParent() instanceof Expression))
+// logger.info(format, arguments);
+// else
+// logger.debug(format, arguments);
return value;
}
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/Expression.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/Expression.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/Expression.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -161,4 +161,8 @@
* @return evaluated result or null if this expression is not evaluated yet
*/
public Value getValue();
+
+ public Integer getMaximumChildren();
+
+ public Integer getMinimumChildren();
}
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/general/Variable.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/general/Variable.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/general/Variable.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -255,7 +255,7 @@
}
else
{
- logger.error("{}Root parent {} is not supported. Returning NULL value.", getIndent(depth), getParentRoot().getClassTag());
+ //logger.error("{}Root parent {} is not supported. Returning NULL value.", getIndent(depth), getParentRoot().getClassTag());
return new NullValue();
}
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/And.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/And.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/And.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -93,14 +93,14 @@
logger.debug("{}Value of {} was already evaluated.", getIndent(depth), getClass().getSimpleName());
// Logs result of evaluation.
- String format = "{}{} -> {}({})";
- Object[] arguments = new Object[] {getIndent(depth), getClass().getSimpleName(), value.getBaseType(), value};
+// String format = "{}{} -> {}({})";
+// Object[] arguments = new Object[] {getIndent(depth), getClass().getSimpleName(), value.getBaseType(), value};
+//
+// if (!(getParent() instanceof Expression))
+// logger.info(format, arguments);
+// else
+// logger.debug(format, arguments);
- if (!(getParent() instanceof Expression))
- logger.info(format, arguments);
- else
- logger.debug(format, arguments);
-
return value;
}
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/CustomOperator.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/CustomOperator.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/expression/operator/CustomOperator.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -69,7 +69,7 @@
*
* @author Jonathon Hare
*/
-public class CustomOperator extends AbstractExpression
+public final class CustomOperator extends AbstractExpression
{
private static final long serialVersionUID = 1L;
@@ -245,7 +245,23 @@
}
}
method.setAccessible(true);
- return (Value) method.invoke(expression, depth);
+ try {
+ return (Value) method.invoke(expression, depth);
+ } catch (java.lang.reflect.InvocationTargetException e3) {
+ String errMsg = "CustomOperator '" + getClassAttr() + "' failed with input: [";
+ boolean first=true;
+ for (Expression x : expression.getChildren()) {
+ if (!first) errMsg += ", ";
+ if (x.getValue() == null)
+ errMsg += x.toXmlString();
+ else
+ errMsg += x.getValue();
+ first=false;
+ }
+ errMsg+="]";
+ throw new QTIEvaluationException(errMsg);
+ }
+
} catch (Exception e) {
throw new QTIEvaluationException(e);
}
@@ -312,13 +328,13 @@
@Override
protected void writeInstanceVars(DataOutputStream dos) {
super.writeInstanceVars(dos);
- if (this.expression == null)
+ //if (this.expression == null)
JQTISerializer.writeString(dos, "__nullValue");
- else
+ /*else
{
JQTISerializer.writeString(dos, "__customOperatorExpression");
this.expression.writeBinary(dos);
- }
+ }*/
}
@Override
@@ -330,10 +346,47 @@
this.expression = null;
return;
}
- s = JQTISerializer.readString(dis);
- if (s.equals("__customOperatorExpression"))
+
+ if (s.equals("__customOperatorExpression")) {
this.expression = (Expression)AbstractNode.readBinary(dis, this);
+ this.expression = null;
+ }
else
throw new QTIEvaluationException("Expected Expression for CustomOperator");
}
+
+ //should be overridden in customoperators to provide the real minimum number of children
+ @Override
+ public Integer getMinimumChildren() {
+ if (expression == null)
+ try {
+ loadExpression();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if (expression != null && expression instanceof AbstractExpression) {
+ return ((AbstractExpression)expression).getMinimumChildren();
+ } else {
+ return super.getMinimumChildren();
+ }
+ }
+
+
+ //should be overridden in customoperators to provide the real maximum number of children
+ @Override
+ public Integer getMaximumChildren() {
+ if (expression == null)
+ try {
+ loadExpression();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if (expression != null && expression instanceof AbstractExpression) {
+ return ((AbstractExpression)expression).getMaximumChildren();
+ } else {
+ return super.getMaximumChildren();
+ }
+ }
}
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/item/AssessmentItem.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/item/AssessmentItem.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/item/AssessmentItem.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -44,6 +44,7 @@
import java.util.Map;
import org.qtitools.qti.JQTI;
+import org.qtitools.qti.JQTISerializer;
import org.qtitools.qti.attribute.value.BooleanAttribute;
import org.qtitools.qti.attribute.value.IdentifierAttribute;
import org.qtitools.qti.attribute.value.StringAttribute;
@@ -595,14 +596,14 @@
* @see #setItemBody
*/
public ItemBody getItemBody() {
- File itemFile = this.getSourceFile();
+ /*File itemFile = this.getSourceFile();
if (itemFile != null && itemFile.exists())
{
AssessmentItem item = new AssessmentItem();
item.loadWithoutClear(itemFile);
item.getNodeGroups().getItemBodyGroup().getItemBody().setParent(this);
return item.getNodeGroups().getItemBodyGroup().getItemBody();
- }
+ }*/
return getNodeGroups().getItemBodyGroup().getItemBody();
}
@@ -960,7 +961,7 @@
- @Override
+ /*@Override
public void load(File sourceFile)
{
super.load(sourceFile);
@@ -977,7 +978,7 @@
{
super.load(sourceFile);
this.setSourceFile(null);
- }
+ }*/
@Override
protected void writeInstanceVars(DataOutputStream dos) {
@@ -987,7 +988,12 @@
this.durationResponse.writeBinary(dos);
- this.timeRecord.writeBinary(dos);
+ if (this.timeRecord==null) JQTISerializer.writeString(dos, "__nullTimeRecord");
+ else
+ {
+ JQTISerializer.writeString(dos, "__notNullTimeRecord");
+ this.timeRecord.writeBinary(dos);
+ }
try {
dos.writeBoolean(this.isInitialized);
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/shared/FieldValue.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/shared/FieldValue.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/shared/FieldValue.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -212,7 +212,7 @@
@Override
protected String bodyToXmlString(int depth, boolean printDefaultAttributes)
{
- return (singleValue != null) ? singleValue.toString() : "";
+ return (singleValue != null) ? singleValue.toString().replaceAll("&", "&").replaceAll("<", "<") : "";
}
@Override
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/AssessmentItemRef.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/AssessmentItemRef.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/AssessmentItemRef.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -34,9 +34,14 @@
package org.qtitools.qti.node.test;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
@@ -57,6 +62,7 @@
import org.qtitools.qti.attribute.value.UriAttribute;
import org.qtitools.qti.exception.QTIEvaluationException;
import org.qtitools.qti.exception.QTIItemFlowException;
+import org.qtitools.qti.group.NodeGroup;
import org.qtitools.qti.group.NodeGroupList;
import org.qtitools.qti.group.test.TemplateDefaultGroup;
import org.qtitools.qti.group.test.VariableMappingGroup;
@@ -114,6 +120,8 @@
private AssessmentItem item;
+ private File binaryAssessmentItem=null;
+
private class ItemState implements Serializable {
private static final long serialVersionUID = 1L;
@@ -309,6 +317,8 @@
{
AssessmentItemRef realItemRef = this.getRealItemRef();
if (realItemRef == null) return super.getNodeGroups();
+ realItemRef.setItem(this.item);
+ //System.out.println("got " + realItemRef.getIdentifier() + ", item=" + this.item);
return realItemRef.getSuperNodeGroups();
}
@@ -318,6 +328,7 @@
{
AssessmentItemRef realItemRef = this.getRealItemRef();
if (realItemRef == null) return super.getAttributes();
+ realItemRef.setItem(this.item);
return realItemRef.getSuperAttributes();
}
@@ -437,24 +448,62 @@
if (item != null)
return this.item;
+ AssessmentItem localItem = null;
- AssessmentItem localItem = null;
- File sourceFile = null;
- if(this.getParentTest().getSourceFile() != null)
+ if (binaryAssessmentItem != null && binaryAssessmentItem.exists())
{
- sourceFile = new File(getParentTest().getSourceFile().getParentFile(), getHref().getPath());
+ try {
+ DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(binaryAssessmentItem)));
+ localItem = (AssessmentItem) AbstractNode.readBinary(dis, null);
+ dis.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
}
- if(this.getParentTest().getSourceUrl() != null)
+ else
{
- sourceFile = new File(this.getParentTest().getSourceUrl().getFile());
- sourceFile = new File(sourceFile.getParentFile(), getHref().getPath());
+ File sourceFile = null;
+ if(this.getParentTest().getSourceFile() != null)
+ {
+ sourceFile = new File(getParentTest().getSourceFile().getParentFile(), getHref().getPath());
+ }
+ if(this.getParentTest().getSourceUrl() != null)
+ {
+ sourceFile = new File(this.getParentTest().getSourceUrl().getFile());
+ sourceFile = new File(sourceFile.getParentFile(), getHref().getPath());
+ }
+
+ File binaryItem = new File(sourceFile.getParentFile(), "InnerFiles" + File.separator + this.getIdentifier() + ".aibf");
+
+ if (binaryItem.exists())
+ {
+ try {
+ //long a,b;
+ DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(binaryItem.getAbsolutePath())));
+ //a=System.currentTimeMillis();
+ localItem = (AssessmentItem) AbstractNode.readBinary(dis, null);
+ //b=System.currentTimeMillis();
+ dis.close();
+ //System.out.println((b-a));
+ localItem.setTimeRecord(getCurrentState().getTimeRecord());
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ else
+ {
+ localItem = new AssessmentItem();
+ localItem.load(sourceFile);
+
+ localItem.setTimeRecord(getCurrentState().getTimeRecord());
+ }
}
-
- localItem = new AssessmentItem();
- localItem.load(sourceFile);
-
- localItem.setTimeRecord(getCurrentState().getTimeRecord());
-
+
if(refresh)
{
this.item = localItem;
@@ -462,6 +511,32 @@
return localItem;
}
+
+ public void setBinaryAssessmentItem(File biaf)
+ {
+ this.binaryAssessmentItem = biaf;
+ }
+
+ public void writeItemToBinary() {
+ if (this.binaryAssessmentItem != null && this.item != null)
+ {
+ //binaryAssessmentItem.mkdirs();
+ binaryAssessmentItem.getParentFile().mkdirs();
+
+ try {
+ if (!binaryAssessmentItem.exists()) binaryAssessmentItem.createNewFile();
+ DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(binaryAssessmentItem)));
+ this.item.writeBinary(dos);
+ dos.flush();
+ dos.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ this.item=null;
+ }
+ }
/**
* Sets new referenced item.
@@ -1044,23 +1119,25 @@
if (getStates().get(state).candidateComment != null && getStates().get(state).candidateComment.length() > 0)
result.setCandidateComment(new CandidateComment(result, getStates().get(state).candidateComment));
- for (OutcomeDeclaration declaration : getItem(false).getOutcomeDeclarations())
+ AssessmentItem ai = getItem(false);
+
+ for (OutcomeDeclaration declaration : ai.getOutcomeDeclarations())
{
//declaration.resetValue();
Value value = lookupValue(declaration.getIdentifier(), state);
OutcomeVariable variable = new OutcomeVariable(result, declaration, value);
result.getItemVariables().add(variable);
}
- result.getItemVariables().add(new OutcomeVariable(result, AssessmentItem.VARIABLE_COMPLETION_STATUS, getItem(false).getOutcomeValue(AssessmentItem.VARIABLE_COMPLETION_STATUS)));
-
- for (String identifier : getItem(false).getResponseValues().keySet())
+ result.getItemVariables().add(new OutcomeVariable(result, AssessmentItem.VARIABLE_COMPLETION_STATUS, ai.getOutcomeValue(AssessmentItem.VARIABLE_COMPLETION_STATUS)));
+
+ for (String identifier : ai.getResponseValues().keySet())
{
- ResponseDeclaration declaration = getItem(false).getResponseDeclaration(identifier);
+ ResponseDeclaration declaration = ai.getResponseDeclaration(identifier);
ResponseVariable variable = new ResponseVariable(result, declaration);
result.getItemVariables().add(variable);
}
- for (TemplateDeclaration declaration : getItem(false).getTemplateDeclarations())
+ for (TemplateDeclaration declaration : ai.getTemplateDeclarations())
{
TemplateVariable variable = new TemplateVariable(result, declaration);
result.getItemVariables().add(variable);
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/AssessmentSection.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/AssessmentSection.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/AssessmentSection.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -36,20 +36,15 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import java.io.File;
import java.util.List;
-import org.qtitools.qti.attribute.AttributeList;
import org.qtitools.qti.attribute.value.BooleanAttribute;
-import org.qtitools.qti.attribute.value.IdentifierAttribute;
import org.qtitools.qti.attribute.value.StringAttribute;
-import org.qtitools.qti.group.NodeGroupList;
import org.qtitools.qti.group.test.OrderingGroup;
import org.qtitools.qti.group.test.RubricBlockGroup;
import org.qtitools.qti.group.test.SectionPartGroup;
import org.qtitools.qti.group.test.SelectionGroup;
import org.qtitools.qti.node.content.variable.RubricBlock;
-import org.w3c.dom.Node;
/**
* Sections group together individual item references and/or sub-sections.
@@ -74,8 +69,6 @@
public static final String ATTR_KEEP_TOGETHER_NAME = "keepTogether";
/** Default value of keepTogether attribute. */
public static final boolean ATTR_KEEP_TOGETHER_DEFAULT_VALUE = true;
-
- boolean cleared = false;
/**
* Constructs section.
@@ -207,114 +200,6 @@
return getNodeGroups().getOrderingGroup().getOrdering();
}
- private AssessmentSection getRealAssessmentSection()
- {
- File assessmentSectionFile = getAssessmentSectionFile();
- if (assessmentSectionFile.exists())
- {
- AssessmentSection temp = new AssessmentSection(this.getParent());
- temp.load(assessmentSectionFile, false);
- return temp;
- }
- return null;
- }
-
- private File getAssessmentSectionFile()
- {
- if (this.getIdentifier() != null && this.getParentTest() != null && this.getParentTest().getSourceFile() != null && this.getParentTest().getSourceFile().exists())
- {
- //System.out.println("Got section file - " + this.getIdentifier());
- File realAssessmentSection = new File(this.getParentTest().getSourceFile().getAbsolutePath().substring(0, this.getParentTest().getSourceFile().getAbsolutePath().lastIndexOf(File.separator)) + File.separator + "InnerFiles" + File.separator + this.getIdentifier() + ".xml");
- return realAssessmentSection;
- }
- return new File("/definitely/does/not/exist/");
- }
-
- private boolean assessmentSectionFileExists()
- {
- return getAssessmentSectionFile().exists();
- }
-
-
- public void load(File sourceFile, boolean clear)
- {
- this.setSourceFile(sourceFile);
-
- load(getNode(sourceFile),clear);
- }
-
- @Override
- public void load(File sourceFile)
- {
- this.load(sourceFile, true);
- }
-
- public void load(Node sourceNode, boolean clear)
- {
- super.load(sourceNode);
-
-// IdentifierAttribute ident = ((IdentifierAttribute)super.getAttributes().get(true,ATTR_IDENTIFIER_NAME));
-// if (ident == null) this.id = null;
-// else this.id = ident.valueToString();
-
- if (clear && this.assessmentSectionFileExists())
- {
- //super.getNodeGroups().clear();
- //super.getNodeGroups().clearAndNullify();
- //super.getAttributes().clearAndNullify();
- //super.getAttributes().add(id);
- this.cleared=true;
- }
-
- }
-
- @Override
- public void load(Node sourceNode)
- {
- this.load(sourceNode, true);
- }
-
- @Override
- public NodeGroupList getNodeGroups()
- {
- if (this.cleared)
- {
- AssessmentSection realSection = this.getRealAssessmentSection();
- if (realSection != null) return realSection.getSuperNodeGroups();
- }
- return super.getNodeGroups();
- }
-
-
- @Override
- public AttributeList getAttributes()
- {
- AssessmentSection realSection = this.getRealAssessmentSection();
- if (realSection == null) return super.getAttributes();
- return realSection.getSuperAttributes();
- }
-
- public NodeGroupList getSuperNodeGroups()
- {
- return super.getNodeGroups();
- }
-
-
- public AttributeList getSuperAttributes()
- {
- return super.getAttributes();
- }
-
- @Override
- public String getIdentifier() {
- IdentifierAttribute id = ((IdentifierAttribute)super.getAttributes().get(true,ATTR_IDENTIFIER_NAME));
- if(id == null)
- return null;
- else
- return id.getValue();
- //return this.id;
- }
-
/**
* Sets new ordering child.
*
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/AssessmentTest.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/AssessmentTest.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/AssessmentTest.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -487,13 +487,18 @@
public AssessmentResult getAssessmentResult()
{
AssessmentResult result = new AssessmentResult();
-
result.setTestResult(getTestResult(result));
-
List<AssessmentItemRef> itemRefs = lookupItemRefs(null);
int sequenceIndex = 1;
+ //long a,b;
+ //a=System.currentTimeMillis();
for (AssessmentItemRef itemRef : itemRefs)
+ {
result.getItemResults().addAll(itemRef.getItemResult(result, sequenceIndex++, null));
+// b=System.currentTimeMillis();
+// if (b-a > 100) System.out.println(" == Done " + sequenceIndex + " ("+ itemRef.getIdentifier() + ") : " + (b-a));
+// a=b;
+ }
return result;
}
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/TimeRecord.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/TimeRecord.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/TimeRecord.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -41,6 +41,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.qtitools.qti.JQTISerializer;
import org.qtitools.qti.exception.QTIEvaluationException;
import org.qtitools.qti.node.item.ItemTimeRecord;
@@ -154,8 +155,12 @@
public long getTotal()
{
long last = 0;
- if (entered.size() == (exited.size() + 1))
- last = parent.getParentTest().getTimer().getCurrentTime() - getLastEntered();
+ //Don't add the time if it's entered but not exited. Since we no longer write the report
+ //after every request in lifeguide, you get the half an hour (or whatever) between the
+ //user finishing and the session writing added to the duration if you do this.
+
+ //if (entered.size() == (exited.size() + 1))
+ // last = parent.getParentTest().getTimer().getCurrentTime() - getLastEntered();
return total + last;
}
@@ -293,39 +298,43 @@
public static TimeRecord readTimeRecord(DataInputStream dis)
{
//AssessmentItemRef parent = (AssessmentItemRef)AbstractNode.readBinary(dis, parent);
- TimeRecord tr = new TimeRecord();
- try {
- int enteredSize = dis.readInt();
- for (int i=0; i< enteredSize; i++)
- {
- tr.entered.add(dis.readLong());
+ if (JQTISerializer.readString(dis).equals("__notNullTimeRecord"))
+ {
+ TimeRecord tr = new TimeRecord();
+ try {
+ int enteredSize = dis.readInt();
+ for (int i=0; i< enteredSize; i++)
+ {
+ tr.entered.add(dis.readLong());
+ }
+
+ int exitedSize = dis.readInt();
+ for (int i=0; i< exitedSize; i++)
+ {
+ tr.exited.add(dis.readLong());
+ }
+
+ int submittedSize = dis.readInt();
+ for (int i=0; i< submittedSize; i++)
+ {
+ tr.submitted.add(dis.readLong());
+ }
+
+ tr.skipped = dis.readLong();
+ if (tr.skipped == -1) tr.skipped = null;
+
+ tr.timedOut = dis.readLong();
+ if (tr.timedOut == -1) tr.timedOut = null;
+
+ tr.total = dis.readLong();
+ tr.duration = dis.readLong();
+ tr.increaseDuration = dis.readBoolean();
+
+ } catch (IOException e) {
+ throw new QTIEvaluationException(e);
}
-
- int exitedSize = dis.readInt();
- for (int i=0; i< exitedSize; i++)
- {
- tr.exited.add(dis.readLong());
- }
-
- int submittedSize = dis.readInt();
- for (int i=0; i< submittedSize; i++)
- {
- tr.submitted.add(dis.readLong());
- }
-
- tr.skipped = dis.readLong();
- if (tr.skipped == -1) tr.skipped = null;
-
- tr.timedOut = dis.readLong();
- if (tr.timedOut == -1) tr.timedOut = null;
-
- tr.total = dis.readLong();
- tr.duration = dis.readLong();
- tr.increaseDuration = dis.readBoolean();
-
- } catch (IOException e) {
- throw new QTIEvaluationException(e);
+ return tr;
}
- return tr;
+ else return null;
}
}
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/flow/DefaultItemFlow.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/flow/DefaultItemFlow.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/node/test/flow/DefaultItemFlow.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -105,6 +105,7 @@
if (currentIndex >= 0)
{
currentItem = this.itemRefOrder.get(currentIndex);
+ if (currentItem.getIdentifier().equals(nextItem.getIdentifier())) return nextItem;
}
else
{
Modified: branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/value/FloatValue.java
===================================================================
--- branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/value/FloatValue.java 2010-04-14 17:35:29 UTC (rev 2456)
+++ branches/lifeguide/JQTI/src/main/java/org/qtitools/qti/value/FloatValue.java 2010-10-04 13:22:19 UTC (rev 2457)
@@ -123,7 +123,8 @@
@Override
public String toString()
- {
+ {
+ if (doubleValue - Math.floor(doubleValue) < 0.00001) return "" + ((int)doubleValue);
return Double.toString(doubleValue);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|