コード例 #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;
        }
コード例 #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;
 }
コード例 #3
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;
 }
コード例 #4
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);
                }
            }
        }
コード例 #5
0
 public POIFSReaderEventArgs(string name, POIFSDocumentPath path, POIFSDocument document)
 {
     this.name = name;
     this.path = path;
     this.document = document;
 }
コード例 #6
0
ファイル: POIFSReader.cs プロジェクト: missxiaohuang/Weekly
        /// <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())
                    {
                        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())
                        {
                            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;
        }
コード例 #7
0
ファイル: POIFSReader.cs プロジェクト: missxiaohuang/Weekly
        /**
         * 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);
        }
コード例 #8
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();
        }
コード例 #9
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 or empty strings");
             }
             if (components[j].Length == 0)
             {
                // throw new ArgumentException("components cannot contain null or empty strings");
             }
             this.components[j + path.components.Length] = components[j];
         }
     }
 }