Search in sources :

Example 11 with Asset

use of org.apache.tapestry5.Asset in project tapestry-5 by apache.

the class ExternalUrlAssetFactory method createAsset.

@Override
public Asset createAsset(Resource resource) {
    final URL url = resource.toURL();
    Asset asset = cache.get(url);
    if (asset == null) {
        asset = new UrlAsset(url.toExternalForm(), resource);
        cache.put(url, asset);
    }
    return asset;
}
Also used : Asset(org.apache.tapestry5.Asset) URL(java.net.URL)

Example 12 with Asset

use of org.apache.tapestry5.Asset in project tapestry-5 by apache.

the class JavaScriptStackPathConstructorImpl method constructPathsForJavaScriptStack.

public List<String> constructPathsForJavaScriptStack(String stackName) {
    JavaScriptStack stack = javascriptStackSource.getStack(stackName);
    List<Asset> assets = stack.getJavaScriptLibraries();
    // if there is more than one library asset, or any modules.
    if (combineScripts && stack.getJavaScriptAggregationStrategy().enablesCombine()) {
        boolean needsVirtual = (assets.size() > 1) || (!stack.getModules().isEmpty());
        if (needsVirtual) {
            return combinedStackURL(stackName, stack);
        }
    }
    return toPaths(assets);
}
Also used : Asset(org.apache.tapestry5.Asset) JavaScriptStack(org.apache.tapestry5.services.javascript.JavaScriptStack)

Example 13 with Asset

use of org.apache.tapestry5.Asset in project tapestry-5 by apache.

the class CSSURLRewriter method replaceURLs.

/**
 * Replaces any relative URLs in the content for the resource and returns the content with
 * the URLs expanded.
 *
 * @param input
 *         content of the resource
 * @param baseResource
 *         resource used to resolve relative URLs
 * @return replacement content, or null if no relative URLs in the content
 */
private String replaceURLs(String input, Resource baseResource) {
    boolean didReplace = false;
    StringBuffer output = new StringBuffer(input.length());
    Matcher matcher = urlPattern.matcher(input);
    while (matcher.find()) {
        // the string inside the quotes
        String url = matcher.group(2);
        // When the URL starts with a slash or a scheme (e.g. http: or data:) , there's no need
        // to rewrite it (this is actually rare in Tapestry as you want to use relative URLs to
        // leverage the asset pipeline.
        Matcher completeURLMatcher = completeURLPattern.matcher(url);
        boolean matchFound = completeURLMatcher.find();
        boolean isAssetUrl = matchFound && "asset:".equals(completeURLMatcher.group(1));
        if (matchFound && !isAssetUrl) {
            String queryParameters = matcher.group(3);
            if (queryParameters != null) {
                url = url + queryParameters;
            }
            // This may normalize single quotes, or missing quotes, to double quotes, but is not
            // considered a real change, since all such variations are valid.
            appendReplacement(matcher, output, url);
            continue;
        }
        if (isAssetUrl) {
            // strip away the "asset:" prefix
            url = url.substring(6);
        }
        Asset asset;
        // TAP5-2656
        try {
            asset = assetSource.getAsset(baseResource, url, null);
        } catch (AssetNotFoundException e) {
            asset = null;
        }
        if (asset != null) {
            String assetURL = asset.toClientURL();
            String queryParameters = matcher.group(3);
            if (queryParameters != null) {
                assetURL += queryParameters;
            }
            appendReplacement(matcher, output, assetURL);
            didReplace = true;
        } else {
            final String message = String.format("URL %s, referenced in file %s, doesn't exist.", url, baseResource.toURL(), baseResource);
            if (strictCssUrlRewriting) {
                throw new RuntimeException(message);
            } else if (logger.isWarnEnabled()) {
                logger.warn(message);
            }
        }
    }
    if (!didReplace) {
        return null;
    }
    matcher.appendTail(output);
    return output.toString();
}
Also used : Matcher(java.util.regex.Matcher) Asset(org.apache.tapestry5.Asset) AssetNotFoundException(org.apache.tapestry5.services.AssetNotFoundException)

Example 14 with Asset

use of org.apache.tapestry5.Asset in project tapestry-5 by apache.

the class ClasspathAssetRequestHandler method handleAssetRequest.

public boolean handleAssetRequest(Request request, Response response, String extraPath) throws IOException {
    ChecksumPath path = new ChecksumPath(streamer, baseFolder, extraPath);
    final boolean handled;
    if (classpathAssetProtectionRule.block(path.resourcePath) && !path.resourcePath.equals(ChecksumPath.NON_EXISTING_RESOURCE)) {
        if (LOGGER.isWarnEnabled()) {
            LOGGER.warn("Blocked request for classpath asset '" + path.resourcePath + "'. Contribute a new ClasspathAssetProtectionRule if you need this asset to be publicly accessible.");
        }
        handled = false;
    } else {
        Resource resource = assetSource.resourceForPath(path.resourcePath);
        handled = path.stream(resource);
    }
    return handled;
}
Also used : Resource(org.apache.tapestry5.commons.Resource)

Example 15 with Asset

use of org.apache.tapestry5.Asset in project gapic-generator-java by googleapis.

the class AsyncListAssets method asyncListAssets.

public static void asyncListAssets() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()).setReadTime(Timestamp.newBuilder().build()).addAllAssetTypes(new ArrayList<String>()).setContentType(ContentType.forNumber(0)).setPageSize(883849137).setPageToken("pageToken873572522").addAllRelationshipTypes(new ArrayList<String>()).build();
        ApiFuture<Asset> future = assetServiceClient.listAssetsPagedCallable().futureCall(request);
        // Do something.
        for (Asset element : future.get().iterateAll()) {
        // doThingsWith(element);
        }
    }
}
Also used : ListAssetsRequest(com.google.cloud.asset.v1.ListAssetsRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ArrayList(java.util.ArrayList) Asset(com.google.cloud.asset.v1.Asset)

Aggregations

Asset (org.apache.tapestry5.Asset)19 Resource (org.apache.tapestry5.commons.Resource)10 Test (org.testng.annotations.Test)9 AssetFactory (org.apache.tapestry5.services.AssetFactory)8 AssetSource (org.apache.tapestry5.services.AssetSource)8 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)6 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)5 ComponentResources (org.apache.tapestry5.ComponentResources)3 Path (org.apache.tapestry5.annotations.Path)3 Asset (com.google.cloud.asset.v1.Asset)2 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)2 ListAssetsRequest (com.google.cloud.asset.v1.ListAssetsRequest)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 ListAssetsResponse (com.google.cloud.asset.v1.ListAssetsResponse)1 OutputStream (java.io.OutputStream)1 SoftReference (java.lang.ref.SoftReference)1 URL (java.net.URL)1 DateFormat (java.text.DateFormat)1