Make an initial start on hpbf code
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@687403 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fb80e82009
commit
cfe2045c5d
76
src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java
Normal file
76
src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java
Normal file
@ -0,0 +1,76 @@
|
||||
/* ====================================================================
|
||||
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.hpbf;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.poi.POIDocument;
|
||||
import org.apache.poi.hpbf.model.MainContents;
|
||||
import org.apache.poi.hpbf.model.QuillContents;
|
||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
|
||||
/**
|
||||
* This class provides the basic functionality
|
||||
* for HPBF, our implementation of the publisher
|
||||
* file format.
|
||||
*/
|
||||
public class HPBFDocument extends POIDocument {
|
||||
private MainContents mainContents;
|
||||
private QuillContents quillContents;
|
||||
|
||||
/**
|
||||
* Opens a new publisher document
|
||||
*/
|
||||
public HPBFDocument(POIFSFileSystem fs) throws IOException {
|
||||
this(fs.getRoot(), fs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens an embeded publisher document,
|
||||
* at the given directory.
|
||||
*/
|
||||
public HPBFDocument(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
|
||||
super(dir, fs);
|
||||
|
||||
// Go looking for our interesting child
|
||||
// streams
|
||||
try {
|
||||
mainContents = new MainContents(dir);
|
||||
} catch(FileNotFoundException e) {
|
||||
throw new IllegalArgumentException("File invalid - missing required main Contents part");
|
||||
}
|
||||
try {
|
||||
quillContents = new QuillContents(dir);
|
||||
} catch(FileNotFoundException e) {
|
||||
throw new IllegalArgumentException("File invalid - missing required Quill CONTENTS part");
|
||||
}
|
||||
}
|
||||
|
||||
public MainContents getMainContents() {
|
||||
return mainContents;
|
||||
}
|
||||
public QuillContents getQuillContents() {
|
||||
return quillContents;
|
||||
}
|
||||
|
||||
public void write(OutputStream out) throws IOException {
|
||||
throw new IllegalStateException("Writing is not yet implemented, see http://poi.apache.org/hpbf/");
|
||||
}
|
||||
}
|
68
src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java
Normal file
68
src/scratchpad/src/org/apache/poi/hpbf/model/HPBFPart.java
Normal file
@ -0,0 +1,68 @@
|
||||
/* ====================================================================
|
||||
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.hpbf.model;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||
import org.apache.poi.poifs.filesystem.DocumentEntry;
|
||||
|
||||
/**
|
||||
* Parent class of all HPBF sub-parts, handling
|
||||
* the fiddly reading in / writing out bits
|
||||
* for all of them.
|
||||
*/
|
||||
public abstract class HPBFPart {
|
||||
protected byte[] data;
|
||||
|
||||
public HPBFPart(DirectoryNode baseDir) throws FileNotFoundException, IOException {
|
||||
String[] path = getPath();
|
||||
DirectoryNode dir = getDir(path, baseDir);
|
||||
String name = path[path.length-1];
|
||||
|
||||
DocumentEntry docProps =
|
||||
(DocumentEntry)dir.getEntry(name);
|
||||
|
||||
// Grab the data from the part stream
|
||||
data = new byte[docProps.getSize()];
|
||||
dir.createDocumentInputStream(name).read(data);
|
||||
}
|
||||
private DirectoryNode getDir(String[] path, DirectoryNode baseDir) throws FileNotFoundException {
|
||||
DirectoryNode dir = baseDir;
|
||||
for(int i=0; i<path.length-1; i++) {
|
||||
dir = (DirectoryNode)dir.getEntry(path[i]);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
public void writeOut(DirectoryNode baseDir) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw data that makes up
|
||||
* this document part.
|
||||
*/
|
||||
public byte[] getData() { return data; }
|
||||
|
||||
/**
|
||||
* Returns the path to the part, eg Contents
|
||||
* or Quill, QuillSub, CONTENTS
|
||||
*/
|
||||
public abstract String[] getPath();
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/* ====================================================================
|
||||
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.hpbf.model;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||
|
||||
/**
|
||||
* The main Contents. Not yet understood
|
||||
*/
|
||||
public class MainContents extends HPBFPart {
|
||||
public MainContents(DirectoryNode baseDir)
|
||||
throws FileNotFoundException, IOException {
|
||||
super(baseDir);
|
||||
}
|
||||
|
||||
public String[] getPath() {
|
||||
return new String[] { "Contents" };
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/* ====================================================================
|
||||
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.hpbf.model;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||
|
||||
/**
|
||||
* Quill -> QuillSub -> CONTENTS
|
||||
*/
|
||||
public class QuillContents extends HPBFPart {
|
||||
public QuillContents(DirectoryNode baseDir)
|
||||
throws FileNotFoundException, IOException {
|
||||
super(baseDir);
|
||||
|
||||
// Now parse the first 512 bytes, and produce
|
||||
// all our bits
|
||||
}
|
||||
|
||||
public String[] getPath() {
|
||||
return new String[] {
|
||||
"Quill", "QuillSub", "CONTENTS"
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user