2008-08-12 16:58:31 -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;
|
|
|
|
|
2010-06-04 08:02:36 -04:00
|
|
|
import junit.framework.TestCase;
|
2008-08-12 16:58:31 -04:00
|
|
|
|
2009-03-18 14:54:01 -04:00
|
|
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
2009-08-23 08:34:24 -04:00
|
|
|
import org.apache.poi.util.PackageHelper;
|
2015-09-30 19:06:39 -04:00
|
|
|
import org.apache.poi.xslf.usermodel.XSLFSlideShow;
|
2010-06-04 08:02:36 -04:00
|
|
|
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
2008-08-12 16:58:31 -04:00
|
|
|
|
2009-08-18 15:49:28 -04:00
|
|
|
public final class TestXMLPropertiesTextExtractor extends TestCase {
|
2009-08-23 08:34:24 -04:00
|
|
|
private static final POIDataSamples _ssSamples = POIDataSamples.getSpreadSheetInstance();
|
2010-06-04 08:02:36 -04:00
|
|
|
private static final POIDataSamples _slSamples = POIDataSamples.getSlideShowInstance();
|
2009-08-18 15:49:28 -04:00
|
|
|
|
2009-01-06 14:09:02 -05:00
|
|
|
public void testGetFromMainExtractor() throws Exception {
|
2009-08-23 08:34:24 -04:00
|
|
|
OPCPackage pkg = PackageHelper.open(_ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm"));
|
|
|
|
|
2009-01-06 14:09:02 -05:00
|
|
|
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
|
|
|
|
|
|
|
XSSFExcelExtractor ext = new XSSFExcelExtractor(wb);
|
|
|
|
POIXMLPropertiesTextExtractor textExt = ext.getMetadataTextExtractor();
|
2009-08-18 15:49:28 -04:00
|
|
|
|
2009-01-06 14:09:02 -05:00
|
|
|
// Check basics
|
|
|
|
assertNotNull(textExt);
|
|
|
|
assertTrue(textExt.getText().length() > 0);
|
2009-08-18 15:49:28 -04:00
|
|
|
|
2009-01-06 14:09:02 -05:00
|
|
|
// Check some of the content
|
|
|
|
String text = textExt.getText();
|
|
|
|
String cText = textExt.getCorePropertiesText();
|
2009-08-18 15:49:28 -04:00
|
|
|
|
2009-01-06 14:09:02 -05:00
|
|
|
assertTrue(text.contains("LastModifiedBy = Yury Batrakov"));
|
|
|
|
assertTrue(cText.contains("LastModifiedBy = Yury Batrakov"));
|
2013-06-17 03:53:59 -04:00
|
|
|
|
|
|
|
textExt.close();
|
|
|
|
ext.close();
|
2009-01-06 14:09:02 -05:00
|
|
|
}
|
2008-08-12 16:58:31 -04:00
|
|
|
|
|
|
|
public void testCore() throws Exception {
|
2009-08-23 08:34:24 -04:00
|
|
|
OPCPackage pkg = PackageHelper.open(
|
|
|
|
_ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm")
|
2008-08-12 16:58:31 -04:00
|
|
|
);
|
|
|
|
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
2009-08-18 15:49:28 -04:00
|
|
|
|
2008-08-12 16:58:31 -04:00
|
|
|
POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(wb);
|
|
|
|
ext.getText();
|
2009-08-18 15:49:28 -04:00
|
|
|
|
2008-08-12 16:58:31 -04:00
|
|
|
// Now check
|
|
|
|
String text = ext.getText();
|
|
|
|
String cText = ext.getCorePropertiesText();
|
2009-08-18 15:49:28 -04:00
|
|
|
|
2008-08-12 16:58:31 -04:00
|
|
|
assertTrue(text.contains("LastModifiedBy = Yury Batrakov"));
|
|
|
|
assertTrue(cText.contains("LastModifiedBy = Yury Batrakov"));
|
2013-06-17 03:53:59 -04:00
|
|
|
|
|
|
|
ext.close();
|
2008-08-12 16:58:31 -04:00
|
|
|
}
|
2009-08-18 15:49:28 -04:00
|
|
|
|
2008-08-12 16:58:31 -04:00
|
|
|
public void testExtended() throws Exception {
|
2009-03-18 14:54:01 -04:00
|
|
|
OPCPackage pkg = OPCPackage.open(
|
2009-08-23 08:34:24 -04:00
|
|
|
_ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm")
|
2008-08-12 16:58:31 -04:00
|
|
|
);
|
|
|
|
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
2009-08-18 15:49:28 -04:00
|
|
|
|
2008-08-12 16:58:31 -04:00
|
|
|
POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(wb);
|
|
|
|
ext.getText();
|
2009-08-18 15:49:28 -04:00
|
|
|
|
2008-08-12 16:58:31 -04:00
|
|
|
// Now check
|
|
|
|
String text = ext.getText();
|
|
|
|
String eText = ext.getExtendedPropertiesText();
|
2009-08-18 15:49:28 -04:00
|
|
|
|
2008-08-12 16:58:31 -04:00
|
|
|
assertTrue(text.contains("Application = Microsoft Excel"));
|
|
|
|
assertTrue(text.contains("Company = Mera"));
|
|
|
|
assertTrue(eText.contains("Application = Microsoft Excel"));
|
|
|
|
assertTrue(eText.contains("Company = Mera"));
|
2013-06-17 03:53:59 -04:00
|
|
|
|
|
|
|
ext.close();
|
2008-08-12 16:58:31 -04:00
|
|
|
}
|
2009-08-18 15:49:28 -04:00
|
|
|
|
2012-01-11 10:51:10 -05:00
|
|
|
public void testCustom() throws Exception {
|
|
|
|
OPCPackage pkg = OPCPackage.open(
|
|
|
|
_ssSamples.openResourceAsStream("ExcelWithAttachments.xlsm")
|
|
|
|
);
|
|
|
|
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
|
|
|
|
|
|
|
POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(wb);
|
|
|
|
ext.getText();
|
|
|
|
|
|
|
|
// Now check
|
|
|
|
String text = ext.getText();
|
|
|
|
String cText = ext.getCustomPropertiesText();
|
|
|
|
|
|
|
|
assertTrue(text.contains("description = another value"));
|
|
|
|
assertTrue(cText.contains("description = another value"));
|
2013-06-17 03:53:59 -04:00
|
|
|
|
|
|
|
ext.close();
|
2008-08-12 16:58:31 -04:00
|
|
|
}
|
2010-06-04 08:02:36 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug #49386 - some properties, especially
|
|
|
|
* dates can be null
|
|
|
|
*/
|
|
|
|
public void testWithSomeNulls() throws Exception {
|
|
|
|
OPCPackage pkg = OPCPackage.open(
|
|
|
|
_slSamples.openResourceAsStream("49386-null_dates.pptx")
|
|
|
|
);
|
|
|
|
XSLFSlideShow sl = new XSLFSlideShow(pkg);
|
|
|
|
|
|
|
|
POIXMLPropertiesTextExtractor ext = new POIXMLPropertiesTextExtractor(sl);
|
|
|
|
ext.getText();
|
|
|
|
|
|
|
|
String text = ext.getText();
|
|
|
|
assertFalse(text.contains("Created =")); // With date is null
|
|
|
|
assertTrue(text.contains("CreatedString = ")); // Via string is blank
|
|
|
|
assertTrue(text.contains("LastModifiedBy = IT Client Services"));
|
2013-06-17 03:53:59 -04:00
|
|
|
|
|
|
|
ext.close();
|
2010-06-04 08:02:36 -04:00
|
|
|
}
|
2008-08-12 16:58:31 -04:00
|
|
|
}
|