1 // PackagePropertiesPart.cs created with MonoDevelop
2 // User: alan at 11:07 04/11/2008
4 // To change standard headers go to Edit->Preferences->Coding->Standard Headers
10 namespace System
.IO
.Packaging
12 class PackagePropertiesPart
: PackageProperties
14 const string NSDc
= "http://purl.org/dc/elements/1.1/";
15 const string NSDcTerms
= "http://purl.org/dc/terms/";
16 const string NSXsi
= "http://www.w3.org/2001/XMLSchema-instance";
27 string lastModifiedBy
;
28 DateTime
? lastPrinted
;
35 public PackagePropertiesPart ()
40 public override string Category
{
45 Package
.CheckIsReadOnly ();
49 public override string ContentStatus
{
54 Package
.CheckIsReadOnly ();
55 contentStatus
= value;
58 public override string ContentType
{
63 Package
.CheckIsReadOnly ();
67 public override DateTime
? Created
{
72 Package
.CheckIsReadOnly ();
76 public override string Creator
{
81 Package
.CheckIsReadOnly ();
85 public override string Description
{
90 Package
.CheckIsReadOnly ();
94 public override string Identifier
{
99 Package
.CheckIsReadOnly ();
103 public override string Keywords
{
108 Package
.CheckIsReadOnly ();
112 public override string Language
{
117 Package
.CheckIsReadOnly ();
121 public override string LastModifiedBy
{
123 return lastModifiedBy
;
126 Package
.CheckIsReadOnly ();
127 lastModifiedBy
= value;
130 public override DateTime
? LastPrinted
{
135 Package
.CheckIsReadOnly ();
139 public override DateTime
? Modified
{
144 Package
.CheckIsReadOnly ();
148 public override string Revision
{
153 Package
.CheckIsReadOnly ();
157 public override string Subject
{
162 Package
.CheckIsReadOnly ();
166 public override string Title
{
171 Package
.CheckIsReadOnly ();
175 public override string Version
{
180 Package
.CheckIsReadOnly ();
185 internal override void LoadFrom (Stream stream
)
187 if (stream
.Length
== 0)
190 XmlDocument doc
= new XmlDocument ();
193 XmlNamespaceManager manager
= new XmlNamespaceManager (doc
.NameTable
);
194 manager
.AddNamespace ("prop", NSPackageProperties
);
195 manager
.AddNamespace ("dc", NSDc
);
196 manager
.AddNamespace ("dcterms", NSDcTerms
);
197 manager
.AddNamespace ("xsi", NSXsi
);
200 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/prop:category", manager
)) != null)
201 category
= node
.InnerXml
;
202 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/prop:contentStatus", manager
)) != null)
203 contentStatus
= node
.InnerXml
;
204 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/prop:contentType", manager
)) != null)
205 contentType
= node
.InnerXml
;
206 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/dcterms:created", manager
)) != null)
207 created
= DateTime
.Parse (node
.InnerXml
);
208 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/dc:creator", manager
)) != null)
209 creator
= node
.InnerXml
;
210 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/dc:description", manager
)) != null)
211 description
= node
.InnerXml
;
212 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/dc:identifier", manager
)) != null)
213 identifier
= node
.InnerXml
;
214 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/prop:keywords", manager
)) != null)
215 keywords
= node
.InnerXml
;
216 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/dc:language", manager
)) != null)
217 language
= node
.InnerXml
;
218 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/prop:lastModifiedBy", manager
)) != null)
219 lastModifiedBy
= node
.InnerXml
;
220 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/prop:lastPrinted", manager
)) != null)
221 lastPrinted
= DateTime
.Parse (node
.InnerXml
);
222 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/dcterms:modified", manager
)) != null)
223 modified
= DateTime
.Parse (node
.InnerXml
);
224 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/prop:revision", manager
)) != null)
225 revision
= node
.InnerXml
;
226 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/dc:subject", manager
)) != null)
227 subject
= node
.InnerXml
;
228 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/dc:title", manager
)) != null)
229 title
= node
.InnerXml
;
230 if ((node
= doc
.SelectSingleNode ("prop:coreProperties/prop:version", manager
)) != null)
231 version
= node
.InnerXml
;
234 internal override void WriteTo(XmlTextWriter writer
)
236 XmlDocument doc
= new XmlDocument ();
237 XmlNamespaceManager manager
= new XmlNamespaceManager (doc
.NameTable
);
238 manager
.AddNamespace ("prop", NSPackageProperties
);
239 manager
.AddNamespace ("dc", NSDc
);
240 manager
.AddNamespace ("dcterms", NSDcTerms
);
241 manager
.AddNamespace ("xsi", NSXsi
);
243 // Create XML declaration
244 doc
.AppendChild (doc
.CreateXmlDeclaration ("1.0", "UTF-8", null));
246 // Create root node with required namespace declarations
247 XmlNode coreProperties
= doc
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "coreProperties", NSPackageProperties
));
248 coreProperties
.Attributes
.Append (doc
.CreateAttribute ("xmlns:dc")).Value
= NSDc
;
249 coreProperties
.Attributes
.Append (doc
.CreateAttribute ("xmlns:dcterms")).Value
= NSDcTerms
;
250 coreProperties
.Attributes
.Append (doc
.CreateAttribute ("xmlns:xsi")).Value
= NSXsi
;
252 // Create the children
253 if (Category
!= null)
254 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "category", NSPackageProperties
)).InnerXml
= Category
;
255 if (ContentStatus
!= null)
256 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "contentStatus", NSPackageProperties
)).InnerXml
= ContentStatus
;
257 if (ContentType
!= null)
258 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "contentType", NSPackageProperties
)).InnerXml
= ContentType
;
259 if (Created
.HasValue
)
260 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "dcterms", "created", NSDcTerms
)).InnerXml
= Created
.Value
.ToString ();
262 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "dc", "creator", NSDc
)).InnerXml
= Creator
;
263 if (Description
!= null)
264 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "dc", "description", NSDc
)).InnerXml
= Description
;
265 if (Identifier
!= null)
266 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "dc", "identifier", NSDc
)).InnerXml
= Identifier
;
267 if (Keywords
!= null)
268 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "keywords", NSPackageProperties
)).InnerXml
= Keywords
;
269 if (Language
!= null)
270 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "dc", "language", NSDc
)).InnerXml
= Language
;
271 if (LastModifiedBy
!= null)
272 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "lastModifiedBy", NSPackageProperties
)).InnerXml
= LastModifiedBy
;
273 if (LastPrinted
.HasValue
)
274 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "lastPrinted", NSPackageProperties
)).InnerXml
= LastPrinted
.Value
.ToString ();
275 if (Revision
!= null)
276 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "revision", NSPackageProperties
)).InnerXml
= Revision
;
278 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "dc", "subject", NSDc
)).InnerXml
= Subject
;
280 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "dc", "title", NSDc
)).InnerXml
= Title
;
282 coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "version", NSPackageProperties
)).InnerXml
= Version
;
284 if (Modified
.HasValue
)
286 XmlAttribute att
= doc
.CreateAttribute("xsi", "type", NSXsi
);
287 att
.Value
= "dcterms:W3CDTF";
289 XmlNode modified
= coreProperties
.AppendChild (doc
.CreateNode (XmlNodeType
.Element
, "dcterms", "modified", NSDcTerms
));
290 modified
.Attributes
.Append (att
);
291 modified
.InnerXml
= Modified
.Value
.ToString ();
294 doc
.WriteContentTo (writer
);