01: package com.xoetrope.export.html;
02:
03: import com.xoetrope.export.DataBinding;
04: import com.xoetrope.export.FragmentBlock;
05: import com.xoetrope.export.TagExporter;
06: import java.io.Reader;
07: import java.io.StringWriter;
08: import java.util.Vector;
09: import net.xoetrope.xml.XmlElement;
10: import net.xoetrope.xml.XmlSource;
11: import net.xoetrope.xml.nanoxml.NanoXmlElement;
12: import net.xoetrope.xml.nanoxml.NanoXmlWriter;
13: import net.xoetrope.xui.XProject;
14: import net.xoetrope.xui.XProjectManager;
15:
16: /**
17: *
18: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
19: * the GNU Public License (GPL), please see license.txt for more details. If
20: * you make commercial use of this software you must purchase a commercial
21: * license from Xoetrope.</p>
22: * <p> $Revision: 1.2 $</p>
23: */
24: public class HTMLFragmentBlock extends FragmentBlock implements
25: TagExporter {
26: /**
27: * The owner project and the context in which this object operates.
28: */
29: protected XProject currentProject = XProjectManager
30: .getCurrentProject();
31:
32: public HTMLFragmentBlock() {
33: super ();
34: }
35:
36: public String getStartTag() {
37: return "<P>";
38: }
39:
40: public String getEndTag() {
41: return "</P>";
42: }
43:
44: public void processFragment(String fragmentName) {
45: try {
46: Reader reader = currentProject.getBufferedReader(
47: fragmentName + "_html.xml", null);
48: XmlElement ele = XmlSource.read(reader);
49: setBindings(ele);
50: StringWriter sr = new StringWriter();
51: NanoXmlWriter writer = new NanoXmlWriter(sr);
52: writer.write(ele, true, 0);
53: //contents.append( sr.toString() );
54: HTMLFragmentItem fragment = new HTMLFragmentItem();
55: fragment.setValue(sr.toString());
56: blocks.add(fragment);
57: } catch (Exception e) {
58: e.printStackTrace();
59: }
60: }
61:
62: private void setBindings(XmlElement ele) {
63: Vector v = ele.getChildren();
64: int numItems = v.size();
65: for (int i = 0; i < numItems; i++) {
66: XmlElement childEle = (XmlElement) v.get(i);
67: if (childEle.getName().compareTo("binding") == 0) {
68: String path = childEle.getAttribute("path");
69: String attrib = childEle.getAttribute("attrib");
70: DataBinding binding = new DataBinding(path, attrib);
71: String value = binding.get();
72: System.out.println(value);
73: ((NanoXmlElement) childEle).getElement().setContent(
74: value);
75: }
76: setBindings(childEle);
77: }
78: }
79:
80: public String getContents() {
81: content.append("</P>\n");
82: return content.toString();
83: }
84:
85: }
|