Ejemplo n.º 1
0
 protected String[] escapePaths(String srcPath, String dstPath) {
   srcPath = srcPath.trim();
   dstPath = dstPath.trim();
   String os = System.getProperty("os.name").toLowerCase();
   if (os != null && os.indexOf("windows") > -1) {
     srcPath = "\"" + srcPath + "\"";
     dstPath = "\"" + dstPath + "\"";
   } else {
     int lastidx = -1, curridx;
     StringBuffer buff = new StringBuffer(srcPath);
     while ((curridx = buff.indexOf(" ", lastidx)) > 0) {
       buff.insert(curridx, "\\");
       lastidx = curridx + 2;
     }
     srcPath = buff.toString();
     buff = new StringBuffer(dstPath);
     lastidx = -1;
     while ((curridx = buff.indexOf(" ", lastidx)) > 0) {
       buff.insert(curridx, "\\");
       lastidx = curridx + 2;
     }
     dstPath = buff.toString();
   }
   return new String[] {srcPath, dstPath};
 }
Ejemplo n.º 2
0
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(getClass().getName());
   sb.append('@');
   sb.append(Integer.toHexString(System.identityHashCode(this)));
   sb.append(" (context=");
   sb.append(_context);
   sb.append(", static_permitions=");
   sb.append(_statisPermissions);
   sb.append(')');
   return sb.toString();
 }
Ejemplo n.º 3
0
  static {
    try {

      String jaggeryDir = System.getProperty("jaggery.home");
      if (jaggeryDir == null) {
        jaggeryDir = System.getProperty("carbon.home");
      }

      if (jaggeryDir == null) {
        log.error("Unable to find jaggery.home or carbon.home system properties");
      }

      String modulesDir = jaggeryDir + File.separator + JAGGERY_MODULES_DIR;

      CommonManager.getInstance()
          .initialize(
              modulesDir,
              new RhinoSecurityController() {
                @Override
                protected void updatePermissions(
                    PermissionCollection permissions, RhinoSecurityDomain securityDomain) {
                  JaggerySecurityDomain domain = (JaggerySecurityDomain) securityDomain;
                  ServletContext context = domain.getServletContext();
                  String docBase = context.getRealPath("/");
                  // Create a file read permission for web app context directory
                  if (!docBase.endsWith(File.separator)) {
                    permissions.add(new FilePermission(docBase, "read"));
                    docBase = docBase + File.separator;
                  } else {
                    permissions.add(
                        new FilePermission(docBase.substring(0, docBase.length() - 1), "read"));
                  }
                  docBase = docBase + "-";
                  permissions.add(new FilePermission(docBase, "read"));
                }
              });
    } catch (ScriptException e) {
      log.error(e.getMessage(), e);
    }
  }
Ejemplo n.º 4
0
  @Nullable
  private static String lintIt(Context context, String fileName, ScriptableObject scope)
      throws IOException {
    if (Boolean.valueOf(System.getProperty("test.lint.skip"))) {
      return null;
    }

    Object[] args = {FileUtil.loadFile(new File(fileName), true), JSHINT_OPTIONS};
    Function function = (Function) ScriptableObject.getProperty(scope.getParentScope(), "JSHINT");
    Object status = function.call(context, scope.getParentScope(), scope.getParentScope(), args);
    if (!(Boolean) Context.jsToJava(status, Boolean.class)) {
      Object errors = function.get("errors", scope);
      StringBuilder sb = new StringBuilder(fileName);
      for (Object errorObj : ((NativeArray) errors)) {
        if (errorObj == null) {
          continue;
        }

        NativeObject e = (NativeObject) errorObj;
        int line = toInt(e.get("line"));
        int character = toInt(e.get("character"));
        if (line < 0 || character < 0) {
          continue;
        }
        Object reasonObj = e.get("reason");
        if (reasonObj instanceof String) {
          String reason = (String) reasonObj;
          if (IGNORED_JSHINT_WARNINGS.contains(reason)
              || reason.startsWith("Expected exactly one space between ')' and ")
              || reason.startsWith("Expected '}' to match '{' from line ")
              || reason.startsWith("Expected '{' and instead saw ")) {
            continue;
          }

          sb.append('\n').append(line).append(':').append(character).append(' ').append(reason);
        }
      }

      return sb.length() == fileName.length() ? null : sb.toString();
    }

    return null;
  }
Ejemplo n.º 5
0
 private URL getUrlObj(String url) {
   URL urlObj;
   try {
     urlObj = new URL(url);
   } catch (MalformedURLException ex) {
     // Assume as Main.processFileSecure it is file, need to build its
     // URL
     String curDir = System.getProperty("user.dir");
     curDir = curDir.replace('\\', '/');
     if (!curDir.endsWith("/")) {
       curDir = curDir + '/';
     }
     try {
       URL curDirURL = new URL("file:" + curDir);
       urlObj = new URL(curDirURL, url);
     } catch (MalformedURLException ex2) {
       throw new RuntimeException(
           "Can not construct file URL for '" + url + "':" + ex2.getMessage());
     }
   }
   return urlObj;
 }
Ejemplo n.º 6
0
  /** Returns an array of the property names on the given script object. */
  private Object[] getObjectIdsImpl(Context cx, Object object) {
    if (!(object instanceof Scriptable) || object == Undefined.instance) {
      return Context.emptyArgs;
    }

    Object[] ids;
    Scriptable scriptable = (Scriptable) object;
    if (scriptable instanceof DebuggableObject) {
      ids = ((DebuggableObject) scriptable).getAllIds();
    } else {
      ids = scriptable.getIds();
    }

    Scriptable proto = scriptable.getPrototype();
    Scriptable parent = scriptable.getParentScope();
    int extra = 0;
    if (proto != null) {
      ++extra;
    }
    if (parent != null) {
      ++extra;
    }
    if (extra != 0) {
      Object[] tmp = new Object[extra + ids.length];
      System.arraycopy(ids, 0, tmp, extra, ids.length);
      ids = tmp;
      extra = 0;
      if (proto != null) {
        ids[extra++] = "__proto__";
      }
      if (parent != null) {
        ids[extra++] = "__parent__";
      }
    }

    return ids;
  }