Return-Path: Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: (qmail 91182 invoked from network); 24 Jul 2009 07:28:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Jul 2009 07:28:40 -0000 Received: (qmail 5880 invoked by uid 500); 24 Jul 2009 07:29:46 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 5845 invoked by uid 500); 24 Jul 2009 07:29:45 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 5836 invoked by uid 99); 24 Jul 2009 07:29:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jul 2009 07:29:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jul 2009 07:29:43 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5544A2388878; Fri, 24 Jul 2009 07:29:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r797350 - in /poi/trunk/src: documentation/content/xdocs/ documentation/content/xdocs/spreadsheet/ ooxml/java/org/apache/poi/openxml4j/opc/ ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ ooxml/java/org/apache/poi/xssf/usermod... Date: Fri, 24 Jul 2009 07:29:22 -0000 To: commits@poi.apache.org From: yegor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090724072923.5544A2388878@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: yegor Date: Fri Jul 24 07:29:22 2009 New Revision: 797350 URL: http://svn.apache.org/viewvc?rev=797350&view=rev Log: fixed compatibility issues with OpenOffice 3.0 and Excel 2008 Mac sp2, see Bugzilla #46419 and #47559 Modified: poi/trunk/src/documentation/content/xdocs/spreadsheet/quick-guide.xml poi/trunk/src/documentation/content/xdocs/status.xml poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java Modified: poi/trunk/src/documentation/content/xdocs/spreadsheet/quick-guide.xml URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/spreadsheet/quick-guide.xml?rev=797350&r1=797349&r2=797350&view=diff ============================================================================== --- poi/trunk/src/documentation/content/xdocs/spreadsheet/quick-guide.xml (original) +++ poi/trunk/src/documentation/content/xdocs/spreadsheet/quick-guide.xml Fri Jul 24 07:29:22 2009 @@ -22,10 +22,6 @@
Busy Developers' Guide to HSSF and XSSF Features - - - -
Busy Developers' Guide to Features Modified: poi/trunk/src/documentation/content/xdocs/status.xml URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=797350&r1=797349&r2=797350&view=diff ============================================================================== --- poi/trunk/src/documentation/content/xdocs/status.xml (original) +++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Jul 24 07:29:22 2009 @@ -33,6 +33,8 @@ + 46419 - Fixed compatibility issue with OpenOffice 3.0 + 47559 - Fixed compatibility issue with Excel 2008 Max sp2 47540 - Fix for saving custom and extended OOXML properties 47535 - Fixed WordExtractor to tolerate files with empty footnote block 47517 - Fixed ExtractorFactory to support .xltx and .dotx files Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java?rev=797350&r1=797349&r2=797350&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackageRelationship.java Fri Jul 24 07:29:22 2009 @@ -136,7 +136,7 @@ /* Getters */ - public URI getContainerPartRelationship() { + public static URI getContainerPartRelationship() { return containerRelationshipPart; } Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java?rev=797350&r1=797349&r2=797350&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java Fri Jul 24 07:29:22 2009 @@ -259,11 +259,14 @@ * The source part URI. * @param targetURI * The target part URI. + * @param msCompatible if true then remove leading slash from the relativized URI. + * This flag violates [M1.4]: A part name shall start with a forward slash ('/') character, but + * allows generating URIs compatible with MS Office and OpenOffice. * @return A fully relativize part name URI ('word/media/image1.gif', * '/word/document.xml' => 'media/image1.gif') else * null. */ - public static URI relativizeURI(URI sourceURI, URI targetURI) { + public static URI relativizeURI(URI sourceURI, URI targetURI, boolean msCompatible) { StringBuilder retVal = new StringBuilder(); String[] segmentsSource = sourceURI.getPath().split("/", -1); String[] segmentsTarget = targetURI.getPath().split("/", -1); @@ -283,6 +286,15 @@ // If the source is the root, then the relativized // form must actually be an absolute URI if(sourceURI.toString().equals("/")) { + String path = targetURI.getPath(); + if(msCompatible && path.charAt(0) == '/') { + try { + targetURI = new URI(path.substring(1)); + } catch (Exception e) { + System.err.println(e); + return null; + } + } return targetURI; } @@ -358,7 +370,22 @@ } } - /** + /** + * Fully relativize the source part URI against the target part URI. + * + * @param sourceURI + * The source part URI. + * @param targetURI + * The target part URI. + * @return A fully relativize part name URI ('word/media/image1.gif', + * '/word/document.xml' => 'media/image1.gif') else + * null. + */ + public static URI relativizeURI(URI sourceURI, URI targetURI) { + return relativizeURI(sourceURI, targetURI, false); + } + + /** * Resolve a source uri against a target. * * @param sourcePartUri Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java?rev=797350&r1=797349&r2=797350&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java Fri Jul 24 07:29:22 2009 @@ -163,7 +163,7 @@ } else { URI targetURI = rel.getTargetURI(); targetValue = PackagingURIHelper.relativizeURI( - sourcePartURI, targetURI).getPath(); + sourcePartURI, targetURI, true).getPath(); if (targetURI.getRawFragment() != null) { targetValue += "#" + targetURI.getRawFragment(); } Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=797350&r1=797349&r2=797350&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Fri Jul 24 07:29:22 2009 @@ -30,6 +30,7 @@ import org.apache.poi.POIXMLDocument; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLException; +import org.apache.poi.POIXMLProperties; import org.apache.poi.hssf.record.formula.SheetNameFormatter; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.OPCPackage; @@ -228,6 +229,10 @@ bv.setActiveTab(0); workbook.addNewSheets(); + //required by Excel 2008 Mac sp2, see Bugzilla #47559 + POIXMLProperties.ExtendedProperties expProps = getProperties().getExtendedProperties(); + expProps.getUnderlyingProperties().setApplication("Microsoft Excel"); + sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.getInstance()); stylesSource = (StylesTable)createRelationship(XSSFRelation.STYLES, XSSFFactory.getInstance()); Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java?rev=797350&r1=797349&r2=797350&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java Fri Jul 24 07:29:22 2009 @@ -23,6 +23,7 @@ import org.apache.poi.POIXMLDocument; import org.apache.poi.POIXMLException; import org.apache.poi.POIXMLDocumentPart; +import org.apache.poi.POIXMLProperties; import org.apache.poi.util.PackageHelper; import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; import org.apache.xmlbeans.XmlException; @@ -187,6 +188,9 @@ ctDocument = CTDocument1.Factory.newInstance(); ctDocument.addNewBody(); + + POIXMLProperties.ExtendedProperties expProps = getProperties().getExtendedProperties(); + expProps.getUnderlyingProperties().setApplication("Microsoft Office Word"); } /** Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java?rev=797350&r1=797349&r2=797350&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java Fri Jul 24 07:29:22 2009 @@ -27,6 +27,7 @@ import java.lang.reflect.Field; import java.net.URI; import java.util.TreeMap; +import java.util.Iterator; import junit.framework.TestCase; @@ -36,11 +37,14 @@ import org.apache.poi.openxml4j.opc.internal.ContentTypeManager; import org.apache.poi.openxml4j.opc.internal.FileHelper; import org.apache.poi.util.TempFile; +import org.apache.poi.util.IOUtils; +import org.apache.poi.util.POILogger; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.Namespace; import org.dom4j.QName; +import org.dom4j.io.SAXReader; public final class TestPackage extends TestCase { private static Logger logger = Logger.getLogger("org.apache.poi.openxml4j.test"); @@ -185,16 +189,17 @@ // Save and re-load pkg.close(); File tmp = TempFile.createTempFile("testCreatePackageWithCoreDocument", ".zip"); - FileOutputStream fout = new FileOutputStream(tmp); + FileOutputStream fout = new FileOutputStream(tmp); fout.write(baos.toByteArray()); fout.close(); pkg = OPCPackage.open(tmp.getPath()); //tmp.delete(); - + // Check still right coreRels = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT); assertEquals(1, coreRels.size()); coreRel = coreRels.getRelationship(0); + assertEquals("/", coreRel.getSourceURI().toString()); assertEquals("/xl/workbook.xml", coreRel.getTargetURI().toString()); corePart = pkg.getPart(coreRel); @@ -205,10 +210,30 @@ rel = rels.getRelationship(0); assertEquals("Sheet1!A1", rel.getTargetURI().getRawFragment()); + assertMSCompatibility(pkg); + } + + private void assertMSCompatibility(OPCPackage pkg) throws Exception { + PackagePartName relName = PackagingURIHelper.createPartName(PackageRelationship.getContainerPartRelationship()); + PackagePart relPart = pkg.getPart(relName); + SAXReader reader = new SAXReader(); + Document xmlRelationshipsDoc = reader + .read(relPart.getInputStream()); + + Element root = xmlRelationshipsDoc.getRootElement(); + for (Iterator i = root + .elementIterator(PackageRelationship.RELATIONSHIP_TAG_NAME); i + .hasNext();) { + Element element = (Element) i.next(); + String value = element.attribute( + PackageRelationship.TARGET_ATTRIBUTE_NAME) + .getValue(); + assertTrue("Root target must not start with a leadng slash ('/'): " + value, value.charAt(0) != '/'); + } } - /** + /** * Test package opening. */ public void testOpenPackage() throws Exception { Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java?rev=797350&r1=797349&r2=797350&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java Fri Jul 24 07:29:22 2009 @@ -31,8 +31,6 @@ /** * Test relativizePartName() method. - * - * TODO: fix and unable */ public void testRelativizeURI() throws Exception { URI uri1 = new URI("/word/document.xml"); @@ -54,23 +52,15 @@ URI retURI2 = PackagingURIHelper.relativizeURI(uri1, uri1); assertEquals("", retURI2.getPath()); - // Document and root totally different - URI uri4 = new URI("/"); - try { - PackagingURIHelper.relativizeURI(uri1, uri4); - //TODO: figure oout why the assertion fails - //fail("Must throw an exception ! Can't relativize with an empty URI"); - } catch (Exception e) { - // Do nothing - } - try { - PackagingURIHelper.relativizeURI(uri4, uri1); - //TODO: figure oout why the assertion fails - //fail("Must throw an exception ! Can't relativize with an empty URI"); - } catch (Exception e) { - // Do nothing - } - } + // relativization against root + URI root = new URI("/"); + uriRes = PackagingURIHelper.relativizeURI(root, uri1); + assertEquals("/word/document.xml", uriRes.toString()); + + //URI compatible with MS Office and OpenOffice: leading slash is removed + uriRes = PackagingURIHelper.relativizeURI(root, uri1, true); + assertEquals("word/document.xml", uriRes.toString()); + } /** * Test createPartName(String, y) Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=797350&r1=797349&r2=797350&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Fri Jul 24 07:29:22 2009 @@ -260,6 +260,8 @@ XSSFWorkbook workbook = new XSSFWorkbook(); POIXMLProperties props = workbook.getProperties(); assertNotNull(props); + //the Application property must be set for new workbooks, see Bugzilla #47559 + assertEquals("Microsoft Excel", props.getExtendedProperties().getUnderlyingProperties().getApplication()); PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties(); assertNotNull(opcProps); @@ -269,6 +271,7 @@ opcProps.setCreatorProperty("poi-dev@poi.apache.org"); workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); + assertEquals("Microsoft Excel", workbook.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication()); opcProps = workbook.getProperties().getCoreProperties().getUnderlyingProperties(); assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue()); assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue()); Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java?rev=797350&r1=797349&r2=797350&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java Fri Jul 24 07:29:22 2009 @@ -21,6 +21,7 @@ import junit.framework.TestCase; import org.apache.poi.POIXMLDocument; +import org.apache.poi.POIXMLProperties; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.xwpf.usermodel.XWPFDocument; @@ -119,4 +120,12 @@ assertEquals(" ", xml.getProperties().getCoreProperties().getTitle()); assertEquals(" ", xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue()); } + + public void testWorkbookProperties() throws Exception { + XWPFDocument doc = new XWPFDocument(); + POIXMLProperties props = doc.getProperties(); + assertNotNull(props); + assertEquals("Microsoft Office Word", props.getExtendedProperties().getUnderlyingProperties().getApplication()); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org