01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import static java.lang.String.format;
18: import static org.apache.tapestry.ioc.internal.util.Defense.notNull;
19:
20: import org.apache.tapestry.Asset;
21: import org.apache.tapestry.PageRenderSupport;
22: import org.apache.tapestry.ioc.internal.util.IdAllocator;
23: import org.apache.tapestry.ioc.services.SymbolSource;
24: import org.apache.tapestry.services.AssetSource;
25:
26: public class PageRenderSupportImpl implements PageRenderSupport {
27: private final IdAllocator _idAllocator = new IdAllocator();
28:
29: private final DocumentScriptBuilder _builder;
30:
31: private final SymbolSource _symbolSource;
32:
33: private final AssetSource _assetSource;
34:
35: public PageRenderSupportImpl(DocumentScriptBuilder builder,
36: SymbolSource symbolSource, AssetSource assetSource) {
37: _builder = builder;
38: _symbolSource = symbolSource;
39: _assetSource = assetSource;
40: }
41:
42: public String allocateClientId(String id) {
43: return _idAllocator.allocateId(id);
44: }
45:
46: public void addScriptLink(Asset... scriptAssets) {
47: for (Asset asset : scriptAssets) {
48: notNull(asset, "scriptAsset");
49:
50: _builder.addScriptLink(asset.toClientURL());
51: }
52: }
53:
54: public void addClasspathScriptLink(String... classpaths) {
55: for (String path : classpaths) {
56: String expanded = _symbolSource.expandSymbols(path);
57:
58: Asset asset = _assetSource.findAsset(null, expanded, null);
59:
60: _builder.addScriptLink(asset.toClientURL());
61: }
62: }
63:
64: public void addScript(String format, Object... arguments) {
65: String script = format(format, arguments);
66:
67: _builder.addScript(script);
68: }
69:
70: }
|