diff 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
line wrap: on
line diff
--- a/dwtx/ui/internal/forms/widgets/FormTextModel.d	Sun Jun 22 22:57:31 2008 +0200
+++ b/dwtx/ui/internal/forms/widgets/FormTextModel.d	Sun Jul 06 23:30:07 2008 +0200
@@ -28,6 +28,8 @@
 import dwt.dwthelper.InputStream;
 
 static import tango.text.xml.Document;
+static import tango.io.Buffer;
+
 import tango.util.collection.ArraySeq;
 public class FormTextModel {
 //     private static const DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
@@ -82,13 +84,7 @@
         }
         return sbuf.toString();
     }
-    public void parseTaggedText(String taggedText, bool expandURLs) {
-        implMissing(__FILE__,__LINE__);
-    }
-    public void parseInputStream(InputStream is_, bool expandURLs) {
-        implMissing(__FILE__,__LINE__);
-    }
-/++
+
     /*
      * @see ITextModel#parse(String)
      */
@@ -97,68 +93,85 @@
             reset();
             return;
         }
-        try {
-            InputStream stream = new ByteArrayInputStream(taggedText
-                    .getBytes("UTF8")); //$NON-NLS-1$
-            parseInputStream(stream, expandURLs);
-        } catch (UnsupportedEncodingException e) {
-            DWT.error(DWT.ERROR_UNSUPPORTED_FORMAT, e);
-        }
+        _parseTaggedText(taggedText, expandURLs);
     }
 
     public void parseInputStream(InputStream is_, bool expandURLs) {
-
-        documentBuilderFactory.setNamespaceAware(true);
-        documentBuilderFactory.setIgnoringComments(true);
-
+        auto buf = new tango.io.Buffer.Buffer( 1024 );
+        {
+            int l;
+            byte[1024] a = void;
+            while((l = is_.read(a)) > 0 ){
+                buf.append( a[ 0 .. l ] );
+            }
+        }
+        _parseTaggedText( cast(char[]) buf.slice(), expandURLs );
+//         documentBuilderFactory.setNamespaceAware(true);
+//         documentBuilderFactory.setIgnoringComments(true);
+//
+//         reset();
+//         try {
+//             DocumentBuilder parser = documentBuilderFactory
+//                     .newDocumentBuilder();
+//             InputSource source = new InputSource(is_);
+//             Document doc = parser.parse(source);
+//             processDocument(doc, expandURLs);
+//         } catch (ParserConfigurationException e) {
+//             DWT.error(DWT.ERROR_INVALID_ARGUMENT, e);
+//         } catch (SAXException e) {
+//             DWT.error(DWT.ERROR_INVALID_ARGUMENT, e);
+//         } catch (IOException e) {
+//             DWT.error(DWT.ERROR_IO, e);
+//         }
+    }
+    private void _parseTaggedText( char[] text, bool expandURLs ){
         reset();
-        try {
-            DocumentBuilder parser = documentBuilderFactory
-                    .newDocumentBuilder();
-            InputSource source = new InputSource(is_);
-            Document doc = parser.parse(source);
-            processDocument(doc, expandURLs);
-        } catch (ParserConfigurationException e) {
-            DWT.error(DWT.ERROR_INVALID_ARGUMENT, e);
-        } catch (SAXException e) {
-            DWT.error(DWT.ERROR_INVALID_ARGUMENT, e);
-        } catch (IOException e) {
-            DWT.error(DWT.ERROR_IO, e);
-        }
+//         try {
+//             auto doc = tango.text.xml.Document.Document!(char)();
+//             doc.parse(text);
+//             processDocument(doc, expandURLs);
+//         } catch (XmlException e) {
+//             DWT.error(DWT.ERROR_INVALID_ARGUMENT, e);
+//         } catch (IOException e) {
+//             DWT.error(DWT.ERROR_IO, e);
+//         }
     }
 
-    private void processDocument(Document doc, bool expandURLs) {
-        Node root = doc.getDocumentElement();
-        NodeList children = root.getChildNodes();
-        processSubnodes(paragraphs, children, expandURLs);
-    }
+//     private void processDocument(tango.text.xml.Document.Document!(char) doc, bool expandURLs) {
+//         auto root = doc.query.root.dup;
+//         auto children = root.childs.dup;
+//         processSubnodes(paragraphs, children, expandURLs);
+//     }
 
-    private void processSubnodes(TArraySeqParagraph plist, NodeList children, bool expandURLs) {
-        for (int i = 0; i < children.getLength(); i++) {
-            Node child = children.item(i);
-            if (child.getNodeType() is Node.TEXT_NODE) {
+/+    private void processSubnodes(TArraySeqParagraph plist, NodeList children, bool expandURLs) {
+//o         for (int i = 0; i < children.getLength(); i++) {
+//o             Node child = children.item(i);
+        foreach( child; children ){
+//o             if (child.getNodeType() is Node.TEXT_NODE) {
+            if (child.type is XmlNodeType.Data) {
                 // Make an implicit paragraph
                 String text = getSingleNodeText(child);
-                if (text !is null && !isIgnorableWhiteSpace(text, true)) {
+                if ( !isIgnorableWhiteSpace(text, true)) {
                     Paragraph p = new Paragraph(true);
-                    p.parseRegularText(text, expandURLs, true,
-                            getHyperlinkSettings(), null);
-                    plist.add(p);
-                }
-            } else if (child.getNodeType() is Node.ELEMENT_NODE) {
-                String tag = child.getNodeName().toLowerCase();
-                if (tag.equals("p")) { //$NON-NLS-1$
-                    Paragraph p = processParagraph(child, expandURLs);
-                    if (p !is null)
-                        plist.add(p);
-                } else if (tag.equals("li")) { //$NON-NLS-1$
-                    Paragraph p = processListItem(child, expandURLs);
-                    if (p !is null)
-                        plist.add(p);
+//                     p.parseRegularText(text, expandURLs, true,
+//                             getHyperlinkSettings(), null);
+//                     plist.add(p);
+//                 }
+//             } else if (child.getNodeType() is Node.ELEMENT_NODE) {
+//                 String tag = child.getNodeName().toLowerCase();
+//                 if (tag.equals("p")) { //$NON-NLS-1$
+//                     Paragraph p = processParagraph(child, expandURLs);
+//                     if (p !is null)
+//                         plist.add(p);
+//                 } else if (tag.equals("li")) { //$NON-NLS-1$
+//                     Paragraph p = processListItem(child, expandURLs);
+//                     if (p !is null)
+//                         plist.add(p);
                 }
             }
         }
-    }
+    }+/
+/++
 
     private Paragraph processParagraph(Node paragraph, bool expandURLs) {
         NodeList children = paragraph.getChildNodes();
@@ -275,9 +288,9 @@
             }
         }
     }
-
+++/
     private bool isIgnorableWhiteSpace(String text, bool ignoreSpaces) {
-        for (int i = 0; i < text.length(); i++) {
+        for (int i = 0; i < text.length; i++) {
             char c = text.charAt(i);
             if (ignoreSpaces && c is ' ')
                 continue;
@@ -287,7 +300,7 @@
         }
         return true;
     }
-
+/++
     private ImageSegment processImageSegment(Node image) {
         ImageSegment segment = new ImageSegment();
         processObjectSegment(segment, image, "i."); //$NON-NLS-1$
@@ -376,10 +389,11 @@
         appendText(text, buf, spaceCounter);
         return buf.toString();
     }
+
+    private String getSingleNodeText(tango.text.xml.Document.Document!(char).NodeImpl node) {
+        return getNormalizedText(node.value());
+    }
 /++
-    private String getSingleNodeText(Node node) {
-        return getNormalizedText(node.getNodeValue());
-    }
 
     private String getNodeText(Node node) {
         NodeList children = node.getChildNodes();
@@ -694,7 +708,7 @@
     }
 
     public bool restoreSavedLink() {
-        if (savedSelectedLinkIndex!is -1) {
+        if (savedSelectedLinkIndex !is -1) {
             selectedSegmentIndex = savedSelectedLinkIndex;
             return true;
         }