sonar fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1734641 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
630bdd0f15
commit
0776e32108
@ -19,53 +19,70 @@
|
|||||||
|
|
||||||
package org.apache.poi.sl.draw.geom;
|
package org.apache.poi.sl.draw.geom;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple regexp-based parser of shape guide formulas in DrawingML
|
* A simple regexp-based parser of shape guide formulas in DrawingML
|
||||||
*
|
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
*/
|
||||||
public class ExpressionParser {
|
public class ExpressionParser {
|
||||||
static final HashMap<String, Class<? extends Expression>> impls =
|
private static final Map<String, ExpressionEntry> impls =
|
||||||
new HashMap<String, Class<? extends Expression>>();
|
new HashMap<String, ExpressionEntry>();
|
||||||
|
|
||||||
static {
|
|
||||||
impls.put("\\*/ +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", MultiplyDivideExpression.class);
|
|
||||||
impls.put("\\+- +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)( 0)?", AddSubtractExpression.class);
|
|
||||||
impls.put("\\+/ +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", AddDivideExpression.class);
|
|
||||||
impls.put("\\?: +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", IfElseExpression.class);
|
|
||||||
impls.put("val +([\\-\\w]+)", LiteralValueExpression.class);
|
|
||||||
impls.put("abs +([\\-\\w]+)", AbsExpression.class);
|
|
||||||
impls.put("sqrt +([\\-\\w]+)", SqrtExpression.class);
|
|
||||||
impls.put("max +([\\-\\w]+) +([\\-\\w]+)", MaxExpression.class);
|
|
||||||
impls.put("min +([\\-\\w]+) +([\\-\\w]+)", MinExpression.class);
|
|
||||||
impls.put("at2 +([\\-\\w]+) +([\\-\\w]+)", ArcTanExpression.class);
|
|
||||||
impls.put("sin +([\\-\\w]+) +([\\-\\w]+)", SinExpression.class);
|
|
||||||
impls.put("cos +([\\-\\w]+) +([\\-\\w]+)", CosExpression.class);
|
|
||||||
impls.put("tan +([\\-\\w]+) +([\\-\\w]+)", TanExpression.class);
|
|
||||||
impls.put("cat2 +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", CosineArcTanExpression.class);
|
|
||||||
impls.put("sat2 +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", SinArcTanExpression.class);
|
|
||||||
impls.put("pin +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", PinExpression.class);
|
|
||||||
impls.put("mod +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", ModExpression.class);
|
|
||||||
|
|
||||||
|
private static class ExpressionEntry {
|
||||||
|
final Pattern regex;
|
||||||
|
final Constructor<? extends Expression> con;
|
||||||
|
ExpressionEntry(String regex, Class<? extends Expression> cls)
|
||||||
|
throws SecurityException, NoSuchMethodException {
|
||||||
|
this.regex = Pattern.compile(regex);
|
||||||
|
this.con = cls.getDeclaredConstructor(Matcher.class);
|
||||||
|
impls.put(op(regex), this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Expression parse(String str){
|
static {
|
||||||
for(String regexp : impls.keySet()) {
|
|
||||||
Pattern ptrn = Pattern.compile(regexp);
|
|
||||||
Matcher m = ptrn.matcher(str);
|
|
||||||
if(m.matches()) {
|
|
||||||
Class<? extends Expression> c = impls.get(regexp);
|
|
||||||
try {
|
try {
|
||||||
return c.getDeclaredConstructor(Matcher.class).newInstance(m);
|
new ExpressionEntry("\\*/ +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", MultiplyDivideExpression.class);
|
||||||
|
new ExpressionEntry("\\+- +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)( 0)?", AddSubtractExpression.class);
|
||||||
|
new ExpressionEntry("\\+/ +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", AddDivideExpression.class);
|
||||||
|
new ExpressionEntry("\\?: +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", IfElseExpression.class);
|
||||||
|
new ExpressionEntry("val +([\\-\\w]+)", LiteralValueExpression.class);
|
||||||
|
new ExpressionEntry("abs +([\\-\\w]+)", AbsExpression.class);
|
||||||
|
new ExpressionEntry("sqrt +([\\-\\w]+)", SqrtExpression.class);
|
||||||
|
new ExpressionEntry("max +([\\-\\w]+) +([\\-\\w]+)", MaxExpression.class);
|
||||||
|
new ExpressionEntry("min +([\\-\\w]+) +([\\-\\w]+)", MinExpression.class);
|
||||||
|
new ExpressionEntry("at2 +([\\-\\w]+) +([\\-\\w]+)", ArcTanExpression.class);
|
||||||
|
new ExpressionEntry("sin +([\\-\\w]+) +([\\-\\w]+)", SinExpression.class);
|
||||||
|
new ExpressionEntry("cos +([\\-\\w]+) +([\\-\\w]+)", CosExpression.class);
|
||||||
|
new ExpressionEntry("tan +([\\-\\w]+) +([\\-\\w]+)", TanExpression.class);
|
||||||
|
new ExpressionEntry("cat2 +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", CosineArcTanExpression.class);
|
||||||
|
new ExpressionEntry("sat2 +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", SinArcTanExpression.class);
|
||||||
|
new ExpressionEntry("pin +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", PinExpression.class);
|
||||||
|
new ExpressionEntry("mod +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", ModExpression.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String op(String str) {
|
||||||
|
return (str == null || !str.contains(" "))
|
||||||
|
? "" : str.substring(0, str.indexOf(" ")).replace("\\", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Expression parse(String str) {
|
||||||
|
ExpressionEntry ee = impls.get(op(str));
|
||||||
|
Matcher m = (ee == null) ? null : ee.regex.matcher(str);
|
||||||
|
if (m == null || !m.matches()) {
|
||||||
throw new RuntimeException("Unsupported formula: " + str);
|
throw new RuntimeException("Unsupported formula: " + str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return ee.con.newInstance(m);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Unsupported formula: " + str, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,14 +106,13 @@ public final class CollaboratingWorkbooksEnvironment {
|
|||||||
}
|
}
|
||||||
private CollaboratingWorkbooksEnvironment(Map<String, WorkbookEvaluator> evaluatorsByName, WorkbookEvaluator[] evaluators) {
|
private CollaboratingWorkbooksEnvironment(Map<String, WorkbookEvaluator> evaluatorsByName, WorkbookEvaluator[] evaluators) {
|
||||||
IdentityHashMap<WorkbookEvaluator, String> uniqueEvals = new IdentityHashMap<WorkbookEvaluator, String>(evaluators.length);
|
IdentityHashMap<WorkbookEvaluator, String> uniqueEvals = new IdentityHashMap<WorkbookEvaluator, String>(evaluators.length);
|
||||||
for (String wbName : evaluatorsByName.keySet()) {
|
for (Map.Entry<String, WorkbookEvaluator> me : evaluatorsByName.entrySet()) {
|
||||||
WorkbookEvaluator wbEval = evaluatorsByName.get(wbName);
|
String uniEval = uniqueEvals.put(me.getValue(), me.getKey());
|
||||||
if (uniqueEvals.containsKey(wbEval)) {
|
if (uniEval != null) {
|
||||||
String msg = "Attempted to register same workbook under names '" +
|
String msg = "Attempted to register same workbook under names '" +
|
||||||
uniqueEvals.get(wbEval) + "' and '" + wbName + "'";
|
uniEval + "' and '" + me.getKey() + "'";
|
||||||
throw new IllegalArgumentException(msg);
|
throw new IllegalArgumentException(msg);
|
||||||
}
|
}
|
||||||
uniqueEvals.put(wbEval, wbName);
|
|
||||||
}
|
}
|
||||||
unhookOldEnvironments(evaluators);
|
unhookOldEnvironments(evaluators);
|
||||||
hookNewEnvironment(evaluators, this);
|
hookNewEnvironment(evaluators, this);
|
||||||
|
@ -209,10 +209,10 @@ public final class AnalysisToolPak implements UDFFinder {
|
|||||||
public static Collection<String> getSupportedFunctionNames(){
|
public static Collection<String> getSupportedFunctionNames(){
|
||||||
AnalysisToolPak inst = (AnalysisToolPak)instance;
|
AnalysisToolPak inst = (AnalysisToolPak)instance;
|
||||||
Collection<String> lst = new TreeSet<String>();
|
Collection<String> lst = new TreeSet<String>();
|
||||||
for(String name : inst._functionsByName.keySet()){
|
for(Map.Entry<String, FreeRefFunction> me : inst._functionsByName.entrySet()){
|
||||||
FreeRefFunction func = inst._functionsByName.get(name);
|
FreeRefFunction func = me.getValue();
|
||||||
if(func != null && !(func instanceof NotImplemented)){
|
if(func != null && !(func instanceof NotImplemented)){
|
||||||
lst.add(name);
|
lst.add(me.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableCollection(lst);
|
return Collections.unmodifiableCollection(lst);
|
||||||
@ -227,10 +227,10 @@ public final class AnalysisToolPak implements UDFFinder {
|
|||||||
public static Collection<String> getNotSupportedFunctionNames(){
|
public static Collection<String> getNotSupportedFunctionNames(){
|
||||||
AnalysisToolPak inst = (AnalysisToolPak)instance;
|
AnalysisToolPak inst = (AnalysisToolPak)instance;
|
||||||
Collection<String> lst = new TreeSet<String>();
|
Collection<String> lst = new TreeSet<String>();
|
||||||
for(String name : inst._functionsByName.keySet()){
|
for(Map.Entry<String, FreeRefFunction> me : inst._functionsByName.entrySet()){
|
||||||
FreeRefFunction func = inst._functionsByName.get(name);
|
FreeRefFunction func = me.getValue();
|
||||||
if(func != null && (func instanceof NotImplemented)){
|
if (func instanceof NotImplemented) {
|
||||||
lst.add(name);
|
lst.add(me.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableCollection(lst);
|
return Collections.unmodifiableCollection(lst);
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package org.apache.poi.openxml4j.opc.internal;
|
package org.apache.poi.openxml4j.opc.internal;
|
||||||
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -186,11 +187,11 @@ public final class ContentType {
|
|||||||
retVal.append(this.getSubType());
|
retVal.append(this.getSubType());
|
||||||
|
|
||||||
if (withParameters) {
|
if (withParameters) {
|
||||||
for (String key : parameters.keySet()) {
|
for (Map.Entry<String, String> me : parameters.entrySet()) {
|
||||||
retVal.append(";");
|
retVal.append(";");
|
||||||
retVal.append(key);
|
retVal.append(me.getKey());
|
||||||
retVal.append("=");
|
retVal.append("=");
|
||||||
retVal.append(parameters.get(key));
|
retVal.append(me.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retVal.toString();
|
return retVal.toString();
|
||||||
|
@ -582,11 +582,7 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get default
|
// get default
|
||||||
XDGFStyleSheet style = _document.getDefaultLineStyle();
|
return _document.getDefaultLineStyle().getLineCap();
|
||||||
if (style != null)
|
|
||||||
return style.getLineCap();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -602,11 +598,7 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get default
|
// get default
|
||||||
XDGFStyleSheet style = _document.getDefaultLineStyle();
|
return _document.getDefaultLineStyle().getLineColor();
|
||||||
if (style != null)
|
|
||||||
return style.getLineColor();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -622,11 +614,7 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get default
|
// get default
|
||||||
XDGFStyleSheet style = _document.getDefaultLineStyle();
|
return _document.getDefaultLineStyle().getLinePattern();
|
||||||
if (style != null)
|
|
||||||
return style.getLinePattern();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -642,11 +630,7 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get default
|
// get default
|
||||||
XDGFStyleSheet style = _document.getDefaultLineStyle();
|
return _document.getDefaultLineStyle().getLineWeight();
|
||||||
if (style != null)
|
|
||||||
return style.getLineWeight();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -662,11 +646,7 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get default
|
// get default
|
||||||
XDGFStyleSheet style = _document.getDefaultTextStyle();
|
return _document.getDefaultTextStyle().getFontColor();
|
||||||
if (style != null)
|
|
||||||
return style.getFontColor();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -682,11 +662,7 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get default
|
// get default
|
||||||
XDGFStyleSheet style = _document.getDefaultTextStyle();
|
return _document.getDefaultTextStyle().getFontSize();
|
||||||
if (style != null)
|
|
||||||
return style.getFontSize();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stroke getStroke() {
|
public Stroke getStroke() {
|
||||||
|
@ -575,14 +575,17 @@ public class XSSFRichTextString implements RichTextString {
|
|||||||
}
|
}
|
||||||
CTRst stf = CTRst.Factory.newInstance();
|
CTRst stf = CTRst.Factory.newInstance();
|
||||||
int runStartIdx = 0;
|
int runStartIdx = 0;
|
||||||
for (Iterator<Integer> it = formats.keySet().iterator(); it.hasNext();) {
|
for (Map.Entry<Integer, CTRPrElt> me : formats.entrySet()) {
|
||||||
int runEndIdx = it.next();
|
int runEndIdx = me.getKey();
|
||||||
CTRElt run = stf.addNewR();
|
CTRElt run = stf.addNewR();
|
||||||
String fragment = text.substring(runStartIdx, runEndIdx);
|
String fragment = text.substring(runStartIdx, runEndIdx);
|
||||||
run.setT(fragment);
|
run.setT(fragment);
|
||||||
preserveSpaces(run.xgetT());
|
preserveSpaces(run.xgetT());
|
||||||
CTRPrElt fmt = formats.get(runEndIdx);
|
|
||||||
if(fmt != null) run.setRPr(fmt);
|
CTRPrElt fmt = me.getValue();
|
||||||
|
if (fmt != null) {
|
||||||
|
run.setRPr(fmt);
|
||||||
|
}
|
||||||
runStartIdx = runEndIdx;
|
runStartIdx = runEndIdx;
|
||||||
}
|
}
|
||||||
return stf;
|
return stf;
|
||||||
|
@ -92,11 +92,10 @@ public final class ListTables
|
|||||||
ByteArrayOutputStream levelBuf = new ByteArrayOutputStream();
|
ByteArrayOutputStream levelBuf = new ByteArrayOutputStream();
|
||||||
|
|
||||||
byte[] shortHolder = new byte[2];
|
byte[] shortHolder = new byte[2];
|
||||||
LittleEndian.putShort(shortHolder, (short)listSize);
|
LittleEndian.putShort(shortHolder, 0, (short)listSize);
|
||||||
tableStream.write(shortHolder);
|
tableStream.write(shortHolder);
|
||||||
|
|
||||||
for(Integer x : _listMap.keySet()) {
|
for(ListData lst : _listMap.values()) {
|
||||||
ListData lst = _listMap.get(x);
|
|
||||||
tableStream.write(lst.toByteArray());
|
tableStream.write(lst.toByteArray());
|
||||||
ListLevel[] lvls = lst.getLevels();
|
ListLevel[] lvls = lst.getLevels();
|
||||||
for (int y = 0; y < lvls.length; y++)
|
for (int y = 0; y < lvls.length; y++)
|
||||||
|
Loading…
Reference in New Issue
Block a user