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; }
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; }
/** * 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; }
/** * @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; }
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; }
public static boolean isCurrent(Session session, NodeOrRelationship thing) { String currentThing = (String) session.get(CURRENT_KEY); return currentThing != null && currentThing.equals(thing.getTypedId().toString()); }