/**
   * Constructor.
   *
   * @param id
   * @param inputComponent
   * @param labelModel optional
   * @param helpModel optional
   */
  public InputBorder(
      final String id,
      final FormComponent<T> inputComponent,
      final IModel<String> labelModel,
      final IModel<String> helpModel) {
    super(id);

    Args.notNull(labelModel, "labelModel");
    Args.notNull(helpModel, "helpModel");

    // set html id so that this border can be refreshed by ajax
    this.setOutputMarkupId(true);

    // add the form component to the border
    this.inputComponent = inputComponent;
    add(this.inputComponent);

    // add the label
    WebMarkupContainer labelContainer = new WebMarkupContainer(labelContainerID);
    Label label = new Label(labelID, labelModel);
    label.setEscapeModelStrings(false);
    labelContainer.add(new AttributeModifier("for", Model.of(inputComponent.getMarkupId())));
    labelContainer.add(label);
    addToBorder(labelContainer);

    // add the help label
    addToBorder(new Label(helpID, helpModel).setEscapeModelStrings(false));

    // add the feedback panel with filter so that it only shows messages
    // relevant for this input component
    this.feedback = new FeedbackPanel(feedbackPanelID, new ContainerFeedbackMessageFilter(this));
    addToBorder(this.feedback.setOutputMarkupId(true));
  }
示例#2
0
文件: ViewLabel.java 项目: msroga/ftt
 public ViewLabel(String id, IValuesFormatter valuesFormatter, IModel... models) {
   super(id);
   Args.notNull(models, "models");
   Args.notNull(valuesFormatter, "valuesFormatter");
   this.models = models;
   this.valuesFormatter = valuesFormatter;
 }
  /**
   * Construct.
   *
   * @param packageName
   * @param pageParametersEncoder
   */
  public PackageMapper(
      final PackageName packageName, final IPageParametersEncoder pageParametersEncoder) {
    Args.notNull(packageName, "packageName");
    Args.notNull(pageParametersEncoder, "pageParametersEncoder");

    this.packageName = packageName;
    this.pageParametersEncoder = pageParametersEncoder;
  }
示例#4
0
  /**
   * Return this value as en enum value.
   *
   * @param enumClass the enum type
   * @return an enum value
   */
  public static <T extends Enum<T>> T toEnum(final CharSequence value, final Class<T> enumClass) {
    Args.notNull(enumClass, "enumClass");
    Args.notNull(value, "value");

    try {
      return Enum.valueOf(enumClass, value.toString());
    } catch (Exception e) {
      throw new StringValueConversionException(
          String.format("Cannot convert '{}' to enum constant of type '{}'.", value, enumClass), e);
    }
  }
示例#5
0
  @Override
  public final void addChildren(MarkupContainer parent, Class<?> childCriteria) {
    Args.notNull(parent, "parent");
    Args.notNull(childCriteria, "childCriteria");

    parent.visitChildren(
        childCriteria,
        new IVisitor<Component, Void>() {
          @Override
          public void component(final Component component, final IVisit<Void> visit) {
            add(component);
            visit.dontGoDeeper();
          }
        });
  }
示例#6
0
 @Override
 public final void reuseStategyNotSupportedForItemsNavigation(IQuickView quickView) {
   Args.notNull(quickView, "quickview");
   if (!quickView.getReuseStrategy().isAddItemsSupported()) {
     throw new ReuseStrategyNotSupportedException(" stategy is not supported for itemsnavigator ");
   }
 }
示例#7
0
  /**
   * Construct.
   *
   * @param context
   */
  public RequestCycle(RequestCycleContext context) {
    Args.notNull(context, "context");
    Args.notNull(context.getRequest(), "context.request");
    Args.notNull(context.getResponse(), "context.response");
    Args.notNull(context.getRequestMapper(), "context.requestMapper");
    Args.notNull(context.getExceptionMapper(), "context.exceptionMapper");

    listeners = new RequestCycleListenerCollection();
    startTime = System.currentTimeMillis();
    requestHandlerExecutor = new HandlerExecutor();
    activeResponse = context.getResponse();
    request = context.getRequest();
    originalResponse = context.getResponse();
    requestMapper = context.getRequestMapper();
    exceptionMapper = context.getExceptionMapper();
  }
示例#8
0
  /**
   * Construct.
   *
   * @param event the event this behavior will be attached to
   */
  public AjaxEventBehavior(String event) {
    Args.notEmpty(event, "event");

    onCheckEvent(event);

    this.event = event;
  }
示例#9
0
  /**
   * Adds a behavior to this component tag.
   *
   * @param behavior
   */
  public final void addBehavior(final Behavior behavior) {
    Args.notNull(behavior, "behavior");

    if (behaviors == null) {
      behaviors = Generics.newArrayList();
    }
    behaviors.add(behavior);
  }
示例#10
0
  /**
   * replaces the version string "current" with the recent available version
   *
   * @param path the full resource path
   */
  public static String useRecent(final String path) {
    Args.notEmpty(path, "path");

    if (path.matches("/webjars/[^/]*/current/.*")) {
      return path.replaceFirst("/current/", "/" + recentVersion(path) + "/");
    }

    return path;
  }
  /**
   * Main constructor that takes in input the object serializer/deserializer and the role-checking
   * strategy to use.
   *
   * @param serialDeserial General class that is used to serialize/desiarilze objects to string
   * @param roleCheckingStrategy the role-checking strategy.
   */
  public AbstractRestResource(T serialDeserial, IRoleCheckingStrategy roleCheckingStrategy) {
    Args.notNull(serialDeserial, "serialDeserial");

    this.objSerialDeserial = serialDeserial;
    this.roleCheckingStrategy = roleCheckingStrategy;

    configureObjSerialDeserial(serialDeserial);
    loadAnnotatedMethods();
  }
示例#12
0
 /** {@inheritDoc} */
 @Override
 public final void outPutMarkupIdNotTrue(IQuickView quickView) {
   Args.notNull(quickView, "quickview");
   MarkupContainer container = quickView.getParent();
   if (container.getOutputMarkupId() == false
       && container.getOutputMarkupPlaceholderTag() == false) {
     throw new OutputMarkupIdNotTrueException("parent doesn't have setOutputMarkupId to true");
   }
 }
  /**
   * Constructor
   *
   * @param selector the html selector (ie: "#myId")
   * @param method the jquery method
   * @param options the {@link Options}
   */
  public JQueryBehavior(String selector, String method, Options options) {
    super(method);

    Args.notNull(options, "options");

    this.method = method;
    this.options = options;
    this.selector = selector;
  }
示例#14
0
 protected void encodePageComponentInfo(Url url, PageComponentInfo info) {
   Args.notNull(url, "url");
   if (info != null && Session.exists() && !Session.get().isSessionInvalidated()) {
     String s = info.toString();
     if (!Strings.isEmpty(s)) {
       QueryParameter parameter = new QueryParameter(s, "");
       url.getQueryParameters().add(parameter);
     }
   }
 }
  public static AttributeAppender prepend(final String attributeName, final IModel<?> value) {
    Args.notEmpty((CharSequence) attributeName, "attributeName");
    return new AttributeAppender(attributeName, value) {
      private static final long serialVersionUID = 1L;

      protected String newValue(final String currentValue, final String replacementValue) {
        return super.newValue(replacementValue, currentValue);
      }
    }.setSeparator(" ");
  }
示例#16
0
  // Data Reading
  public User getUserByUsername(String uname) {
    Args.notNull(uname, "Name");
    String password = cassandra.readColumn(uname, "password", USERS);

    if (null == password || password.equals("")) {
      return null;
    }

    return new User(uname.getBytes(), password);
  }
示例#17
0
  /**
   * Constructor
   *
   * @param page the currently active page
   */
  public AjaxRequestHandler(final Page page) {
    this.page = Args.notNull(page, "page");

    update =
        new XmlPartialPageUpdate(page) {
          /**
           * Freezes the {@link AjaxRequestHandler#listeners} before firing the event and un-freezes
           * them afterwards to allow components to add more {@link AjaxRequestTarget.IListener}s
           * for the second event.
           */
          @Override
          protected void onBeforeRespond(final Response response) {
            listenersFrozen = true;

            if (listeners != null) {
              for (AjaxRequestTarget.IListener listener : listeners) {
                listener.onBeforeRespond(markupIdToComponent, AjaxRequestHandler.this);
              }
            }

            listenersFrozen = false;
          }

          /**
           * Freezes the {@link AjaxRequestHandler#listeners}, and does not un-freeze them as the
           * events will have been fired by now.
           *
           * @param response the response to write to
           */
          @Override
          protected void onAfterRespond(final Response response) {
            listenersFrozen = true;

            // invoke onafterresponse event on listeners
            if (listeners != null) {
              final Map<String, Component> components =
                  Collections.unmodifiableMap(markupIdToComponent);

              // create response that will be used by listeners to append
              // javascript
              final AjaxRequestTarget.IJavaScriptResponse jsresponse =
                  new AjaxRequestTarget.IJavaScriptResponse() {
                    @Override
                    public void addJavaScript(String script) {
                      writeNormalEvaluations(response, Collections.<CharSequence>singleton(script));
                    }
                  };

              for (AjaxRequestTarget.IListener listener : listeners) {
                listener.onAfterRespond(components, jsresponse);
              }
            }
          }
        };
  }
示例#18
0
  /**
   * convert byte array to hex string
   *
   * @param bytes bytes to convert to hexadecimal representation
   * @return hex string
   */
  public static String toHexString(byte[] bytes) {
    Args.notNull(bytes, "bytes");

    final StringBuilder hex = new StringBuilder(bytes.length << 1);

    for (final byte b : bytes) {
      hex.append(toHex(b >> 4));
      hex.append(toHex(b));
    }
    return hex.toString();
  }
示例#19
0
  /**
   * Note that this method will be called from a "cleanup" thread which might not have a thread
   * local application.
   */
  @Override
  public final IMarkupFragment removeMarkup(final String cacheKey) {
    Args.notNull(cacheKey, "cacheKey");

    if (log.isDebugEnabled()) {
      log.debug("Removing from cache: " + cacheKey);
    }

    // Remove the markup from the cache
    String locationString = markupKeyCache.get(cacheKey);
    IMarkupFragment markup = (locationString != null ? markupCache.get(locationString) : null);
    if (markup == null) {
      return null;
    }

    // Found an entry: actual markup or Markup.NO_MARKUP. Null values are not possible
    // because of ConcurrentHashMap.
    markupCache.remove(locationString);

    if (log.isDebugEnabled()) {
      log.debug("Removed from cache: " + locationString);
    }

    // If a base markup file has been removed from the cache then
    // the derived markup should be removed as well.
    removeMarkupWhereBaseMarkupIsNoLongerInTheCache();

    // And now remove all watcher entries associated with markup
    // resources no longer in the cache.

    // Note that you can not use Application.get() since removeMarkup() will be called from a
    // ModificationWatcher thread which has no associated Application.

    IModificationWatcher watcher = application.getResourceSettings().getResourceWatcher(false);
    if (watcher != null) {
      Iterator<IModifiable> iter = watcher.getEntries().iterator();
      while (iter.hasNext()) {
        IModifiable modifiable = iter.next();
        if (modifiable instanceof MarkupResourceStream) {
          if (!isMarkupCached((MarkupResourceStream) modifiable)) {
            iter.remove();

            if (log.isDebugEnabled()) {
              log.debug("Removed from watcher: " + modifiable);
            }
          }
        }
      }
    }

    return markup;
  }
示例#20
0
  @Override
  public void addListener(AjaxRequestTarget.IListener listener) throws IllegalStateException {
    Args.notNull(listener, "listener");
    assertListenersNotFrozen();

    if (listeners == null) {
      listeners = new LinkedList<>();
    }

    if (!listeners.contains(listener)) {
      listeners.add(listener);
    }
  }
示例#21
0
  /**
   * Executes a request handler and fires pre/post listener methods
   *
   * @param handler
   */
  private void execute(IRequestHandler handler) {
    Args.notNull(handler, "handler");

    try {
      listeners.onRequestHandlerResolved(this, handler);
      requestHandlerExecutor.execute(handler);
      listeners.onRequestHandlerExecuted(this, handler);
    } catch (RuntimeException e) {
      IRequestHandler replacement = requestHandlerExecutor.resolveHandler(e);
      if (replacement != null) {
        execute(replacement);
      } else {
        throw e;
      }
    }
  }
  /**
   * Construct.
   *
   * @param panelClass The class to use for creating instances. Must be of type {@link
   *     BreadCrumbPanel}, and must have constructor {@link BreadCrumbPanel#BreadCrumbPanel(String,
   *     IBreadCrumbModel)}
   */
  public BreadCrumbPanelFactory(final Class<? extends BreadCrumbPanel> panelClass) {
    Args.notNull(panelClass, "panelClass");

    if (!BreadCrumbPanel.class.isAssignableFrom(panelClass)) {
      throw new IllegalArgumentException(
          "argument panelClass ("
              + panelClass
              + ") must extend class "
              + BreadCrumbPanel.class.getName());
    }

    this.panelClass = panelClass;

    // check whether it has the proper constructor
    getConstructor();
  }
  /**
   * Creates an {@link AjaxNewWindowNotifyingBehavior} based on lambda expressions
   *
   * @param windowName the window name
   * @param onNewWindow the {@code SerializableConsumer} which accepts the {@link AjaxRequestTarget}
   * @return the {@link AjaxNewWindowNotifyingBehavior}
   */
  public static AjaxNewWindowNotifyingBehavior onNewWindow(
      String windowName, SerializableConsumer<AjaxRequestTarget> onNewWindow) {
    Args.notNull(onNewWindow, "onNewWindow");

    if (Strings.isEmpty(windowName)) {
      windowName = UUID.randomUUID().toString();
    }

    return new AjaxNewWindowNotifyingBehavior(windowName) {
      private static final long serialVersionUID = 1L;

      @Override
      protected void onNewWindow(AjaxRequestTarget target) {
        onNewWindow.accept(target);
      }
    };
  }
示例#24
0
  @Override
  public void add(Component... components) {
    for (final Component component : components) {
      Args.notNull(component, "component");

      if (component.getOutputMarkupId() == false && !(component instanceof Page)) {
        throw new IllegalArgumentException(
            "Cannot update component that does not have setOutputMarkupId property set to true. Component: "
                + component.toString());
      } else if (component.getPage() != getPage()) {
        throw new IllegalArgumentException(
            "Cannot update component because its page is not the same as "
                + "the one this handler has been created for. Component: "
                + component.toString());
      }
      add(component, component.getMarkupId());
    }
  }
示例#25
0
 /** {@inheritDoc} */
 @Override
 public final void parentNotSuitable(IQuickView quickView) {
   Args.notNull(quickView, "quickview");
   if (!quickView.getReuseStrategy().isAddItemsSupported()) {
     return;
   }
   MarkupContainer parent = quickView.getParent();
   if (parent == null) {
     throw new QuickViewNotAddedToParentException("add quickview to a markupcontainer");
   }
   if (parent instanceof Page) {
     throw new QuickViewNotAddedToParentException("add quickview to a markupcontainer");
   }
   if (parent.size() > 1) {
     throw new ParentNotUnaryException(
         "the markupcontainer to which quickview is attached should have quickview as its only child");
   }
 }
  /**
   * Search for the child's markup in the associated markup file.
   *
   * @param parent The container expected to contain the markup for child
   * @param child The child component to find the markup for
   * @return The markup associated with the child
   */
  @Override
  public IMarkupFragment getMarkup(final MarkupContainer parent, final Component child) {
    Args.notNull(tagName, "tagName");

    IMarkupFragment associatedMarkup = parent.getAssociatedMarkup();
    if (associatedMarkup == null) {
      throw new MarkupNotFoundException(
          "Failed to find markup file associated. "
              + Classes.simpleName(parent.getClass())
              + ": "
              + parent.toString());
    }

    // Find <wicket:panel>
    IMarkupFragment markup = MarkupUtil.findStartTag(associatedMarkup, tagName);
    if (markup == null) {
      throw new MarkupNotFoundException(
          "Expected to find <wicket:"
              + tagName
              + "> in associated markup file. Markup: "
              + associatedMarkup.toString());
    }

    // If child == null, than return the markup fragment starting with <wicket:panel>
    if (child == null) {
      return markup;
    }

    // Find the markup for the child component
    associatedMarkup = markup.find(child.getId());
    if (associatedMarkup != null) {
      return associatedMarkup;
    }

    associatedMarkup = searchMarkupInTransparentResolvers(parent, markup, child);
    if (associatedMarkup != null) {
      return associatedMarkup;
    }

    return findMarkupInAssociatedFileHeader(parent, child);
  }
示例#27
0
 /**
  * constructor supporting programmatic setup of the filter
  *
  * <p>this can be useful for programmatically creating and appending the wicket filter to the
  * servlet context using servlet 3 features.
  *
  * @param application web application
  */
 public WicketFilter(WebApplication application) {
   this.application = Args.notNull(application, "application");
 }
示例#28
0
 /**
  * A function with the signature filter(parsedResponse) that transforms the response body into an
  * array of datums. Expected to return an array of datums.
  *
  * @param filter A function with the signature filter(parsedResponse) that transforms the response
  *     body into an array of datums
  * @return this instance for chaining
  */
 public Prefetch withFilter(final Json.RawValue filter) {
   Args.notNull(filter, "filter");
   put(Filter, filter);
   return this;
 }
示例#29
0
 /**
  * A URL to a JSON file containing an array of datums. <strong>Required</strong>.
  *
  * @param url mandatory parameter
  * @return this instance for chaining
  */
 public Prefetch withUrl(final CharSequence url) {
   Args.notEmpty(url, "url");
   put(Url, url);
   return this;
 }
  /**
   * Constructor
   *
   * @param id component id
   * @param component component that this label is linked to
   */
  public FormComponentLabel(String id, LabeledWebMarkupContainer component) {
    super(id);

    this.component = Args.notNull(component, "component");
    component.setOutputMarkupId(true);
  }