@Override public String readAttribute(HttpServerExchange exchange) { String val = attribute.readAttribute(exchange); if(val == null || val.isEmpty()) { return substitute; } return val; }
@Override public void beforeCommit(HttpServerExchange exchange) { try { attribute.writeAttribute(exchange, value.readAttribute(exchange)); } catch (ReadOnlyAttributeException e) { throw new RuntimeException(e); } } });
@Override public void writeAttribute(HttpServerExchange exchange, String newValue) throws ReadOnlyAttributeException { attribute.writeAttribute(exchange, newValue); } }
@Override public void writeAttribute(HttpServerExchange exchange, String newValue) throws ReadOnlyAttributeException { attribute.writeAttribute(exchange, newValue); } }
@Override public boolean resolve(final HttpServerExchange value) { final String att = attribute.readAttribute(value); if(att == null) { return false; } return !att.isEmpty(); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if(preCommit) { exchange.addResponseCommitListener(new ResponseCommitListener() { @Override public void beforeCommit(HttpServerExchange exchange) { try { attribute.writeAttribute(exchange, value.readAttribute(exchange)); } catch (ReadOnlyAttributeException e) { throw new RuntimeException(e); } } }); } else { attribute.writeAttribute(exchange, value.readAttribute(exchange)); } next.handleRequest(exchange); }
@Override public void writeAttribute(HttpServerExchange exchange, String newValue) throws ReadOnlyAttributeException { attribute.writeAttribute(exchange, newValue); } }
@Override public boolean resolve(final HttpServerExchange value) { String attr = attribute.readAttribute(value); if (attr == null) { return false; } for (int i = 0; i < values.length; ++i) { if (attr.contains(values[i])) { return true; } } return false; }
@Override public void beforeCommit(HttpServerExchange exchange) { try { attribute.writeAttribute(exchange, value.readAttribute(exchange)); } catch (ReadOnlyAttributeException e) { throw new RuntimeException(e); } } });
@Override public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException { RequestURLAttribute.INSTANCE.writeAttribute(exchange, newValue); }
@Override public boolean resolve(final HttpServerExchange value) { if(attributes.length < 2) { return true; } String first = attributes[0].readAttribute(value); for(int i = 1; i < attributes.length; ++i) { String current = attributes[i].readAttribute(value); if(first == null) { if(current != null) { return false; } } else if(current == null) { return false; } else if(!first.equals(current)) { return false; } } return true; }
@Override public void beforeCommit(HttpServerExchange exchange) { try { attribute.writeAttribute(exchange, value.readAttribute(exchange)); } catch (ReadOnlyAttributeException e) { throw new RuntimeException(e); } } });
@Override public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException { RelativePathAttribute.INSTANCE.writeAttribute(exchange, newValue); }
@Override public String readAttribute(HttpServerExchange exchange) { final StringBuilder sb = new StringBuilder(); for (int i = 0; i < attributes.length; ++i) { final String val = attributes[i].readAttribute(exchange); if(val != null) { sb.append(val); } } return sb.toString(); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if(preCommit) { exchange.addResponseCommitListener(new ResponseCommitListener() { @Override public void beforeCommit(HttpServerExchange exchange) { try { attribute.writeAttribute(exchange, value.readAttribute(exchange)); } catch (ReadOnlyAttributeException e) { throw new RuntimeException(e); } } }); } else { attribute.writeAttribute(exchange, value.readAttribute(exchange)); } next.handleRequest(exchange); }
public static String resolve(final HttpServerExchange exchange, final ExchangeAttribute[] attributes) { final StringBuilder result = new StringBuilder(); for (int i = 0; i < attributes.length; ++i) { final String str = attributes[i].readAttribute(exchange); if (str != null) { result.append(str); } } return result.toString(); }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if(preCommit) { exchange.addResponseCommitListener(new ResponseCommitListener() { @Override public void beforeCommit(HttpServerExchange exchange) { try { attribute.writeAttribute(exchange, value.readAttribute(exchange)); } catch (ReadOnlyAttributeException e) { throw new RuntimeException(e); } } }); } else { attribute.writeAttribute(exchange, value.readAttribute(exchange)); } next.handleRequest(exchange); }
@Override public String readAttribute(HttpServerExchange exchange) { String svalue = exchangeAttribute.readAttribute(exchange); // Does the value contain a " ? If so must encode it if (svalue == null || "-".equals(svalue) || svalue.isEmpty()) { return "-"; } /* Wrap all quotes in double quotes. */ StringBuilder buffer = new StringBuilder(svalue.length() + 2); buffer.append('\''); int i = 0; while (i < svalue.length()) { int j = svalue.indexOf('\'', i); if (j == -1) { buffer.append(svalue.substring(i)); i = svalue.length(); } else { buffer.append(svalue.substring(i, j + 1)); buffer.append('"'); i = j + 2; } } buffer.append('\''); return buffer.toString(); }
@Override public boolean resolve(final HttpServerExchange value) { String input = matchAttribute.readAttribute(value); if(input == null) { return false; } Matcher matcher = pattern.matcher(input); final boolean matches; if (requireFullMatch) { matches = matcher.matches(); } else { matches = matcher.find(); } if (matches) { Map<String, Object> context = value.getAttachment(PREDICATE_CONTEXT); if(context == null) { value.putAttachment(PREDICATE_CONTEXT, context = new TreeMap<>()); } int count = matcher.groupCount(); for (int i = 0; i <= count; ++i) { context.put(Integer.toString(i), matcher.group(i)); } } return matches; }
@Override public boolean resolve(final HttpServerExchange exchange) { final Map<String, String> params = new HashMap<>(); String path = attribute.readAttribute(exchange); if(path == null) { return false; } boolean result = this.value.matches(path, params); if (result) { Map<String, Object> context = exchange.getAttachment(PREDICATE_CONTEXT); if(context == null) { exchange.putAttachment(PREDICATE_CONTEXT, context = new TreeMap<>()); } context.putAll(params); } return result; }