예제 #1
0
 private static String trimLength(Session session, String string) {
   String maxLengthString = (String) session.get(AbstractClient.TITLE_MAX_LENGTH);
   int maxLength = maxLengthString != null ? Integer.parseInt(maxLengthString) : Integer.MAX_VALUE;
   if (string.length() > maxLength) {
     string = string.substring(0, maxLength) + "...";
   }
   return string;
 }
예제 #2
0
파일: Env.java 프로젝트: Analect/neo4j
 public Continuation execute(AppCommandParser parser, Session session, Output out)
     throws Exception {
   for (String key : session.keys()) {
     Object value = session.get(key);
     out.println(key + "=" + (value == null ? "" : value));
   }
   return Continuation.INPUT_COMPLETE;
 }
예제 #3
0
 /**
  * Reads the session variable specified in {@link #WORKING_DIR_KEY} and returns it as a list of
  * typed ids.
  *
  * @param session the session to read from.
  * @return the working directory as a list.
  * @throws RemoteException if an RMI error occurs.
  */
 public static List<TypedId> readCurrentWorkingDir(Session session) throws RemoteException {
   List<TypedId> list = new ArrayList<TypedId>();
   String path = (String) session.get(WORKING_DIR_KEY);
   if (path != null && path.trim().length() > 0) {
     for (String typedId : path.split(",")) {
       list.add(new TypedId(typedId));
     }
   }
   return list;
 }
예제 #4
0
 /**
  * @param server the {@link GraphDatabaseShellServer} to get the current node/relationship from.
  * @param session the {@link Session} used by the client.
  * @return the current node/relationship the client stands on at the moment.
  * @throws ShellException if some error occured.
  */
 public static NodeOrRelationship getCurrent(GraphDatabaseShellServer server, Session session)
     throws ShellException {
   String currentThing = (String) session.get(CURRENT_KEY);
   NodeOrRelationship result = null;
   if (currentThing == null) {
     try {
       result = NodeOrRelationship.wrap(server.getDb().getReferenceNode());
     } catch (NotFoundException e) {
       throw new ShellException("Reference node not found");
     }
     setCurrent(session, result);
   } else {
     TypedId typedId = new TypedId(currentThing);
     result = getThingById(server, typedId);
   }
   return result;
 }
예제 #5
0
  protected static String findTitle(GraphDatabaseShellServer server, Session session, Node node) {
    String keys = (String) session.get(AbstractClient.TITLE_KEYS_KEY);
    if (keys == null) {
      return null;
    }

    String[] titleKeys = keys.split(Pattern.quote(","));
    Pattern[] patterns = new Pattern[titleKeys.length];
    for (int i = 0; i < titleKeys.length; i++) {
      patterns[i] = Pattern.compile(titleKeys[i]);
    }
    for (Pattern pattern : patterns) {
      for (String nodeKey : node.getPropertyKeys()) {
        if (matches(pattern, nodeKey, false, false)) {
          return trimLength(session, format(node.getProperty(nodeKey), false));
        }
      }
    }
    return null;
  }
예제 #6
0
 public static boolean isCurrent(Session session, NodeOrRelationship thing) {
   String currentThing = (String) session.get(CURRENT_KEY);
   return currentThing != null && currentThing.equals(thing.getTypedId().toString());
 }