KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > logging > LoggingElementListObserver


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: LoggingElementListObserver.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.logging;
21
22 import java.util.List JavaDoc;
23 import java.util.ListIterator JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.fop.layoutmgr.ListElement;
28 import org.apache.fop.layoutmgr.ElementListObserver.Observer;
29
30 /**
31  * <p>Logs all observed element lists.
32  * </p>
33  * <p>You can enable/disabled individual categories separately, for example for JDK 1.4 logging:
34  * </p>
35  * <p>org.apache.fop.logging.LoggingElementListObserver.level = INFO</p>
36  * <p>org.apache.fop.logging.LoggingElementListObserver.table-cell.level = FINE</p>
37  */

38 public class LoggingElementListObserver implements Observer {
39
40     /** @see org.apache.fop.layoutmgr.ElementListObserver.Observer */
41     public void observe(List JavaDoc elementList, String JavaDoc category, String JavaDoc id) {
42         Log log = LogFactory.getLog(LoggingElementListObserver.class.getName() + "." + category);
43         if (!log.isDebugEnabled()) {
44             return;
45         }
46         log.debug(" ");
47         log.debug("ElementList: category=" + category + ", id=" + id);
48         if (elementList == null) {
49             log.debug("<<empty list>>");
50             return;
51         }
52         ListIterator JavaDoc tempIter = elementList.listIterator();
53         ListElement temp;
54         while (tempIter.hasNext()) {
55             temp = (ListElement) tempIter.next();
56             if (temp.isBox()) {
57                 log.debug(tempIter.previousIndex()
58                         + ") " + temp);
59             } else if (temp.isGlue()) {
60                 log.debug(tempIter.previousIndex()
61                         + ") " + temp);
62             } else {
63                 log.debug(tempIter.previousIndex()
64                         + ") " + temp);
65             }
66             if (temp.getPosition() != null) {
67                 log.debug(" " + temp.getPosition());
68             }
69         }
70         log.debug(" ");
71     }
72
73 }
74
Popular Tags