KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > fo > InlineCharIterator


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: InlineCharIterator.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.fo;
21
22 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
23 import org.apache.fop.util.CharUtilities;
24 import java.util.NoSuchElementException JavaDoc;
25
26 /**
27  * A recursive char iterator that indicates boundaries by returning
28  * an EOT char.
29  */

30 public class InlineCharIterator extends RecursiveCharIterator {
31     private boolean startBoundary = false;
32     private boolean endBoundary = false;
33
34     /**
35      * @param fobj the object for whose character contents and for whose
36      * descendant's character contents should be iterated
37      * @param bpb the CommonBorderPaddingBackground properties to be applied
38      */

39     public InlineCharIterator(FObj fobj, CommonBorderPaddingBackground bpb) {
40         super(fobj);
41         checkBoundaries(bpb);
42     }
43
44
45     private void checkBoundaries(CommonBorderPaddingBackground bpb) {
46         /* Current understanding is that an <fo:inline> is always a boundary for
47          * whitespace collapse if it has a border or not
48         startBoundary = (bpb.getBorderStartWidth(false) > 0
49                        || bpb.getPaddingStart(false, null) > 0); // TODO do we need context here?
50         endBoundary = (bpb.getBorderEndWidth(false) > 0
51                      || bpb.getPaddingEnd(false, null) > 0); // TODO do we need context here?
52          */

53         startBoundary = true;
54         endBoundary = true;
55     }
56
57     /**
58      * @return true if there are more characters
59      */

60     public boolean hasNext() {
61         if (startBoundary) {
62             return true;
63         }
64         return (super.hasNext() || endBoundary);
65         /* If super.hasNext() returns false,
66          * we return true if we are going to return a "boundary" signal
67          * else false.
68          */

69     }
70
71     /**
72      * @return the next character
73      * @throws NoSuchElementException if there are no more characters
74      */

75     public char nextChar() throws NoSuchElementException JavaDoc {
76         if (startBoundary) {
77             startBoundary = false;
78             return CharUtilities.CODE_EOT;
79         }
80         try {
81             return super.nextChar();
82         } catch (NoSuchElementException JavaDoc e) {
83             // Underlying has nothing more to return
84
// Check end boundary char
85
if (endBoundary) {
86                 endBoundary = false;
87                 return CharUtilities.CODE_EOT;
88             } else {
89                 throw e;
90             }
91         }
92     }
93 }
94
95
Popular Tags