TemplateProcessor.java Sample

This topic inludes the source code for the TemplateProcessor.java Sample.

Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/ExtensionDevKit/TaglibExtDevKit/TaglibInstall/TDK/

Sample Source Code


01 package TDK; 
02 
03 import com.bea.ide.workspace.project.IProjectTemplate;
04 import com.bea.ide.workspace.project.IProjectTemplateProcessor;
05 import com.bea.ide.workspace.project.web.IWebProjectDriver;
06 import com.bea.wlw.config.j2ee.WebAppDocument.WebApp;
07 import com.bea.wlw.config.j2ee.WebAppDocument.WebApp.Taglib;
08 import com.bea.xbean.tool.XMLBean;
09 
10 public class TemplateProcessor implements IProjectTemplateProcessor
11 {
12     private IProjectTemplate _template;
13     private IContext _context;   
14     
15     public TemplateProcessor (IProjectTemplate template, IContext c)
16     {
17         _template = template;
18         _context = c;        
19     }
20     
21     public boolean load()
22     {
23         _context.loadAllContent(_template);
24         IWebProjectDriver driver = (IWebProjectDriver)_context.getProject().getDriver(IWebProjectDriver.class);    
25         WebApp bean = (WebApp)driver.getWebXmlBean();
26         
27         // UNDONE -- extract the taglibs from template dynamically.
28         String taglibLocation = "/WEB-INF/tdk-tags.tld";
29         String taglibUri = "tdk-tags.tld";
30         
31         // check if this guy is already defined in web.xml
32         Taglib[] taglibs = bean.getTaglibArray();
33         for(int i = 0; i < taglibs.length; i++)
34         {
35             if(taglibs[i].getTaglibLocation().equals(taglibLocation&&
36                taglibs[i].getTaglibUri().equals(taglibUri))
37                {
38                     return true;
39                }  
40         }
41         
42         // add a new <taglib> entry to web.xml using xmlbeans.
43         Taglib taglib = bean.addNewTaglib();
44         taglib.setTaglibLocation(taglibLocation);
45         taglib.setTaglibUri(taglibUri);    
46         bean.setTaglibArray(taglibs.length, taglib);        
47         driver.setWebXmlBean(bean, true);
48         return true;
49     }
50 
51     public String check()
52     {
53         return null;
54     }
55