Java 类javax.portlet.ValidatorException 实例源码

项目:portals-pluto    文件:PreferencesValidatorImpl.java   
private void checkValidatorCount() throws ValidatorException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Checking validator count...");
    }
    Integer instanceCreated = (Integer) INSTANCE_COUNTER.get(
            getClass().getName());
    if (LOG.isDebugEnabled()) {
        LOG.debug("Method validate() invoked " + validateInvoked + " times.");
        LOG.debug("Validator created " + instanceCreated.intValue() + " times.");
    }
    if (instanceCreated.intValue() != 1) {
        throw new ValidatorException(instanceCreated.toString()
                + " validator instances were created, "
                + "expected 1 validator instance per portlet definition.",
                null);
    }
}
项目:portals-pluto    文件:PortletPreferencesImpl.java   
/**
 * 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());
    }
}
项目:liferay-voice-command    文件:SpeechUtil.java   
public static PortletPreferences deleteVoiceCommand(ActionRequest request, String voiceCommand) 
        throws PortalException, SystemException, ReadOnlyException, ValidatorException, IOException {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long plid = themeDisplay.getLayout().getPlid();
    long ownerId = PortletKeys.PREFS_OWNER_ID_DEFAULT;
    int ownerType = PortletKeys.PREFS_OWNER_TYPE_LAYOUT;
    long companyId = themeDisplay.getCompanyId();

    PortletPreferences preference = request.getPreferences();
    Map<String, String[]> preferencesMap = new HashMap<String, String[]>(preference.getMap());
    preferencesMap.remove(voiceCommand);

    PortletPreferencesLocalServiceUtil.deletePortletPreferences(ownerId, ownerType, plid, SpeechConstants.PORTLET_NAMESPACE);

    preference = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId, ownerType, plid,
            SpeechConstants.PORTLET_NAMESPACE);

    for (Map.Entry<String, String[]> entry : preferencesMap.entrySet()) {
        preference.setValue(entry.getKey(), entry.getValue()[0]);
    }
    preference.store();
    return preference;
}
项目:flashlight-search    文件:FlashlightSearchServiceImpl.java   
@Override
public SearchResultsContainer search(PortletRequest request, PortletResponse response, String tabId, int pageOffset, boolean isLoadMore) throws ReadOnlyException, ValidatorException, IOException, SearchException {
    FlashlightSearchConfiguration config = this.readConfiguration(request.getPreferences());
    Map<String, FlashlightSearchConfigurationTab> tabs = config.getTabs();
    FacetedSearcher searcher = this.facetedSearcherManager.createFacetedSearcher();

    LinkedHashMap<FlashlightSearchConfigurationTab, SearchPage> resultMap = new LinkedHashMap<>(tabs.size());
    for(FlashlightSearchConfigurationTab tab : tabs.values()) {
        int pageSize;
        int loadMoreSize;

        if(tab.getId().equals(tabId)) {
            pageSize = tab.getFullPageSize();
        } else {
            pageSize = tab.getPageSize();
        }

        if(isLoadMore) {
            loadMoreSize = tab.getLoadMorePageSize();
        } else {
            loadMoreSize = 0;
        }

        resultMap.put(tab, this.search(request, response, config, tab, searcher, pageOffset, pageSize, loadMoreSize));
    }

    return new SearchResultsContainer(resultMap);
}
项目:flashlight-search    文件:ConfigurationStorageV1.java   
@Override
public void saveGlobalSettings(String adtUuid, boolean doSearchOnStartup, String doSearchOnStartupKeywords, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException {
    if(Validator.isNull(doSearchOnStartupKeywords)) {
        doSearchOnStartupKeywords = FlashlightSearchService.CONFIGURATION_DEFAULT_SEARCH_KEYWORDS;
    }
    preferences.setValue(CONF_KEY_ADT_UUID, adtUuid);
    preferences.setValue(CONF_KEY_DO_SEARCH_ON_STARTUP, Boolean.toString(doSearchOnStartup));
    preferences.setValue(CONF_KEY_DO_SEARCH_ON_STARTUP_KEYWORDS, doSearchOnStartupKeywords);
    preferences.store();
}
项目:flashlight-search    文件:ConfigurationStorageV1.java   
@Override
public void saveSearchFacetConfig(FlashlightSearchConfigurationTab configurationTab, SearchFacet searchFacet, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException {
    String tabId = configurationTab.getId();
    String facetConfigKey = format(CONF_KEY_FORMAT_SEARCH_FACET, tabId, searchFacet.getClass().getName());
    preferences.setValue(facetConfigKey, searchFacet.getData().toJSONString());
    preferences.store();
}
项目:invite-friend    文件:JuZExoInviteFriendFrontendApplication.java   
@Action
public Response saveSettings(String enableStoreData,String invitationUrl) throws ReadOnlyException, IOException, ValidatorException {
  portletPreferences.setValue(ENABLE_STORE_DATA,enableStoreData);
  portletPreferences.setValue(INVITATION_URL,invitationUrl);
  portletPreferences.store();
  return JuZExoInviteFriendFrontendApplication_.index().with(JuzuPortlet.PORTLET_MODE, PortletMode.VIEW);
}
项目:org.portletbeans    文件:AbstractMangedBean.java   
/**
 * Stores the values of this bean into the preferences and stays in the current portlet mode.
 */
public void store() {
    try {
        final PortletPreferences portletPreferences = getPortletPreferences();
        store(portletPreferences);
        portletPreferences.store();
    } catch (final ReadOnlyException | ValidatorException | IOException e) {
        log.error("Could not store portlet preferences", e);
    }
}
项目:edemocracia    文件:ConfiguracaoPage.java   
private void initForm() {



        form = new Form<Void>("form") {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onSubmit() {
                PortletPreferences prefs = UIUtils.getPortletPreferences();
                HtmlStripper htmlStripper = new HtmlStripper();

                try {
                    prefs.setValue("titulo", tituloProjetoLei.getModelObject());
                    prefs.setValue("tituloDescricao", tituloDescricaoProjeto.getModelObject());
                    prefs.setValue("descricaoProjeto", htmlStripper.strip(descricaoProjeto.getModelObject()));
                    prefs.setValue("habilitaPlugins", habilitaPlugins.getModelObject().toString());
                    prefs.setValue("habilitaSugestoes", habilitaSugestoes.getModelObject().toString());

                    info("Alterações realizadas com sucesso!");
                    getRequestCycle().setRequestTarget(new RedirectRequestTarget(viewUrl));
                } catch (ReadOnlyException e) {
                    error("Erro ao gravar alterações");
                    return;
                }
                try {
                    prefs.store();
                } catch (ValidatorException e) {
                    error("Erro ao gravar alterações");
                } catch (IOException e) {
                    error("Erro ao gravar alterações");
                }
            }
        };
        add(form);
    }
项目:portals-pluto    文件:V2EnvironmentTests_PortletPreferences_Validator.java   
@Override
public void validate(PortletPreferences preferences) throws ValidatorException {

  EnvironmentTests_PortletPreferences_ApiAction.tr32_success = true;
  EnvironmentTests_PortletPreferences_ApiEvent_event.tr32_success = true;
  EnvironmentTests_PortletPreferences_ApiResource.tr32_success = true;

  if (preferences.getValue("tr33", "true").equals("false")) {
    ArrayList<String> al = new ArrayList<String>();
    al.add("tr33");
    al.add("tr34");
    throw new ValidatorException("ValidatorException for tr33 and tr34", al);
  }
}
项目:politaktiv-aktuelles-meinungsbild-portlet    文件:MeinungsbildRepository.java   
public void saveMaximumRatings(SetOfOpinion tmpSetOfOpinionWithOnlyMaxValues, ActionRequest actionRequest) throws ReadOnlyException, ValidatorException, IOException {
        javax.portlet.PortletPreferences prefs = actionRequest.getPreferences();

        if(tmpSetOfOpinionWithOnlyMaxValues.validateMaxValues()){
            prefs.setValue("maximumRatingPerUser", Integer.toString(tmpSetOfOpinionWithOnlyMaxValues.getNumberOfMaximumScoresByUser()));
            prefs.setValue("maximumOfRatingPerSubtopic", Integer.toString(tmpSetOfOpinionWithOnlyMaxValues.getNumberOfMaximumScoreBySubtopic()));
            prefs.store();
        } else {
            SessionErrors.add(actionRequest, "maximumsInputNotValid");
        }
}
项目:flashlight-search    文件:FlashlightSearchServiceImpl.java   
@Override
public FlashlightSearchConfiguration readConfiguration(PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException {
    return this.storageEngine.readConfiguration(preferences);
}
项目:flashlight-search    文件:FlashlightSearchServiceImpl.java   
@Override
public void saveGlobalSettings(String adtUuid, boolean doSearchOnStartup, String doSearchOnStartupKeywords, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException {
    this.storageEngine.saveGlobalSettings(adtUuid, doSearchOnStartup, doSearchOnStartupKeywords, preferences);
}
项目:flashlight-search    文件:FlashlightSearchServiceImpl.java   
@Override
public void saveConfigurationTab(FlashlightSearchConfigurationTab configurationTab, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException {
    this.storageEngine.saveConfigurationTab(configurationTab, preferences);
}
项目:flashlight-search    文件:FlashlightSearchServiceImpl.java   
@Override
public void saveSearchFacetConfig(FlashlightSearchConfigurationTab configurationTab, SearchFacet searchFacet, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException {
    this.storageEngine.saveSearchFacetConfig(configurationTab, searchFacet, preferences);
}
项目:flashlight-search    文件:FlashlightSearchServiceImpl.java   
@Override
public void deleteConfigurationTab(String tabId, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException {
    this.storageEngine.deleteConfigurationTab(tabId, preferences);
}
项目:flashlight-search    文件:ConfigurationStorageV1.java   
@Override
public void deleteConfigurationTab(String tabId, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException {
    // First, delete any reference to this tab
    List<String> tabIds = Arrays.asList(preferences.getValues(CONF_KEY_TABS, EMPTY_ARRAY))
        .stream()
        .filter(tab -> !tab.equals(tabId))
        .collect(Collectors.toList());
    preferences.setValues(CONF_KEY_TABS, tabIds.toArray(new String[tabIds.size()]));

    // Then, flush out any singular value
    String assetTypeKey = format(CONF_KEY_FORMAT_ASSET_TYPE, tabId);
    String journalArticleViewTemplateKey = format(CONF_KEY_FORMAT_JOURNAL_ARTICLE_VIEW_TEMPLATE, tabId);
    String orderKey = format(CONF_KEY_FORMAT_ORDER, tabId);
    String pageSizeKey = format(CONF_KEY_FORMAT_PAGE_SIZE, tabId);
    String fullPageSizeKey = format(CONF_KEY_FORMAT_FULL_PAGE_SIZE, tabId);
    String loadMoreSizeKey = format(CONF_KEY_FORMAT_LOAD_MORE_PAGE_SIZE, tabId);
    String sortByKey = format(CONF_KEY_FORMAT_SORT_BY, tabId);
    String sortReverseKey = format(CONF_KEY_FORMAT_SORT_REVERSE, tabId);

    preferences.reset(orderKey);
    preferences.reset(assetTypeKey);
    preferences.reset(journalArticleViewTemplateKey);
    preferences.reset(pageSizeKey);
    preferences.reset(fullPageSizeKey);
    preferences.reset(loadMoreSizeKey);
    preferences.reset(sortByKey);
    preferences.reset(sortReverseKey);

    // Finally, flush out composed values
    Enumeration<String> prefKeys = preferences.getNames();
    Pattern journalArticleTemplatesKeyPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_JOURNAL_ARTICLE_TEMPLATES, tabId));
    Pattern dlFileEntryTemplatesKeyPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_DL_FILE_ENTRY_TYPE_TEMPLATES, tabId));
    Pattern titleKeyPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_TITLE, tabId));
    Pattern searchFacetPattern = Pattern.compile(format(CONF_KEY_PATTERN_FORMAT_SEARCH_FACET, tabId));

    while(prefKeys.hasMoreElements()) {
        String key = prefKeys.nextElement();
        boolean journalArticleTemplatesMatches = journalArticleTemplatesKeyPattern.matcher(key).matches();
        boolean dlFileEntryTemplatesMatches = dlFileEntryTemplatesKeyPattern.matcher(key).matches();
        boolean titleMatches = titleKeyPattern.matcher(key).matches();
        boolean searchFacetMatches = searchFacetPattern.matcher(key).matches();

        if(journalArticleTemplatesMatches || dlFileEntryTemplatesMatches || titleMatches || searchFacetMatches) {
            preferences.reset(key);
        }
    }

    preferences.store();
}
项目:spring4-understanding    文件:MockPortletPreferences.java   
@Override
public void store() throws IOException, ValidatorException {
    if (this.preferencesValidator != null) {
        this.preferencesValidator.validate(this);
    }
}
项目:spring4-understanding    文件:MockPortletPreferences.java   
@Override
public void store() throws IOException, ValidatorException {
    if (this.preferencesValidator != null) {
        this.preferencesValidator.validate(this);
    }
}
项目:liferay-db-setup-core    文件:SetupPages.java   
private static void setupLiferayPage(final Layout layout, final Page page, final String defaultLayout,
                                     final String defaultLayoutContainedInThemeWithId, final long groupId,
                                     final boolean isPrivate, final long company, final long userId,
                                     final String pageTemplateName) throws SystemException, PortalException {
    if (page.getTheme() != null) {
        setPageTheme(layout, page);
    }
    if (page.getLayout() != null) {
        setLayoutTemplate(layout, page, userId);
    }

    setPageTarget(page, layout);

    List<Pageportlet> portlets = page.getPageportlet();
    if (portlets != null && !portlets.isEmpty()) {
        for (Pageportlet portlet : portlets) {
            try {
                addPortletIntoPage(page, layout, portlet, company, groupId);

            } catch (ValidatorException | IOException e) {
                LOG.error(e);
            }
        }
    }

    List<Page> subPages = page.getPage();
    if (subPages != null && !subPages.isEmpty()) {
        if (pageTemplateName != null && !pageTemplateName.equals("")) {
            LOG.error("Page template " + pageTemplateName + " may not have any sub-pages! "
                    + "Will ignore them!");
        } else {
            addPages(subPages, defaultLayout, defaultLayoutContainedInThemeWithId, groupId, isPrivate,
                    layout.getLayoutId(), company, userId);
        }
    }

    if (page.getCustomFieldSetting() != null && !page.getCustomFieldSetting().isEmpty()) {
        setCustomFields(userId, groupId, company, page, layout);
    }

    SetupPermissions.updatePermission("Page " + page.getFriendlyURL(), groupId, company,
            layout.getPlid(), Layout.class, page.getRolePermissions(),
            getDefaultPermissions(isPrivate));
}
项目:sakai    文件:SimpleRSSPreferencesValidator.java   
@Override
public void validate(PortletPreferences prefs) throws ValidatorException {

    //get prefs as strings
    String max_items = prefs.getValue("max_items", Integer.toString(Constants.MAX_ITEMS));
    String feed_url = prefs.getValue(PREF_FEED_URL, null);

    //check readonly
    boolean feedUrlIsLocked = prefs.isReadOnly(PREF_FEED_URL);

    /**
     * max_items
     */
    IntegerValidator integerValidator = IntegerValidator.getInstance();
    Integer maxItems = integerValidator.validate(max_items);


    //check it's a number
    if(maxItems == null) {
        throw new ValidatorException("Invalid value, must be a number", Collections.singleton("max_items"));
    }

    //check greater than or equal to a minimum of 1
    if(!integerValidator.minValue(maxItems, Constants.MIN_ITEMS)) {
        throw new ValidatorException("Invalid number, must be greater than 0", Collections.singleton("max_items"));
    }

    /**
     * feed_url
     */
    //only validate if it's not readonly
    if(!feedUrlIsLocked) {
        String[] schemes = {"http","https"};
        DetailedUrlValidator urlValidator = new DetailedUrlValidator(schemes);

        //check not null
        if(StringUtils.isBlank(feed_url)){
            throw new ValidatorException("You must specify a URL for the RSS feed", Collections.singleton(PREF_FEED_URL));
        }

        //check valid scheme
        if(!urlValidator.isValidScheme(feed_url)){
            throw new ValidatorException("Invalid feed scheme. Must be one of: " + Arrays.toString(schemes), Collections.singleton(PREF_FEED_URL));
        }

        //check valid URL
        if(!urlValidator.isValid(feed_url)){
            throw new ValidatorException("Invalid feed URL", Collections.singleton(PREF_FEED_URL));

        }
    }

    /**
     * portlet_title not validated here as it is reasonable to allow blank entry. We deal with this later
     */

}
项目:org.portletbeans    文件:TestPreferences.java   
@Override
public void store() throws IOException, ValidatorException {
    // Nothing to do
}
项目:class-guard    文件:MockPortletPreferences.java   
public void store() throws IOException, ValidatorException {
    if (this.preferencesValidator != null) {
        this.preferencesValidator.validate(this);
    }
}
项目:class-guard    文件:MockPortletPreferences.java   
public void store() throws IOException, ValidatorException {
    if (this.preferencesValidator != null) {
        this.preferencesValidator.validate(this);
    }
}
项目:portals-pluto    文件:PreferencesValidatorImpl.java   
public void validate(PortletPreferences preferences)
throws ValidatorException {
    validateInvoked++;
    String value = preferences.getValue(CHECK_VALIDATOR_COUNT, null);
    if (value != null && value.equalsIgnoreCase("true")) {
        checkValidatorCount();
    }

    //
    // TODO: Determine why we use this - I seem to remember it's a
    //   spec requirement, and fix it so that we don't have issues
    //   anymore.  When enabled, all preferences fail in testsuite.
    //
    final String[] DEFAULT_VALUES = new String[] { "no values" };
    Collection<String> failedNames = new ArrayList<String>();
    for (Enumeration<String> en = preferences.getNames(); 
            en.hasMoreElements(); ) {
        String name = (String) en.nextElement();
        String[] values = preferences.getValues(name, DEFAULT_VALUES);
        if (values != null) { // null values are allowed
            for (int i = 0; i < values.length; i++) {
                if (values[i] != null) { // null values are allowed
                    // Validate that the preferences do not
                    //   start or end with white spaces.
                    if (!values[i].equals(values[i].trim())) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Validation failed: "
                                    + "value has white spaces: "
                                    + "name=" + name
                                    + "; value=|" + values[i] + "|");
                        }
                        failedNames.add(name);
                    }
                }
            }
        }
    }

    if (!failedNames.isEmpty()) {
        throw new ValidatorException(
                "One or more preferences do not pass the validation.",
                failedNames);
    }
}
项目:portals-pluto    文件:ExceptionTests_ValidatorException_ApiRender.java   
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp)
    throws PortletException, IOException {

  long tid = Thread.currentThread().getId();
  portletReq.setAttribute(THREADID_ATTR, tid);

  PrintWriter writer = portletResp.getWriter();

  JSR286ApiTestCaseDetails tcd = new JSR286ApiTestCaseDetails();

  // Create result objects for the tests

  /* TestCase: V2ExceptionTests_ValidatorException_ApiRender_constructor2 */
  /* Details: "For ValidatorException(java.lang.String, */
  /* java.util.Collection&lt;java.lang.String&gt;), the failedKeys */
  /* parameter may be null" */
  TestResult tr0 =
      tcd.getTestResultFailed(V2EXCEPTIONTESTS_VALIDATOREXCEPTION_APIRENDER_CONSTRUCTOR2);
  ValidatorException ve = new ValidatorException("TestException", null);
  if (ve.getMessage().equals("TestException")) {
    tr0.setTcSuccess(true);
  }
  tr0.writeTo(writer);

  /* TestCase: V2ExceptionTests_ValidatorException_ApiRender_constructor4 */
  /* Details: "For ValidatorException(java.lang.String, */
  /* java.lang.Throwable, */
  /* java.util.Collection&lt;java.lang.String&gt;), the failedKeys */
  /* parameter may be null" */
  TestResult tr1 =
      tcd.getTestResultFailed(V2EXCEPTIONTESTS_VALIDATOREXCEPTION_APIRENDER_CONSTRUCTOR4);
  Throwable tw = new Throwable("TestThrow");
  ValidatorException ve1 = new ValidatorException("TestException1", tw, null);
  if (ve1.getMessage().equals("TestException1")) {
    tr1.setTcSuccess(true);
  }
  tr1.writeTo(writer);

  /* TestCase: V2ExceptionTests_ValidatorException_ApiRender_constructor6 */
  /* Details: "For ValidatorException(java.lang.Throwable, */
  /* java.util.Collection&lt;java.lang.String&gt;), the failedKeys */
  /* parameter may be null" */
  TestResult tr2 =
      tcd.getTestResultFailed(V2EXCEPTIONTESTS_VALIDATOREXCEPTION_APIRENDER_CONSTRUCTOR6);
  Throwable tw1 = new Throwable("TestThrow1");
  ValidatorException ve2 = new ValidatorException(tw1, null);
  if (ve2.getMessage().contains("TestThrow1")) {
    tr2.setTcSuccess(true);
  }
  tr2.writeTo(writer);

  /* TestCase: V2ExceptionTests_ValidatorException_ApiRender_getFailedKeys1 */
  /* Details: "Method getFailedKeys(): Returns a */
  /* java.util.Enumeration&lt;java.lang.String&gt; object containing */
  /* the preference keys that failed validation" */
  TestResult tr3 =
      tcd.getTestResultFailed(V2EXCEPTIONTESTS_VALIDATOREXCEPTION_APIRENDER_GETFAILEDKEYS1);
  tr3.setTcSuccess(true);
  tr3.appendTcDetail("There are no Preference Keys that Failed Validation in this Test Portlet.");
  tr3.writeTo(writer);

  /* TestCase: V2ExceptionTests_ValidatorException_ApiRender_getFailedKeys2 */
  /* Details: "Method getFailedKeys(): Returns an empty enmueration if */
  /* no failed keys are available" */
  TestResult tr4 =
      tcd.getTestResultFailed(V2EXCEPTIONTESTS_VALIDATOREXCEPTION_APIRENDER_GETFAILEDKEYS2);
  Enumeration<?> eu = ve1.getFailedKeys();
  List<?> li = Collections.list(eu);
  if (li.isEmpty()) {
    tr4.setTcSuccess(true);
  }
  tr4.writeTo(writer);
}
项目:portals-pluto    文件:TestAnnotatedPrefs2.java   
@Override
public void validate(PortletPreferences arg0) throws ValidatorException {
}
项目:portals-pluto    文件:TestAnnotatedPrefs1.java   
@Override
public void validate(PortletPreferences arg0) throws ValidatorException {
}
项目:sakai    文件:SimpleRSSPreferencesValidator.java   
@Override
public void validate(PortletPreferences prefs) throws ValidatorException {

    //get prefs as strings
    String max_items = prefs.getValue("max_items", Integer.toString(Constants.MAX_ITEMS));
    String feed_url = prefs.getValue(PREF_FEED_URL, null);

    //check readonly
    boolean feedUrlIsLocked = prefs.isReadOnly(PREF_FEED_URL);

    /**
     * max_items
     */
    IntegerValidator integerValidator = IntegerValidator.getInstance();
    Integer maxItems = integerValidator.validate(max_items);


    //check it's a number
    if(maxItems == null) {
        throw new ValidatorException("Invalid value, must be a number", Collections.singleton("max_items"));
    }

    //check greater than or equal to a minimum of 1
    if(!integerValidator.minValue(maxItems, Constants.MIN_ITEMS)) {
        throw new ValidatorException("Invalid number, must be greater than 0", Collections.singleton("max_items"));
    }

    /**
     * feed_url
     */
    //only validate if it's not readonly
    if(!feedUrlIsLocked) {
        String[] schemes = {"http","https"};
        DetailedUrlValidator urlValidator = new DetailedUrlValidator(schemes);

        //check not null
        if(StringUtils.isBlank(feed_url)){
            throw new ValidatorException("You must specify a URL for the RSS feed", Collections.singleton(PREF_FEED_URL));
        }

        //check valid scheme
        if(!urlValidator.isValidScheme(feed_url)){
            throw new ValidatorException("Invalid feed scheme. Must be one of: " + Arrays.toString(schemes), Collections.singleton(PREF_FEED_URL));
        }

        //check valid URL
        if(!urlValidator.isValid(feed_url)){
            throw new ValidatorException("Invalid feed URL", Collections.singleton(PREF_FEED_URL));

        }
    }

    /**
     * portlet_title not validated here as it is reasonable to allow blank entry. We deal with this later
     */

}
项目:liferay-voice-command    文件:SpeechUtil.java   
public static void deleteVoiceCommand(ActionRequest request) 
        throws PortalException, SystemException, ReadOnlyException, ValidatorException, IOException {

    String commandKey = ParamUtil.get(request, SpeechConstants.VOICE_COMMAND, StringPool.BLANK);
    deleteVoiceCommand(request, commandKey);
}
项目:edemocracia    文件:ConfiguracaoManager.java   
public static void salvarConfiguracao(Configuracao config) throws ReadOnlyException, ValidatorException, IOException{

    PortletPreferences portletPrefs = LiferayFacesContext.getInstance().getPortletPreferences();
    portletPrefs.setValue(CONFIGURACAO_KEY, config.convertToJSON());
    portletPrefs.store();

}
项目:portals-pluto    文件:PortletPreferencesImpl.java   
/**
 * Stores the portlet preferences to a persistent storage. This method
 * should only be invoked within <code>processAction()</code> method.
 * 
 * @see #internalStore()
 * 
 * @throws IllegalStateException  if this method is not invoked within
 *         <code>processAction()</code> method.
 * @throws ValidatorException  if the portlet preferences are not valid.
 * @throws IOException  if an error occurs with the persistence mechanism.
 */
public void store() throws IOException, ValidatorException {
    if (PortletRequest.RENDER_PHASE.equals(request.getAttribute(PortletRequest.LIFECYCLE_PHASE))) {
        throw new IllegalStateException(
                "store is not allowed during RENDER phase.");
    }
    internalStore();
}
项目:GridSphere    文件:PortletPreferencesImpl.java   
/**
     * Commits all changes made to the preferences via the
     * <code>set</code> methods in the persistent store.
     * <p/>
     * If this call returns succesfull, all changes are made
     * persistent. If this call fails, no changes are made
     * in the persistent store. This call is an atomic operation
     * regardless of how many preference attributes have been modified.
     * <p/>
     * All changes made to preferences not followed by a call
     * to the <code>store</code> method are discarded when the
     * portlet finishes the <code>processAction</code> method.
     * <p/>
     * If a validator is defined for this preferences in the
     * deployment descriptor, this validator is called before
     * the actual store is performed to check wether the given
     * preferences are vaild. If this check fails a
     * <code>ValidatorException</code> is thrown.
     *
     * @throws java.io.IOException if changes cannot be written into
     *                             the backend store
     * @throws javax.portlet.ValidatorException
     *                             if the validation performed by the
     *                             associated validator fails
     * @throws java.lang.IllegalStateException
     *                             if this method is called inside a render call
     * @see javax.portlet.PreferencesValidator
     */
    public void store() throws java.io.IOException, ValidatorException {
        if (isRender) throw new IllegalStateException("Cannot persist PortletPreferences in render method!");
        if (validator != null) validator.validate(this);
        try {
//            if (oid!=null) pm.saveOrUpdate(this); else pm.create(this);
            pm.saveOrUpdate(this);
        } catch (PersistenceManagerException e) {
            throw new IOException(e.getMessage());
        }
    }
项目:flashlight-search    文件:ConfigurationStorage.java   
/**
 * Saves the application's global settings
 *
 * @param adtUuid The ADT's UUID
 * @param doSearchOnStartup True to perform a search as soon as the portlet is displayed
 * @param doSearchOnStartupKeywords The keywords to send to the search if a search is triggered on startup
 * @param preferences The portlet preferences
 *
 * @throws ReadOnlyException If the configuration is read only
 * @throws ValidatorException If the configuration is invalid
 * @throws IOException If the configuration fails to save
 */
public void saveGlobalSettings(String adtUuid, boolean doSearchOnStartup, String doSearchOnStartupKeywords, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException;
项目:flashlight-search    文件:ConfigurationStorage.java   
/**
 * Writes the given configuration tab model into the configuration. No format validation is performed at this level.
 * It is the developer's responsibility to send data that is in the expected format.
 *
 * Also, this method does not alter facet configurations. It only alters which facets are selected.
 *
 * @param configurationTab The configuration tab model
 * @param preferences The portlet preferences
 *
 * @throws ReadOnlyException If the configuration is read only
 * @throws ValidatorException If the configuration is invalid
 * @throws IOException If the configuration fails to save
 */
public void saveConfigurationTab(FlashlightSearchConfigurationTab configurationTab, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException;
项目:flashlight-search    文件:ConfigurationStorage.java   
/**
 * Delete the given configuration tab
 *
 * @param tabId The tab's unique ID
 * @param preferences The portlet preferences
 *
 * @throws ReadOnlyException If the configuration is read only
 * @throws ValidatorException If the configuration is invalid
 * @throws IOException If the configuration fails to save
 */
public void deleteConfigurationTab(String tabId, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException;
项目:flashlight-search    文件:ConfigurationStorage.java   
/**
 * Writes the given facet configuration into the tab's configuration. No format validation is performed at this
 * level.
 *
 * @param configurationTab The tab for which we configure facets
 * @param searchFacet The facet to save
 * @param preferences The portlet preferences
 *
 * @throws ReadOnlyException If the configuration is read only
 * @throws ValidatorException If the configuration is invalid
 * @throws IOException If the configuration fails to save
 */
public void saveSearchFacetConfig(FlashlightSearchConfigurationTab configurationTab, SearchFacet searchFacet, PortletPreferences preferences) throws ReadOnlyException, ValidatorException, IOException;
项目:portals-pluto    文件:PortletPreferencesService.java   
/**
 * 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;
项目:portals-pluto    文件:TestPreferencesValidator.java   
@Override
public void validate(PortletPreferences arg0) throws ValidatorException {

}
项目:GridSphere    文件:PreferencesValidatorImpl.java   
/**
 * If the preferences values are successfully validated the call to this method
 * must finish gracefully. Otherwise it must throw a <code>ValidatorException</code>.
 *
 * @param preferences preferences to validate
 * @throws ValidatorException if the given preferences contains invalid
 *                            settings
 */

public void validate(PortletPreferences preferences)
        throws ValidatorException {
    // TODO
}