FileSpec.cs :  » PDF » PDF-Clown » it » stefanochizzolini » clown » documents » fileSpecs » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » PDF » PDF Clown 
PDF Clown » it » stefanochizzolini » clown » documents » fileSpecs » FileSpec.cs
/*
  Copyright 2008 Stefano Chizzolini. http://clown.stefanochizzolini.it

  Contributors:
    * Stefano Chizzolini (original code developer, http://www.stefanochizzolini.it)

  This file should be part of the source code distribution of "PDF Clown library"
  (the Program): see the accompanying README files for more info.

  This Program is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free Software
  Foundation; either version 2 of the License, or (at your option) any later version.

  This Program is distributed in the hope that it will be useful, but WITHOUT ANY
  WARRANTY, either expressed or implied; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.

  You should have received a copy of the GNU General Public License along with this
  Program (see README files); if not, go to the GNU website (http://www.gnu.org/).

  Redistribution and use, with or without modification, are permitted provided that such
  redistributions retain the above copyright notice, license and disclaimer, along with
  this list of conditions.
*/

using it.stefanochizzolini.clown.bytes;
using it.stefanochizzolini.clown.documents;
using it.stefanochizzolini.clown.objects;

using System;
using System.IO;

namespace it.stefanochizzolini.clown.documents.fileSpecs{
  /**
    <summary>Reference to the contents of another file (file specification) [PDF:1.6:3.10.2].</summary>
  */
  public class FileSpec
    : PdfObjectWrapper<PdfDictionary>
  {
    #region dynamic
    #region constructors
    public FileSpec(
      Document context
      ) : base(
        context.File,
        new PdfDictionary(
          new PdfName[]
          {PdfName.Type},
          new PdfDirectObject[]
          {PdfName.Filespec}
          )
        )
    {}

    public FileSpec(
      EmbeddedFile embeddedFile,
      string name
      ) : this(embeddedFile.Document)
    {
      Name = name;
      EmbeddedFile = embeddedFile;
    }

    internal FileSpec(
      PdfDirectObject baseObject,
      PdfIndirectObject container
      ) : base(baseObject,container)
    {}
    #endregion

    #region interface
    #region public
    public override object Clone(
      Document context
      )
    {throw new NotImplementedException();}

    /**
      <summary>Gets/Sets the related files.</summary>
    */
    public RelatedFiles Dependencies
    {
      get
      {return GetDependencies(PdfName.F);}
      set
      {SetDependencies(PdfName.F,value);}
    }

    /**
      <summary>Gets/Sets the description of the file.</summary>
    */
    public string Description
    {
      get
      {
        /*
          NOTE: 'Desc' entry may be undefined.
        */
        PdfTextString descriptionObject = (PdfTextString)BaseDataObject[PdfName.Desc];
        if(descriptionObject == null)
          return null;

        return (string)descriptionObject.Value;
      }
      set
      {BaseDataObject[PdfName.Desc] = new PdfTextString(value);}
    }

    /**
      <summary>Gets/Sets the embedded file.</summary>
    */
    public EmbeddedFile EmbeddedFile
    {
      get
      {return GetEmbeddedFile(PdfName.F);}
      set
      {SetEmbeddedFile(PdfName.F,value);}
    }

    /**
      <summary>Gets/Sets the Mac OS-specific related files.</summary>
    */
    public RelatedFiles MacDependencies
    {
      get
      {return GetDependencies(PdfName.Mac);}
      set
      {SetDependencies(PdfName.Mac,value);}
    }

    /**
      <summary>Gets/Sets the Mac OS-specific embedded file.</summary>
    */
    public EmbeddedFile MacEmbeddedFile
    {
      get
      {return GetEmbeddedFile(PdfName.Mac);}
      set
      {SetEmbeddedFile(PdfName.Mac,value);}
    }

    /**
      <summary>Gets/Sets the Mac OS-specific file name.</summary>
    */
    public string MacName
    {
      get
      {return GetName(PdfName.Mac);}
      set
      {SetName(PdfName.Mac,value);}
    }

    /**
      <summary>Gets/Sets the file name.</summary>
    */
    public string Name
    {
      get
      {return GetName(PdfName.F);}
      set
      {SetName(PdfName.F,value);}
    }

    /**
      <summary>Gets/Sets the Unix-specific related files.</summary>
    */
    public RelatedFiles UnixDependencies
    {
      get
      {return GetDependencies(PdfName.Unix);}
      set
      {SetDependencies(PdfName.Unix,value);}
    }

    /**
      <summary>Gets/Sets the Unix-specific embedded file.</summary>
    */
    public EmbeddedFile UnixEmbeddedFile
    {
      get
      {return GetEmbeddedFile(PdfName.Unix);}
      set
      {SetEmbeddedFile(PdfName.Unix,value);}
    }

    /**
      <summary>Gets/Sets the Unix-specific file name.</summary>
    */
    public string UnixName
    {
      get
      {return GetName(PdfName.Unix);}
      set
      {SetName(PdfName.Unix,value);}
    }

    /**
      <summary>Gets/Sets the Windows-specific related files.</summary>
    */
    public RelatedFiles WinDependencies
    {
      get
      {return GetDependencies(PdfName.DOS);}
      set
      {SetDependencies(PdfName.DOS,value);}
    }

    /**
      <summary>Gets/Sets the Windows-specific embedded file.</summary>
    */
    public EmbeddedFile WinEmbeddedFile
    {
      get
      {return GetEmbeddedFile(PdfName.DOS);}
      set
      {SetEmbeddedFile(PdfName.DOS,value);}
    }

    /**
      <summary>Gets/Sets the Windows-specific file name.</summary>
    */
    public string WinName
    {
      get
      {return GetName(PdfName.DOS);}
      set
      {SetName(PdfName.DOS,value);}
    }
    #endregion

    #region private
    /**
      <summary>Gets the related files associated to the given key.</summary>
    */
    private RelatedFiles GetDependencies(
      PdfName key
      )
    {
      /*
        NOTE: 'RF' entry may be undefined.
      */
      PdfDictionary dependenciesObject = (PdfDictionary)BaseDataObject[PdfName.RF];
      if(dependenciesObject == null)
        return null;

      /*
        NOTE: key entry may be undefined.
      */
      PdfReference dependencyFilesObject = (PdfReference)dependenciesObject[key];
      if(dependencyFilesObject == null)
        return null;

      return new RelatedFiles(dependencyFilesObject,Container);
    }

    /**
      <summary>Gets the embedded file associated to the given key.</summary>
    */
    private EmbeddedFile GetEmbeddedFile(
      PdfName key
      )
    {
      /*
        NOTE: 'EF' entry may be undefined.
      */
      PdfDictionary embeddedFilesObject = (PdfDictionary)BaseDataObject[PdfName.EF];
      if(embeddedFilesObject == null)
        return null;

      /*
        NOTE: key entry may be undefined.
      */
      PdfReference embeddedFileObject = (PdfReference)embeddedFilesObject[key];
      if(embeddedFileObject == null)
        return null;

      return new EmbeddedFile(embeddedFileObject);
    }

    /**
      <summary>Gets the file name associated to the given key.</summary>
    */
    private string GetName(
      PdfName key
      )
    {
      /*
        NOTE: key entry may be undefined.
      */
      PdfString nameObject = (PdfString)BaseDataObject[key];
      if(nameObject == null)
        return null;

      return (string)nameObject.Value;
    }

    private void SetDependencies(
      PdfName key,
      RelatedFiles value
      )
    {
      /*
        NOTE: 'RF' entry may be undefined.
      */
      PdfDictionary dependenciesObject = (PdfDictionary)BaseDataObject[PdfName.RF];
      if(dependenciesObject == null)
      {
        dependenciesObject = new PdfDictionary();
        BaseDataObject[PdfName.RF] = dependenciesObject;
      }

      dependenciesObject[key] = value.BaseObject;
    }

    private void SetEmbeddedFile(
      PdfName key,
      EmbeddedFile value
      )
    {
      /*
        NOTE: 'EF' entry may be undefined.
      */
      PdfDictionary embeddedFilesObject = (PdfDictionary)BaseDataObject[PdfName.EF];
      if(embeddedFilesObject == null)
      {
        embeddedFilesObject = new PdfDictionary();
        BaseDataObject[PdfName.EF] = embeddedFilesObject;
      }

      embeddedFilesObject[key] = value.BaseObject;
    }

    private void SetName(
      PdfName key,
      string value
      )
    {BaseDataObject[key] = new PdfString(value);}
    #endregion
    #endregion
    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.