1 16 17 package org.springframework.web.servlet.view.xslt; 18 19 import org.springframework.util.Assert; 20 import org.springframework.util.xml.SimpleTransformErrorListener; 21 import org.springframework.web.servlet.view.AbstractUrlBasedView; 22 import org.springframework.web.servlet.view.UrlBasedViewResolver; 23 24 import javax.xml.transform.ErrorListener ; 25 import javax.xml.transform.URIResolver ; 26 import java.util.Properties ; 27 28 36 public class XsltViewResolver extends UrlBasedViewResolver { 37 38 private ErrorListener errorListener = new SimpleTransformErrorListener(logger); 39 40 private URIResolver uriResolver; 41 42 private boolean cacheTemplates = true; 43 44 private String sourceKey; 45 46 private Properties outputProperties; 47 48 private boolean indent = true; 49 50 public XsltViewResolver() { 51 setViewClass(XsltView.class); 52 } 53 54 57 public void setCacheTemplates(boolean cacheTemplates) { 58 this.cacheTemplates = cacheTemplates; 59 } 60 61 64 public void setUriResolver(URIResolver uriResolver) { 65 this.uriResolver = uriResolver; 66 } 67 68 71 public void setErrorListener(ErrorListener errorListener) { 72 Assert.notNull(errorListener, "'errorListener' cannot be null."); 73 this.errorListener = errorListener; 74 } 75 76 79 public void setSourceKey(String sourceKey) { 80 this.sourceKey = sourceKey; 81 } 82 83 86 public void setOutputProperties(Properties outputProperties) { 87 this.outputProperties = outputProperties; 88 } 89 90 93 public void setIndent(boolean indent) { 94 this.indent = indent; 95 } 96 97 protected Class requiredViewClass() { 98 return XsltView.class; 99 } 100 101 protected AbstractUrlBasedView buildView(String viewName) throws Exception { 102 XsltView view = (XsltView) super.buildView(viewName); 103 view.setUriResolver(this.uriResolver); 104 view.setErrorListener(this.errorListener); 105 view.setSourceKey(this.sourceKey); 106 view.setOutputProperties(this.outputProperties); 107 view.setIndent(this.indent); 108 return view; 109 } 110 } 111 | Popular Tags |