Package org.milyn.edisax

Examples of org.milyn.edisax.BufferedSegmentReader


            throw new IllegalStateException("'mappingsRegistry' not set.  Cannot parse EDI stream.");
        }

        try {
            ControlBlockHandlerFactory handlerFactory = new UNEdifact41ControlBlockHandlerFactory(hierarchyChangeListener);
          BufferedSegmentReader segmentReader = new BufferedSegmentReader(unedifactInterchange, defaultUNEdifactDelimiters);
          boolean validate = getFeature(EDIParser.FEATURE_VALIDATE);
          String segCode;
         
          segmentReader.mark();
          segmentReader.setIgnoreNewLines(getFeature(EDIParser.FEATURE_IGNORE_NEWLINES));

          contentHandler.startDocument();
          AttributesImpl attrs = new AttributesImpl();
          attrs.addAttribute(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, ControlBlockHandlerFactory.ENVELOPE_PREFIX, XMLConstants.XMLNS_ATTRIBUTE + ":" + ControlBlockHandlerFactory.ENVELOPE_PREFIX, "CDATA", handlerFactory.getNamespace());
            String envElementQName = ControlBlockHandlerFactory.ENVELOPE_PREFIX + ":unEdifact";
            contentHandler.startElement(handlerFactory.getNamespace(), "unEdifact", envElementQName, attrs);
 
          while(true) {
            segCode = segmentReader.peek(3, true);
            if(segCode.length() == 3) {
                    interchangeContext = createInterchangeContext(segmentReader, validate, handlerFactory, namespaceDeclarationStack);
                    namespaceDeclarationStack = interchangeContext.getNamespaceDeclarationStack();

                    if(hierarchyChangeListener != null) {
View Full Code Here


*/
public class UNAHandler implements ControlBlockHandler {

  public void process(InterchangeContext interchangeContext) throws IOException, SAXException {
    Delimiters delimiters = new Delimiters();
    BufferedSegmentReader segmentReader = interchangeContext.getSegmentReader();

    // The UNA segment code is still in the segment buffer... clear it before
    // reading the segment delimiters...
    segmentReader.getSegmentBuffer().setLength(0);
   
    // Read the delimiter chars one-by-one and set in the Delimiters instance...
   
    // 1st char is the component ("sub-element") delimiter...
    delimiters.setComponent( segmentReader.read(1));
    // 2nd char is the field ("data-element") delimiter...
    delimiters.setField(     segmentReader.read(1));
    // 3rd char is the decimal point indicator...
    delimiters.setDecimalSeparator(segmentReader.read(1));
    // 4th char is the escape char ("release")...
    delimiters.setEscape(    segmentReader.read(1));
    // 5th char is reserved for future use...
    segmentReader.read(1);
    // 6th char is the segment delimiter...
    delimiters.setSegment(   segmentReader.read(1));

    interchangeContext.pushDelimiters(delimiters);
  }
View Full Code Here

        this.ungSegment = ungSegment;
        this.uneSegment = uneSegment;
    }

    public void process(InterchangeContext interchangeContext) throws IOException, SAXException {
    BufferedSegmentReader segmentReader = interchangeContext.getSegmentReader();

    interchangeContext.getControlSegmentParser().startElement("group", ungSegment.getNamespace(), true);

    segmentReader.moveToNextSegment(false);
    interchangeContext.mapControlSegment(ungSegment, true);

        while(true) {
          String segCode = segmentReader.peek(3, true);

          if(segCode.equals("UNE")) {
          segmentReader.moveToNextSegment(false);
          interchangeContext.mapControlSegment(uneSegment, true);
          break;
            } else if(segCode.length() > 0) {
            ControlBlockHandler handler = interchangeContext.getControlBlockHandler(segCode);
            handler.process(interchangeContext);
View Full Code Here

        this.unzSegment = unzSegment;
        this.toCharsetMapping = toCharsetMapping;
    }

    public void process(InterchangeContext interchangeContext) throws IOException, SAXException {
    BufferedSegmentReader segmentReader = interchangeContext.getSegmentReader();
   
    segmentReader.moveToNextSegment(false);
   
    String[] fields = segmentReader.getCurrentSegmentFields();
   
    interchangeContext.mapControlSegment(unbSegment, true);
   
    String[] syntaxIdComponents = EDIUtils.split(fields[1], segmentReader.getDelimiters().getComponent(), segmentReader.getDelimiters().getEscape());

    // First component (index 0) defines the char repertoire.  Fourth
    // component (index 3) is optional and can override...
    if(syntaxIdComponents.length < 4) {
      changeReadEncoding(syntaxIdComponents[0], interchangeContext.getSegmentReader());
    } else {
      changeReadEncoding(syntaxIdComponents[3], interchangeContext.getSegmentReader());
    }
   
        while(true) {
          String segCode = segmentReader.peek(3, true);

          if(segCode.equals("UNZ")) {
          segmentReader.moveToNextSegment(false);
          interchangeContext.mapControlSegment(unzSegment, true);
          break;
            } else if(segCode.length() > 0) {
            ControlBlockHandler handler = interchangeContext.getControlBlockHandler(segCode);
            handler.process(interchangeContext);
View Full Code Here

* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
public class GenericHandler implements ControlBlockHandler {

  public void process(InterchangeContext interchangeContext) throws IOException, SAXException {
    BufferedSegmentReader segmentReader = interchangeContext.getSegmentReader();
   
    segmentReader.moveToNextSegment(false);
   
    String[] fields = segmentReader.getCurrentSegmentFields();
    StringBuffer segBuffer = segmentReader.getSegmentBuffer();
    char[] segChars = new char[segBuffer.length()];
   
    segBuffer.getChars(0, segBuffer.length(), segChars, 0);
   
    interchangeContext.getControlSegmentParser().startElement(fields[0], interchangeContext.getNamespace(), true);
    interchangeContext.getControlSegmentParser().getContentHandler().characters(segChars, 0, segChars.length);
    interchangeContext.getControlSegmentParser().endElement(fields[0], interchangeContext.getNamespace(), false);

    // And clear out the buffer...
    segmentReader.getSegmentBuffer().setLength(0);
  }
View Full Code Here

        this.untSegment = untSegment;
        this.hierarchyChangeListener = hierarchyChangeListener;
    }

    public void process(InterchangeContext interchangeContext) throws IOException, SAXException {
    BufferedSegmentReader segmentReader = interchangeContext.getSegmentReader();
    MappingsRegistry registry = interchangeContext.getRegistry();

    // Move to the end of the UNH segment and map it's fields..
    segmentReader.moveToNextSegment(false);

    // Select the mapping model to use for this message...
    String[] fields = segmentReader.getCurrentSegmentFields();
    String messageName = fields[2];
    EdifactModel mappingModel = registry.getMappingModel(messageName, segmentReader.getDelimiters());
        Edimap ediMap = mappingModel.getEdimap();

        Description description = ediMap.getDescription();
        AttributesImpl attrs = new AttributesImpl();
        String namespace = description.getNamespace();
        String commonNS = null;
        String messageNSPrefix = null;
        if(namespace != null && !namespace.equals(XMLConstants.NULL_NS_URI)) {
            int nameComponentIndex = namespace.lastIndexOf(":");
            if(nameComponentIndex != -1) {
                commonNS = namespace.substring(0, nameComponentIndex) + ":common";
                messageNSPrefix = description.getName().toLowerCase();
                attrs.addAttribute(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "c", "xmlns:c", "CDATA", commonNS);
                attrs.addAttribute(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, messageNSPrefix, "xmlns:" + messageNSPrefix, "CDATA", namespace);
            }
        }

    interchangeContext.getControlSegmentParser().startElement(InterchangeContext.INTERCHANGE_MESSAGE_BLOCK_ELEMENT_NAME, unhSegment.getNamespace(), true, attrs);
        interchangeContext.mapControlSegment(unhSegment, false);

    // Map the message... stopping at the UNT segment...
    try {
      EDIParser parser = interchangeContext.newParser(mappingModel);

      segmentReader.setSegmentListener(untSegmentListener);

            if(hierarchyChangeListener != null) {
                hierarchyChangeListener.attachXMLReader(parser);
            } else if (!interchangeContext.isContainerManagedNamespaceStack()) {
                interchangeContext.getNamespaceDeclarationStack().pushReader(parser);
            }

            parser.parse();
    } finally {
      segmentReader.setSegmentListener(null);
            if(hierarchyChangeListener != null) {
                hierarchyChangeListener.detachXMLReader();
            } else if (!interchangeContext.isContainerManagedNamespaceStack()) {
                interchangeContext.getNamespaceDeclarationStack().popReader();
            }
    }

    // We're at the end of the UNT segment now.  See the UNTSegmentListener below.

    // Map the UNT segment...
    interchangeContext.mapControlSegment(untSegment, true);
    segmentReader.getSegmentBuffer().setLength(0);

    interchangeContext.getControlSegmentParser().endElement(InterchangeContext.INTERCHANGE_MESSAGE_BLOCK_ELEMENT_NAME, unhSegment.getNamespace(), true);
  }
View Full Code Here

TOP

Related Classes of org.milyn.edisax.BufferedSegmentReader

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.