001: /**********************************************************************************
002: * $URL$
003: * $Id$
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.assessment.shared.impl.qti;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.w3c.dom.Document;
025:
026: import org.sakaiproject.tool.assessment.data.ifc.assessment.AssessmentIfc;
027: import org.sakaiproject.tool.assessment.data.ifc.assessment.ItemDataIfc;
028: import org.sakaiproject.tool.assessment.services.qti.QTIService;
029: import org.sakaiproject.tool.assessment.shared.api.qti.QTIServiceAPI;
030: import org.sakaiproject.tool.assessment.services.qti.QTIServiceException;
031:
032: /**
033: * QTIServiceImpl implements a shared interface to get/set assessment
034: * information.
035: * @author Ed Smiley <esmiley@stanford.edu>
036: */
037: public class QTIServiceImpl implements QTIServiceAPI {
038: private static Log log = LogFactory.getLog(QTIServiceImpl.class);
039:
040: /**
041: * Import an assessment XML document in QTI format, extract & persist the data.
042: * @param document the assessment XML document in QTI format
043: * @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0;
044: * @return a persisted assessment
045: */
046:
047: public AssessmentIfc createImportedAssessment(Document document,
048: int qtiVersion) {
049: try {
050: QTIService nativeQTIService = new QTIService();
051: return (AssessmentIfc) nativeQTIService
052: .createImportedAssessment(document, qtiVersion,
053: null);
054: } catch (Exception ex) {
055: log.warn("createImportedAssessment() returning null");
056: //new QTIServiceException(ex);
057: }
058: log.error("createImportedAssessment() returning null");
059: return null;
060: }
061:
062: /**
063: * Import an item XML document in QTI format, extract & persist the data.
064: * @param document the item XML document in QTI format
065: * @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0;
066: * @return a persisted item
067: */
068:
069: public ItemDataIfc createImportedItem(Document document,
070: int qtiVersion) {
071: try {
072: QTIService nativeQTIService = new QTIService();
073: return (ItemDataIfc) nativeQTIService.createImportedItem(
074: document, qtiVersion);
075: } catch (Exception ex) {
076: log.warn("createImportedItem() returning null");
077: //new QTIServiceException(ex);
078: }
079: log.error("createImportedItem() returning null");
080: return null;
081: }
082:
083: /**
084: * Get an assessment in Document form.
085: *
086: * Note: this service requires a Faces context.
087: *
088: * @param assessmentId the assessment's Id
089: * @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0;
090: * @return the Document with the assessment data
091: */
092: public Document getExportedAssessment(String assessmentId,
093: int qtiVersion) {
094: try {
095: QTIService nativeQTIService = new QTIService();
096: return nativeQTIService.getExportedAssessment(assessmentId,
097: qtiVersion);
098: } catch (Exception ex) {
099: log.warn("getExportedAssessment() returning null");
100: //new QTIServiceException(ex);
101: }
102: log.error("getExportedAssessment() returning null");
103: return null;
104: }
105:
106: /**
107: * Get an item in Document form.
108: *
109: * Note: this service requires a Faces context.
110: *
111: * @param itemId the item's Id
112: * @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0;
113: * @return the Document with the assessment data
114: */
115:
116: public Document getExportedItem(String itemId, int qtiVersion) {
117: try {
118: QTIService nativeQTIService = new QTIService();
119: return nativeQTIService.getExportedAssessment(itemId,
120: qtiVersion);
121: } catch (Exception ex) {
122: log.warn("getExportedItem() returning null");
123: //new QTIServiceException(ex);
124: }
125: log.error("getExportedItem() returning null");
126: return null;
127: }
128:
129: /**
130: * Get an item bank in Document form.
131: *
132: * Note: this service requires a Faces context.
133: *
134: * @param itemIds an array of item ids
135: * @param qtiVersion either 1=QTI VERSION 1.2 or 2=QTI Version 2.0;
136: * @return the Document with the item bank
137: */
138: public Document getExportedItemBank(String[] itemIds, int qtiVersion) {
139: try {
140: QTIService nativeQTIService = new QTIService();
141: return nativeQTIService.getExportedItemBank(itemIds,
142: qtiVersion);
143: } catch (Exception ex) {
144: log.warn("getExportedItemBank() returning null");
145: // new QTIServiceException(ex);
146: }
147: log.error("getExportedItemBank() returning null");
148: return null;
149: }
150:
151: }
|