/** * Constructor. Uses a byte buffer of a given size. * * @param source * The source representation. * @param bufferSize * The byte buffer to use. * @throws IOException */ public CharacterReadingListener(Representation source, int bufferSize) throws IOException { super(source, bufferSize); this.characterSet = source.getCharacterSet(); }
/** * Constructor. Uses a byte buffer of a given size. * * @param source * The source representation. * @param bufferSize * The byte buffer to use. * @throws IOException */ public CharacterReadingListener(Representation source, int bufferSize) throws IOException { super(source, bufferSize); this.characterSet = source.getCharacterSet(); }
/** * Constructor. * * @param representation * The representation. */ public ContentType(Representation representation) { this(representation.getMediaType(), representation.getCharacterSet()); }
/** * Constructor.<br> * In case the representation does not define a character set, the UTF-8 * character set is used. * * @param representation * The web form content. * @throws IOException * if the stream of the representation could not be opened. */ public FormReader(Representation representation) throws IOException { this.decoding = true; this.stream = representation.getStream(); this.separator = '&'; if (representation.getCharacterSet() != null) { this.characterSet = representation.getCharacterSet(); } else { this.characterSet = CharacterSet.UTF_8; } }
/** * Constructor.<br> * In case the representation does not define a character set, the UTF-8 * character set is used. * * @param representation * The web form content. * @param decode * Indicates if the parameters should be decoded using the given * character set. * @throws IOException * if the stream of the representation could not be opened. */ public FormReader(Representation representation, boolean decode) throws IOException { this.decode = decode; this.stream = representation.getStream(); this.separator = '&'; if (representation.getCharacterSet() != null) { this.characterSet = representation.getCharacterSet(); } else { this.characterSet = CharacterSet.UTF_8; } }
/** * Constructor.<br> * In case the representation does not define a character set, the UTF-8 * character set is used. * * @param representation * The web form content. * @param decode * Indicates if the parameters should be decoded using the given * character set. * @throws IOException * if the stream of the representation could not be opened. */ public FormReader(Representation representation, boolean decode) throws IOException { this.decode = decode; this.stream = representation.getStream(); this.separator = '&'; if (representation.getCharacterSet() != null) { this.characterSet = representation.getCharacterSet(); } else { this.characterSet = CharacterSet.UTF_8; } }
@Override public CharacterSet getCharacterSet() { return getWrappedRepresentation().getCharacterSet(); }
/** * Writes the HTTP "Content-Type" header. * * @param representation * The related representation. * @return The HTTP "Content-Type" header. */ public static String writeHeader(Representation representation) { return writeHeader(representation.getMediaType(), representation.getCharacterSet()); }
/** * @return the character set of the current entity, or null, if no entity or * no character set is available. */ private CharacterSet getCurrentRequestEntityCharacterSet() { Representation entity = Request.getCurrent().getEntity(); if (entity == null) return null; return entity.getCharacterSet(); }
/** * @return the character set of the current entity, or null, if no entity or * no character set is available. */ private CharacterSet getCurrentRequestEntityCharacterSet() { Representation entity = Request.getCurrent().getEntity(); if (entity == null) return null; return entity.getCharacterSet(); }
/** * Constructor. * * @param xmlRepresentation * A source XML representation to parse. * @throws IOException */ public SaxRepresentation(Representation xmlRepresentation) { super((xmlRepresentation == null) ? null : xmlRepresentation .getMediaType()); try { if (xmlRepresentation instanceof XmlRepresentation) { this.source = new InputSource(xmlRepresentation.getStream()); } else { this.source = new InputSource(xmlRepresentation.getStream()); } if (xmlRepresentation.getCharacterSet()!= null) { this.source.setEncoding(xmlRepresentation.getCharacterSet().getName()); } if (xmlRepresentation.getLocationRef() != null) { this.source.setSystemId(xmlRepresentation.getLocationRef() .getTargetRef().toString()); } } catch (IOException ioe) { ioe.printStackTrace(); } }
/** * @see MessageBodyWriter#writeTo(Object, Type, Annotation[], MediaType, * MultivaluedMap, OutputStream) */ @Override public void writeTo(Reader reader, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { CharacterSet cs = Response.getCurrent().getEntity().getCharacterSet(); IoUtils.copy(reader, IoUtils.getWriter(entityStream, cs)); } }
/** * Get the media type of the request entity * * @return the media type or null if there is no request entity. * @throws java.lang.IllegalStateException * if called outside the scope of a request * @see HttpHeaders#getMediaType() */ public MediaType getMediaType() { if (this.mediaType == null) { org.restlet.data.MediaType rmt = request.getEntity().getMediaType(); CharacterSet rCharSet = request.getEntity().getCharacterSet(); this.mediaType = Converter.toJaxRsMediaType(rmt, rCharSet); } return this.mediaType; }
/** * Returns a Reader wrapping the given entity stream, with respect to the * {@link CharacterSet} of the entity of the current {@link Request}, or * UTF-8 if no character set was given or if it is not available */ static Reader getReader(InputStream entityStream) { final Representation entity = Request.getCurrent().getEntity(); CharacterSet cs; if (entity != null) { cs = entity.getCharacterSet(); if (cs == null) { cs = Util.JAX_RS_DEFAULT_CHARACTER_SET; } } else { cs = Util.JAX_RS_DEFAULT_CHARACTER_SET; } try { return IoUtils.getReader(entityStream, cs); } catch (UnsupportedEncodingException e) { try { return IoUtils.getReader(entityStream, null); } catch (UnsupportedEncodingException e2) { throw new WebApplicationException(500); } } }
/** * Returns a FreeMarker template from a representation and a configuration. * * @param config * The FreeMarker configuration. * @param templateRepresentation * The template representation. * @return The template or null if not found. */ public static Template getTemplate(Configuration config, Representation templateRepresentation) { try { // Instantiate the template with the character set of the template // representation if it has been set, otherwise use UTF-8. if (templateRepresentation.getCharacterSet() != null) { return new Template("template", templateRepresentation.getReader(), config, templateRepresentation.getCharacterSet().getName()); } return new Template("template", templateRepresentation.getReader(), config, CharacterSet.UTF_8.getName()); } catch (IOException e) { Context.getCurrentLogger().warning( "Unable to get the template from the representation " + templateRepresentation.getLocationRef() + ". Error message: " + e.getMessage()); return null; } }
/** * @return the character set of the current entity, or null, if no entity or * no character set is available. */ private String getCurrentResponseEntityCharset() { String result = null; Response rsp = Response.getCurrent(); if (rsp == null) { Context.getCurrentLogger().warning( "Unable to find the current response"); } else { Representation entity = Response.getCurrent().getEntity(); if (entity == null) return null; CharacterSet characterSet = entity.getCharacterSet(); if (characterSet == null) return null; result = characterSet.toString(); } return result; }
/** * Constructor based on a Velocity 'encoded' representation. * * @param templateRepresentation * The representation to 'decode'. * @param mediaType * The representation's media type. * @throws IOException * @throws ParseErrorException * @throws ResourceNotFoundException */ public TemplateRepresentation(Representation templateRepresentation, MediaType mediaType) throws ResourceNotFoundException, ParseErrorException, IOException { super(mediaType); this.engine = null; this.template = new Template(); CharacterSet charSet = (templateRepresentation.getCharacterSet() != null) ? templateRepresentation .getCharacterSet() : CharacterSet.DEFAULT; this.template.setEncoding(charSet.getName()); this.template.setLastModified((templateRepresentation .getModificationDate() == null) ? new Date().getTime() : templateRepresentation.getModificationDate().getTime()); this.template.setName("org.restlet.resource.representation"); this.template.setRuntimeServices(RuntimeSingleton.getRuntimeServices()); this.template.setResourceLoader(new RepresentationResourceLoader( templateRepresentation)); this.template.process(); this.templateName = null; }
.getCharacterSet()); resultRepresentation .setMediaType(representation.getMediaType());
this.template = new Template(); CharacterSet charSet = (templateRepresentation.getCharacterSet() != null) ? templateRepresentation .getCharacterSet() : CharacterSet.DEFAULT; this.template.setEncoding(charSet.getName());
try { return mbr.readFrom(this.convToCl, this.convToGen, this.annotations, mediaType, entity.getCharacterSet(), httpHeaders, entity.getStream()); } catch (WebApplicationException wae) {