}
// Creates a new package
- OPCPackage pkg = null;
- pkg = new ZipPackage();
+ OPCPackage pkg = new ZipPackage();
pkg.originalPackagePath = file.getAbsolutePath();
configurePackage(pkg);
}
public static OPCPackage create(OutputStream output) {
- OPCPackage pkg = null;
- pkg = new ZipPackage();
+ OPCPackage pkg = new ZipPackage();
pkg.originalPackagePath = null;
pkg.output = output;
// Create the thumbnail part name
String contentType = ContentTypes
.getContentTypeFromFileExtension(filename);
- PackagePartName thumbnailPartName = null;
+ PackagePartName thumbnailPartName;
try {
thumbnailPartName = PackagingURIHelper.createPartName("/docProps/"
+ filename);
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
-import org.apache.poi.openxml4j.opc.OPCPackage;
-import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackagePartName;
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.openxml4j.opc.*;
import org.apache.poi.util.DocumentHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Content type namespace
*/
- public static final String TYPES_NAMESPACE_URI = "http://schemas.openxmlformats.org/package/2006/content-types";
+ public static final String TYPES_NAMESPACE_URI = PackageNamespaces.CONTENT_TYPES;
/* Xml elements in content type part */
@Override\r
public boolean getFlipHorizontal(){\r
CTGroupTransform2D xfrm = getXfrm();\r
- return (xfrm == null || !xfrm.isSetFlipH()) ? false : xfrm.getFlipH();\r
+ return !(xfrm == null || !xfrm.isSetFlipH()) && xfrm.getFlipH();\r
}\r
\r
@Override\r
public boolean getFlipVertical(){\r
CTGroupTransform2D xfrm = getXfrm();\r
- return (xfrm == null || !xfrm.isSetFlipV()) ? false : xfrm.getFlipV();\r
+ return !(xfrm == null || !xfrm.isSetFlipV()) && xfrm.getFlipV();\r
}\r
\r
@Override\r
\r
// recursively update each shape\r
for(XSLFShape shape : gr.getShapes()) {\r
- XSLFShape newShape = null;\r
+ XSLFShape newShape;\r
if (shape instanceof XSLFTextBox) {\r
newShape = createTextBox();\r
} else if (shape instanceof XSLFAutoShape) {\r
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.util.DocumentHelper;
import org.apache.poi.xssf.usermodel.XSSFTable;
import org.apache.poi.xssf.usermodel.helpers.XSSFSingleXmlCell;
import org.apache.poi.xssf.usermodel.helpers.XSSFXmlColumnPr;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STXmlDataType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
* @param validate if true, validates the XML againts the XML Schema
* @throws SAXException
* @throws ParserConfigurationException
- * @throws TransformerException
- * @throws InvalidFormatException
+ * @throws TransformerException
*/
public void exportToXML(OutputStream os, String encoding, boolean validate) throws SAXException, ParserConfigurationException, TransformerException{
List<XSSFSingleXmlCell> singleXMLCells = map.getRelatedSingleXMLCell();
Document doc = DocumentHelper.createDocument();
- Element root = null;
+ final Element root;
if (isNamespaceDeclared()) {
- root=doc.createElementNS(getNamespace(),rootElement);
+ root = doc.createElementNS(getNamespace(),rootElement);
} else {
root = doc.createElementNS("", rootElement);
}
tableMappings.put(commonXPath, table);
}
-
Collections.sort(xpaths,this);
for(String xpath : xpaths) {
XSSFCell cell = simpleXmlCell.getReferencedCell();
if (cell!=null) {
Node currentNode = getNodeByXPath(xpath,doc.getFirstChild(),doc,false);
- STXmlDataType.Enum dataType = simpleXmlCell.getXmlDataType();
- mapCellOnNode(cell,currentNode,dataType);
+ mapCellOnNode(cell,currentNode);
//remove nodes which are empty in order to keep the output xml valid
if("".equals(currentNode.getTextContent()) && currentNode.getParentNode() != null) {
XSSFXmlColumnPr pointer = tableColumns.get(j-startColumnIndex);
String localXPath = pointer.getLocalXPath();
Node currentNode = getNodeByXPath(localXPath,tableRootNode,doc,false);
- STXmlDataType.Enum dataType = pointer.getXmlDataType();
-
- mapCellOnNode(cell,currentNode,dataType);
+ mapCellOnNode(cell,currentNode);
}
-
}
-
}
-
-
-
}
- } else {
+ } /*else {
// TODO: implement filtering management in xpath
- }
+ }*/
}
boolean isValid = true;
isValid =isValid(doc);
}
-
-
if (isValid) {
/////////////////
}
- private void mapCellOnNode(XSSFCell cell, Node node, STXmlDataType.Enum outputDataType) {
+ private void mapCellOnNode(XSSFCell cell, Node node) {
String value ="";
switch (cell.getCellTypeEnum()) {
}
currentNode = selectedNode;
} else {
-
-
- Node attribute = createAttribute(doc, currentNode, axisName);
-
- currentNode = attribute;
+ currentNode = createAttribute(doc, currentNode, axisName);
}
}
return currentNode;
for(int i =1;i <minLenght; i++) {
- String leftElementName =leftTokens[i];
+ String leftElementName = leftTokens[i];
String rightElementName = rightTokens[i];
if (leftElementName.equals(rightElementName)) {
- Node complexType = getComplexTypeForElement(leftElementName, xmlSchema,localComplexTypeRootNode);
- localComplexTypeRootNode = complexType;
+ localComplexTypeRootNode = getComplexTypeForElement(leftElementName, xmlSchema, localComplexTypeRootNode);
} else {
int leftIndex = indexOfElementInComplexType(leftElementName,localComplexTypeRootNode);
int rightIndex = indexOfElementInComplexType(rightElementName,localComplexTypeRootNode);
}if ( leftIndex > rightIndex) {
return 1;
}
- } else {
+ } /*else {
// NOTE: the xpath doesn't match correctly in the schema
- }
+ }*/
}
}
// Note: we expect that all the complex types are defined at root level
Node complexTypeNode = null;
if (!"".equals(complexTypeName)) {
- complexTypeNode = getComplexTypeNodeFromSchemaChildren(xmlSchema, complexTypeNode, complexTypeName);
+ complexTypeNode = getComplexTypeNodeFromSchemaChildren(xmlSchema, null, complexTypeName);
}
return complexTypeNode;
((FormulaValue)_value)._value = ((FormulaValue)prevValue)._value;
}
}
+
//TODO: implement this correctly
@NotImplemented
/*package*/ CellType computeTypeFromFormula(String formula)
package org.apache.poi.openxml4j.opc.internal;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
// Retrieves core properties part
OPCPackage p = OPCPackage.open(filepath, PackageAccess.READ);
- PackageRelationshipCollection rels = p.getRelationshipsByType(PackageRelationshipTypes.CORE_PROPERTIES);
- PackageRelationship corePropertiesRelationship = rels.getRelationship(0);
- PackagePart coreDocument = p.getPart(corePropertiesRelationship);
-
- assertEquals("application/vnd.openxmlformats-package.core-properties+xml", coreDocument.getContentType());
-
- // TODO - finish writing this test
- assumeTrue("finish writing this test", false);
-
- ContentTypeManager ctm = new ZipContentTypeManager(coreDocument.getInputStream(), p);
+ try {
+ PackageRelationshipCollection rels = p.getRelationshipsByType(PackageRelationshipTypes.CORE_PROPERTIES);
+ PackageRelationship corePropertiesRelationship = rels.getRelationship(0);
+ PackagePart coreDocument = p.getPart(corePropertiesRelationship);
+
+ assertEquals("application/vnd.openxmlformats-package.core-properties+xml", coreDocument.getContentType());
+
+ // TODO - finish writing this test
+ assumeTrue("finish writing this test", false);
+
+ ContentTypeManager ctm = new ZipContentTypeManager(coreDocument.getInputStream(), p);
+ assertNotNull(ctm);
+ } finally {
+ p.close();
+ }
}
/**
@Test
public void addPicture_Stream() throws IOException {
SlideShow<?,?> show = createSlideShow();
- InputStream stream = slTests.openResourceAsStream("clock.jpg");
-
- assertEquals(0, show.getPictureData().size());
- PictureData picture = show.addPicture(stream, PictureType.JPEG);
- assertEquals(1, show.getPictureData().size());
- assertSame(picture, show.getPictureData().get(0));
-
- show.close();
+ try {
+ InputStream stream = slTests.openResourceAsStream("clock.jpg");
+ try {
+ assertEquals(0, show.getPictureData().size());
+ PictureData picture = show.addPicture(stream, PictureType.JPEG);
+ assertEquals(1, show.getPictureData().size());
+ assertSame(picture, show.getPictureData().get(0));
+
+ } finally {
+ stream.close();
+ }
+ } finally {
+ show.close();
+ }
}
@Test
@Test(expected=RuntimeException.class)\r
public void setCellStylePropertyWithInvalidValue() throws IOException {\r
Workbook wb = _testDataProvider.createWorkbook();\r
- Sheet s = wb.createSheet();\r
- Row r = s.createRow(0);\r
- Cell c = r.createCell(0);\r
+ try {\r
+ Sheet s = wb.createSheet();\r
+ Row r = s.createRow(0);\r
+ Cell c = r.createCell(0);\r
\r
- // An invalid BorderStyle constant\r
- CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, 42);\r
- \r
- wb.close();\r
+ // An invalid BorderStyle constant\r
+ CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, 42);\r
+ } finally {\r
+ wb.close();\r
+ }\r
}\r
\r
@Test()\r
CellUtil.setFont(A1, font2);\r
fail("setFont not allowed if font belongs to a different workbook");\r
} catch (final IllegalArgumentException e) {\r
- if (e.getMessage().startsWith("Font does not belong to this workbook")) {\r
- // expected\r
- }\r
- else {\r
+ // one specific message is expected\r
+ if (!e.getMessage().startsWith("Font does not belong to this workbook")) {\r
throw e;\r
}\r
} finally {\r
*/\r
// bug 55555\r
@Test\r
- public void setFillForegroundColorBeforeFillBackgroundColor() {\r
+ public void setFillForegroundColorBeforeFillBackgroundColor() throws IOException {\r
Workbook wb1 = _testDataProvider.createWorkbook();\r
Cell A1 = wb1.createSheet().createRow(0).createCell(0);\r
Map<String, Object> properties = new HashMap<String, Object>();\r
assertEquals("fill pattern", CellStyle.BRICKS, style.getFillPattern());\r
assertEquals("fill foreground color", IndexedColors.BLUE, IndexedColors.fromInt(style.getFillForegroundColor()));\r
assertEquals("fill background color", IndexedColors.RED, IndexedColors.fromInt(style.getFillBackgroundColor()));\r
+ wb1.close();\r
}\r
/**\r
* bug 55555\r
* @since POI 3.15 beta 3\r
*/\r
@Test\r
- public void setFillForegroundColorBeforeFillBackgroundColorEnum() {\r
+ public void setFillForegroundColorBeforeFillBackgroundColorEnum() throws IOException {\r
Workbook wb1 = _testDataProvider.createWorkbook();\r
Cell A1 = wb1.createSheet().createRow(0).createCell(0);\r
Map<String, Object> properties = new HashMap<String, Object>();\r
assertEquals("fill pattern", FillPatternType.BRICKS, style.getFillPatternEnum());\r
assertEquals("fill foreground color", IndexedColors.BLUE, IndexedColors.fromInt(style.getFillForegroundColor()));\r
assertEquals("fill background color", IndexedColors.RED, IndexedColors.fromInt(style.getFillBackgroundColor()));\r
+\r
+ wb1.close();\r
}\r
}\r