1 package org.opensync.engine.server.adapter;
2
3 import java.io.IOException;
4
5 import javax.xml.parsers.ParserConfigurationException;
6
7 import org.dom4j.DocumentException;
8 import org.opensync.engine.server.OpenSync;
9 import org.opensync.engine.server.Statistic;
10 import org.opensync.engine.server.View;
11 import org.opensync.engine.server.Window;
12 import org.xml.sax.SAXException;
13
14 public class EDI_X12_Adapter extends FileAdapter {
15
16 static OpenSync openSync = OpenSync.getInstance();
17 /****/
18 public EDI_X12_Adapter() {
19 }
20
21 /***
22 * @param txt ?xml?
23 * @param view
24 * @exception Exception
25 */
26 public String adaptInputView(String txt,View view, Statistic stat, Window win)throws Exception{
27 String fileSeparator = System.getProperty("file.separator");
28 String configFolder = System.getProperty("opensync.configfolder");
29 configFolder = (configFolder == null ? "" : configFolder);
30
31 String descriptorFileName = view.getDescriptor();
32 String fulldescriptorFileName = openSync.getFilePath(
33 fileSeparator+ "etc"+fileSeparator+configFolder+fileSeparator+"descript"+fileSeparator + descriptorFileName ,true
34 );
35 EdiX128402Xml ediX128402xml = new EdiX128402Xml();
36 ediX128402xml.readDescriptor(fulldescriptorFileName);
37 return ediX128402xml.parseTxt(txt);
38
39 }
40
41 /***
42 * @param xml
43 * @param view
44 * @exception IOException
45 * @exception DocumentException
46 * @exception SAXException
47 * @exception ParserConfigurationException
48 */
49 public String adaptOutputView(String xml,View view, Statistic stat)
50 throws IOException,SAXException, ParserConfigurationException {
51 String fileSeparator = System.getProperty("file.separator");
52 String configFolder = System.getProperty("opensync.configfolder");
53 configFolder = (configFolder == null ? "" : configFolder);
54
55 String descriptorFileName = view.getDescriptor();
56 String fulldescriptorFileName = openSync.getFilePath(
57 fileSeparator+"etc"+fileSeparator+configFolder+fileSeparator+"descript"+fileSeparator + descriptorFileName ,true
58 );
59 Xml2EdiX12840 xml2EdiX12840 = new Xml2EdiX12840();
60 xml2EdiX12840.readDescriptor(fulldescriptorFileName);
61 return xml2EdiX12840.parseXml(xml);
62 }
63
64
65 /****/
66 public String toString(){
67 StringBuffer buffer = new StringBuffer();
68 buffer.append("EDI_X12_Adapter{\n");
69 buffer.append("}\n");
70 return buffer.toString();
71 }
72
73 }