Package org.dom4j

Examples of org.dom4j.Document


   */
  public static Document retreiveResultsReporting(Identity subj, String type, long aiid) {
    File fUserdataRoot = new File(WebappHelper.getUserDataRoot());
    String path = RES_REPORTING + File.separator + subj.getName() + File.separator + type + File.separator + aiid + ".xml";
    File fDoc = new File(fUserdataRoot, path);
    Document doc = null;
    try {
      InputStream is = new FileInputStream(fDoc);
      BufferedInputStream bis = new BufferedInputStream(is);
      XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
      doc = xmlParser.parse(bis, false);
View Full Code Here


   */
  public void setUp(AssessmentInstance assessInstance) {
    this.assessInstance = assessInstance;
    init();

    Document el_questestinterop = assessInstance.getResolver().getQTIDocument();
    el_assessment = (Element) el_questestinterop.selectSingleNode("questestinterop/assessment");

    ident = el_assessment.attributeValue("ident");
    title = el_assessment.attributeValue("title");
    Element dur = (Element) el_assessment.selectSingleNode("duration");

View Full Code Here

    // with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if
    // no longer needed.
    VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedDir);
    VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml");
    // getDocument(..) ensures that InputStream is closed in every case.
    Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
    // if doc is null an error loading the document occured
    if (doc == null) return false;
    // check if this is marked as test
    List metas = doc.selectNodes("questestinterop/assessment/qtimetadata/qtimetadatafield");
    for (Iterator iter = metas.iterator(); iter.hasNext();) {
      Element el_metafield = (Element) iter.next();
      Element el_label = (Element) el_metafield.selectSingleNode("fieldlabel");
      String label = el_label.getText();
      if (label.equals(AssessmentInstance.QMD_LABEL_TYPE)) { // type meta
        Element el_entry = (Element) el_metafield.selectSingleNode("fieldentry");
        String entry = el_entry.getText();
        if (!(entry.equals(AssessmentInstance.QMD_ENTRY_TYPE_SELF) || entry.equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS))) return false;
      }
    }

    // check if at least one section with one item
    List sectionItems = doc.selectNodes("questestinterop/assessment/section/item");
    if (sectionItems.size() == 0) return false;
   
   
    for (Iterator iter = sectionItems.iterator(); iter.hasNext();) {
      Element it = (Element) iter.next();
View Full Code Here

   * @param unzippedDir
   * @return True if is of type.
   */
  public static boolean validate(File unzippedDir) throws AddingResourceException {
    File fManifest = new File(unzippedDir, "imsmanifest.xml");
    Document doc = IMSLoader.loadIMSDocument(fManifest);
    //do not throw exception already here, as it might be only a generic zip file
    if (doc == null) return false;
   
    String adluri = null;
    String seqencingUri = null;
    String simpleSeqencingUri = null;
    // get all organization elements. need to set namespace
    Element rootElement = doc.getRootElement();
    String nsuri = rootElement.getNamespace().getURI();
    // look for the adl cp namespace that differs a scorm package from a normal cp package
    Namespace nsADL = rootElement.getNamespaceForPrefix("adlcp");
    if (nsADL != null ) adluri = nsADL.getURI();
    Namespace nsADLSeq = rootElement.getNamespaceForPrefix("adlseq");
View Full Code Here

  private Map<String, String> createContentMap() throws DocumentException {
    Map<String, String> result = new HashMap<String, String>();
    List<StructureFieldVO> fields = structure.getFields();
    String xml = getPageBusiness().getPageContent(getPage(),
        getLanguageCode()).getContent();
    Document doc = DocumentHelper.parseText(xml);
    for (StructureFieldVO field : fields) {
        String fieldContent = doc.getRootElement().elementText(
            field.getName());
        if (fieldContent == null) {
          continue;
        }
        fieldContent = fieldContent.replace("]]]", "]]>");
View Full Code Here

    //with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if no longer needed.
    VFSContainer vfsUnzippedRoot = new LocalFolderImpl(unzippedRoot);
    VFSItem vfsQTI = vfsUnzippedRoot.resolve("qti.xml");
    //getDocument(..) ensures that InputStream is closed in every case.
    Document doc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
    //if doc is null an error loading the document occured (IOException, qti.xml does not exist)
    if (doc == null) return;
   

    // extract title
    Element el_assess = (Element)doc.selectSingleNode("questestinterop/assessment");
    String title = el_assess.attributeValue("title");
    if (title != null) addFormElement("qti.title", new StaticTextElement("qti.title", title));
    else addFormElement("qti.title", new StaticTextElement("qti.title", "-"));
   
    // extract objectives
    HTMLTextAreaElement htmlTA = new HTMLTextAreaElement("qti.objectives", 10, 60);
    htmlTA.setReadOnly(true);
    Element el_objectives = (Element)doc.selectSingleNode("//questestinterop/assessment/objectives");
    if (el_objectives != null) {
      Element el_mat = (Element)el_objectives.selectSingleNode("material/mattext");
      if (el_mat != null)
        htmlTA.setValue(el_mat.getTextTrim());
    } else htmlTA.setValue("-");
    addFormElement("qti.objectives", htmlTA);
   
    // extract num of questions
    List items = doc.selectNodes("//item");
    if (items.size() > 0)
      addFormElement("qti.questions", new StaticTextElement("qti.questions", "" + items.size()));
    else addFormElement("qti.questions", new StaticTextElement("qti.questions", "-"));
   
    // extract time limit
View Full Code Here

  public Element getObjectBank(String ident) { 
    //with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if no longer needed.
    VFSContainer vfsUnzippedRoot = new LocalFolderImpl(fUnzippedDirRoot);
    VFSItem vfsQTI = vfsUnzippedRoot.resolve(ident + ".xml");
    //getDocument(..) ensures that InputStream is closed in every case.
    Document theDoc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
    //if doc is null an error loading the document occured (IOException, qti.xml does not exist)
    if (theDoc == null) return null;
    Element objectBank = (Element) theDoc.selectSingleNode("questestinterop/objectbank");
    return objectBank;
  }
View Full Code Here

  public Document getQTIDocument() {
    //with VFS FIXME:pb:c: remove casts to LocalFileImpl and LocalFolderImpl if no longer needed.
    VFSContainer vfsUnzippedRoot = new LocalFolderImpl(fUnzippedDirRoot);
    VFSItem vfsQTI = vfsUnzippedRoot.resolve(QTI_FILE);
    //getDocument(..) ensures that InputStream is closed in every case.
    Document theDoc = QTIHelper.getDocument((LocalFileImpl) vfsQTI);
    //if doc is null an error loading the document occured (IOException, qti.xml does not exist)
    return theDoc;
  }
View Full Code Here

    if (fMeta == null) return null;
    FileInputStream in;
    try in = new FileInputStream(fMeta); }
    catch (FileNotFoundException e) {  return null}
    XMLParser xmlp = new XMLParser();
    Document doc = xmlp.parse(in, false);
    if (doc == null) return null;
   
    // extract data from XML
    Element root = doc.getRootElement();
    Element authorElement = root.element("author");
    if (authorElement != null) {
      return authorElement.getText();
    }
    return null;
View Full Code Here

   * @return Document The XML document
   */
  public Document getResDoc(AssessmentInstance ai, Locale locale, Identity identity) {
    AssessmentContext ac = ai.getAssessmentContext();
    DocumentFactory df = DocumentFactory.getInstance();
    Document res_doc = df.createDocument();
    Element root = df.createElement("qti_result_report");
    res_doc.setRootElement(root);
    Element result = root.addElement("result");
    Element extension_result = result.addElement("extension_result");

    // add items (not qti standard, but nice to display original questions ->
    // put it into extensions)
View Full Code Here

TOP

Related Classes of org.dom4j.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.