@Test public void testFileOutputEncoding() { try { configProps.put(Cob2XsdConfig.XSD_ENCODING, "UTF-8"); configProps.put(Cob2XsdConfig.ADD_LEGSTAR_ANNOTATIONS, Boolean.toString(true)); Cob2XsdIO cob2xsd = new Cob2XsdIO(new Cob2XsdConfig(configProps)); File tempCobolFile = File.createTempFile("test", ".cob"); tempCobolFile.deleteOnExit(); FileUtils.write(tempCobolFile, " 01 A.\n 02 B PIC G(4) VALUE '牛年快乐'.", "UTF8"); File xmlSchema = cob2xsd.translate(tempCobolFile, "UTF8", tempDir, "http: for (String line : FileUtils.readLines(xmlSchema, "UTF8")) { if (line.contains("cobolName=\"B\"")) { assertTrue(line.contains("value=\"牛年快乐\"")); } } xmlSchema.deleteOnExit(); } catch (Exception e) { e.printStackTrace(); fail(); } }
public File translate(final File cobolFile, final String cobolFileEncoding, final File target, final String targetNamespacePrefix, final String xsltFileName) throws RecognizerException, XsdGenerationException { try { if (_log.isDebugEnabled()) { _log.debug("Translating COBOL file: " + cobolFile); } checkCobolSourceFile(cobolFile); checkTarget(target); String baseName = FilenameUtils.getBaseName( cobolFile.getAbsolutePath()).toLowerCase(); Reader cobolReader = cobolFileEncoding == null ? new InputStreamReader( new FileInputStream(cobolFile)) : new InputStreamReader( new FileInputStream(cobolFile), cobolFileEncoding); String xsdString = translate(cobolReader, getUniqueTargetNamespace(targetNamespacePrefix, baseName), xsltFileName); File xsdFile = null; if (target.isDirectory()) { String xsdFileName = cobolFile.getName() + ".xsd"; xsdFile = new File(target, xsdFileName); } else { xsdFile = target; } FileUtils.writeStringToFile(xsdFile, xsdString, getConfig() .getXsdEncoding()); if (_log.isDebugEnabled()) { _log.debug("Created XML schema file: " + xsdFile); } return xsdFile; } catch (IOException e) { throw (new XsdGenerationException(e)); } }
Cob2XsdIO extends Cob2Xsd { public File translate(final File cobolFile, final String cobolFileEncoding, final File target, final String targetNamespacePrefix, final String xsltFileName) throws RecognizerException, XsdGenerationException { try { if (_log.isDebugEnabled()) { _log.debug("Translating COBOL file: " + cobolFile); } checkCobolSourceFile(cobolFile); checkTarget(target); String baseName = FilenameUtils.getBaseName( cobolFile.getAbsolutePath()).toLowerCase(); Reader cobolReader = cobolFileEncoding == null ? new InputStreamReader( new FileInputStream(cobolFile)) : new InputStreamReader( new FileInputStream(cobolFile), cobolFileEncoding); String xsdString = translate(cobolReader, getUniqueTargetNamespace(targetNamespacePrefix, baseName), xsltFileName); File xsdFile = null; if (target.isDirectory()) { String xsdFileName = cobolFile.getName() + ".xsd"; xsdFile = new File(target, xsdFileName); } else { xsdFile = target; } FileUtils.writeStringToFile(xsdFile, xsdString, getConfig() .getXsdEncoding()); if (_log.isDebugEnabled()) { _log.debug("Created XML schema file: " + xsdFile); } return xsdFile; } catch (IOException e) { throw (new XsdGenerationException(e)); } } }
Cob2XsdIO extends Cob2Xsd { public File translate(final File cobolFile, final String cobolFileEncoding, final File target, final String targetNamespacePrefix, final String xsltFileName) throws RecognizerException, XsdGenerationException { try { if (_log.isDebugEnabled()) { _log.debug("Translating COBOL file: " + cobolFile); } checkCobolSourceFile(cobolFile); checkTarget(target); String baseName = FilenameUtils.getBaseName( cobolFile.getAbsolutePath()).toLowerCase(); Reader cobolReader = cobolFileEncoding == null ? new InputStreamReader( new FileInputStream(cobolFile)) : new InputStreamReader( new FileInputStream(cobolFile), cobolFileEncoding); String xsdString = translate(cobolReader, getUniqueTargetNamespace(targetNamespacePrefix, baseName), xsltFileName); File xsdFile = null; if (target.isDirectory()) { String xsdFileName = cobolFile.getName() + ".xsd"; xsdFile = new File(target, xsdFileName); } else { xsdFile = target; } FileUtils.writeStringToFile(xsdFile, xsdString, getConfig() .getXsdEncoding()); if (_log.isDebugEnabled()) { _log.debug("Created XML schema file: " + xsdFile); } return xsdFile; } catch (IOException e) { throw (new XsdGenerationException(e)); } } Cob2XsdIO(final Cob2XsdConfig config); }
Cob2XsdIO extends Cob2Xsd { public File translate(final File cobolFile, final String cobolFileEncoding, final File target, final String targetNamespacePrefix, final String xsltFileName) throws RecognizerException, XsdGenerationException { try { if (_log.isDebugEnabled()) { _log.debug("Translating COBOL file: " + cobolFile); } checkCobolSourceFile(cobolFile); checkTarget(target); String baseName = FilenameUtils.getBaseName( cobolFile.getAbsolutePath()).toLowerCase(); Reader cobolReader = cobolFileEncoding == null ? new InputStreamReader( new FileInputStream(cobolFile)) : new InputStreamReader( new FileInputStream(cobolFile), cobolFileEncoding); String xsdString = translate(cobolReader, getUniqueTargetNamespace(targetNamespacePrefix, baseName), xsltFileName); File xsdFile = null; if (target.isDirectory()) { String xsdFileName = cobolFile.getName() + ".xsd"; xsdFile = new File(target, xsdFileName); } else { xsdFile = target; } FileUtils.writeStringToFile(xsdFile, xsdString, getConfig() .getXsdEncoding()); if (_log.isDebugEnabled()) { _log.debug("Created XML schema file: " + xsdFile); } return xsdFile; } catch (IOException e) { throw (new XsdGenerationException(e)); } } Cob2XsdIO(final Cob2XsdConfig config); File translate(final File cobolFile, final String cobolFileEncoding,
            final File target, final String targetNamespacePrefix,
            final String xsltFileName); }
Cob2XsdIO extends Cob2Xsd { public File translate(final File cobolFile, final String cobolFileEncoding, final File target, final String targetNamespacePrefix, final String xsltFileName) throws RecognizerException, XsdGenerationException { try { if (_log.isDebugEnabled()) { _log.debug("Translating COBOL file: " + cobolFile); } checkCobolSourceFile(cobolFile); checkTarget(target); String baseName = FilenameUtils.getBaseName( cobolFile.getAbsolutePath()).toLowerCase(); Reader cobolReader = cobolFileEncoding == null ? new InputStreamReader( new FileInputStream(cobolFile)) : new InputStreamReader( new FileInputStream(cobolFile), cobolFileEncoding); String xsdString = translate(cobolReader, getUniqueTargetNamespace(targetNamespacePrefix, baseName), xsltFileName); File xsdFile = null; if (target.isDirectory()) { String xsdFileName = cobolFile.getName() + ".xsd"; xsdFile = new File(target, xsdFileName); } else { xsdFile = target; } FileUtils.writeStringToFile(xsdFile, xsdString, getConfig() .getXsdEncoding()); if (_log.isDebugEnabled()) { _log.debug("Created XML schema file: " + xsdFile); } return xsdFile; } catch (IOException e) { throw (new XsdGenerationException(e)); } } Cob2XsdIO(final Cob2XsdConfig config); File translate(final File cobolFile, final String cobolFileEncoding,
            final File target, final String targetNamespacePrefix,
            final String xsltFileName);  }