public class CacheControlDelegate implements RuntimeDelegate.HeaderDelegate<CacheControl>
{
public CacheControl fromString(String value) throws IllegalArgumentException
{
if (value == null) throw new IllegalArgumentException("Cache-Control value is null");
ExtendedCacheControl result = new ExtendedCacheControl();
result.setNoTransform(false);
String[] directives = value.split(",");
for (String directive : directives)
{
directive = directive.trim();
String[] nv = directive.split("=");
String name = nv[0].trim();
String val = null;
if (nv.length > 1)
{
val = nv[1].trim();
if (val.startsWith("\"")) val = val.substring(1);
if (val.endsWith("\"")) val = val.substring(0, val.length() - 1);
}
String lowercase = name.toLowerCase();
if ("no-cache".equals(lowercase))
{
result.setNoCache(true);
if (val != null && !"".equals(val))
{
result.getNoCacheFields().add(val);
}
}
else if ("private".equals(lowercase))
{
result.setPrivate(true);
if (val != null && !"".equals(val))
{
result.getPrivateFields().add(val);
}
}
else if ("no-store".equals(lowercase))
{
result.setNoStore(true);
}
else if ("max-age".equals(lowercase))
{
if (val == null)
throw new IllegalArgumentException("CacheControl max-age header does not have a value: " + value);
result.setMaxAge(Integer.valueOf(val));
}
else if ("s-maxage".equals(lowercase))
{
if (val == null)
throw new IllegalArgumentException("CacheControl s-maxage header does not have a value: " + value);
result.setSMaxAge(Integer.valueOf(val));
}
else if ("no-transform".equals(lowercase))
{
result.setNoTransform(true);
}
else if ("must-revalidate".equals(lowercase))
{
result.setMustRevalidate(true);
}
else if ("proxy-revalidate".equals(lowercase))
{
result.setProxyRevalidate(true);
}
else if ("public".equals(lowercase))
{
result.setPublic(true);
}
else
{
if (val == null) val = "";
result.getCacheExtension().put(name, val);
}
}
return result;
}