2009-05-10 20:28:45 -04:00
|
|
|
/* ====================================================================
|
|
|
|
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.hssf.record.aggregates;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.apache.poi.hssf.model.RecordStream;
|
2009-12-19 06:37:45 -05:00
|
|
|
import org.apache.poi.hssf.record.*;
|
2009-05-10 20:28:45 -04:00
|
|
|
|
|
|
|
/**
|
2016-06-13 19:08:13 -04:00
|
|
|
* Manages the all the records associated with a 'Custom View Settings' sub-stream.<p>
|
2009-05-10 20:28:45 -04:00
|
|
|
* Includes the initial USERSVIEWBEGIN(0x01AA) and final USERSVIEWEND(0x01AB).
|
|
|
|
*/
|
|
|
|
public final class CustomViewSettingsRecordAggregate extends RecordAggregate {
|
|
|
|
|
|
|
|
private final Record _begin;
|
|
|
|
private final Record _end;
|
|
|
|
/**
|
|
|
|
* All the records between BOF and EOF
|
|
|
|
*/
|
|
|
|
private final List<RecordBase> _recs;
|
|
|
|
private PageSettingsBlock _psBlock;
|
|
|
|
|
|
|
|
public CustomViewSettingsRecordAggregate(RecordStream rs) {
|
|
|
|
_begin = rs.getNext();
|
2009-12-19 06:37:45 -05:00
|
|
|
if (_begin.getSid() != UserSViewBegin.sid) {
|
2009-05-10 20:28:45 -04:00
|
|
|
throw new IllegalStateException("Bad begin record");
|
|
|
|
}
|
|
|
|
List<RecordBase> temp = new ArrayList<RecordBase>();
|
2009-12-19 06:37:45 -05:00
|
|
|
while (rs.peekNextSid() != UserSViewEnd.sid) {
|
2009-05-10 20:28:45 -04:00
|
|
|
if (PageSettingsBlock.isComponentRecord(rs.peekNextSid())) {
|
2015-08-25 04:28:54 -04:00
|
|
|
if (_psBlock != null) {
|
|
|
|
if (rs.peekNextSid() == HeaderFooterRecord.sid) {
|
|
|
|
// test samples: 45538_classic_Footer.xls, 45538_classic_Header.xls
|
|
|
|
_psBlock.addLateHeaderFooter((HeaderFooterRecord)rs.getNext());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw new IllegalStateException(
|
|
|
|
"Found more than one PageSettingsBlock in chart sub-stream, had sid: " + rs.peekNextSid());
|
|
|
|
}
|
2009-05-10 20:28:45 -04:00
|
|
|
_psBlock = new PageSettingsBlock(rs);
|
|
|
|
temp.add(_psBlock);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
temp.add(rs.getNext());
|
|
|
|
}
|
|
|
|
_recs = temp;
|
|
|
|
_end = rs.getNext(); // no need to save EOF in field
|
2009-12-19 06:37:45 -05:00
|
|
|
if (_end.getSid() != UserSViewEnd.sid) {
|
2009-05-10 20:28:45 -04:00
|
|
|
throw new IllegalStateException("Bad custom view settings end record");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void visitContainedRecords(RecordVisitor rv) {
|
|
|
|
if (_recs.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rv.visitRecord(_begin);
|
|
|
|
for (int i = 0; i < _recs.size(); i++) {
|
|
|
|
RecordBase rb = _recs.get(i);
|
|
|
|
if (rb instanceof RecordAggregate) {
|
|
|
|
((RecordAggregate) rb).visitContainedRecords(rv);
|
|
|
|
} else {
|
|
|
|
rv.visitRecord((Record) rb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rv.visitRecord(_end);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isBeginRecord(int sid) {
|
2009-12-19 06:37:45 -05:00
|
|
|
return sid == UserSViewBegin.sid;
|
2009-05-10 20:28:45 -04:00
|
|
|
}
|
2009-12-19 06:37:45 -05:00
|
|
|
|
|
|
|
public void append(RecordBase r){
|
|
|
|
_recs.add(r);
|
|
|
|
}
|
2009-05-10 20:28:45 -04:00
|
|
|
}
|