You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by sh...@apache.org on 2018/12/02 18:51:51 UTC
svn commit: r1848009 - in
/ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache:
ofbiz/pricat/AbstractPricatParser.java
ofbiz/pricat/sample/SamplePricatParser.java ofbiz/pricat/util/
ofbiz/pricat/util/OFBizPricatUtil.java poi/
Author: shijh
Date: Sun Dec 2 18:51:51 2018
New Revision: 1848009
URL: http://svn.apache.org/viewvc?rev=1848009&view=rev
Log:
Improved: OFBizPricatUtil class don't use a org.apache.ofbiz.pricat package
(OFBIZ-10655)
I didn't realized OFBizPricatUtil under org.apache.poi package is a bug
for OFBiz project at the first sight of this issue. When I tried to think from
Jacques view as our project SQA, I understood this OFBizPricatUtil may be missed
during code style check, and this is a major problem :).
Now I moved the OFBizPricatUtil under org.apache.ofbiz.pricat.util package and
changed two other files accordingly.
I upgraded the implement to match the POI 3.7 used in the OFBiz plugins
trunk, and I also tested it with POI 4.0.0 and it worked fine.
Thanks: Jacques for pointing out this issue
Added:
ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/util/
ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/util/OFBizPricatUtil.java
Removed:
ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/poi/
Modified:
ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/AbstractPricatParser.java
ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/sample/SamplePricatParser.java
Modified: ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/AbstractPricatParser.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/AbstractPricatParser.java?rev=1848009&r1=1848008&r2=1848009&view=diff
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/AbstractPricatParser.java (original)
+++ ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/AbstractPricatParser.java Sun Dec 2 18:51:51 2018
@@ -33,12 +33,12 @@ import javax.servlet.http.HttpServletReq
import javax.servlet.http.HttpSession;
import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.util.WorkbookUtil;
-import org.apache.poi.xssf.usermodel.OFBizPricatUtil;
import org.apache.poi.xssf.usermodel.XSSFAnchor;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
@@ -57,6 +57,7 @@ import org.apache.commons.fileupload.Fil
import org.apache.ofbiz.htmlreport.InterfaceReport;
import org.apache.ofbiz.order.finaccount.FinAccountHelper;
+import org.apache.ofbiz.pricat.util.OFBizPricatUtil;
import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.FileUtil;
import org.apache.ofbiz.base.util.UtilDateTime;
@@ -295,22 +296,22 @@ public abstract class AbstractPricatPars
XSSFCell cell = sourceRow.getCell(j);
if (cell != null) {
XSSFCell newCell = targetRow.createCell(j);
- int cellType = cell.getCellType();
+ CellType cellType = cell.getCellTypeEnum();
newCell.setCellType(cellType);
switch (cellType) {
- case XSSFCell.CELL_TYPE_BOOLEAN:
+ case BOOLEAN:
newCell.setCellValue(cell.getBooleanCellValue());
break;
- case XSSFCell.CELL_TYPE_ERROR:
+ case ERROR:
newCell.setCellErrorValue(cell.getErrorCellValue());
break;
- case XSSFCell.CELL_TYPE_FORMULA:
+ case FORMULA:
newCell.setCellFormula(cell.getCellFormula());
break;
- case XSSFCell.CELL_TYPE_NUMERIC:
+ case NUMERIC:
newCell.setCellValue(cell.getNumericCellValue());
break;
- case XSSFCell.CELL_TYPE_STRING:
+ case STRING:
newCell.setCellValue(cell.getRichStringCellValue());
break;
default:
@@ -427,10 +428,10 @@ public abstract class AbstractPricatPars
cell = row.createCell(i);
}
}
- int cellType = cell.getCellType();
+ CellType cellType = cell.getCellTypeEnum();
String cellValue = formatter.formatCellValue(cell);
if (UtilValidate.isNotEmpty(cellValue)) {
- if (cellType == XSSFCell.CELL_TYPE_FORMULA) {
+ if (cellType == CellType.FORMULA) {
cellValue = BigDecimal.valueOf(cell.getNumericCellValue()).setScale(FinAccountHelper.decimals, FinAccountHelper.rounding).toString();
report.print(((i == 0)?"":", ") + cellValue, InterfaceReport.FORMAT_NOTE);
} else {
@@ -446,13 +447,13 @@ public abstract class AbstractPricatPars
results.add(null);
continue;
}
- if ((Boolean) colNames.get(i)[2] && cellType != (int) colNames.get(i)[1]) {
+ if ((Boolean) colNames.get(i)[2] && cellType != colNames.get(i)[1]) {
// String warningMessage = "";
- if ((int) colNames.get(i)[1] == XSSFCell.CELL_TYPE_STRING) {
+ if (colNames.get(i)[1] == CellType.STRING) {
results.add(cellValue);
- } else if ((int) colNames.get(i)[1] == XSSFCell.CELL_TYPE_NUMERIC) {
- if (cell.getCellType() != XSSFCell.CELL_TYPE_STRING) {
- cell.setCellType(XSSFCell.CELL_TYPE_STRING);
+ } else if (colNames.get(i)[1] == CellType.NUMERIC) {
+ if (cell.getCellTypeEnum() != CellType.STRING) {
+ cell.setCellType(CellType.STRING);
}
try {
results.add(BigDecimal.valueOf(Double.parseDouble(cell.getStringCellValue())).setScale(FinAccountHelper.decimals, FinAccountHelper.rounding));
@@ -466,21 +467,21 @@ public abstract class AbstractPricatPars
results.add(null);
continue;
}
- if ((int) colNames.get(i)[1] == XSSFCell.CELL_TYPE_STRING) {
- if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) {
+ if (colNames.get(i)[1] == CellType.STRING) {
+ if (cell.getCellTypeEnum() == CellType.STRING) {
results.add(cell.getStringCellValue());
} else {
results.add(cellValue);
}
- } else if ((int) colNames.get(i)[1] == XSSFCell.CELL_TYPE_NUMERIC) {
- if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) {
+ } else if (colNames.get(i)[1] == CellType.NUMERIC) {
+ if (cell.getCellTypeEnum() == CellType.STRING) {
try {
results.add(BigDecimal.valueOf(Double.valueOf(cell.getStringCellValue())));
} catch (NumberFormatException e) {
results.add(null);
errorMessages.put(new CellReference(cell), UtilProperties.getMessage(resource, "ErrorParseValueToNumeric", locale));
}
- } else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
+ } else if (cell.getCellTypeEnum() == CellType.NUMERIC) {
try {
results.add(BigDecimal.valueOf(cell.getNumericCellValue()).setScale(FinAccountHelper.decimals, FinAccountHelper.rounding));
} catch (NumberFormatException e) {
Modified: ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/sample/SamplePricatParser.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/sample/SamplePricatParser.java?rev=1848009&r1=1848008&r2=1848009&view=diff
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/sample/SamplePricatParser.java (original)
+++ ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/sample/SamplePricatParser.java Sun Dec 2 18:51:51 2018
@@ -42,8 +42,8 @@ import org.apache.ofbiz.order.finaccount
import org.apache.ofbiz.pricat.AbstractPricatParser;
import org.apache.ofbiz.service.LocalDispatcher;
import org.apache.ofbiz.service.ServiceUtil;
-import org.apache.poi.POIXMLException;
import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
@@ -87,10 +87,6 @@ public class SamplePricatParser extends
report.println(e);
report.println(UtilProperties.getMessage(resource, "PricatSuggestion", locale), InterfaceReport.FORMAT_ERROR);
return;
- } catch(POIXMLException e) {
- report.println(e);
- report.println(UtilProperties.getMessage(resource, "PricatSuggestion", locale), InterfaceReport.FORMAT_ERROR);
- return;
}
// 3. only first sheet will be parsed
@@ -478,54 +474,54 @@ public class SamplePricatParser extends
private static List<Object[]> genExcelHeaderNamesV1_1() {
List<Object[]> listHeaderName = new ArrayList<Object[]>();
listHeaderName.add(new Object[] {"Facility Name",
- XSSFCell.CELL_TYPE_STRING,
+ CellType.STRING,
Boolean.TRUE});
listHeaderName.add(new Object[] {"FacilityId",
- XSSFCell.CELL_TYPE_STRING,
+ CellType.STRING,
Boolean.TRUE});
listHeaderName.add(new Object[] {"Category L1",
- XSSFCell.CELL_TYPE_STRING,
+ CellType.STRING,
Boolean.FALSE});
listHeaderName.add(new Object[] {"Category L2",
- XSSFCell.CELL_TYPE_STRING,
+ CellType.STRING,
Boolean.FALSE});
listHeaderName.add(new Object[] {"Category L3",
- XSSFCell.CELL_TYPE_STRING,
+ CellType.STRING,
Boolean.FALSE});
listHeaderName.add(new Object[] {"Category L4",
- XSSFCell.CELL_TYPE_STRING,
+ CellType.STRING,
Boolean.FALSE});
listHeaderName.add(new Object[] {"Brand",
- XSSFCell.CELL_TYPE_STRING,
+ CellType.STRING,
Boolean.TRUE});
listHeaderName.add(new Object[] {"Style No",
- XSSFCell.CELL_TYPE_STRING,
+ CellType.STRING,
Boolean.TRUE});
listHeaderName.add(new Object[] {"Product Name",
- XSSFCell.CELL_TYPE_STRING,
+ CellType.STRING,
Boolean.TRUE});
listHeaderName.add(new Object[] {"Color",
- XSSFCell.CELL_TYPE_STRING,
+ CellType.STRING,
Boolean.FALSE});
listHeaderName.add(new Object[] {"Size",
- XSSFCell.CELL_TYPE_STRING,
+ CellType.STRING,
Boolean.FALSE});
listHeaderName.add(new Object[] {"Barcode",
- XSSFCell.CELL_TYPE_STRING,
+ CellType.STRING,
Boolean.FALSE});
listHeaderName.add(new Object[] {"Stock Qty",
- XSSFCell.CELL_TYPE_NUMERIC,
+ CellType.NUMERIC,
Boolean.TRUE});
listHeaderName.add(new Object[] {"Average Cost",
- XSSFCell.CELL_TYPE_NUMERIC,
+ CellType.NUMERIC,
Boolean.TRUE,
Boolean.TRUE});
listHeaderName.add(new Object[] {"List Price",
- XSSFCell.CELL_TYPE_NUMERIC,
+ CellType.NUMERIC,
Boolean.TRUE,
Boolean.TRUE});
listHeaderName.add(new Object[] {"Member Price",
- XSSFCell.CELL_TYPE_NUMERIC,
+ CellType.NUMERIC,
Boolean.FALSE,
Boolean.TRUE});
return listHeaderName;
@@ -569,10 +565,10 @@ public class SamplePricatParser extends
cell = row.createCell(i);
}
}
- int cellType = cell.getCellType();
+ CellType cellType = cell.getCellTypeEnum();
String cellValue = formatter.formatCellValue(cell);
if (UtilValidate.isNotEmpty(cellValue) && UtilValidate.isNotEmpty(cellValue.trim())) {
- if (cellType == XSSFCell.CELL_TYPE_FORMULA) {
+ if (cellType == CellType.FORMULA) {
try {
cellValue = BigDecimal.valueOf(cell.getNumericCellValue()).setScale(FinAccountHelper.decimals, FinAccountHelper.rounding).toString();
} catch (IllegalStateException e) {
@@ -596,17 +592,17 @@ public class SamplePricatParser extends
results.add(null);
continue;
}
- if ((Boolean) colNames.get(i)[2] && cellType != (int) colNames.get(i)[1]) {
+ if ((Boolean) colNames.get(i)[2] && cellType != colNames.get(i)[1]) {
// String warningMessage = "";
- if ((int) colNames.get(i)[1] == XSSFCell.CELL_TYPE_STRING) {
+ if (colNames.get(i)[1] == CellType.STRING) {
if (UtilValidate.isNotEmpty(cellValue) && UtilValidate.isNotEmpty(cellValue.trim())) {
results.add(cellValue);
} else {
results.add(null);
}
- } else if ((int) colNames.get(i)[1] == XSSFCell.CELL_TYPE_NUMERIC) {
- if (cell.getCellType() != XSSFCell.CELL_TYPE_STRING) {
- cell.setCellType(XSSFCell.CELL_TYPE_STRING);
+ } else if (colNames.get(i)[1] == CellType.NUMERIC) {
+ if (cell.getCellTypeEnum() != CellType.STRING) {
+ cell.setCellType(CellType.STRING);
}
try {
results.add(BigDecimal.valueOf(Double.parseDouble(cell.getStringCellValue())).setScale(FinAccountHelper.decimals, FinAccountHelper.rounding));
@@ -620,22 +616,22 @@ public class SamplePricatParser extends
results.add(null);
continue;
}
- if ((int) colNames.get(i)[1] == XSSFCell.CELL_TYPE_STRING) {
- if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) {
+ if (colNames.get(i)[1] == CellType.STRING) {
+ if (cell.getCellTypeEnum() == CellType.STRING) {
cellValue = cell.getStringCellValue().trim();
results.add(cellValue);
} else {
results.add(cellValue.trim());
}
- } else if ((int) colNames.get(i)[1] == XSSFCell.CELL_TYPE_NUMERIC) {
- if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) {
+ } else if (colNames.get(i)[1] == CellType.NUMERIC) {
+ if (cell.getCellTypeEnum() == CellType.STRING) {
try {
results.add(BigDecimal.valueOf(Double.valueOf(cell.getStringCellValue())));
} catch (NumberFormatException e) {
results.add(null);
errorMessages.put(new CellReference(cell), UtilProperties.getMessage(resource, "ErrorParseValueToNumeric", locale));
}
- } else if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
+ } else if (cell.getCellTypeEnum() == CellType.NUMERIC) {
try {
results.add(BigDecimal.valueOf(cell.getNumericCellValue()).setScale(FinAccountHelper.decimals, FinAccountHelper.rounding));
} catch (NumberFormatException e) {
Added: ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/util/OFBizPricatUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/util/OFBizPricatUtil.java?rev=1848009&view=auto
==============================================================================
--- ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/util/OFBizPricatUtil.java (added)
+++ ofbiz/ofbiz-plugins/trunk/pricat/src/main/java/org/apache/ofbiz/pricat/util/OFBizPricatUtil.java Sun Dec 2 18:51:51 2018
@@ -0,0 +1,88 @@
+/*
+ * 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.ofbiz.pricat.util;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.ofbiz.base.util.Debug;
+import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFVMLDrawing;
+
+import com.microsoft.schemas.vml.CTShape;
+
+public final class OFBizPricatUtil {
+
+ public static final String module = OFBizPricatUtil.class.getName();
+
+ protected static Method VMLDrawingMethod;
+
+ // for POI 4.0.0 and later, this field can be removed
+ protected static Method FindCommentShapeMethod;
+
+ static {
+ Method[] methods = XSSFSheet.class.getDeclaredMethods();
+ for (Method method : methods) {
+ if (method.getName().equals("getVMLDrawing")) {
+ VMLDrawingMethod = method;
+ break;
+ }
+ }
+
+ // for POI 4.0.0 and later, this part can be removed
+ methods = XSSFVMLDrawing.class.getDeclaredMethods();
+ for (Method method : methods) {
+ if (method.getName().equals("findCommentShape")) {
+ FindCommentShapeMethod = method;
+ break;
+ }
+ }
+ }
+
+ public static void formatCommentShape(XSSFSheet sheet, CellReference cell) {
+ if (VMLDrawingMethod != null && FindCommentShapeMethod != null) {
+ try {
+ XSSFVMLDrawing vml = (XSSFVMLDrawing) VMLDrawingMethod.invoke(sheet, true);
+ /** for POI 4.0 and later, use:
+ CTShape ctshape = vml.findCommentShape(cell.getRow(), cell.getCol());
+ */
+ CTShape ctshape = (CTShape) FindCommentShapeMethod.invoke(vml, cell.getRow(), cell.getCol());
+ ctshape.setType("#_x0000_t202");
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ Debug.logError(e, module);;
+ }
+ }
+ }
+
+ public static void formatCommentShape(XSSFSheet sheet, int rowNum, short colNum) {
+ if (VMLDrawingMethod != null && FindCommentShapeMethod != null) {
+ try {
+ XSSFVMLDrawing vml = (XSSFVMLDrawing) VMLDrawingMethod.invoke(sheet, true);
+ /** for POI 4.0 and later, use:
+ CTShape ctshape = vml.findCommentShape(rowNum, colNum);
+ */
+ CTShape ctshape = (CTShape) FindCommentShapeMethod.invoke(vml, rowNum, colNum);
+ ctshape.setType("#_x0000_t202");
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+ Debug.logError(e, module);;
+ }
+ }
+ }
+}