//
Response.Status status = (Response.Status)response;
//
final AssetService assetPlugin = (AssetService)bridge.getApplication().getPlugin("asset");
//
Stream stream = new Stream() {
/** . */
private Charset charset = Tools.ISO_8859_1;
/** . */
private String mimeType = null;
/** . */
private Stream dataStream = null;
/** . */
private final LinkedList<String> assets = new LinkedList<String>();
public void provide(Chunk chunk) {
if (chunk instanceof Chunk.Property) {
Chunk.Property<?> property = (Chunk.Property<?>)chunk;
if (property.type == PropertyType.ENCODING) {
charset = (Charset)property.value;
} else if (property.type == PropertyType.MIME_TYPE) {
mimeType = (String)property.value;
} else if (property.type == PropertyType.HEADER) {
Map.Entry<String, String[]> header = (Map.Entry<String, String[]>)property.value;
for (String value : header.getValue()) {
resp.addProperty(header.getKey(), value);
}
} if (property.type == PropertyType.TITLE) {
if (resp instanceof RenderResponse) {
((RenderResponse)resp).setTitle((String)property.value);
}
} else if (property.type == PropertyType.META_TAG) {
Map.Entry<String, String> metaTag = (Map.Entry<String, String>)property.value;
Element elt = resp.createElement("meta");
elt.setAttribute("name", metaTag.getKey());
elt.setAttribute("content", metaTag.getValue());
resp.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, elt);
} else if (property.type == PropertyType.ASSET) {
assets.add(((String)property.value));
} else if (property.type == PropertyType.HEADER_TAG) {
Element headerTag = (Element)property.value;
Element responseTag = resp.createElement(headerTag.getTagName());
for (Node child : Tools.children(headerTag)) {
child = responseTag.getOwnerDocument().importNode(headerTag, true);
responseTag.appendChild(child);
}
resp.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, headerTag);
}
} else if (chunk instanceof Chunk.Data) {
Chunk.Data data = (Chunk.Data)chunk;
if (dataStream == null) {
Iterable<Asset> resolvedAssets = assetPlugin.getAssetManager().resolveAssets(assets);
for (Asset resolvedAsset : resolvedAssets) {
Element elt;
if (resolvedAsset.isStylesheet()) {
int pos = resolvedAsset.getURI().lastIndexOf('.');
String ext = pos == -1 ? "css" : resolvedAsset.getURI().substring(pos + 1);