/** * Parses a tag formatted as defined by the HTTP standard. * * @param httpTag * The HTTP tag string; if it starts with 'W/' the tag will be * marked as weak and the data following the 'W/' used as the * tag; otherwise it should be surrounded with quotes (e.g., * "sometag"). * @return A new tag instance. * @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.11">HTTP Entity Tags</a> */ public static Tag parse(final String httpTag) { Tag result = null; boolean weak = false; String httpTagCopy = httpTag; if (httpTagCopy.startsWith("W/")) { weak = true; httpTagCopy = httpTagCopy.substring(2); } if (httpTagCopy.startsWith("\"") && httpTagCopy.endsWith("\"")) { result = new Tag( httpTagCopy.substring(1, httpTagCopy.length() - 1), weak); } else if (httpTagCopy.equals("*")) { result = new Tag("*", weak); } else { Context.getCurrentLogger().log(Level.WARNING, "Invalid tag format detected: " + httpTagCopy); } return result; }
/** * Parses a tag formatted as defined by the HTTP standard. * * @param httpTag * The HTTP tag string; if it starts with 'W/' the tag will be * marked as weak and the data following the 'W/' used as the * tag; otherwise it should be surrounded with quotes (e.g., * "sometag"). * @return A new tag instance. * @see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.11">HTTP Entity Tags</a> */ public static Tag parse(String httpTag) { Tag result = null; boolean weak = false; String httpTagCopy = httpTag; if (httpTagCopy.startsWith("W/")) { weak = true; httpTagCopy = httpTagCopy.substring(2); } if (httpTagCopy.startsWith("\"") && httpTagCopy.endsWith("\"")) { result = new Tag( httpTagCopy.substring(1, httpTagCopy.length() - 1), weak); } else if (httpTagCopy.equals("*")) { result = new Tag("*", weak); } else { Context.getCurrentLogger().log(Level.WARNING, "Invalid tag format detected: " + httpTagCopy); } return result; }
/** * Converts a JAX-RS-EntityTag to a Restlet-EntityTag * * @param jaxRsEntityTag * the JAX-RS-EntityTag to convert. * @return The corresponding Restlet-Entity-Tag */ public static Tag toRestletTag(EntityTag jaxRsEntityTag) { if (jaxRsEntityTag == null) { return null; } return new Tag(jaxRsEntityTag.getValue(), jaxRsEntityTag.isWeak()); }
private Representation entityHeaders( Representation representation, EntityState entityState ) { representation.setModificationDate( java.util.Date.from( entityState.lastModified() ) ); representation.setTag( new Tag( "" + entityState.version() ) ); representation.setCharacterSet( CharacterSet.UTF_8 ); representation.setLanguages( Collections.singletonList( Language.ENGLISH ) ); return representation; }
@Get public Representation represent() { // Modification date (Fri, 17 Apr 2012 10:10:10 GMT) unchanged. Calendar cal = new GregorianCalendar(2012, 4, 17, 10, 10, 10); Representation result = new StringRepresentation("<a href=" + getReference() + ">" + System.currentTimeMillis() + "</a>"); result.setMediaType(MediaType.TEXT_HTML); result.setModificationDate(cal.getTime()); // Expiration date (Fri, 17 Apr 2012 13:10:10 GMT) unchanged. cal.roll(Calendar.HOUR, 3); result.setExpirationDate(cal.getTime()); // Setting E-Tag result.setTag(new Tag("xyz123")); // Setting a cache directive getResponse().getCacheDirectives().add(CacheDirective.publicInfo()); return result; }
void updateResponse( Response response ) { if( entity != null ) { EntityState state = spi.entityStateOf( entity ); Tag tag = new Tag( state.entityReference().identity() + "/" + state.version() ); response.getEntity().setModificationDate( java.util.Date.from( state.lastModified() ) ); response.getEntity().setTag( tag ); } }
void updateResponse( Response response ) { if( entity != null ) { EntityState state = spi.entityStateOf( entity ); Tag tag = new Tag( state.entityReference().identity() + "/" + state.version() ); response.getEntity().setModificationDate( java.util.Date.from( state.lastModified() ) ); response.getEntity().setTag( tag ); } }
public void updateResponse( Response response ) { if( entity != null ) { EntityState state = spi.entityStateOf( entity ); Date lastModified = new Date( state.lastModified() ); Tag tag = new Tag( state.identity().identity() + "/" + state.version() ); response.getEntity().setModificationDate( lastModified ); response.getEntity().setTag( tag ); } }
public StorageFileItemRepresentation(StorageFileItem file) { super(MediaType.valueOf(file.getMimeType()), file); setSize(file.getLength()); if (file.getRepositoryItemAttributes().containsKey(DigestCalculatingInspector.DIGEST_SHA1_KEY)) { // Shield SHA1 // {SHA1{xxxx}} final String tag = String.format("{SHA1{%s}}", file.getRepositoryItemAttributes().get(DigestCalculatingInspector.DIGEST_SHA1_KEY)); setTag(new Tag(tag, false)); } if (file.getItemContext().containsKey(AbstractResourceStoreContentPlexusResource.OVERRIDE_FILENAME_KEY)) { String filename = file.getItemContext().get(AbstractResourceStoreContentPlexusResource.OVERRIDE_FILENAME_KEY).toString(); setDownloadable(true); setDownloadName(filename); } }
public StorageFileItemRepresentation( StorageFileItem file ) { super( MediaType.valueOf( file.getMimeType() ), file ); setSize( file.getLength() ); if ( file.getRepositoryItemAttributes().containsKey( DigestCalculatingInspector.DIGEST_SHA1_KEY ) ) { // Shield SHA1 // {SHA1{xxxx}} final String tag = String.format( "{SHA1{%s}}", file.getRepositoryItemAttributes().get( DigestCalculatingInspector.DIGEST_SHA1_KEY ) ); setTag( new Tag( tag, false ) ); } if ( file.getItemContext().containsKey( AbstractResourceStoreContentPlexusResource.OVERRIDE_FILENAME_KEY ) ) { String filename = file.getItemContext().get( AbstractResourceStoreContentPlexusResource.OVERRIDE_FILENAME_KEY ).toString(); setDownloadable( true ); setDownloadName( filename ); } }