/** * Create a new {@link ReaderResource} using values in this builder. * * @return A new immutable {@link ReaderResource} object. * @throws IOException */ public ReaderResource build() throws IOException { return new ReaderResource(this); } }
/** * Returns the contents of this resource. * * @return The contents of this resource. */ public Reader getContents() { if (contents.length == 1 && contents[0] instanceof Reader) { return (Reader)contents[0]; } return new StringReader(toString()); } }
@Override /* Object */ public String toString() { try { if (contents.length == 1) return read(contents[0]); return writeTo(new StringWriter()).toString(); } catch (IOException e) { throw new RuntimeException(e); } }
@RestMethod public ReaderResource a05() throws Exception { return ReaderResource.create().contents(new ByteArrayInputStream("foo".getBytes())).build(); }
@Override /* Parameter */ public String resolve(VarResolverSession session, String key) throws Exception { RestRequest req = session.getSessionObject(RestRequest.class, SESSION_req, false); if (req != null) { ReaderResource rr = req.getClasspathReaderResource(key); return (rr == null ? null : rr.toCommentStrippedString()); } ClasspathResourceManager crm = session.getSessionObject(ClasspathResourceManager.class, SESSION_crm, false); if (crm != null) return crm.getString(key); return null; } }
@RestMethod public ReaderResource a06() throws Exception { return ReaderResource.create().contents(new StringReader("foo")).build(); }
@Override /* Parameter */ public String resolve(VarResolverSession session, String key) throws Exception { RestRequest req = session.getSessionObject(RestRequest.class, SESSION_req, false); if (req != null) { ReaderResource rr = req.getClasspathReaderResource(key); return (rr == null ? null : rr.toCommentStrippedString()); } ClasspathResourceManager crm = session.getSessionObject(ClasspathResourceManager.class, SESSION_crm, false); if (crm != null) return crm.getString(key); return null; } }
@RestMethod public ReaderResource a07() throws Exception { return ReaderResource.create().contents(new StringBuilder("foo")).build(); } }
/** * Returns the contents of this resource. * * @return The contents of this resource. */ public Reader getContents() { if (contents.length == 1 && contents[0] instanceof Reader) { return (Reader)contents[0]; } return new StringReader(toString()); } }
@Override /* Object */ public String toString() { try { if (contents.length == 1) return read(contents[0]); return writeTo(new StringWriter()).toString(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Create a new {@link ReaderResource} using values in this builder. * * @return A new immutable {@link ReaderResource} object. * @throws IOException */ public ReaderResource build() throws IOException { return new ReaderResource(this); } }
@Override /* Parameter */ public String resolve(VarResolverSession session, String key) throws Exception { RestRequest req = session.getSessionObject(RestRequest.class, SESSION_req, false); if (req != null) { ReaderResource rr = req.getClasspathReaderResource(key); return (rr == null ? null : rr.toCommentStrippedString()); } ClasspathResourceManager crm = session.getSessionObject(ClasspathResourceManager.class, SESSION_crm, false); if (crm != null) return crm.getString(key); return null; } }
@RestMethod public ReaderResource a02() throws Exception { return ReaderResource.create().header("Foo", "Bar").build(); }
/** * Returns the contents of this resource. * * @return The contents of this resource. */ public Reader getContents() { if (contents.length == 1 && contents[0] instanceof Reader) { return (Reader)contents[0]; } return new StringReader(toString()); } }
@Override /* Object */ public String toString() { try { if (contents.length == 1) return read(contents[0]); return writeTo(new StringWriter()).toString(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Create a new {@link ReaderResource} using values in this builder. * * @return A new immutable {@link ReaderResource} object. * @throws IOException */ public ReaderResource build() throws IOException { return new ReaderResource(this); } }
@RestMethod public ReaderResource a01() throws Exception { return ReaderResource.create().contents("foo").build(); }
/** * Same as {@link #toString()} but strips comments from the text before returning it. * * <p> * Supports stripping comments from the following media types: HTML, XHTML, XML, JSON, Javascript, CSS. * * @return The resource contents stripped of any comments. */ public String toCommentStrippedString() { String s = toString(); String subType = mediaType.getSubType(); if ("html".equals(subType) || "xhtml".equals(subType) || "xml".equals(subType)) s = s.replaceAll("(?s)<!--(.*?)-->\\s*", ""); else if ("json".equals(subType) || "javascript".equals(subType) || "css".equals(subType)) s = s.replaceAll("(?s)\\/\\*(.*?)\\*\\/\\s*", ""); return s; }
@RestMethod public ReaderResource a03() throws Exception { return ReaderResource.create().mediaType(MediaType.JSON).build(); }
/** * Same as {@link #toString()} but strips comments from the text before returning it. * * <p> * Supports stripping comments from the following media types: HTML, XHTML, XML, JSON, Javascript, CSS. * * @return The resource contents stripped of any comments. */ public String toCommentStrippedString() { String s = toString(); String subType = mediaType.getSubType(); if ("html".equals(subType) || "xhtml".equals(subType) || "xml".equals(subType)) s = s.replaceAll("(?s)<!--(.*?)-->\\s*", ""); else if ("json".equals(subType) || "javascript".equals(subType) || "css".equals(subType)) s = s.replaceAll("(?s)\\/\\*(.*?)\\*\\/\\s*", ""); return s; }