/** Default implementation; subclasses should override as necessary. */
 public InputStream getInputStream(IArchiveResource archiveResource)
     throws IOException, FileNotFoundException {
   if (archiveResource.getType() == IArchive.ARCHIVE_TYPE) {
     IArchive thisArchive = (IArchive) archiveResource;
     ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
     IArchiveSaveAdapter saveAdapter = new ZipStreamArchiveSaveAdapterImpl(byteOut);
     ArchiveOptions archiveOptions = new ArchiveOptions();
     archiveOptions.setOption(ArchiveOptions.SAVE_ADAPTER, saveAdapter);
     try {
       IArchiveFactory.INSTANCE.saveArchive(
           thisArchive, archiveOptions, new NullProgressMonitor());
     } catch (ArchiveSaveFailureException e) {
       throw new IOException(
           "Unable to save nested Archive "
               + archiveResource.getPath()
               + " nested exception = "
               + e.getMessage()); // $NON-NLS-1$//$NON-NLS-2$
     }
     return new ByteArrayInputStream(byteOut.toByteArray());
   }
   return null;
 }
Exemplo n.º 2
0
  private void queueResources(
      HttpServletRequest request,
      ExecutionCourse executionCourse,
      ArchiveOptions options,
      Fetcher fetcher) {
    fetcher.queue(new Resource("CSS/main.css", "/CSS/main.css"));
    fetcher.queue(new Resource("images/icon_email.gif", "/images/icon_email.gif"));

    String announcementsName = options.isAnnouncements() ? "announcements.html" : "#";
    String planningName = options.isPlanning() ? "planning.html" : "#";
    String scheduleName = options.isSchedule() ? "schedule.html" : "#";
    String shiftsName = options.isShifts() ? "shifts.html" : "#";
    String groupingsName = options.isGroupings() ? "groupings.html" : "#";
    String evaluationName = options.isEvaluations() ? "evaluation.html" : "#";

    String contextPath = request.getContextPath();

    List<Rule> globalRules = new ArrayList<Rule>();
    globalRules.add(new ResourceRule(contextPath + "/CSS/(.*)", "CSS/$1"));
    globalRules.add(new ResourceRule(contextPath + "/images/(.*)", "images/$1"));
    globalRules.add(
        new SimpleTransformRule(
            contextPath + "/publico/showCourseSite.do\\?.*?method=showCurricularCourseSite.*",
            "#"));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/executionCourse.do\\?(executionCourseID=[0-9]+|&amp;|method=firstPage)+",
            "index.html"));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/announcementManagement.do\\?(executionCourseID=[0-9]+|&amp;|method=start)+",
            announcementsName));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/executionCourse.do\\?(executionCourseID=[0-9]+|&amp;|method=lessonPlannings)+",
            planningName));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/executionCourse.do\\?(executionCourseID=[0-9]+|&amp;|method=summaries)+",
            "summaries.html"));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/executionCourse.do\\?(executionCourseID=[0-9]+|&amp;|method=objectives)+",
            "objectives.html"));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/executionCourse.do\\?(executionCourseID=[0-9]+|&amp;|method=program)+",
            "program.html"));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/executionCourse.do\\?(executionCourseID=[0-9]+|&amp;|method=evaluationMethod)+",
            "evaluation-method.html"));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/executionCourse.do\\?(executionCourseID=[0-9]+|&amp;|method=bibliographicReference)+",
            "bibliography.html"));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/executionCourse.do\\?(executionCourseID=[0-9]+|&amp;|method=schedule)+",
            scheduleName));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/executionCourse.do\\?(executionCourseID=[0-9]+|&amp;|method=shifts)+",
            shiftsName));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/executionCourse.do\\?(executionCourseID=[0-9]+|&amp;|method=groupings)+",
            groupingsName));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/executionCourse.do\\?(executionCourseID=[0-9]+|&amp;|method=evaluations)+",
            evaluationName));
    globalRules.add(
        new SimpleTransformRule(
            contextPath
                + "/publico/searchScormContent.do\\?(executionCourseID=[0-9]+|&amp;|method=prepareSearchForExecutionCourse)+",
            "#"));
    globalRules.add(
        new SimpleTransformRule(
            contextPath + "/publico/executionCourse.do\\?.*?sectionID=([0-9]+).*",
            "section-$1.html"));
    globalRules.add(
        new SimpleTransformRule(
            contextPath + "/publico/executionCourse.do\\?.*?method=rss.*", "#"));

    Resource resource =
        new Resource(
            "index.html",
            "/publico/executionCourse.do?method=firstPage&executionCourseID="
                + executionCourse.getExternalId());
    resource.addAllRules(globalRules);
    resource.addRule(
        new SimpleTransformRule(
            contextPath + "/publico/announcementManagement.do\\?.*?announcementId=([0-9]+).*",
            announcementsName.equals("#") ? "#" : announcementsName + "#ID_$1"));
    fetcher.queue(resource);

    if (options.isAnnouncements()) {
      resource =
          new Resource(
              "announcements.html",
              "/publico/announcementManagement.do?method=start&ommitArchive=true&executionCourseID="
                  + executionCourse.getExternalId());
      resource.addAllRules(globalRules);
      resource.addRule(
          new SimpleTransformRule(
              contextPath + "/publico/announcementManagement.do.*?announcementId=([0-9]+).*",
              "announcements.html#ID_$1"));
      resource.addRule(
          new SimpleTransformRule(
              contextPath + "/publico/announcementManagement.do.*?announcementBoardId=([0-9]+).*",
              "#"));
      fetcher.queue(resource);
    }

    if (options.isPlanning()) {
      resource =
          new Resource(
              "planning.html",
              "/publico/executionCourse.do?method=lessonPlannings&executionCourseID="
                  + executionCourse.getExternalId());
      resource.addAllRules(globalRules);
      fetcher.queue(resource);
    }

    resource =
        new Resource(
            "summaries.html",
            "/publico/executionCourse.do?method=summaries&ommitFilter=true&executionCourseID="
                + executionCourse.getExternalId());
    resource.addAllRules(globalRules);
    fetcher.queue(resource);

    resource =
        new Resource(
            "objectives.html",
            "/publico/executionCourse.do?method=objectives&executionCourseID="
                + executionCourse.getExternalId());
    resource.addAllRules(globalRules);
    fetcher.queue(resource);

    resource =
        new Resource(
            "program.html",
            "/publico/executionCourse.do?method=program&executionCourseID="
                + executionCourse.getExternalId());
    resource.addAllRules(globalRules);
    fetcher.queue(resource);

    resource =
        new Resource(
            "evaluation-method.html",
            "/publico/executionCourse.do?method=evaluationMethod&executionCourseID="
                + executionCourse.getExternalId());
    resource.addAllRules(globalRules);
    fetcher.queue(resource);

    resource =
        new Resource(
            "bibliography.html",
            "/publico/executionCourse.do?method=bibliographicReference&executionCourseID="
                + executionCourse.getExternalId());
    resource.addAllRules(globalRules);
    fetcher.queue(resource);

    if (options.isSchedule()) {
      resource =
          new Resource(
              "schedule.html",
              "/publico/executionCourse.do?method=schedule&executionCourseID="
                  + executionCourse.getExternalId());
      resource.addAllRules(globalRules);
      resource.addRule(
          new SimpleTransformRule("(" + contextPath + "/publico/)?siteViewer.do.*", "#"));
      fetcher.queue(resource);
    }

    if (options.isShifts()) {
      resource =
          new Resource(
              "shifts.html",
              "/publico/executionCourse.do?method=shifts&executionCourseID="
                  + executionCourse.getExternalId());
      resource.addAllRules(globalRules);
      resource.addRule(
          new SimpleTransformRule("(" + contextPath + "/publico/)?siteViewer.do.*", "#"));
      resource.addRule(
          new SimpleTransformRule(
              "("
                  + contextPath
                  + "/publico/)?viewClassTimeTableWithClassNameAndDegreeInitialsAction.do.*",
              "#"));
      fetcher.queue(resource);
    }

    if (options.isGroupings()) {
      resource =
          new Resource(
              "groupings.html",
              "/publico/executionCourse.do?method=groupings&executionCourseID="
                  + executionCourse.getExternalId());
      resource.addAllRules(globalRules);
      ResourceRule groupRule =
          new ResourceRule(
              contextPath + "/publico/executionCourse.do\\?method=grouping.*?groupingID=([0-9]+).*",
              "group-$1.html");
      groupRule.addAllRules(globalRules);
      resource.addRule(groupRule);
      fetcher.queue(resource);
    }

    if (options.isEvaluations()) {
      resource =
          new Resource(
              "evaluation.html",
              "/publico/executionCourse.do?method=evaluations&executionCourseID="
                  + executionCourse.getExternalId());
      resource.addAllRules(globalRules);
      ResourceRule marksRule =
          new ResourceRule(
              contextPath + "/publico/executionCourse.do\\?.*method=marks.*", "marks.html");
      marksRule.addAllRules(globalRules);
      resource.addRule(marksRule);
      fetcher.queue(resource);
    }

    for (Section section : executionCourse.getSite().getAssociatedSections()) {
      String name = String.format("section-%s.html", section.getExternalId());
      String url =
          String.format(
              "/publico/executionCourse.do?method=section&executionCourseID=%s&sectionID=%s",
              executionCourse.getExternalId(), section.getExternalId());
      resource = new Resource(name, url);
      resource.addAllRules(globalRules);

      if (options.isFiles()) {
        ResourceRule fileRule =
            new ResourceRule(".*?/bitstream/([0-9]+/[0-9]+/[0-9]+)/(.*)", "files/$2");
        resource.addRule(fileRule);
      }

      fetcher.queue(resource);
    }
  }