下面列出了org.apache.commons.io.monitor.FileAlterationListenerAdaptor#org.apache.wicket.util.lang.Args 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void push(CharSequence message)
{
if (connection.isOpen())
{
Args.notNull(message, "message");
try
{
connection.sendMessage(message.toString());
} catch (IOException iox)
{
LOG.error("An error occurred while pushing text message.", iox);
}
}
else
{
LOG.warn("The websocket connection is already closed. Cannot push the text message '{}'", message);
}
}
@Override
public void push(byte[] message, int offset, int length)
{
if (connection.isOpen())
{
Args.notNull(message, "message");
try
{
connection.sendMessage(message, offset, length);
} catch (IOException iox)
{
LOG.error("An error occurred while pushing binary message.", iox);
}
}
else
{
LOG.warn("The websocket connection is already closed. Cannot push the binary message '{}'", message);
}
}
@Override
public void add(Component... components)
{
for (final Component component : components)
{
Args.notNull(component, "component");
if (component.getOutputMarkupId() == false)
{
throw new IllegalArgumentException(
"cannot update component that does not have setOutputMarkupId property set to true. Component: " +
component.toString());
}
add(component, component.getMarkupId());
}
}
@Override
public IWebSocketConnection getConnection(Application application, String sessionId, IKey key)
{
Args.notNull(application, "application");
Args.notNull(sessionId, "sessionId");
Args.notNull(key, "key");
IWebSocketConnection connection = null;
ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>> connectionsBySession = application.getMetaData(KEY);
if (connectionsBySession != null)
{
ConcurrentMap<IKey, IWebSocketConnection> connectionsByPage = connectionsBySession.get(sessionId);
if (connectionsByPage != null)
{
connection = connectionsByPage.get(key);
}
}
return connection;
}
@Override
public Collection<IWebSocketConnection> getConnections(Application application, String sessionId)
{
Args.notNull(application, "application");
Args.notNull(sessionId, "sessionId");
Collection<IWebSocketConnection> connections = Collections.emptyList();
ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>> connectionsBySession = application.getMetaData(KEY);
if (connectionsBySession != null)
{
ConcurrentMap<IKey, IWebSocketConnection> connectionsByPage = connectionsBySession.get(sessionId);
if (connectionsByPage != null)
{
connections = connectionsByPage.values();
}
}
return connections;
}
/**
* Returns a collection of currently active websockets. The connections might close at any time.
*
* @param application
* The application
* @return a collection of currently active websockets
*/
public Collection<IWebSocketConnection> getConnections(Application application)
{
Args.notNull(application, "application");
Collection<IWebSocketConnection> connections = new ArrayList<>();
ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>> connectionsBySession = application.getMetaData(KEY);
if (connectionsBySession != null)
{
for (ConcurrentMap<IKey, IWebSocketConnection> connectionsByPage : connectionsBySession.values())
{
connections.addAll(connectionsByPage.values());
}
}
return connections;
}
/**
* Adds a validator to this form component
*
* @param validator
* validator to be added
* @return <code>this</code> for chaining
* @throws IllegalArgumentException
* if validator is null
* @see IValidator
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public final FormComponent<T> add(final IValidator<? super T> validator)
{
Args.notNull(validator, "validator");
if (validator instanceof Behavior)
{
add((Behavior)validator);
}
else
{
add((Behavior)new ValidatorAdapter(validator));
}
return this;
}
/**
* Calculates the length of string in bytes, uses specified <code>charset</code> if provided.
*
* @param string
* @param charset
* (optional) character set to use when converting string to bytes
* @return length of string in bytes
*/
public static int lengthInBytes(final String string, final Charset charset)
{
Args.notNull(string, "string");
if (charset != null)
{
try
{
return string.getBytes(charset.name()).length;
}
catch (UnsupportedEncodingException e)
{
throw new RuntimeException(
"StringResourceStream created with unsupported charset: " + charset.name());
}
}
else
{
return string.getBytes().length;
}
}
/**
* Return this value as en enum value.
*
* @param value
* the value to convert to an 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 '%s' to enum constant of type '%s'.", value, enumClass), e);
}
}
/**
* Constructor.
*
* @param sassStream
* The resource stream that loads the Sass content. Only UrlResourceStream is
* supported at the moment!
* @param scopeClass
* The name of the class used as a scope to resolve "package!" dependencies/imports
*/
public SassResourceStream(IResourceStream sassStream, String scopeClass)
{
Args.notNull(sassStream, "sassStream");
while (sassStream instanceof ResourceStreamWrapper) {
ResourceStreamWrapper wrapper = (ResourceStreamWrapper) sassStream;
try {
sassStream = wrapper.getDelegate();
}
catch (Exception x) {
throw new WicketRuntimeException(x);
}
}
if (!(sassStream instanceof UrlResourceStream)) {
throw new IllegalArgumentException(String.format("%s can work only with %s",
SassResourceStream.class.getSimpleName(), UrlResourceStream.class.getName()));
}
URL sassUrl = ((UrlResourceStream) sassStream).getURL();
SassCacheManager cacheManager = SassCacheManager.get();
this.sassSource = cacheManager.getSassContext(sassUrl, scopeClass);
}
public InfinitePagingDataTable(String id, final List<? extends IColumn<T, S>> columns, final InfiniteDataProvider<T> dataProvider, final long rowsPerPage)
{
super(id);
Args.notEmpty(columns, "columns");
this.columns = columns;
this.caption = new Caption("caption", getCaptionModel());
add(caption);
body = newBodyContainer("body");
datagrid = newInfinitePagingDataGridView("rows", columns, dataProvider);
datagrid.setItemsPerPage(rowsPerPage);
body.add(datagrid);
add(body);
topToolbars = new ToolbarsContainer("topToolbars");
bottomToolbars = new ToolbarsContainer("bottomToolbars");
add(topToolbars);
add(bottomToolbars);
}
/**
* Process a component. A web page will be automatically created with the {@code pageMarkup}
* provided. In case pageMarkup is null, the markup will be automatically created with
* {@link #createFormPageMarkup(String, String)}.
* <p>
* <strong>Note</strong>: the instantiated component will have an auto-generated id. To
* reach any of its children use their relative path to the component itself. For example
* if the started component has a child a Link component with id "link" then after starting
* the component you can click it with: <code>tester.clickLink("link")</code>
* </p>
*
* @param <C>
* the type of the component
*
* @param componentClass
* the class of the component to be tested
* @param inputType
* the type of HTML input to be associated with the component to be tested
* @param pageMarkup
* the markup for the Page that will be automatically created. May be {@code null}.
* @return The component processed
*/
@SuppressWarnings("deprecation")
public final <C extends Component> C startComponentInForm(final Class<C> componentClass,
final String inputType, final IMarkupFragment pageMarkup)
{
Args.notNull(componentClass, "componentClass");
// Create the component instance from the class
C comp = null;
try
{
Constructor<C> c = componentClass.getConstructor(String.class);
comp = c.newInstance(ComponentInForm.ID);
componentInForm = new ComponentInForm();
componentInForm.component = comp;
componentInForm.isInstantiated = true;
}
catch (Exception e)
{
fail(String.format("Cannot instantiate component with type '%s' because of '%s'",
componentClass.getName(), e.getMessage()));
}
// process the component
return startComponentInForm(comp, inputType, pageMarkup);
}
public InfinitePagingDataTable(String id, final List<? extends IColumn<T, S>> columns, final InfiniteDataProvider<T> dataProvider, final long rowsPerPage)
{
super(id);
Args.notEmpty(columns, "columns");
this.columns = columns;
this.caption = new Caption("caption", getCaptionModel());
add(caption);
body = newBodyContainer("body");
datagrid = newInfinitePagingDataGridView("rows", columns, dataProvider);
datagrid.setItemsPerPage(rowsPerPage);
body.add(datagrid);
add(body);
topToolbars = new ToolbarsContainer("topToolbars");
bottomToolbars = new ToolbarsContainer("bottomToolbars");
add(topToolbars);
add(bottomToolbars);
}
@Override
public final void bind(final Component hostComponent)
{
Args.notNull(hostComponent, "hostComponent");
if (component != null)
{
throw new IllegalStateException("this kind of handler cannot be attached to " +
"multiple components; it is already attached to component " + component +
", but component " + hostComponent + " wants to be attached too");
}
if(!(hostComponent instanceof AbstractWidget))
{
throw new IllegalStateException("This behaviour can be attached only to "+AbstractWidget.class.getSimpleName()+
", but this one: "+hostComponent.getClass().getName());
}
component = (AbstractWidget<?>)hostComponent;
}
@Override
public void inject(PageParameters targetParameters, ILinkParameterConversionService conversionService)
throws LinkParameterInjectionException {
Args.notNull(targetParameters, "targetParameters");
Args.notNull(conversionService, "conversionService");
Artifact artifact = artifactModel.getObject();
if (artifact != null) {
if (artifact.getGroup() != null && artifact.getGroup().getGroupId() != null) {
targetParameters.add(GROUP_ID_PARAMETER, artifact.getGroup().getGroupId());
}
if (artifact.getArtifactId() != null) {
targetParameters.add(ARTIFACT_ID_PARAMETER, artifact.getArtifactId());
}
}
}
@Override
public void extract(PageParameters sourceParameters, ILinkParameterConversionService conversionService)
throws LinkParameterExtractionException {
Args.notNull(sourceParameters, "sourceParameters");
Args.notNull(conversionService, "conversionService");
String groupId = sourceParameters.get(GROUP_ID_PARAMETER).toString();
String artifactId = sourceParameters.get(ARTIFACT_ID_PARAMETER).toString();
Artifact artifact = null;
if (groupId != null && artifactId != null) {
ArtifactKey artifactKey = new ArtifactKey(groupId, artifactId);
try {
artifact = conversionService.convert(artifactKey, Artifact.class);
} catch (ConversionException e) {
throw new LinkParameterExtractionException(e);
}
}
artifactModel.setObject(artifact);
}
/**
* Construct.
*
* @param webRequest
* @param httpServletResponse
*/
public ServletWebResponse(ServletWebRequest webRequest, HttpServletResponse httpServletResponse)
{
Args.notNull(webRequest, "webRequest");
Args.notNull(httpServletResponse, "httpServletResponse");
this.httpServletResponse = httpServletResponse;
this.webRequest = webRequest;
}
@Override
public String encodeURL(CharSequence url)
{
Args.notNull(url, "url");
UrlRenderer urlRenderer = getUrlRenderer();
Url originalUrl = Url.parse(url);
/*
WICKET-4645 - always pass absolute url to the web container for encoding
because when REDIRECT_TO_BUFFER is in use Wicket may render PageB when
PageA is actually the requested one and the web container cannot resolve
the base url properly
*/
String fullUrl = urlRenderer.renderFullUrl(originalUrl);
String encodedFullUrl = httpServletResponse.encodeURL(fullUrl);
final String encodedUrl;
if (originalUrl.isFull())
{
encodedUrl = encodedFullUrl;
}
else
{
if (fullUrl.equals(encodedFullUrl))
{
// no encoding happened so just reuse the original url
encodedUrl = url.toString();
}
else
{
// get the relative url with the jsessionid encoded in it
Url _encoded = Url.parse(encodedFullUrl);
encodedUrl = urlRenderer.renderRelativeUrl(_encoded);
}
}
return encodedUrl;
}
@Override
public String encodeRedirectURL(CharSequence url)
{
Args.notNull(url, "url");
UrlRenderer urlRenderer = getUrlRenderer();
Url originalUrl = Url.parse(url);
/*
* WICKET-4645 - always pass absolute url to the web container for encoding because when
* REDIRECT_TO_BUFFER is in use Wicket may render PageB when PageA is actually the requested
* one and the web container cannot resolve the base url properly
*/
String fullUrl = urlRenderer.renderFullUrl(originalUrl);
String encodedFullUrl = httpServletResponse.encodeRedirectURL(fullUrl);
final String encodedUrl;
if (originalUrl.isFull())
{
encodedUrl = encodedFullUrl;
}
else
{
if (fullUrl.equals(encodedFullUrl))
{
// no encoding happened so just reuse the original url
encodedUrl = url.toString();
}
else
{
// get the relative url with the jsessionid encoded in it
Url _encoded = Url.parse(encodedFullUrl);
encodedUrl = urlRenderer.renderRelativeUrl(_encoded);
}
}
return encodedUrl;
}
/**
* @param redirectUrl
* URL to redirect to.
* @param status
* 301 (Moved permanently) or 302 (Moved temporarily)
*/
public RedirectRequestHandler(final String redirectUrl, final int status)
{
if ((status != HttpServletResponse.SC_MOVED_PERMANENTLY) &&
(status != HttpServletResponse.SC_MOVED_TEMPORARILY) &&
(status != HttpServletResponse.SC_SEE_OTHER))
{
throw new IllegalStateException("Status must be either 301, 302 or 303, but was: " + status);
}
this.redirectUrl = Args.notEmpty(redirectUrl, "redirectUrl");
this.status = status;
}
/**
* Removes a validator from the form component.
*
* @param validator
* validator
* @throws IllegalArgumentException
* if validator is null or not found
* @see IValidator
* @see #add(IValidator)
* @return form component for chaining
*/
public final FormComponent<T> remove(final IValidator<? super T> validator)
{
Args.notNull(validator, "validator");
Behavior match = null;
for (Behavior behavior : getBehaviors())
{
if (behavior.equals(validator))
{
match = behavior;
break;
}
else if (behavior instanceof ValidatorAdapter)
{
if (((ValidatorAdapter<?>)behavior).getValidator().equals(validator))
{
match = behavior;
break;
}
}
}
if (match != null)
{
remove(match);
}
else
{
throw new IllegalStateException(
"Tried to remove validator that was not previously added. "
+ "Make sure your validator's equals() implementation is sufficient");
}
return this;
}
/**
* Adds a validator to this form component.
*
* @param validators
* The validator(s) to be added
* @return This
* @throws IllegalArgumentException
* if validator is null
* @see IValidator
*/
@SafeVarargs
public final FormComponent<T> add(final IValidator<? super T>... validators)
{
Args.notNull(validators, "validators");
for (IValidator<? super T> validator : validators)
{
add(validator);
}
// return this for chaining
return this;
}
/**
* 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();
}
/**
* Construct.
*
* @param pageParametersEncoder
* @param cachingStrategy
*/
public BasicResourceReferenceMapper(IPageParametersEncoder pageParametersEncoder,
IProvider<? extends IResourceCachingStrategy> cachingStrategy)
{
this.pageParametersEncoder = Args.notNull(pageParametersEncoder, "pageParametersEncoder");
this.cachingStrategy = cachingStrategy;
}
/**
* Constructor.
*
* @param session
* the jetty websocket connection
*/
public WebSocketConnection(Session session, AbstractWebSocketProcessor webSocketProcessor, PageKey pageKey)
{
super(webSocketProcessor);
this.session = Args.notNull(session, "connection");
this.pageKey = pageKey;
}
@Override
public final void bind(final Component hostComponent) {
Args.notNull(hostComponent, "hostComponent");
if (component != null) {
throw new IllegalStateException(
"this kind of validator cannot be attached to "
+ "multiple components; it is already attached to component "
+ component + ", but component " + hostComponent
+ " wants to be attached too");
}
component = hostComponent;
}
public FilterCriteriaManager(String field) {
Args.notNull(field, "field");
this.field = field;
filterCriterias = Maps.newHashMap();
and = true;
}
/**
* @param wrapperClass to wrap into
*/
public DocumentWrapperTransformer(Class<? extends T> wrapperClass)
{
Args.notNull(wrapperClass, "wrapperClass");
this.wrapperClass = wrapperClass;
//To check that appropriate constructor exists
getConstructor();
}
public DynamicPropertyValueModel(IModel<ODocument> docModel, IModel<OProperty> propertyModel, Class<? extends T> valueType)
{
Args.notNull(docModel, "documentModel");
this.docModel = docModel;
this.propertyModel = propertyModel;
this.valueType = valueType;
}
public OIndexPrototyper(String className, List<String> fields)
{
Args.notEmpty(fields, "fields");
values.put(DEF_CLASS_NAME, className);
values.put(DEF_FIELDS, fields);
values.put(DEF_NULLS_IGNORED, true);
if(fields!=null && fields.size()==1) {
values.put(NAME, className+"."+fields.get(0));
}
}