Mercurial > projects > dwt-addons
comparison dwtx/ui/internal/forms/widgets/FormTextModel.d @ 90:7ffeace6c47f
Update 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 06 Jul 2008 23:30:07 +0200 |
parents | 4ac9946b9fb5 |
children | 04b47443bb01 |
comparison
equal
deleted
inserted
replaced
89:040da1cb0d76 | 90:7ffeace6c47f |
---|---|
26 | 26 |
27 import dwt.dwthelper.utils; | 27 import dwt.dwthelper.utils; |
28 import dwt.dwthelper.InputStream; | 28 import dwt.dwthelper.InputStream; |
29 | 29 |
30 static import tango.text.xml.Document; | 30 static import tango.text.xml.Document; |
31 static import tango.io.Buffer; | |
32 | |
31 import tango.util.collection.ArraySeq; | 33 import tango.util.collection.ArraySeq; |
32 public class FormTextModel { | 34 public class FormTextModel { |
33 // private static const DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory | 35 // private static const DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory |
34 // .newInstance(); | 36 // .newInstance(); |
35 | 37 |
80 String text = paragraph.getAccessibleText(); | 82 String text = paragraph.getAccessibleText(); |
81 sbuf.append(text); | 83 sbuf.append(text); |
82 } | 84 } |
83 return sbuf.toString(); | 85 return sbuf.toString(); |
84 } | 86 } |
85 public void parseTaggedText(String taggedText, bool expandURLs) { | 87 |
86 implMissing(__FILE__,__LINE__); | |
87 } | |
88 public void parseInputStream(InputStream is_, bool expandURLs) { | |
89 implMissing(__FILE__,__LINE__); | |
90 } | |
91 /++ | |
92 /* | 88 /* |
93 * @see ITextModel#parse(String) | 89 * @see ITextModel#parse(String) |
94 */ | 90 */ |
95 public void parseTaggedText(String taggedText, bool expandURLs) { | 91 public void parseTaggedText(String taggedText, bool expandURLs) { |
96 if (taggedText is null) { | 92 if (taggedText is null) { |
97 reset(); | 93 reset(); |
98 return; | 94 return; |
99 } | 95 } |
100 try { | 96 _parseTaggedText(taggedText, expandURLs); |
101 InputStream stream = new ByteArrayInputStream(taggedText | |
102 .getBytes("UTF8")); //$NON-NLS-1$ | |
103 parseInputStream(stream, expandURLs); | |
104 } catch (UnsupportedEncodingException e) { | |
105 DWT.error(DWT.ERROR_UNSUPPORTED_FORMAT, e); | |
106 } | |
107 } | 97 } |
108 | 98 |
109 public void parseInputStream(InputStream is_, bool expandURLs) { | 99 public void parseInputStream(InputStream is_, bool expandURLs) { |
110 | 100 auto buf = new tango.io.Buffer.Buffer( 1024 ); |
111 documentBuilderFactory.setNamespaceAware(true); | 101 { |
112 documentBuilderFactory.setIgnoringComments(true); | 102 int l; |
113 | 103 byte[1024] a = void; |
104 while((l = is_.read(a)) > 0 ){ | |
105 buf.append( a[ 0 .. l ] ); | |
106 } | |
107 } | |
108 _parseTaggedText( cast(char[]) buf.slice(), expandURLs ); | |
109 // documentBuilderFactory.setNamespaceAware(true); | |
110 // documentBuilderFactory.setIgnoringComments(true); | |
111 // | |
112 // reset(); | |
113 // try { | |
114 // DocumentBuilder parser = documentBuilderFactory | |
115 // .newDocumentBuilder(); | |
116 // InputSource source = new InputSource(is_); | |
117 // Document doc = parser.parse(source); | |
118 // processDocument(doc, expandURLs); | |
119 // } catch (ParserConfigurationException e) { | |
120 // DWT.error(DWT.ERROR_INVALID_ARGUMENT, e); | |
121 // } catch (SAXException e) { | |
122 // DWT.error(DWT.ERROR_INVALID_ARGUMENT, e); | |
123 // } catch (IOException e) { | |
124 // DWT.error(DWT.ERROR_IO, e); | |
125 // } | |
126 } | |
127 private void _parseTaggedText( char[] text, bool expandURLs ){ | |
114 reset(); | 128 reset(); |
115 try { | 129 // try { |
116 DocumentBuilder parser = documentBuilderFactory | 130 // auto doc = tango.text.xml.Document.Document!(char)(); |
117 .newDocumentBuilder(); | 131 // doc.parse(text); |
118 InputSource source = new InputSource(is_); | 132 // processDocument(doc, expandURLs); |
119 Document doc = parser.parse(source); | 133 // } catch (XmlException e) { |
120 processDocument(doc, expandURLs); | 134 // DWT.error(DWT.ERROR_INVALID_ARGUMENT, e); |
121 } catch (ParserConfigurationException e) { | 135 // } catch (IOException e) { |
122 DWT.error(DWT.ERROR_INVALID_ARGUMENT, e); | 136 // DWT.error(DWT.ERROR_IO, e); |
123 } catch (SAXException e) { | 137 // } |
124 DWT.error(DWT.ERROR_INVALID_ARGUMENT, e); | 138 } |
125 } catch (IOException e) { | 139 |
126 DWT.error(DWT.ERROR_IO, e); | 140 // private void processDocument(tango.text.xml.Document.Document!(char) doc, bool expandURLs) { |
127 } | 141 // auto root = doc.query.root.dup; |
128 } | 142 // auto children = root.childs.dup; |
129 | 143 // processSubnodes(paragraphs, children, expandURLs); |
130 private void processDocument(Document doc, bool expandURLs) { | 144 // } |
131 Node root = doc.getDocumentElement(); | 145 |
132 NodeList children = root.getChildNodes(); | 146 /+ private void processSubnodes(TArraySeqParagraph plist, NodeList children, bool expandURLs) { |
133 processSubnodes(paragraphs, children, expandURLs); | 147 //o for (int i = 0; i < children.getLength(); i++) { |
134 } | 148 //o Node child = children.item(i); |
135 | 149 foreach( child; children ){ |
136 private void processSubnodes(TArraySeqParagraph plist, NodeList children, bool expandURLs) { | 150 //o if (child.getNodeType() is Node.TEXT_NODE) { |
137 for (int i = 0; i < children.getLength(); i++) { | 151 if (child.type is XmlNodeType.Data) { |
138 Node child = children.item(i); | |
139 if (child.getNodeType() is Node.TEXT_NODE) { | |
140 // Make an implicit paragraph | 152 // Make an implicit paragraph |
141 String text = getSingleNodeText(child); | 153 String text = getSingleNodeText(child); |
142 if (text !is null && !isIgnorableWhiteSpace(text, true)) { | 154 if ( !isIgnorableWhiteSpace(text, true)) { |
143 Paragraph p = new Paragraph(true); | 155 Paragraph p = new Paragraph(true); |
144 p.parseRegularText(text, expandURLs, true, | 156 // p.parseRegularText(text, expandURLs, true, |
145 getHyperlinkSettings(), null); | 157 // getHyperlinkSettings(), null); |
146 plist.add(p); | 158 // plist.add(p); |
159 // } | |
160 // } else if (child.getNodeType() is Node.ELEMENT_NODE) { | |
161 // String tag = child.getNodeName().toLowerCase(); | |
162 // if (tag.equals("p")) { //$NON-NLS-1$ | |
163 // Paragraph p = processParagraph(child, expandURLs); | |
164 // if (p !is null) | |
165 // plist.add(p); | |
166 // } else if (tag.equals("li")) { //$NON-NLS-1$ | |
167 // Paragraph p = processListItem(child, expandURLs); | |
168 // if (p !is null) | |
169 // plist.add(p); | |
147 } | 170 } |
148 } else if (child.getNodeType() is Node.ELEMENT_NODE) { | 171 } |
149 String tag = child.getNodeName().toLowerCase(); | 172 } |
150 if (tag.equals("p")) { //$NON-NLS-1$ | 173 }+/ |
151 Paragraph p = processParagraph(child, expandURLs); | 174 /++ |
152 if (p !is null) | |
153 plist.add(p); | |
154 } else if (tag.equals("li")) { //$NON-NLS-1$ | |
155 Paragraph p = processListItem(child, expandURLs); | |
156 if (p !is null) | |
157 plist.add(p); | |
158 } | |
159 } | |
160 } | |
161 } | |
162 | 175 |
163 private Paragraph processParagraph(Node paragraph, bool expandURLs) { | 176 private Paragraph processParagraph(Node paragraph, bool expandURLs) { |
164 NodeList children = paragraph.getChildNodes(); | 177 NodeList children = paragraph.getChildNodes(); |
165 NamedNodeMap atts = paragraph.getAttributes(); | 178 NamedNodeMap atts = paragraph.getAttributes(); |
166 Node addSpaceAtt = atts.getNamedItem("addVerticalSpace"); //$NON-NLS-1$ | 179 Node addSpaceAtt = atts.getNamedItem("addVerticalSpace"); //$NON-NLS-1$ |
273 if (segment !is null) { | 286 if (segment !is null) { |
274 p.addSegment(segment); | 287 p.addSegment(segment); |
275 } | 288 } |
276 } | 289 } |
277 } | 290 } |
278 | 291 ++/ |
279 private bool isIgnorableWhiteSpace(String text, bool ignoreSpaces) { | 292 private bool isIgnorableWhiteSpace(String text, bool ignoreSpaces) { |
280 for (int i = 0; i < text.length(); i++) { | 293 for (int i = 0; i < text.length; i++) { |
281 char c = text.charAt(i); | 294 char c = text.charAt(i); |
282 if (ignoreSpaces && c is ' ') | 295 if (ignoreSpaces && c is ' ') |
283 continue; | 296 continue; |
284 if (c is '\n' || c is '\r' || c is '\f') | 297 if (c is '\n' || c is '\r' || c is '\f') |
285 continue; | 298 continue; |
286 return false; | 299 return false; |
287 } | 300 } |
288 return true; | 301 return true; |
289 } | 302 } |
290 | 303 /++ |
291 private ImageSegment processImageSegment(Node image) { | 304 private ImageSegment processImageSegment(Node image) { |
292 ImageSegment segment = new ImageSegment(); | 305 ImageSegment segment = new ImageSegment(); |
293 processObjectSegment(segment, image, "i."); //$NON-NLS-1$ | 306 processObjectSegment(segment, image, "i."); //$NON-NLS-1$ |
294 return segment; | 307 return segment; |
295 } | 308 } |
374 if (text is null) | 387 if (text is null) |
375 return null; | 388 return null; |
376 appendText(text, buf, spaceCounter); | 389 appendText(text, buf, spaceCounter); |
377 return buf.toString(); | 390 return buf.toString(); |
378 } | 391 } |
392 | |
393 private String getSingleNodeText(tango.text.xml.Document.Document!(char).NodeImpl node) { | |
394 return getNormalizedText(node.value()); | |
395 } | |
379 /++ | 396 /++ |
380 private String getSingleNodeText(Node node) { | |
381 return getNormalizedText(node.getNodeValue()); | |
382 } | |
383 | 397 |
384 private String getNodeText(Node node) { | 398 private String getNodeText(Node node) { |
385 NodeList children = node.getChildNodes(); | 399 NodeList children = node.getChildNodes(); |
386 StringBuffer buf = new StringBuffer(); | 400 StringBuffer buf = new StringBuffer(); |
387 int[] spaceCounter = new int[1]; | 401 int[] spaceCounter = new int[1]; |
692 } | 706 } |
693 return selectables[nextIndex]; | 707 return selectables[nextIndex]; |
694 } | 708 } |
695 | 709 |
696 public bool restoreSavedLink() { | 710 public bool restoreSavedLink() { |
697 if (savedSelectedLinkIndex!is -1) { | 711 if (savedSelectedLinkIndex !is -1) { |
698 selectedSegmentIndex = savedSelectedLinkIndex; | 712 selectedSegmentIndex = savedSelectedLinkIndex; |
699 return true; | 713 return true; |
700 } | 714 } |
701 return false; | 715 return false; |
702 } | 716 } |