1 16 17 package org.apache.commons.jelly.tags.core; 18 19 import java.io.File ; 20 21 import org.apache.commons.jelly.JellyException; 22 import org.apache.commons.jelly.JellyTagException; 23 import org.apache.commons.jelly.MissingAttributeException; 24 import org.apache.commons.jelly.TagSupport; 25 import org.apache.commons.jelly.XMLOutput; 26 27 32 33 public class IncludeTag extends TagSupport { 34 35 private String uri; 36 private File file; 37 38 private boolean shouldExport; 39 private boolean shouldInherit; 40 41 public IncludeTag() { 42 this.shouldExport = false; 43 this.shouldInherit = true; 44 } 45 46 public void setInherit(String inherit) { 47 if ("true".equals(inherit)) { 48 this.shouldInherit = true; 49 } else { 50 this.shouldInherit = false; 51 } 52 } 53 54 public void setExport(String export) { 55 if ("true".equals(export)) { 56 this.shouldExport = true; 57 } else { 58 this.shouldExport = false; 59 } 60 } 61 62 public boolean isInherit() { 63 return this.shouldInherit; 64 } 65 66 public boolean isExport() { 67 return this.shouldExport; 68 } 69 70 73 public File getFile() { 74 return file; 75 } 76 77 81 public void setFile(File file) { 82 this.file = file; 83 } 84 85 86 public void doTag(XMLOutput output) 89 throws MissingAttributeException, JellyTagException { 90 91 if (uri == null && file == null) { 92 throw new MissingAttributeException("uri"); 93 } 94 95 String text = null; 98 try { 99 if (uri != null) { 100 text = uri; 101 context.runScript(uri, output, isExport(), isInherit()); 102 } 103 else { 104 text = file.toString(); 105 context.runScript(file, output, isExport(), isInherit()); 106 } 107 } 108 catch (JellyException e) { 109 throw new JellyTagException("could not include jelly script: " + text + ". Reason: " + e, e); 110 } 111 } 112 113 116 public void setUri(String uri) { 117 this.uri = uri; 118 } 119 } 120 | Popular Tags |