View Javadoc
1   /*
2    * Copyright (C) 2010-2014 Hamburg Sud and the contributors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.aludratest.content.edifact;
17  
18  import java.io.InputStream;
19  import java.io.OutputStream;
20  import java.util.Map;
21  
22  import javax.xml.namespace.QName;
23  
24  import org.aludratest.content.ContentHandler;
25  import org.databene.edifatto.ComparisonSettings;
26  import org.databene.edifatto.EdiFormatSymbols;
27  import org.databene.edifatto.compare.AggregateDiff;
28  import org.databene.edifatto.compare.ComparisonModel;
29  import org.databene.edifatto.model.Interchange;
30  import org.w3c.dom.Element;
31  
32  /**
33   * Parses and saves EDIFACT and X12 documents from and to streams.
34   * @author Volker Bergmann
35   */
36  public interface EdifactContent extends ContentHandler {
37  
38      /** Parses an EDIFACT or X12 interchange available in an {@link InputStream}. 
39       *  @param in  the {@link InputStream} from which to read the EDI document
40       *  @return an object representation of the EDI {@link Interchange} */
41      Interchange readInterchange(InputStream in);
42  
43      /** Writes an EDIFACT or X12 interchange to an {@link OutputStream}. 
44       *  @param interchange the EDI {@link Interchange} to write
45       *  @param out the {@link OutputStream} to write to 
46       *  @param linefeed */
47      void writeInterchange(Interchange interchange, OutputStream out, boolean linefeed);
48  
49      /** Uses a FreeMarker template to create an EDI message based on the content of a variables map.
50       *  @param templateUri
51       *  @param symbols
52       *  @param variables
53       *  @return an {@link Interchange} with the data configured in the variables map */
54      Interchange createInterchange(String templateUri, EdiFormatSymbols symbols, Map<String, Object> variables);
55  
56      /** 
57       * Creates an XML representation of the interchange and performs an XPath query on it.
58       * @param interchange the interchange to query
59       * @param expression the XPath query to perform
60       * @param returnType determines the type of the returned object: 
61       *   {@link javax.xml.xpath.XPathConstants#STRING} for a single {@link java.lang.String},
62       *   {@link javax.xml.xpath.XPathConstants#NODE} for a single {@link org.w3c.dom.Element},
63       *   {@link javax.xml.xpath.XPathConstants#NODESET} for a {@link org.w3c.dom.NodeList}
64       * @return the found nodes of the interchange in the form of XML elements
65       */
66      Object queryXML(Interchange interchange, String expression, QName returnType);
67  
68      /** Finds out the differences between two EDIFACT or X12 interchanges, 
69       *  ignoring elements that match the XPath exclusion paths.
70       *  @param expected 
71       *  @param actual 
72       *  @param settings 
73       *  @param model 
74       *  @return an aggregated diff of the documents */
75      AggregateDiff diff(Interchange expected, Interchange actual, 
76              ComparisonSettings settings, ComparisonModel<Element> model);
77  
78      /** Formats a full interchange structure recursively as String.
79       *  @param interchange the Edifact interchange to format
80       *  @return a string representation of the interchange */
81      String formatRecursively(Interchange interchange);
82  
83  }