001: /*
002: * Copyright (c) 2007, intarsys consulting GmbH
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * - Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * - Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * - Neither the name of intarsys nor the names of its contributors may be used
015: * to endorse or promote products derived from this software without specific
016: * prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
028: * POSSIBILITY OF SUCH DAMAGE.
029: */
030: package de.intarsys.pdf.st;
031:
032: import de.intarsys.pdf.cos.COSArray;
033: import de.intarsys.pdf.cos.COSDictionary;
034: import de.intarsys.pdf.cos.COSInteger;
035: import de.intarsys.pdf.cos.COSName;
036: import de.intarsys.pdf.cos.COSObject;
037: import de.intarsys.pdf.cos.COSStream;
038: import de.intarsys.pdf.cos.COSTrailer;
039: import de.intarsys.pdf.writer.COSWriter;
040:
041: /**
042: * A section in a stream XRef.
043: */
044: public class STStreamXRefSection extends STXRefSection {
045: public static final COSName DK_Type = COSName.constant("Type");
046:
047: public static final COSName CN_Type_XRef = COSName.constant("XRef");
048:
049: public static final COSName DK_Index = COSName.constant("Index");
050:
051: public static final COSName DK_W = COSName.constant("W");
052:
053: private COSStream stream;
054:
055: public STStreamXRefSection(STDocument doc, long offset,
056: COSStream stream) {
057: super (doc, offset);
058: this .stream = stream;
059: }
060:
061: public STStreamXRefSection(STDocument doc) {
062: super (doc);
063: this .stream = COSStream.create(COSDictionary.create());
064: cosGetDict().put(DK_Type, CN_Type_XRef);
065: }
066:
067: public COSDictionary cosGetDict() {
068: return stream.getDict();
069: }
070:
071: protected boolean isStreamed() {
072: return true;
073: }
074:
075: public COSStream cosGetStream() {
076: return stream;
077: }
078:
079: protected COSArray getIndex() {
080: COSArray index = cosGetDict().get(DK_Index).asArray();
081: if (index == null) {
082: index = COSArray.create(2);
083: index.add(COSInteger.create(0));
084: index.add(COSInteger.create(getSize()));
085: }
086: return index;
087: }
088:
089: public void setIndex(COSArray index) {
090: cosGetDict().put(DK_Index, index);
091: }
092:
093: protected COSArray getW() {
094: return cosGetDict().get(DK_W).asArray();
095: }
096:
097: protected void setW(COSArray wArray) {
098: cosGetDict().put(DK_W, wArray);
099: }
100:
101: protected void cosSetStream(COSStream pStream) {
102: this .stream = pStream;
103: }
104:
105: public STXRefSection createSuccessor() {
106: STStreamXRefSection newXRefSection = new STStreamXRefSection(
107: getDoc());
108: newXRefSection.cosGetDict().put(COSTrailer.DK_ID,
109: cosGetDict().get(COSTrailer.DK_ID).copyShallow());
110: newXRefSection.cosGetDict().put(COSTrailer.DK_Root,
111: cosGetDict().get(COSTrailer.DK_Root));
112: newXRefSection.cosGetDict().put(COSTrailer.DK_Info,
113: cosGetDict().get(COSTrailer.DK_Info));
114: newXRefSection.cosGetDict().put(COSTrailer.DK_Encrypt,
115: cosGetDict().get(COSTrailer.DK_Encrypt));
116:
117: newXRefSection.setPrevious(this );
118: return newXRefSection;
119: }
120:
121: public COSObject cosGetObject() {
122: return stream;
123: }
124:
125: public AbstractXRefWriter getWriter(COSWriter cosWriter) {
126: return new XRefStreamWriter(cosWriter);
127: }
128: }
|