All Downloads are FREE. Search and download functionalities are using the official Maven repository.

loci.poi.hpsf.DocumentSummaryInformation Maven / Gradle / Ivy

Go to download

Java API to handle Microsoft OLE 2 Compound Document format (Word, Excel). Based on poi-2.5.1-final-20040804.jar, with bugfixes for OLE v2 and memory efficiency improvements. Used by Bio-Formats for OLE support (cxd, ipw, oib, zvi). Used by VisBio overlays logic for XLS export feature.

The newest version!
/*
 * #%L
 * Fork of Apache Jakarta POI.
 * %%
 * Copyright (C) 2008 - 2016 Open Microscopy Environment:
 *   - Board of Regents of the University of Wisconsin-Madison
 *   - Glencoe Software, Inc.
 *   - University of Dundee
 * %%
 * Licensed 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.
 * #L%
 */

/* ====================================================================
   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.
==================================================================== */
        
package loci.poi.hpsf;

import java.util.Iterator;
import java.util.Map;

import loci.poi.hpsf.wellknown.PropertyIDMap;
import loci.poi.hpsf.wellknown.SectionIDMap;

/**
 * 

Convenience class representing a DocumentSummary Information stream in a * Microsoft Office document.

* * @author Rainer Klute <[email protected]> * @author Drew Varner (Drew.Varner closeTo sc.edu) * @author [email protected] * @see SummaryInformation * @version $Id: DocumentSummaryInformation.java 489730 2006-12-22 19:18:16Z bayard $ * @since 2002-02-09 */ public class DocumentSummaryInformation extends SpecialPropertySet { /** *

The document name a document summary information stream * usually has in a POIFS filesystem.

*/ public static final String DEFAULT_STREAM_NAME = "\005DocumentSummaryInformation"; /** *

Creates a {@link DocumentSummaryInformation} from a given * {@link PropertySet}.

* * @param ps A property set which should be created from a * document summary information stream. * @throws UnexpectedPropertySetTypeException if ps * does not contain a document summary information stream. */ public DocumentSummaryInformation(final PropertySet ps) throws UnexpectedPropertySetTypeException { super(ps); if (!isDocumentSummaryInformation()) throw new UnexpectedPropertySetTypeException ("Not a " + getClass().getName()); } /** *

Returns the category (or null).

* * @return The category value */ public String getCategory() { return (String) getProperty(PropertyIDMap.PID_CATEGORY); } /** *

Sets the category.

* * @param category The category to set. */ public void setCategory(final String category) { final MutableSection s = (MutableSection) getFirstSection(); s.setProperty(PropertyIDMap.PID_CATEGORY, category); } /** *

Removes the category.

*/ public void removeCategory() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_CATEGORY); } /** *

Returns the presentation format (or * null).

* * @return The presentation format value */ public String getPresentationFormat() { return (String) getProperty(PropertyIDMap.PID_PRESFORMAT); } /** *

Sets the presentation format.

* * @param presentationFormat The presentation format to set. */ public void setPresentationFormat(final String presentationFormat) { final MutableSection s = (MutableSection) getFirstSection(); s.setProperty(PropertyIDMap.PID_PRESFORMAT, presentationFormat); } /** *

Removes the presentation format.

*/ public void removePresentationFormat() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_PRESFORMAT); } /** *

Returns the byte count or 0 if the {@link * DocumentSummaryInformation} does not contain a byte count.

* * @return The byteCount value */ public int getByteCount() { return getPropertyIntValue(PropertyIDMap.PID_BYTECOUNT); } /** *

Sets the byte count.

* * @param byteCount The byte count to set. */ public void setByteCount(final int byteCount) { final MutableSection s = (MutableSection) getFirstSection(); s.setProperty(PropertyIDMap.PID_BYTECOUNT, byteCount); } /** *

Removes the byte count.

*/ public void removeByteCount() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_BYTECOUNT); } /** *

Returns the line count or 0 if the {@link * DocumentSummaryInformation} does not contain a line count.

* * @return The line count value */ public int getLineCount() { return getPropertyIntValue(PropertyIDMap.PID_LINECOUNT); } /** *

Sets the line count.

* * @param lineCount The line count to set. */ public void setLineCount(final int lineCount) { final MutableSection s = (MutableSection) getFirstSection(); s.setProperty(PropertyIDMap.PID_LINECOUNT, lineCount); } /** *

Removes the line count.

*/ public void removeLineCount() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_LINECOUNT); } /** *

Returns the par count or 0 if the {@link * DocumentSummaryInformation} does not contain a par count.

* * @return The par count value */ public int getParCount() { return getPropertyIntValue(PropertyIDMap.PID_PARCOUNT); } /** *

Sets the par count.

* * @param parCount The par count to set. */ public void setParCount(final int parCount) { final MutableSection s = (MutableSection) getFirstSection(); s.setProperty(PropertyIDMap.PID_PARCOUNT, parCount); } /** *

Removes the par count.

*/ public void removeParCount() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_PARCOUNT); } /** *

Returns the slide count or 0 if the {@link * DocumentSummaryInformation} does not contain a slide count.

* * @return The slide count value */ public int getSlideCount() { return getPropertyIntValue(PropertyIDMap.PID_SLIDECOUNT); } /** *

Sets the slideCount.

* * @param slideCount The slide count to set. */ public void setSlideCount(final int slideCount) { final MutableSection s = (MutableSection) getFirstSection(); s.setProperty(PropertyIDMap.PID_SLIDECOUNT, slideCount); } /** *

Removes the slide count.

*/ public void removeSlideCount() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_SLIDECOUNT); } /** *

Returns the note count or 0 if the {@link * DocumentSummaryInformation} does not contain a note count.

* * @return The note count value */ public int getNoteCount() { return getPropertyIntValue(PropertyIDMap.PID_NOTECOUNT); } /** *

Sets the note count.

* * @param noteCount The note count to set. */ public void setNoteCount(final int noteCount) { final MutableSection s = (MutableSection) getFirstSection(); s.setProperty(PropertyIDMap.PID_NOTECOUNT, noteCount); } /** *

Removes the noteCount.

*/ public void removeNoteCount() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_NOTECOUNT); } /** *

Returns the hidden count or 0 if the {@link * DocumentSummaryInformation} does not contain a hidden * count.

* * @return The hidden count value */ public int getHiddenCount() { return getPropertyIntValue(PropertyIDMap.PID_HIDDENCOUNT); } /** *

Sets the hidden count.

* * @param hiddenCount The hidden count to set. */ public void setHiddenCount(final int hiddenCount) { final MutableSection s = (MutableSection) getSections().get(0); s.setProperty(PropertyIDMap.PID_HIDDENCOUNT, hiddenCount); } /** *

Removes the hidden count.

*/ public void removeHiddenCount() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_HIDDENCOUNT); } /** *

Returns the mmclip count or 0 if the {@link * DocumentSummaryInformation} does not contain a mmclip * count.

* * @return The mmclip count value */ public int getMMClipCount() { return getPropertyIntValue(PropertyIDMap.PID_MMCLIPCOUNT); } /** *

Sets the mmclip count.

* * @param mmClipCount The mmclip count to set. */ public void setMMClipCount(final int mmClipCount) { final MutableSection s = (MutableSection) getFirstSection(); s.setProperty(PropertyIDMap.PID_MMCLIPCOUNT, mmClipCount); } /** *

Removes the mmclip count.

*/ public void removeMMClipCount() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_MMCLIPCOUNT); } /** *

Returns true when scaling of the thumbnail is * desired, false if cropping is desired.

* * @return The scale value */ public boolean getScale() { return getPropertyBooleanValue(PropertyIDMap.PID_SCALE); } /** *

Sets the scale.

* * @param scale The scale to set. */ public void setScale(final boolean scale) { final MutableSection s = (MutableSection) getFirstSection(); s.setProperty(PropertyIDMap.PID_SCALE, scale); } /** *

Removes the scale.

*/ public void removeScale() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_SCALE); } /** *

Returns the heading pair (or null) * when this method is implemented. Please note that the * return type is likely to change! * * @return The heading pair value */ public byte[] getHeadingPair() { notYetImplemented("Reading byte arrays "); return (byte[]) getProperty(PropertyIDMap.PID_HEADINGPAIR); } /** *

Sets the heading pair.

* * @param headingPair The heading pair to set. */ public void setHeadingPair(final byte[] headingPair) { notYetImplemented("Writing byte arrays "); } /** *

Removes the heading pair.

*/ public void removeHeadingPair() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_HEADINGPAIR); } /** *

Returns the doc parts (or null) * when this method is implemented. Please note that the * return type is likely to change! * * @return The doc parts value */ public byte[] getDocparts() { notYetImplemented("Reading byte arrays"); return (byte[]) getProperty(PropertyIDMap.PID_DOCPARTS); } /** *

Sets the doc parts.

* * @param docparts The doc parts to set. */ public void setDocparts(final byte[] docparts) { notYetImplemented("Writing byte arrays"); } /** *

Removes the doc parts.

*/ public void removeDocparts() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_DOCPARTS); } /** *

Returns the manager (or null).

* * @return The manager value */ public String getManager() { return (String) getProperty(PropertyIDMap.PID_MANAGER); } /** *

Sets the manager.

* * @param manager The manager to set. */ public void setManager(final String manager) { final MutableSection s = (MutableSection) getFirstSection(); s.setProperty(PropertyIDMap.PID_MANAGER, manager); } /** *

Removes the manager.

*/ public void removeManager() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_MANAGER); } /** *

Returns the company (or null).

* * @return The company value */ public String getCompany() { return (String) getProperty(PropertyIDMap.PID_COMPANY); } /** *

Sets the company.

* * @param company The company to set. */ public void setCompany(final String company) { final MutableSection s = (MutableSection) getFirstSection(); s.setProperty(PropertyIDMap.PID_COMPANY, company); } /** *

Removes the company.

*/ public void removeCompany() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_COMPANY); } /** *

Returns true if the custom links are dirty.

* * @return The links dirty value */ public boolean getLinksDirty() { return getPropertyBooleanValue(PropertyIDMap.PID_LINKSDIRTY); } /** *

Sets the linksDirty.

* * @param linksDirty The links dirty value to set. */ public void setLinksDirty(final boolean linksDirty) { final MutableSection s = (MutableSection) getFirstSection(); s.setProperty(PropertyIDMap.PID_LINKSDIRTY, linksDirty); } /** *

Removes the links dirty.

*/ public void removeLinksDirty() { final MutableSection s = (MutableSection) getFirstSection(); s.removeProperty(PropertyIDMap.PID_LINKSDIRTY); } /** *

Gets the custom properties.

* * @return The custom properties. * @since 2006-02-09 */ public CustomProperties getCustomProperties() { CustomProperties cps = null; if (getSectionCount() >= 2) { cps = new CustomProperties(); final Section section = (Section) getSections().get(1); final Map dictionary = section.getDictionary(); final Property[] properties = section.getProperties(); int propertyCount = 0; for (int i = 0; i < properties.length; i++) { final Property p = properties[i]; final long id = p.getID(); if (id != 0 && id != 1) { propertyCount++; final CustomProperty cp = new CustomProperty(p, (String) dictionary.get(new Long(id))); cps.put(cp.getName(), cp); } } if (cps.size() != propertyCount) cps.setPure(false); } return cps; } /** *

Sets the custom properties.

* * @param customProperties The custom properties * @since 2006-02-07 */ public void setCustomProperties(final CustomProperties customProperties) { ensureSection2(); final MutableSection section = (MutableSection) getSections().get(1); final Map dictionary = customProperties.getDictionary(); 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 = customProperties.getCodepage(); if (cpCodepage < 0) cpCodepage = section.getCodepage(); if (cpCodepage < 0) cpCodepage = Constants.CP_UNICODE; customProperties.setCodepage(cpCodepage); section.setCodepage(cpCodepage); section.setDictionary(dictionary); for (final Iterator i = customProperties.values().iterator(); i.hasNext();) { final Property p = (Property) i.next(); section.setProperty(p); } } /** *

Creates section 2 if it is not already present.

* */ private void ensureSection2() { if (getSectionCount() < 2) { MutableSection s2 = new MutableSection(); s2.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[1]); addSection(s2); } } /** *

Removes the custom properties.

* * @since 2006-02-08 */ public void removeCustomProperties() { if (getSectionCount() >= 2) getSections().remove(1); else throw new HPSFRuntimeException("Illegal internal format of Document SummaryInformation stream: second section is missing."); } /** *

Throws an {@link UnsupportedOperationException} with a message text * telling which functionality is not yet implemented.

* * @param msg text telling was leaves to be implemented, e.g. * "Reading byte arrays". */ private void notYetImplemented(final String msg) { throw new UnsupportedOperationException(msg + " is not yet implemented."); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy