Java 类net.sf.jasperreports.engine.JRExpressionChunk 实例源码

项目:jasperreports    文件:JRBaseObjectFactory.java   
/**
 *
 */
protected JRBaseExpressionChunk getExpressionChunk(JRExpressionChunk expressionChunk)
{
    JRBaseExpressionChunk baseExpressionChunk = null;

    if (expressionChunk != null)
    {
        baseExpressionChunk = (JRBaseExpressionChunk)get(expressionChunk);
        if (baseExpressionChunk == null)
        {
            baseExpressionChunk = new JRBaseExpressionChunk(expressionChunk, this);
        }
    }

    return baseExpressionChunk;
}
项目:jasperreports    文件:JRExpressionUtil.java   
/**
 *
 */
public static String getSimpleExpressionText(JRExpression expression)
{
    String value = null;
    if (expression != null)
    {
        JRExpressionChunk[] chunks = expression.getChunks();
        if (
            chunks != null 
            && chunks.length == 1 
            && chunks[0].getType() == JRExpressionChunk.TYPE_TEXT
            )
        {
            String chunk = chunks[0].getText();
            Matcher matcher = SIMPLE_EXPRESSION_PATTERN.matcher(chunk);
            if (matcher.matches())
            {
                String text = matcher.group(SIMPLE_EXPRESSION_TEXT_GROUP);
                value = TEXT_QUOTE_PATTERN.matcher(text).replaceAll(
                        TEXT_QUOTE_REPLACEMENT);
            }
        }
    }
    return value;
}
项目:jasperreports    文件:SimpleTextExpressionEvaluator.java   
public static String evaluateExpression(JRExpression expression, ExpressionValues values)
{
    if (expression.getType() != ExpressionTypeEnum.SIMPLE_TEXT)
    {
        throw new IllegalArgumentException("Simple text expression expected");
    }

    JRExpressionChunk[] chunks = expression.getChunks();
    if (chunks == null || chunks.length == 0)
    {
        return EMPTY_RESULT;
    }

    ResultCollector result = new ResultCollector(values);
    result.collectChunks(chunks);
    return result.getResult();
}
项目:jasperreports    文件:SimpleTextExpressionEvaluator.java   
private void appendValueChunk(byte chunkType, String chunkText)
{
    switch (chunkType)
    {
    case JRExpressionChunk.TYPE_RESOURCE:
        appendValueChunk(values.getMessage(chunkText));
        break;

    case JRExpressionChunk.TYPE_PARAMETER:
        appendValueChunk(values.getParameterValue(chunkText));
        break;

    case JRExpressionChunk.TYPE_FIELD:
        appendValueChunk(values.getFieldValue(chunkText));
        break;

    case JRExpressionChunk.TYPE_VARIABLE:
        appendValueChunk(values.getVariableValue(chunkText));
        break;

    default:
        throw new JRRuntimeException("Unexpected expression chunk type " + chunkType);
    }
}
项目:jasperreports    文件:TableUtil.java   
public static boolean hasSingleChunkExpression(JRTextField textField) 
{
    if (textField != null)
    {
        JRExpression textExpression = textField.getExpression();
        JRExpressionChunk[] chunks = textExpression == null ? null : textExpression.getChunks();
        if (chunks == null || chunks.length != 1
                || (chunks[0].getType() != JRExpressionChunk.TYPE_FIELD
                && chunks[0].getType() != JRExpressionChunk.TYPE_VARIABLE))
        {
            return false;
        }

        return true;
    }

    return false;
}
项目:jasperreports    文件:ExpressionParsingTest.java   
@DataProvider
public Object[][] expressions()
{
    return new Object[][]{
            {"20", new Object[]{JRExpressionChunk.TYPE_TEXT, "20"}},
            {"\"20\"", new Object[]{JRExpressionChunk.TYPE_TEXT, "\"20\""}},
            {"$R{foo}", new Object[]{JRExpressionChunk.TYPE_RESOURCE, "foo"}},
            {"$P{foo}", new Object[]{JRExpressionChunk.TYPE_PARAMETER, "foo"}},
            {"$F{foo}", new Object[]{JRExpressionChunk.TYPE_FIELD, "foo"}},
            {"$V{foo}", new Object[]{JRExpressionChunk.TYPE_VARIABLE, "foo"}},
            {"$V{fo\no}", new Object[]{JRExpressionChunk.TYPE_VARIABLE, "fo\no"}},
            {"bar$V{foo}", new Object[]{JRExpressionChunk.TYPE_TEXT, "bar", JRExpressionChunk.TYPE_VARIABLE, "foo"}},
            {"$V{foo}bar", new Object[]{JRExpressionChunk.TYPE_VARIABLE, "foo", JRExpressionChunk.TYPE_TEXT, "bar"}},
            {"moo$V{foo}bar", new Object[]{JRExpressionChunk.TYPE_TEXT, "moo", JRExpressionChunk.TYPE_VARIABLE, "foo", JRExpressionChunk.TYPE_TEXT, "bar"}},
            {"$V{foo} + $F{bar}", new Object[]{JRExpressionChunk.TYPE_VARIABLE, "foo", JRExpressionChunk.TYPE_TEXT, " + ", JRExpressionChunk.TYPE_FIELD, "bar",}},
            {"$V{foo} \n+ $F{bar}", new Object[]{JRExpressionChunk.TYPE_VARIABLE, "foo", JRExpressionChunk.TYPE_TEXT, " \n+ ", JRExpressionChunk.TYPE_FIELD, "bar",}},
            {"$F{$foo}", new Object[]{JRExpressionChunk.TYPE_FIELD, "$foo"}},
            {"$F{foo", new Object[]{JRExpressionChunk.TYPE_TEXT, "$F{foo"}},
            {"$X{foo}", new Object[]{JRExpressionChunk.TYPE_TEXT, "$X{foo}"}},
            {"$F{foo}bar}", new Object[]{JRExpressionChunk.TYPE_FIELD, "foo", JRExpressionChunk.TYPE_TEXT, "bar}"}},
            {"$$P{foo}", new Object[]{JRExpressionChunk.TYPE_TEXT, "$P{foo}"}},
            {"$P{foo} + \"$$P{bar}\"", new Object[]{JRExpressionChunk.TYPE_PARAMETER, "foo", JRExpressionChunk.TYPE_TEXT, " + \"$P{bar}\""}},
            {"$P{foo} + \"$$P{bar}\" + $V{var}", new Object[]{JRExpressionChunk.TYPE_PARAMETER, "foo", JRExpressionChunk.TYPE_TEXT, " + \"$P{bar}\" + ", JRExpressionChunk.TYPE_VARIABLE, "var"}},
            {"$R{}", new Object[]{JRExpressionChunk.TYPE_RESOURCE, ""}},
    };
}
项目:PDFReporter-Studio    文件:JEvalExpressionEvaluator.java   
private IExpressionElement buildExpression(JRExpression expression, int expressionId) throws JRException {
    JRExpressionChunk[] designExpressionChunks = expression.getChunks();
    try {
        boolean singleChunk = (designExpressionChunks==null || designExpressionChunks.length == 1);
        if (designExpressionChunks != null && designExpressionChunks.length > 0) {
            if (singleChunk) {
                IExpressionElement result = SingleChunkExpressionFactory.buildExpression(this, designExpressionChunks[0]);
                return result==null ? JevalExpressionFactory.buildExpression(this, designExpressionChunks, expressionId) : result;
            } else {
                return JevalExpressionFactory.buildExpression(this, designExpressionChunks, expressionId);
            }           
        }
        return SingleChunkTextTypeFactory.buildExpression("null");
    } catch (ExpressionParseException e) {
        throw new JRException(e);
    }
}
项目:jasperreports    文件:JRBaseExpressionChunk.java   
/**
 *
 */
protected JRBaseExpressionChunk(JRExpressionChunk queryChunk, JRBaseObjectFactory factory)
{
    factory.put(queryChunk, this);

    type = queryChunk.getType();
    text = queryChunk.getText();
}
项目:jasperreports    文件:JRBaseExpression.java   
/**
 * Creates a copy of an expression.
 * 
 * @param expression the original expression
 * @param factory the base object factory
 * @param expressionId if not null, the created expression will use it as ID
 * instead of the original expressions's ID 
 */
protected JRBaseExpression(JRExpression expression, JRBaseObjectFactory factory, Integer expressionId)
{
    factory.put(expression, this);

    if (expressionId == null)
    {
        id = expression.getId();
    }
    else
    {
        id = expressionId.intValue();
    }

    type = expression.getType();

    /*   */
    JRExpressionChunk[] jrChunks = expression.getChunks();
    if (jrChunks != null && jrChunks.length > 0)
    {
        chunks = new JRExpressionChunk[jrChunks.length];
        for(int i = 0; i < chunks.length; i++)
        {
            chunks[i] = factory.getExpressionChunk(jrChunks[i]);
        }
    }
}
项目:jasperreports    文件:CompositeExpressionChunkVisitor.java   
@Override
public void visitTextChunk(JRExpressionChunk chunk)
{
    for (ExpressionChunkVisitor visitor : visitors)
    {
        visitor.visitTextChunk(chunk);
    }
}
项目:jasperreports    文件:CompositeExpressionChunkVisitor.java   
@Override
public void visitParameterChunk(JRExpressionChunk chunk)
{
    for (ExpressionChunkVisitor visitor : visitors)
    {
        visitor.visitParameterChunk(chunk);
    }
}
项目:jasperreports    文件:CompositeExpressionChunkVisitor.java   
@Override
public void visitFieldChunk(JRExpressionChunk chunk)
{
    for (ExpressionChunkVisitor visitor : visitors)
    {
        visitor.visitFieldChunk(chunk);
    }
}
项目:jasperreports    文件:CompositeExpressionChunkVisitor.java   
@Override
public void visitVariableChunk(JRExpressionChunk chunk)
{
    for (ExpressionChunkVisitor visitor : visitors)
    {
        visitor.visitVariableChunk(chunk);
    }
}
项目:jasperreports    文件:CompositeExpressionChunkVisitor.java   
@Override
public void visitResourceChunk(JRExpressionChunk chunk)
{
    for (ExpressionChunkVisitor visitor : visitors)
    {
        visitor.visitResourceChunk(chunk);
    }
}
项目:jasperreports    文件:JRExpressionUtil.java   
public static void visitChunks(JRExpression expression, ExpressionChunkVisitor visitor)
{
    JRExpressionChunk[] chunks = expression.getChunks();
    if (chunks != null)
    {
        for (JRExpressionChunk chunk : chunks)
        {
            switch (chunk.getType())
            {
            case JRExpressionChunk.TYPE_TEXT:
                visitor.visitTextChunk(chunk);
                break;
            case JRExpressionChunk.TYPE_PARAMETER:
                visitor.visitParameterChunk(chunk);
                break;
            case JRExpressionChunk.TYPE_FIELD:
                visitor.visitFieldChunk(chunk);
                break;
            case JRExpressionChunk.TYPE_VARIABLE:
                visitor.visitVariableChunk(chunk);
                break;
            case JRExpressionChunk.TYPE_RESOURCE:
                visitor.visitResourceChunk(chunk);
                break;
            default:
                throw 
                    new JRRuntimeException(
                        EXCEPTION_MESSAGE_KEY_UNKNOWN_EXPRESSION_CHUNK_TYPE,
                        new Object[]{chunk.getType()});
            }
        }
    }
}
项目:jasperreports    文件:ExpressionParser.java   
protected byte chunkStringToType(String chunkStringType)
{
    byte chunkType;
    char firstChar = chunkStringType.charAt(0);
    switch (firstChar)
    {
    case PLACEHOLDER_TYPE_PARAMETER:
        chunkType = JRExpressionChunk.TYPE_PARAMETER;
        break;

    case PLACEHOLDER_TYPE_FIELD:
        chunkType = JRExpressionChunk.TYPE_FIELD;
        break;

    case PLACEHOLDER_TYPE_VARIABLE:
        chunkType = JRExpressionChunk.TYPE_VARIABLE;
        break;

    case PLACEHOLDER_TYPE_RESOURCE_MESSAGE:
        chunkType = JRExpressionChunk.TYPE_RESOURCE;
        break;

    default:
        throw 
            new JRRuntimeException(
                    JRExpressionUtil.EXCEPTION_MESSAGE_KEY_UNKNOWN_EXPRESSION_CHUNK_TYPE,
                    new Object[]{chunkStringType});
    }
    return chunkType;
}
项目:jasperreports    文件:JRDesignExpression.java   
@Override
public JRExpressionChunk[] getChunks()
{
    JRExpressionChunk[] chunkArray = null;

    if (chunks != null && chunks.size() > 0)
    {
        chunkArray = new JRExpressionChunk[chunks.size()];
        chunks.toArray(chunkArray);
    }

    return chunkArray;
}
项目:jasperreports    文件:JRDesignExpression.java   
/**
 *
 */
public void addTextChunk(String text)
{
    JRDesignExpressionChunk chunk = new JRDesignExpressionChunk();
    chunk.setType(JRExpressionChunk.TYPE_TEXT);
    chunk.setText(text);

    this.chunks.add(chunk);
}
项目:jasperreports    文件:JRDesignExpression.java   
/**
 *
 */
public void addParameterChunk(String text)
{
    JRDesignExpressionChunk chunk = new JRDesignExpressionChunk();
    chunk.setType(JRExpressionChunk.TYPE_PARAMETER);
    chunk.setText(text);

    this.chunks.add(chunk);
}
项目:jasperreports    文件:JRDesignExpression.java   
/**
 *
 */
public void addFieldChunk(String text)
{
    JRDesignExpressionChunk chunk = new JRDesignExpressionChunk();
    chunk.setType(JRExpressionChunk.TYPE_FIELD);
    chunk.setText(text);

    this.chunks.add(chunk);
}
项目:jasperreports    文件:JRDesignExpression.java   
/**
 *
 */
public void addVariableChunk(String text)
{
    JRDesignExpressionChunk chunk = new JRDesignExpressionChunk();
    chunk.setType(JRExpressionChunk.TYPE_VARIABLE);
    chunk.setText(text);

    this.chunks.add(chunk);
}
项目:jasperreports    文件:JRDesignExpression.java   
/**
 *
 */
public void addResourceChunk(String text)
{
    JRDesignExpressionChunk chunk = new JRDesignExpressionChunk();
    chunk.setType(JRExpressionChunk.TYPE_RESOURCE);
    chunk.setText(text);

    this.chunks.add(chunk);
}
项目:jasperreports    文件:SimpleTextExpressionEvaluator.java   
public void collectChunks(JRExpressionChunk[] chunks)
{
    for (JRExpressionChunk chunk : chunks)
    {
        byte chunkType = chunk.getType();
        if (chunkType == JRExpressionChunk.TYPE_TEXT)
        {
            appendTextChunk(chunk.getText());
        }
        else
        {
            appendValueChunk(chunkType, chunk.getText());
        }
    }
}
项目:jasperreports    文件:JavaScriptCompilerBase.java   
@Override
public void visitParameterChunk(JRExpressionChunk chunk)
{
    String paramName = getParameterVar(chunk.getText());
    script.append(paramName);
    script.append(".getValue()");
}
项目:jasperreports    文件:JavaScriptCompilerBase.java   
@Override
public void visitResourceChunk(JRExpressionChunk chunk)
{
    String key = chunk.getText();
    script.append(JavaScriptEvaluatorScope.EVALUATOR_VAR);
    script.append(".str('");
    script.append(JRStringUtil.escapeJavaScript(key));
    script.append("')");
}
项目:PDFReporter-Studio    文件:SingleChunkExpressionFactory.java   
public static IExpressionElement buildExpression(IDataHolder dataholder, JRExpressionChunk chunk) throws ExpressionParseException {
    String chunkText = chunk.getText();
    if (chunkText == null)
    {
        chunkText = "";
    }

    switch (chunk.getType())
    {
        case JRExpressionChunk.TYPE_TEXT :
        {
            return SingleChunkTextTypeFactory.buildExpression(chunkText);
        }
        case JRExpressionChunk.TYPE_PARAMETER :
        {
            // jrParameter = sourceTask.getParametersMap().get(chunkText);
            // we do not need the class type for now: jrParameter.getValueClassName()
            return new ParameterElement(dataholder, chunkText);
        }
        case JRExpressionChunk.TYPE_FIELD :
        {
            // jrField = sourceTask.getFieldsMap().get(chunkText);
            // we do not need the class type for now: jrField.getValueClassName()
            return new FieldElement(dataholder, chunkText);
        }
        case JRExpressionChunk.TYPE_VARIABLE :
        {
            // jrVariable = sourceTask.getVariablesMap().get(chunkText);
            // we do not need the class type for now: jrVariable.getValueClassName()
            return new VariableElement(dataholder, chunkText);
        }
        case JRExpressionChunk.TYPE_RESOURCE :
        {
            return SingleChunkTextTypeFactory.buildExpression("str(\"" + chunkText + "\")");
        }
    }
    throw new ExpressionParseException("Unreachable type: " + chunk.getType() + ", text: " + chunkText);
}
项目:ireport-fork    文件:ModelUtils.java   
/**
 * Replace a particular name with another name.
 * If newClassName is null, it is ignored, otherwise the expression will take the new class value.
 * if oldName is null or newName is null, nothing is done
 * if oldName and newName are equals,  nothing is done
 * if exp is null, nothing is done
 * 
 * @param exp
 * @param oldName
 * @param newName
 * @param chunckType
 * @param newClassName (can be null)
 */
public static void replaceChunkText(JRDesignExpression exp, String oldName, String newName, byte chunckType, String newClassName) {
    if (exp == null) return;
    if (oldName == null || newName == null) return;
    if (oldName.equals(newName)) return;

    // replace the correct chunk. TODO: better implementation?
    String oldString = "";
    String pre = "";
    String post = "";

    switch (chunckType)
    {
        case JRExpressionChunk.TYPE_FIELD:
            pre = "$F{";  post = "}"; break;
        case JRExpressionChunk.TYPE_VARIABLE:
            pre = "$V{";  post = "}"; break;
        case JRExpressionChunk.TYPE_PARAMETER:
            pre = "$P{";  post = "}";  break;
        case JRExpressionChunk.TYPE_RESOURCE:
            pre = "$R{";  post = "}";  break;
        default:
           break;
    }

    oldName = pre + oldName + post;
    newName = pre + newName + post;

    if (exp.getText() == null || exp.getText().indexOf(oldName) < 0) return;

    exp.setText( Misc.string_replace(newName, oldName, exp.getText()));
    if (exp.getValueClassName() != null &&
        newClassName != null &&
        !exp.getValueClassName().equals(newClassName))
    {
        exp.setValueClassName( newClassName );
    }
}
项目:ireport-fork    文件:CrosstabMeasureNode.java   
@Override
public void setString(String newName) {



    String oldName = getMeasure().getName();
    int index = crosstab.getMesuresList().indexOf(getMeasure());


    crosstab.removeMeasure(getMeasure().getName());

    getMeasure().setName(newName);
    try {
        crosstab.addMeasure(getMeasure());
        crosstab.getMesuresList().remove(getMeasure());
        crosstab.getMesuresList().add(index, getMeasure());
        crosstab.getEventSupport().firePropertyChange( JRDesignCrosstab.PROPERTY_MEASURES, 0, 1);
        IReportManager.getInstance().setSelectedObject(getMeasure());
    } catch (JRException ex) {
        Exceptions.printStackTrace(ex);
    }


    // replace oldName with newName in all the crosstab expressions...

    ModelUtils.fixElementsExpressions(crosstab, oldName, newName, JRExpressionChunk.TYPE_VARIABLE, getMeasure().getValueClassName());

    List expressions = JRExpressionCollector.collectExpressions(jd, crosstab);
    for (int i=0; i<expressions.size(); ++i)
    {
        JRDesignExpression exp = (JRDesignExpression)expressions.get(i);
        ModelUtils.replaceChunkText(exp, oldName, newName, JRExpressionChunk.TYPE_VARIABLE, getMeasure().getValueClassName());
    }
}
项目:jasperreports    文件:JRBaseExpression.java   
@Override
public JRExpressionChunk[] getChunks()
{
    return chunks;
}
项目:jasperreports    文件:JRBaseExpression.java   
@Override
public String getText()
{
    String text = "";

    chunks = getChunks();
    if (chunks != null && chunks.length > 0)
    {
        StringBuilder sb = new StringBuilder();

        for(int i = 0; i < chunks.length; i++)
        {
            switch(chunks[i].getType())
            {
                case JRExpressionChunk.TYPE_PARAMETER :
                {
                    sb.append("$P{");
                    sb.append( chunks[i].getText() );
                    sb.append("}");
                    break;
                }
                case JRExpressionChunk.TYPE_FIELD :
                {
                    sb.append("$F{");
                    sb.append( chunks[i].getText() );
                    sb.append("}");
                    break;
                }
                case JRExpressionChunk.TYPE_VARIABLE :
                {
                    sb.append("$V{");
                    sb.append( chunks[i].getText() );
                    sb.append("}");
                    break;
                }
                case JRExpressionChunk.TYPE_RESOURCE :
                {
                    sb.append("$R{");
                    sb.append( chunks[i].getText() );
                    sb.append("}");
                    break;
                }
                case JRExpressionChunk.TYPE_TEXT :
                default :
                {
                    String textChunk = chunks[i].getText();
                    String escapedText = escapeTextChunk(textChunk);
                    sb.append(escapedText);
                    break;
                }
            }
        }

        text = sb.toString();
    }

    return text;
}
项目:jasperreports    文件:PropertyStyleProvider.java   
public PropertyStyleProvider(
    StyleProviderContext context, 
    Map<String, JRPropertyExpression> stylePropertyExpressions
    )
{
    this.context = context;
    this.stylePropertyExpressions = stylePropertyExpressions;

    List<String> fieldsList = new ArrayList<String>();
    List<String> variablesList = new ArrayList<String>();

    if (stylePropertyExpressions != null)
    {
        for(JRPropertyExpression stylePropertyExpression : stylePropertyExpressions.values())
        {
            JRExpression expression = stylePropertyExpression.getValueExpression();
            if (expression != null)
            {
                JRExpressionChunk[] chunks = expression.getChunks();
                if (chunks != null)
                {
                    for (int i = 0; i < chunks.length; i++)
                    {
                        JRExpressionChunk chunk = chunks[i];
                        switch (chunk.getType())
                        {
                            case JRExpressionChunk.TYPE_FIELD:
                            {
                                fieldsList.add(chunk.getText());
                                break;
                            }
                            case JRExpressionChunk.TYPE_VARIABLE:
                            {
                                variablesList.add(chunk.getText());
                                break;
                            }
                        }
                    }
                }
            }
        }
    }

    fields = fieldsList.size() > 0 ? (String[]) fieldsList.toArray(new String[fieldsList.size()]) : null;
    variables = variablesList.size() > 0 ? (String[]) variablesList.toArray(new String[variablesList.size()]) : null;

    JRElement element = context.getElement();
    JREvaluation evaluation = element instanceof JREvaluation ? (JREvaluation)element : null;
    lateEvaluated = evaluation != null && evaluation.getEvaluationTimeValue() != EvaluationTimeEnum.NOW;
}
项目:jasperreports    文件:JRVerifier.java   
/**
 *
 */
private void verifyExpressions(
        List<JRExpression> expressions, 
        Map<String, ? extends JRParameter> parametersMap, 
        Map<String, JRField> fieldsMap, 
        Map<String, JRVariable> variablesMap
        )
{
    if (expressions != null && expressions.size() > 0)
    {
        for(Iterator<JRExpression> it = expressions.iterator(); it.hasNext();)
        {
            JRExpression expression = it.next();
            JRExpressionChunk[] chunks = expression.getChunks();
            if (chunks != null && chunks.length > 0)
            {
                for(int j = 0; j < chunks.length; j++)
                {
                    JRExpressionChunk expressionChunk = chunks[j];
                    switch (expressionChunk.getType())
                    {
                        case JRExpressionChunk.TYPE_VARIABLE :
                        {
                            if ( !variablesMap.containsKey(expressionChunk.getText()) )
                            {
                                addBrokenRule("Variable not found : " + expressionChunk.getText(), expression);
                            }
                            break;
                        }
                        case JRExpressionChunk.TYPE_FIELD :
                        {
                            if ( !fieldsMap.containsKey(expressionChunk.getText()) )
                            {
                                addBrokenRule("Field not found : " + expressionChunk.getText(), expression);
                            }
                            break;
                        }
                        case JRExpressionChunk.TYPE_PARAMETER :
                        {
                            if ( !parametersMap.containsKey(expressionChunk.getText()) )
                            {
                                addBrokenRule("Parameter not found : " + expressionChunk.getText(), expression);
                            }
                            break;
                        }
                        case JRExpressionChunk.TYPE_RESOURCE :
                        case JRExpressionChunk.TYPE_TEXT :
                        default :
                        {
                        }
                    }
                }
            }
        }
    }
}
项目:jasperreports    文件:JRDesignExpression.java   
/**
 * Clears the current list of chunks and adds the passed list of chunks.  The reference
 * to the list passed is not kept.
 */
public void setChunks(List<JRExpressionChunk> chunks)
{
    this.chunks.clear();
    this.chunks.addAll(chunks);
}
项目:jasperreports    文件:JRFillCrosstab.java   
private void copyVariables(JRCrosstab crosstab, JRFillObjectFactory factory)
{
    JRVariable[] vars = crosstab.getVariables();
    variables = new JRFillVariable[vars.length];
    variablesMap = new HashMap<String,JRFillVariable>();
    for (int i = 0; i < variables.length; i++)
    {
        variables[i] = factory.getVariable(vars[i]);
        variablesMap.put(variables[i].getName(), variables[i]);
    }

    Map<String,int[]> totalVarPos = new HashMap<String,int[]>();
    totalVariables = new JRFillVariable[rowGroups.length + 1][columnGroups.length + 1][measures.length];
    for (int row = 0; row <= rowGroups.length; ++row)
    {
        JRCrosstabRowGroup rowGroup = row == rowGroups.length ? null : rowGroups[row];
        for (int col = 0; col <= columnGroups.length; ++col)
        {
            JRCrosstabColumnGroup colGroup = col == columnGroups.length ? null : columnGroups[col];

            if (row < rowGroups.length || col < columnGroups.length)
            {
                for (int m = 0; m < measures.length; m++)
                {
                    String totalVariableName = JRDesignCrosstab.getTotalVariableName(measures[m], rowGroup, colGroup);
                    totalVariables[row][col][m] = variablesMap.get(totalVariableName);
                    totalVarPos.put(totalVariableName, new int[]{row, col});
                }
            }
        }
    }

    Set<String> measureVars = new HashSet<String>();
    for (JRFillCrosstabMeasure measure : measures)
    {
        measureVars.add(measure.getFillVariable().getName());
    }

    retrieveTotal = new boolean[rowGroups.length + 1][columnGroups.length + 1];

    //FIXME avoid this
    JRExpressionCollector collector = JRExpressionCollector.collector(filler.getJasperReportsContext(), filler.getJasperReport(), crosstab);
    List<JRExpression> expressions = collector.getExpressions(crosstab);
    for (Iterator<JRExpression> iter = expressions.iterator(); iter.hasNext();)
    {
        JRExpression expression = iter.next();
        Object expressionContext = collector.getExpressionContext(expression);
        boolean groupHeaderExpression = expressionContext instanceof JRCrosstabGroup;
        JRExpressionChunk[] chunks = expression.getChunks();
        if (chunks != null)
        {
            for (int i = 0; i < chunks.length; i++)
            {
                JRExpressionChunk chunk = chunks[i];
                if (chunk.getType() == JRExpressionChunk.TYPE_VARIABLE)
                {
                    String varName = chunk.getText();
                    int[] pos = totalVarPos.get(varName);
                    if (pos != null)
                    {
                        retrieveTotal[pos[0]][pos[1]] = true;
                    }

                    // if a measure variable is used inside a group header, compute all totals.
                    // in theory we could have a finer grained rule here, but it complicates
                    // the logic without a singnificant gain.
                    if (groupHeaderExpression && (pos != null || measureVars.contains(varName)))
                    {
                        retrieveTotal[0][0] = true;
                    }
                }
            }
        }
    }
}
项目:jasperreports    文件:JavaScriptCompilerBase.java   
@Override
public void visitTextChunk(JRExpressionChunk chunk)
{
    script.append(chunk.getText());
}
项目:jasperreports    文件:JavaScriptCompilerBase.java   
@Override
public void visitFieldChunk(JRExpressionChunk chunk)
{
    String fieldName = getFieldVar(chunk.getText());
    script.append(fieldName).append('.').append(fieldMethod).append("()");
}
项目:jasperreports    文件:JavaScriptCompilerBase.java   
@Override
public void visitVariableChunk(JRExpressionChunk chunk)
{
    String varName = getVariableVar(chunk.getText());
    script.append(varName).append('.').append(variableMethod).append("()");
}
项目:jasperreports    文件:SortCommand.java   
@Override
public void execute() throws CommandException 
{
    SortOrderEnum sortOrder = HeaderToolbarElementUtils.getSortOrder(sortData.getSortOrder());//FIXMEJIVE use labels in JR enum, even if they are longer

    JRDesignSortField newSortField = 
        new JRDesignSortField(
            sortData.getSortColumnName(),
            SortFieldTypeEnum.getByName(sortData.getSortColumnType()),
            sortOrder
            );

    JRSortField oldSortField = null;
    List<JRSortField> sortFields = dataset.getSortFieldsList();
    if (
        JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(dataset, PROPERTY_CREATE_SORT_FIELDS_FOR_GROUPS, false)
        && (sortFields == null || sortFields.isEmpty())
        )
    {
        List<JRGroup> groups = dataset.getGroupsList();
        for (JRGroup group : groups)
        {
            JRExpression expression = group.getExpression();
            if (expression != null)
            {
                JRExpressionChunk[] chunks = expression.getChunks();
                if (chunks != null && chunks.length == 1)
                {
                    JRExpressionChunk chunk = chunks[0];
                    if (
                        chunk.getType() == JRExpressionChunk.TYPE_FIELD
                        || chunk.getType() == JRExpressionChunk.TYPE_VARIABLE
                        )
                    {
                        JRDesignSortField groupSortField = 
                            new JRDesignSortField(
                                chunk.getText(),
                                chunk.getType() == JRExpressionChunk.TYPE_FIELD 
                                    ? SortFieldTypeEnum.FIELD
                                    : SortFieldTypeEnum.VARIABLE,
                                SortOrderEnum.ASCENDING
                                );
                        individualCommandStack.execute(new AddSortFieldCommand(dataset, groupSortField));
                    }
                }
            }
        }
    }

    for (JRSortField crtSortField : sortFields)
    {
        if (
            newSortField.getName().equals(crtSortField.getName())
            && newSortField.getType() == crtSortField.getType()
            )
        {
            oldSortField = crtSortField;
            break;
        }
    }

    if (oldSortField != null)
    {
        individualCommandStack.execute(new RemoveSortFieldCommand(dataset, oldSortField));
    }

    if (sortOrder != null)
    {
        individualCommandStack.execute(new AddSortFieldCommand(dataset, newSortField));
    }
}
项目:PDFReporter-Studio    文件:JevalExpressionFactory.java   
public static IExpressionElement buildExpression(IDataHolder dataholder, JRExpressionChunk[] chunks, int expressionId) throws JRException {
    return new JevalExpressionFactory(dataholder).build(chunks, expressionId);
}
项目:PDFReporter-Studio    文件:JevalExpressionFactory.java   
private IExpressionElement build(JRExpressionChunk[] chunks, int expressionId) throws JRException {
    ResultCast result = new ResultCast();
    ChunkBuilder expressionBuilder = new ChunkBuilder();
    rawExpression  = new StringBuilder();
    try {
        for (JRExpressionChunk designChunk : chunks) {

            String chunkText = designChunk.getText();

            if (chunkText == null) {
                chunkText = "";
            }
            switch (designChunk.getType()) {
                case JRExpressionChunk.TYPE_TEXT: {
                    rawExpression.append(chunkText);
                    if (ResultCast.isCast(chunkText)) {
                        result = ResultCast.parseCast(chunkText);
                        expressionBuilder.addText(ResultCast.getNext(chunkText));
                    } else {                            
                        expressionBuilder.addText(chunkText);
                    }
                    break;
                }
                case JRExpressionChunk.TYPE_PARAMETER: {
                    appendRawParameter(chunkText);
                    expressionBuilder.addVariable(new ExpressionParameter(dataholder, chunkText));
                    break;
                }
                case JRExpressionChunk.TYPE_FIELD: {
                    appendRawField(chunkText);
                    expressionBuilder.addVariable(new ExpressionField(dataholder, chunkText));
                    break;
                }
                case JRExpressionChunk.TYPE_VARIABLE: {
                    appendRawVariable(chunkText);
                    expressionBuilder.addVariable(new ExpressionVariable(dataholder, chunkText));
                    break;
                }
                case JRExpressionChunk.TYPE_RESOURCE: {
                    appendRawResource(chunkText);
                    expressionBuilder.addResource(chunkText);
                    break;
                }
            }
        }           

        result.setExpression(JEvalExpression.newInstance(expressionBuilder.getChunkList()));
        logger.finest("Compiled expression " + expressionId + " - " + rawExpression.toString());
        return result;
    } catch (ExpressionParseException e) {
        logger.log(Level.SEVERE, "Error parsing '" + rawExpression.toString() + "' in JRXML DesignReport.", e);
        throw new JRException("Error parsing '" + rawExpression.toString() + "' in JRXML DesignReport.", e);
    }

}