Exemple #1
0
  /**
   * renders wiki markup like _italic_ to XHTML see also www.radeox.org @Deprecated The wiki markup
   * area is no longer supported. In the legacy form infrastructure it's still there, but it won't
   * be available in the new flexi forms. In flexi forms use the RichTextElement instead. tested
   * during migration and expanded to prevent radeox failures
   *
   * @param originalText
   * @return result (rendered originalText) or null if originalText was null
   */
  @Deprecated
  public static String formatWikiMarkup(String oldValue) {
    if (oldValue != null) {
      String newValue = "";
      // oldValue = oldValue.replaceAll("<>", "&lt;&gt;");
      // oldValue = oldValue.replaceAll(Pattern.quote("[]"),
      // "&#91;&#93;");

      // prevent error with {$} interpreted as regexp
      String marker1 = "piYie6Eigh0phafeiTuk4dahwahvoh7eedoegee2egh8xuj9phah8eop8iuk";
      oldValue = oldValue.replaceAll(Pattern.quote("{$}"), marker1);

      // \{code} will result in an error => convert
      String marker2 = "RohbaeW7xahbohk8iewoo7thocaemaech2pahS8oe1UVohkohJiugaagaeco";
      oldValue = oldValue.replaceAll(Pattern.quote("\\{code}"), marker2);

      // radeox gets an error, if {code} is not a closed tag. prevent at
      // least the case with one single statement.
      int nrOfCodeStatements = countOccurrences(oldValue, "{code}");
      String marker3 = "shagheiph6enieNo0theph9aique0EihoChae6ve2edie4Pohwaok8thaoda";
      if (nrOfCodeStatements == 1) {
        oldValue = oldValue.replaceAll(Pattern.quote("{code}"), marker3);
      }
      if (nrOfCodeStatements % 2 != 0 && nrOfCodeStatements != 1) {
        Formatter fInst = Formatter.getInstance(new Locale("olat"));
        fInst.log(
            "There will be a Warning/NPE from Radeox soon, as there are not enough {code} statements in a text.");
        fInst.log("Old value of text will be kept! " + oldValue);
      }

      // added for compatibility with wikimedia syntax used in the new wiki component.
      // WikiMarkupComponent
      // filters " ''' " for bold and " ''''' " for bold/italic
      oldValue =
          oldValue.replaceAll(
              "(^|>|[\\p{Punct}\\p{Space}]+)'{3}(.*?)'{3}([\\p{Punct}\\p{Space}]+|<|$)",
              "$1*$2*$3");
      oldValue =
          oldValue.replaceAll(
              "(^|>|[\\p{Punct}\\p{Space}]+)'{5}(.*?)'{5}([\\p{Punct}\\p{Space}]+|<|$)",
              "$1_*$2*_$3");

      // try-catch not usable, as Radeox doesn't throw an exception,
      // it just prints warnings and returns unconverted value!
      newValue = engineWithContext.render(oldValue, baseRenderContext);

      // convert back
      newValue = newValue.replaceAll(marker1, Matcher.quoteReplacement("{$}"));
      newValue = newValue.replaceAll(marker2, Matcher.quoteReplacement("\\{code}"));
      newValue = newValue.replaceAll(marker3, Matcher.quoteReplacement("{code}"));

      return newValue;
    } else return null;
  }
Exemple #2
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;
 }
  /** writes content of all results to a file */
  private String writeContentToFile(
      final String shortTitle,
      final File exportDirectory,
      final String charset,
      final QTIExportFormatter qef,
      final String fileNameSuffix) {
    // defining target filename
    final StringBuilder tf = new StringBuilder();
    tf.append(qef.getFileNamePrefix());
    tf.append(Formatter.makeStringFilesystemSave(shortTitle));
    tf.append("_");
    final DateFormat myformat = new SimpleDateFormat("yyyy-MM-dd__hh-mm-ss__SSS");
    final String timestamp = myformat.format(new Date());
    tf.append(timestamp);
    tf.append(fileNameSuffix);
    final String targetFileName = tf.toString();

    ExportUtil.writeContentToFile(targetFileName, qef.getReport(), exportDirectory, charset);

    return targetFileName;
  }
Exemple #4
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));
  }