Search in sources :

Example 1 with IDocSegment

use of com.sap.conn.idoc.IDocSegment in project iaf by ibissource.

the class IdocXmlHandler method endElement.

public void endElement(String uri, String localName, String qName) throws SAXException {
    // log.debug("endElement("+localName+")");
    if (currentField != null) {
        String value = currentFieldValue.toString().trim();
        if (StringUtils.isNotEmpty(value)) {
            if (parsingEdiDcHeader) {
                if (log.isDebugEnabled())
                    log.debug("parsed header field [" + currentField + "] value [" + value + "]");
                try {
                    if (currentField.equals("ARCKEY")) {
                        doc.setArchiveKey(value);
                    } else if (currentField.equals("MANDT")) {
                        doc.setClient(value);
                    } else if (currentField.equals("CREDAT")) {
                        doc.setCreationDate(value);
                    } else if (currentField.equals("CRETIM")) {
                        doc.setCreationTime(value);
                    } else if (currentField.equals("DIRECT")) {
                        doc.setDirection(value);
                    } else if (currentField.equals("REFMES")) {
                        doc.setEDIMessage(value);
                    } else if (currentField.equals("REFGRP")) {
                        doc.setEDIMessageGroup(value);
                    } else if (currentField.equals("STDMES")) {
                        doc.setEDIMessageType(value);
                    } else if (currentField.equals("STD")) {
                        doc.setEDIStandardFlag(value);
                    } else if (currentField.equals("STDVRS")) {
                        doc.setEDIStandardVersion(value);
                    } else if (currentField.equals("REFINT")) {
                        doc.setEDITransmissionFile(value);
                    } else // else if (currentField.equals("EXPRSS")) { doc.setExpressFlag(value); }
                    if (currentField.equals("DOCTYP")) {
                        doc.setIDocCompoundType(value);
                    } else if (currentField.equals("DOCNUM")) {
                        doc.setIDocNumber(value);
                    } else if (currentField.equals("DOCREL")) {
                        doc.setIDocSAPRelease(value);
                    } else if (currentField.equals("IDOCTYP")) {
                        doc.setIDocType(value);
                    } else if (currentField.equals("CIMTYP")) {
                        doc.setIDocTypeExtension(value);
                    } else if (currentField.equals("MESCOD")) {
                        doc.setMessageCode(value);
                    } else if (currentField.equals("MESFCT")) {
                        doc.setMessageFunction(value);
                    } else if (currentField.equals("MESTYP")) {
                        doc.setMessageType(value);
                    } else if (currentField.equals("OUTMOD")) {
                        doc.setOutputMode(value);
                    } else if (currentField.equals("RCVSAD")) {
                        doc.setRecipientAddress(value);
                    } else if (currentField.equals("RCVLAD")) {
                        doc.setRecipientLogicalAddress(value);
                    } else if (currentField.equals("RCVPFC")) {
                        doc.setRecipientPartnerFunction(value);
                    } else if (currentField.equals("RCVPRN")) {
                        doc.setRecipientPartnerNumber(value);
                    } else if (currentField.equals("RCVPRT")) {
                        doc.setRecipientPartnerType(value);
                    } else if (currentField.equals("RCVPOR")) {
                        doc.setRecipientPort(value);
                    } else if (currentField.equals("SNDSAD")) {
                        doc.setSenderAddress(value);
                    } else if (currentField.equals("SNDLAD")) {
                        doc.setSenderLogicalAddress(value);
                    } else if (currentField.equals("SNDPFC")) {
                        doc.setSenderPartnerFunction(value);
                    } else if (currentField.equals("SNDPRN")) {
                        doc.setSenderPartnerNumber(value);
                    } else if (currentField.equals("SNDPRT")) {
                        doc.setSenderPartnerType(value);
                    } else if (currentField.equals("SNDPOR")) {
                        doc.setSenderPort(value);
                    } else if (currentField.equals("SERIAL")) {
                        doc.setSerialization(value);
                    } else if (currentField.equals("STATUS")) {
                        doc.setStatus(value);
                    } else if (currentField.equals("TEST")) {
                        doc.setTestFlag(value);
                    } else {
                        log.warn("header field [" + currentField + "] value [" + value + "] discarded");
                    }
                } catch (IDocConversionException e) {
                    throw new SAXException("could not parse header field, idoc conversion exception", e);
                } catch (IDocSyntaxException e) {
                    throw new SAXException("could not parse header field, idoc syntax exception", e);
                }
            } else {
                IDocSegment segment = (IDocSegment) segmentStack.get(segmentStack.size() - 1);
                if (log.isDebugEnabled())
                    log.debug("setting field [" + currentField + "] to [" + value + "]");
                try {
                    segment.setValue(currentField, value);
                } catch (IDocFieldNotFoundException e) {
                    throw new SAXException("could not set field [" + currentField + "] to [" + value + "], idoc field not found", e);
                } catch (IDocConversionException e) {
                    throw new SAXException("could not set field [" + currentField + "] to [" + value + "], idoc conversion exception", e);
                } catch (IDocSyntaxException e) {
                    throw new SAXException("could not set field [" + currentField + "] to [" + value + "], idoc syntax exception", e);
                }
            }
        }
        currentField = null;
        currentFieldValue.setLength(0);
    } else {
        if (parsingEdiDcHeader) {
            parsingEdiDcHeader = false;
        } else {
            if (segmentStack.size() > 0) {
                segmentStack.remove(segmentStack.size() - 1);
            }
        }
    }
}
Also used : IDocSegment(com.sap.conn.idoc.IDocSegment) IDocFieldNotFoundException(com.sap.conn.idoc.IDocFieldNotFoundException) IDocConversionException(com.sap.conn.idoc.IDocConversionException) IDocSyntaxException(com.sap.conn.idoc.IDocSyntaxException) SAXException(org.xml.sax.SAXException)

Example 2 with IDocSegment

use of com.sap.conn.idoc.IDocSegment in project iaf by ibissource.

the class IdocXmlHandler method startElement.

public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    // log.debug("startElement("+localName+")");
    if (doc == null) {
        log.debug("creating Idoc [" + localName + "]");
        try {
            doc = JCoIDoc.getIDocFactory().createIDocDocument(sapSystem.getIDocRepository(), localName);
        } catch (IDocMetaDataUnavailableException e) {
            throw new SAXException("could not create idoc document, idoc meta data unavailable", e);
        } catch (JCoException e) {
            throw new SAXException("could not create idoc document", e);
        }
        IDocSegment segment = doc.getRootSegment();
        segmentStack.add(segment);
    } else {
        if (attributes.getIndex("SEGMENT") >= 0) {
            if (localName.startsWith("EDI_DC")) {
                parsingEdiDcHeader = true;
            } else {
                log.debug("creating segment [" + localName + "]");
                IDocSegment parentSegment = (IDocSegment) segmentStack.get(segmentStack.size() - 1);
                IDocSegment segment;
                try {
                    segment = parentSegment.addChild(localName);
                } catch (IDocIllegalTypeException e) {
                    throw new SAXException("could not parse segment, idoc illegal type", e);
                } catch (IDocMetaDataUnavailableException e) {
                    throw new SAXException("could not parse segment, idoc meta data unavailable", e);
                }
                segmentStack.add(segment);
            }
        } else {
            currentField = localName;
        }
    }
}
Also used : IDocSegment(com.sap.conn.idoc.IDocSegment) IDocIllegalTypeException(com.sap.conn.idoc.IDocIllegalTypeException) JCoException(com.sap.conn.jco.JCoException) IDocMetaDataUnavailableException(com.sap.conn.idoc.IDocMetaDataUnavailableException) SAXException(org.xml.sax.SAXException)

Aggregations

IDocSegment (com.sap.conn.idoc.IDocSegment)2 SAXException (org.xml.sax.SAXException)2 IDocConversionException (com.sap.conn.idoc.IDocConversionException)1 IDocFieldNotFoundException (com.sap.conn.idoc.IDocFieldNotFoundException)1 IDocIllegalTypeException (com.sap.conn.idoc.IDocIllegalTypeException)1 IDocMetaDataUnavailableException (com.sap.conn.idoc.IDocMetaDataUnavailableException)1 IDocSyntaxException (com.sap.conn.idoc.IDocSyntaxException)1 JCoException (com.sap.conn.jco.JCoException)1