Package net.asfun.jangod.interpret

Examples of net.asfun.jangod.interpret.InterpretException


public class EqualFilter implements Filter{

  @Override
  public Object filter(Object object, JangodInterpreter interpreter, String... arg) throws InterpretException {
    if ( arg.length != 1 ) {
      throw new InterpretException("filter equal 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);
View Full Code Here


  @Override
  public Object filter(Object object, JangodInterpreter interpreter, String... arg)
      throws InterpretException {
    if ( arg.length != 1) {
      throw new InterpretException("filter add expects 1 arg >>> " + arg.length);
    }
    Object toAdd = interpreter.resolveObject(arg[0]);
    Number num;
    if ( toAdd instanceof String ) {
      try {
        num = new BigDecimal(toAdd.toString());
      } catch (Exception e) {
        throw new InterpretException("filter add arg can't cast to number >>> " + toAdd);
      }
    } else if ( toAdd instanceof Number ) {
      num = (Number) toAdd;
    } 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).add(BigDecimal.valueOf(num.doubleValue()));
    }
    if ( object instanceof BigInteger ) {
      return ((BigInteger)object).add(BigInteger.valueOf(num.longValue()));
    }
    if ( object instanceof Byte ) {
      return num.byteValue() + (Byte)object;
    }
    if ( object instanceof String ) {
      try {
        String sv = (String) object;
        if ( sv.contains(".") ) {
          return num.doubleValue() + Double.valueOf(sv);
        } else {
          return num.longValue() + Long.valueOf(sv);
        }
      } catch (Exception e) {
        throw new InterpretException(object + " can't be dealed with add 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 'ifchanged' expects 1 helper >>> 0");
    }
    boolean isChanged = true;
    String var = helpers;
    Object older = interpreter.fetchRuntimeScope(LASTKEY + var);
    Object test = interpreter.retraceVariable(var);
View Full Code Here

      sdf.setTimeZone(interpreter.getConfiguration().getTimezone());
    } else if ( arg.length == 2 ) {
      sdf = new SimpleDateFormat(interpreter.resolveString(arg[0]));
      sdf.setTimeZone(TimeZone.getTimeZone(interpreter.resolveString(arg[1])));
    } else {
      throw new InterpretException("filter date expects 1 or 2 args >>> " + arg.length);
    }
    try {
      return sdf.format(object);
    } catch (Exception e) {
      JangodLogger.log(Level.SEVERE, "filter date can't format a datetime >>> " + object, e.getCause());
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 != 1) {
      throw new InterpretException("Tag 'extends' 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.getContext().getApplication().getParseResult(
          fullName, interpreter.getConfiguration().getEncoding() );
     
     
      ListOrderedMap blockList = new ListOrderedMap();
      interpreter.assignRuntimeScope(JangodInterpreter.BLOCK_LIST, blockList, 1);
      JangodInterpreter parent = interpreter.clone();
      interpreter.assignRuntimeScope(JangodInterpreter.CHILD_FLAG, true, 1);
      parent.assignRuntimeScope(JangodInterpreter.PARENT_FLAG, true, 1);
      String semi = parent.render(node);
      interpreter.assignRuntimeScope(JangodInterpreter.SEMI_RENDER, semi, 1);
      return Constants.STR_BLANK;
    } catch (IOException e) {
      throw new InterpretException(e.getMessage());
    }
  }
View Full Code Here

    if ( object == null ) {
      return false;
    }
    if ( object instanceof Number ) {
      if ( arg.length != 1 ) {
        throw new InterpretException("filter divisible expects 1 arg >>> " + arg.length);
      }
      long factor = Long.valueOf(interpreter.resolveString(arg[0]));
      long value = ((Number)object).longValue();
      if ( value % factor == 0 ) {
        return true;
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 < 2 || helper.length > 3 ) {
      throw new InterpretException("Tag 'set' expects 2 or 3 helper >>> " + helper.length);
    }
    String scope = SCOPE_TOP;
    if ( helper.length == 3 ) {
      scope = helper[2].toLowerCase();
    }
View Full Code Here

  public Object filter(Object object, JangodInterpreter interpreter, String... arg) throws InterpretException {
    if ( ObjectTruthValue.evaluate(object) ) {
      return object;
    } else {
      if ( arg.length != 1) {
        throw new InterpretException("filter default expects 1 arg >>> " + arg.length);
      }
      return interpreter.resolveObject(arg[0]);
    }
  }
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 != 1) {
      throw new InterpretException("Tag 'block' expects 1 helper >>> " + helper.length);
    }
    String blockName = interpreter.resolveString(helper[0]);
    //check block name is unique
    List<String> blockNames = (List<String>) interpreter.fetchRuntimeScope(BLOCKNAMES ,1);
    if ( blockNames == null ) {
      blockNames = new ArrayList<String>();
    }
    if ( blockNames.contains(blockName) ) {
      throw new InterpretException("Can't redefine the block with name >>> " + blockName);
    } else {
      blockNames.add(blockName);
      interpreter.assignRuntimeScope(BLOCKNAMES, blockNames, 1);
    }
    Object isChild = interpreter.fetchRuntimeScope(JangodInterpreter.CHILD_FLAG, 1);
    if ( isChild != null ) {
      ListOrderedMap blockList = (ListOrderedMap) interpreter.fetchRuntimeScope(JangodInterpreter.BLOCK_LIST, 1);
      //check block was defined in parent
      if ( ! blockList.containsKey(blockName) ) {
        throw new InterpretException("Dosen't define block in extends parent with name >>> " + blockName);
      }
      //cover parent block content with child's.
      blockList.put(blockName, getBlockContent(carries, interpreter));
      return "";
    }
View Full Code Here

  @Override
  public Object filter(Object object, JangodInterpreter interpreter, String... arg)
      throws InterpretException {
    if ( arg.length != 1 ) {
      throw new InterpretException("filter cut expects 1 arg >>> " + arg.length);
    }
    String cutee = interpreter.resolveString(arg[0]);
    String origin = ObjectValue.printable(object);
    return origin.replace(cutee, Constants.STR_BLANK);
  }
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.