Ejemplo n.º 1
0
 /**
  * @param ureq
  * @return
  */
 private StringBuilder createChangelogMsg(final UserRequest ureq) {
   /*
    * TODO:pb:is ImsRepositoryResolver the right place for getting the change log?
    */
   final RepositoryEntry re = courseNode.getReferencedRepositoryEntry();
   // re could be null, but if we are here it should not be null!
   final Roles userRoles = ureq.getUserSession().getRoles();
   boolean showAll = false;
   showAll = userRoles.isAuthor() || userRoles.isOLATAdmin();
   // get changelog
   final Formatter formatter = Formatter.getInstance(ureq.getLocale());
   final ImsRepositoryResolver resolver = new ImsRepositoryResolver(re.getKey());
   final QTIChangeLogMessage[] qtiChangeLog = resolver.getDocumentChangeLog();
   final StringBuilder qtiChangelog = new StringBuilder();
   Date msgDate = null;
   if (qtiChangeLog.length > 0) {
     // there are resource changes
     Arrays.sort(qtiChangeLog);
     for (int i = qtiChangeLog.length - 1; i >= 0; i--) {
       // show latest change first
       if (!showAll && qtiChangeLog[i].isPublic()) {
         // logged in person is a normal user, hence public messages only
         msgDate = new Date(qtiChangeLog[i].getTimestmp());
         qtiChangelog
             .append("\nChange date: ")
             .append(formatter.formatDateAndTime(msgDate))
             .append("\n");
         qtiChangelog.append(qtiChangeLog[i].getLogMessage());
         qtiChangelog.append("\n********************************\n");
       } else if (showAll) {
         // logged in person is an author, olat admin, owner, show all messages
         msgDate = new Date(qtiChangeLog[i].getTimestmp());
         qtiChangelog
             .append("\nChange date: ")
             .append(formatter.formatDateAndTime(msgDate))
             .append("\n");
         qtiChangelog.append(qtiChangeLog[i].getLogMessage());
         qtiChangelog.append("\n********************************\n");
       } // else non public messages are not shown to normal user
     }
   }
   return qtiChangelog;
 }
Ejemplo n.º 2
0
  /**
   * some old testing
   *
   * @param args
   */
  public static void main(String[] args) {
    System.out.println("hello");
    // log.debug(linePrepend("asdfsdf. bla and. \n2.line\n3.third",">"));
    // log.debug(escape("bla<>and so on &&\nsecond line").toString());

    System.out.println(":" + StringEscapeUtils.escapeHtml("abcdef&<>") + ":");
    System.out.println(":" + StringEscapeUtils.escapeHtml("&#256;<ba>abcdef&<>") + ":");
    System.out.println(":" + StringEscapeUtils.escapeHtml("&#256;\n<ba>\nabcdef&<>") + ":");

    System.out.println(":" + Formatter.truncate("abcdef", 0) + ":");
    System.out.println(":" + Formatter.truncate("abcdef", 2) + ":");
    System.out.println(":" + Formatter.truncate("abcdef", 4) + ":");
    System.out.println(":" + Formatter.truncate("abcdef", 6) + ":");
    System.out.println(":" + Formatter.truncate("abcdef", 7) + ":");
    System.out.println(":" + Formatter.truncate("abcdef", 8) + ":");

    System.out.println(":" + Formatter.truncate("abcdef", -2) + ":");
    System.out.println(":" + Formatter.truncate("abcdef", -4) + ":");
    System.out.println(":" + Formatter.truncate("abcdef", -6) + ":");
    System.out.println(":" + Formatter.truncate("abcdef", -7) + ":");
    System.out.println(":" + Formatter.truncate("abcdef", -8) + ":");

    Locale loc = new Locale("de");
    Formatter f2 = new Formatter(loc);
    Date d = new Date();
    Calendar cal = Calendar.getInstance(loc);
    cal.setTime(d);
    cal.add(Calendar.HOUR_OF_DAY, 7);
    // so ists 16:36 nachmittags
    d = cal.getTime();
    System.out.println(f2.formatDate(d));
    System.out.println(f2.formatTime(d));
    System.out.println(f2.formatDateAndTime(d));

    System.out.println("Now make String filesystem save");
    // String ugly = "\"/asdf/?._||\"blaöäü";
    String ugly = "guido/\\:? .|*\"\"<><guidoöäü";
    System.out.println("input: " + ugly);
    System.out.println("output: " + Formatter.makeStringFilesystemSave(ugly));
  }