All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.wicket.resource.loader.ValidatorStringResourceLoader Maven / Gradle / Ivy

Go to download

Wicket is a Java web application framework that takes simplicity, separation of concerns and ease of development to a whole new level. Wicket pages can be mocked up, previewed and later revised using standard WYSIWYG HTML design tools. Dynamic content processing and form handling is all handled in Java code using a first-class component model backed by POJO data beans that can easily be persisted using your favorite technology.

There is a newer version: 10.0.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.wicket.resource.loader;

import java.util.Locale;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.validation.FormValidatorAdapter;
import org.apache.wicket.markup.html.form.validation.IFormValidator;
import org.apache.wicket.validation.IValidator;
import org.apache.wicket.validation.ValidatorAdapter;


/**
 * This is one of Wicket's default string resource loaders.
 * 

* The validator string resource loader checks resource bundles attached to validators (eg * MinimumValidator.properties). The validator list is pulled from the form / form component in error. *

* This implementation is fully aware of both locale and style values when trying to obtain the * appropriate resources. *

* * @author igor.vaynberg */ public class ValidatorStringResourceLoader extends ComponentStringResourceLoader { /** * Create and initialize the resource loader. */ public ValidatorStringResourceLoader() { } /** * @see org.apache.wicket.resource.loader.ComponentStringResourceLoader#loadStringResource(java.lang.Class, * java.lang.String, java.util.Locale, java.lang.String, java.lang.String) */ @Override public String loadStringResource(Class clazz, final String key, final Locale locale, final String style, final String variation) { // only care about IValidator/IFormValidator subclasses if ( clazz == null || !(IValidator.class.isAssignableFrom(clazz) || IFormValidator.class.isAssignableFrom(clazz))) { return null; } return super.loadStringResource(clazz, key, locale, style, variation); } /** * @see org.apache.wicket.resource.loader.ComponentStringResourceLoader#loadStringResource(org.apache.wicket.Component, * java.lang.String, java.util.Locale, java.lang.String, java.lang.String) */ @Override public String loadStringResource(final Component component, final String key, final Locale locale, final String style, final String variation) { final String resource; if (component instanceof FormComponent) { resource = loadStringResource((FormComponent) component, key, locale, style, variation); } else if (component instanceof Form) { resource = loadStringResource((Form) component, key, locale, style, variation); } else { resource = null; } return resource; } private String loadStringResource(Form form, final String key, final Locale locale, final String style, final String variation) { for (IFormValidator validator : form.getFormValidators()) { Class scope = getScope(validator); String resource = loadStringResource(scope, key, locale, style, variation); if (resource != null) { return resource; } } return null; } private String loadStringResource(FormComponent fc, final String key, final Locale locale, final String style, final String variation) { for (IValidator validator : fc.getValidators()) { Class scope = getScope(validator); String resource = loadStringResource(scope, key, locale, style, variation); if (resource != null) { return resource; } } return null; } private Class getScope(IValidator validator) { Class scope; if (validator instanceof ValidatorAdapter) { scope = ((ValidatorAdapter) validator).getValidator().getClass(); } else { scope = validator.getClass(); } return scope; } private Class getScope(IFormValidator formValidator) { Class scope; if (formValidator instanceof FormValidatorAdapter) { scope = ((FormValidatorAdapter) formValidator).getValidator().getClass(); } else { scope = formValidator.getClass(); } return scope; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy