Search in sources :

Example 1 with UnsupportedDataTypeException

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);
}
Also used : TetfuPage(common.tetfu.TetfuPage) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) Files(java.nio.file.Files) org.apache.commons.cli(org.apache.commons.cli) FrameType(util.fig.FrameType) IOException(java.io.IOException) Tetfu(common.tetfu.Tetfu) FinderParseException(exceptions.FinderParseException) ColorConverter(common.tetfu.common.ColorConverter) Collectors(java.util.stream.Collectors) List(java.util.List) MinoFactory(core.mino.MinoFactory) Charset(java.nio.charset.Charset) Paths(java.nio.file.Paths) Optional(java.util.Optional) UnsupportedDataTypeException(javax.activation.UnsupportedDataTypeException) CommandLineWrapper(entry.CommandLineWrapper) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) FrameType(util.fig.FrameType) UnsupportedDataTypeException(javax.activation.UnsupportedDataTypeException) Path(java.nio.file.Path) Charset(java.nio.charset.Charset) IOException(java.io.IOException) FinderParseException(exceptions.FinderParseException) NormalCommandLineWrapper(entry.NormalCommandLineWrapper) CommandLineWrapper(entry.CommandLineWrapper)

Example 2 with UnsupportedDataTypeException

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) {
    }
}
Also used : ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) IFD(org.openecard.ifd.scio.IFD) Connect(iso.std.iso_iec._24727.tech.schema.Connect) EstablishChannelResponse(iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) UnsupportedDataTypeException(javax.activation.UnsupportedDataTypeException) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) ClientEnv(org.openecard.common.ClientEnv) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) EstablishChannel(iso.std.iso_iec._24727.tech.schema.EstablishChannel) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) Test(org.testng.annotations.Test)

Aggregations

UnsupportedDataTypeException (javax.activation.UnsupportedDataTypeException)2 Tetfu (common.tetfu.Tetfu)1 TetfuPage (common.tetfu.TetfuPage)1 ColorConverter (common.tetfu.common.ColorConverter)1 MinoFactory (core.mino.MinoFactory)1 CommandLineWrapper (entry.CommandLineWrapper)1 NormalCommandLineWrapper (entry.NormalCommandLineWrapper)1 FinderParseException (exceptions.FinderParseException)1 Connect (iso.std.iso_iec._24727.tech.schema.Connect)1 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)1 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)1 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)1 ListIFDs (iso.std.iso_iec._24727.tech.schema.ListIFDs)1 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1