/* * Copyright 2000-2014 Vaadin Ltd. * * Licensed 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 com.vaadin.data; import java.io.Serializable; import com.vaadin.server.VaadinServlet; /** * Interface that implements a method for validating if an {@link Object} is * valid or not. *

* Implementors of this class can be added to any * {@link com.vaadin.data.Validatable Validatable} implementor to verify its * value. *

*

* {@link #validate(Object)} can be used to check if a value is valid. An * {@link InvalidValueException} with an appropriate validation error message is * thrown if the value is not valid. *

*

* Validators must not have any side effects. *

*

* Since Vaadin 7, the method isValid(Object) does not exist in the interface - * {@link #validate(Object)} should be used instead, and the exception caught * where applicable. Concrete classes implementing {@link Validator} can still * internally implement and use isValid(Object) for convenience or to ease * migration from earlier Vaadin versions. *

* * @author Vaadin Ltd. * @since 3.0 */ public interface Validator extends Serializable { /** * Checks the given value against this validator. If the value is valid the * method does nothing. If the value is invalid, an * {@link InvalidValueException} is thrown. * * @param value * the value to check * @throws Validator.InvalidValueException * if the value is invalid */ public void validate(Object value) throws Validator.InvalidValueException; /** * Exception that is thrown by a {@link Validator} when a value is invalid. * *

* The default implementation of InvalidValueException does not support HTML * in error messages. To enable HTML support, override * {@link #getHtmlMessage()} and use the subclass in validators. *

* * @author Vaadin Ltd. * @since 3.0 */ @SuppressWarnings("serial") public class InvalidValueException extends RuntimeException { /** * Array of one or more validation errors that are causing this * validation error. */ private InvalidValueException[] causes = null; /** * Constructs a new {@code InvalidValueException} with the specified * message. * * @param message * The detail message of the problem. */ public InvalidValueException(String message) { this(message, new InvalidValueException[] {}); } /** * Constructs a new {@code InvalidValueException} with a set of causing * validation exceptions. The causing validation exceptions are included * when the exception is painted to the client. * * @param message * The detail message of the problem. * @param causes * One or more {@code InvalidValueException}s that caused * this exception. */ public InvalidValueException(String message, InvalidValueException... causes) { super(message); if (causes == null) { throw new NullPointerException( "Possible causes array must not be null"); } this.causes = causes; } /** * Check if the error message should be hidden. * * An empty (null or "") message is invisible unless it contains nested * exceptions that are visible. * * @return true if the error message should be hidden, false otherwise */ public boolean isInvisible() { String msg = getMessage(); if (msg != null && msg.length() > 0) { return false; } if (causes != null) { for (int i = 0; i < causes.length; i++) { if (!causes[i].isInvisible()) { return false; } } } return true; } /** * Returns the message of the error in HTML. * * Note that this API may change in future versions. */ public String getHtmlMessage() { return VaadinServlet.safeEscapeForHtml(getLocalizedMessage()); } /** * Returns the {@code InvalidValueExceptions} that caused this * exception. * * @return An array containing the {@code InvalidValueExceptions} that * caused this exception. Returns an empty array if this * exception was not caused by other exceptions. */ public InvalidValueException[] getCauses() { return causes; } } /** * A specific type of {@link InvalidValueException} that indicates that * validation failed because the value was empty. What empty means is up to * the thrower. * * @author Vaadin Ltd. * @since 5.3.0 */ @SuppressWarnings("serial") public class EmptyValueException extends Validator.InvalidValueException { public EmptyValueException(String message) { super(message); } } } orage Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
aboutsummaryrefslogtreecommitdiffstats
path: root/apps/testing/lib/Settings/DeclarativeSettingsForm.php
blob: dd83e9c9e893de6d57cf3072ab18407d2d86fc77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php

declare(strict_types=1);
/**
 * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\Testing\Settings;

use OCP\Settings\DeclarativeSettingsTypes;
use OCP\Settings\IDeclarativeSettingsForm;

class DeclarativeSettingsForm implements IDeclarativeSettingsForm {
	public function getSchema(): array {
		return [
			'id' => 'test_declarative_form',
			'priority' => 10,
			'section_type' => DeclarativeSettingsTypes::SECTION_TYPE_ADMIN, // admin, personal
			'section_id' => 'additional',
			'storage_type' => DeclarativeSettingsTypes::STORAGE_TYPE_INTERNAL, // external, internal (handled by core to store in appconfig and preferences)
			'title' => 'Test declarative settings class', // NcSettingsSection name
			'description' => 'This form is registered with a DeclarativeSettingsForm class', // NcSettingsSection description
			'doc_url' => '', // NcSettingsSection doc_url for documentation or help page, empty string if not needed
			'fields' => [
				[
					'id' => 'test_ex_app_field_7', // configkey
					'title' => 'Multi-selection', // name or label
					'description' => 'Select some option setting', // hint
					'type' => DeclarativeSettingsTypes::MULTI_SELECT, // select, radio, multi-select
					'options' => ['foo', 'bar', 'baz'], // simple options for select, radio, multi-select
					'placeholder' => 'Select some multiple options', // input placeholder
					'default' => ['foo', 'bar'],
				],
				[
					'id' => 'some_real_setting',
					'title' => 'Choose init status check background job interval',
					'description' => 'How often AppAPI should check for initialization status',
					'type' => DeclarativeSettingsTypes::RADIO, // radio (NcCheckboxRadioSwitch type radio)
					'placeholder' => 'Choose init status check background job interval',
					'default' => '40m',
					'options' => [
						[
							'name' => 'Each 40 minutes', // NcCheckboxRadioSwitch display name
							'value' => '40m' // NcCheckboxRadioSwitch value
						],
						[
							'name' => 'Each 60 minutes',
							'value' => '60m'
						],
						[
							'name' => 'Each 120 minutes',
							'value' => '120m'
						],
						[
							'name' => 'Each day',
							'value' => 60 * 24 . 'm'
						],
					],
				],
				[
					'id' => 'test_ex_app_field_1', // configkey
					'title' => 'Default text field', // label
					'description' => 'Set some simple text setting', // hint
					'type' => DeclarativeSettingsTypes::TEXT, // text, password, email, tel, url, number
					'placeholder' => 'Enter text setting', // placeholder
					'default' => 'foo',
				],
				[
					'id' => 'test_ex_app_field_1_1',
					'title' => 'Email field',
					'description' => 'Set email config',
					'type' => DeclarativeSettingsTypes::EMAIL,
					'placeholder' => 'Enter email',
					'default' => '',
				],
				[
					'id' => 'test_ex_app_field_1_2',
					'title' => 'Tel field',
					'description' => 'Set tel config',
					'type' => DeclarativeSettingsTypes::TEL,
					'placeholder' => 'Enter your tel',
					'default' => '',
				],
				[
					'id' => 'test_ex_app_field_1_3',
					'title' => 'Url (website) field',
					'description' => 'Set url config',
					'type' => 'url',
					'placeholder' => 'Enter url',
					'default' => '',
				],
				[
					'id' => 'test_ex_app_field_1_4',
					'title' => 'Number field',
					'description' => 'Set number config',
					'type' => DeclarativeSettingsTypes::NUMBER,
					'placeholder' => 'Enter number value',
					'default' => 0,
				],
				[
					'id' => 'test_ex_app_field_2',
					'title' => 'Password',
					'description' => 'Set some secure value setting',
					'type' => 'password',
					'placeholder' => 'Set secure value',
					'default' => '',
				],
				[
					'id' => 'test_ex_app_field_3',
					'title' => 'Selection',
					'description' => 'Select some option setting',
					'type' => DeclarativeSettingsTypes::SELECT, // select, radio, multi-select
					'options' => ['foo', 'bar', 'baz'],
					'placeholder' => 'Select some option setting',
					'default' => 'foo',
				],
				[
					'id' => 'test_ex_app_field_4',
					'title' => 'Toggle something',
					'description' => 'Select checkbox option setting',
					'type' => DeclarativeSettingsTypes::CHECKBOX, // checkbox, multiple-checkbox
					'label' => 'Verify something if enabled',
					'default' => false,
				],
				[
					'id' => 'test_ex_app_field_5',
					'title' => 'Multiple checkbox toggles, describing one setting, checked options are saved as an JSON object {foo: true, bar: false}',
					'description' => 'Select checkbox option setting',
					'type' => DeclarativeSettingsTypes::MULTI_CHECKBOX, // checkbox, multi-checkbox
					'default' => ['foo' => true, 'bar' => true, 'baz' => true],
					'options' => [
						[
							'name' => 'Foo',
							'value' => 'foo', // multiple-checkbox configkey
						],
						[
							'name' => 'Bar',
							'value' => 'bar',
						],
						[
							'name' => 'Baz',
							'value' => 'baz',
						],
						[
							'name' => 'Qux',
							'value' => 'qux',
						],
					],
				],
				[
					'id' => 'test_ex_app_field_6',
					'title' => 'Radio toggles, describing one setting like single select',
					'description' => 'Select radio option setting',
					'type' => DeclarativeSettingsTypes::RADIO, // radio (NcCheckboxRadioSwitch type radio)
					'label' => 'Select single toggle',
					'default' => 'foo',
					'options' => [
						[
							'name' => 'First radio', // NcCheckboxRadioSwitch display name
							'value' => 'foo' // NcCheckboxRadioSwitch value
						],
						[
							'name' => 'Second radio',
							'value' => 'bar'
						],
						[
							'name' => 'Third radio',
							'value' => 'baz'
						],
					],
				],
			],
		];
	}
}