[LIB-9] Add ability to archive qrcode content
[chesshog.git] / chesshog-qrcode / src / main / java / org / hedgecode / chess / qrcode / ChessQRCodeReader.java
index a0bbbdf..b10caa4 100644 (file)
@@ -36,8 +36,6 @@ import com.google.zxing.common.HybridBinarizer;
 import com.google.zxing.qrcode.decoder.Decoder;
 import com.google.zxing.qrcode.detector.Detector;
 
-import org.hedgecode.chess.ChessQRCodeConstants;
-
 /**
  * Chess-specific QR Codes reader (image decoder).
  *
@@ -49,7 +47,7 @@ public class ChessQRCodeReader {
 
     private static ChessQRCodeReader _instance = new ChessQRCodeReader();
 
-    private ChessQRCodeReader() {
+    protected ChessQRCodeReader() {
         decoder = new Decoder();
     }
 
@@ -126,20 +124,7 @@ public class ChessQRCodeReader {
             );
         }
 
-        ChessQRCodeMode mode = ChessQRCodeMode.byCode(
-                decoderResult.getText().substring(0, ChessQRCodeMode.CODE_LENGTH)
-        );
-
-        if (mode == null) {
-            throw new ChessQRCodeException(
-                    ChessQRCodeException.Type.READ, "read.unknown.chess.mode"
-            );
-        }
-
-        return new ChessQRResult(
-                mode,
-                decoderResult.getText().substring(ChessQRCodeMode.CODE_LENGTH)
-        );
+        return createResult(decoderResult);
 /*
         ResultPoint[] points = detectorResult.getPoints();
 
@@ -176,6 +161,22 @@ public class ChessQRCodeReader {
 */
     }
 
+    protected ChessQRResult createResult(DecoderResult decoderResult) throws ChessQRCodeException {
+        String result = decoderResult.getText();
+
+        ChessQRCodeMode mode = ChessQRResult.getMode(result);
+        if (mode == null) {
+            throw new ChessQRCodeException(
+                    ChessQRCodeException.Type.READ, "read.unknown.chess.mode"
+            );
+        }
+
+        return new ChessQRResult(
+                mode,
+                ChessQRResult.getContents(result)
+        );
+    }
+
     public static ChessQRCodeReader getInstance() {
         return _instance;
     }
@@ -184,7 +185,7 @@ public class ChessQRCodeReader {
     public static void main(String[] args) {
         try {
             ChessQRResult qrCodeResult = ChessQRCodeReader.getInstance().read(
-                    new File("MyQRCode.png")
+                    new File("qrcode.png")
             );
             System.out.println("Decoded format = " + qrCodeResult.getMode());
             System.out.println("Decoded text = " + qrCodeResult.getContents());