Package org.olat.core.util

Examples of org.olat.core.util.Formatter


  }


  private String getPlaintextContent(Locale locale) {
    Translator trans = Util.createPackageTranslator(SubscriptionInfo.class, locale);
    Formatter form = Formatter.getInstance(locale);
    StringBuilder sb = new StringBuilder();
    String datePart = trans.translate("subscription.listitem.dateprefix", new String [] { form.formatDateAndTime(date) } ) ;
    sb.append("- ");
    sb.append(description.trim());
    sb.append(" ").append(datePart.trim());
    if (StringHelper.containsNonWhitespace(link)) sb.append("\n").append("  ").append(link);
    return sb.toString();
View Full Code Here


  }

  private String getHTMLContent(Locale locale) {
    StringBuilder sb = new StringBuilder();
    Translator trans = Util.createPackageTranslator(SubscriptionInfo.class, locale);
    Formatter form = Formatter.getInstance(locale);
    String datePart = trans.translate("subscription.listitem.dateprefix", new String [] { form.formatDateAndTime(date) } ) ;
    if (iconCssClass != null) {
      sb.append("<li class=\"b_with_small_icon_left ");
      sb.append(iconCssClass);
      sb.append("\">");
    } else {
View Full Code Here

        sb.append("<span class=\"b_form_datechooser\" id=\"trigger_").append(textElement.getName()).append("\" title=\"").append(StringEscapeUtils.escapeHtml(f.getTranslator().translate("calendar.choose"))).append("\">&nbsp;</span>");
        // date chooser javascript
        sb.append("<script type=\"text/javascript\">").append("Calendar.setup({").append("inputField:\"").append(textElement.getName()).append("\",").append("ifFormat:\"");
        if (textElement.getDateChooserDateFormat() == null) {
          // use default format from default locale file
          Formatter formatter = Formatter.getInstance(f.getTranslator().getLocale());
          if (textElement.isDateChooserTimeEnabled()) sb.append(formatter.getSimpleDatePatternForDateAndTime());
          else sb.append(formatter.getSimpleDatePatternForDate());

        } else {
          // use custom date format
          sb.append(textElement.getDateChooserDateFormat());
        }
View Full Code Here

    // the idea is that at this stage the throwable still contains a stacktrace but passed into the OLATRuntimeException
    // below as the cause it somehow gets lost. If this does not turn out to be true then the line below can be removed.
    // in any case, it is just a log.warn
    Tracing.logWarn("ExceptionWindowController<init>: Throwable occurred, logging the full stacktrace:", th, getClass());
    Translator trans = new PackageTranslator(PACKAGE, ureq.getLocale());
    Formatter formatter = Formatter.getInstance(ureq.getLocale());
    msg = new VelocityContainer("olatmain", VELOCITY_ROOT + "/exception_page.html", trans, this);
    // disallow wrapping of divs around the panel and the main velocity page
    // (since it contains the "<html><head... intro of the html page,
    // and thus has better to be replaced as a whole (new page load) instead of
    // a dom replacement)
    msg.setDomReplaceable(false);
   
    Version v = (Version) CoreSpringFactory.getBean("org.olat.core.Version");
    msg.contextPut("buildversion", v.getVersion());

    OLATRuntimeException o3e;
   
    if (th == null){
      o3e = new OLATRuntimeException("Error Screen with a Throwable == null", null);
    } else if (!(th instanceof OLATRuntimeException)) {
      o3e = new OLATRuntimeException(th.getMessage(), th);
    } else {
      o3e = (OLATRuntimeException) th;
    }

    String detailedmessage = null;
    // translate user message if available
    if (o3e.getUsrMsgKey() != null && o3e.getUsrMsgPackage() != null) {
      PackageTranslator usrMsgTrans = new PackageTranslator(o3e.getUsrMsgPackage(), ureq.getLocale());
      if (o3e.getUsrMsgArgs() == null) {
        detailedmessage = usrMsgTrans.translate(o3e.getUsrMsgKey());
      } else {
        detailedmessage = usrMsgTrans.translate(o3e.getUsrMsgKey(), o3e.getUsrMsgArgs());
      }
    }
    // fix detailed message
    if (detailedmessage == null) {
      if (o3e instanceof StaleObjectRuntimeException) {
        StaleObjectRuntimeException soe = (StaleObjectRuntimeException) o3e;
        detailedmessage = trans.translate("error.staleobjectexception") + "<br />(" + soe.getKey() + " : " + soe.getPersClassName() + ")";
      }
      else detailedmessage = "-";
    }

    // fetch more info
    // get the latest window which caused this exception
    String componentListenerInfo = "";
    Windows ws = Windows.getWindows(ureq);
   
    Window window = ws.getWindow(ureq);
    if (window != null) {
      Component target = window.getAndClearLatestDispatchedComponent();
      if (target != null) {
        // there was a component id given, and a matching target could be found
        componentListenerInfo = "<dispatchinfo>\n\t<componentinfo>\n\t\t<compname>" + target.getComponentName() + "</compname>\n\t\t<compclass>"
            + target.getClass().getName() + "</compclass>\n\t\t<extendedinfo>" + target.getExtendedDebugInfo()
            + "</extendedinfo>\n\t\t<event>";
        Event latestEv = target.getAndClearLatestFiredEvent();
        if (latestEv != null) {
          componentListenerInfo += "\n\t\t\t<class>"+latestEv.getClass().getName()+"</class>\n\t\t\t<command>"+latestEv.getCommand()+"</command>\n\t\t\t<tostring>"+latestEv+"</tostring>";
        }
        componentListenerInfo += "\n\t\t</event>\n\t</componentinfo>\n\t<controllerinfo>";
        Controller c = target.getLatestDispatchedController();
        if (c != null) {
          // can be null if the error occured in the component itself
          // componentListenerInfo += c.toString();
          //WindowControl control = c.getWindowControl();
          // sorry, getting windowcontrol on a controller which does not have one (all should have one, legacy) throws an exception
          try {
           
            WindowControlInfo wci = c.getWindowControlForDebug().getWindowControlInfo();
            while (wci != null) {
              String cName = wci.getControllerClassName();
              componentListenerInfo += "\n\t\t<controllername>" + cName + "</controllername>";
              wci = wci.getParentWindowControlInfo();
            }
          } catch (Exception e) {
            componentListenerInfo += "no info, probably no windowcontrol set: "+e.getClass().getName()+", "+e.getMessage();
          }
        }
        componentListenerInfo += "\n\t</controllerinfo>\n</dispatchinfo>";
      }
    }

    if(o3e instanceof KnownIssueException){
      KnownIssueException kie = (KnownIssueException)o3e;
      msg.contextPut("knownissuelink", kie.getJiraLink());
    }
   
    // TODO: DB.getInstance().hasTransaction() TODO: log db transaction id if in
    // transaction
    long refNum = Tracing.logError("**RedScreen** "+o3e.getLogMsg() + " ::_::" + componentListenerInfo + " ::_::", o3e, o3e.getThrowingClazz());
    // only if debug
    if (Settings.isDebuging()) {
      msg.contextPut("debug", Boolean.TRUE);
    } else {
      msg.contextPut("debug", Boolean.FALSE);     
    }
    msg.contextPut("listenerInfo", Formatter.escWithBR(componentListenerInfo).toString());     
    msg.contextPut("stacktrace", OLATRuntimeException.throwableToHtml(th));     
   
    Identity curIdent = ureq.getIdentity();
    msg.contextPut("username", curIdent == null? "n/a" : curIdent.getName());
    msg.contextPut("allowBackButton", Boolean.valueOf(allowBackButton));
    msg.contextPut("detailedmessage", detailedmessage);
    // Cluster NodeId + E-Nr
    msg.contextPut("errnum", "N" + CoordinatorManager.getCoordinator().getNodeId() + "-E"+ refNum);
    msg.contextPut("supportaddress", WebappHelper.getMailConfig("mailSupport"));
    msg.contextPut("time", formatter.formatDateAndTime(new Date()));

    WindowBackOffice wbo = ws.getWindowManager().createWindowBackOffice("errormessagewindow", this);
    Window w = wbo.getWindow();
   
    msg.put("jsCssRawHtmlHeader", w.getJsCssRawHtmlHeader());   
View Full Code Here

   * @param cellValue
   * @param translator
   */ 
  public void render(StringOutput target, Object cellValue, Translator translator) {
    if (cellValue instanceof Date) {
      Formatter formatter = Formatter.getInstance(translator.getLocale());
      target.append( formatter.formatDateAndTime((Date)cellValue) );
    } else {
      target.append( cellValue.toString() );
    }
  }
View Full Code Here

      content.append("<script type=\"text/javascript\">\n /* <![CDATA[ */ \n").append("Calendar.setup({").append("inputField:\"").append(receiverId).append("\",")
          .append("ifFormat:\"");
      if (jsdcc.getDateChooserDateFormat() == null) {
        // use default format from default locale file

        Formatter formatter = Formatter.getInstance(translator.getLocale());
        if (jsdcc.isDateChooserTimeEnabled()) content.append(formatter.getSimpleDatePatternForDateAndTime());
        else content.append(formatter.getSimpleDatePatternForDate());

      } else {
        // use custom date format
        content.append(jsdcc.getDateChooserDateFormat());
      }
View Full Code Here

   
    // information about the cluster nodes
    mainVc.contextPut("own_nodeid", "This node is node: '"+clusBus.clusterConfig.getNodeId()+"'");
   
    nodeInfoVc = createVelocityContainer("nodeinfos");
    Formatter f = Formatter.getInstance(ureq.getLocale());
    nodeInfoVc.contextPut("f", f);
    mainVc.put("nodeinfos", nodeInfoVc);
    updateNodeInfos();
   
    toggleStartStop = LinkFactory.createButtonSmall("toggleStartStop", mainVc, this);
    resetStats = LinkFactory.createButtonSmall("resetStats", mainVc, this);

    perfInfoVc = createVelocityContainer("performanceinfos");
    Formatter f2 = Formatter.getInstance(ureq.getLocale());
    perfInfoVc.contextPut("f", f2);
    mainVc.put("performanceinfos", perfInfoVc);
    updatePerfInfos();
   
    // test for the distributed cache
View Full Code Here

    StringBuilder sb = new StringBuilder();
    int ucCnt = UserSession.getUserSessionsCnt();
    Set usesss = UserSession.getAuthenticatedUserSessions();
    int contcnt = DefaultController.getControllerCount();
    sb.append("total usersessions (auth and non auth): "+ucCnt+"<br />auth usersessions: "+usesss.size()+"<br />Total Controllers (active, not disposed) of all users:"+contcnt+"<br /><br />");
    Formatter f = Formatter.getInstance(ureq.getLocale());
    for (Iterator iter = usesss.iterator(); iter.hasNext();) {
      UserSession usess = (UserSession) iter.next();
      Identity iden = usess.getIdentity();
      sb.append("authusersession (").append(usess.hashCode()).append(") of ");
      if (iden != null) {
View Full Code Here

    final int MAX_RESULTS = 5;
    ArrayList<WikiPage> pages = new ArrayList<WikiPage>(wikiPages.values());
    Collections.sort(pages, WikiPageSort.MODTIME_ORDER);
    StringBuilder sb = new StringBuilder();
    int counter = 0;
    Formatter f = Formatter.getInstance(locale);
    for (Iterator<WikiPage> iter = pages.iterator(); iter.hasNext();) {
      if (counter > MAX_RESULTS) break;
      WikiPage page = iter.next();
      if (!page.getPageName().startsWith("O_") && !page.getPageName().startsWith(WikiPage.WIKI_MENU_PAGE)) {
        sb.append("* [[");
        sb.append(page.getPageName());
        sb.append("]] ");
        sb.append(f.formatDateAndTime(new Date(page.getModificationTime())));
        sb.append(" Author: ");
        long author = page.getModifyAuthor();
        if (author != 0) sb.append(ManagerFactory.getManager().loadIdentityByKey(Long.valueOf(page.getModifyAuthor())).getName());
        sb.append("\n");
        counter++;
View Full Code Here

    sb.append("<h4>");
    sb.append(ac.getTitle());
    sb.append("</h4>");

    // append assessment navigation
    Formatter formatter = Formatter.getInstance(translator.getLocale());
    int scnt = ac.getSectionContextCount();
    for (int i = 0; i < scnt; i++) {
      SectionContext sc = ac.getSectionContext(i);
      boolean clickable = (ai.isSectionPage() && sc.isOpen()) || (!ai.isSectionPage());
      clickable = clickable && !ai.isClosed();
View Full Code Here

TOP

Related Classes of org.olat.core.util.Formatter

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.