/** * Constructor. * * @param wrappedRepresentation * The wrapped representation. */ public DecodeRepresentation(Representation wrappedRepresentation) { super(wrappedRepresentation); this.decoding = getSupportedEncodings().containsAll( wrappedRepresentation.getEncodings()); this.wrappedEncodings = new CopyOnWriteArrayList<Encoding>( wrappedRepresentation.getEncodings()); }
private Object getEncodingsAsString(Representation entity) { if (entity != null && !entity.getEncodings().isEmpty()) { final StringBuilder value = new StringBuilder(); for (int i = 0; i < entity.getEncodings().size(); i++) { if (i > 0) { value.append(", "); } value.append(entity.getEncodings().get(i).getName()); } return value.toString(); } return null; } }
@Override public List<Encoding> getEncodings() { return getWrappedRepresentation().getEncodings(); }
/** * Indicates if a representation can be decoded. * * @param representation * The representation to test. * @return True if the call can be decoded. */ public boolean canDecode(Representation representation) { // Test the existence of the representation and that at least an // encoding applies. boolean result = (representation != null) && (!representation.getEncodings().isEmpty()); if (result) { boolean found = false; for (final Iterator<Encoding> iter = representation.getEncodings() .iterator(); !found && iter.hasNext();) { found = (!iter.next().equals(Encoding.IDENTITY)); } result = found; } return result; }
/** * Decodes a given representation if its encodings are supported by NRE. * * @param representation * The representation to encode. * @return The decoded representation or the original one if the encoding * isn't supported by NRE. */ public Representation decode(Representation representation) { Representation result = representation; // Check if all encodings of the representation are supported in order // to avoid the creation of a useless decodeRepresentation object. // False if an encoding is not supported boolean supported = true; // True if all representation's encodings are IDENTITY boolean identityEncodings = true; for (final Iterator<Encoding> iter = representation.getEncodings() .iterator(); supported && iter.hasNext();) { final Encoding encoding = iter.next(); supported = DecodeRepresentation.getSupportedEncodings().contains( encoding); identityEncodings &= encoding.equals(Encoding.IDENTITY); } if (supported && !identityEncodings) { result = new DecodeRepresentation(representation); } return result; }
this.encodings.addAll(getWrappedRepresentation().getEncodings()); if (canEncode()) { this.encodings.add(this.encoding);
&& !representation.getEncodings().isEmpty() && !var.getEncodings().containsAll(representation.getEncodings())) { return false;
boolean identity = true; for (Iterator<Encoding> iter = representation.getEncodings() .iterator(); identity && iter.hasNext();) { identity = (iter.next().equals(Encoding.IDENTITY));
@Override protected void afterHandle(Request request, Response response) { if (response.isEntityAvailable() && response.getEntity().getEncodings() .contains(Encoding.FREEMARKER)) { TemplateRepresentation representation = new TemplateRepresentation( response.getEntity(), this.configuration, response .getEntity().getMediaType()); representation.setDataModel(createDataModel(request, response)); response.setEntity(representation); } }
.setMediaType(representation.getMediaType()); resultRepresentation .setEncodings(representation.getEncodings()); resultRepresentation .setLanguages(representation.getLanguages());
.getCharacterSet()); resultRepresentation.setMediaType(source.getMediaType()); resultRepresentation.getEncodings().addAll( source.getEncodings()); resultRepresentation.getLanguages().addAll( source.getLanguages());
/** * Transforms a source XML representation by applying an XSLT transform * sheet to it. * * @param source * The source XML representation. * @return The generated result representation. */ public Representation transform(Representation source) { final Representation result = new TransformRepresentation(getContext(), source, getTransformSheet()); if (this.resultLanguages != null) { result.getLanguages().addAll(getResultLanguages()); } result.setCharacterSet(getResultCharacterSet()); if (this.resultEncodings != null) { result.getEncodings().addAll(getResultEncodings()); } result.setMediaType(getResultMediaType()); return result; }
/** * Transforms a source XML representation by applying an XSLT transform * sheet to it. * * @param source * The source XML representation. * @return The generated result representation. */ public Representation transform(Representation source) { final Representation result = new TransformRepresentation(getContext(), source, getTransformSheet()); if (this.resultLanguages != null) { result.getLanguages().addAll(getResultLanguages()); } result.setCharacterSet(getResultCharacterSet()); if (this.resultEncodings != null) { result.getEncodings().addAll(getResultEncodings()); } result.setMediaType(getResultMediaType()); return result; }
for (Encoding encoding : request.getEntity().getEncodings()) { updateFileExtension(fileName, encoding);
if (result.getEncodings().isEmpty()) { result.getEncodings().addAll(target.getEncodings());
@Override protected void afterHandle(Request request, Response response) { if (response.isEntityAvailable() && response.getEntity().getEncodings().contains(THYMELEAF)) { try { final TemplateRepresentation representation = new TemplateRepresentation( (TemplateRepresentation) response.getEntity(), getLocale(), response.getEntity().getMediaType()); if ((this.mapDataModel == null) && (this.resolverDataModel == null)) { representation.setDataModel(request, response); } else { if (this.mapDataModel == null) { representation.setDataModel(this.resolverDataModel); } else { representation.setDataModel(this.mapDataModel); } } response.setEntity(representation); } catch (IOException e) { response.setStatus(Status.SERVER_ERROR_INTERNAL, e); } } }
@Override protected void afterHandle(Request request, Response response) { if (response.isEntityAvailable() && response.getEntity().getEncodings().contains( Encoding.VELOCITY)) { try {
HeaderConstants.HEADER_CONTENT_ENCODING)) { new EncodingReader(header.getValue()).addValues(result .getEncodings()); } else if (header.getName().equalsIgnoreCase( HeaderConstants.HEADER_CONTENT_LANGUAGE)) {
entityHeaderFound = true; } else if (HEADER_CONTENT_ENCODING.equalsIgnoreCase(header.getName())) { new EncodingReader(header.getValue()).addValues(result.getEncodings()); entityHeaderFound = true; } else if (HEADER_CONTENT_LANGUAGE.equalsIgnoreCase(header.getName())) {
addHeader(HEADER_CONTENT_ENCODING, EncodingWriter.write(entity.getEncodings()), headers); addHeader(HEADER_CONTENT_LANGUAGE, LanguageWriter.write(entity.getLanguages()), headers);