Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create entity provider for mneme - code taken from UMICH jiras. #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion mneme/mneme-impl/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
<war.bundle>true</war.bundle>
</properties>-->
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;

/**
* <p>
Expand Down Expand Up @@ -327,7 +329,7 @@ public Element createLomElement(Document doc, String type, String title, String
Element titleElement = doc.createElementNS("http://www.imsglobal.org/xsd/imsmd_v1p2", "imsmd:title");
Element langstring = doc.createElementNS("http://www.imsglobal.org/xsd/imsmd_v1p2", "imsmd:langstring");
title = FormattedText.unEscapeHtml(title);
langstring.setTextContent(title);
langstring.appendChild(doc.createCDATASection(title));
titleElement.appendChild(langstring);
general.appendChild(titleElement);
}
Expand All @@ -337,7 +339,7 @@ public Element createLomElement(Document doc, String type, String title, String
Element langstring = doc.createElementNS("http://www.imsglobal.org/xsd/imsmd_v1p2", "imsmd:langstring");
description = FormattedText.unEscapeHtml(description);
if (zip != null && mediaFiles != null) description = translateEmbedData(zip, subFolder, subFolder, description, mediaFiles);
langstring.setTextContent(description);
langstring.appendChild(doc.createCDATASection(description));
descElement.appendChild(langstring);
general.appendChild(descElement);
}
Expand Down Expand Up @@ -1149,9 +1151,7 @@ public Map<String, Element> getallQuestionElements(ZipOutputStream zip, Document

if (mediaFiles.isEmpty())
{
Element div = questionDocument.createElement("div");
div.setTextContent(text);
itemBody.appendChild(div);
itemBody.appendChild(questionDocument.createCDATASection(text));
}
}

Expand Down Expand Up @@ -1285,7 +1285,7 @@ else if ("file".equals(basetype))
ArrayList anFiles = new ArrayList<String>();
answer = translateEmbedData(zip, testId + "/Resources/", "Resources/", answer, anFiles);
Element correctResponseValue = questionDocument.createElement("value");
correctResponseValue.setTextContent(answer);
correctResponseValue.appendChild(questionDocument.createCDATASection(answer));
correctResponse.appendChild(correctResponseValue);
}

Expand Down Expand Up @@ -1324,9 +1324,7 @@ public Element getFillBlanksResponseChoices(Document questionDocument, Element i
while (m_fillBlanks.find())
{
String fib = m_fillBlanks.group(1);
Element textDiv = questionDocument.createElement("div");
textDiv.setTextContent(fib);
itemBody.appendChild(textDiv);
itemBody.appendChild(questionDocument.createCDATASection(fib));

String fib_curly = m_fillBlanks.group(2);
Element fbInteraction = questionDocument.createElement("textEntryInteraction");
Expand All @@ -1343,9 +1341,7 @@ public Element getFillBlanksResponseChoices(Document questionDocument, Element i
itemBody = translateEmbedData(zip, testId + "/Resources/", sb.toString(), itemBody, mediaFiles, questionDocument);
if (mediaFiles.isEmpty())
{
Element textDiv = questionDocument.createElement("div");
textDiv.setTextContent(sb.toString());
itemBody.appendChild(textDiv);
itemBody.appendChild(questionDocument.createCDATASection(sb.toString()));
}
}

Expand Down Expand Up @@ -1576,7 +1572,7 @@ public void getMCResponseChoices(Document questionDocument, Question question, M
simpleChoice = translateEmbedData(zip, testId + "/Resources/", choiceText, simpleChoice, mediaFiles, questionDocument);
if (mediaFiles.isEmpty())
{
simpleChoice.setTextContent(choiceText);
simpleChoice.appendChild(questionDocument.createCDATASection(choiceText));
}
choiceInteraction.appendChild(simpleChoice);
}
Expand Down Expand Up @@ -1709,7 +1705,7 @@ public void getMatchResponseChoices(Document questionDocument, Question question
simpleAssociableChoice = translateEmbedData(zip, testId + "/Resources/", choiceText, simpleAssociableChoice, mediaFiles, questionDocument);
if (mediaFiles.isEmpty())
{
simpleAssociableChoice.setTextContent(choiceText);
simpleAssociableChoice.appendChild(questionDocument.createCDATASection(choiceText));
}
simpleMatchSet1.appendChild(simpleAssociableChoice);

Expand All @@ -1724,7 +1720,7 @@ public void getMatchResponseChoices(Document questionDocument, Question question
simpleAssociableMatch = translateEmbedData(zip, testId + "/Resources/", matchText, simpleAssociableMatch, mediaFiles, questionDocument);
if (mediaFiles.isEmpty())
{
simpleAssociableMatch.setTextContent(matchText);
simpleAssociableMatch.appendChild(questionDocument.createCDATASection(matchText));
}
simpleMatchSet2.appendChild(simpleAssociableMatch);

Expand Down Expand Up @@ -1853,6 +1849,7 @@ protected String translateEmbedData(ZipOutputStream zip, String subFolder, Strin
private Element translateEmbedData(ZipOutputStream zip, String subFolder, String text, Element itemBody, List<String> mediaFiles,
Document questionDocument)
{
StringBuilder appender=new StringBuilder();
if (text == null || text.length() == 0) return itemBody;

Element media = null;
Expand Down Expand Up @@ -1881,9 +1878,10 @@ private Element translateEmbedData(ZipOutputStream zip, String subFolder, String

Element div = questionDocument.createElement("div");
if (startIdx <= text.length())
{
String divText = text.substring(start, startIdx);
div.setTextContent(divText);
{
String txt = text.substring(start, startIdx);
appender.append(txt);

start = m.end();
}
ref = ref.replaceAll("%20", " ");
Expand All @@ -1904,20 +1902,27 @@ private Element translateEmbedData(ZipOutputStream zip, String subFolder, String
media = questionDocument.createElement(m.group(1));
if ("a".equalsIgnoreCase(m.group(1))) media.setAttribute("target", "_blank");
media.setAttribute(m_src.group(1), embedSubFolder + embedFileName);
Document ownerDocument = media.getOwnerDocument();
//converting the element to string to add to the appender variable
DOMImplementationLS domImplLS = (DOMImplementationLS) ownerDocument
.getImplementation();
LSSerializer serializer = domImplLS.createLSSerializer();
serializer.getDomConfig().setParameter("xml-declaration", false);
String mediaString = serializer.writeToString(media);

m.appendReplacement(sb, "");

writeContentResourceToZip(zip, subFolder, resource_id, embedFileName);
itemBody.appendChild(div);
itemBody.appendChild(media);
appender.append(mediaString);
}
}
m.appendTail(sb);
if (start > 0 && start < text.length())
{
Element div = questionDocument.createElement("div");
div.setTextContent(text.substring(start));
itemBody.appendChild(div);
String substring = text.substring(start);
appender.append(substring);
}
itemBody.appendChild(questionDocument.createCDATASection(appender.toString()));
return itemBody;
}
catch (Exception e)
Expand Down
29 changes: 28 additions & 1 deletion mneme/mneme-tool/tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@
<artifactId>servlet-api</artifactId>
</dependency>

<dependency>
<groupId>org.sakaiproject.edu-services.gradebook</groupId>
<artifactId>gradebook-service-api</artifactId>
</dependency>

<dependency>
<groupId>org.sakaiproject.edu-services.gradebook</groupId>
<artifactId>gradebook-service-hibernate</artifactId>
<version>${sakai.edu-services.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
Expand All @@ -95,13 +107,28 @@
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>


<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>xml-resolver</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>org.sakaiproject.entitybroker</groupId>
<artifactId>entitybroker-api</artifactId>
</dependency>

<dependency>
<groupId>org.sakaiproject.entitybroker</groupId>
<artifactId>entitybroker-utils</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
5 changes: 5 additions & 0 deletions mneme/mneme-tool/tool/src/bundle/mneme.properties
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,8 @@ n-of-size={0} of {1}
view-essay-question={0} Essay Question
view-task-question={0} Task Question

# properties used by entity provider.
mneme.action.site=Retrieves the assessment items for a site. The request url pattern: /direct/mneme/site/{siteId}
mneme.entityprovider.notauthorized=You are not authorized to perform this operation
mneme.entityprovider.mustlogin=Only logged in users can access assessment listings
mneme.entityprovider.invalidurl=valid site id must be included in the URL /mneme/site/{siteId}
Loading