当前位置: 首页>>代码示例>>Java>>正文


Java ResourceReference类代码示例

本文整理汇总了Java中org.jtwig.resource.reference.ResourceReference的典型用法代码示例。如果您正苦于以下问题:Java ResourceReference类的具体用法?Java ResourceReference怎么用?Java ResourceReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ResourceReference类属于org.jtwig.resource.reference包,在下文中一共展示了ResourceReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
@Override
public Node get(JtwigParser parser, Environment environment, ResourceReference resource) {
    Optional<Future<Result>> optional = Optional.fromNullable(cache.get(resource));
    if (optional.isPresent()) {
        return retriever.apply(optional.get()).get();
    } else {
        SettableFuture<Result> future = SettableFuture.create();
        Future<Result> result = cache.putIfAbsent(resource, future);
        if (result == null) {
            try {
                Node node = parser.parse(environment, resource);
                future.set(new Result(Optional.of(node), Optional.<RuntimeException>absent()));
                return node;
            } catch (RuntimeException e) {
                cache.remove(resource);
                future.set(new Result(Optional.<Node>absent(), Optional.of(e)));
                throw e;
            }
        } else {
            return retriever.apply(result).get();
        }
    }
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:24,代码来源:InMemoryConcurrentPersistentTemplateCache.java

示例2: resolve

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
public ResourceReference resolve(ResourceReference current, String path) {
    ResourceReference resourceReference = resourceReferenceExtractor.extract(path);

    if (absoluteResourceTypes.contains(current.getType()) || absoluteResourceTypes.contains(resourceReference.getType())) {
        return resourceReference;
    } else {
        if (ResourceReference.ANY_TYPE.equals(resourceReference.getType()) || resourceReference.getType().equals(current.getType())) {
            for (RelativeResourceResolver resourceResolver : relativeResourceResolvers) {
                Optional<ResourceReference> referenceOptional = resourceResolver.resolve(current, resourceReference);
                if (referenceOptional.isPresent()) return referenceOptional.get();
            }
        }
    }

    return resourceReference;
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:17,代码来源:ResourceService.java

示例3: loadMetadata

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
public ResourceMetadata loadMetadata(ResourceReference reference) {
    ResourceLoader result;
    if (ResourceReference.ANY_TYPE.equals(reference.getType())) {
        Optional<ResourceLoader> resourceLoader = getFirstExistingResourceLoader(reference);
        if (!resourceLoader.isPresent())
            return EmptyResourceMetadata.instance();
        else
            result = resourceLoader.get();
    } else {
        Optional<ResourceLoader> loaderOptional = Optional.fromNullable(loaderMap.get(reference.getType()));
        if (!loaderOptional.isPresent()) {
            throw new ResourceException(String.format("Cannot load resource %s. Resource loader for type '%s' not configured", reference, reference.getType()));
        } else {
            result = loaderOptional.get();
        }
    }
    return new ResourceResourceMetadata(result, reference);
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:19,代码来源:ResourceService.java

示例4: render

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
public Object render(PropertyResolveRequest request, List<Object> arguments, Macro macro) {
    Map<String, Object> valueMap = new HashMap<>();
    Iterator<Object> valueIterator = arguments.iterator();

    for (String variableName : macro.getArgumentNames()) {
        if (valueIterator.hasNext()) {
            valueMap.put(variableName, valueIterator.next());
        }
    }

    ValueContext valueContext = MapValueContext.newContext(valueMap);
    request.getRenderContext().start(ValueContext.class, valueContext);
    request.getRenderContext().start(ResourceReference.class, macro.getResourceReference());
    RenderResult renderResult = new StringBuilderRenderResult();

    request.getEnvironment().getRenderEnvironment().getRenderNodeService()
            .render(request, macro.getContent())
            .appendTo(renderResult);


    request.getRenderContext().end(ValueContext.class);
    request.getRenderContext().end(ResourceReference.class);

    return renderResult.content();

}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:27,代码来源:MacroRender.java

示例5: render

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
public void render (RenderRequest request, ResourceReference resourceReference, String macroIdentifier) {
    Node content = request.getEnvironment().getParser().parse(request.getEnvironment(), resourceReference);

    ArrayList<MacroNode> macroNodes = new ArrayList<>();
    content.visit(new CollectMacroNodes(macroNodes));
    Map<String, Macro> macros = new HashMap<>();

    for (MacroNode macroNode : macroNodes) {
        macros.put(macroNode.getMacroName().getIdentifier(), new Macro(
                resourceReference,
                macroNode.getContent(),
                macroNode.getMacroArgumentNames()
        ));
    }

    request.getRenderContext().getCurrent(ValueContext.class)
            .with(macroIdentifier, new ImportedMacros(macros));
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:19,代码来源:ImportRender.java

示例6: render

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
@Override
public Renderable render(RenderRequest renderRequest, ImportNode node) {
    Environment environment = renderRequest.getEnvironment();
    CalculateExpressionService calculateExpressionService = environment.getRenderEnvironment().getCalculateExpressionService();
    ResourceService resourceService = environment.getResourceEnvironment().getResourceService();

    String macroIdentifier = node.getAliasIdentifier().getIdentifier();

    Object objectPath = calculateExpressionService.calculate(renderRequest, node.getImportExpression());
    String path = environment.getValueEnvironment().getStringConverter().convert(objectPath);
    ResourceReference current = renderRequest.getRenderContext().getCurrent(ResourceReference.class);
    ResourceReference newReference = resourceService.resolve(current, path);
    ResourceMetadata resourceMetadata = resourceService.loadMetadata(newReference);

    if (resourceMetadata.exists()) {
        importRender.render(renderRequest, newReference, macroIdentifier);
    } else {
        throw new ResourceNotFoundException(ErrorMessageFormatter.errorMessage(node.getPosition(), String.format("Resource '%s' not found", path)));
    }

    return EmptyRenderable.instance();
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:23,代码来源:ImportNodeRender.java

示例7: render

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
@Override
public Renderable render(RenderRequest renderRequest, ExtendsNode node) {
    Environment environment = renderRequest.getEnvironment();
    CalculateExpressionService calculateExpressionService = renderRequest.getEnvironment().getRenderEnvironment().getCalculateExpressionService();
    RenderNodeService renderNodeService = renderRequest.getEnvironment().getRenderEnvironment().getRenderNodeService();
    RenderResourceService renderResourceService = renderRequest.getEnvironment().getRenderEnvironment().getRenderResourceService();
    ResourceService resourceService = renderRequest.getEnvironment().getResourceEnvironment().getResourceService();

    Expression extendsExpression = node.getExtendsExpression();
    Object path = calculateExpressionService.calculate(renderRequest, extendsExpression);
    ResourceReference current = renderRequest.getRenderContext().getCurrent(ResourceReference.class);

    ResourceReference newReference = resourceService.resolve(current, path, environment.getValueEnvironment());
    ResourceMetadata resourceMetadata = resourceService.loadMetadata(newReference);

    if (!resourceMetadata.exists()) {
        throw new ResourceNotFoundException(errorMessage(node.getPosition(), String.format("Resource '%s' not found", environment.getValueEnvironment().getStringConverter().convert(path))));
    } else {
        for (Node subNode : node.getNodes()) {
            renderNodeService.render(renderRequest, subNode);
        }

        return renderResourceService.render(renderRequest, new RenderResourceRequest(newReference, false, false, WrappedCollection.empty()));
    }
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:26,代码来源:ExtendsNodeRender.java

示例8: expressionRule

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
@Test
public void expressionRule() throws Exception {
    DefaultJtwigParserConfiguration config = new DefaultJtwigParserConfiguration();
    ParserContext context = ParserContext.instance(
            ResourceReference.inline("Hello"),
            config,
            config.getAddonParserProviders(),
            config.getUnaryOperators(),
            config.getBinaryOperators(),
            config.getTestExpressionParsers()
    );

    MapSelectionExpressionParser parser = context.parser(MapSelectionExpressionParser.class);

    TracingParseRunner<Expression> runner = new TracingParseRunner<>(parser.ExpressionRule());
    ParsingResult<Expression> result = runner.run("list[position.size]");
    Expression resultValue = result.resultValue;

    System.out.println(resultValue);
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:21,代码来源:MapSelectionExpressionParserTest.java

示例9: resolvePathRelative

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
@Test
public void resolvePathRelative() throws Exception {
    String newPath = "path";
    String parentPath = "parentPath";
    String resolved = "resolved";
    ResourceReference parentReference = mock(ResourceReference.class);
    ResourceReference newReference = mock(ResourceReference.class);

    types.add("blah");
    when(newReference.getPath()).thenReturn(newPath);
    when(parentReference.getType()).thenReturn("blah");
    when(parentReference.getPath()).thenReturn(parentPath);
    when(pathResolver.isRelative(newPath)).thenReturn(true);
    when(pathResolver.resolve(parentPath, newPath)).thenReturn(resolved);

    Optional<ResourceReference> result = underTest.resolve(parentReference, newReference);

    assertThat(result.get().getPath(), is(resolved));
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:20,代码来源:ReferenceRelativeResourceResolverTest.java

示例10: resolveSameTypeNonAbsolute

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
@Test
public void resolveSameTypeNonAbsolute() throws Exception {
    ResourceReference expected = mock(ResourceReference.class);
    ResourceReference source = mock(ResourceReference.class);
    ResourceReference reference = mock(ResourceReference.class);
    RelativeResourceResolver relativeResourceResolver = mock(RelativeResourceResolver.class);

    relativeResourceResolvers.add(relativeResourceResolver);
    when(source.getType()).thenReturn("blah");
    when(reference.getType()).thenReturn("blah");
    when(resourceReferenceExtractor.extract("path")).thenReturn(reference);
    when(relativeResourceResolver.resolve(source, reference)).thenReturn(Optional.of(expected));

    ResourceReference result = underTest.resolve(source, "path");

    assertSame(expected, result);
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:18,代码来源:ResourceServiceTest.java

示例11: resolveAnyTargetNonAbsolute

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
@Test
public void resolveAnyTargetNonAbsolute() throws Exception {
    ResourceReference expected = mock(ResourceReference.class);
    ResourceReference source = mock(ResourceReference.class);
    ResourceReference reference = mock(ResourceReference.class);
    RelativeResourceResolver relativeResourceResolver = mock(RelativeResourceResolver.class);

    relativeResourceResolvers.add(relativeResourceResolver);
    when(source.getType()).thenReturn("blah");
    when(reference.getType()).thenReturn("any");
    when(resourceReferenceExtractor.extract("path")).thenReturn(reference);
    when(relativeResourceResolver.resolve(source, reference)).thenReturn(Optional.of(expected));

    ResourceReference result = underTest.resolve(source, "path");

    assertSame(expected, result);
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:18,代码来源:ResourceServiceTest.java

示例12: resolveSameTypeNonAbsoluteNotFound

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
@Test
public void resolveSameTypeNonAbsoluteNotFound() throws Exception {
    ResourceReference expected = mock(ResourceReference.class);
    ResourceReference source = mock(ResourceReference.class);
    ResourceReference reference = mock(ResourceReference.class);
    RelativeResourceResolver relativeResourceResolver = mock(RelativeResourceResolver.class);

    relativeResourceResolvers.add(relativeResourceResolver);
    when(source.getType()).thenReturn("blah");
    when(reference.getType()).thenReturn("blah");
    when(resourceReferenceExtractor.extract("path")).thenReturn(reference);
    when(relativeResourceResolver.resolve(source, reference)).thenReturn(Optional.<ResourceReference>absent());

    ResourceReference result = underTest.resolve(source, "path");

    assertSame(reference, result);
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:18,代码来源:ResourceServiceTest.java

示例13: resolveRelativeSourceAnyTarget

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
@Test
public void resolveRelativeSourceAnyTarget() throws Exception {
    ResourceReference expected = mock(ResourceReference.class);
    ResourceReference source = mock(ResourceReference.class);
    ResourceReference reference = mock(ResourceReference.class);
    RelativeResourceResolver relativeResourceResolver = mock(RelativeResourceResolver.class);

    relativeResourceResolvers.add(relativeResourceResolver);
    when(source.getType()).thenReturn("blah");
    when(reference.getType()).thenReturn("any");
    when(resourceReferenceExtractor.extract("path")).thenReturn(reference);
    when(relativeResourceResolver.resolve(source, reference)).thenReturn(Optional.<ResourceReference>absent());

    ResourceReference result = underTest.resolve(source, "path");

    assertSame(reference, result);
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:18,代码来源:ResourceServiceTest.java

示例14: resolveRelativeDistinctTypes

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
@Test
public void resolveRelativeDistinctTypes() throws Exception {
    ResourceReference expected = mock(ResourceReference.class);
    ResourceReference source = mock(ResourceReference.class);
    ResourceReference reference = mock(ResourceReference.class);
    RelativeResourceResolver relativeResourceResolver = mock(RelativeResourceResolver.class);

    relativeResourceResolvers.add(relativeResourceResolver);
    when(source.getType()).thenReturn("blah");
    when(reference.getType()).thenReturn("tu");
    when(resourceReferenceExtractor.extract("path")).thenReturn(reference);
    when(relativeResourceResolver.resolve(source, reference)).thenReturn(Optional.<ResourceReference>absent());

    ResourceReference result = underTest.resolve(source, "path");

    assertSame(reference, result);
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:18,代码来源:ResourceServiceTest.java

示例15: resolveGenericResourceFromString

import org.jtwig.resource.reference.ResourceReference; //导入依赖的package包/类
@Test
public void resolveGenericResourceFromString() throws Exception {
    ResourceReference source = mock(ResourceReference.class);
    ResourceReference reference = mock(ResourceReference.class);
    ResourceMetadata resourceMetadata = mock(ResourceMetadata.class);
    ValueEnvironment valueEnvironment = mock(ValueEnvironment.class);
    StringConverter stringConverter = mock(StringConverter.class);

    ResourceService underTest = mock(ResourceService.class);

    when(stringConverter.convert("path")).thenReturn("path");
    when(valueEnvironment.getStringConverter()).thenReturn(stringConverter);
    when(resourceMetadata.exists()).thenReturn(true);
    when(underTest.loadMetadata(reference)).thenReturn(resourceMetadata);
    when(underTest.resolve(source, "path")).thenReturn(reference);
    when(underTest.resolve(source, "path", valueEnvironment)).thenCallRealMethod();

    ResourceReference result = underTest.resolve(source, "path", valueEnvironment);

    assertSame(reference, result);
}
 
开发者ID:jtwig,项目名称:jtwig-core,代码行数:22,代码来源:ResourceServiceTest.java


注:本文中的org.jtwig.resource.reference.ResourceReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。