2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
package org.apache.fop.fo.properties;
19
import java.util.Iterator;
20
import java.util.List;
22
import org.apache.fop.fo.Constants;
23
import org.apache.fop.fo.FObj;
24
import org.apache.fop.fo.PropertyList;
25
import org.apache.fop.fo.expr.NCnameProperty;
26
import org.apache.fop.fo.expr.PropertyException;
29
* Special list property for text-decoration.
31
public class TextDecorationProperty extends ListProperty {
34
* Inner class for creating instances of ListProperty
36
public static class Maker extends PropertyMaker {
39
* @param propId ID of the property for which Maker should be created
41
public Maker(int propId) {
48
public Property convertProperty(Property p,
49
PropertyList propertyList, FObj fo)
50
throws PropertyException {
51
if (p instanceof TextDecorationProperty) {
54
if (p instanceof ListProperty) {
55
ListProperty lst = (ListProperty)p;
56
lst = checkEnums(lst);
57
return new TextDecorationProperty((ListProperty)p);
58
} else if (p instanceof EnumProperty) {
59
ListProperty lst = new ListProperty(p);
60
return new TextDecorationProperty(lst);
62
throw new PropertyException("Cannot convert anything other "
63
+ "than a list property, got a " + p.getClass().getName());
68
private ListProperty checkEnums(ListProperty lst) throws PropertyException {
69
List l = lst.getList();
70
for (int i = 0; i < l.size(); i++) {
71
Property prop = (Property)l.get(i);
72
if (prop instanceof EnumProperty) {
74
} else if (prop instanceof NCnameProperty) {
75
Property prop_enum = checkEnumValues(((NCnameProperty)prop).getString());
76
if (prop_enum == null) {
77
throw new PropertyException("Illegal enum value: " + prop.getString());
81
throw new PropertyException("Invalid content for text-decoration "
82
+ "property: " + prop);
91
* Constructs a new instance by converting a ListProperty.
92
* @param listProp the ListProperty to be converted
93
* @throws PropertyException in case the conversion fails
95
public TextDecorationProperty(ListProperty listProp) throws PropertyException {
96
List lst = listProp.getList();
98
boolean under = false;
100
boolean through = false;
101
boolean blink = false;
102
Iterator i = lst.iterator();
103
while (i.hasNext()) {
104
Property prop = (Property)i.next();
105
switch (prop.getEnum()) {
106
case Constants.EN_NONE:
107
if (under | over | through | blink) {
108
throw new PropertyException(
109
"Invalid combination of values");
113
case Constants.EN_UNDERLINE:
114
case Constants.EN_NO_UNDERLINE:
116
throw new PropertyException("'none' specified, no additional values allowed");
119
throw new PropertyException("Invalid combination of values");
123
case Constants.EN_OVERLINE:
124
case Constants.EN_NO_OVERLINE:
126
throw new PropertyException("'none' specified, no additional values allowed");
129
throw new PropertyException("Invalid combination of values");
133
case Constants.EN_LINE_THROUGH:
134
case Constants.EN_NO_LINE_THROUGH:
136
throw new PropertyException("'none' specified, no additional values allowed");
139
throw new PropertyException("Invalid combination of values");
143
case Constants.EN_BLINK:
144
case Constants.EN_NO_BLINK:
146
throw new PropertyException("'none' specified, no additional values allowed");
149
throw new PropertyException("Invalid combination of values");
154
throw new PropertyException("Invalid value specified: " + prop);