KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sdk > ActionDocGen


1 package sdk;
2
3 import dinamica.*;
4 import java.io.*;
5
6 /**
7  * ActionDocGen<br>
8  * Generates documentation for every Action
9  * under /web-inf/action for a given application.
10  * <br><br>
11  * Creation date: 05/08/2004<br>
12  * (c) 2004 Martin Cordova y Asociados<br>
13  * http://www.martincordova.com<br>
14  * @author Martin Cordova dinamica@martincordova.com
15  */

16 public class ActionDocGen
17 {
18
19     String JavaDoc rootPath = null;
20     Recordset action = new Recordset();
21
22     public ActionDocGen(String JavaDoc path) throws Throwable JavaDoc
23     {
24         rootPath = path;
25         action.append("path", java.sql.Types.VARCHAR);
26         action.append("dataclass", java.sql.Types.VARCHAR);
27         action.append("outputclass", java.sql.Types.VARCHAR);
28         action.append("log", java.sql.Types.VARCHAR);
29         action.append("jdbclog", java.sql.Types.VARCHAR);
30         action.append("tx-enabled", java.sql.Types.VARCHAR);
31         action.append("summary", java.sql.Types.VARCHAR);
32         
33         File f = new File(rootPath);
34         if (!f.exists())
35             throw new Throwable JavaDoc("Path not found - Invalid Action path: " + rootPath);
36         getData(f);
37         
38     }
39
40     void getData(File f) throws Throwable JavaDoc
41     {
42         String JavaDoc items[] = f.list();
43         
44         //System.out.println(f.getPath() + " -> " + items.length + " items.");
45

46         for (int i=0;i<items.length;i++)
47         {
48             
49             String JavaDoc fname = f.getPath() + File.separator + items[i];
50             
51             File item = new File(fname);
52             if (item.isDirectory())
53             {
54                 getData(item);
55             }
56             else
57             {
58                 if (item.getName().equals("config.xml"))
59                 {
60                     Config c = new Config(getFile(item), item.getParent());
61                     String JavaDoc path = c.path.substring(c.path.lastIndexOf("WEB-INF") + "WEB-INF".length());
62                     path = StringUtil.replace(path, "\\", "/");
63                     action.addNew();
64                     action.setValue("path", path);
65                     action.setValue("summary", c.summary);
66                     action.setValue("tx-enabled", c.transTransactions);
67                     action.setValue("dataclass", c.transClassName);
68                     action.setValue("outputclass", c.outClassName);
69                     action.setValue("log", c.mvcLog);
70                     action.setValue("jdbclog", c.jdbcLog);
71                 }
72             }
73             
74         }
75         
76     }
77
78     String JavaDoc getFile(File f) throws Throwable JavaDoc
79     {
80         byte buffer[] = new byte[(int)f.length()];
81         FileInputStream fis = null;
82         try
83         {
84             fis = new FileInputStream(f);
85             fis.read(buffer);
86             String JavaDoc data = new String JavaDoc(buffer);
87             return data;
88         }
89         catch (FileNotFoundException e)
90         {
91             throw e;
92         }
93         catch (IOException e)
94         {
95             throw e;
96         }
97         finally
98         {
99             if (fis!=null)
100                 fis.close();
101         }
102     }
103
104     /**
105      * Returns the internal recordset that contains a record
106      * for every Action of the given application. Each record contains
107      * the folllowing columns:<br>
108      * <ul>
109      * <li> path
110      * <li> summary
111      * <li> tx-enabled
112      * <li> dataclass
113      * <li> outputclass
114      * <li> log
115      * <li> jdbclog
116      * </ul>
117      *
118      * @return Recordset containing list of Actions and related properties
119      */

120     public Recordset getActions()
121     {
122         return action;
123     }
124
125 }
126
Popular Tags