Package de.ddb.conversion

Examples of de.ddb.conversion.Converter


            logger.debug("main(String[]) - start");
        }
        parseArgs(args);
        try {
          ConversionContext ctx = ConversionContextFactory.newDefaultEnvironment();
          Converter c = new BinaryConverter(fcvprogrampath + " "
                                            + fcvtablepath + " mab", new ArrayList<String>(0), "x-PICA", "x-PICA", 0);
          c.getConverterContext().setSourceEncoding("x-PICA");
          c.getConverterContext().setTargetEncoding("x-PICA");
          c.getConverterContext().setSourceFormat(ctx.getFormat(ConversionContextFactory.DOCFORMATNAME_PICAPLUS));
          c.getConverterContext().setTargetFormat(ctx.getFormat(ConversionContextFactory.DOCFORMATNAME_MABXML1));
          ctx.addConverter(c);
           
            if (logger.isDebugEnabled()) {
                logger.debug("main() - starting conversion");
            }
            // StringBuffer input = new StringBuffer();
            // int i;
            // while ((i = in.read()) != -1) {
            // input.append((char) i);
            // }
            // String output = new MabToMabxmlConverter().convert(picaToMab
            // .convert(input.substring(0), report), report);
            // out.write(output);
            // if (logger.isDebugEnabled()) {
            // logger.debug("main() - finished conversion. output = " + output);
            // }
            Converter mab2Mabxml = ctx.addConverter(new MabToMabxmlConverter());
            ConversionParameters params = new ConversionParameters();
            mab2Mabxml.convert(c.convert(in, params),
                    out);
            if (logger.isDebugEnabled()) {
                logger.debug("main() - finished conversion.");
            }
        } finally {
View Full Code Here


        .getConversionContext().getConverters().getJavaConverterList();
    for (final de.ddb.conversion.context.xml.JavaConverter jc : javaConverters) {
      for (final String sf : jc.getSourceFormatList()) {
        for (final String tf : jc.getTargetFormatList()) {
          try {
            final Converter converter = (Converter) Class.forName(
                jc.getClassName()).newInstance();

            Properties converterProps = null;
            if (jc.isSetProperties()) {
              final List<Property> props = jc.getProperties()
                  .getPropertyList();
              if (!props.isEmpty()) {
                converterProps = new Properties();
                for (final Property prop : props) {
                  if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Found property ["
                        + prop.getKey() + "] = "
                        + prop.getStringValue());
                  }
                  converterProps.setProperty(prop.getKey(),
                      prop.getStringValue());
                }
              }
            }
            context.addConverter(converter, sf, tf,
                jc.getSourceEncoding(), jc.getTargetEncoding(),
                converterProps);
          } catch (final ClassNotFoundException e) {
            LOGGER.error("Could not find class: "
                + jc.getClassName());
            if (LOGGER.isDebugEnabled()) {
              LOGGER.debug(e, e);
            }
          } catch (final InstantiationException e) {
            LOGGER.error("Could not instantiate converter: "
                + jc.getClassName());
            if (LOGGER.isDebugEnabled()) {
              LOGGER.debug(e, e);
            }
          } catch (final IllegalAccessException e) {
            LOGGER.error("Could not access converter: "
                + jc.getClassName());
            if (LOGGER.isDebugEnabled()) {
              LOGGER.debug(e, e);
            }
          } catch (final Exception e) {
            LOGGER.error("Unknown exception: " + jc.getClassName()
                + " : " + e.getMessage());
            if (LOGGER.isDebugEnabled()) {
              LOGGER.debug(e, e);
            }
          }
        }
      }
    }

    /*
     * set piped converters
     */
    final List<de.ddb.conversion.context.xml.PipedConverter> pipedConverters = contextDocument
        .getConversionContext().getConverters().getPipedConverterList();
    for (final de.ddb.conversion.context.xml.PipedConverter pc : pipedConverters) {
      try {
        Properties converterProps = null;
        if (pc.isSetProperties()) {
          final List<Property> props = pc.getProperties()
              .getPropertyList();
          if (!props.isEmpty()) {
            converterProps = new Properties();
            for (final Property prop : props) {
              converterProps.setProperty(prop.getKey(),
                  prop.xmlText());
            }
          }
        }
        if (pc.getSourceFormatList().isEmpty()) {
          throw new ConverterInitializationException(
              "Missing source format to initialize piped converter.");
        }
        if (pc.getTargetFormatList().isEmpty()) {
          throw new ConverterInitializationException(
              "Missing target format to initialize piped converter.");
        }
        final Converter c1 = context.getConverter(pc
            .getSourceFormatList().get(0), pc
            .getIntermediateFormat(), pc.getSourceEncoding(), pc
            .getIntermediateEncoding());
        final Converter c2 = context.getConverter(pc
            .getIntermediateFormat(),
            pc.getTargetFormatList().get(0), pc
                .getIntermediateEncoding(), pc
                .getTargetEncoding());
        final PipedConverter c = new PipedConverter(c1, c2);
View Full Code Here

TOP

Related Classes of de.ddb.conversion.Converter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.