Package net.asfun.jangod.interpret

Examples of net.asfun.jangod.interpret.InterpretException


  @Override
  public String interpreter(NodeList carries, String helpers, JangodInterpreter interpreter)
      throws InterpretException {
    String[] helper = new HelperStringTokenizer(helpers).allTokens();
    if( helper.length != 1) {
      throw new InterpretException("Tag 'include' expects 1 helper >>> " + helper.length);
    }
    String templateFile = interpreter.resolveString(helper[0]);
    try {
      String fullName = ResourceManager.getFullName(templateFile,
          interpreter.getWorkspace(), interpreter.getConfiguration().getWorkspace());
      Node node = interpreter.getApplication().getParseResult(
          fullName, interpreter.getConfiguration().getEncoding() );
      JangodInterpreter child = interpreter.clone();
      child.assignRuntimeScope(JangodInterpreter.INSERT_FLAG, true, 1);
      return child.render(node);
    } catch (IOException e) {
      throw new InterpretException(e.getMessage());
    }
  }
View Full Code Here


  @Override
  public Object filter(Object object, JangodInterpreter interpreter, String... arg)
      throws InterpretException {
    if ( arg.length != 1) {
      throw new InterpretException("filter multiply expects 1 arg >>> " + arg.length);
    }
    Object toMul = interpreter.resolveObject(arg[0]);
    Number num;
    if ( toMul instanceof String ) {
      num = new BigDecimal(toMul.toString());
    } else if ( toMul instanceof Number ) {
      num = (Number) toMul;
    } else {
      return object;
    }
    if ( object instanceof Integer ) {
      return 0L + num.intValue() * (Integer)object;
    }
    if ( object instanceof Float ) {
      return 0D + num.floatValue() * (Float)object;
    }
    if ( object instanceof Long ) {
      return num.longValue() * (Long)object;
    }
    if ( object instanceof Short ) {
      return 0 + num.shortValue() * (Short)object;
    }
    if ( object instanceof Double ) {
      return num.doubleValue() * (Double)object;
    }
    if ( object instanceof BigDecimal ) {
      return ((BigDecimal)object).multiply(BigDecimal.valueOf(num.doubleValue()));
    }
    if ( object instanceof BigInteger ) {
      return ((BigInteger)object).multiply(BigInteger.valueOf(num.longValue()));
    }
    if ( object instanceof Byte ) {
      return num.byteValue() * (Byte)object;
    }
    if ( object instanceof String ) {
      try {
        return num.doubleValue() * Double.valueOf(object.toString());
      } catch (Exception e) {
        throw new InterpretException(object + " can't be dealed with multiply filter");
      }
    }
    return object;
  }
View Full Code Here

 
  @Override
  public String interpreter(NodeList carries, String helpers, JangodInterpreter interpreter) throws InterpretException {
    String[] helper = new HelperStringTokenizer(helpers).allTokens();
    if ( helper.length != 3 ) {
      throw new InterpretException("Tag 'for' expects 3 helpers >>> " + helper.length);
    }
    String item = helper[0];
    Object collection = VariableFilter.compute( helper[2], interpreter);
    ForLoop loop = ObjectIterator.getLoop(collection);
   
View Full Code Here

    }
    if ( object instanceof String ) {
      try {
        return new BigDecimal(object.toString()).abs();
      } catch (Exception e) {
        throw new InterpretException(object + " can't be dealed with abs filter");
      }
    }
    return object;
  }
View Full Code Here

  @Override
  public Object filter(Object object, JangodInterpreter interpreter, String... arg)
      throws InterpretException {
    if ( arg.length != 1) {
      throw new InterpretException("filter multiply expects 1 arg >>> " + arg.length);
    }
    Object toMul = interpreter.resolveObject(arg[0]);
    Number num;
    if ( toMul instanceof String ) {
      num = new BigDecimal(toMul.toString());
    } else if ( toMul instanceof Number ) {
      num = (Number) toMul;
    } else {
      return object;
    }
    if ( object instanceof Integer ) {
      return (Integer)object / num.intValue();
    }
    if ( object instanceof Float ) {
      return (Float)object / num.floatValue();
    }
    if ( object instanceof Long ) {
      return (Long)object / num.longValue();
    }
    if ( object instanceof Short ) {
      return (Short)object / num.shortValue();
    }
    if ( object instanceof Double ) {
      return (Double)object / num.doubleValue();
    }
    if ( object instanceof BigDecimal ) {
      return ((BigDecimal)object).divide(BigDecimal.valueOf(num.doubleValue()));
    }
    if ( object instanceof BigInteger ) {
      return ((BigInteger)object).divide(BigInteger.valueOf(num.longValue()));
    }
    if ( object instanceof Byte ) {
      return (Byte)object / num.byteValue();
    }
    if ( object instanceof String ) {
      try {
        return Double.valueOf(object.toString()) / num.doubleValue();
      } catch (Exception e) {
        throw new InterpretException(object + " can't be dealed with multiply filter");
      }
    }
    return object;
  }
View Full Code Here

  @Override
  public String interpreter(NodeList carries, String helpers, JangodInterpreter interpreter)
      throws InterpretException {
    if ( helpers.length() == 0 ) {
      throw new InterpretException("Tag 'if' expects 1 helper >>> 0");
    }
    Object test = VariableFilter.compute(helpers, interpreter);
    StringBuffer sb = new StringBuffer();
    if ( ObjectTruthValue.evaluate(test) ) {
      for(Node node : carries) {
View Full Code Here

      }
      var = helper[2];
      interpreter.assignRuntimeScope(var, values);
      return Constants.STR_BLANK;
    } else {
      throw new InterpretException("Tag 'cycle' expects 1 or 3 helper(s) >>> " + helper.length);
    }
  }
View Full Code Here

      throws InterpretException {
    if ( object == null ) {
      return false;
    }
    if ( arg.length != 1 ) {
      throw new InterpretException("filter contain expects 1 arg >>> " + arg.length);
    }
    Object argObj ;
    boolean isNull = false;
    if ( arg[0].startsWith(Constants.STR_SINGLE_QUOTE) || arg[0].startsWith(Constants.STR_DOUBLE_QUOTE) ) {
      argObj = arg[0].substring(1, arg[0].length()-1);
    } else {
      argObj = interpreter.retraceVariable(arg[0]);
      if ( isNull = argObj == null ) {
        argObj = arg[0];
      }
    }
    //iterable
    if ( object instanceof Iterable ) {
      Iterator<?> it = ((Iterable<?>)object).iterator();
      return iteratorContain(it, isNull, argObj);
    }
    //array
    if ( object.getClass().isArray() ) {
      int length = Array.getLength(object);
      Object item;
      for(int i=0; i<length; i++) {
        item = Array.get(object, i);
        if ( item == null ) {
          if ( isNull )
            return true;
        } else if ( ObjectStringEqual.evaluate(item, argObj) ){
          return true;
        }
      }
      return false;
    }
    //map
    if( object instanceof Map ) {
      Iterator<?> it = ((Map<?,?>)object).values().iterator();
      return iteratorContain(it, isNull, argObj);
    }
    //string
    if ( object instanceof String ) {
      return object.toString().contains(argObj.toString());
    }
    //iterator
    if ( object instanceof Iterator ) {
      return iteratorContain((Iterator<?>)object, isNull, argObj);
    }
    throw new InterpretException("filter contain can't be applied to >>> " + object.getClass().getName());
  }
View Full Code Here

TOP

Related Classes of net.asfun.jangod.interpret.InterpretException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.