();
@@ -141,49 +132,11 @@
"/manifest/organizations/organization/item");
parseItem(topItem.get(0));
} catch (IOException e) {
- log.error("Error displaying navigation from manifest:" + e.getMessage());
- log.error("");
+ SimpleCommonCartridgeConverter.log
+ .error("
Error displaying navigation from manifest:" + e.getMessage());
+ SimpleCommonCartridgeConverter.log.error("");
return;
}
-
- // String schemaText = getText(manifestDoc, "//metadata/schema");
- // String schemaVersion = getText(manifestDoc, "//metadata/schemaversion");
- // this.schema = (schemaText != null ? schemaText : "unknown") + " "
- // + (schemaVersion != null ? schemaVersion : "unknown");
- //
- // Document orgs = buildOrganisationList();
- // if (orgs == null) {
- // String error =
- // "Unable to convert organizations from manifest file to our own structure. Reason unknown - buildOrganisationList returned null";
- // log.error(error);
- // throw new ImscpApplicationException(error);
- // }
- //
- // try {
- // this.organzationXML = XMLUtils.write2XMLString(orgs);
- // } catch (IOException ioe) {
- // String error = "Exception thrown converting organization structure (as document) to an XML string."
- // + ioe.getMessage();
- // log.error(error, ioe);
- // throw new ImscpApplicationException(error, ioe);
- // }
- //
- // XMLPath xmlPath = new XMLPath("//metadata/*:lom/*:general/*:title/*:langstring");
- // this.title = getMetaValue(xmlPath);
- // if (this.title == null) {
- // // try the old root name - untested
- // xmlPath = new XMLPath("//metadata/*:record/*:general/*:title/*:langstring");
- // this.title = getMetaValue(xmlPath);
- // }
- //
- // xmlPath = new XMLPath("//metadata/*:lom/*:general/*:description/*:langstring");
- // this.description = getMetaValue(xmlPath);
- // if (this.description == null) {
- // // try the old root name - untested
- // xmlPath = new XMLPath("//metadata/*:record/*:general/*:description/*:langstring");
- // this.description = getMetaValue(xmlPath);
- // }
-
}
private void parseItem(Map item) throws IOException {
@@ -195,7 +148,7 @@
if (ref != null) {
String type = types.getProperty(ref);
String href = hrefs.getProperty(ref);
- if (type != null && href != null) {
+ if ((type != null) && (href != null)) {
File basciLTIXml = new File(directoryName, href);
if (type.equals("webcontent")) {
@@ -246,335 +199,27 @@
}
/**
- * Finds a value at the given xmlPath. If only one element, uses that value. If more than one element, tries to find
- * an English value.
- *
- * @param xmlPath
- * @return Value of the element found at xmlPath.
- */
- private String getMetaValue(XMLPath xmlPath) {
- Element[] elList = manifestDoc.getElements(xmlPath);
- String value = null;
- if (elList != null) {
- if (elList.length == 0) {
- value = "Unknown";
- } else if (elList.length == 1) {
- value = elList[0].getTextTrim();
- } else {
- value = null;
- // TODO check if it is really testing for english
- for (int i = 0; value == null && i < elList.length; i++) {
- // grab the first English one
- Element el = elList[i];
- String attrValue = el.getAttributeValue("lang", Namespace.XML_NAMESPACE);
- if (attrValue != null && attrValue.startsWith("en")) {
- value = el.getTextTrim();
- }
- }
- if (value == null) {
- // can't seem to find an English one, just pick the first
- value = elList[0].getTextTrim();
- }
- }
- }
- return value;
- }
-
- /* Get the text for this element - expect only 1 */
- private String getText(XMLDocument document, String xmlPathString) {
- XMLPath xmlPath = new XMLPath(xmlPathString);
- Element el = document.getElement(xmlPath);
- return el != null ? el.getTextTrim() : null;
- }
-
- private String debug(XMLDocument document, String param, String xmlPathString) {
- XMLPath xmlPath = new XMLPath(xmlPathString);
- Element[] elList = document.getElements(xmlPath);
- if (elList != null) {
- log.error(param + " xp: length " + elList.length + " el " + elList);
- if (elList.length >= 1) {
- log.error("text is " + elList[0].getTextTrim());
- return elList[0].getTextTrim();
- }
- } else {
- log.error(param + " xp: el is null");
- }
- return null;
- }
-
- /**
* @param directoryName
- * @return
- * @throws JDOMException
- * @throws IOException
*/
- private XMLDocument getDocument(String directoryName) throws IMSManifestException {
+ private void parseManifestFullMap() throws IOException {
+ // Parsing manifest
+ Document document = null;
try {
- XMLDocument doc = new XMLDocument();
- doc.loadDocument(new File(directoryName, "imsmanifest.xml"));
- return doc;
- } catch (JDOMException je) {
- String error = "Parsing error occured while loading imsmanifest.xml file. Contents of file may be invalid. "
- + je.getMessage();
- log.error(error, je);
- throw new IMSManifestException(error, je);
- } catch (FileNotFoundException e) {
- String error = "Unable to find imsmanifest file in the package." + e.getMessage();
- log.error(error, e);
- throw new IMSManifestException(error, e);
- } catch (IOException ioe) {
- String error = "IOException occured while loading imsmanifest file. " + ioe.getMessage();
- log.error(error, ioe);
- throw new IMSManifestException(error, ioe);
+ document = SimpleCommonCartridgeConverter.docBuilder.parse(new File(directoryName, "imsmanifest.xml"));
+ } catch (SAXException e) {
+ SimpleCommonCartridgeConverter.log.error("Error parsing manifest XML", e);
}
- }
-
- /**
- * @param directoryName
- * @return
- * @throws JDOMException
- * @throws IOException
- */
- private Map getManifestFullMap() throws IMSManifestException {
-
- try {
- // Parsing manifest
- DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- org.w3c.dom.Document document = parser.parse(new File(directoryName, "imsmanifest.xml"));
-
- if (document == null)
- return null;
-
- Map manifestFullMap = XMLMap.getFullMap(document);
-
- if (manifestFullMap == null) {
- log.error("Error parsing manifest XML");
- }
-
- return manifestFullMap;
-
- } catch (Exception e) {
- log.error("Error parsing manifest XML" + e.getMessage());
- return null;
+ if (document == null) {
+ throw new IOException("Error parsing manifest XML");
}
- // out.println("Reading resources from manifest...");
-
- // try {
- // XMLDocument doc = new XMLDocument();
- // doc.loadDocument(new File(directoryName, "imsmanifest.xml"));
- // return doc;
- // } catch (JDOMException je) {
- // String error = "Parsing error occured while loading imsmanifest.xml file. Contents of file may be invalid. "
- // + je.getMessage();
- // log.error(error, je);
- // throw new IMSManifestException(error, je);
- // } catch (FileNotFoundException e) {
- // String error = "Unable to find imsmanifest file in the package." + e.getMessage();
- // log.error(error, e);
- // throw new IMSManifestException(error, e);
- // } catch (IOException ioe) {
- // String error = "IOException occured while loading imsmanifest file. " + ioe.getMessage();
- // log.error(error, ioe);
- // throw new IMSManifestException(error, ioe);
- // }
- }
-
- /**
- * Built an XML document which is a list of organisations/commonCartridge.
- */
- private Document buildOrganisationList() throws IMSManifestException {
-
- Namespace nm = cpCore.getRootManifestElement().getNamespace();
-
- Element rootElement = cpCore.getRootManifestElement();
- Element orgsElement = rootElement.getChild(CP_Core.ORGANIZATIONS, nm);
-
- // set up a list of all the commonCartridge
-
- // now get all the organizations and set up the new XML document, combining
- // the organization and the commonCartridge.
- Element defaultOrg = cpCore.getDefaultOrganization(orgsElement);
- String defaultOrgIdentifier = null;
- if (defaultOrg != null)
- defaultOrgIdentifier = defaultOrg.getAttributeValue("identifier");
-
- log.debug("cpCore default org id: " + defaultOrgIdentifier);
-
- Element newRootElement = new Element("organizations");
- setAttribute(newRootElement, "version", "imscp1");
- Document doc = new Document(newRootElement);
-
- Element[] orgs = cpCore.getOrganizationsAllowed(orgsElement);
- Element initOrganizationElement = null;
- for (int i = 0; i < orgs.length; i++) {
-
- Element organizationElement = processItem(orgs[i], nm, defaultOrgIdentifier, null);
- if (initOrganizationElement == null)
- initOrganizationElement = organizationElement;
-
- newRootElement.addContent(organizationElement);
+ this.manifestFullMap = XMLMap.getFullMap(document);
+ if (manifestFullMap == null) {
+ throw new IOException("Error parsing manifest XML");
}
-
- if (log.isDebugEnabled()) {
- try {
- log.debug("Organizations are: " + XMLUtils.write2XMLString(doc));
- } catch (IOException e) {
- log.debug("Unable to convert organizations to XML for log. Organizations are: " + doc);
- }
- }
-
- return doc;
}
/**
- * Process the given element. Returns a newly formatted Element if the element is a visible item, null otherwise.
- * Will also set the value "defaultItemURL" while processing, if it finds the default item.
- *
- * First time through, the element will be an organization and parentOrgIdentifier will be null. After that,
- * elements are expected to be items and parentOrgIdentifier should not be null.
- *
- * parentOrgIdentifier is the parent organization of an item. An item is the default item if either: (a) the
- * defaultOrgIdentifier is null and it is the first item encountered which has a commonCartridge or (b)
- * parentOrgIdentifier==defaultOrgIdentifier and it is the first item encountered which has a commonCartridge.
- *
- * @param element
- * @return New version of element combining organization/item/commonCartridge details
- */
- private Element processItem(Element element, Namespace nm, String defaultOrgIdentifier, String parentOrgIdentifier)
- throws IMSManifestException {
-
- String isVisibleString = element.getAttributeValue(CP_Core.ISVISIBLE);
- if (isVisible(isVisibleString)) {
-
- String id = element.getAttributeValue(CP_Core.IDENTIFIER);
- // only process visible items as we are building the list for display to the user
- Element itref = new Element(OrganizationXMLDef.ITEM);
-
- setAttribute(itref, OrganizationXMLDef.IDENTIFIER, id); // mandatory
- setAttribute(itref, OrganizationXMLDef.PARAMETERS, element.getAttributeValue(CP_Core.PARAMETERS)); // optional
- setAttribute(itref, OrganizationXMLDef.TITLE, element.getChildText(CP_Core.TITLE, nm)); // optional
- String commonCartridgeURL = getCommonCartridgeURL(element);
- if (commonCartridgeURL != null)
- setAttribute(itref, OrganizationXMLDef.RESOURCE, commonCartridgeURL); // optional
-
- if (commonCartridgeURL != null && this.defaultItem == null
- && (defaultOrgIdentifier == null || defaultOrgIdentifier.equals(parentOrgIdentifier))) {
- setAttribute(itref, OrganizationXMLDef.DEFAULT, Boolean.TRUE.toString());
- this.defaultItem = commonCartridgeURL;
- } else {
- setAttribute(itref, OrganizationXMLDef.DEFAULT, Boolean.FALSE.toString());
- }
-
- List items = element.getChildren(CP_Core.ITEM, nm);
- Iterator iter = items.iterator();
- while (iter.hasNext()) {
- Element itrefChild = processItem((Element) iter.next(), nm, defaultOrgIdentifier,
- parentOrgIdentifier != null ? parentOrgIdentifier : id);
- if (itrefChild != null)
- itref.addContent(itrefChild);
- }
-
- return itref;
- }
- return null;
-
- }
-
- /**
- * Not sure exactly what format "isVisible" will be in. In the spec, it says Boolean (True|False) yet the
- * imslipv1p0cp.zip package has a value of "1". So this code will accept anything as visible except for false (any
- * case) or 0.
- */
- private boolean isVisible(String value) {
-
- if (value != null) {
- String trimmed = value.trim();
- if (trimmed.equalsIgnoreCase("false") || trimmed.equals("0")) {
- return false;
- }
- }
- return true;
- }
-
- private void setAttribute(Element element, String attributeName, String value) {
- if (element != null && attributeName != null && value != null)
- element.setAttribute(attributeName, value);
- }
-
- /*
- * Get the commonCartridge relating to this item. First time called it will get a list of allowed commonCartridge it
- * will cache the value in cachedCommonCartridgeList. After that, it will go to the cache. If it doesn't find the
- * commonCartridge, then it will regenerate the list of commonCartridge.
- *
- * This is done for performance - it is assumed that most items will have access to the same commonCartridge. This
- * may not be true if sub-manifests are used, hence the regneration of the array if the commonCartridge isn't found
- * in the cache.
- *
- * Note: assumes all reference ids are unique across the whole of the manifest file.
- *
- * @param item Element of type ITEM
- *
- * @return relative path of the commonCartridge, null if no IDENTIFIERREF found
- *
- * @throws IMSManifestException if IDENTIFIERREF is not null but the commonCartridge could not found.
- */
- private String getCommonCartridgeURL(Element itemElement) throws IMSManifestException {
-
- if (cachedCommonCartridgeList == null) {
- cachedCommonCartridgeList = cpCore.getReferencedElementsAllowed(itemElement);
- if (log.isDebugEnabled())
- log.debug("CommonCartridge are " + cachedCommonCartridgeList);
- }
-
- String identifierRef = itemElement.getAttributeValue(CP_Core.IDENTIFIERREF);
-
- if (identifierRef == null) {
-
- return null;
-
- } else {
-
- Element commonCartridge = getCommonCartridge2(identifierRef);
-
- if (commonCartridge == null) {
-
- // We failed to find a matching commonCartridge so try generating the list again.
- // Note: this may case the list to be generated twice first time if the
- // commonCartridge is missing. Too bad!
- cachedCommonCartridgeList = cpCore.getReferencedElementsAllowed(itemElement);
- if (log.isDebugEnabled())
- log.debug("CommonCartridge are " + cachedCommonCartridgeList);
-
- commonCartridge = getCommonCartridge2(identifierRef);
- }
-
- if (commonCartridge != null) {
- return cpCore.getRelativeURL(commonCartridge);
- } else {
- throw new IMSManifestException("Unable to find commonCartridge for item element "
- + itemElement.getAttributeValue(CP_Core.TITLE) + " looking for identifier " + identifierRef);
- }
-
- }
-
- }
-
- /**
- * @param identifierRef
- * @return
- */
- private Element getCommonCartridge2(String identifierRef) {
- for (int i = 0; i < cachedCommonCartridgeList.length; i++) {
- Element commonCartridge = cachedCommonCartridgeList[i];
- if (identifierRef != null && identifierRef.equals(commonCartridge.getAttributeValue(CP_Core.IDENTIFIER))) {
- return commonCartridge;
- }
- }
- return null;
- }
-
- /**
* @return Returns the defaultItem.
*/
public String getDefaultItem() {
@@ -655,4 +300,4 @@
public List getBasicLTIItems() {
return basicLTIItems;
}
-}
+}
\ No newline at end of file
Index: lams_tool_imscc/src/java/org/lamsfoundation/lams/tool/commonCartridge/service/CommonCartridgeServiceImpl.java
===================================================================
diff -u -r5e63656a12c02f7476564e278b43ff4ce86ac930 -rb16c3ac5e9748ee9abe4d9f4e502c643a9b3fb96
--- lams_tool_imscc/src/java/org/lamsfoundation/lams/tool/commonCartridge/service/CommonCartridgeServiceImpl.java (.../CommonCartridgeServiceImpl.java) (revision 5e63656a12c02f7476564e278b43ff4ce86ac930)
+++ lams_tool_imscc/src/java/org/lamsfoundation/lams/tool/commonCartridge/service/CommonCartridgeServiceImpl.java (.../CommonCartridgeServiceImpl.java) (revision b16c3ac5e9748ee9abe4d9f4e502c643a9b3fb96)
@@ -72,8 +72,6 @@
import org.lamsfoundation.lams.tool.commonCartridge.dao.CommonCartridgeUserDAO;
import org.lamsfoundation.lams.tool.commonCartridge.dto.ReflectDTO;
import org.lamsfoundation.lams.tool.commonCartridge.dto.Summary;
-import org.lamsfoundation.lams.tool.commonCartridge.ims.IMSManifestException;
-import org.lamsfoundation.lams.tool.commonCartridge.ims.ImscpApplicationException;
import org.lamsfoundation.lams.tool.commonCartridge.ims.SimpleCommonCartridgeConverter;
import org.lamsfoundation.lams.tool.commonCartridge.model.CommonCartridge;
import org.lamsfoundation.lams.tool.commonCartridge.model.CommonCartridgeConfigItem;
@@ -621,14 +619,6 @@
CommonCartridgeServiceImpl.log
.error(messageService.getMessage("error.msg.io.exception") + ":" + e.toString());
throw new UploadCommonCartridgeFileException(messageService.getMessage("error.msg.io.exception"));
- } catch (IMSManifestException e) {
- CommonCartridgeServiceImpl.log
- .error(messageService.getMessage("error.msg.ims.package") + ":" + e.toString());
- throw new UploadCommonCartridgeFileException(messageService.getMessage("error.msg.ims.package"));
- } catch (ImscpApplicationException e) {
- CommonCartridgeServiceImpl.log
- .error(messageService.getMessage("error.msg.ims.application") + ":" + e.toString());
- throw new UploadCommonCartridgeFileException(messageService.getMessage("error.msg.ims.application"));
}
}