import java.text.MessageFormat;
import java.util.List;
import java.util.Properties;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
import jp.sourceforge.jindolf.corelib.LandDef;
import jp.sourceforge.jindolf.parser.DecodeException;
import jp.sourceforge.jindolf.parser.HtmlParseException;
-import org.xml.sax.SAXException;
/**
* メインエントリ。
/** バージョン。 */
private static final String VERSION;
- private static final List<LandDef> LANDDEF_LIST;
-
/** バージョン定義リソース。 */
private static final String RES_VERDEF = "resources/version.properties";
+
static{
SELF_KLASS = JinArchiver.class;
SELF_PACKAGE = SELF_KLASS.getPackage();
TITLE = getPackageInfo(verProp, "pkg-title.", "Unknown");
VERSION = getPackageInfo(verProp, "pkg-version.", "0");
GENERATOR = TITLE + " " + VERSION;
-
- DocumentBuilderFactory factory =
- DocumentBuilderFactory.newInstance();
- try{
- DocumentBuilder builder = factory.newDocumentBuilder();
- LANDDEF_LIST = LandDef.buildLandDefList(builder);
- }catch(ParserConfigurationException e){
- throw new ExceptionInInitializerError(e);
- }catch(IOException e){
- throw new ExceptionInInitializerError(e);
- }catch(SAXException e){
- throw new ExceptionInInitializerError(e);
- }
}
}
/**
- * 国IDから国情報を得る。
- * @param landId 国ID
- * @return 国情報
- */
- public static LandDef getLandDef(String landId){
- for(LandDef landDef : LANDDEF_LIST){
- if(landDef.getLandId().equals(landId)) return landDef;
- }
- return null;
- }
-
- /**
* ヘルプメッセージ出力。
*/
private static void helpMessage(){
+"-stdout\n\t標準出力へ出力\n\n"
+"※ -outdir と -stdout は排他指定\n"
);
- StringBuilder landList = new StringBuilder();
- for(LandDef landDef : LANDDEF_LIST){
- landList.append(landDef.getLandId()).append(' ');
- }
+
+ String landList = LandUtils.getLandList();
errprintln("利用可能な国識別子は " + landList + "\n");
return;
String val = args[pos];
if(arg.equals("-land")){
- landDef = getLandDef(val);
+ landDef = LandUtils.getLandDef(val);
if(landDef == null){
errprintln("不正な国識別子です。 " + val);
exit(1);
--- /dev/null
+/*
+ * Land Utilities
+ *
+ * License : The MIT License
+ * Copyright(c) 2016 olyutorskii
+ */
+
+package jp.sourceforge.jindolf.archiver;
+
+import java.io.IOException;
+import java.util.List;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+import jp.sourceforge.jindolf.corelib.LandDef;
+import org.xml.sax.SAXException;
+
+/**
+ * 国周りの各種情報提供。
+ */
+public final class LandUtils{
+
+ private static final List<LandDef> LANDDEF_LIST;
+ private static final char DELIM_SP = '\u0020';
+
+
+ static{
+ DocumentBuilder builder;
+ try{
+ builder = XmlUtils.createDocumentBuilder();
+ }catch(ParserConfigurationException e){
+ throw new ExceptionInInitializerError(e);
+ }
+
+ try{
+ LANDDEF_LIST = LandDef.buildLandDefList(builder);
+ }catch(IOException | SAXException e){
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+
+
+ /**
+ * 隠しコンストラクタ。
+ */
+ private LandUtils(){
+ assert false;
+ throw new AssertionError();
+ }
+
+
+ /**
+ * 国IDから国情報を得る。
+ * @param landId 国ID
+ * @return 国情報 見つからなければnull
+ */
+ public static LandDef getLandDef(String landId){
+ for(LandDef landDef : LANDDEF_LIST){
+ String id = landDef.getLandId();
+ if(id.equals(landId)) return landDef;
+ }
+
+ return null;
+ }
+
+ /**
+ * 国識別子一覧文字列を得る。
+ * 各識別子は空白記号で区切られる。
+ * @return 一覧文字列
+ */
+ public static String getLandList(){
+ StringBuilder landList = new StringBuilder();
+
+ for(LandDef landDef : LANDDEF_LIST){
+ String id = landDef.getLandId();
+ landList.append(id).append(DELIM_SP);
+ }
+
+ String result = landList.toString();
+ return result;
+ }
+
+}
import java.io.PipedWriter;
import java.io.Reader;
import java.io.Writer;
-import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.xml.sax.SAXException;
*/
public class ValidateTask implements Runnable{
- private static final SchemaFactory FACTORY =
- SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-
private final Validator validator;
private final Source source;
*/
protected ValidateTask(Reader reader) throws SAXException{
super();
- Schema schema = FACTORY.newSchema();
- this.validator = schema.newValidator();
+ this.validator = XmlUtils.createValidator();
this.source = new StreamSource(reader);
return;
}
import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
import jp.sourceforge.jindolf.parser.DecodeErrorInfo;
import jp.sourceforge.jindolf.parser.DecodedContent;
+import org.xml.sax.SAXException;
/**
* XML用各種ユーティリティ。
/**
+ * XML読み込み用DocumentBuilderを生成する。
+ * @return DocumentBuilder
+ * @throws ParserConfigurationException 実装が要求に応えられない。
+ */
+ public static DocumentBuilder createDocumentBuilder()
+ throws ParserConfigurationException {
+ DocumentBuilderFactory factory;
+ factory = DocumentBuilderFactory.newInstance();
+
+ DocumentBuilder builder;
+ builder = factory.newDocumentBuilder();
+
+ return builder;
+ }
+
+ /**
+ * バリデータを生成する。
+ * @return バリデータ
+ * @throws SAXException 実装が要求に応えられない。
+ */
+ public static Validator createValidator() throws SAXException{
+ SchemaFactory factory;
+ String nsuri = XMLConstants.W3C_XML_SCHEMA_NS_URI;
+ factory = SchemaFactory.newInstance(nsuri);
+
+ Schema schema;
+ schema = factory.newSchema();
+
+ Validator validator = schema.newValidator();
+
+ return validator;
+ }
+
+ /**
* DOCTYPE宣言を出力する。
* @param writer 出力先
* @throws IOException 出力エラー