~ubuntu-branches/ubuntu/saucy/fop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/java/org/apache/fop/fo/properties/TextDecorationMaker.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-05-21 12:21:26 UTC
  • mfrom: (15.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130521122126-3c9r5fo6ountjg6r
Tags: 1:1.1.dfsg-2ubuntu1
* Merge from Debian unstable.  Remaining changes:
  -  Transition libservlet2.5-java -> libservlet3.0-java.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
18
/* $Id: TextDecorationMaker.java 1089559 2011-04-06 18:39:15Z adelmelle $ */
 
19
 
 
20
package org.apache.fop.fo.properties;
 
21
 
 
22
import java.util.List;
 
23
 
 
24
import org.apache.fop.fo.Constants;
 
25
import org.apache.fop.fo.FObj;
 
26
import org.apache.fop.fo.PropertyList;
 
27
import org.apache.fop.fo.expr.NCnameProperty;
 
28
import org.apache.fop.fo.expr.PropertyException;
 
29
 
 
30
/**
 
31
 * Dedicated {@link org.apache.fop.fo.properties.PropertyMaker} for handling the
 
32
 * <a href="http://www.w3.org/TR/xsl/#text-decoration"><code>text-decoration</code></a>
 
33
 * property.
 
34
 */
 
35
public class TextDecorationMaker extends ListProperty.Maker {
 
36
 
 
37
    /**
 
38
     * Create a maker for the given property id.
 
39
     * @param propId id of the property for which a maker should be created
 
40
     */
 
41
    public TextDecorationMaker(int propId) {
 
42
        super(propId);
 
43
    }
 
44
 
 
45
    /**
 
46
     * {@inheritDoc}
 
47
     * Add validation rules for the <code>text-decoration</code> property.
 
48
     */
 
49
    @Override
 
50
    public Property convertProperty(Property p,
 
51
                                    PropertyList propertyList,
 
52
                                    FObj fo)
 
53
                        throws PropertyException {
 
54
 
 
55
        ListProperty listProp = (ListProperty) super.convertProperty(p, propertyList, fo);
 
56
        List lst = listProp.getList();
 
57
        boolean none = false;
 
58
        boolean under = false;
 
59
        boolean over = false;
 
60
        boolean through = false;
 
61
        boolean blink = false;
 
62
        int enumValue = -1;
 
63
        for (int i = lst.size(); --i >= 0;) {
 
64
            Property prop = (Property)lst.get(i);
 
65
            if (prop instanceof NCnameProperty) {
 
66
                prop = checkEnumValues(prop.getString());
 
67
                lst.set(i, prop);
 
68
            }
 
69
            if (prop != null) {
 
70
                enumValue = prop.getEnum();
 
71
            }
 
72
            switch (enumValue) {
 
73
                case Constants.EN_NONE:
 
74
                    if (under | over | through | blink) {
 
75
                        throw new PropertyException("Invalid combination of values");
 
76
                    }
 
77
                    none = true;
 
78
                    break;
 
79
                case Constants.EN_UNDERLINE:
 
80
                case Constants.EN_NO_UNDERLINE:
 
81
                case Constants.EN_OVERLINE:
 
82
                case Constants.EN_NO_OVERLINE:
 
83
                case Constants.EN_LINE_THROUGH:
 
84
                case Constants.EN_NO_LINE_THROUGH:
 
85
                case Constants.EN_BLINK:
 
86
                case Constants.EN_NO_BLINK:
 
87
                    if (none) {
 
88
                        throw new PropertyException
 
89
                                ("'none' specified, no additional values allowed");
 
90
                    }
 
91
                    switch (enumValue) {
 
92
                        case Constants.EN_UNDERLINE:
 
93
                        case Constants.EN_NO_UNDERLINE:
 
94
                            if (!under) {
 
95
                                under = true;
 
96
                                continue;
 
97
                            }
 
98
                        case Constants.EN_OVERLINE:
 
99
                        case Constants.EN_NO_OVERLINE:
 
100
                            if (!over) {
 
101
                                over = true;
 
102
                                continue;
 
103
                            }
 
104
                        case Constants.EN_LINE_THROUGH:
 
105
                        case Constants.EN_NO_LINE_THROUGH:
 
106
                            if (!through) {
 
107
                                through = true;
 
108
                                continue;
 
109
                            }
 
110
                        case Constants.EN_BLINK:
 
111
                        case Constants.EN_NO_BLINK:
 
112
                            if (!blink) {
 
113
                                blink = true;
 
114
                                continue;
 
115
                            }
 
116
                        default:
 
117
                            throw new PropertyException("Invalid combination of values");
 
118
                    }
 
119
                default:
 
120
                    throw new PropertyException("Invalid value specified: " + p);
 
121
            }
 
122
        }
 
123
        return listProp;
 
124
    }
 
125
}