01: package org.apache.anakia;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21:
22: import java.io.IOException;
23: import java.io.StringWriter;
24:
25: import org.jdom.Element;
26: import org.jdom.output.XMLOutputter;
27: import org.jdom.output.Format;
28:
29: /**
30: * This class extends XMLOutputter in order to provide
31: * a way to walk an Element tree into a String.
32: *
33: * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
34: * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
35: * @version $Id: OutputWrapper.java 524478 2007-03-31 20:51:49Z wglass $
36: */
37: public class OutputWrapper extends XMLOutputter {
38: /**
39: * Empty constructor
40: */
41: public OutputWrapper() {
42: }
43:
44: /**
45: * @param f
46: */
47: public OutputWrapper(Format f) {
48: super (f);
49: }
50:
51: /**
52: * This method walks an Element tree into a String. The cool
53: * thing about it is that it will strip off the first Element.
54: * For example, if you have:
55: * <p>
56: * <td> foo <strong>bar</strong> ack </td>
57: * </p>
58: * It will output
59: * <p>
60: * foo <strong>bar</strong> ack </td>
61: * </p>
62: * @param element
63: * @param strip
64: * @return The output string.
65: */
66: public String outputString(Element element, boolean strip) {
67: StringWriter buff = new StringWriter();
68:
69: try {
70: outputElementContent(element, buff);
71: } catch (IOException e) {
72: }
73: return buff.toString();
74: }
75: }
|