KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fotreetest > ext > AssertElement


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: AssertElement.java 433456 2006-08-22 01:39:35Z adelmelle $ */
19  
20 package org.apache.fop.fotreetest.ext;
21
22
23 import org.apache.fop.apps.FOPException;
24 import org.apache.fop.fo.FONode;
25 import org.apache.fop.fo.FOPropertyMapping;
26 import org.apache.fop.fo.PropertyList;
27 import org.apache.fop.fo.properties.KeepProperty;
28 import org.apache.fop.fo.properties.LengthPairProperty;
29 import org.apache.fop.fo.properties.LengthRangeProperty;
30 import org.apache.fop.fo.properties.Property;
31 import org.apache.fop.fo.properties.SpaceProperty;
32 import org.apache.fop.fotreetest.ResultCollector;
33
34 import org.xml.sax.Attributes JavaDoc;
35 import org.xml.sax.Locator JavaDoc;
36
37 /**
38  * Defines the assert element for the FOP Test extension.
39  */

40 public class AssertElement extends TestObj {
41
42     /**
43      * @see org.apache.fop.fo.FONode#FONode(FONode)
44      */

45     public AssertElement(FONode parent) {
46         super(parent);
47     }
48
49     /**
50      * @see org.apache.fop.fo.FONode#processNode
51      */

52     public void processNode(String JavaDoc elementName,
53                             Locator JavaDoc locator,
54                             Attributes JavaDoc attlist,
55                             PropertyList propertyList) throws FOPException {
56         //super.processNode(elementName, locator, attlist, propertyList);
57

58         ResultCollector collector = ResultCollector.getInstance();
59         String JavaDoc propName = attlist.getValue("property");
60         String JavaDoc component = null;
61         int dotIndex = propName.indexOf('.');
62         if (dotIndex >= 0) {
63             component = propName.substring(dotIndex + 1);
64             propName = propName.substring(0, dotIndex);
65         }
66         int propID = FOPropertyMapping.getPropertyId(propName);
67         if (propID < 0) {
68             collector.notifyException(new IllegalArgumentException JavaDoc(
69                     "Property not found: " + propName));
70         } else {
71             Property prop;
72             prop = propertyList.getParentPropertyList().get(propID);
73             if (component != null) {
74                 //Access subcomponent
75
Property mainProp = prop;
76                 prop = null;
77                 LengthPairProperty lpp = mainProp.getLengthPair();
78                 if (lpp != null) {
79                     prop = lpp.getComponent(FOPropertyMapping.getSubPropertyId(component));
80                 }
81                 LengthRangeProperty lrp = mainProp.getLengthRange();
82                 if (lrp != null) {
83                     prop = lrp.getComponent(FOPropertyMapping.getSubPropertyId(component));
84                 }
85                 KeepProperty kp = mainProp.getKeep();
86                 if (kp != null) {
87                     prop = kp.getComponent(FOPropertyMapping.getSubPropertyId(component));
88                 }
89                 SpaceProperty sp = mainProp.getSpace();
90                 if (sp != null) {
91                     prop = sp.getComponent(FOPropertyMapping.getSubPropertyId(component));
92                 }
93             }
94             String JavaDoc s = String.valueOf(prop);
95             String JavaDoc expected = attlist.getValue("expected");
96             if (!expected.equals(s)) {
97                 collector.notifyException(
98                     new IllegalStateException JavaDoc(locator.getSystemId()
99                         + "\nProperty '" + propName
100                         + "' expected to evaluate to '" + expected
101                         + "' but got '" + s
102                         + "'\n(test:assert in "
103                         + propertyList.getParentFObj().getName()
104                         + " at line #" + locator.getLineNumber()
105                         + ", column #" + locator.getColumnNumber() + ")\n"));
106             }
107         }
108         
109     }
110
111     /** @see org.apache.fop.fo.FONode#getLocalName() */
112     public String JavaDoc getLocalName() {
113         return "assert";
114     }
115     
116 }
117
118
Popular Tags