Package org.mvel2.util

Examples of org.mvel2.util.StringAppender


      if (comp == char.class) {
        return "\"" + (Array.getLength(v) < 50 ? new String((char[]) v) : new String((char[]) v, 0, 50) + "...") + "\"";
      }
      else {
        StringAppender appender = new StringAppender();

        int len = Array.getLength(v);
        appender.append("[");
        for (int i = 0; i < len && i < 25; ) {
          appender.append(String.valueOf(Array.get(v, i)));
          if (++i < len && i < 25) appender.append(", ");
        }
        return appender.append("]").toString();
      }
    }
    else if (cls == Character.class) {
      return "'" + String.valueOf(v) + "'";
    }
View Full Code Here


              new DefaultMutableTreeNode("Callpoints (" + endpoints.size() + ")");

          for (String endpoint : endpoints) {
            String[] epParts = endpoint.split(":");

            StringAppender appender = new StringAppender(epParts[0]).append('(');
            for (int i = 1; i < epParts.length; i++) {
              appender.append(epParts[i]);
              if ((i + 1) < epParts.length) appender.append(", ");
            }

            remoteCPs.add(UiHelper.createIconEntry("database_connect.png", appender.append(')').toString()));
          }

          node.add(remoteCPs);
        }
      }
View Full Code Here

                  {
                     cursor++;
                     while ((cursor != length) && Character.isWhitespace(expr[cursor]))
                        cursor++;

                     StringAppender buf = new StringAppender("def".equals(tk) ? " " : "");

                     if (cursor != length)
                     {
                        do
                        {
                           boolean openBracket = expr[cursor] == '{';

                           if (openBracket)
                           {
                              cursor++;
                           }

                           buf.append(shellToMVEL(new String(expr, start, cursor - start - (openBracket ? 1 : 0)), true));
                           if (openBracket)
                           {
                              buf.append('{');
                           }

                           start = cursor;

                           if (openBracket)
                           {
                              cursor = balancedCapture(expr, cursor, '{');
                           }
                           else
                           {
                              while ((cursor != length) && (expr[cursor] != ';'))
                                 cursor++;
                           }

                           int offset = (cursor != length) && (expr[cursor] == '}') ? -1 : 0;

                           buf.append(shellToMVEL(new String(expr, start, cursor - start).trim(), false));

                           if (offset == -1)
                           {
                              buf.append("}");
                              cursor++;
                           }

                           tk += buf.toString();
                           buf.reset();

                           start = cursor;
                        }
                        while (ifThenElseBlockContinues());
View Full Code Here

      return logicalStatement;
   }

   private String shellToMVEL(final String subStmt, final boolean noShellCall)
   {
      StringAppender buf = new StringAppender();

      boolean stmtStart = true;
      boolean openShellCall = false;
      boolean scriptOnly = false;

      Nest nest = new Nest();

      for (int i = 0; i < subStmt.length(); i++)
      {
         if (stmtStart)
         {
            while ((i < subStmt.length()) && isWhitespace(subStmt.charAt(i)))
               i++;

            if (i >= subStmt.length())
            {
               break;
            }

            int firstToken = getEndOfToken(subStmt, i);
            String tk = subStmt.substring(i, firstToken).trim();
            if (!noShellCall && (tk.charAt(0) != '@') && ((firstToken == -1) || !isReservedWord(tk)))
            {
               buf.append("shell(\"");
               openShellCall = true;
            }
            else
            {
               scriptOnly = true;
               stmtStart = false;
               if (tk.charAt(0) == '@')
               {
                  continue;
               }
            }

            stmtStart = false;
         }

         switch (subStmt.charAt(i))
         {
         case '\\':
            buf.append("\\");
            if (nest.isLiteral())
            {
               buf.append("\\");
            }
            buf.append(subStmt.charAt(++i));
            if (subStmt.charAt(i) == '\\')
            {
               buf.append("\\");
            }

            break;

         case '\'':
            nest.nestSingleQuote();
            buf.append(subStmt.charAt(i));
            break;

         case '"':
            nest.nestDoubleQuote();
            if (openShellCall)
            {
               buf.append("\\\"");
            }
            else
            {
               buf.append(subStmt.charAt(i));
            }
            break;

         case '(':
            if (!nest.isLiteral())
            {
               nest.bracket++;
            }
            buf.append(subStmt.charAt(i));
            break;

         case '{':
            buf.append(subStmt.charAt(i));

            if (!nest.isLiteral())
            {
               int start = ++i;
               buf.append(shellToMVEL(subStmt.substring(start,
                        i = balancedCapture(subStmt.toCharArray(), i, '{')), false)).append('}');
            }

            break;

         case '[':
            if (!nest.isLiteral())
            {
               nest.square++;
            }
            buf.append(subStmt.charAt(i));
            break;

         case ')':
            if (!nest.isLiteral())
            {
               nest.bracket--;
            }
            buf.append(subStmt.charAt(i));
            break;

         case '}':
            if (!nest.isLiteral())
            {
               nest.curly--;
            }
            buf.append(subStmt.charAt(i));
            break;

         case ']':
            if (!nest.isLiteral())
            {
               nest.square--;
            }
            buf.append(subStmt.charAt(i));
            break;

         case ';':
            if (!nest.isLiteral())
            {
               if (openShellCall)
               {
                  buf.append("\")");
                  openShellCall = false;
               }

               stmtStart = true;
               scriptOnly = false;
            }

            buf.append(subStmt.charAt(i));
            break;

         case '$':
            if (!scriptOnly)
            {
               buf.append("\"+");

               int start = ++i;
               i = captureToken(i, subStmt.length(), subStmt.toCharArray());
               buf.append(subStmt.substring(start, i));

               if (i < subStmt.length())
               {
                  buf.append("+\"");
                  i--;
               }
               else
               {
                  buf.append(")");
                  openShellCall = false;
               }
            }
            else
            {
               if (++i < subStmt.length())
               {
                  buf.append(subStmt.charAt(i));
               }
            }
            break;

         default:
            buf.append(subStmt.charAt(i));
         }

      }

      if (nest.isLiteral())
      {
         throw new RuntimeException("unterminated string literal while parsing script");
      }

      if (nest.isNested())
      {
         throw new RuntimeException("unterminated nest while parsing script");
      }

      if (openShellCall)
      {
         buf.append("\")");
      }

      return buf.toString();
   }
View Full Code Here

        this.injector = injector;
        this.type = type;
    }

    public String doTask(InjectionContext ctx) {
        StringAppender appender = new StringAppender();
        InjectionPoint injectionPoint
                = new InjectionPoint(null, injectType, constructor, method, field, type, parm, injector, ctx);
        switch (injectType) {
            case Field:

                appender.append(injector.getVarName()).append('.').append(field.getName()).append(" = ")
                        .append(ctx.getInjector(field.getType().isClassOrInterface()).getType(ctx, injectionPoint))
                        .append(";\n");
                break;

            case Method:
                appender.append(injector.getVarName()).append('.')
                        .append(method.getName()).append('(');

                String[] vars = InjectUtil.resolveInjectionDependencies(method.getParameters(), ctx, injectionPoint);

                appender.append(InjectUtil.commaDelimitedList(vars)).append(");\n");
                break;
        }

        return appender.toString();
    }
View Full Code Here

            return new ConstructionStrategy() {
                public String generateConstructor() {
                    String[] vars = resolveInjectionDependencies(constructor.getParameters(), ctx, constructor);

                    StringAppender appender = new StringAppender("final ").append(type.getQualifiedSourceName())
                            .append(' ').append(injector.getVarName()).append(" = new ")
                            .append(type.getQualifiedSourceName())
                            .append('(').append(commaDelimitedList(vars)).append(");\n");

                    handleInjectionTasks(appender, ctx, injectionTasks);

                    doPostConstruct(appender, injector, postConstructTasks);

                    return appender.toString();
                }
            };

        } else {
            // field injection

            if (!hasDefaultConstructor(type))
                throw new InjectionFailure("there is no default constructor for type: " + type.getQualifiedSourceName());

            return new ConstructionStrategy() {
                public String generateConstructor() {
                    StringAppender appender = new StringAppender("final ").append(type.getQualifiedSourceName())
                            .append(' ').append(injector.getVarName()).append(" = new ")
                            .append(type.getQualifiedSourceName()).append("();\n");

                    handleInjectionTasks(appender, ctx, injectionTasks);

                    doPostConstruct(appender, injector, postConstructTasks);

                    return appender.toString();
                }
            };
        }
    }
View Full Code Here

        return varNames;
    }

    public static String commaDelimitedList(String[] parts) {
        StringAppender appender = new StringAppender();
        for (int i = 0; i < parts.length; i++) {
            appender.append(parts[i]);
            if ((i + 1) < parts.length) appender.append(", ");
        }
        return appender.toString();
    }
View Full Code Here

      }
   }

   private void match(InputStream instream, Pattern pattern, PipeOut out, boolean caseInsensitive) throws IOException
   {
      StringAppender buf = new StringAppender();

      int c;
      while ((c = instream.read()) != -1)
      {
         switch (c)
         {
         case '\r':
         case '\n':
            String s = caseInsensitive ? buf.toString().toLowerCase() : buf.toString();

            if (pattern.matcher(s).matches())
            {
               out.println(s);
            }
            buf.reset();
            break;
         default:
            buf.append((char) c);
            break;
         }
      }
   }
View Full Code Here

    return parmValues;
  }

  public static String commaDelimitedList(Context context, Statement[] parts) {
    StringAppender appender = new StringAppender();
    for (int i = 0; i < parts.length; i++) {
      appender.append(parts[i].generate(context));
      if ((i + 1) < parts.length) appender.append(", ");
    }
    return appender.toString();
  }
View Full Code Here

    return parmValues;
  }

  public static String commaDelimitedList(Context context, Statement[] parts) {
    StringAppender appender = new StringAppender();
    for (int i = 0; i < parts.length; i++) {
      appender.append(parts[i].generate(context));
      if ((i + 1) < parts.length) appender.append(", ");
    }
    return appender.toString();
  }
View Full Code Here

TOP

Related Classes of org.mvel2.util.StringAppender

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.