Skip to content

Commit d5200b3

Browse files
Move InputType default to config #11418
save changes
1 parent c76e523 commit d5200b3

File tree

22 files changed

+10
-465
lines changed

22 files changed

+10
-465
lines changed

modules/core/core-api/src/main/java/com/enonic/xp/form/Input.java

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import com.enonic.xp.annotation.PublicApi;
99
import com.enonic.xp.inputtype.InputTypeConfig;
10-
import com.enonic.xp.inputtype.InputTypeDefault;
1110
import com.enonic.xp.inputtype.InputTypeName;
1211
import com.enonic.xp.inputtype.InputTypeProperty;
1312

@@ -25,8 +24,6 @@ public final class Input
2524

2625
private final String labelI18nKey;
2726

28-
private final InputTypeDefault defaultValue;
29-
3027
private final Occurrences occurrences;
3128

3229
private final String helpText;
@@ -48,7 +45,6 @@ private Input( Builder builder )
4845
this.type = builder.inputType;
4946
this.label = builder.label;
5047
this.labelI18nKey = builder.labelI18nKey;
51-
this.defaultValue = builder.defaultValue;
5248
this.occurrences = builder.occurrences;
5349
this.helpText = builder.helpText;
5450
this.helpTextI18nKey = builder.helpTextI18nKey;
@@ -77,11 +73,6 @@ public String getLabel()
7773
return label;
7874
}
7975

80-
public InputTypeDefault getDefaultValue()
81-
{
82-
return defaultValue;
83-
}
84-
8576
public boolean isRequired()
8677
{
8778
return occurrences.impliesRequired();
@@ -137,16 +128,16 @@ public boolean equals( final Object o )
137128

138129
final Input that = (Input) o;
139130
return super.equals( o ) && Objects.equals( this.type, that.type ) && Objects.equals( this.label, that.label ) &&
140-
Objects.equals( this.defaultValue, that.defaultValue ) && Objects.equals( this.occurrences, that.occurrences ) &&
141-
Objects.equals( this.helpText, that.helpText ) && Objects.equals( this.inputTypeConfig, that.inputTypeConfig ) &&
142-
Objects.equals( this.helpTextI18nKey, that.helpTextI18nKey ) && Objects.equals( this.labelI18nKey, that.labelI18nKey );
131+
Objects.equals( this.occurrences, that.occurrences ) && Objects.equals( this.helpText, that.helpText ) &&
132+
Objects.equals( this.inputTypeConfig, that.inputTypeConfig ) && Objects.equals( this.helpTextI18nKey, that.helpTextI18nKey ) &&
133+
Objects.equals( this.labelI18nKey, that.labelI18nKey );
143134
}
144135

145136
@Override
146137
public int hashCode()
147138
{
148-
return Objects.hash( super.hashCode(), this.type, this.label, this.defaultValue, this.occurrences, this.helpText,
149-
this.inputTypeConfig, this.labelI18nKey, this.helpTextI18nKey );
139+
return Objects.hash( super.hashCode(), this.type, this.label, this.occurrences, this.helpText, this.inputTypeConfig,
140+
this.labelI18nKey, this.helpTextI18nKey );
150141
}
151142

152143
public static Builder create()
@@ -169,8 +160,6 @@ public static final class Builder
169160

170161
private String labelI18nKey;
171162

172-
private InputTypeDefault defaultValue;
173-
174163
private Occurrences occurrences = Occurrences.create( 0, 1 );
175164

176165
private String helpText;
@@ -188,7 +177,6 @@ private Builder( final Input source )
188177
this.name = source.name;
189178
this.inputType = source.type;
190179
this.label = source.label;
191-
this.defaultValue = source.defaultValue;
192180
this.occurrences = source.occurrences;
193181
this.helpText = source.helpText;
194182
this.labelI18nKey = source.labelI18nKey;
@@ -224,12 +212,6 @@ public Builder labelI18nKey( String value )
224212
return this;
225213
}
226214

227-
public Builder defaultValue( InputTypeDefault value )
228-
{
229-
defaultValue = value;
230-
return this;
231-
}
232-
233215
public Builder occurrences( Occurrences value )
234216
{
235217
occurrences = value;

modules/core/core-api/src/main/java/com/enonic/xp/inputtype/CheckBoxType.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@
55
import com.enonic.xp.data.Value;
66
import com.enonic.xp.data.ValueFactory;
77
import com.enonic.xp.data.ValueTypes;
8-
import com.enonic.xp.form.Input;
9-
10-
import static com.google.common.base.Strings.isNullOrEmpty;
118

129
@PublicApi
1310
final class CheckBoxType
1411
extends InputTypeBase
1512
{
1613
public static final CheckBoxType INSTANCE = new CheckBoxType();
1714

18-
private static final String VALID_VALUE = "checked";
19-
2015
private CheckBoxType()
2116
{
2217
super( InputTypeName.CHECK_BOX );
@@ -28,21 +23,6 @@ public Value createValue( final Value value, final InputTypeConfig config )
2823
return ValueFactory.newBoolean( value.asBoolean() );
2924
}
3025

31-
@Override
32-
public Value createDefaultValue( final Input input )
33-
{
34-
final String defaultValue = input.getDefaultValue().getRootValue();
35-
36-
if ( !isNullOrEmpty( defaultValue ) )
37-
{
38-
if ( VALID_VALUE.equals( defaultValue ) )
39-
{
40-
return ValueFactory.newBoolean( true );
41-
}
42-
}
43-
return super.createDefaultValue( input );
44-
}
45-
4626
@Override
4727
public void validate( final Property property, final InputTypeConfig config )
4828
{

modules/core/core-api/src/main/java/com/enonic/xp/inputtype/ComboBoxType.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
import com.enonic.xp.data.Value;
77
import com.enonic.xp.data.ValueFactory;
88
import com.enonic.xp.data.ValueTypes;
9-
import com.enonic.xp.form.Input;
10-
11-
import static com.google.common.base.Strings.isNullOrEmpty;
129

1310
final class ComboBoxType
1411
extends InputTypeBase
@@ -26,17 +23,6 @@ public Value createValue( final Value value, final InputTypeConfig config )
2623
return ValueFactory.newString( value.asString() );
2724
}
2825

29-
@Override
30-
public Value createDefaultValue( final Input input )
31-
{
32-
final String defaultValue = input.getDefaultValue().getRootValue();
33-
if ( !isNullOrEmpty( defaultValue ) )
34-
{
35-
return ValueFactory.newString( defaultValue );
36-
}
37-
return super.createDefaultValue( input );
38-
}
39-
4026
@Override
4127
public void validate( final Property property, final InputTypeConfig config )
4228
{

modules/core/core-api/src/main/java/com/enonic/xp/inputtype/CustomSelectorType.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
import com.enonic.xp.data.Value;
55
import com.enonic.xp.data.ValueFactory;
66
import com.enonic.xp.data.ValueTypes;
7-
import com.enonic.xp.form.Input;
8-
9-
import static com.google.common.base.Strings.isNullOrEmpty;
107

118
final class CustomSelectorType
129
extends InputTypeBase
@@ -18,17 +15,6 @@ private CustomSelectorType()
1815
super( InputTypeName.CUSTOM_SELECTOR );
1916
}
2017

21-
@Override
22-
public Value createDefaultValue( final Input input )
23-
{
24-
final String defaultValue = input.getDefaultValue().getRootValue();
25-
if ( !isNullOrEmpty( defaultValue ) )
26-
{
27-
return ValueFactory.newString( defaultValue );
28-
}
29-
return super.createDefaultValue( input );
30-
}
31-
3218
@Override
3319
public Value createValue( final Value value, final InputTypeConfig config )
3420
{

modules/core/core-api/src/main/java/com/enonic/xp/inputtype/DateTimeType.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import com.enonic.xp.data.Property;
55
import com.enonic.xp.data.Value;
66
import com.enonic.xp.data.ValueFactory;
7-
import com.enonic.xp.data.ValueTypeException;
87
import com.enonic.xp.data.ValueTypes;
9-
import com.enonic.xp.form.Input;
108

119
@PublicApi
1210
final class DateTimeType
@@ -25,34 +23,9 @@ public Value createValue( final Value value, final InputTypeConfig config )
2523
return ValueFactory.newLocalDateTime( value.asLocalDateTime() );
2624
}
2725

28-
@Override
29-
public Value createDefaultValue( final Input input )
30-
{
31-
final String defaultValue = input.getDefaultValue().getRootValue();
32-
33-
if ( defaultValue != null )
34-
{
35-
return parseLocalDateTime( defaultValue );
36-
}
37-
38-
return super.createDefaultValue( input );
39-
}
40-
4126
@Override
4227
public void validate( final Property property, final InputTypeConfig config )
4328
{
4429
validateType( property, ValueTypes.LOCAL_DATE_TIME );
4530
}
46-
47-
private Value parseLocalDateTime( final String value )
48-
{
49-
try
50-
{
51-
return ValueFactory.newLocalDateTime( ValueTypes.LOCAL_DATE_TIME.convert( value ) );
52-
}
53-
catch ( ValueTypeException e )
54-
{
55-
throw new IllegalArgumentException( String.format( "Invalid DateTime format: %s", value ) );
56-
}
57-
}
5831
}

modules/core/core-api/src/main/java/com/enonic/xp/inputtype/DateType.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package com.enonic.xp.inputtype;
22

3-
import java.time.LocalDate;
4-
import java.time.Period;
5-
63
import com.enonic.xp.data.Property;
74
import com.enonic.xp.data.Value;
85
import com.enonic.xp.data.ValueFactory;
9-
import com.enonic.xp.data.ValueTypeException;
106
import com.enonic.xp.data.ValueTypes;
11-
import com.enonic.xp.form.Input;
127

138
final class DateType
149
extends InputTypeBase
@@ -26,37 +21,6 @@ public Value createValue( final Value value, final InputTypeConfig config )
2621
return ValueFactory.newLocalDate( value.asLocalDate() );
2722
}
2823

29-
@Override
30-
public Value createDefaultValue( final Input input )
31-
{
32-
final String defaultValue = input.getDefaultValue().getRootValue();
33-
if ( defaultValue != null )
34-
{
35-
try
36-
{
37-
return ValueFactory.newLocalDate( ValueTypes.LOCAL_DATE.convert( defaultValue ) );
38-
}
39-
catch ( ValueTypeException e )
40-
{
41-
final RelativeTime result = RelativeTimeParser.parse( defaultValue );
42-
43-
if ( result != null )
44-
{
45-
final Period period = result.getDate();
46-
final LocalDate localDate =
47-
LocalDate.now().plusYears( period.getYears() ).plusMonths( period.getMonths() ).plusDays( period.getDays() );
48-
return ValueFactory.newLocalDate( localDate );
49-
}
50-
else
51-
{
52-
throw new IllegalArgumentException( "Invalid Date format: " + defaultValue );
53-
}
54-
55-
}
56-
}
57-
return super.createDefaultValue( input );
58-
}
59-
6024
@Override
6125
public void validate( final Property property, final InputTypeConfig config )
6226
{

modules/core/core-api/src/main/java/com/enonic/xp/inputtype/DoubleType.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
import com.enonic.xp.data.Value;
99
import com.enonic.xp.data.ValueFactory;
1010
import com.enonic.xp.data.ValueTypes;
11-
import com.enonic.xp.form.Input;
12-
13-
import static com.google.common.base.Strings.isNullOrEmpty;
1411

1512
final class DoubleType
1613
extends InputTypeBase
@@ -30,17 +27,6 @@ public Value createValue( final Value value, final InputTypeConfig config )
3027
return ValueFactory.newDouble( value.asDouble() );
3128
}
3229

33-
@Override
34-
public Value createDefaultValue( final Input input )
35-
{
36-
final String defaultValue = input.getDefaultValue().getRootValue();
37-
if ( !isNullOrEmpty( defaultValue ) )
38-
{
39-
return ValueFactory.newDouble( Double.valueOf( defaultValue ) );
40-
}
41-
return super.createDefaultValue( input );
42-
}
43-
4430
@Override
4531
public void validate( final Property property, final InputTypeConfig config )
4632
{

modules/core/core-api/src/main/java/com/enonic/xp/inputtype/GeoPointType.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import com.enonic.xp.data.Value;
55
import com.enonic.xp.data.ValueFactory;
66
import com.enonic.xp.data.ValueTypes;
7-
import com.enonic.xp.form.Input;
8-
import com.enonic.xp.util.GeoPoint;
97

108
final class GeoPointType
119
extends InputTypeBase
@@ -23,16 +21,6 @@ public Value createValue( final Value value, final InputTypeConfig config )
2321
return ValueFactory.newGeoPoint( value.asGeoPoint() );
2422
}
2523

26-
@Override
27-
public Value createDefaultValue( final Input input )
28-
{
29-
final String rootValue = input.getDefaultValue().getRootValue();
30-
if ( rootValue != null )
31-
{
32-
return ValueFactory.newGeoPoint( GeoPoint.from(rootValue) );
33-
}
34-
return super.createDefaultValue( input );
35-
}
3624
@Override
3725
public void validate( final Property property, final InputTypeConfig config )
3826
{

modules/core/core-api/src/main/java/com/enonic/xp/inputtype/HtmlAreaType.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.enonic.xp.data.Value;
55
import com.enonic.xp.data.ValueFactory;
66
import com.enonic.xp.data.ValueTypes;
7-
import com.enonic.xp.form.Input;
87

98
final class HtmlAreaType
109
extends InputTypeBase
@@ -16,17 +15,6 @@ private HtmlAreaType()
1615
super( InputTypeName.HTML_AREA );
1716
}
1817

19-
@Override
20-
public Value createDefaultValue( final Input input )
21-
{
22-
final String rootValue = input.getDefaultValue().getRootValue();
23-
if ( rootValue != null )
24-
{
25-
return ValueFactory.newString( rootValue );
26-
}
27-
return super.createDefaultValue( input );
28-
}
29-
3018
@Override
3119
public Value createValue( final Value value, final InputTypeConfig config )
3220
{

modules/core/core-api/src/main/java/com/enonic/xp/inputtype/InputType.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.enonic.xp.annotation.PublicApi;
44
import com.enonic.xp.data.Property;
55
import com.enonic.xp.data.Value;
6-
import com.enonic.xp.form.Input;
76

87
@PublicApi
98
public interface InputType
@@ -12,7 +11,5 @@ public interface InputType
1211

1312
Value createValue( Value value, InputTypeConfig config );
1413

15-
Value createDefaultValue( Input input );
16-
1714
void validate( Property property, InputTypeConfig config );
1815
}

0 commit comments

Comments
 (0)