Search in sources :

Example 11 with Asset

use of com.google.cloud.asset.v1.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 com.google.cloud.asset.v1.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 com.google.cloud.asset.v1.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 com.google.cloud.asset.v1.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)

Example 15 with Asset

use of com.google.cloud.asset.v1.Asset in project gapic-generator-java by googleapis.

the class AssetServiceClientTest method listAssetsTest.

@Test
public void listAssetsTest() throws Exception {
    Asset responsesElement = Asset.newBuilder().build();
    ListAssetsResponse expectedResponse = ListAssetsResponse.newBuilder().setNextPageToken("").addAllAssets(Arrays.asList(responsesElement)).build();
    mockAssetService.addResponse(expectedResponse);
    ResourceName parent = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
    ListAssetsPagedResponse pagedListResponse = client.listAssets(parent);
    List<Asset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getAssetsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockAssetService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListAssetsRequest actualRequest = ((ListAssetsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ResourceName(com.google.api.resourcenames.ResourceName) ListAssetsPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse) Test(org.junit.Test)

Aggregations

Asset (org.apache.tapestry5.Asset)19 Resource (org.apache.tapestry5.commons.Resource)8 Test (org.testng.annotations.Test)7 AssetFactory (org.apache.tapestry5.services.AssetFactory)6 AssetSource (org.apache.tapestry5.services.AssetSource)6 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)5 ContentType (com.google.cloud.asset.v1.ContentType)4 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)4 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)3 ComponentResources (org.apache.tapestry5.ComponentResources)3 Path (org.apache.tapestry5.annotations.Path)3 Test (org.junit.Test)3 Asset (com.google.cloud.asset.v1.Asset)2 ListAssetsPagedResponse (com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse)2 ListAssetsRequest (com.google.cloud.asset.v1.ListAssetsRequest)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ArrayList (java.util.ArrayList)2 ResourceName (com.google.api.resourcenames.ResourceName)1 BatchGetAssetsHistoryRequest (com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest)1 BatchGetAssetsHistoryResponse (com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse)1