summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/git/SideBandProgressMonitor.java
blob: 0322f180c4b065595313acff63f0079730116d03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright (C) 2008-2010, Google Inc.
 * and other copyright owners as documented in the project's IP log.
 *
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Distribution License v1.0 which
 * accompanies this distribution, is reproduced below, and is
 * available at http://www.eclipse.org/org/documents/edl-v10.php
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above
 *   copyright notice, this list of conditions and the following
 *   disclaimer in the documentation and/or other materials provided
 *   with the distribution.
 *
 * - Neither the name of the Eclipse Foundation, Inc. nor the
 *   names of its contributors may be used to endorse or promote
 *   products derived from this software without specific prior
 *   written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.gitblit.git;

import java.io.IOException;
import java.io.OutputStream;

import org.eclipse.jgit.lib.BatchingProgressMonitor;
import org.eclipse.jgit.lib.Constants;

/** Write progress messages out to the sideband channel. */
class SideBandProgressMonitor extends BatchingProgressMonitor {
	private final OutputStream out;

	private boolean write;

	SideBandProgressMonitor(final OutputStream os) {
		out = os;
		write = true;
	}

	@Override
	protected void onUpdate(String taskName, int workCurr) {
		StringBuilder s = new StringBuilder();
		format(s, taskName, workCurr);
		s.append("   \r"); //$NON-NLS-1$
		send(s);
	}

	@Override
	protected void onEndTask(String taskName, int workCurr) {
		StringBuilder s = new StringBuilder();
		format(s, taskName, workCurr);
		s.append(", done\n"); //$NON-NLS-1$
		send(s);
	}

	private void format(StringBuilder s, String taskName, int workCurr) {
		s.append(taskName);
		s.append(": "); //$NON-NLS-1$
		s.append(workCurr);
	}

	@Override
	protected void onUpdate(String taskName, int cmp, int totalWork, int pcnt) {
		StringBuilder s = new StringBuilder();
		format(s, taskName, cmp, totalWork, pcnt);
		s.append("   \r"); //$NON-NLS-1$
		send(s);
	}

	@Override
	protected void onEndTask(String taskName, int cmp, int totalWork, int pcnt) {
		StringBuilder s = new StringBuilder();
		format(s, taskName, cmp, totalWork, pcnt);
		s.append("\n"); //$NON-NLS-1$
		send(s);
	}

	private void format(StringBuilder s, String taskName, int cmp,
			int totalWork, int pcnt) {
		s.append(taskName);
		s.append(": "); //$NON-NLS-1$
		if (pcnt < 100)
			s.append(' ');
		if (pcnt < 10)
			s.append(' ');
		s.append(pcnt);
		s.append("% ("); //$NON-NLS-1$
		s.append(cmp);
		s.append("/"); //$NON-NLS-1$
		s.append(totalWork);
		s.append(")"); //$NON-NLS-1$
	}

	private void send(StringBuilder s) {
		if (write) {
			try {
				out.write(Constants.encode(s.toString()));
				out.flush();
			} catch (IOException err) {
				write = false;
			}
		}
	}
}
34' href='#n434'>434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
/* ====================================================================
   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 org.apache.poi.hpsf;

import static org.apache.poi.hpsf.ClassIDPredefined.DOC_SUMMARY;
import static org.apache.poi.hpsf.ClassIDPredefined.USER_PROPERTIES;

import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.poi.hpsf.wellknown.PropertyIDMap;

/**
 * Convenience class representing a DocumentSummary Information stream in a
 * Microsoft Office document.
 *
 * @see SummaryInformation
 */
@SuppressWarnings("unused")
public class DocumentSummaryInformation extends PropertySet {

    /**
     * The document name a document summary information stream
     * usually has in a POIFS filesystem.
     */
    public static final String DEFAULT_STREAM_NAME =
        "\005DocumentSummaryInformation";

    /**
     * The DocumentSummaryInformation's first and second sections' format ID.
     */
    public static final ClassID[] FORMAT_ID = {
        DOC_SUMMARY.getClassID(), USER_PROPERTIES.getClassID()
    };

    @Override
    public PropertyIDMap getPropertySetIDMap() {
    	return PropertyIDMap.getDocumentSummaryInformationProperties();
    }


    /**
     * Creates an empty {@link DocumentSummaryInformation}.
     */
    public DocumentSummaryInformation() {
        getFirstSection().setFormatID(DOC_SUMMARY.getClassID());
    }


    /**
     * 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 {@code 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());
        }
    }

    /**
     * Creates a {@link DocumentSummaryInformation} instance from an {@link
     * InputStream} in the Horrible Property Set Format.<p>
     *
     * The constructor reads the first few bytes from the stream
     * and determines whether it is really a property set stream. If
     * it is, it parses the rest of the stream. If it is not, it
     * resets the stream to its beginning in order to let other
     * components mess around with the data and throws an
     * exception.
     *
     * @param stream Holds the data making out the property set
     * stream.
     * @throws IOException
     *    if the {@link InputStream} cannot be accessed as needed.
     * @exception NoPropertySetStreamException
     *    if the input stream does not contain a property set.
     */
    public DocumentSummaryInformation(final InputStream stream)
    throws NoPropertySetStreamException, IOException {
        super(stream);
    }

    /**
     * Returns the category (or {@code null}).
     *
     * @return The category value
     */
    public String getCategory() {
        return getPropertyStringValue(PropertyIDMap.PID_CATEGORY);
    }

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

    /**
     * Removes the category.
     */
    public void removeCategory() {
        remove1stProperty(PropertyIDMap.PID_CATEGORY);
    }



    /**
     * Returns the presentation format (or
     * {@code null}).
     *
     * @return The presentation format value
     */
    public String getPresentationFormat() {
        return getPropertyStringValue(PropertyIDMap.PID_PRESFORMAT);
    }

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

    /**
     * Removes the presentation format.
     */
    public void removePresentationFormat() {
        remove1stProperty(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) {
        set1stProperty(PropertyIDMap.PID_BYTECOUNT, byteCount);
    }

    /**
     * Removes the byte count.
     */
    public void removeByteCount() {
        remove1stProperty(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) {
        set1stProperty(PropertyIDMap.PID_LINECOUNT, lineCount);
    }

    /**
     * Removes the line count.
     */
    public void removeLineCount() {
        remove1stProperty(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) {
        set1stProperty(PropertyIDMap.PID_PARCOUNT, parCount);
    }

    /**
     * Removes the par count.
     */
    public void removeParCount() {
        remove1stProperty(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) {
        set1stProperty(PropertyIDMap.PID_SLIDECOUNT, slideCount);
    }

    /**
     * Removes the slide count.
     */
    public void removeSlideCount() {
        remove1stProperty(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) {
        set1stProperty(PropertyIDMap.PID_NOTECOUNT, noteCount);
    }

    /**
     * Removes the noteCount.
     */
    public void removeNoteCount() {
        remove1stProperty(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) {
        set1stProperty(PropertyIDMap.PID_HIDDENCOUNT, hiddenCount);
    }

    /**
     * Removes the hidden count.
     */
    public void removeHiddenCount() {
        remove1stProperty(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) {
        set1stProperty(PropertyIDMap.PID_MMCLIPCOUNT, mmClipCount);
    }

    /**
     * Removes the mmclip count.
     */
    public void removeMMClipCount() {
        remove1stProperty(PropertyIDMap.PID_MMCLIPCOUNT);
    }



    /**
     * Returns {@code true} when scaling of the thumbnail is
     * desired, {@code 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) {
        set1stProperty(PropertyIDMap.PID_SCALE, scale);
    }

    /**
     * Removes the scale.
     */
    public void removeScale() {
        remove1stProperty(PropertyIDMap.PID_SCALE);
    }



    /**
     * <p>Returns the heading pair (or {@code null})
     * <strong>when this method is implemented. Please note that the
     * return type is likely to change!</strong>
     *
     * @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() {
        remove1stProperty(PropertyIDMap.PID_HEADINGPAIR);
    }



    /**
     * <p>Returns the doc parts (or {@code null})
     * <strong>when this method is implemented. Please note that the
     * return type is likely to change!</strong>
     *
     * @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() {
        remove1stProperty(PropertyIDMap.PID_DOCPARTS);
    }



    /**
     * Returns the manager (or {@code null}).
     *
     * @return The manager value
     */
    public String getManager() {
        return getPropertyStringValue(PropertyIDMap.PID_MANAGER);
    }

    /**
     * Sets the manager.
     *
     * @param manager The manager to set.
     */
    public void setManager(final String manager) {
        set1stProperty(PropertyIDMap.PID_MANAGER, manager);
    }

    /**
     * Removes the manager.
     */
    public void removeManager() {
        remove1stProperty(PropertyIDMap.PID_MANAGER);
    }



    /**
     * Returns the company (or {@code null}).
     *
     * @return The company value
     */
    public String getCompany() {
        return getPropertyStringValue(PropertyIDMap.PID_COMPANY);
    }

    /**
     * Sets the company.
     *
     * @param company The company to set.
     */
    public void setCompany(final String company) {
        set1stProperty(PropertyIDMap.PID_COMPANY, company);
    }

    /**
     * Removes the company.
     */
    public void removeCompany() {
        remove1stProperty(PropertyIDMap.PID_COMPANY);
    }


    /**
     * Returns {@code true} if the custom links are dirty. <p>
     *
     * @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) {
        set1stProperty(PropertyIDMap.PID_LINKSDIRTY, linksDirty);
    }

    /**
     * Removes the links dirty.
     */
    public void removeLinksDirty() {
        remove1stProperty(PropertyIDMap.PID_LINKSDIRTY);
    }


    /**
     * Returns the character count including whitespace, or 0 if the
     *  {@link DocumentSummaryInformation} does not contain this char count.
     * <p>This is the whitespace-including version of {@link SummaryInformation#getCharCount()}
     *
     * @return The character count or {@code null}
     */
    public int getCharCountWithSpaces() {
        return getPropertyIntValue(PropertyIDMap.PID_CCHWITHSPACES);
    }

    /**
     * Sets the character count including whitespace
     *
     * @param count The character count to set.
     */
    public void setCharCountWithSpaces(int count) {
        set1stProperty(PropertyIDMap.PID_CCHWITHSPACES, count);
    }

    /**
     * Removes the character count
     */
    public void removeCharCountWithSpaces() {
        remove1stProperty(PropertyIDMap.PID_CCHWITHSPACES);
    }


    /**
     * Get if the User Defined Property Set has been updated outside of the
     * Application.<p>
     * If it has (true), the hyperlinks should be updated on document load.
     *
     * @return true, if the hyperlinks should be updated on document load
     */
    public boolean getHyperlinksChanged() {
        return getPropertyBooleanValue(PropertyIDMap.PID_HYPERLINKSCHANGED);
    }

    /**
     * Set the flag for if the User Defined Property Set has been updated outside
     *  of the Application.
     *
     * @param changed true, if the User Defined Property Set has been updated
     */
    public void setHyperlinksChanged(boolean changed) {
        set1stProperty(PropertyIDMap.PID_HYPERLINKSCHANGED, changed);
    }

    /**
     * Removes the flag for if the User Defined Property Set has been updated
     *  outside of the Application.
     */
    public void removeHyperlinksChanged() {
        remove1stProperty(PropertyIDMap.PID_HYPERLINKSCHANGED);
    }


    /**
     * Gets the version of the Application which wrote the
     *  Property set, stored with the two high order bytes having the major
     *  version number, and the two low order bytes the minor version number.<p>
     * This will be 0 if no version is set.
     *
     * @return the Application version
     */
    public int getApplicationVersion() {
        return getPropertyIntValue(PropertyIDMap.PID_VERSION);
    }

    /**
     * Sets the Application version, which must be a 4 byte int with
     *  the  two high order bytes having the major version number, and the
     *  two low order bytes the minor version number.
     *
     * @param version the Application version
     */
    public void setApplicationVersion(int version) {
        set1stProperty(PropertyIDMap.PID_VERSION, version);
    }

    /**
     * Removes the Application Version
     */
    public void removeApplicationVersion() {
        remove1stProperty(PropertyIDMap.PID_VERSION);
    }


    /**
     * Returns the VBA digital signature for the VBA project
     * embedded in the document (or {@code null}).
     *
     * @return the VBA digital signature
     */
    public byte[] getVBADigitalSignature() {
        Object value = getProperty(PropertyIDMap.PID_DIGSIG);
        return (value instanceof byte[]) ? (byte[])value : null;
    }

    /**
     * Sets the VBA digital signature for the VBA project
     *  embedded in the document.
     *
     * @param signature VBA Digital Signature for the project
     */
    public void setVBADigitalSignature(byte[] signature) {
        set1stProperty(PropertyIDMap.PID_DIGSIG, signature);
    }

    /**
     * Removes the VBA Digital Signature
     */
    public void removeVBADigitalSignature() {
        remove1stProperty(PropertyIDMap.PID_DIGSIG);
    }


    /**
     * Gets the content type of the file (or {@code null}).
     *
     * @return the content type of the file
     */
    public String getContentType() {
        return getPropertyStringValue(PropertyIDMap.PID_CONTENTTYPE);
    }

    /**
     * Sets the content type of the file
     *
     * @param type the content type of the file
     */
    public void setContentType(String type) {
        set1stProperty(PropertyIDMap.PID_CONTENTTYPE, type);
    }

    /**
     * Removes the content type of the file
     */
    public void removeContentType() {
        remove1stProperty(PropertyIDMap.PID_CONTENTTYPE);
    }


    /**
     * Gets the content status of the file (or {@code null}).
     *
     * @return the content status of the file
     */
    public String getContentStatus() {
        return getPropertyStringValue(PropertyIDMap.PID_CONTENTSTATUS);
    }

    /**
     * Sets the content status of the file
     *
     * @param status the content status of the file
     */
    public void setContentStatus(String status) {
        set1stProperty(PropertyIDMap.PID_CONTENTSTATUS, status);
    }

    /**
     * Removes the content status of the file
     */
    public void removeContentStatus() {
        remove1stProperty(PropertyIDMap.PID_CONTENTSTATUS);
    }


    /**
     * Gets the document language, which is normally unset and empty (or {@code null}).
     *
     * @return the document language
     */
    public String getLanguage() {
        return getPropertyStringValue(PropertyIDMap.PID_LANGUAGE);
    }

    /**
     * Set the document language
     *
     * @param language the document language
     */
    public void setLanguage(String language) {
        set1stProperty(PropertyIDMap.PID_LANGUAGE, language);
    }

    /**
     * Removes the document language
     */
    public void removeLanguage() {
        remove1stProperty(PropertyIDMap.PID_LANGUAGE);
    }


    /**
     * Gets the document version as a string, which is normally unset and empty
     *  (or {@code null}).
     *
     *  @return the document verion
     */
    public String getDocumentVersion() {
        return getPropertyStringValue(PropertyIDMap.PID_DOCVERSION);
    }

    /**
     * Sets the document version string
     *
     * @param version the document version string
     */
    public void setDocumentVersion(String version) {
        set1stProperty(PropertyIDMap.PID_DOCVERSION, version);
    }

    /**
     * Removes the document version string
     */
    public void removeDocumentVersion() {
        remove1stProperty(PropertyIDMap.PID_DOCVERSION);
    }


    /**
     * Gets the custom properties.
     *
     * @return The custom properties.
     */
    public CustomProperties getCustomProperties() {
        CustomProperties cps = null;
        if (getSectionCount() >= 2) {
            cps = new CustomProperties();
            final Section section = getSections().get(1);
            final Map<Long,String> dictionary = section.getDictionary();
            final Property[] properties = section.getProperties();
            int propertyCount = 0;
            for (Property p : properties) {
                final long id = p.getID();
                if (id == PropertyIDMap.PID_CODEPAGE) {
                    cps.setCodepage((Integer)p.getValue());
                } else if (id > PropertyIDMap.PID_CODEPAGE) {
                    propertyCount++;
                    final CustomProperty cp = new CustomProperty(p, dictionary.get(id));
                    cps.put(cp.getName(), cp);
                }
            }
            if (cps.size() != propertyCount) {
                cps.setPure(false);
            }
        }
        return cps;
    }

    /**
     * Sets the custom properties.
     *
     * @param customProperties The custom properties
     */
    public void setCustomProperties(final CustomProperties customProperties) {
        ensureSection2();
        final Section section = getSections().get(1);
        final Map<Long,String> 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 ISO-8859-1. */
        int cpCodepage = customProperties.getCodepage();
        if (cpCodepage < 0) {
            cpCodepage = section.getCodepage();
        }
        if (cpCodepage < 0) {
            cpCodepage = Property.DEFAULT_CODEPAGE;
        }
        customProperties.setCodepage(cpCodepage);
        section.setCodepage(cpCodepage);
        section.setDictionary(dictionary);
        for (CustomProperty p : customProperties.properties()) {
            section.setProperty(p);
        }
    }

    /**
     * Creates section 2 if it is not already present.
     */
    private void ensureSection2() {
        if (getSectionCount() < 2) {
            Section s2 = new Section();
            s2.setFormatID(USER_PROPERTIES.getClassID());
            addSection(s2);
        }
    }

    /**
     * Removes the custom properties.
     */
    public void removeCustomProperties() {
        if (getSectionCount() < 2) {
            throw new HPSFRuntimeException("Illegal internal format of Document SummaryInformation stream: second section is missing.");
        }

        List<Section> l = new LinkedList<>(getSections());
        clearSections();
        int idx = 0;
        for (Section s : l) {
            if (idx++ != 1) {
                addSection(s);
            }
        }
    }

    /**
     * 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.");
    }
}