

















web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>MayaaServlet</servlet-name>
<servlet-class>org.seasar.mayaa.impl.MayaaServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MayaaServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>


index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <META HTTP-EQUIV="content-type" CONTENT="text/html; charset=EUC-JP"><title>Welcome!</title>
</head> <body><p> <span id="message">Mayaa engine suspended.</span> </p>
</body> </html>


index.mayaa
<?xml version="1.0" encoding="iso-8859-1"?>
<m:mayaa xmlns:m="http://mayaa.seasar.org">
<m:write m:id="message"
value="Welcome to the Mayaa's template driven development!"/>
</m:mayaa>













mayaa/sampleproject/Bundle.properties
Templates/Project/Samples/MayaaSampleProject.zip=Mayaa Sample








mayaa/MayaaFileTemplate.mayaa
<?xml version="1.0" encoding="iso-8859-1"?> <m:mayaa xmlns:m="http://mayaa.seasar.org"> </m:mayaa>







mayaa/webmodule/Bundle.properties
# Sample ResourceBundle properties file Mayaa_Name=Mayaa 1.0 Mayaa_Desc=Mayaa 1.0
mayaa/webmodule/MayaaWebModule.java
package mayaa.webmodule;import java.io.File; import java.util.Set; import org.netbeans.modules.web.api.webmodule.WebModule; import org.netbeans.modules.web.spi.webmodule.FrameworkConfigurationPanel; import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider; import org.openide.util.NbBundle;
/** * * @author kishida */public class MayaaWebModule extends WebFrameworkProvider{
/** Creates a new instance of MayaaWebModule */ public MayaaWebModule() {super( NbBundle.getMessage(MayaaWebModule.class, "Mayaa_Name"), //NOI18N NbBundle.getMessage(MayaaWebModule.class, "Mayaa_Desc")); //NOI18N
} public Set extend(WebModule wm) {return null;
} public boolean isInWebModule(WebModule wm) {return true;
} public File[] getConfigurationFiles(WebModule wm) {return null;
} public FrameworkConfigurationPanel getConfigurationPanel(WebModule wm) {return new MayaaWebModuleWizardPanel1(true);
} }
layer.xml
<folder name="j2ee"> <folder name="webtier"> <folder name="framework"> <file name="mayaa-webmodule-MayaaWebModule.instance"/> </folder> </folder> </folder>
<folder name="org-netbeans-api-project-libraries"> <folder name="Libraries"> <file name="Mayaa1.0.xml" url="Mayaa1.0.xml"/> </folder> </folder> </filesystem>


mayaa/webmodule/MayaaWebModule.java
package mayaa.webmodule; import java.io.File;import java.io.IOException; import java.math.BigInteger;
import java.util.Set;import org.netbeans.api.project.FileOwnerQuery; import org.netbeans.api.project.Project; import org.netbeans.api.project.libraries.Library; import org.netbeans.api.project.libraries.LibraryManager; import org.netbeans.modules.j2ee.dd.api.web.DDProvider; import org.netbeans.modules.j2ee.dd.api.web.Servlet; import org.netbeans.modules.j2ee.dd.api.web.ServletMapping; import org.netbeans.modules.j2ee.dd.api.web.WebApp;
import org.netbeans.modules.web.api.webmodule.WebModule; import org.netbeans.modules.web.spi.webmodule.FrameworkConfigurationPanel; import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider;import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileStateInvalidException; import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileSystem.AtomicAction;
import org.openide.util.NbBundle; /** * * @author kishida */ public class MayaaWebModule extends WebFrameworkProvider{ /** Creates a new instance of MayaaWebModule */ public MayaaWebModule() { super( NbBundle.getMessage(MayaaWebModule.class, "Mayaa_Name"), //NOI18N NbBundle.getMessage(MayaaWebModule.class, "Mayaa_Desc")); //NOI18N }public static final String MAYAA_SERVLET = "org.seasar.mayaa.impl.MayaaServlet";
public Set extend(WebModule wm) {FileObject fo = wm.getDocumentBase(); Project project = FileOwnerQuery.getOwner(fo); //Mayaaライブラリの取得 Library lib = LibraryManager.getDefault().getLibrary("Mayaa1.0"); if(lib == null) return null; //ライブラリの追加 ProjectClassPathExtender pcpe = (ProjectClassPathExtender)project.getLookup().lookup(ProjectClassPathExtender.class); if(pcpe == null) return null; try { pcpe.addLibrary(lib); } catch (IOException ex) { return null; } //web.xml操作 FileSystem fs; try { fs = wm.getWebInf().getFileSystem(); } catch (FileStateInvalidException ex) { return null; } try { fs.runAtomicAction(new CreateMayaaConfig(wm)); } catch (IOException ex) { return null; }
return null; }/** 一連のweb.xml操作 */ class CreateMayaaConfig implements FileSystem.AtomicAction{ WebModule wm; public CreateMayaaConfig(WebModule wm){ this.wm = wm; } public void run() throws IOException { //Web.xmlを取得 FileObject dd = wm.getDeploymentDescriptor(); WebApp wa = DDProvider.getDefault().getDDRootCopy(dd); if(wa == null) return; try { //Servletタグを追加 Servlet serv = (Servlet)wa.createBean("Servlet"); serv.setServletName("MayaaServlet"); serv.setServletClass(MAYAA_SERVLET); serv.setLoadOnStartup(new BigInteger("1")); wa.addServlet(serv); //Servletマッピングの追加 ServletMapping mapping = (ServletMapping)wa.createBean("ServletMapping"); mapping.setServletName(serv.getServletName()); mapping.setUrlPattern("*.html"); wa.addServletMapping(mapping); //書き込み wa.write(dd); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } } }
/** Webモジュールで使われているかどうか判定 サーブレット定義があれば使われていると判定する */
public boolean isInWebModule(WebModule wm) {//web.xmlの取得 FileObject dd = wm.getDeploymentDescriptor(); WebApp wa; try { wa = DDProvider.getDefault().getDDRoot(dd); } catch (IOException ex) { return false; } //サーブレットの検索 Servlet serv = (Servlet)wa.findBeanByName("Servlet", "ServletClass", MAYAA_SERVLET); return serv != null;
} public File[] getConfigurationFiles(WebModule wm) { return null; } public FrameworkConfigurationPanel getConfigurationPanel(WebModule wm) { return new MayaaWebModuleWizardPanel1(true); } }

