use of org.apache.poi.util.Internal in project poi by apache.
the class CommentsTable method newComment.
/**
* Create a new comment located` at cell address
*
* @param ref the location to add the comment
* @return a new CTComment located at ref with default author
*/
@Internal
public CTComment newComment(CellAddress ref) {
CTComment ct = comments.getCommentList().addNewComment();
ct.setRef(ref.formatAsString());
ct.setAuthorId(DEFAULT_AUTHOR_ID);
if (commentRefs != null) {
commentRefs.put(ref, ct);
}
return ct;
}
use of org.apache.poi.util.Internal in project poi by apache.
the class WorkbookEvaluator method evaluateFormula.
// visibility raised for testing
@Internal
/* package */
ValueEval evaluateFormula(OperationEvaluationContext ec, Ptg[] ptgs) {
// always init. to non-null just for defensive avoiding NPE
String dbgIndentStr = "";
if (dbgEvaluationOutputForNextEval) {
// first evaluation call when ouput is desired, so iit. this evaluator instance
dbgEvaluationOutputIndent = 1;
dbgEvaluationOutputForNextEval = false;
}
if (dbgEvaluationOutputIndent > 0) {
// init. indent string to needed spaces (create as substring vom very long space-only string;
// limit indendation for deep recursions)
dbgIndentStr = " ";
dbgIndentStr = dbgIndentStr.substring(0, Math.min(dbgIndentStr.length(), dbgEvaluationOutputIndent * 2));
EVAL_LOG.log(POILogger.WARN, dbgIndentStr + "- evaluateFormula('" + ec.getRefEvaluatorForCurrentSheet().getSheetNameRange() + "'/" + new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString() + "): " + Arrays.toString(ptgs).replaceAll("\\Qorg.apache.poi.ss.formula.ptg.\\E", ""));
dbgEvaluationOutputIndent++;
}
Stack<ValueEval> stack = new Stack<ValueEval>();
for (int i = 0, iSize = ptgs.length; i < iSize; i++) {
// since we don't know how to handle these yet :(
Ptg ptg = ptgs[i];
if (dbgEvaluationOutputIndent > 0) {
EVAL_LOG.log(POILogger.INFO, dbgIndentStr + " * ptg " + i + ": " + ptg + ", stack: " + stack);
}
if (ptg instanceof AttrPtg) {
AttrPtg attrPtg = (AttrPtg) ptg;
if (attrPtg.isSum()) {
// Excel prefers to encode 'SUM()' as a tAttr token, but this evaluator
// expects the equivalent function token
ptg = FuncVarPtg.SUM;
}
if (attrPtg.isOptimizedChoose()) {
ValueEval arg0 = stack.pop();
int[] jumpTable = attrPtg.getJumpTable();
int dist;
int nChoices = jumpTable.length;
try {
int switchIndex = Choose.evaluateFirstArg(arg0, ec.getRowIndex(), ec.getColumnIndex());
if (switchIndex < 1 || switchIndex > nChoices) {
stack.push(ErrorEval.VALUE_INVALID);
// +4 for tFuncFar(CHOOSE)
dist = attrPtg.getChooseFuncOffset() + 4;
} else {
dist = jumpTable[switchIndex - 1];
}
} catch (EvaluationException e) {
stack.push(e.getErrorEval());
// +4 for tFuncFar(CHOOSE)
dist = attrPtg.getChooseFuncOffset() + 4;
}
// Encoded dist for tAttrChoose includes size of jump table, but
// countTokensToBeSkipped() does not (it counts whole tokens).
// subtract jump table size
dist -= nChoices * 2 + 2;
i += countTokensToBeSkipped(ptgs, i, dist);
continue;
}
if (attrPtg.isOptimizedIf()) {
ValueEval arg0 = stack.pop();
boolean evaluatedPredicate;
try {
evaluatedPredicate = IfFunc.evaluateFirstArg(arg0, ec.getRowIndex(), ec.getColumnIndex());
} catch (EvaluationException e) {
stack.push(e.getErrorEval());
int dist = attrPtg.getData();
i += countTokensToBeSkipped(ptgs, i, dist);
attrPtg = (AttrPtg) ptgs[i];
dist = attrPtg.getData() + 1;
i += countTokensToBeSkipped(ptgs, i, dist);
continue;
}
if (evaluatedPredicate) {
// nothing to skip - true param follows
} else {
int dist = attrPtg.getData();
i += countTokensToBeSkipped(ptgs, i, dist);
Ptg nextPtg = ptgs[i + 1];
if (ptgs[i] instanceof AttrPtg && nextPtg instanceof FuncVarPtg && // if we really have the IF next or some other FuncVarPtg as third param, e.g. ROW()/COLUMN()!
((FuncVarPtg) nextPtg).getFunctionIndex() == FunctionMetadataRegistry.FUNCTION_INDEX_IF) {
// this is an if statement without a false param (as opposed to MissingArgPtg as the false param)
i++;
stack.push(BoolEval.FALSE);
}
}
continue;
}
if (attrPtg.isSkip()) {
int dist = attrPtg.getData() + 1;
i += countTokensToBeSkipped(ptgs, i, dist);
if (stack.peek() == MissingArgEval.instance) {
stack.pop();
stack.push(BlankEval.instance);
}
continue;
}
}
if (ptg instanceof ControlPtg) {
// skip Parentheses, Attr, etc
continue;
}
if (ptg instanceof MemFuncPtg || ptg instanceof MemAreaPtg) {
// can ignore, rest of tokens for this expression are in OK RPN order
continue;
}
if (ptg instanceof MemErrPtg) {
continue;
}
if (ptg instanceof UnionPtg) {
ValueEval v2 = stack.pop();
ValueEval v1 = stack.pop();
stack.push(new RefListEval(v1, v2));
continue;
}
ValueEval opResult;
if (ptg instanceof OperationPtg) {
OperationPtg optg = (OperationPtg) ptg;
int numops = optg.getNumberOfOperands();
ValueEval[] ops = new ValueEval[numops];
// storing the ops in reverse order since they are popping
for (int j = numops - 1; j >= 0; j--) {
ValueEval p = stack.pop();
ops[j] = p;
}
// logDebug("invoke " + operation + " (nAgs=" + numops + ")");
opResult = OperationEvaluatorFactory.evaluate(optg, ops, ec);
} else {
opResult = getEvalForPtg(ptg, ec);
}
if (opResult == null) {
throw new RuntimeException("Evaluation result must not be null");
}
// logDebug("push " + opResult);
stack.push(opResult);
if (dbgEvaluationOutputIndent > 0) {
EVAL_LOG.log(POILogger.INFO, dbgIndentStr + " = " + opResult);
}
}
ValueEval value = stack.pop();
if (!stack.isEmpty()) {
throw new IllegalStateException("evaluation stack not empty");
}
ValueEval result = dereferenceResult(value, ec.getRowIndex(), ec.getColumnIndex());
if (dbgEvaluationOutputIndent > 0) {
EVAL_LOG.log(POILogger.INFO, dbgIndentStr + "finshed eval of " + new CellReference(ec.getRowIndex(), ec.getColumnIndex()).formatAsString() + ": " + result);
dbgEvaluationOutputIndent--;
if (dbgEvaluationOutputIndent == 1) {
// this evaluation is done, reset indent to stop logging
dbgEvaluationOutputIndent = -1;
}
}
// if
return result;
}
use of org.apache.poi.util.Internal in project poi by apache.
the class XSLFSlideShow method getSlide.
/**
* Returns the low level slide object from
* the supplied slide reference
*/
@Internal
public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException {
PackagePart slidePart = getSlidePart(slide);
SldDocument slideDoc = SldDocument.Factory.parse(slidePart.getInputStream(), DEFAULT_XML_OPTIONS);
return slideDoc.getSld();
}
use of org.apache.poi.util.Internal in project poi by apache.
the class XSLFSlideShow method getNotes.
/**
* Returns the low level notes object for the given
* slide, as found from the supplied slide reference
*/
@Internal
public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException {
PackagePart notesPart = getNodesPart(slide);
if (notesPart == null)
return null;
NotesDocument notesDoc = NotesDocument.Factory.parse(notesPart.getInputStream(), DEFAULT_XML_OPTIONS);
return notesDoc.getNotes();
}
use of org.apache.poi.util.Internal in project poi by apache.
the class XSLFSlideShow method getSlideMaster.
/**
* Returns the low level slide master object from
* the supplied slide master reference
*/
@Internal
public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException {
PackagePart masterPart = getSlideMasterPart(master);
SldMasterDocument masterDoc = SldMasterDocument.Factory.parse(masterPart.getInputStream(), DEFAULT_XML_OPTIONS);
return masterDoc.getSldMaster();
}
Aggregations