本文整理汇总了Java中org.odftoolkit.odfdom.doc.OdfDocument.loadDocument方法的典型用法代码示例。如果您正苦于以下问题:Java OdfDocument.loadDocument方法的具体用法?Java OdfDocument.loadDocument怎么用?Java OdfDocument.loadDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.odftoolkit.odfdom.doc.OdfDocument
的用法示例。
在下文中一共展示了OdfDocument.loadDocument方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import org.odftoolkit.odfdom.doc.OdfDocument; //导入方法依赖的package包/类
@Override
public ByteArrayOutputStream convert(InputStream stream) {
OdfDocument document = null;
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
try {
document = OdfDocument.loadDocument(stream);
PdfOptions options = PdfOptions.create();
PdfConverter.getInstance().convert(document, outStream, options);
return outStream;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例2: loadFromStream
import org.odftoolkit.odfdom.doc.OdfDocument; //导入方法依赖的package包/类
@Override
public boolean loadFromStream(InputStream is, boolean asTemplate){
logger.info("loadFromStream: " + (file != null));
if (!ensureClosed()) {
return false;
}
if (file != null) {
closeFile();
}
try {
file = File.createTempFile(getTempPrefix(), ".odt");
logger.info("loadFromStream: " + file.toString());
file.deleteOnExit();
odt = (OdfTextDocument) OdfDocument.loadDocument(is);
odt.save(file);
fileValid();
logger.info("loadFromStream: saved (but not yet converted) " + file.toString());
} catch (Exception e) {
e.printStackTrace();
logger.info("loadFromStream: loading document failed ");
return false;
}
return true;
}
示例3: main
import org.odftoolkit.odfdom.doc.OdfDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// https://weblogs.java.net/blog/mullan/archive/2008/02/using_jsr_105_w.html
XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM",
new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
OdfDocument doc = OdfDocument.loadDocument(new File(
"testdata/sign_hello_world.odt"));
System.out.println(doc.getOfficeMetadata().getDocumentStatistic()
.getCharacterCount());
for (String fileEntry : doc.getPackage().getFilePaths()) {
// System.out.println(fileEntry);
if (fileEntry.startsWith("META-INF/documentsignatures.xml")) {
// we found signature file create DocumentSignatureGroup and att
// to list
// parse file to find all Document signatures
org.w3c.dom.Document docSig = doc.getPackage()
.getDom(fileEntry);
Node nodeSig = docSig.getFirstChild();
Element sigElement = (Element) nodeSig.getFirstChild();
System.out.println(sigElement.getNodeName());
X509Certificate cert = parseSigGetCertOnly(sigElement);
// https://github.com/pruiz/signserver/blob/master/signserver/modules/SignServer-Lib-ODFDOM/src/main/java/org/odftoolkit/odfdom/pkg/signature/DocumentSignature.java
DOMValidateContext dvc = new DOMValidateContext(
cert.getPublicKey(), sigElement);
dvc.setURIDereferencer(new ODFURIDereferencer(doc, factory
.getURIDereferencer()));
javax.xml.crypto.dsig.XMLSignature sig = factory
.unmarshalXMLSignature(dvc);
System.out.println(sig);
// validate signature
boolean validate = sig.validate(dvc);
System.out.println("VALIDATE RESULT:" + validate);
}
}
}
示例4: main
import org.odftoolkit.odfdom.doc.OdfDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// https://weblogs.java.net/blog/mullan/archive/2008/02/using_jsr_105_w.html
XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM",
new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
String pathEmail = "testdata/sign_hello_world.odt";
String pathCitizen = "testdata/notupload/citzen_hello_world.odt";
String pathY12Studio = "testdata/notupload/y12studio_hello_world.odt";
String pathY12StudioAndCitizen = "testdata/notupload/y12studio_and_citizen_hello_world.odt";
OdfDocument doc = OdfDocument.loadDocument(new File(
pathY12StudioAndCitizen));
for (String fileEntry : doc.getPackage().getFilePaths()) {
// System.out.println(fileEntry);
if (fileEntry.startsWith("META-INF/documentsignatures.xml")) {
// we found signature file create DocumentSignatureGroup and att
// to list
// parse file to find all Document signatures
org.w3c.dom.Document docSig = doc.getPackage()
.getDom(fileEntry);
Node nodeSig = docSig.getFirstChild();
System.out.println(nodeSig.getNodeName());
System.out.println(nodeSig.getChildNodes().getLength());
for (int i = 0; i < nodeSig.getChildNodes().getLength(); i++) {
Node n = nodeSig.getChildNodes().item(i);
Element sigElement = (Element) n;
System.out.println(sigElement.getNodeName());
if (sigElement.getNodeName().equals("Signature")) {
X509Certificate cert = parseSigGetCertOnly(sigElement);
// https://github.com/pruiz/signserver/blob/master/signserver/modules/SignServer-Lib-ODFDOM/src/main/java/org/odftoolkit/odfdom/pkg/signature/DocumentSignature.java
DOMValidateContext dvc = new DOMValidateContext(
cert.getPublicKey(), sigElement);
dvc.setURIDereferencer(new ODFURIDereferencer(doc,
factory.getURIDereferencer()));
javax.xml.crypto.dsig.XMLSignature sig = factory
.unmarshalXMLSignature(dvc);
System.out.println(sig);
try {
// validate signature
boolean validate = sig.validate(dvc);
System.out.println("VALIDATE RESULT:" + validate);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
}
}
示例5: parseOneFile
import org.odftoolkit.odfdom.doc.OdfDocument; //导入方法依赖的package包/类
@Override
public void parseOneFile(
Project project,
ProjectMetadata metadata,
ImportingJob job,
String fileSource,
InputStream inputStream,
int limit,
JSONObject options,
List<Exception> exceptions
) {
OdfDocument odfDoc;
try {
odfDoc = OdfDocument.loadDocument(inputStream);
} catch (Exception e) { // Ugh! could they throw any wider exception?
exceptions.add(e);
return;
}
List<OdfTable> tables = odfDoc.getTableList();
int[] sheets = JSONUtilities.getIntArray(options, "sheets");
for (int sheetIndex : sheets) {
final OdfTable table = tables.get(sheetIndex);
final int lastRow = table.getRowCount();
TableDataReader dataReader = new TableDataReader() {
int nextRow = 0;
Map<String, Recon> reconMap = new HashMap<String, Recon>();
@Override
public List<Object> getNextRowOfCells() throws IOException {
if (nextRow > lastRow) {
return null;
}
List<Object> cells = new ArrayList<Object>();
OdfTableRow row = table.getRowByIndex(nextRow++);
if (row != null) {
int lastCell = row.getCellCount();
for (int cellIndex = 0; cellIndex <= lastCell; cellIndex++) {
Cell cell = null;
OdfTableCell sourceCell = row.getCellByIndex(cellIndex);
if (sourceCell != null) {
cell = extractCell(sourceCell, reconMap);
}
cells.add(cell);
}
}
return cells;
}
};
TabularImportingParserBase.readTable(
project,
metadata,
job,
dataReader,
fileSource + "#" + table.getTableName(),
limit,
options,
exceptions
);
}
}