Package org.apache.wicket.util.string

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


    {
      // get the hidden field id
      String nameAndId = getHiddenFieldId();

      // render the hidden field
      AppendingStringBuffer buffer = new AppendingStringBuffer(HIDDEN_DIV_START).append(
        "<input type=\"hidden\" name=\"")
        .append(nameAndId)
        .append("\" id=\"")
        .append(nameAndId)
        .append("\" />");

      // if it's a get, did put the parameters in the action attribute,
      // and have to write the url parameters as hidden fields
      if (encodeUrlInHiddenFields())
      {
        String url = getActionUrl().toString();
        int i = url.indexOf('?');
        String queryString = (i > -1) ? url.substring(i + 1) : url;
        String[] params = Strings.split(queryString, '&');

        writeParamsAsHiddenFields(params, buffer);
      }
      buffer.append("</div>");
      getResponse().write(buffer);

      // if a default submitting component was set, handle the rendering of that
      if (defaultSubmittingComponent instanceof Component)
      {
View Full Code Here


          int offsetMins = (int)(Double.parseDouble(hourPart) * 6);

          // construct a GMT timezone offset string from the retrieved
          // offset which can be parsed by the TimeZone class.

          AppendingStringBuffer sb = new AppendingStringBuffer("GMT");
          sb.append(offsetHours > 0 ? '+' : '-');
          sb.append(Math.abs(offsetHours));
          sb.append(':');
          if (offsetMins < 10)
          {
            sb.append('0');
          }
          sb.append(offsetMins);
          timeZone = TimeZone.getTimeZone(sb.toString());
        }
        else
        {
          int offset = Integer.parseInt(utc);
          if (offset < 0)
          {
            utc = utc.substring(1);
          }
          timeZone = TimeZone.getTimeZone("GMT" + ((offset > 0) ? '+' : '-') + utc);
        }

        String dstOffset = getUtcDSTOffset();
        if (timeZone != null && dstOffset != null)
        {
          TimeZone dstTimeZone;
          dotPos = dstOffset.indexOf('.');
          if (dotPos >= 0)
          {
            String hours = dstOffset.substring(0, dotPos);
            String hourPart = dstOffset.substring(dotPos + 1);

            if (hours.startsWith("+"))
            {
              hours = hours.substring(1);
            }
            int offsetHours = Integer.parseInt(hours);
            int offsetMins = (int)(Double.parseDouble(hourPart) * 6);

            // construct a GMT timezone offset string from the
            // retrieved
            // offset which can be parsed by the TimeZone class.

            AppendingStringBuffer sb = new AppendingStringBuffer("GMT");
            sb.append(offsetHours > 0 ? '+' : '-');
            sb.append(Math.abs(offsetHours));
            sb.append(':');
            if (offsetMins < 10)
            {
              sb.append('0');
            }
            sb.append(offsetMins);
            dstTimeZone = TimeZone.getTimeZone(sb.toString());
          }
          else
          {
            int offset = Integer.parseInt(dstOffset);
            if (offset < 0)
View Full Code Here

   * @see FormComponent#getModelValue()
   */
  @Override
  public final String getModelValue()
  {
    final AppendingStringBuffer buffer = new AppendingStringBuffer();

    final Collection<T> selectedValues = getModelObject();
    if (selectedValues != null)
    {
      final List<? extends T> choices = getChoices();
      for (T object : selectedValues)
      {
        if (buffer.length() > 0)
        {
          buffer.append(VALUE_SEPARATOR);
        }
        int index = choices.indexOf(object);
        buffer.append(getChoiceRenderer().getIdValue(object, index));
      }
    }

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

   */
  @Override
  public void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag)
  {
    List<? extends E> choices = getChoices();
    final AppendingStringBuffer buffer = new AppendingStringBuffer((choices.size() * 50) + 16);
    final String selectedValue = getValue();

    // Append default option
    buffer.append(getDefaultChoice(selectedValue));

    for (int index = 0; index < choices.size(); index++)
    {
      final E choice = choices.get(index);
      appendOptionHtml(buffer, choice, index, selectedValue);
    }

    buffer.append('\n');
    replaceComponentTagBody(markupStream, openTag, buffer);
  }
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

  {
    // Iterate through choices
    final List<? extends T> choices = getChoices();

    // Buffer to hold generated body
    final AppendingStringBuffer buffer = new AppendingStringBuffer((choices.size() + 1) * 70);

    // The selected value
    final String selected = getValue();

    // Loop through choices
View Full Code Here

    return sb.toString();
  }

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

   *
   * @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();

      page.getSession().getPageManager().touchPage(page);
      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

   * @return String
   */
  @Override
  public final String toString(final boolean markupOnly)
  {
    final AppendingStringBuffer buf = new AppendingStringBuffer(400);

    if (markupOnly == false)
    {
      if (markupResourceStream != null)
      {
        buf.append(markupResourceStream.toString());
      }
      else
      {
        buf.append("null MarkupResouceStream");
      }
      buf.append("\n");
    }

    if (markupElements != null)
    {
      for (MarkupElement markupElement : markupElements)
      {
        buf.append(markupElement);
      }
    }

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

   * @return The javascript
   */
  private String getElementsDeleteJavaScript()
  {
    // build the javascript call
    final AppendingStringBuffer buffer = new AppendingStringBuffer(100);

    buffer.append("Wicket.Tree.removeNodes(\"");

    // first parameter is the markup id of tree (will be used as prefix to
    // build ids of child items
    buffer.append(getMarkupId() + "_\",[");

    // append the ids of elements to be deleted
    buffer.append(deleteIds);

    // does the buffer end if ','?
    if (buffer.endsWith(","))
    {
      // it does, trim it
      buffer.setLength(buffer.length() - 1);
    }

    buffer.append("]);");

    return buffer.toString();
  }
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.