1 16 package org.apache.cocoon.generation; 17 18 import java.beans.PropertyDescriptor ; 19 import java.io.BufferedReader ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.io.StringReader ; 23 import java.io.StringWriter ; 24 import java.util.ArrayList ; 25 import java.util.HashMap ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Map ; 30 import java.util.Set ; 31 32 import org.apache.avalon.framework.activity.Initializable; 33 import org.apache.avalon.framework.configuration.Configurable; 34 import org.apache.avalon.framework.configuration.Configuration; 35 import org.apache.avalon.framework.configuration.ConfigurationException; 36 import org.apache.avalon.framework.context.ContextException; 37 import org.apache.avalon.framework.context.DefaultContext; 38 import org.apache.avalon.framework.parameters.Parameters; 39 import org.apache.avalon.framework.service.ServiceException; 40 import org.apache.cocoon.ProcessingException; 41 import org.apache.cocoon.ResourceNotFoundException; 42 import org.apache.cocoon.components.flow.FlowHelper; 43 import org.apache.cocoon.components.flow.WebContinuation; 44 import org.apache.cocoon.environment.ObjectModelHelper; 45 import org.apache.cocoon.environment.Request; 46 import org.apache.cocoon.environment.Response; 47 import org.apache.cocoon.environment.Session; 48 import org.apache.cocoon.environment.SourceResolver; 49 import org.apache.commons.collections.ExtendedProperties; 50 import org.apache.commons.jxpath.DynamicPropertyHandler; 51 import org.apache.commons.jxpath.JXPathBeanInfo; 52 import org.apache.commons.jxpath.JXPathIntrospector; 53 import org.apache.commons.lang.StringUtils; 54 import org.apache.excalibur.source.Source; 55 import org.apache.excalibur.xml.sax.SAXParser; 56 import org.apache.velocity.VelocityContext; 57 import org.apache.velocity.app.VelocityEngine; 58 import org.apache.velocity.context.Context; 59 import org.apache.velocity.runtime.RuntimeConstants; 60 import org.apache.velocity.runtime.RuntimeServices; 61 import org.apache.velocity.runtime.log.LogSystem; 62 import org.apache.velocity.runtime.resource.Resource; 63 import org.apache.velocity.util.introspection.Info; 64 import org.apache.velocity.util.introspection.UberspectImpl; 65 import org.apache.velocity.util.introspection.VelMethod; 66 import org.apache.velocity.util.introspection.VelPropertyGet; 67 import org.apache.velocity.util.introspection.VelPropertySet; 68 import org.mozilla.javascript.JavaScriptException; 69 import org.mozilla.javascript.NativeArray; 70 import org.mozilla.javascript.ScriptRuntime; 71 import org.mozilla.javascript.Scriptable; 72 import org.mozilla.javascript.ScriptableObject; 73 import org.mozilla.javascript.Undefined; 74 import org.mozilla.javascript.Wrapper; 75 import org.xml.sax.InputSource ; 76 import org.xml.sax.SAXException ; 77 import org.xml.sax.SAXParseException ; 78 79 158 public class VelocityGenerator extends ServiceableGenerator 159 implements Initializable, Configurable, LogSystem { 160 161 200 public static class ChainedContext extends VelocityContext 201 { 202 203 206 private Request request; 207 208 211 private Response response; 212 213 216 private Session session; 217 218 221 private org.apache.cocoon.environment.Context application; 222 223 226 private Parameters parameters; 227 228 231 public static final String REQUEST = "request"; 232 233 236 public static final String RESPONSE = "response"; 237 238 241 public static final String SESSION = "session"; 242 243 246 public static final String APPLICATION = "context"; 247 248 251 public static final String PARAMETERS = "parameters"; 252 253 254 257 public ChainedContext(org.apache.velocity.context.Context ctx, 258 Request request, 259 Response response, 260 org.apache.cocoon.environment.Context application, 261 Parameters parameters) 262 { 263 super(null, ctx); 264 this.request = request; 265 this.response = response; 266 this.session = request.getSession(false); 267 this.application = application; 268 this.parameters = parameters; 269 } 270 271 272 281 public Object internalGet( String key ) 282 { 283 if ( key.equals( REQUEST )) 285 { 286 return request; 287 } 288 else if( key.equals(RESPONSE) ) 289 { 290 return response; 291 } 292 else if ( key.equals(SESSION) ) 293 { 294 return session; 295 } 296 else if ( key.equals(APPLICATION)) 297 { 298 return application; 299 } 300 else if ( key.equals(PARAMETERS)) 301 { 302 return parameters; 303 } 304 305 Object o = null; 306 307 o = super.internalGet( key ); 309 310 if (o == null) 312 { 313 o = request.getAttribute( key ); 314 315 if ( o == null ) 316 { 317 if ( session != null ) 318 { 319 o = session.getAttribute( key ); 320 } 321 322 if ( o == null ) 323 { 324 o = application.getAttribute( key ); 325 } 326 } 327 } 328 329 return o; 330 } 331 332 333 } 335 340 public static class JSIntrospector extends UberspectImpl { 341 342 public static class JSMethod implements VelMethod { 343 344 Scriptable scope; 345 String name; 346 347 public JSMethod(Scriptable scope, String name) { 348 this.scope = scope; 349 this.name = name; 350 } 351 352 public Object invoke(Object thisArg, Object [] args) 353 throws Exception { 354 org.mozilla.javascript.Context cx = org.mozilla.javascript.Context.enter(); 355 try { 356 Object result; 357 Scriptable thisObj; 358 if (!(thisArg instanceof Scriptable)) { 359 thisObj = org.mozilla.javascript.Context.toObject(thisArg, scope); 360 } else { 361 thisObj = (Scriptable)thisArg; 362 } 363 result = ScriptableObject.getProperty(thisObj, name); 364 Object [] newArgs = null; 365 if (args != null) { 366 newArgs = new Object [args.length]; 367 for (int i = 0; i < args.length; i++) { 368 newArgs[i] = args[i]; 369 if (args[i] != null && 370 !(args[i] instanceof Number ) && 371 !(args[i] instanceof Boolean ) && 372 !(args[i] instanceof String ) && 373 !(args[i] instanceof Scriptable)) { 374 newArgs[i] = org.mozilla.javascript.Context.toObject(args[i], scope); 375 } 376 } 377 } 378 result = ScriptRuntime.call(cx, result, thisObj, 379 newArgs, scope); 380 if (result == Undefined.instance || 381 result == Scriptable.NOT_FOUND) { 382 result = null; 383 } else while (result instanceof Wrapper) { 384 result = ((Wrapper)result).unwrap(); 385 } 386 return result; 387 } catch (JavaScriptException e) { 388 throw new java.lang.reflect.InvocationTargetException (e); 389 } finally { 390 org.mozilla.javascript.Context.exit(); 391 } 392 } 393 394 public boolean isCacheable() { 395 return false; 396 } 397 398 public String getMethodName() { 399 return name; 400 } 401 402 public Class getReturnType() { 403 return Object .class; 404 } 405 406 } 407 408 public static class JSPropertyGet implements VelPropertyGet { 409 410 Scriptable scope; 411 String name; 412 413 public JSPropertyGet(Scriptable scope, String name) { 414 this.scope = scope; 415 this.name = name; 416 } 417 418 public Object invoke(Object thisArg) throws Exception { 419 org.mozilla.javascript.Context.enter(); 420 try { 421 Scriptable thisObj; 422 if (!(thisArg instanceof Scriptable)) { 423 thisObj = org.mozilla.javascript.Context.toObject(thisArg, scope); 424 } else { 425 thisObj = (Scriptable)thisArg; 426 } 427 Object result = ScriptableObject.getProperty(thisObj, name); 428 if (result == Undefined.instance || 429 result == Scriptable.NOT_FOUND) { 430 result = null; 431 } else while (result instanceof Wrapper) { 432 result = ((Wrapper)result).unwrap(); 433 } 434 return result; 435 } finally { 436 org.mozilla.javascript.Context.exit(); 437 } 438 } 439 440 public boolean isCacheable() { 441 return false; 442 } 443 444 public String getMethodName() { 445 return name; 446 } 447 448 } 449 450 public static class JSPropertySet implements VelPropertySet { 451 452 Scriptable scope; 453 String name; 454 455 public JSPropertySet(Scriptable scope, String name) { 456 this.scope = scope; 457 this.name = name; 458 } 459 460 public Object invoke(Object thisArg, Object rhs) throws Exception { 461 org.mozilla.javascript.Context.enter(); 462 try { 463 Scriptable thisObj; 464 Object arg = rhs; 465 if (!(thisArg instanceof Scriptable)) { 466 thisObj = org.mozilla.javascript.Context.toObject(thisArg, scope); 467 } else { 468 thisObj = (Scriptable)thisArg; 469 } 470 if (arg != null && 471 !(arg instanceof Number ) && 472 !(arg instanceof Boolean ) && 473 !(arg instanceof String ) && 474 !(arg instanceof Scriptable)) { 475 arg = org.mozilla.javascript.Context.toObject(arg, scope); 476 } 477 ScriptableObject.putProperty(thisObj, name, arg); 478 return rhs; 479 } finally { 480 org.mozilla.javascript.Context.exit(); 481 } 482 } 483 484 public boolean isCacheable() { 485 return false; 486 } 487 488 public String getMethodName() { 489 return name; 490 } 491 } 492 493 public static class NativeArrayIterator implements Iterator { 494 495 NativeArray arr; 496 int index; 497 498 public NativeArrayIterator(NativeArray arr) { 499 this.arr = arr; 500 this.index = 0; 501 } 502 503 public boolean hasNext() { 504 return index < (int)arr.jsGet_length(); 505 } 506 507 public Object next() { 508 org.mozilla.javascript.Context.enter(); 509 try { 510 Object result = arr.get(index++, arr); 511 if (result == Undefined.instance || 512 result == Scriptable.NOT_FOUND) { 513 result = null; 514 } else while (result instanceof Wrapper) { 515 result = ((Wrapper)result).unwrap(); 516 } 517 return result; 518 } finally { 519 org.mozilla.javascript.Context.exit(); 520 } 521 } 522 523 public void remove() { 524 arr.delete(index); 525 } 526 } 527 528 public static class ScriptableIterator implements Iterator { 529 530 Scriptable scope; 531 Object [] ids; 532 int index; 533 534 public ScriptableIterator(Scriptable scope) { 535 this.scope = scope; 536 this.ids = scope.getIds(); 537 this.index = 0; 538 } 539 540 public boolean hasNext() { 541 return index < ids.length; 542 } 543 544 public Object next() { 545 org.mozilla.javascript.Context.enter(); 546 try { 547 Object result = 548 ScriptableObject.getProperty(scope, 549 ids[index++].toString()); 550 if (result == Undefined.instance || 551 result == Scriptable.NOT_FOUND) { 552 result = null; 553 } else while (result instanceof Wrapper) { 554 result = ((Wrapper)result).unwrap(); 555 } 556 return result; 557 } finally { 558 org.mozilla.javascript.Context.exit(); 559 } 560 } 561 562 public void remove() { 563 org.mozilla.javascript.Context.enter(); 564 try { 565 scope.delete(ids[index].toString()); 566 } finally { 567 org.mozilla.javascript.Context.exit(); 568 } 569 } 570 } 571 572 public Iterator getIterator(Object obj, Info i) 573 throws Exception { 574 if (!(obj instanceof Scriptable)) { 575 return super.getIterator(obj, i); 576 } 577 if (obj instanceof NativeArray) { 578 return new NativeArrayIterator((NativeArray)obj); 579 } 580 return new ScriptableIterator((Scriptable)obj); 581 } 582 583 public VelMethod getMethod(Object obj, String methodName, 584 Object [] args, Info i) 585 throws Exception { 586 if (!(obj instanceof Scriptable)) { 587 return super.getMethod(obj, methodName, args, i); 588 } 589 return new JSMethod((Scriptable)obj, methodName); 590 } 591 592 public VelPropertyGet getPropertyGet(Object obj, String identifier, 593 Info i) 594 throws Exception { 595 if (!(obj instanceof Scriptable)) { 596 return super.getPropertyGet(obj, identifier, i); 597 } 598 return new JSPropertyGet((Scriptable)obj, identifier); 599 } 600 601 public VelPropertySet getPropertySet(Object obj, String identifier, 602 Object arg, Info i) 603 throws Exception { 604 if (!(obj instanceof Scriptable)) { 605 return super.getPropertySet(obj, identifier, arg, i); 606 } 607 return new JSPropertySet((Scriptable)obj, identifier); 608 } 609 } 610 611 619 public static class TemplateLoader 620 extends org.apache.velocity.runtime.resource.loader.ResourceLoader { 621 622 private org.apache.avalon.framework.context.Context resolverContext; 623 624 637 public void init(ExtendedProperties config) { 638 this.resolverContext = (org.apache.avalon.framework.context.Context) config.get("context"); 639 if (this.resolverContext == null) { 640 throw new IllegalArgumentException ("Runtime Cocoon resolver context not specified in resource loader configuration."); 641 } 642 } 643 644 648 public InputStream getResourceStream(String systemId) 649 throws org.apache.velocity.exception.ResourceNotFoundException { 650 try { 651 return resolveSource(systemId).getInputStream(); 652 } catch (org.apache.velocity.exception.ResourceNotFoundException ex) { 653 throw ex; 654 } catch (Exception ex) { 655 throw new org.apache.velocity.exception.ResourceNotFoundException("Unable to resolve source: " + ex); 656 } 657 } 658 659 662 public boolean isSourceModified(Resource resource) { 663 long lastModified = 0; 664 try { 665 lastModified = resolveSource(resource.getName()).getLastModified(); 666 } catch (Exception ex) { 667 super.rsvc.warn("Unable to determine last modified for resource: " 668 + resource.getName() + ": " + ex); 669 } 670 671 return lastModified > 0 ? lastModified != resource.getLastModified() : true; 672 } 673 674 677 public long getLastModified(Resource resource) { 678 long lastModified = 0; 679 try { 680 lastModified = resolveSource(resource.getName()).getLastModified(); 681 } catch (Exception ex) { 682 super.rsvc.warn("Unable to determine last modified for resource: " 683 + resource.getName() + ": " + ex); 684 } 685 686 return lastModified; 687 } 688 689 695 private Source resolveSource(String systemId) throws org.apache.velocity.exception.ResourceNotFoundException { 696 Map sourceCache; 697 try { 698 sourceCache = (Map ) this.resolverContext.get(CONTEXT_SOURCE_CACHE_KEY); 699 } catch (ContextException ignore) { 700 throw new org.apache.velocity.exception.ResourceNotFoundException("Runtime Cocoon source cache not specified in resource loader resolver context."); 701 } 702 703 Source source = (Source) sourceCache.get(systemId); 704 if (source == null) { 705 try { 706 SourceResolver resolver = (SourceResolver) this.resolverContext.get(CONTEXT_RESOLVER_KEY); 707 source = resolver.resolveURI(systemId); 708 } catch (ContextException ex) { 709 throw new org.apache.velocity.exception.ResourceNotFoundException("No Cocoon source resolver associated with current request."); 710 } catch (Exception ex) { 711 throw new org.apache.velocity.exception.ResourceNotFoundException("Unable to resolve source: " + ex); 712 } 713 } 714 715 sourceCache.put(systemId, source); 716 return source; 717 } 718 } 719 720 724 final private static String CONTEXT_RESOLVER_KEY = "resolver"; 725 726 730 final private static String CONTEXT_SOURCE_CACHE_KEY = "source-cache"; 731 732 private VelocityEngine tmplEngine; 733 private boolean tmplEngineInitialized; 734 private DefaultContext resolverContext; 735 private Context velocityContext; 736 private boolean activeFlag; 737 738 745 public void configure(Configuration configuration) throws ConfigurationException { 746 this.resolverContext = new DefaultContext(); 747 this.tmplEngine = new VelocityEngine(); 748 749 this.tmplEngine.setProperty(org.apache.velocity.runtime.RuntimeConstants.UBERSPECT_CLASSNAME, 751 JSIntrospector.class.getName()); 752 this.tmplEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, this); 753 754 this.tmplEngine.setProperty("cocoon.resource.loader.class", 756 TemplateLoader.class.getName()); 757 this.tmplEngine.setProperty("cocoon.resource.loader.cache", 758 configuration.getAttribute("usecache", "false")); 759 this.tmplEngine.setProperty("cocoon.resource.loader.modificationCheckInterval", 760 configuration.getAttribute("checkInterval", "0")); 761 this.tmplEngine.setProperty("cocoon.resource.loader.context", 762 this.resolverContext); 763 764 Configuration[] properties = configuration.getChildren("property"); 766 for (int i = 0; i < properties.length; ++i) { 767 Configuration c = properties[i]; 768 String name = c.getAttribute("name"); 769 770 if (name.startsWith("runtime.log") 772 || name.indexOf(".resource.loader.") != -1) { 773 if (getLogger().isInfoEnabled()) { 774 getLogger().info("ignoring disallowed property '" + name + "'."); 775 } 776 continue; 777 } 778 this.tmplEngine.setProperty(name, c.getAttribute("value")); 779 } 780 781 List resourceLoaders = new ArrayList (); 783 Configuration[] loaders = configuration.getChildren("resource-loader"); 784 for (int i = 0; i < loaders.length; ++i) { 785 Configuration loader = loaders[i]; 786 String name = loader.getAttribute("name"); 787 if (name.equals("cocoon")) { 788 if (getLogger().isInfoEnabled()) { 789 getLogger().info("'cocoon' resource loader already defined."); 790 } 791 continue; 792 } 793 resourceLoaders.add(name); 794 String prefix = name + ".resource.loader."; 795 String type = loader.getAttribute("class"); 796 this.tmplEngine.setProperty(prefix + "class", type); 797 Configuration[] loaderProperties = loader.getChildren("property"); 798 for (int j = 0; j < loaderProperties.length; j++) { 799 Configuration c = loaderProperties[j]; 800 String propName = c.getAttribute("name"); 801 this.tmplEngine.setProperty(prefix + propName, c.getAttribute("value")); 802 } 803 } 804 805 StringBuffer buffer = new StringBuffer ("cocoon"); 808 for (Iterator it = resourceLoaders.iterator(); it.hasNext();) { 809 buffer.append(','); 810 buffer.append((String ) it.next()); 811 } 812 tmplEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, buffer.toString()); 813 } 814 815 818 public void initialize() throws Exception { 819 } 821 822 825 public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params) 826 throws ProcessingException, SAXException , IOException { 827 if (activeFlag) { 828 throw new IllegalStateException ("setup called on recyclable sitemap component before properly recycling previous state"); 829 } 830 831 super.setup(resolver, objectModel, src, params); 832 833 this.resolverContext.put(CONTEXT_RESOLVER_KEY, resolver); 835 this.resolverContext.put(CONTEXT_SOURCE_CACHE_KEY, new HashMap ()); 836 837 final Object bean = FlowHelper.getContextObject(objectModel); 839 if (bean != null) { 840 841 final WebContinuation kont = FlowHelper.getWebContinuation(objectModel); 842 843 final JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass()); 845 DynamicPropertyHandler h = null; 846 final PropertyDescriptor [] props; 847 if (bi.isDynamic()) { 848 Class cl = bi.getDynamicPropertyHandlerClass(); 849 try { 850 h = (DynamicPropertyHandler) cl.newInstance(); 851 } catch (Exception exc) { 852 exc.printStackTrace(); 853 h = null; 854 } 855 props = null; 856 } else { 857 h = null; 858 props = bi.getPropertyDescriptors(); 859 } 860 final DynamicPropertyHandler handler = h; 861 862 this.velocityContext = new Context() { 863 public Object put(String key, Object value) { 864 if (key.equals("flowContext") 865 || key.equals("continuation")) { 866 return value; 867 } 868 if (handler != null) { 869 handler.setProperty(bean, key, value); 870 return value; 871 } else { 872 for (int i = 0; i < props.length; i++) { 873 if (props[i].getName().equals(key)) { 874 try { 875 return props[i].getWriteMethod().invoke(bean, new Object []{value}); 876 } catch (Exception ignored) { 877 break; 878 } 879 } 880 } 881 return value; 882 } 883 } 884 885 public boolean containsKey(Object key) { 886 if (key.equals("flowContext") 887 || key.equals("continuation")) { 888 return true; 889 } 890 if (handler != null) { 891 String [] result = handler.getPropertyNames(bean); 892 for (int i = 0; i < result.length; i++) { 893 if (key.equals(result[i])) { 894 return true; 895 } 896 } 897 } else { 898 for (int i = 0; i < props.length; i++) { 899 if (key.equals(props[i].getName())) { 900 return true; 901 } 902 } 903 } 904 return false; 905 } 906 907 public Object [] getKeys() { 908 Object [] result = null; 909 if (handler != null) { 910 result = handler.getPropertyNames(bean); 911 } else { 912 result = new Object [props.length]; 913 for (int i = 0; i < props.length; i++) { 914 result[i] = props[i].getName(); 915 } 916 } 917 Set set = new HashSet (); 918 for (int i = 0; i < result.length; i++) { 919 set.add(result[i]); 920 } 921 set.add("flowContext"); 922 set.add("continuation"); 923 result = new Object [set.size()]; 924 set.toArray(result); 925 return result; 926 } 927 928 public Object get(String key) { 929 if (key.equals("flowContext")) { 930 return bean; 931 } 932 if (key.equals("continuation")) { 933 return kont; 934 } 935 if (handler != null) { 936 return handler.getProperty(bean, key); 937 } else { 938 for (int i = 0; i < props.length; i++) { 939 if (props[i].getName().equals(key)) { 940 try { 941 return props[i].getReadMethod().invoke(bean, null); 942 } catch (Exception ignored) { 943 break; 944 } 945 } 946 } 947 return null; 948 } 949 } 950 951 public Object remove(Object key) { 952 return key; 954 } 955 }; 956 } 957 this.velocityContext = 958 new ChainedContext (this.velocityContext, 959 ObjectModelHelper.getRequest(objectModel), 960 ObjectModelHelper.getResponse(objectModel), 961 ObjectModelHelper.getContext(objectModel), 962 params); 963 this.velocityContext.put("template", src); 964 this.activeFlag = true; 965 } 966 972 public void recycle() { 973 this.activeFlag = false; 974 975 try { 977 Map sourceCache = (Map ) this.resolverContext.get(CONTEXT_SOURCE_CACHE_KEY); 978 for (Iterator it = sourceCache.values().iterator(); it.hasNext();) { 979 this.resolver.release((Source) it.next()); 980 } 981 } catch (ContextException ignore) { 982 } 983 984 this.velocityContext = null; 985 super.recycle(); 986 } 987 988 993 public void generate() 994 throws IOException , SAXException , ProcessingException { 995 if (!activeFlag) { 997 throw new IllegalStateException ("generate called on sitemap component before setup."); 998 } 999 1000 SAXParser parser = null; 1001 StringWriter w = new StringWriter (); 1002 try { 1003 parser = (SAXParser) this.manager.lookup(SAXParser.ROLE); 1004 if (getLogger().isDebugEnabled()) { 1005 getLogger().debug("Processing File: " + super.source); 1006 } 1007 if (!tmplEngineInitialized) { 1008 tmplEngine.init(); 1009 tmplEngineInitialized = true; 1010 } 1011 1012 this.tmplEngine.mergeTemplate(super.source, velocityContext, w); 1013 1014 InputSource xmlInput = 1015 new InputSource (new StringReader (w.toString())); 1016 xmlInput.setSystemId(super.source); 1017 parser.parse(xmlInput, this.xmlConsumer); 1018 } catch (IOException e) { 1019 getLogger().warn("VelocityGenerator.generate()", e); 1020 throw new ResourceNotFoundException("Could not get Resource for VelocityGenerator", e); 1021 } catch (SAXParseException e) { 1022 int line = e.getLineNumber(); 1023 int column = e.getColumnNumber(); 1024 if (line <= 0) { 1025 line = Integer.MAX_VALUE; 1026 } 1027 BufferedReader reader = 1028 new BufferedReader (new StringReader (w.toString())); 1029 StringBuffer message = new StringBuffer (e.getMessage()); 1030 message.append(" In generated document:\n"); 1031 for (int i = 0; i < line; i++) { 1032 String lineStr = reader.readLine(); 1033 if (lineStr == null) { 1034 break; 1035 } 1036 message.append(lineStr); 1037 message.append("\n"); 1038 } 1039 if (column > 0) { 1040 message.append(StringUtils.leftPad("^\n", column + 1)); 1041 } 1042 SAXException pe = new SAXParseException (message.toString(), 1043 e.getPublicId(), 1044 "(Document generated from template "+e.getSystemId() + ")", 1045 e.getLineNumber(), 1046 e.getColumnNumber(), 1047 null); 1048 getLogger().error("VelocityGenerator.generate()", pe); 1049 throw pe; 1050 } catch (SAXException e) { 1051 getLogger().error("VelocityGenerator.generate()", e); 1052 throw e; 1053 } catch (ServiceException e) { 1054 getLogger().error("Could not get parser", e); 1055 throw new ProcessingException("Exception in VelocityGenerator.generate()", e); 1056 } catch (ProcessingException e) { 1057 throw e; 1058 } catch (Exception e) { 1059 getLogger().error("Could not get parser", e); 1060 throw new ProcessingException("Exception in VelocityGenerator.generate()", e); 1061 } finally { 1062 this.manager.release(parser); 1063 } 1064 } 1065 1066 1067 1072 public void init(RuntimeServices rs) throws Exception { 1073 } 1074 1075 1080 public void logVelocityMessage(int level, String message) { 1081 switch (level) { 1082 case LogSystem.WARN_ID: 1083 getLogger().warn(message); 1084 break; 1085 case LogSystem.INFO_ID: 1086 getLogger().info(message); 1087 break; 1088 case LogSystem.DEBUG_ID: 1089 getLogger().debug(message); 1090 break; 1091 case LogSystem.ERROR_ID: 1092 getLogger().error(message); 1093 break; 1094 default : 1095 getLogger().info(message); 1096 break; 1097 } 1098 } 1099} 1100 | Popular Tags |