コード例 #1
0
ファイル: Cd.java プロジェクト: eldersantos/community
 @Override
 public List<String> completionCandidates(String partOfLine, Session session) {
   String lastWord = TextUtil.lastWordOrQuoteOf(partOfLine, false);
   if (lastWord.startsWith("-")) {
     return super.completionCandidates(partOfLine, session);
   }
   try {
     TreeSet<String> result = new TreeSet<String>();
     NodeOrRelationship current = getCurrent(session);
     if (current.isNode()) {
       // TODO Check if -r is supplied
       Node node = current.asNode();
       for (Node otherNode : RelationshipToNodeIterable.wrap(node.getRelationships(), node)) {
         long otherNodeId = otherNode.getId();
         String title = findTitle(getServer(), session, otherNode);
         if (title != null) {
           if (!result.contains(title)) {
             maybeAddCompletionCandidate(result, title + "," + otherNodeId, lastWord);
           }
         }
         maybeAddCompletionCandidate(result, "" + otherNodeId, lastWord);
       }
     } else {
       maybeAddCompletionCandidate(result, START_ALIAS, lastWord);
       maybeAddCompletionCandidate(result, END_ALIAS, lastWord);
       Relationship rel = current.asRelationship();
       maybeAddCompletionCandidate(result, "" + rel.getStartNode().getId(), lastWord);
       maybeAddCompletionCandidate(result, "" + rel.getEndNode().getId(), lastWord);
     }
     return new ArrayList<String>(result);
   } catch (ShellException e) {
     e.printStackTrace();
     return super.completionCandidates(partOfLine, session);
   }
 }
コード例 #2
0
ファイル: RemoteClient.java プロジェクト: jakewins/community
 private ShellServer findRemoteServer() throws ShellException {
   try {
     ShellServer result = (ShellServer) this.serverLocation.getBoundObject();
     updateTimeForMostRecentConnection();
     return result;
   } catch (RemoteException e) {
     throw ShellException.wrapCause(e);
   }
 }
コード例 #3
0
ファイル: Trav.java プロジェクト: jakewins/neo4j
 private Evaluator parseEvaluator(String evaluator) throws ShellException {
   scripting = scripting != null ? scripting : new ScriptEngineViaReflection(getServer());
   try {
     evaluator = decorateWithImports(evaluator, STANDARD_EVAL_IMPORTS);
     Object scriptEngine = scripting.getJavascriptEngine();
     Object compiledScript = scripting.compile(scriptEngine, evaluator);
     return new CompiledScriptEvaluator(compiledScript);
   } catch (Exception e) {
     throw ShellException.wrapCause(e);
   }
 }
コード例 #4
0
  public int complete(String buffer, int cursor, List candidates) {
    if (buffer == null || buffer.length() == 0) {
      return cursor;
    }

    try {
      if (buffer.contains(" ")) {
        TabCompletion completion = client.getServer().tabComplete(buffer.trim(), client.session());
        cursor = completion.getCursor();
        candidates.addAll(completion.getCandidates());
      } else {
        // Complete the app name
        return getAppNameCompletor().complete(buffer, cursor, candidates);
      }
    } catch (RemoteException e) {
      // TODO Throw something?
      e.printStackTrace();
    } catch (ShellException e) {
      // TODO Throw something?
      e.printStackTrace();
    }
    return cursor;
  }
コード例 #5
0
  protected void setProperties(PropertyContainer entity, String propertyJson)
      throws ShellException {
    if (propertyJson == null) {
      return;
    }

    try {
      Map<String, Object> properties = parseJSONMap(propertyJson);
      for (Map.Entry<String, Object> entry : properties.entrySet()) {
        entity.setProperty(entry.getKey(), entry.getValue());
      }
    } catch (JSONException e) {
      throw ShellException.wrapCause(e);
    }
  }
コード例 #6
0
ファイル: AbstractApp.java プロジェクト: nkhoang/neo4j
  protected static Map<String, Object> parseFilter(String filterString, Output out)
      throws RemoteException, ShellException {
    if (filterString == null) {
      return new HashMap<String, Object>();
    }

    Map<String, Object> map = null;
    String signsOfJSON = ":";
    int numberOfSigns = 0;
    for (int i = 0; i < signsOfJSON.length(); i++) {
      if (filterString.contains(String.valueOf(signsOfJSON.charAt(i)))) {
        numberOfSigns++;
      }
    }

    if (numberOfSigns >= 1) {
      String jsonString = filterString;
      if (!jsonString.startsWith("{")) {
        jsonString = "{" + jsonString;
      }
      if (!jsonString.endsWith("}")) {
        jsonString += "}";
      }
      try {
        map = parseJSONMap(jsonString);
      } catch (JSONException e) {
        out.println(
            "parser: \""
                + filterString
                + "\" hasn't got "
                + "correct JSON formatting: "
                + e.getMessage());
        throw ShellException.wrapCause(e);
      }
    } else {
      map = new HashMap<String, Object>();
      map.put(filterString, null);
    }
    return map;
  }