本文整理汇总了Java中org.apache.velocity.exception.ResourceNotFoundException类的典型用法代码示例。如果您正苦于以下问题:Java ResourceNotFoundException类的具体用法?Java ResourceNotFoundException怎么用?Java ResourceNotFoundException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResourceNotFoundException类属于org.apache.velocity.exception包,在下文中一共展示了ResourceNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResourceStream
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
@Override
public InputStream getResourceStream(String source) throws ResourceNotFoundException {
if (logger.isDebugEnabled()) {
logger.debug("Looking for Velocity resource with name [" + source + "]");
}
for (String resourceLoaderPath : this.resourceLoaderPaths) {
org.springframework.core.io.Resource resource =
this.resourceLoader.getResource(resourceLoaderPath + source);
try {
return resource.getInputStream();
}
catch (IOException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Could not find Velocity resource: " + resource);
}
}
}
throw new ResourceNotFoundException(
"Could not find resource [" + source + "] in Spring resource loader path");
}
示例2: render
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
@Override
public boolean render(InternalContextAdapter context, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
String value = (String) node.jjtGetChild(0).value(context);
String character = (String) node.jjtGetChild(1).value(context);
int len = value.length();
StringBuilder sb = new StringBuilder(len);
sb.append(value.charAt(0));
for (int i = 1; i < len; i++) {
char c = value.charAt(i);
if (Character.isUpperCase(c)) {
sb.append(character).append(Character.toLowerCase(c));
} else {
sb.append(c);
}
}
writer.write(sb.toString());
return true;
}
示例3: outputCode
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
public void outputCode(String codePath, String templatePath) throws IOException {
VelocityContext context = new VelocityContext();
context.put("cModule", cModule);
Template template = null;
try {
template = Velocity.getTemplate(templatePath, TEMPLATE_ENCODING);
} catch (ResourceNotFoundException e) {
throw e;
}
File file = new File(codePath);
logger.info("Generating {} ({})", file.getName(), templatePath);
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), OUTPUT_ENCODING)));
template.merge(context, pw);
pw.close();
}
示例4: render
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
@Override
public boolean render(RenderHandler handler)
throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException {
String src = handler.getStringParameter(0);
String base = handler.getRequest().getContextPath();
// 判断是否启用图片域名
if (Global.getImageDomain()) {
base = Global.getImageHost();
}
StringBuffer buf = new StringBuffer();
buf.append(base);
buf.append(src);
handler.write(buf.toString());
return true;
}
示例5: render
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
@Override
public boolean render(RenderHandler handler) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException {
ServletRequest request = handler.getRequest();
// request 获取参数
String ord = ServletRequestUtils.getStringParameter(request, "ord", Consts.order.NEWEST);
int pn = ServletRequestUtils.getIntParameter(request, "pn", 1);
// 标签中获取参数
int groupId = handler.getIntParameter(0);
String alias = handler.getStringParameter(1);
Paging paging = wrapPaing(pn);
Paging result = postPlanet.paging(paging, groupId, ord);
handler.put(alias, result);
handler.doRender();
postRender(handler.getContext());
return true;
}
示例6: render
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
public boolean render(InternalContextAdapter ctx, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
// get the bean
ValueStack stack = (ValueStack) ctx.get("stack");
HttpServletRequest req = (HttpServletRequest) stack.getContext().get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse res = (HttpServletResponse) stack.getContext().get(ServletActionContext.HTTP_RESPONSE);
Component bean = getBean(stack, req, res);
Container container = (Container) stack.getContext().get(ActionContext.CONTAINER);
container.inject(bean);
// get the parameters
Map params = createPropertyMap(ctx, node);
bean.copyParams(params);
//bean.addAllParameters(params);
bean.start(writer);
if (getType() == BLOCK) {
Node body = node.jjtGetChild(node.jjtGetNumChildren() - 1);
body.render(ctx, writer);
}
bean.end(writer, "");
return true;
}
示例7: render
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
@Override
public boolean render(InternalContextAdapter context, Writer writer,
Node node) throws IOException, ResourceNotFoundException,
ParseErrorException, MethodInvocationException
{
int argsNum = node.jjtGetNumChildren();
for(int step = 0 ; step < argsNum; step++)
{
SimpleNode simpleNode = (SimpleNode) node.jjtGetChild(step);
Object argObject = simpleNode.value(context);
//传入参数
if(argObject instanceof String)
{
System.out.println((String)argObject);
writer.write((String)argObject);
writer.flush();
}
}
return true;
}
示例8: resolveTemplate
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
/**
* Process the resourceName with {@link #resolveTemplateIdentifiers(String)} and return the
* localized message object of the referenced template definition and the locale object.
*
* @param resourceName
* the velocity resource name
* @return the message and the locale extract from the resource name
* @throws ResourceNotFoundException
* in case the resource name is not an identifier for a note template or the note
* template does not exist
*/
private Pair<LocalizedMessage, Locale> resolveTemplate(String resourceName)
throws ResourceNotFoundException {
String[] templateParts = resolveTemplateIdentifiers(resourceName);
NoteTemplateDefinition definition = getNoteTemplateService()
.getDefinition(templateParts[0]);
if (definition == null) {
throw new ResourceNotFoundException("Note template " + templateParts[0]
+ " does not exist");
}
NoteRenderMode mode = null;
Locale locale = null;
try {
locale = LocaleHelper.toLocale(templateParts[1]);
if (templateParts[2] != null) {
mode = NoteRenderMode.valueOf(templateParts[2]);
}
} catch (IllegalArgumentException e) {
throw new ResourceNotFoundException("Resource name " + resourceName
+ " cannot be parsed", e);
}
return new Pair<LocalizedMessage, Locale>(definition.getTemplate(mode), locale);
}
示例9: resolveTemplateIdentifiers
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
/**
* Extract templateId, locale string and optionally the render mode from the resourceName.
*
* @param resourceName
* the velocity resource name to process
* @return an array with 3 elements where the first is the templateId, the 2nd the locale string
* and the 3rd the render mode or null if not contained
* @throws ResourceNotFoundException
* in case the resource name is not an identifier for a note template
*/
private String[] resolveTemplateIdentifiers(String resourceName)
throws ResourceNotFoundException {
if (!resourceName.startsWith(RESOURCE_NAME_PREFIX)) {
throw new ResourceNotFoundException("Resource " + resourceName
+ " not supported by this loader");
}
String[] result = new String[3];
int startIdx = RESOURCE_NAME_PREFIX.length();
try {
int idx = resourceName.indexOf(RESOURCE_NAME_PARTS_SEPARATOR, startIdx);
result[0] = resourceName.substring(startIdx, idx);
startIdx = idx + 1;
idx = resourceName.indexOf(RESOURCE_NAME_PARTS_SEPARATOR, startIdx);
// third part (render mode) is optional
if (idx < 0) {
result[1] = resourceName.substring(startIdx);
} else {
result[1] = resourceName.substring(startIdx, idx);
result[2] = resourceName.substring(idx + 1);
}
return result;
} catch (IndexOutOfBoundsException e) {
throw new ResourceNotFoundException("Resource " + resourceName + " not found");
}
}
示例10: renderTemplate
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
/**
* Return the String representation of the template rendered using Velocity.
*
* @param context context use to render the template
* @param templateFileName file name of the template in the classpath
* @throws TemplateRenderException if there is an error with the template
*/
public static String renderTemplate(String templateFileName,
VelocityContext context)
throws TemplateRenderException {
VelocityEngine ve = new VelocityEngine();
ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
ve.setProperty("classpath.resource.loader.class",
ClasspathResourceLoader.class.getName());
StringWriter sw = new StringWriter();
try {
ve.mergeTemplate(templateFileName, "UTF-8", context, sw);
} catch (ResourceNotFoundException
| ParseErrorException
| MethodInvocationException e) {
throw new TemplateRenderException("Error rendering template file: " + templateFileName, e);
}
return sw.toString();
}
示例11: getResourceStream
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
@Override
public InputStream getResourceStream(String resourceName) throws ResourceNotFoundException {
FileTemplateManager templateManager = ourTemplateManager.get();
if (templateManager == null) templateManager = FileTemplateManager.getDefaultInstance();
final FileTemplate include = templateManager.getPattern(resourceName);
if (include == null) {
throw new ResourceNotFoundException("Template not found: " + resourceName);
}
final String text = include.getText();
try {
return new ByteArrayInputStream(text.getBytes(FileTemplate.ourEncoding));
}
catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
示例12: getResourceStream
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
@Override
public InputStream getResourceStream(String name) throws ResourceNotFoundException {
try {
Registry registry =
CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_CONFIGURATION);
if (registry == null) {
throw new IllegalStateException("No valid registry instance is attached to the current carbon context");
}
if (!registry.resourceExists(EMAIL_CONFIG_BASE_LOCATION + "/" + name)) {
throw new ResourceNotFoundException("Resource '" + name + "' does not exist");
}
org.wso2.carbon.registry.api.Resource resource =
registry.get(EMAIL_CONFIG_BASE_LOCATION + "/" + name);
resource.setMediaType("text/plain");
return resource.getContentStream();
} catch (RegistryException e) {
throw new ResourceNotFoundException("Error occurred while retrieving resource", e);
}
}
示例13: prepareVelocityTemplate
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
private Set<String> prepareVelocityTemplate(String template) throws PIPException {
VelocityContext vctx = new VelocityContext();
EventCartridge vec = new EventCartridge();
VelocityParameterReader reader = new VelocityParameterReader();
vec.addEventHandler(reader);
vec.attachToContext(vctx);
try {
Velocity.evaluate(vctx, new StringWriter(), "LdapResolver", template);
} catch (ParseErrorException pex) {
throw new PIPException("Velocity template preparation failed", pex);
} catch (MethodInvocationException mix) {
throw new PIPException("Velocity template preparation failed", mix);
} catch (ResourceNotFoundException rnfx) {
throw new PIPException("Velocity template preparation failed", rnfx);
}
if (this.logger.isTraceEnabled()) {
this.logger.trace("(" + id + ") " + template + " with parameters " + reader.parameters);
}
return reader.parameters;
}
示例14: evaluateVelocityTemplate
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
private String evaluateVelocityTemplate(String template,
final Map<String, PIPRequest> templateParameters,
final PIPFinder pipFinder)
throws PIPException {
StringWriter out = new StringWriter();
VelocityContext vctx = new VelocityContext();
EventCartridge vec = new EventCartridge();
VelocityParameterWriter writer = new VelocityParameterWriter(pipFinder, templateParameters);
vec.addEventHandler(writer);
vec.attachToContext(vctx);
try {
Velocity.evaluate(vctx, out, "LdapResolver", template);
} catch (ParseErrorException pex) {
throw new PIPException("Velocity template evaluation failed", pex);
} catch (MethodInvocationException mix) {
throw new PIPException("Velocity template evaluation failed", mix);
} catch (ResourceNotFoundException rnfx) {
throw new PIPException("Velocity template evaluation failed", rnfx);
}
this.logger.warn("(" + id + ") " + " template yields " + out.toString());
return out.toString();
}
示例15: render
import org.apache.velocity.exception.ResourceNotFoundException; //导入依赖的package包/类
public boolean render(InternalContextAdapter context, Writer writer, Node node)
throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
//render content
StringWriter content = new StringWriter();
node.jjtGetChild(0).render(context, content);
//compress
try {
writer.write(htmlCompressor.compress(content.toString()));
} catch (Exception e) {
writer.write(content.toString());
String msg = "Failed to compress content: "+content.toString();
log.error(msg, e);
throw new RuntimeException(msg, e);
}
return true;
}