int process(CharSequence org, int index, char begin, char end, StringBuilder result, Link link) { StringBuilder line = new StringBuilder(org); int nesting = 1; StringBuilder variable = new StringBuilder(); outer: while (index < line.length()) { char c1 = line.charAt(index++); if (c1 == end) { if (--nesting == 0) { result.append(replace(variable.toString(), link)); return index; } } else if (c1 == begin) nesting++; else if (c1 == '\\' && index < line.length() - 1 && line.charAt(index) == '$') { // remove the escape backslash and interpret the dollar // as a // literal index++; variable.append('$'); continue outer; } else if (c1 == '$' && index < line.length() - 2) { char c2 = line.charAt(index); char terminator = getTerminator(c2); if (terminator != 0) { index = process(line, index + 1, c2, terminator, variable, link); continue outer; } } else if (c1 == '.' && index < line.length() && line.charAt(index) == '/') { // Found the sequence ./ if (index == 1 || Character.isWhitespace(line.charAt(index - 2))) { // make sure it is preceded by whitespace or starts at begin index++; variable.append(domain.getBase().getAbsolutePath()); variable.append('/'); continue outer; } } variable.append(c1); } result.append(variable); return index; }
private boolean checkHandlerWorkaround( String elementName, String handlerName, boolean writeHandler) throws ClickException, IOException { // If talking to an old ControlSocket, try the "handlers" handler // instead. String s = readString(elementName, "handlers"); int pos = 0; // Find handler with same name. while (true) { pos = s.indexOf(handlerName, pos); if (pos < 0) // no such handler return false; if ((pos == 0 || s.charAt(pos - 1) == '\n') && Character.isWhitespace(s.charAt(pos + handlerName.length()))) break; pos++; } // we have a matching handler: will it be read/write suitable? char wantType = (writeHandler ? 'w' : 'r'); for (pos += handlerName.length(); pos < s.length() && Character.isWhitespace(s.charAt(pos)); pos++) /* nada */ ; for (; pos < s.length(); pos++) { char c = s.charAt(pos); if (Character.toLowerCase(c) == wantType) return true; else if (Character.isWhitespace(c)) break; } return false; }
/** * Gets the information about an element's handlers in the current router configuration. * * @param el The element name. * @return Vector of HandlerInfo structures. * @exception NoSuchElementException If there is no such element in the current configuration. * @exception HandlerErrorException If the handler returned an error. * @exception PermissionDeniedException If the router would not let us access the handler. * @exception IOException If there was some other error accessing the handler (e.g., there was a * stream or socket error, the ControlSocket returned an unknwon unknown error code, or the * response could otherwise not be understood). * @see #HandlerInfo * @see #getConfigElementNames * @see #getRouterConfig * @see #getRouterFlatConfig */ public Vector getElementHandlers(String elementName) throws ClickException, IOException { Vector v = new Vector(); Vector vh; try { char[] buf = read(elementName, "handlers"); vh = StringUtils.split(buf, 0, '\n'); } catch (ClickException.NoSuchHandlerException e) { return v; } for (int i = 0; i < vh.size(); i++) { String s = (String) vh.elementAt(i); int j; for (j = 0; j < s.length() && !Character.isWhitespace(s.charAt(j)); j++) ; // find record split if (j == s.length()) throw new ClickException.HandlerFormatException(elementName + ".handlers"); HandlerInfo hi = new HandlerInfo(elementName, s.substring(0, j).trim()); while (j < s.length() && Character.isWhitespace(s.charAt(j))) j++; for (; j < s.length(); j++) { char c = s.charAt(j); if (Character.toLowerCase(c) == 'r') hi.canRead = true; else if (Character.toLowerCase(c) == 'w') hi.canWrite = true; else if (Character.isWhitespace(c)) break; } v.addElement(hi); } return v; }