org.cactoos.text.Lowered Java Examples
The following examples show how to use
org.cactoos.text.Lowered.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HtHeaders.java From cactoos-http with MIT License | 6 votes |
/** * Ctor. * @param head Response head part */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public HtHeaders(final Input head) { super(() -> { final Map<String, List<String>> map = new HashMap<>(); final ListOf<Text> texts = new ListOf<>( new Split(new TextOf(head), "\r\n") ); for (final Text line : texts.subList(1, texts.size())) { final String[] parts = line.asString().split(":", 2); map.merge( new Lowered( new Trimmed(new TextOf(parts[0])), Locale.ENGLISH ).asString(), new ListOf<>( new Trimmed(new TextOf(parts[1])).asString() ), (first, second) -> new Joined<String>(first, second) ); } return map; }); }
Example #2
Source File: MediaTypes.java From takes with MIT License | 6 votes |
/** * Ctor. * @param text Text to parse * @return List of media types */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private static SortedSet<MediaType> parse(final String text) { final SortedSet<MediaType> list = new TreeSet<>(); final Iterable<Text> parts = new Split( new UncheckedText(new Lowered(text)), "," ); for (final Text part : parts) { final String name = new UncheckedText(part).asString(); if (!name.isEmpty()) { list.add(new MediaType(name)); } } return list; }
Example #3
Source File: RqWithoutHeader.java From takes with MIT License | 6 votes |
/** * Ctor. * @param req Original request * @param name Header name */ public RqWithoutHeader(final Request req, final CharSequence name) { super( // @checkstyle AnonInnerLengthCheck (50 lines) new RequestOf( () -> new Filtered<>( header -> new Not( new StartsWith( new Lowered(header), new FormattedText( "%s:", new Lowered(name.toString()) ) ) ).value(), req.head() ), req::body ) ); }
Example #4
Source File: ResponseOf.java From takes with MIT License | 6 votes |
/** * Apply header to servlet response. * @param sresp Response * @param header Header */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private static void applyHeader(final HttpServletResponse sresp, final String header) { final Iterator<Text> split = new Split(header, ":").iterator(); final UncheckedText name = new UncheckedText(new Trimmed(split.next())); final UncheckedText val = new UncheckedText(new Trimmed(split.next())); if (new Equality<Text>( new TextOf("set-cookie"), new Lowered(name) ).value() ) { for (final HttpCookie cck : HttpCookie.parse(header)) { sresp.addCookie( new Cookie(cck.getName(), cck.getValue()) ); } } else { sresp.setHeader(name.asString(), val.asString()); } }
Example #5
Source File: HttpServletResponseFake.java From takes with MIT License | 6 votes |
@Override public Collection<String> getHeaders(final String header) { final String prefix = String.format( "%s", new Lowered(header) ); try { return new Filtered<>( hdr -> new StartsWith( new Lowered(hdr), new TextOf(prefix) ).value(), this.response.get().head() ); } catch (final IOException ex) { throw new IllegalStateException(ex); } }
Example #6
Source File: ContactsSqlFiltered.java From cactoos-jdbc with MIT License | 6 votes |
/** * Ctor. * @param sssn A Session. * @param name Contact's name to be filtered. */ public ContactsSqlFiltered(final Session sssn, final String name) { this.session = sssn; this.ids = new ResultSetAsValues<>( new StatementSelect( sssn, new QuerySimple( new Joined( " ", "SELECT id FROM contact WHERE LOWER(name) LIKE", "'%' || :name || '%'" ), new ParamText("name", new Lowered(name)) ) ) ); }
Example #7
Source File: RsWithoutHeader.java From takes with MIT License | 6 votes |
/** * Ctor. * @param res Original response * @param name Header name */ public RsWithoutHeader(final Response res, final CharSequence name) { super( new ResponseOf( () -> new Filtered<>( header -> new Not( new StartsWith( new Lowered(header), new FormattedText( "%s:", new Lowered(name.toString()) ) ) ).value(), res.head() ), res::body ) ); }
Example #8
Source File: TkProxy.java From takes with MIT License | 5 votes |
/** * Creates the request to be forwarded to the target host. * * @param req Original request * @param dest Destination URL * @return Request to be forwarded * @throws Exception If some problem inside */ @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private com.jcabi.http.Request request(final Request req, final URI dest) throws Exception { final String method = new RqMethod.Base(req).method(); com.jcabi.http.Request proxied = new JdkRequest(dest).method(method); final RqHeaders headers = new RqHeaders.Base(req); for (final String name : headers.names()) { if ("content-length".equals( new UncheckedText( new Lowered(name) ).asString() )) { continue; } if (TkProxy.isHost(name)) { proxied = proxied.header(name, this.target); continue; } for (final String value : headers.header(name)) { proxied = proxied.header(name, value); } } if (headers.header("Content-Length").iterator().hasNext() || headers.header("Transfer-Encoding").iterator().hasNext()) { final ByteArrayOutputStream output = new ByteArrayOutputStream(); new RqPrint(new RqLengthAware(req)).printBody(output); proxied = proxied.body().set(output.toByteArray()).back(); } return proxied; }
Example #9
Source File: EqualityTest.java From takes with MIT License | 5 votes |
@Test public void mustEvaluateTrueEqualityOfTexts() { new Assertion<>( "Must evaluate true equality for Texts", new Equality<>( new Lowered(new TextOf("Hello")), new TextOf("hello") ), new ScalarHasValue<>(true) ).affirm(); }
Example #10
Source File: RqMtBase.java From takes with MIT License | 5 votes |
@Override public Iterable<Request> part(final CharSequence name) { final List<Request> values = this.map.getOrDefault( new UncheckedText( new Lowered(name.toString()) ).asString(), Collections.emptyList() ); final Iterable<Request> iter; if (values.isEmpty()) { iter = new VerboseIterable<>( Collections.emptyList(), new FormattedText( "there are no parts by name \"%s\" among %d others: %s", name, this.map.size(), this.map.keySet() ).toString() ); } else { iter = new VerboseIterable<>( values, new FormattedText( "there are just %d parts by name \"%s\"", values.size(), name ).toString() ); } return iter; }
Example #11
Source File: RqHeaders.java From takes with MIT License | 5 votes |
@Override public List<String> header(final CharSequence key) throws IOException { final List<String> values = this.map().getOrDefault( new UncheckedText( new Lowered(key.toString()) ).asString(), Collections.emptyList() ); final List<String> list; if (values.isEmpty()) { list = new VerboseList<>( Collections.emptyList(), String.format( // @checkstyle LineLengthCheck (1 line) "there are no headers by name \"%s\" among %d others: %s", key, this.map().size(), this.map().keySet() ) ); } else { list = new VerboseList<>( values, String.format( // @checkstyle LineLengthCheck (1 line) "there are only %d headers by name \"%s\"", values.size(), key ) ); } return list; }
Example #12
Source File: RqFormBase.java From takes with MIT License | 5 votes |
/** * Create map of request parameter. * @return Parameters map or empty map in case of error. * @throws IOException If something fails reading or parsing body */ private Map<String, List<String>> freshMap() throws IOException { final String body = new RqPrint(this.req).printBody(); final Map<String, List<String>> map = new HashMap<>(1); // @checkstyle MultipleStringLiteralsCheck (1 line) for (final String pair : body.split("&")) { if (pair.isEmpty()) { continue; } // @checkstyle MultipleStringLiteralsCheck (1 line) final String[] parts = pair.split("=", 2); if (parts.length < 2) { throw new HttpException( HttpURLConnection.HTTP_BAD_REQUEST, String.format( "invalid form body pair: %s", pair ) ); } final String key = RqFormBase.decode(new Lowered(parts[0])); if (!map.containsKey(key)) { map.put(key, new LinkedList<>()); } map.get(key).add( RqFormBase.decode( new Trimmed(new TextOf(parts[1])) ) ); } return map; }
Example #13
Source File: RqFormBase.java From takes with MIT License | 5 votes |
@Override public Iterable<String> param(final CharSequence key) throws IOException { final List<String> values = this.map().getOrDefault( new UncheckedText( new Lowered(key.toString()) ).asString(), Collections.emptyList() ); final Iterable<String> iter; if (values.isEmpty()) { iter = new VerboseIterable<>( Collections.emptyList(), new FormattedText( "there are no params \"%s\" among %d others: %s", key, this.map().size(), this.map().keySet() ).asString() ); } else { iter = new VerboseIterable<>( values, new FormattedText( "there are only %d params by name \"%s\"", values.size(), key ).asString() ); } return iter; }
Example #14
Source File: TkProxy.java From takes with MIT License | 5 votes |
/** * Checks whether the provided argument is a "Host" header name. * @param header Header name * @return Returns {@code true} if {@code header} parameter is a "Host" * header name, {@code false} otherwise */ private static boolean isHost(final String header) { return "host".equals( new UncheckedText( new Lowered(header) ).asString() ); }
Example #15
Source File: RqCookies.java From takes with MIT License | 5 votes |
@Override public Iterable<String> cookie(final CharSequence key) throws IOException { final Map<String, String> map = this.map(); final String value = map.getOrDefault( new UncheckedText( new Lowered(key.toString()) ).asString(), "" ); final Iterable<String> iter; if (value.isEmpty()) { iter = new VerboseIterable<>( Collections.<String>emptyList(), new FormattedText( // @checkstyle LineLengthCheck (1 line) "There are no Cookies by name \"%s\" among %d others: %s", key, map.size(), map.keySet() ).asString() ); } else { iter = new VerboseIterable<>( Collections.singleton(value), new FormattedText( "There is always only one Cookie by name \"%s\"", key ).asString() ); } return iter; }
Example #16
Source File: FkHost.java From takes with MIT License | 5 votes |
/** * Make fork. * @param host Host * @param take Take to use * @return Fork */ private static Fork fork(final String host, final Take take) { return req -> { final String hst = new RqHeaders.Smart( new RqHeaders.Base(req) ).single("host"); return new Ternary<Opt<Response>>( new EqualsNullable( new Lowered(host), new Lowered(hst) ), new Opt.Single<>(take.act(req)), new Opt.Empty<>() ).value(); }; }
Example #17
Source File: FkEncoding.java From takes with MIT License | 5 votes |
@Override public Opt<Response> route(final Request req) throws IOException { final Iterator<String> headers = new RqHeaders.Base(req).header("Accept-Encoding").iterator(); final Opt<Response> resp; if (this.encoding.isEmpty()) { resp = new Opt.Single<>(this.origin); } else if (headers.hasNext()) { final Collection<String> items = Arrays.asList( FkEncoding.ENCODING_SEP.split( new UncheckedText( new Lowered( new Trimmed( new TextOf(headers.next()) ) ) ).asString() ) ); if (items.contains(this.encoding)) { resp = new Opt.Single<>(this.origin); } else { resp = new Opt.Empty<>(); } } else { resp = new Opt.Empty<>(); } return resp; }
Example #18
Source File: FkEncoding.java From takes with MIT License | 5 votes |
/** * Ctor. * @param enc Encoding we accept * @param response Response to return */ public FkEncoding(final String enc, final Response response) { this.encoding = new UncheckedText( new Lowered(new Trimmed(new TextOf(enc))) ).asString(); this.origin = response; }
Example #19
Source File: MediaType.java From takes with MIT License | 5 votes |
/** * Returns the media type sectors. * @param text The media type text. * @return String array with the sectors of the media type. */ private static String[] sectors(final String text) { return new UncheckedText( new Lowered(MediaType.split(text)[0]) ).asString() .split( "/", 2 ); }
Example #20
Source File: CactoosStringUtils.java From tutorials with MIT License | 4 votes |
public String toLowerCase(String testString) throws IOException { String lowerCaseString = new Lowered(new TextOf(testString)).asString(); return lowerCaseString; }