import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
public class StrutsCheck {
/*
* Actionタグ内で出力する属性
*/
public static final String[] chkWord = {"name","type","path","input","scope","validate"};
/*
* セル区切る
*/
public static final String kugiri = ",";
/*
* レコード区切り
*/
public static final String recend = "¥r¥n";
public static void main(String[] args) {
// 引数チェック
if ( args.length < 1 )
{
System.out.println("引数:struts-config.xmlのパス");
return;
}
// XMLオープン
DocumentBuilderFactory dbf;
DocumentBuilder bl;
Document doc;
try
{
dbf = DocumentBuilderFactory.newInstance();
bl = dbf.newDocumentBuilder();
doc = bl.parse(new File(args[0]));
}
catch(Exception e)
{
e.printStackTrace();
return;
}
// actionをget
NodeList actionList = doc.getElementsByTagName("action");
for(int i = 0 ; i < actionList.getLength(); i++)
{
//1アクション分処理
Node action = actionList.item(i);
NamedNodeMap attr = action.getAttributes();
Node item = null;
String val = "";
for ( int j = 0 ; j < chkWord.length ; j ++ )
{
//1アトリビュート分処理
item = attr.getNamedItem(chkWord[j]);
if ( j != 0 )
{
System.out.print(kugiri);
}
if ( item != null )
{
val = item.getNodeValue();
if ( val == null )
val = "";
System.out.print(val);
}
else
{
System.out.print(val);
}
}
System.out.print(recend);
}
}
}
|