use of javax.activation.UnsupportedDataTypeException in project solution-finder by knewjade.
the class FigUtilSettingParser method parse.
public Optional<FigUtilSettings> parse() throws FinderParseException {
Options options = createOptions();
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parseToCommandLine(options, parser);
CommandLineWrapper wrapper = new NormalCommandLineWrapper(commandLine);
FigUtilSettings settings = new FigUtilSettings();
// help
if (wrapper.hasOption("help")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("util fig [options]", options);
return Optional.empty();
}
// ホールドの設定
Optional<Boolean> isUsingHold = wrapper.getBoolOption("hold");
isUsingHold.ifPresent(settings::setUsingHold);
// ループの設定
Optional<Boolean> isInfiniteLoop = wrapper.getBoolOption("loop");
isInfiniteLoop.ifPresent(settings::setInfiniteLoop);
// アウトプットファイルの設定
Optional<String> outputPath = wrapper.getStringOption("output");
outputPath.ifPresent(settings::setOutputFilePath);
// ディレイタイムの設定
Optional<Integer> delay = wrapper.getIntegerOption("delay");
try {
delay.ifPresent(value -> {
if (value <= 0)
throw new RuntimeException("Delay should be positive: delay=" + value);
settings.setDelay(value);
});
} catch (RuntimeException e) {
throw new FinderParseException(e.getMessage());
}
// フレームの設定
Optional<String> frameTypeName = wrapper.getStringOption("frame");
try {
Optional<FrameType> frameType = frameTypeName.map(frame -> {
try {
return parseFrameType(frame);
} catch (UnsupportedDataTypeException e) {
throw new RuntimeException(e);
}
});
frameType.ifPresent(settings::setFrameType);
} catch (RuntimeException e) {
throw new FinderParseException("Unsupported frame: frame=" + frameTypeName.orElse("<empty>"));
}
// フォーマットの設定
Optional<String> formatName = wrapper.getStringOption("format");
try {
Optional<FigFormat> figFormat = formatName.map(format -> {
try {
return parseFigFormat(format);
} catch (UnsupportedDataTypeException e) {
throw new RuntimeException(e);
}
});
figFormat.ifPresent(settings::setFigFormat);
} catch (RuntimeException e) {
throw new FinderParseException("Unsupported format: format=" + formatName.orElse("<empty>"));
}
// 高さの設定
Optional<Integer> height = wrapper.getIntegerOption("line");
try {
height.ifPresent(value -> {
if (value == 0)
throw new RuntimeException("Line should be positive or -1: line=" + value);
settings.setHeight(value);
});
} catch (RuntimeException e) {
throw new FinderParseException(e.getMessage());
}
// テト譜の設定
if (wrapper.hasOption("tetfu")) {
// パラメータから
Optional<String> tetfuData = wrapper.getStringOption("tetfu");
if (!tetfuData.isPresent())
throw new FinderParseException("Should specify option value: --tetfu");
String encoded = Tetfu.removeDomainData(tetfuData.get());
wrapper = loadTetfu(encoded, wrapper, settings);
} else {
// フィールドファイルから
Optional<String> fieldPathOption = wrapper.getStringOption("field-path");
String fieldPath = fieldPathOption.orElse(DEFAULT_FIELD_TXT);
Path path = Paths.get(fieldPath);
Charset charset = Charset.forName(CHARSET_NAME);
try {
LinkedList<String> fieldLines = Files.lines(path, charset).map(str -> {
if (str.contains("#"))
return str.substring(0, str.indexOf('#'));
return str;
}).map(String::trim).filter(s -> !s.isEmpty()).collect(Collectors.toCollection(LinkedList::new));
if (fieldLines.isEmpty())
throw new FinderParseException("Should specify field-definition in field file");
String encoded = fieldLines.get(0);
String removeDomainData = Tetfu.removeDomainData(encoded);
wrapper = loadTetfu(removeDomainData, wrapper, settings);
} catch (IOException e) {
throw new FinderParseException("Cannot open field file", e);
}
}
// ネクストの設定
Optional<Integer> next = wrapper.getIntegerOption("next");
Optional<Integer> positiveNext = next.map(integer -> 0 < integer ? integer : 0);
positiveNext.ifPresent(settings::setNextBoxCount);
return Optional.of(settings);
}
use of javax.activation.UnsupportedDataTypeException in project open-ecard by ecsec.
the class PACETest method executePACE_PIN.
@Test(enabled = false)
public void executePACE_PIN() throws UnsupportedDataTypeException, JAXBException, SAXException, WSMarshallerException {
ClientEnv env = new ClientEnv();
MessageDispatcher dispatcher = new MessageDispatcher(env);
IFD ifd = new IFD();
SwingUserConsent gui = new SwingUserConsent(new SwingDialogWrapper());
ifd.setGUI(gui);
env.setIFD(ifd);
env.setDispatcher(dispatcher);
ifd.addProtocol(ECardConstants.Protocol.PACE, new PACEProtocolFactory());
EstablishContext eCtx = new EstablishContext();
byte[] ctxHandle = ifd.establishContext(eCtx).getContextHandle();
ListIFDs listIFDs = new ListIFDs();
listIFDs.setContextHandle(ctxHandle);
String ifdName = ifd.listIFDs(listIFDs).getIFDName().get(0);
Connect connect = new Connect();
connect.setContextHandle(ctxHandle);
connect.setIFDName(ifdName);
connect.setSlot(BigInteger.ZERO);
byte[] slotHandle = ifd.connect(connect).getSlotHandle();
// PinID: 02 = CAN, 03 = PIN
String xmlCall = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<iso:EstablishChannel xmlns:iso=\"urn:iso:std:iso-iec:24727:tech:schema\">\n" + " <iso:SlotHandle>" + ByteUtils.toHexString(slotHandle) + "</iso:SlotHandle>\n" + " <iso:AuthenticationProtocolData Protocol=\"urn:oid:0.4.0.127.0.7.2.2.4\">\n" + " <iso:PinID>02</iso:PinID>\n" + " <iso:CHAT>7f4c12060904007f0007030102025305300301ffb7</iso:CHAT>\n" + // Remove PIN element to active the GUI
" <iso:PIN>142390</iso:PIN>\n" + // + " <iso:PIN>123456</iso:PIN>\n"
" </iso:AuthenticationProtocolData>\n" + "</iso:EstablishChannel>";
WSMarshaller m = WSMarshallerFactory.createInstance();
EstablishChannel eCh = (EstablishChannel) m.unmarshal(m.str2doc(xmlCall));
EstablishChannelResponse eChR = ifd.establishChannel(eCh);
LOG.info("PACE result: {}", eChR.getResult().getResultMajor());
try {
LOG.info("{}", eChR.getResult().getResultMinor());
LOG.info("{}", eChR.getResult().getResultMessage().getValue());
} catch (Exception ignore) {
}
}
Aggregations