示例#1
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 POIFSWriterEvent(POIFSDocumentWriter stream, POIFSDocumentPath path, string documentName, int limit)
 {
     this.stream = stream;
     this.path = path;
     this.documentName = documentName;
     this.limit = limit;
 }
    /**
     * 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(Stream stream,
                     POIFSDocumentPath path, String documentName)
    {
        this.stream       = stream;
        this.path         = path;
        this.documentName = documentName;
    }
示例#3
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;
 }
示例#4
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();
        }
 /// <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;
 }
示例#6
0
 public OPOIFSDocument(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);
     }
 }
示例#7
0
 internal BigBlockStore(POIFSDocument enclosingInstance, object[] blocks)
 {
     this.InitBlock(enclosingInstance);
     this.bigBlocks = new DocumentBlock[blocks.Length];
     for (int i = 0; i < blocks.Length; i++)
     {
         if (blocks[i] is DocumentBlock)
         {
             this.bigBlocks[i] = (DocumentBlock)blocks[i];
         }
         else
         {
             this.bigBlocks[i] = new DocumentBlock((RawDataBlock)blocks[i]);
         }
     }
     this.path = null;
     this.name = null;
     this.size = -1;
 }
示例#8
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);
            }
        }
    }
示例#9
0
        /// <summary>
        /// Create a DirectoryNode. This method Is not public by design; it
        /// Is intended strictly for the internal use of this package
        /// </summary>
        /// <param name="property">the DirectoryProperty for this DirectoryEntry</param>
        /// <param name="filesystem">the POIFSFileSystem we belong to</param>
        /// <param name="parent">the parent of this entry</param>
        public DirectoryNode(DirectoryProperty property,
                      POIFSFileSystem filesystem,
                      DirectoryNode parent)
            : base(property, parent)
        {
            if (parent == null)
            {
                _path = new POIFSDocumentPath();
            }
            else
            {
                _path = new POIFSDocumentPath(parent._path, new String[]
                {
                    property.Name
                });
            }
            _filesystem = filesystem;
            _entries    = new Hashtable();
            IEnumerator iter = property.Children;

            while (iter.MoveNext())
            {
                Property child     = ( Property ) iter.Current;
                Entry    childNode = null;

                if (child.IsDirectory)
                {
                    childNode = new DirectoryNode(( DirectoryProperty ) child,
                                                  _filesystem, this);
                }
                else
                {
                    childNode = new DocumentNode(( DocumentProperty ) child,
                                                 this);
                }
                _entries[childNode.Name]=childNode;
            }
        }
示例#10
0
        /// <summary>
        /// Create a DirectoryNode. This method Is not public by design; it
        /// Is intended strictly for the internal use of this package
        /// </summary>
        /// <param name="property">the DirectoryProperty for this DirectoryEntry</param>
        /// <param name="filesystem">the POIFSFileSystem we belong to</param>
        /// <param name="parent">the parent of this entry</param>
        public DirectoryNode(DirectoryProperty property,
                             POIFSFileSystem filesystem,
                             DirectoryNode parent) : base(property, parent)
        {
            if (parent == null)
            {
                _path = new POIFSDocumentPath();
            }
            else
            {
                _path = new POIFSDocumentPath(parent._path, new String[]
                {
                    property.Name
                });
            }
            _filesystem = filesystem;
            _entries    = new Hashtable();
            IEnumerator iter = property.Children;

            while (iter.MoveNext())
            {
                Property child     = ( Property )iter.Current;
                Entry    childNode = null;

                if (child.IsDirectory)
                {
                    childNode = new DirectoryNode(( DirectoryProperty )child,
                                                  _filesystem, this);
                }
                else
                {
                    childNode = new DocumentNode(( DocumentProperty )child,
                                                 this);
                }
                _entries[childNode.Name] = childNode;
            }
        }
示例#11
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)
                {
                }
            }
        }
示例#12
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;


                    int size = property.Size;
                    POIFSDocument document = null;

                    if (property.ShouldUseSmallBlocks)
                    {
                        document =
                            new POIFSDocument(name, small_blocks
                                .FetchBlocks(startBlock,-1), size);
                    }
                    else
                    {
                        document =
                            new POIFSDocument(name, big_blocks
                                .FetchBlocks(startBlock,-1), size);
                    }

                    documents.Add(
                            new DocumentDescriptor(path, name));
                    //fire event
                    OnStreamReaded(new POIFSReaderEventArgs(name, path, document));
                }
            }
            return documents;
        }
示例#13
0
 public POIFSReaderEventArgs(string name, POIFSDocumentPath path, POIFSDocument document)
 {
     this.name = name;
     this.path = path;
     this.document = document;
 }
示例#14
0
文件: POIFile.cs 项目: 89sos98/npoi
 /**
  * Sets the POI file's path.
  *
  * @param path The POI file's path.
  */
 public void SetPath(POIFSDocumentPath path)
 {
     this.path = path;
 }
示例#15
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);
                        }
                    }
                }
            }
        }
示例#16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="POIFSDocument"/> class.
 /// </summary>
 /// <param name="name">the name of the POIFSDocument</param>
 /// <param name="size">the length of the POIFSDocument</param>
 /// <param name="path">the path of the POIFSDocument</param>
 public POIFSDocument(string name, int size, POIFSDocumentPath path)
 {
     this._size = size;
     this._property = new DocumentProperty(name, this._size);
     this._property.Document = this;
     if (this._property.ShouldUseSmallBlocks)
     {
         this._small_store = new SmallBlockStore(this, path, name, size);
         this._big_store = new BigBlockStore(this, new object[0]);
     }
     else
     {
         this._small_store = new SmallBlockStore(this, new BlockWritable[0]);
         this._big_store = new BigBlockStore(this, path, name, size);
     }
 }
示例#17
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)
            {
            }
        }
示例#18
0
 internal BigBlockStore(POIFSBigBlockSize bigBlockSize, DocumentBlock[] blocks)
 {
     this.bigBlockSize = bigBlockSize;
     bigBlocks = (DocumentBlock[])blocks.Clone();
     path = null;
     name = null;
     size = -1;
     writer = null;
 }
示例#19
0
 public POIFSDocument(string name, int size, POIFSDocumentPath path, POIFSWriterListener writer)
     :this(name, size, POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, path, writer)
 {
 }
示例#20
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) || (components[j].Length == 0))
             {
                 throw new ArgumentException("components cannot contain null or empty strings");
             }
             this.components[j + path.components.Length] = components[j];
         }
     }
 }
示例#21
0
 internal SmallBlockStore(POIFSDocument enclosingInstance, object[] blocks)
 {
     this.InitBlock(enclosingInstance);
     this.smallBlocks = new SmallDocumentBlock[blocks.Length];
     for (int i = 0; i < blocks.Length; i++)
     {
         this.smallBlocks[i] = (SmallDocumentBlock)blocks[i];
     }
     this.path = null;
     this.name = null;
     this.size = -1;
 }
示例#22
0
 public void Dispose()
 {
     bigBlocks = null;
     enclosingInstance = null;
     name = null;
     path = null;
 }
示例#23
0
 internal BigBlockStore(POIFSDocument enclosingInstance, object[] blocks)
 {
     this.InitBlock(enclosingInstance);
     this.bigBlocks = new DocumentBlock[blocks.Length];
     for (int i = 0; i < blocks.Length; i++)
     {
         if (blocks[i] is DocumentBlock)
         {
             this.bigBlocks[i] = (DocumentBlock)blocks[i];
         }
         else
         {
             this.bigBlocks[i] = new DocumentBlock((RawDataBlock)blocks[i]);
         }
     }
     this.path = null;
     this.name = null;
     this.size = -1;
 }
示例#24
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);
            }
        }
示例#25
0
        public void TestDefaultConstructor()
        {
            POIFSDocumentPath path = new POIFSDocumentPath();

            Assert.AreEqual(0, path.Length);
        }
示例#26
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());
        }
示例#27
0
 internal SmallBlockStore(POIFSDocument enclosingInstance, POIFSDocumentPath path, string name, int size)
 {
     this.InitBlock(enclosingInstance);
     this.smallBlocks = new SmallDocumentBlock[0];
     this.path = path;
     this.name = name;
     this.size = size;
 }
示例#28
0
 public POIFSDocument(string name, int size, POIFSDocumentPath path, POIFSWriterListener writer)
     : this(name, size, POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, path, writer)
 {
 }
示例#29
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);
     }
 }
示例#30
0
 public void Dispose()
 {
     enclosingInstance = null;
     path = null;
     smallBlocks = null;
     name = null;
 }
示例#31
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;
 }
示例#32
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);
        }
示例#33
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;
 }
示例#34
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;
        }