KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > properties > TextDecorationProperty


1 /*
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */

17 package org.apache.fop.fo.properties;
18
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21
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;
27
28 /**
29  * Special list property for text-decoration.
30  */

31 public class TextDecorationProperty extends ListProperty {
32
33     /**
34      * Inner class for creating instances of ListProperty
35      */

36     public static class Maker extends PropertyMaker {
37
38         /**
39          * @param propId ID of the property for which Maker should be created
40          */

41         public Maker(int propId) {
42             super(propId);
43         }
44
45         /**
46          * @see PropertyMaker#convertProperty
47          */

48         public Property convertProperty(Property p,
49                                         PropertyList propertyList, FObj fo)
50                     throws PropertyException {
51             if (p instanceof TextDecorationProperty) {
52                 return p;
53             } else {
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);
61                 } else {
62                     throw new PropertyException("Cannot convert anything other "
63                             + "than a list property, got a " + p.getClass().getName());
64                 }
65             }
66         }
67
68         private ListProperty checkEnums(ListProperty lst) throws PropertyException {
69             List JavaDoc l = lst.getList();
70             for (int i = 0; i < l.size(); i++) {
71                 Property prop = (Property)l.get(i);
72                 if (prop instanceof EnumProperty) {
73                     //skip
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());
78                     }
79                     l.set(i, prop_enum);
80                 } else {
81                     throw new PropertyException("Invalid content for text-decoration "
82                             + "property: " + prop);
83                 }
84             }
85             return lst;
86         }
87         
88     }
89
90     /**
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
94      */

95     public TextDecorationProperty(ListProperty listProp) throws PropertyException {
96         List JavaDoc lst = listProp.getList();
97         boolean none = false;
98         boolean under = false;
99         boolean over = false;
100         boolean through = false;
101         boolean blink = false;
102         Iterator JavaDoc 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");
110                     }
111                     none = true;
112                     break;
113                 case Constants.EN_UNDERLINE:
114                 case Constants.EN_NO_UNDERLINE:
115                     if (none) {
116                         throw new PropertyException("'none' specified, no additional values allowed");
117                     }
118                     if (under) {
119                         throw new PropertyException("Invalid combination of values");
120                     }
121                     under = true;
122                     break;
123                 case Constants.EN_OVERLINE:
124                 case Constants.EN_NO_OVERLINE:
125                     if (none) {
126                         throw new PropertyException("'none' specified, no additional values allowed");
127                     }
128                     if (over) {
129                         throw new PropertyException("Invalid combination of values");
130                     }
131                     over = true;
132                     break;
133                 case Constants.EN_LINE_THROUGH:
134                 case Constants.EN_NO_LINE_THROUGH:
135                     if (none) {
136                         throw new PropertyException("'none' specified, no additional values allowed");
137                     }
138                     if (through) {
139                         throw new PropertyException("Invalid combination of values");
140                     }
141                     through = true;
142                     break;
143                 case Constants.EN_BLINK:
144                 case Constants.EN_NO_BLINK:
145                     if (none) {
146                         throw new PropertyException("'none' specified, no additional values allowed");
147                     }
148                     if (blink) {
149                         throw new PropertyException("Invalid combination of values");
150                     }
151                     blink = true;
152                     break;
153                 default:
154                     throw new PropertyException("Invalid value specified: " + prop);
155             }
156             addProperty(prop);
157         }
158     }
159     
160 }
161
Popular Tags