Package org.apache.wicket.util.string

Examples of org.apache.wicket.util.string.AppendingStringBuffer


   *
   * @return javascript that opens the window
   */
  protected final String getWindowOpenJavaScript()
  {
    AppendingStringBuffer buffer = new AppendingStringBuffer(500);

    if (isCustomComponent() == true)
    {
      buffer.append("var element = document.getElementById(\"");
      buffer.append(getContentMarkupId());
      buffer.append("\");\n");
    }

    buffer.append("var settings = new Object();\n");

    appendAssignment(buffer, "settings.minWidth", getMinimalWidth());
    appendAssignment(buffer, "settings.minHeight", getMinimalHeight());
    appendAssignment(buffer, "settings.className", getCssClassName());
    appendAssignment(buffer, "settings.width", getInitialWidth());

    if ((isUseInitialHeight() == true) || (isCustomComponent() == false))
    {
      appendAssignment(buffer, "settings.height", getInitialHeight());
    }
    else
    {
      buffer.append("settings.height=null;\n");
    }

    appendAssignment(buffer, "settings.resizable", isResizable());

    if (isResizable() == false)
    {
      appendAssignment(buffer, "settings.widthUnit", getWidthUnit());
      appendAssignment(buffer, "settings.heightUnit", getHeightUnit());
    }

    if (isCustomComponent() == false)
    {
      Page page = createPage();
      if (page == null)
      {
        throw new WicketRuntimeException("Error creating page for modal dialog.");
      }
      CharSequence pageUrl;
      RequestCycle requestCycle = RequestCycle.get();

      if (page.isPageStateless())
      {
        pageUrl = requestCycle.urlFor(page.getClass(), page.getPageParameters());
      }
      else
      {
        IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
        pageUrl = requestCycle.urlFor(handler);
      }

      appendAssignment(buffer, "settings.src", pageUrl);
    }
    else
    {
      buffer.append("settings.element=element;\n");
    }

    if (getCookieName() != null)
    {
      appendAssignment(buffer, "settings.cookieId", getCookieName());
    }

    Object title = getTitle() != null ? getTitle().getObject() : null;
    if (title != null)
    {
      appendAssignment(buffer, "settings.title", escapeQuotes(title.toString()));
    }

    if (getMaskType() == MaskType.TRANSPARENT)
    {
      buffer.append("settings.mask=\"transparent\";\n");
    }
    else if (getMaskType() == MaskType.SEMI_TRANSPARENT)
    {
      buffer.append("settings.mask=\"semi-transparent\";\n");
    }

    appendAssignment(buffer, "settings.autoSize", autoSize);

    appendAssignment(buffer, "settings.unloadConfirmation", showUnloadConfirmation());

    // set true if we set a windowclosedcallback
    boolean haveCloseCallback = false;

    // in case user is interested in window close callback or we have a pagemap to clean attach
    // notification request
    if (windowClosedCallback != null)
    {
      WindowClosedBehavior behavior = getBehaviors(WindowClosedBehavior.class).get(0);
      buffer.append("settings.onClose = function() { ");
      buffer.append(behavior.getCallbackScript());
      buffer.append(" };\n");

      haveCloseCallback = true;
    }

    // in case we didn't set windowclosecallback, we need at least callback on close button, to
    // close window property (thus cleaning the shown flag)
    if ((closeButtonCallback != null) || (haveCloseCallback == false))
    {
      CloseButtonBehavior behavior = getBehaviors(CloseButtonBehavior.class).get(0);
      buffer.append("settings.onCloseButton = function() { ");
      buffer.append(behavior.getCallbackScript());
      buffer.append(";return false;};\n");
    }

    postProcessSettings(buffer);

    buffer.append(getShowJavaScript());
    return buffer.toString();
  }
View Full Code Here


   *            the Ajax {@link Response} body
   * @return filtered response
   */
  private AppendingStringBuffer invokeResponseFilters(final StringResponse contentResponse)
  {
    AppendingStringBuffer responseBuffer = new AppendingStringBuffer(
      contentResponse.getBuffer());

    List<IResponseFilter> responseFilters = Application.get()
      .getRequestCycleSettings()
      .getResponseFilters();
View Full Code Here

      return value;
    }

    if (resourceSettings.getThrowExceptionOnMissingResource())
    {
      AppendingStringBuffer message = new AppendingStringBuffer("Unable to find property: '");
      message.append(key);
      message.append("'");

      if (component != null)
      {
        message.append(" for component: ");
        message.append(component.getPageRelativePath());
        message.append(" [class=").append(component.getClass().getName()).append("]");
      }

      throw new MissingResourceException(message.toString(), (component != null
        ? component.getClass().getName() : ""), key);
    }

    return "[Warning: Property for '" + key + "' not found]";
  }
View Full Code Here

    }
  }

  private String createRequestData(RequestData rd, SessionData sd)
  {
    AppendingStringBuffer sb = new AppendingStringBuffer(150);

    sb.append("startTime=\"");
    sb.append(formatDate(rd.getStartDate()));
    sb.append("\",duration=");
    sb.append(rd.getTimeTaken());
    sb.append(",url=\"");
    sb.append(rd.getRequestedUrl());
    sb.append("\"");
    sb.append(",event={");
    sb.append(getRequestHandlerString(rd.getEventTarget()));
    sb.append("},response={");
    sb.append(getRequestHandlerString(rd.getResponseTarget()));
    sb.append("},sessionid=\"");
    sb.append(rd.getSessionId());
    sb.append("\"");
    sb.append(",sessionsize=");
    sb.append(rd.getSessionSize());
    if (rd.getSessionInfo() != null && !Strings.isEmpty(rd.getSessionInfo().toString()))
    {
      sb.append(",sessioninfo={");
      sb.append(rd.getSessionInfo());
      sb.append("}");
    }
    if (sd != null)
    {
      sb.append(",sessionstart=\"");
      sb.append(formatDate(sd.getStartDate()));
      sb.append("\",requests=");
      sb.append(sd.getNumberOfRequests());
      sb.append(",totaltime=");
      sb.append(sd.getTotalTimeTaken());
    }
    sb.append(",activerequests=");
    sb.append(rd.getActiveRequest());

    Runtime runtime = Runtime.getRuntime();
    long max = runtime.maxMemory() / 1000000;
    long total = runtime.totalMemory() / 1000000;
    long used = total - runtime.freeMemory() / 1000000;
    sb.append(",maxmem=");
    sb.append(max);
    sb.append("M,total=");
    sb.append(total);
    sb.append("M,used=");
    sb.append(used);
    sb.append("M");

    return sb.toString();
  }
View Full Code Here

    return sb.toString();
  }

  private String getRequestHandlerString(IRequestHandler handler)
  {
    AppendingStringBuffer sb = new AppendingStringBuffer(128);
    if (handler != null)
    {
      sb.append("handler=");
      sb.append(handler.getClass().isAnonymousClass() ? handler.getClass().getName()
        : handler.getClass().getSimpleName());
      if (handler instanceof ILoggableRequestHandler)
      {
        sb.append(",data=");
        sb.append(((ILoggableRequestHandler)handler).getLogData());
      }
    }
    else
    {
      sb.append("none");
    }
    return sb.toString();
  }
View Full Code Here

  private CharSequence getInitScript()
  {
    Map additionalSettings = new HashMap();
    appendSettings(additionalSettings);

    AppendingStringBuffer b = new AppendingStringBuffer();

    if (defaultDate != null)
    {
      Calendar calendar = Calendar.getInstance();
      calendar.setTime(defaultDate);

      b.append("\nvar defaultDate = new Date();");
      b.append("\ndefaultDate.setFullYear(").append(calendar.get(Calendar.YEAR)).append(");");
      b.append("\ndefaultDate.setDate(").append(calendar.get(Calendar.DAY_OF_MONTH)).append(
      ");");
      b.append("\ndefaultDate.setMonth(").append(calendar.get(Calendar.MONTH)).append(");");
      b.append("\ndefaultDate.setHours(").append(calendar.get(Calendar.HOUR_OF_DAY)).append(
          ");");
      b.append("\ndefaultDate.setMinutes(").append(calendar.get(Calendar.MINUTE)).append(
          ");\n");
    }

    b.append("\nCalendar.setup(\n{");

    // Append specific settings
    for (Iterator iter = additionalSettings.keySet().iterator(); iter.hasNext();)
    {
      String option = (String)iter.next();

      b.append("\n\t\t").append(option).append(" : ").append(additionalSettings.get(option))
          .append(",");
    }

    // Callbacks
    if (settings.getOnClose() != null)
    {
      b.append("\n\t\tonClose : ").append(onClose.getCallbackFunctionName()).append(",");
    }
    if (settings.getOnSelect() != null)
    {
      b.append("\n\t\tonSelect : ").append(onSelect.getCallbackFunctionName()).append(",");
    }
    if (settings.getOnUpdate() != null)
    {
      b.append("\n\t\tonUpdate : ").append(onUpdate.getCallbackFunctionName()).append(",");
    }

    if (defaultDate != null)
    {
      b.append("\n\t\tdate : defaultDate,");
    }

    String pattern = null;
    if (dateConverter == null)
    {
      dateConverter = getDateConverter();
    }
    DateFormat df = dateConverter.getDateFormat(getDatePickerLocale());
    if (df instanceof SimpleDateFormat)
    {
      pattern = ((SimpleDateFormat)df).toPattern();
    }
    b.append(settings.toScript(getDatePickerLocale(), pattern));

    int last = b.length() - 1;
    if (',' == b.charAt(last))
    {
      b.deleteCharAt(last);
    }
    b.append("\n});");
    return b;
  }
View Full Code Here

    protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
    {
      if (selectCallback != null)
      {
        AppendingStringBuffer b = new AppendingStringBuffer("\nfunction ");

        String functionName = getCallbackFunctionName();
        b.append(functionName).append("(calendar){\n");
        b.append("\tvar dateParam = calendar.date.getFullYear();\n");
        b.append("\tdateParam += '-';\n");
        b.append("\tdateParam += calendar.date.getMonth()+1;\n");
        b.append("\tdateParam += '-';\n");
        b.append("\tdateParam += calendar.date.getDate();\n");
        b.append("\tdateParam += '-';\n");
        b.append("\tdateParam += calendar.date.getHours();\n");
        b.append("\tdateParam += '-';\n");
        b.append("\tdateParam += calendar.date.getMinutes();\n");

        CharSequence handleCallback = selectCallback.handleCallback();
        b.append("\t").append(handleCallback).append("\n");
        b.append("}\n");

        replaceComponentTagBody(markupStream, openTag, b);
      }
    }
View Full Code Here

        {
          private static final long serialVersionUID = 1L;

          public CharSequence decorateScript(CharSequence script)
          {
            AppendingStringBuffer b = new AppendingStringBuffer();

            Matcher mat = ajaxScriptPattern.matcher(script);
            if (mat.matches())
            {
              String url = mat.group(1);
              String newUrl = url + "&dateParam='+dateParam+'";
              b.append(Strings.replaceAll(script, url, newUrl));
            }
            else
            {
              throw new WicketRuntimeException("Internal error in Wicket");
            }
View Full Code Here

          private static final long serialVersionUID = 1L;

                    @Override
          public CharSequence decorateScript(CharSequence script)
          {
            AppendingStringBuffer b = new AppendingStringBuffer();

            Matcher mat = ajaxScriptPattern.matcher(script);
            if (mat.matches())
            {
              String url = mat.group(1);
              String newUrl = url + "&dateParam='+dateParam+'";
              b.append(Strings.replaceAll(script, url, newUrl));
            }
            else
            {
              throw new WicketRuntimeException("Internal error in Wicket");
            }
View Full Code Here

  private CharSequence getInitScript()
  {
    Map<String, String> additionalSettings = new HashMap<String, String>();
    appendSettings(additionalSettings);

    AppendingStringBuffer b = new AppendingStringBuffer();

    if (defaultDate != null)
    {
      Calendar calendar = Calendar.getInstance();
      calendar.setTime(defaultDate);

      b.append("\nvar defaultDate = new Date();");
      b.append("\ndefaultDate.setFullYear(").append(calendar.get(Calendar.YEAR)).append(");");
      b.append("\ndefaultDate.setDate(").append(calendar.get(Calendar.DAY_OF_MONTH)).append(
      ");");
      b.append("\ndefaultDate.setMonth(").append(calendar.get(Calendar.MONTH)).append(");");
      b.append("\ndefaultDate.setHours(").append(calendar.get(Calendar.HOUR_OF_DAY)).append(
          ");");
      b.append("\ndefaultDate.setMinutes(").append(calendar.get(Calendar.MINUTE)).append(
          ");\n");
    }

    b.append("\nCalendar.setup(\n{");

    // Append specific settings
    for (Iterator iter = additionalSettings.keySet().iterator(); iter.hasNext();)
    {
      String option = (String)iter.next();

      b.append("\n\t\t").append(option).append(" : ").append(additionalSettings.get(option))
          .append(",");
    }

    // Callbacks
    if (settings.getOnClose() != null)
    {
      b.append("\n\t\tonClose : ").append(onClose.getCallbackFunctionName()).append(",");
    }
    if (settings.getOnSelect() != null)
    {
      b.append("\n\t\tonSelect : ").append(onSelect.getCallbackFunctionName()).append(",");
    }
    if (settings.getOnUpdate() != null)
    {
      b.append("\n\t\tonUpdate : ").append(onUpdate.getCallbackFunctionName()).append(",");
    }

    if (defaultDate != null)
    {
      b.append("\n\t\tdate : defaultDate,");
    }

    String pattern = null;
    if (dateConverter == null)
    {
      dateConverter = getDateConverter();
    }
    DateFormat df = dateConverter.getDateFormat(getDatePickerLocale());
    if (df instanceof SimpleDateFormat)
    {
      pattern = ((SimpleDateFormat)df).toPattern();
    }
    b.append(settings.toScript(getDatePickerLocale(), pattern));

    int last = b.length() - 1;
    if (',' == b.charAt(last))
    {
      b.deleteCharAt(last);
    }
    b.append("\n});");
    return b;
  }
View Full Code Here

TOP

Related Classes of org.apache.wicket.util.string.AppendingStringBuffer

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.