01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: FromParentFunction.java 426576 2006-07-28 15:44:37Z jeremias $ */
19:
20: package org.apache.fop.fo.expr;
21:
22: import org.apache.fop.fo.FOPropertyMapping;
23: import org.apache.fop.fo.properties.Property;
24:
25: /**
26: * Class modelling the from-parent Property Value function. See Sec. 5.10.4 of
27: * the XSL-FO spec.
28: */
29: public class FromParentFunction extends FunctionBase {
30:
31: /**
32: * @return 1 (maximum arguments for the from-parent function)
33: */
34: public int nbArgs() {
35: return 1;
36: }
37:
38: /**
39: * @return true (allow padding of arglist with property name)
40: */
41: public boolean padArgsWithPropertyName() {
42: return true;
43: }
44:
45: /**
46: * @param args array of arguments, which should either be empty, or the
47: * first of which should contain an NCName corresponding to property name
48: * @param pInfo PropertyInfo object to be evaluated
49: * @return property containing the computed value
50: * @throws PropertyException if the arguments are incorrect
51: */
52: public Property eval(Property[] args, PropertyInfo pInfo)
53: throws PropertyException {
54: String propName = args[0].getString();
55: if (propName == null) {
56: throw new PropertyException(
57: "Incorrect parameter to from-parent function");
58: }
59: // NOTE: special cases for shorthand property
60: // Should return COMPUTED VALUE
61: /*
62: * For now, this is the same as inherited-property-value(propName)
63: * (The only difference I can see is that this could work for
64: * non-inherited properties too. Perhaps the result is different for
65: * a property line line-height which "inherits specified"???
66: */
67: return pInfo.getPropertyList().getFromParent(
68: FOPropertyMapping.getPropertyId(propName));
69: }
70:
71: }
|