KickJava   Java API By Example, From Geeks To Geeks.

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


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: GenericShorthandParser.java 454018 2006-10-07 21:00:13Z pietsch $ */
19
20 package org.apache.fop.fo.properties;
21
22 import java.util.Iterator JavaDoc;
23
24 import org.apache.fop.fo.PropertyList;
25 import org.apache.fop.fo.expr.PropertyException;
26
27 /**
28  * Generic shorthand parser for ListProperties
29  */

30 public class GenericShorthandParser implements ShorthandParser {
31
32     /**
33      * Constructor.
34      */

35     public GenericShorthandParser() {
36     }
37
38     /**
39      * @param list the ListProperty
40      * @param index the index into the List of properties
41      * @return the property from the List of properties at the index parameter
42      */

43     protected Property getElement(Property list, int index) {
44         if (list.getList().size() > index) {
45             return (Property) list.getList().get(index);
46         } else {
47             return null;
48         }
49     }
50     
51     /**
52      * @see org.apache.fop.fo.properties.ShorthandParser#getValueForProperty(int, Property, PropertyMaker, PropertyList)
53      */

54     public Property getValueForProperty(int propId,
55                                         Property property,
56                                         PropertyMaker maker,
57                                         PropertyList propertyList)
58                     throws PropertyException {
59         // Check for keyword "inherit"
60
if (property.getList().size() == 1) {
61             String JavaDoc sval = getElement(property, 0).getString();
62             if (sval != null && sval.equals("inherit")) {
63                 return propertyList.getFromParent(propId);
64             }
65         }
66         return convertValueForProperty(propId, property, maker, propertyList);
67     }
68
69
70     /**
71      * Converts a property name into a Property
72      * @param propId the property ID in the Constants interface
73      * @param maker the Property.Maker to be used in the conversion
74      * @param property ...
75      * @param propertyList the PropertyList from which the Property should be
76      * extracted
77      * @return the Property matching the parameters, or null if not found
78      * @throws PropertyException (when?)
79      */

80     protected Property convertValueForProperty(int propId,
81                                                Property property,
82                                                PropertyMaker maker,
83                                                PropertyList propertyList)
84                     throws PropertyException {
85         Property prop = null;
86         // Try each of the stored values in turn
87
Iterator JavaDoc iprop = property.getList().iterator();
88         while (iprop.hasNext() && prop == null) {
89             Property p = (Property)iprop.next();
90             prop = maker.convertShorthandProperty(propertyList, p, null);
91         }
92         return prop;
93     }
94
95 }
96
97
Popular Tags