Beispiel #1
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);
                }
            }
        }
Beispiel #2
0
 public POIFSReaderEventArgs(string name, POIFSDocumentPath path, POIFSDocument document)
 {
     this.name     = name;
     this.path     = path;
     this.document = document;
 }
Beispiel #3
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);
                        }
                    }
                }
            }
        }
Beispiel #4
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);
                    OPOIFSDocument document   = null;
                    if (listeners.MoveNext())
                    {
                        listeners.Reset();
                        int size = property.Size;


                        if (property.ShouldUseSmallBlocks)
                        {
                            document =
                                new OPOIFSDocument(name, small_blocks
                                                   .FetchBlocks(startBlock, -1), size);
                        }
                        else
                        {
                            document =
                                new OPOIFSDocument(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);
        }
Beispiel #5
0
 /**
  * Sets the POI file's path.
  *
  * @param path The POI file's path.
  */
 public void SetPath(POIFSDocumentPath path)
 {
     this.path = path;
 }
        public void TestDefaultConstructor()
        {
            POIFSDocumentPath path = new POIFSDocumentPath();

            Assert.AreEqual(0, path.Length);
        }
        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);
                }
            }
        }
        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)
                {
                }
            }
        }
Beispiel #9
0
        public void TestFullPathConstructor()
        {
            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(params1);

                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)
            {
            }
        }