/* ====================================================================
Licensed To the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for Additional information regarding copyright ownership.
The ASF licenses this file To You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed To in writing, software
distributed under the License is distributed on an "AS Is" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
/* ================================================================
* About NPOI
* Author: Tony Qu
* Author's email: tonyqus (at) gmail.com
* Author's Blog: tonyqus.wordpress.com.cn (wp.tonyqus.cn)
* HomePage: http://www.codeplex.com/npoi
* Contributors:
*
* ==============================================================*/
namespace Npoi.Core.HPSF
{
using System;
using System.Collections;
using Npoi.Core.HPSF.Wellknown;
using Npoi.Core.Util;
///
/// Convenience class representing a DocumentSummary Information stream in a
/// Microsoft Office document.
/// @author Rainer Klute
/// klute@rainer-klute.de
/// @author Drew Varner (Drew.Varner cloSeto sc.edu)
/// @author robert_flaherty@hyperion.com
/// @since 2002-02-09
///
[Serializable]
public class DocumentSummaryInformation : SpecialPropertySet
{
/**
* The document name a document summary information stream
* usually has in a POIFS filesystem.
*/
public const string DEFAULT_STREAM_NAME = "\x0005DocumentSummaryInformation";
public override PropertyIDMap PropertySetIDMap
{
get
{
return PropertyIDMap.DocumentSummaryInformationProperties;
}
}
///
/// Initializes a new instance of the class.
///
/// A property Set which should be Created from a
/// document summary information stream.
public DocumentSummaryInformation(PropertySet ps): base(ps)
{
if (!IsDocumentSummaryInformation)
throw new UnexpectedPropertySetTypeException
("Not a " + GetType().Name);
}
///
/// Gets or sets the category.
///
/// The category value
public String Category
{
get
{
return GetPropertyStringValue(PropertyIDMap.PID_CATEGORY);
}
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_CATEGORY, value);
}
}
///
/// Removes the category.
///
public void RemoveCategory()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_CATEGORY);
}
///
/// Gets or sets the presentation format (or null).
///
/// The presentation format value
public String PresentationFormat
{
get { return GetPropertyStringValue(PropertyIDMap.PID_PRESFORMAT); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_PRESFORMAT, value);
}
}
///
/// Removes the presentation format.
///
public void RemovePresentationFormat()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_PRESFORMAT);
}
///
/// Gets or sets the byte count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a byte count.
///
/// The byteCount value
public int ByteCount
{
get
{
return GetPropertyIntValue(PropertyIDMap.PID_BYTECOUNT);
}
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_BYTECOUNT, value);
}
}
///
/// Removes the byte count.
///
public void RemoveByteCount()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_BYTECOUNT);
}
///
/// Gets or sets the line count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a line count.
///
/// The line count value.
public int LineCount
{
get
{
return GetPropertyIntValue(PropertyIDMap.PID_LINECOUNT);
}
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_LINECOUNT, value);
}
}
///
/// Removes the line count.
///
public void RemoveLineCount()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_LINECOUNT);
}
///
/// Gets or sets the par count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a par count.
///
/// The par count value
public int ParCount
{
get { return GetPropertyIntValue(PropertyIDMap.PID_PARCOUNT); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_PARCOUNT, value);
}
}
///
/// Removes the par count.
///
public void RemoveParCount()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_PARCOUNT);
}
///
/// Gets or sets the slide count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a slide count.
///
/// The slide count value
public int SlideCount
{
get { return GetPropertyIntValue(PropertyIDMap.PID_SLIDECOUNT); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_SLIDECOUNT, value);
}
}
///
/// Removes the slide count.
///
public void RemoveSlideCount()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_SLIDECOUNT);
}
///
/// Gets or sets the note count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a note count
///
/// The note count value
public int NoteCount
{
get { return GetPropertyIntValue(PropertyIDMap.PID_NOTECOUNT); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_NOTECOUNT, value);
}
}
///
/// Removes the note count.
///
public void RemoveNoteCount()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_NOTECOUNT);
}
///
/// Gets or sets the hidden count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a hidden
/// count.
///
/// The hidden count value.
public int HiddenCount
{
get { return GetPropertyIntValue(PropertyIDMap.PID_HIDDENCOUNT); }
set
{
MutableSection s = (MutableSection)Sections[0];
s.SetProperty(PropertyIDMap.PID_HIDDENCOUNT, value);
}
}
///
/// Removes the hidden count.
///
public void RemoveHiddenCount()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_HIDDENCOUNT);
}
///
/// Returns the mmclip count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a mmclip
/// count.
///
/// The mmclip count value.
public int MMClipCount
{
get { return GetPropertyIntValue(PropertyIDMap.PID_MMCLIPCOUNT); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_MMCLIPCOUNT, value);
}
}
///
/// Removes the MMClip count.
///
public void RemoveMMClipCount()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_MMCLIPCOUNT);
}
///
/// Gets or sets a value indicating whether this is scale.
///
/// true if cropping is desired; otherwise, false.
public bool Scale
{
get { return GetPropertyBooleanValue(PropertyIDMap.PID_SCALE); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_SCALE, value);
}
}
///
/// Removes the scale.
///
public void RemoveScale()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_SCALE);
}
///
/// Gets or sets the heading pair (or null)
///
/// The heading pair value.
public byte[] HeadingPair
{
get
{
return (byte[])GetProperty(PropertyIDMap.PID_HEADINGPAIR);
}
set {
throw new NotImplementedException("Writing byte arrays ");
}
}
///
/// Removes the heading pair.
///
public void RemoveHeadingPair()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_HEADINGPAIR);
}
///
/// Gets or sets the doc parts.
///
/// The doc parts value
public byte[] Docparts
{
get
{
return (byte[])GetProperty(PropertyIDMap.PID_DOCPARTS);
}
set
{
throw new NotImplementedException("Writing byte arrays");
}
}
///
/// Removes the doc parts.
///
public void RemoveDocparts()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_DOCPARTS);
}
///
/// Gets or sets the manager (or null).
///
/// The manager value
public String Manager
{
get { return GetPropertyStringValue(PropertyIDMap.PID_MANAGER); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_MANAGER, value);
}
}
///
/// Removes the manager.
///
public void RemoveManager()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_MANAGER);
}
///
/// Gets or sets the company (or null).
///
/// The company value
public String Company
{
get { return GetPropertyStringValue(PropertyIDMap.PID_COMPANY); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_COMPANY, value);
}
}
///
/// Removes the company.
///
public void RemoveCompany()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_COMPANY);
}
///
/// Gets or sets a value indicating whether [links dirty].
///
/// true if the custom links are dirty.; otherwise, false.
public bool LinksDirty
{
get { return GetPropertyBooleanValue(PropertyIDMap.PID_LINKSDIRTY); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_LINKSDIRTY, value);
}
}
///
/// Removes the links dirty.
///
public void RemoveLinksDirty()
{
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_LINKSDIRTY);
}
///
/// Gets or sets the custom properties.
///
/// The custom properties.
public CustomProperties CustomProperties
{
get
{
CustomProperties cps = null;
if (SectionCount >= 2)
{
cps = new CustomProperties();
Section section = (Section)Sections[1];
IDictionary dictionary = section.Dictionary;
Property[] properties = section.Properties;
int propertyCount = 0;
for (int i = 0; i < properties.Length; i++)
{
Property p = properties[i];
long id = p.ID;
if (id != 0 && id != 1)
{
propertyCount++;
CustomProperty cp = new CustomProperty(p,
(string)dictionary[id]);
cps.Put(cp.Name, cp);
}
}
if (cps.Count != propertyCount)
cps.IsPure=false;
}
return cps;
}
set
{
EnsureSection2();
MutableSection section = (MutableSection)Sections[1];
IDictionary dictionary = value.Dictionary;
section.Clear();
/* Set the codepage. If both custom properties and section have a
* codepage, the codepage from the custom properties wins, else take the
* one that is defined. If none is defined, take Unicode. */
int cpCodepage = value.Codepage;
if (cpCodepage < 0)
cpCodepage = section.Codepage;
if (cpCodepage < 0)
cpCodepage = CodePageUtil.CP_UNICODE;
value.Codepage=cpCodepage;
section.Codepage=cpCodepage; //add codepage propertyset
section.Dictionary=dictionary; //generate dictionary propertyset
//generate MutableSections
for (IEnumerator i = value.Values.GetEnumerator(); i.MoveNext(); )
{
Property p = (Property)i.Current;
section.SetProperty(p);
}
}
}
///
/// Creates section 2 if it is not alReady present.
///
private void EnsureSection2()
{
if (SectionCount < 2)
{
MutableSection s2 = new MutableSection();
s2.SetFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID2);
AddSection(s2);
}
}
///
/// Removes the custom properties.
///
public void RemoveCustomProperties()
{
if (SectionCount >= 2)
Sections.RemoveAt(1);
else
throw new HPSFRuntimeException("Illegal internal format of Document SummaryInformation stream: second section is missing.");
}
}
}