Package org.milyn.edisax.model.internal

Examples of org.milyn.edisax.model.internal.Delimiters


* @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a>
*/
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


     * Digest attributes of Delimiter element and populate Delimiter.
     * @param node the Delimiter element.
     * @param edimap the {@link org.milyn.edisax.model.internal.Edimap} to populate.
     */
    private static void digestDelimiters(Node node, Edimap edimap) {
        Delimiters delimiters = new Delimiters();
        edimap.setDelimiters(delimiters);
        delimiters.setSegment(getAttributeValue(node, "segment"));
        delimiters.setField(getAttributeValue(node, "field"));
        delimiters.setFieldRepeat(getAttributeValue(node, "fieldRepeat"));
        delimiters.setComponent(getAttributeValue(node, "component"));
        delimiters.setSubComponent(getAttributeValue(node, "sub-component"));
        delimiters.setEscape(getAttributeValue(node, "escape"));
        delimiters.setDecimalSeparator(getAttributeValue(node, "decimalSeparator"));
    }
View Full Code Here

        decimalFormat.setParseBigDecimal(true);
    }

    protected Delimiters getContextDelimiters() {
        ExecutionContext ec = Filter.getCurrentExecutionContext();
        Delimiters delimiters = null;

        if (ec != null) {
            delimiters = ec.getBeanContext().getBean(Delimiters.class);
        }
View Full Code Here


  }

    public void test_concatAndTruncate() {
        Delimiters delims = UNEdifactInterchangeParser.defaultUNEdifactDelimiters;

        assertEquals("ab", EDIUtils.concatAndTruncate(CollectionsUtil.toList("a", "b", "+:+"), DelimiterType.SEGMENT, delims));
        assertEquals("a+:+b", EDIUtils.concatAndTruncate(CollectionsUtil.toList("a", "+:+", "b", "+:+"), DelimiterType.SEGMENT, delims));
        assertEquals("a+:+bc+:+", EDIUtils.concatAndTruncate(CollectionsUtil.toList("a", "+:+", "b", "c+:+"), DelimiterType.SEGMENT, delims));
View Full Code Here

    assertEquals("All segments not read.", segments.length, segIndex);
  }

    private BufferedSegmentReader createSegmentReader(String input, String segmentDelim, String fieldDelim) {
        InputSource inputSource = new InputSource(new ByteArrayInputStream(input.getBytes()));
        Delimiters delimiters = new Delimiters().setSegment(segmentDelim).setField(fieldDelim);
        BufferedSegmentReader reader = new BufferedSegmentReader(inputSource, delimiters);
        return reader;
    }
View Full Code Here

        Description description = new Description();
        description.setName("Custom Config Reader");
        description.setVersion("1.0");
        edimap.setDescription(description);

        Delimiters delimiters = new Delimiters();
        delimiters.setSegment("'");
        delimiters.setField("+");
        delimiters.setComponent(":");
        delimiters.setSubComponent("^");
        delimiters.setEscape("?");
        edimap.setDelimiters(delimiters);

        SegmentGroup root = new SegmentGroup();
        root.setXmltag("Root");
        edimap.setSegments(root);
View Full Code Here

    // Iterate over the fields and map them...
        int numFields = currentSegmentFields.length - 1; // It's "currentSegmentFields.length - 1" because we don't want to include the segment code.
        int numFieldsMapped = segment.getFields().size();
        boolean ignoreUnmappedFields = segment.isIgnoreUnmappedFields();
        Delimiters delimiters = segmentReader.getDelimiters();
        String fieldRepeat = delimiters.getFieldRepeat();
    for(int i = 0; i < numFields; i++) {
      if (ignoreUnmappedFields && i >= numFieldsMapped) {
                break;
            }
      String fieldMessageVal = currentSegmentFields[i + 1]; // +1 to skip the segment code
      Field expectedField = expectedFields.get(i);

      if(fieldRepeat != null) {
        String[] repeatedFields = EDIUtils.split(fieldMessageVal, fieldRepeat, delimiters.getEscape());
        for(String repeatedField : repeatedFields) {
          mapField(repeatedField, expectedField, i, segmentCode);
        }
      } else {     
        mapField(fieldMessageVal, expectedField, i, segmentCode);
View Full Code Here

  private void mapField(String fieldMessageVal, Field expectedField, int fieldIndex, String segmentCode) throws SAXException {
    List<Component> expectedComponents = expectedField.getComponents();

    // If there are components defined on this field...
    if(expectedComponents.size() != 0) {
            Delimiters delimiters = segmentReader.getDelimiters();
      String[] currentFieldComponents = EDIUtils.split(fieldMessageVal, delimiters.getComponent(), delimiters.getEscape());

            assertComponentsOK(expectedField, fieldIndex, segmentCode, expectedComponents, currentFieldComponents);

            if (currentFieldComponents.length > 0 || !ignoreEmptyNodes()) {
              startElement(expectedField, true);
View Full Code Here

   */
  private void mapComponent(String componentMessageVal, Component expectedComponent, int fieldIndex, int componentIndex, String segmentCode, String field) throws SAXException {
    List<SubComponent> expectedSubComponents = expectedComponent.getSubComponents();

    if(expectedSubComponents.size() != 0) {
            Delimiters delimiters = segmentReader.getDelimiters();
      String[] currentComponentSubComponents = EDIUtils.split(componentMessageVal, delimiters.getSubComponent(), delimiters.getEscape());

            assertSubComponentsOK(expectedComponent, fieldIndex, componentIndex, segmentCode, field, expectedSubComponents, currentComponentSubComponents);

            if (currentComponentSubComponents.length > 0 || !ignoreEmptyNodes()) {
                startElement(expectedComponent, true);
View Full Code Here

            edimap = new Edimap();
            SegmentGroup rootGroup = new SegmentGroup();
            rootGroup.setXmltag(XmlTagEncoder.encode(type));
            edimap.setSegments(rootGroup);

            Delimiters delimiters = new Delimiters();
            delimiters.setSegment(DELIMITER_SEGMENT);
            delimiters.setField(DELIMITER_COMPOSITE);
            delimiters.setComponent(DELIMITER_DATA);
            delimiters.setSubComponent(DELIMITER_NOT_USED);
            delimiters.setEscape(ESCAPE);
            edimap.setDelimiters(delimiters);

            edimap.setDescription(new Description());
            edimap.getDescription().setName(type);
            edimap.getDescription().setVersion(version + ":" + release + ":" + agency);
View Full Code Here

TOP

Related Classes of org.milyn.edisax.model.internal.Delimiters

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.