Ejemplo n.º 1
0
        /**
         * package scoped constructor
         *
         * @param stream the DocumentInputStream, freshly opened
         * @param path the path of the document
         * @param documentName the name of the document
         */

        public POIFSReaderEvent(DocumentInputStream stream,
                         POIFSDocumentPath path, String documentName)
        {
            this.stream = stream;
            this.path = path;
            this.documentName = documentName;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="POIFSWriterEvent"/> class.
 /// </summary>
 /// <param name="stream">the POIFSDocumentWriter, freshly opened</param>
 /// <param name="path">the path of the document</param>
 /// <param name="documentName">the name of the document</param>
 /// <param name="limit">the limit, in bytes, that can be written to the stream</param>
 public POIFSWriterEventArgs(DocumentOutputStream stream, POIFSDocumentPath path, string documentName, int limit)
 {
     this.stream = stream;
     this.path = path;
     this.documentName = documentName;
     this.limit = limit;
 }
Ejemplo n.º 3
0
 public POIFSDocument(string name, int size, POIFSBigBlockSize bigBlockSize, POIFSDocumentPath path, POIFSWriterListener writer)
 {
     _size              = size;
     _bigBigBlockSize   = bigBlockSize;
     _property          = new DocumentProperty(name, _size);
     _property.Document = this;
     if (_property.ShouldUseSmallBlocks)
     {
         _small_store = new SmallBlockStore(_bigBigBlockSize, path, name, size, writer);
         _big_store   = new BigBlockStore(_bigBigBlockSize, EMPTY_BIG_BLOCK_ARRAY);
     }
     else
     {
         _small_store = new SmallBlockStore(_bigBigBlockSize, EMPTY_SMALL_BLOCK_ARRAY);
         _big_store   = new BigBlockStore(_bigBigBlockSize, path, name, size, writer);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DocumentDescriptor"/> class.
 /// </summary>
 /// <param name="path">the Document path</param>
 /// <param name="name">the Document name</param>
 public DocumentDescriptor(POIFSDocumentPath path, String name)
 {
     if (path == null)
     {
         throw new NullReferenceException("path must not be null");
     }
     if (name == null)
     {
         throw new NullReferenceException("name must not be null");
     }
     if (name.Length== 0)
     {
         throw new ArgumentException("name cannot be empty");
     }
     this.path = path;
     this.name = name;
 }
Ejemplo n.º 5
0
        /**
         * Register a POIFSReaderListener for a particular document
         *
         * @param listener the listener
         * @param path the path of the document of interest
         * @param documentName the name of the document of interest
         */

        public void RegisterListener(POIFSReaderListener listener,
                              POIFSDocumentPath path,
                              String documentName)
        {
            if (!omnivorousListeners.Contains(listener))
            {

                // not an omnivorous listener (if it was, this method is a
                // no-op)
                ArrayList descriptors = (ArrayList)selectiveListeners[listener];

                if (descriptors == null)
                {

                    // this listener has not Registered before
                    descriptors = new ArrayList();
                    selectiveListeners[listener] = descriptors;
                }
                DocumentDescriptor descriptor = new DocumentDescriptor(path,
                                                    documentName);

                if (descriptors.Add(descriptor) >= 0)
                {

                    // this listener wasn't alReady listening for this
                    // document -- Add the listener to the Set of
                    // listeners for this document
                    ArrayList listeners =
                        (ArrayList)chosenDocumentDescriptors[descriptor];

                    if (listeners == null)
                    {

                        // nobody was listening for this document before
                        listeners = new ArrayList();
                        chosenDocumentDescriptors[descriptor] = listeners;
                    }
                    listeners.Add(listener);
                }
            }
        }
Ejemplo n.º 6
0
        public void TestDefaultConstructor()
        {
            POIFSDocumentPath path = new POIFSDocumentPath();

            Assert.AreEqual(0, path.Length);
        }
Ejemplo n.º 7
0
        public void TestEquality()
        {
            POIFSDocumentPath a1 = new POIFSDocumentPath();
            POIFSDocumentPath a2 = new POIFSDocumentPath(null);
            POIFSDocumentPath a3 = new POIFSDocumentPath(new String[0]);
            POIFSDocumentPath a4 = new POIFSDocumentPath(a1, null);
            POIFSDocumentPath a5 = new POIFSDocumentPath(a1, new string[0]);

            POIFSDocumentPath[] paths = { a1, a2, a3, a4, a5 };

            for (int j = 0; j < paths.Length; j++)
            {
                for (int k = 0; k < paths.Length; k++)
                    Assert.AreEqual(paths[j], paths[k], j + "<>" + k);
            }

            a2 = new POIFSDocumentPath(a1, new string[] { "foo" });
            a3 = new POIFSDocumentPath(a2, new string[] { "bar" });
            a4 = new POIFSDocumentPath(a3, new string[] { "fubar" });
            a5 = new POIFSDocumentPath(a4, new string[] { "foobar" });

            POIFSDocumentPath[] builtUpPaths = { a1, a2, a3, a4, a5 };

            POIFSDocumentPath[] fullPaths =
            {
                    new POIFSDocumentPath(),
                    new POIFSDocumentPath(new string[]{"foo"}),
                    new POIFSDocumentPath(new string[]{"foo", "bar"}),
                    new POIFSDocumentPath(new string[]{"foo", "bar", "fubar"}),
                    new POIFSDocumentPath(new string[]{"foo", "bar", "fubar", "foobar"})
            };

            for (int k = 0; k < builtUpPaths.Length; k++)
            {
                for (int j = 0; j < fullPaths.Length; j++)
                {
                    if (k == j)
                        Assert.AreEqual(fullPaths[j], builtUpPaths[k], j + "<>" + k);
                    else
                        Assert.IsTrue(!(fullPaths[j].Equals(builtUpPaths[k])), j + "<>" + k);
                }
            }
            POIFSDocumentPath[] badPaths =
            {
                    new POIFSDocumentPath(new string[]{"_foo"}),
                    new POIFSDocumentPath(new string[]{"foo", "_bar"}),
                    new POIFSDocumentPath(new string[]{"foo", "bar", "_fubar"}),
                    new POIFSDocumentPath(new string[]{"foo", "bar", "fubar", "_foobar"})

            };

            for (int k = 0; k < builtUpPaths.Length; k++)
            {
                for (int j = 0; j < badPaths.Length; j++)
                    Assert.IsTrue(!(fullPaths[k].Equals(badPaths[j])), j + "<>" + k);
            }
        }
Ejemplo n.º 8
0
        public void TestRelativePathConstructor()
        {
            string[] initialComponents = { "a", "b", "c" };

            for (int n = 0; n < initialComponents.Length; n++)
            {
                String[] initialParams = new String[n];

                for (int k = 0; k < n; k++)
                    initialParams[k] = initialComponents[k];

                POIFSDocumentPath b = new POIFSDocumentPath(initialParams);
                string[] components = { "foo", "bar", "foobar", "fubar" };

                for (int j = 0; j < components.Length; j++)
                {
                    String[] params1 = new String[j];

                    for (int k = 0; k < j; k++)
                    {
                        params1[k] = components[k];
                    }
                    POIFSDocumentPath path = new POIFSDocumentPath(b, params1);

                    Assert.AreEqual(j + n, path.Length);
                    for (int k = 0; k < n; k++)
                    {
                        Assert.AreEqual(initialComponents[k],
                                     path.GetComponent(k));
                    }
                    for (int k = 0; k < j; k++)
                    {
                        Assert.AreEqual(components[k], path.GetComponent(k + n));
                    }
                    if ((j + n) == 0)
                    {
                        Assert.IsNull(path.Parent);
                    }
                    else
                    {
                        POIFSDocumentPath parent = path.Parent;

                        Assert.IsNotNull(parent);
                        Assert.AreEqual(j + n - 1, parent.Length);
                        for (int k = 0; k < (j + n - 1); k++)
                        {
                            Assert.AreEqual(path.GetComponent(k), parent.GetComponent(k));
                        }
                    }
                }

                Assert.AreEqual(n, new POIFSDocumentPath(b, null).Length);
                //this one is allowed.
                new POIFSDocumentPath(b, new string[] { "fu", "" });

                //this one is allowed too
                new POIFSDocumentPath(b, new string[] { "", "fu" });

                //this one is not allowed.
                try
                {
                    new POIFSDocumentPath(b, new string[] { "fu", null });
                    Assert.Fail("should have caught ArgumentException");
                }
                catch (ArgumentException)
                {
                }
                try
                {
                    new POIFSDocumentPath(b, new string[] { "fu", null });
                    Assert.Fail("should have caught ArgumentException");
                }
                catch (ArgumentException)
                {
                }
            }
        }
Ejemplo n.º 9
0
 public POIFSReaderEventArgs(string name, POIFSDocumentPath path, POIFSDocument document)
 {
     this.name = name;
     this.path = path;
     this.document = document;
 }
Ejemplo n.º 10
0
        /**
         * Get am iterator of listeners for a particular document
         *
         * @param path the document path
         * @param name the name of the document
         *
         * @return an Iterator POIFSReaderListeners; may be empty
         */

        public IEnumerator GetListeners(POIFSDocumentPath path, String name)
        {
            ArrayList rval = new ArrayList(omnivorousListeners);
            ArrayList selectiveListeners =
                (ArrayList)chosenDocumentDescriptors[new DocumentDescriptor(path,
                    name)];

            if (selectiveListeners != null)
            {
                rval.AddRange(selectiveListeners);
            }
            return rval.GetEnumerator();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Processes the properties.
        /// </summary>
        /// <param name="small_blocks">The small_blocks.</param>
        /// <param name="big_blocks">The big_blocks.</param>
        /// <param name="properties">The properties.</param>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        private List<DocumentDescriptor> ProcessProperties(BlockList small_blocks,
                                       BlockList big_blocks,
                                       IEnumerator properties,
                                       POIFSDocumentPath path)
        {
            List<DocumentDescriptor> documents =
                new List<DocumentDescriptor>();

            while (properties.MoveNext())
            {
                Property property = (Property)properties.Current;
                String name = property.Name;

                if (property.IsDirectory)
                {
                    POIFSDocumentPath new_path = new POIFSDocumentPath(path,
                                                     new String[]
                {
                    name
                });

                    ProcessProperties(
                        small_blocks, big_blocks,
                        ((DirectoryProperty)property).Children, new_path);
                }
                else
                {
                    int startBlock = property.StartBlock;
                    IEnumerator listeners = registry.GetListeners(path, name);
                    POIFSDocument document = null;
                    if (listeners.MoveNext())
                    {
                        listeners.Reset();
                        int size = property.Size;
                        

                        if (property.ShouldUseSmallBlocks)
                        {
                            document =
                                new POIFSDocument(name, small_blocks
                                    .FetchBlocks(startBlock, -1), size);
                        }
                        else
                        {
                            document =
                                new POIFSDocument(name, big_blocks
                                    .FetchBlocks(startBlock, -1), size);
                        }
                        //POIFSReaderListener listener =
                        //        (POIFSReaderListener)listeners.Current;
                        //listener.ProcessPOIFSReaderEvent(
                        //        new POIFSReaderEvent(
                        //            new DocumentInputStream(document), path,
                        //            name));
                        while (listeners.MoveNext())
                        {
                            POIFSReaderListener listener =
                                (POIFSReaderListener)listeners.Current;
                            listener.ProcessPOIFSReaderEvent(
                                new POIFSReaderEvent(
                                    new DocumentInputStream(document), path,
                                    name));
                        }
                    }
                    else
                    {
                        // consume the document's data and discard it
                        if (property.ShouldUseSmallBlocks)
                        {
                            small_blocks.FetchBlocks(startBlock, -1);
                        }
                        else
                        {
                            big_blocks.FetchBlocks(startBlock, -1);
                        }
                        //documents.Add(
                        //        new DocumentDescriptor(path, name));
                        //fire event
                        //OnStreamReaded(new POIFSReaderEventArgs(name, path, document));
                    }
                }
            }
            return documents;
        }
Ejemplo n.º 12
0
        /**
         * Register a POIFSReaderListener for a document in the specified
         * directory
         *
         * @param listener the listener to be registered
         * @param path the document path; if null, the root directory is
         *             assumed
         * @param name the document name
         *
         * @exception NullPointerException if listener is null or name is
         *                                 null or empty
         * @exception IllegalStateException if read() has already been
         *                                  called
         */

        public void RegisterListener(POIFSReaderListener listener,
                                     POIFSDocumentPath path,
                                     String name)
        {
            if ((listener == null) || (name == null) || (name.Length == 0))
            {
                throw new NullReferenceException();
            }
            if (registryClosed)
            {
                throw new InvalidOperationException();
            }
            registry.RegisterListener(listener,
                                      (path == null) ? new POIFSDocumentPath()
                                                     : path, name);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// constructor that adds additional subdirectories to an existing
 /// path
 /// </summary>
 /// <param name="path">the existing path</param>
 /// <param name="components">the additional subdirectory names to be added</param>
 public POIFSDocumentPath(POIFSDocumentPath path, string[] components)
 {
     if (components == null)
     {
         this.components = new string[path.components.Length];
     }
     else
     {
         this.components = new string[path.components.Length + components.Length];
     }
     for (int i = 0; i < path.components.Length; i++)
     {
         this.components[i] = path.components[i];
     }
     if (components != null)
     {
         for (int j = 0; j < components.Length; j++)
         {
             if (components[j] == null)
             {
                 throw new ArgumentException("components cannot contain null");
             }
             if (components[j].Length == 0)
             {
                // throw new ArgumentException("components cannot contain null or empty strings");
             }
             this.components[j + path.components.Length] = components[j];
         }
     }
 }
Ejemplo n.º 14
0
        public void TestEquality()
        {
            String[] names =
        {
            "c1", "c2", "c3", "c4", "c5"
        };
            POIFSDocumentPath a1 = new POIFSDocumentPath();
            POIFSDocumentPath a2 = new POIFSDocumentPath(null);
            POIFSDocumentPath a3 = new POIFSDocumentPath(new String[0]);
            POIFSDocumentPath a4 = new POIFSDocumentPath(a1, null);
            POIFSDocumentPath a5 = new POIFSDocumentPath(a1,
                                            new String[0]);
            POIFSDocumentPath[] paths =
        {
            a1, a2, a3, a4, a5
        };

            for (int j = 0; j < paths.Length; j++)
            {
                for (int k = 0; k < paths.Length; k++)
                {
                    for (int m = 0; m < names.Length; m++)
                    {
                        DocumentDescriptor d1 = new DocumentDescriptor(paths[j],
                                                    names[m]);

                        for (int n = 0; n < names.Length; n++)
                        {
                            DocumentDescriptor d2 =
                                new DocumentDescriptor(paths[k], names[n]);

                            if (m == n)
                            {
                                Assert.AreEqual(d1, d2, "" + j + "," + k + "," + m + ","
                                             + n);
                            }
                            else
                            {
                                Assert.IsTrue(!d1.Equals(d2), "" + j + "," + k + "," + m + "," + n);
                            }
                        }
                    }
                }
            }
            a2 = new POIFSDocumentPath(a1, new String[]
        {
            "foo"
        });
            a3 = new POIFSDocumentPath(a2, new String[]
        {
            "bar"
        });
            a4 = new POIFSDocumentPath(a3, new String[]
        {
            "fubar"
        });
            a5 = new POIFSDocumentPath(a4, new String[]
        {
            "foobar"
        });
            POIFSDocumentPath[] builtUpPaths =
        {
            a1, a2, a3, a4, a5
        };
            POIFSDocumentPath[] fullPaths =
        {
            new POIFSDocumentPath(), new POIFSDocumentPath(new String[]
            {
                "foo"
            }), new POIFSDocumentPath(new String[]
            {
                "foo", "bar"
            }), new POIFSDocumentPath(new String[]
            {
                "foo", "bar", "fubar"
            }), new POIFSDocumentPath(new String[]
            {
                "foo", "bar", "fubar", "foobar"
            })
        };

            for (int k = 0; k < builtUpPaths.Length; k++)
            {
                for (int j = 0; j < fullPaths.Length; j++)
                {
                    for (int m = 0; m < names.Length; m++)
                    {
                        DocumentDescriptor d1 =
                            new DocumentDescriptor(fullPaths[j], names[m]);

                        for (int n = 0; n < names.Length; n++)
                        {
                            DocumentDescriptor d2 =
                                new DocumentDescriptor(builtUpPaths[k],
                                                       names[n]);

                            if ((k == j) && (m == n))
                            {
                                Assert.AreEqual(d1, d2, "" + j + "," + k + "," + m + ","
                                             + n);
                            }
                            else
                            {
                                Assert.IsTrue(!(d1.Equals(d2)), "" + j + "," + k + "," + m + "," + n);
                            }
                        }
                    }
                }
            }
            POIFSDocumentPath[] badPaths =
        {
            new POIFSDocumentPath(new String[]
            {
                "_foo"
            }), new POIFSDocumentPath(new String[]
            {
                "foo", "_bar"
            }), new POIFSDocumentPath(new String[]
            {
                "foo", "bar", "_fubar"
            }), new POIFSDocumentPath(new String[]
            {
                "foo", "bar", "fubar", "_foobar"
            })
        };

            for (int k = 0; k < builtUpPaths.Length; k++)
            {
                for (int j = 0; j < badPaths.Length; j++)
                {
                    for (int m = 0; m < names.Length; m++)
                    {
                        DocumentDescriptor d1 =
                            new DocumentDescriptor(badPaths[j], names[m]);

                        for (int n = 0; n < names.Length; n++)
                        {
                            DocumentDescriptor d2 =
                                new DocumentDescriptor(builtUpPaths[k],
                                                       names[n]);

                            Assert.IsTrue(!(d1.Equals(d2)), "" + j + "," + k + "," + m + "," + n);
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public void TestFullPathConstructor()
        {
            string[] components = { "foo", "bar", "foobar", "fubar" };

            for (int j = 0; j < components.Length; j++)
            {
                string[] pms = new string[j];

                for (int k = 0; k < j; k++)
                {
                    pms[k] = components[k];
                }

                POIFSDocumentPath path = new POIFSDocumentPath(pms);

                Assert.AreEqual(j, path.Length);
                for (int k = 0; k < j; k++)
                {
                    Assert.AreEqual(components[k], path.GetComponent(k));
                }
                if (j == 0)
                    Assert.IsNull(path.Parent);
                else
                {
                    POIFSDocumentPath parent = path.Parent;

                    Assert.IsNotNull(parent);
                    Assert.AreEqual(j - 1, parent.Length);
                    for (int k = 0; k < j - 1; k++)
                        Assert.AreEqual(components[k], parent.GetComponent(k));
                }
            }

            // Test weird variants
            Assert.AreEqual(0, new POIFSDocumentPath(null).Length);
            try
            {
                new POIFSDocumentPath(new string[] { "fu", "" });
                Assert.Fail("Should have caught IllegalArgumentException");
            }
            catch (ArgumentException)
            {
            }
            try
            {
                new POIFSDocumentPath(new string[] { "fu", null });
                Assert.Fail("Should have caught IllegalArgumentException");
            }
            catch (ArgumentException)
            {
            }
        }
Ejemplo n.º 16
0
 internal BigBlockStore(POIFSBigBlockSize bigBlockSize, POIFSDocumentPath path, string name, int size, POIFSWriterListener writer)
 {
     this.bigBlockSize = bigBlockSize;
     this.bigBlocks = new DocumentBlock[0];
     this.path = path;
     this.name = name;
     this.size = size;
     this.writer = writer;
 }
Ejemplo n.º 17
0
 internal BigBlockStore(POIFSBigBlockSize bigBlockSize, DocumentBlock[] blocks)
 {
     this.bigBlockSize = bigBlockSize;
     bigBlocks = (DocumentBlock[])blocks.Clone();
     path = null;
     name = null;
     size = -1;
     writer = null;
 }
Ejemplo n.º 18
0
 internal SmallBlockStore(POIFSBigBlockSize bigBlockSize, SmallDocumentBlock[] blocks)
 {
     this.bigBlockSize = bigBlockSize;
     smallBlocks = (SmallDocumentBlock[])blocks.Clone();
     this.path = null;
     this.name = null;
     this.size = -1;
     this.writer = null;
 }
Ejemplo n.º 19
0
 public POIFSDocument(string name, int size, POIFSDocumentPath path, POIFSWriterListener writer)
     :this(name, size, POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, path, writer)
 {
 }
Ejemplo n.º 20
0
 public POIFSDocument(string name, int size, POIFSBigBlockSize bigBlockSize, POIFSDocumentPath path, POIFSWriterListener writer)
     {
     _size = size;
     _bigBigBlockSize = bigBlockSize;
     _property = new DocumentProperty(name, _size);
     _property.Document = this;
     if (_property.ShouldUseSmallBlocks)
     {
         _small_store = new SmallBlockStore(_bigBigBlockSize, path, name, size, writer);
         _big_store = new BigBlockStore(_bigBigBlockSize, EMPTY_BIG_BLOCK_ARRAY);
     }
     else
     {
         _small_store = new SmallBlockStore(_bigBigBlockSize, EMPTY_SMALL_BLOCK_ARRAY);
         _big_store = new BigBlockStore(_bigBigBlockSize, path, name, size, writer);
     }
 }
Ejemplo n.º 21
0
 public POIFSDocument(string name, int size, POIFSDocumentPath path, POIFSWriterListener writer)
     : this(name, size, POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, path, writer)
 {
 }
Ejemplo n.º 22
0
        public NPOIFSDocument(String name, int size, NPOIFSFileSystem filesystem, POIFSWriterListener Writer)
        {
            this._filesystem = filesystem;

            if (size < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE)
            {
                _stream = new NPOIFSStream(filesystem.GetMiniStore());
                _block_size = _filesystem.GetMiniStore().GetBlockStoreBlockSize();
            }
            else
            {
                _stream = new NPOIFSStream(filesystem);
                _block_size = _filesystem.GetBlockStoreBlockSize();
            }

            Stream innerOs = _stream.GetOutputStream();
            DocumentOutputStream os = new DocumentOutputStream(innerOs, size);
            POIFSDocumentPath path = new POIFSDocumentPath(name.Split(new string[] { "\\\\" }, StringSplitOptions.RemoveEmptyEntries));
            String docName = path.GetComponent(path.Length - 1);
            POIFSWriterEvent event1 = new POIFSWriterEvent(os, path, docName, size);
            Writer.ProcessPOIFSWriterEvent(event1);
            innerOs.Close();

            // And build the property for it
            this._property = new DocumentProperty(name, size);
            _property.StartBlock = (/*setter*/_stream.GetStartBlock());
        }