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; }
protected static void printAndInterpretTemplateLines( Collection<String> templateLines, boolean forcePrintHitHeader, boolean newLineBetweenHits, NodeOrRelationship entity, GraphDatabaseShellServer server, Session session, Output out) throws ShellException, RemoteException { if (templateLines.isEmpty() || forcePrintHitHeader) { out.println(getDisplayName(server, session, entity, true)); } if (!templateLines.isEmpty()) { Map<String, Object> data = new HashMap<String, Object>(); data.put("i", entity.getId()); for (String command : templateLines) { String line = TextUtil.templateString(command, data); server.interpretLine(session.getId(), line, out); } } if (newLineBetweenHits) { out.println(); } }
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; }
/** * 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 void writeCurrentWorkingDir(List<TypedId> paths, Session session) throws RemoteException { session.set(WORKING_DIR_KEY, makePath(paths)); }
protected static void setCurrent(Session session, NodeOrRelationship current) { session.set(CURRENT_KEY, current.getTypedId().toString()); }
protected static void clearCurrent(Session session) { session.set(CURRENT_KEY, new TypedId(NodeOrRelationship.TYPE_NODE, 0).toString()); }
public static boolean isCurrent(Session session, NodeOrRelationship thing) { String currentThing = (String) session.get(CURRENT_KEY); return currentThing != null && currentThing.equals(thing.getTypedId().toString()); }