@Test public void testStreamWithNullExpression_mustEvaluateToEmptyString() throws Exception { final String data = "aa\nbbbb\ncc#{requestScope.test}cc\ndddd\n\n"; final String evaluatedData = "aa\nbbbb\ncccc\ndddd\n\n"; byte[] dataArray = data.getBytes(); byte[] evaluatedDataArray = evaluatedData.getBytes(); FacesContext.getCurrentInstance().getExternalContext().getRequestMap().remove("test"); ValueExpressionEvaluationInputStream inputStream = new ValueExpressionEvaluationInputStream( FacesContext.getCurrentInstance(), new ByteArrayInputStream(dataArray)); byte[] inputStreamDataArray = new byte[evaluatedDataArray.length]; inputStream.read(inputStreamDataArray); Assert.assertArrayEquals(evaluatedDataArray, inputStreamDataArray); Assert.assertEquals(-1, inputStream.read()); }
@Override public int read() throws IOException { if (currentValueIndex != -1) { if (currentValueIndex < currentValue.length()) { return currentValue.charAt(currentValueIndex++); } else { currentValueIndex = -1; } } int c1 = wrapped.read(); if (c1 != '#') { return c1; } else { int c2 = wrapped.read(); if (c2 != '{') { wrapped.unread(c2); return c1; } else { List<Integer> possibleValueExpression = new LinkedList<Integer>(); int c = wrapped.read(); boolean insideString = (c == '\''); while (c != -1 && c != '\n' && (insideString || c != '}')) { possibleValueExpression.add(c); c = wrapped.read(); if (c == '\'') { insideString = !insideString; } } if (c != '}') { if (c != -1) { wrapped.unread(c); } ListIterator<Integer> it = possibleValueExpression.listIterator(possibleValueExpression.size()); while (it.hasPrevious()) { wrapped.unread(it.previous()); } wrapped.unread(c2); return c1; } else { String expressionString = createExpressionString(possibleValueExpression); String expressionValue = facesContext.getApplication() .evaluateExpressionGet(facesContext, expressionString, String.class); if (expressionValue == null) { if (log.isLoggable(Level.WARNING)) { log.warning("ValueExpression " + expressionString + " evaluated to null."); } expressionValue = "null"; } this.currentValue = expressionValue; if (currentValue.length() != 0) { this.currentValueIndex = 0; return currentValue.charAt(currentValueIndex++); } else { this.currentValueIndex = -1; return read(); } } } } }
ValueExpressionEvaluationInputStream extends InputStream { @Override public int read() throws IOException { if (currentValueIndex != -1) { if (currentValueIndex < currentValue.length()) { return currentValue.charAt(currentValueIndex++); } else { currentValueIndex = -1; } } int c1 = wrapped.read(); if (c1 != '#') { return c1; } else { int c2 = wrapped.read(); if (c2 != '{') { wrapped.unread(c2); return c1; } else { List<Integer> possibleValueExpression = new LinkedList<Integer>(); int c = wrapped.read(); boolean insideString = (c == '\''); while (c != -1 && c != '\n' && (insideString || c != '}')) { possibleValueExpression.add(c); c = wrapped.read(); if (c == '\'') { insideString = !insideString; } } if (c != '}') { if (c != -1) { wrapped.unread(c); } ListIterator<Integer> it = possibleValueExpression.listIterator(possibleValueExpression.size()); while (it.hasPrevious()) { wrapped.unread(it.previous()); } wrapped.unread(c2); return c1; } else { String expressionString = createExpressionString(possibleValueExpression); String expressionValue = facesContext.getApplication() .evaluateExpressionGet(facesContext, expressionString, String.class); if (expressionValue == null) { if (log.isLoggable(Level.WARNING)) { log.warning("ValueExpression " + expressionString + " evaluated to null."); } expressionValue = "null"; } this.currentValue = expressionValue; if (currentValue.length() != 0) { this.currentValueIndex = 0; return currentValue.charAt(currentValueIndex++); } else { this.currentValueIndex = -1; return read(); } } } } } }
ValueExpressionEvaluationInputStream extends InputStream { @Override public int read() throws IOException { if (currentValueIndex != -1) { if (currentValueIndex < currentValue.length()) { return currentValue.charAt(currentValueIndex++); } else { currentValueIndex = -1; } } int c1 = wrapped.read(); if (c1 != '#') { return c1; } else { int c2 = wrapped.read(); if (c2 != '{') { wrapped.unread(c2); return c1; } else { List<Integer> possibleValueExpression = new LinkedList<Integer>(); int c = wrapped.read(); boolean insideString = (c == '\''); while (c != -1 && c != '\n' && (insideString || c != '}')) { possibleValueExpression.add(c); c = wrapped.read(); if (c == '\'') { insideString = !insideString; } } if (c != '}') { if (c != -1) { wrapped.unread(c); } ListIterator<Integer> it = possibleValueExpression.listIterator(possibleValueExpression.size()); while (it.hasPrevious()) { wrapped.unread(it.previous()); } wrapped.unread(c2); return c1; } else { String expressionString = createExpressionString(possibleValueExpression); String expressionValue = facesContext.getApplication() .evaluateExpressionGet(facesContext, expressionString, String.class); if (expressionValue == null) { if (log.isLoggable(Level.WARNING)) { log.warning("ValueExpression " + expressionString + " evaluated to null."); } expressionValue = "null"; } this.currentValue = expressionValue; if (currentValue.length() != 0) { this.currentValueIndex = 0; return currentValue.charAt(currentValueIndex++); } else { this.currentValueIndex = -1; return read(); } } } } } ValueExpressionEvaluationInputStream(FacesContext facesContext, InputStream inputStream); }
ValueExpressionEvaluationInputStream extends InputStream { @Override public int read() throws IOException { if (currentValueIndex != -1) { if (currentValueIndex < currentValue.length()) { return currentValue.charAt(currentValueIndex++); } else { currentValueIndex = -1; } } int c1 = wrapped.read(); if (c1 != '#') { return c1; } else { int c2 = wrapped.read(); if (c2 != '{') { wrapped.unread(c2); return c1; } else { List<Integer> possibleValueExpression = new LinkedList<Integer>(); int c = wrapped.read(); boolean insideString = (c == '\''); while (c != -1 && c != '\n' && (insideString || c != '}')) { possibleValueExpression.add(c); c = wrapped.read(); if (c == '\'') { insideString = !insideString; } } if (c != '}') { if (c != -1) { wrapped.unread(c); } ListIterator<Integer> it = possibleValueExpression.listIterator(possibleValueExpression.size()); while (it.hasPrevious()) { wrapped.unread(it.previous()); } wrapped.unread(c2); return c1; } else { String expressionString = createExpressionString(possibleValueExpression); String expressionValue = facesContext.getApplication() .evaluateExpressionGet(facesContext, expressionString, String.class); if (expressionValue == null) { if (log.isLoggable(Level.WARNING)) { log.warning("ValueExpression " + expressionString + " evaluated to null."); } expressionValue = "null"; } this.currentValue = expressionValue; if (currentValue.length() != 0) { this.currentValueIndex = 0; return currentValue.charAt(currentValueIndex++); } else { this.currentValueIndex = -1; return read(); } } } } } ValueExpressionEvaluationInputStream(FacesContext facesContext, InputStream inputStream); @Override int read(); }
ValueExpressionEvaluationInputStream extends InputStream { @Override public int read() throws IOException { if (currentValueIndex != -1) { if (currentValueIndex < currentValue.length()) { return currentValue.charAt(currentValueIndex++); } else { currentValueIndex = -1; } } int c1 = wrapped.read(); if (c1 != '#') { return c1; } else { int c2 = wrapped.read(); if (c2 != '{') { wrapped.unread(c2); return c1; } else { List<Integer> possibleValueExpression = new LinkedList<Integer>(); int c = wrapped.read(); boolean insideString = (c == '\''); while (c != -1 && c != '\n' && (insideString || c != '}')) { possibleValueExpression.add(c); c = wrapped.read(); if (c == '\'') { insideString = !insideString; } } if (c != '}') { if (c != -1) { wrapped.unread(c); } ListIterator<Integer> it = possibleValueExpression.listIterator(possibleValueExpression.size()); while (it.hasPrevious()) { wrapped.unread(it.previous()); } wrapped.unread(c2); return c1; } else { String expressionString = createExpressionString(possibleValueExpression); String expressionValue = facesContext.getApplication() .evaluateExpressionGet(facesContext, expressionString, String.class); if (expressionValue == null) { if (log.isLoggable(Level.WARNING)) { log.warning("ValueExpression " + expressionString + " evaluated to null."); } expressionValue = "null"; } this.currentValue = expressionValue; if (currentValue.length() != 0) { this.currentValueIndex = 0; return currentValue.charAt(currentValueIndex++); } else { this.currentValueIndex = -1; return read(); } } } } } ValueExpressionEvaluationInputStream(FacesContext facesContext, InputStream inputStream); @Override int read();  }