/** * Processes PortletPreferencesValidator annotated classes. The preferences validators are temorarily stored while * the portlet configuration annotations are being processed. * * @param cls * The annotated class */ @Override public void processValidatorAnnotation(Class<?> cls) { PortletPreferencesValidator vali = cls.getAnnotation(PortletPreferencesValidator.class); if (vali != null) { if (!PreferencesValidator.class.isAssignableFrom(cls)) { StringBuilder txt = new StringBuilder(128); txt.append("@PortletPreferencesValidator annotated class must implement PreferencesValidator interface. "); txt.append(", class: ").append(cls.getCanonicalName()); LOG.warn(txt.toString()); throw new IllegalArgumentException(txt.toString()); } String clsName = cls.getCanonicalName(); prefValidators.put(vali, clsName); } }
/** * Stores the portlet preferences to a persistent storage. If a preferences * validator is defined for this portlet, this method firstly validates the * portlet preferences. * <p> * This method is invoked internally, thus it does not check the portlet * request method ID (METHOD_RENDER or METHOD_ACTION). * </p> * @throws ValidatorException if the portlet preferences are not valid. * @throws IOException if an error occurs with the persistence mechanism. */ protected final void internalStore() throws IOException, ValidatorException { // Validate the preferences before storing, if a validator is defined. // If the preferences cannot pass the validation, // an ValidatorException will be thrown out. PortletDefinition portletD = window.getPortletDefinition(); PreferencesValidator validator = preferencesService.getPreferencesValidator(portletD); if (validator != null) { validator.validate(this); } // Store the portlet preferences. try { preferencesService.store(window, request, preferences); } catch (PortletContainerException ex) { LOG.error("Error storing preferences.", ex); throw new IOException("Error storing perferences: " + ex.getMessage()); } }
public void setPreferencesValidator(PreferencesValidator preferencesValidator) { this.preferencesValidator = preferencesValidator; }
public PortletPreferencesManagerImpl(org.gridsphere.portletcontainer.impl.descriptor.PortletPreferences prefsDesc, PreferencesValidator validator) { PersistenceManagerService pms = (PersistenceManagerService) PortletServiceFactory.createPortletService(PersistenceManagerService.class, true); pm = pms.createGridSphereRdbms(); this.prefsDesc = prefsDesc; this.validator = validator; }
public PreferencesValidator getValidator() { return validator; }
public void setValidator(PreferencesValidator validator) { this.validator = validator; }
/** * Returns the preferences validator instance for the given portlet * definition. If no preferences validator class is defined for the portlet * definition, null is returned. This method caches the validator instances * in the cache to ensure that only one validator instance is created per * portlet definition. * @param portletDefinition the portlet definition. * @return the preferences validator if defined for the portlet definition. * @throw ValidatorException if fail to instantiate validator instance. */ PreferencesValidator getPreferencesValidator(PortletDefinition portletDefinition) throws ValidatorException;