001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.web3.impl;
018:
019: import com.sap.mw.jco.JCO;
020:
021: import org.apache.cocoon.components.web3.Web3Streamer;
022: import org.apache.cocoon.components.web3.Web3;
023:
024: import org.apache.avalon.excalibur.pool.Poolable;
025:
026: import org.xml.sax.SAXException;
027: import org.xml.sax.helpers.AttributesImpl;
028: import org.xml.sax.ContentHandler;
029:
030: /**
031: * TBD
032: *
033: * @author <a href="mailto:michael.gerzabek@at.efp.cc">Michael Gerzabek</a>
034: * @since 2.1
035: * @version CVS $Id: DefaultWeb3StreamerImpl.java 524407 2007-03-31 10:59:28Z joerg $
036: */
037: public class DefaultWeb3StreamerImpl implements Web3Streamer, Poolable {
038:
039: public void stream(JCO.Function function,
040: ContentHandler contentHandler) throws SAXException {
041:
042: AttributesImpl attributes = new AttributesImpl();
043: attributes.addAttribute(Web3.URI, Web3.INCLUDE_NAME_ATTR,
044: Web3.INCLUDE_NAME_ATTR, "CDATA", function.getName()
045: .toUpperCase());
046: contentHandler.startElement(Web3.URI, Web3.INCLUDE_ELEM,
047: Web3.INCLUDE_ELEM, attributes);
048: attributes.clear();
049: contentHandler.startElement(Web3.URI, Web3.IMPORT_ELEM,
050: Web3.IMPORT_ELEM, attributes);
051: streamParameterList(function.getImportParameterList(),
052: contentHandler);
053: contentHandler.endElement(Web3.URI, Web3.IMPORT_ELEM,
054: Web3.IMPORT_ELEM);
055:
056: attributes.clear();
057: contentHandler.startElement(Web3.URI, Web3.EXPORT_ELEM,
058: Web3.EXPORT_ELEM, attributes);
059: streamParameterList(function.getExportParameterList(),
060: contentHandler);
061: contentHandler.endElement(Web3.URI, Web3.EXPORT_ELEM,
062: Web3.EXPORT_ELEM);
063:
064: JCO.ParameterList tablesParameterList = function
065: .getTableParameterList();
066: attributes.clear();
067: contentHandler.startElement(Web3.URI, Web3.TABLES_ELEM,
068: Web3.TABLES_ELEM, attributes);
069: if (null != tablesParameterList) {
070: for (int i = 0; i < tablesParameterList.getFieldCount(); i++) {
071: attributes.clear();
072: attributes.addAttribute(Web3.URI, Web3.TABLE_NAME_ATTR,
073: Web3.TABLE_NAME_ATTR, "CDATA",
074: tablesParameterList.getName(i).toUpperCase());
075: contentHandler.startElement(Web3.URI, Web3.TABLE_ELEM,
076: Web3.TABLE_ELEM, attributes);
077: JCO.Table sapTable = tablesParameterList.getTable(i);
078: if (null != sapTable) {
079: for (int j = 0; j < sapTable.getNumRows(); j++) {
080: sapTable.setRow(j);
081: attributes.clear();
082: attributes.addAttribute(Web3.URI,
083: Web3.ROW_ID_ATTR, Web3.ROW_ID_ATTR,
084: "CDATA", "" + (j + 1));
085: contentHandler.startElement(Web3.URI,
086: Web3.ROW_ELEM, Web3.ROW_ELEM,
087: attributes);
088: for (int k = 0; k < sapTable.getFieldCount(); k++) {
089: attributes.clear();
090: attributes.addAttribute(Web3.URI,
091: Web3.FIELD_NAME_ATTR,
092: Web3.FIELD_NAME_ATTR, "CDATA",
093: sapTable.getName(k).toUpperCase());
094: contentHandler.startElement(Web3.URI,
095: Web3.FIELD_ELEM, Web3.FIELD_ELEM,
096: attributes);
097: String theValue = (sapTable.getString(k) == null) ? ""
098: : sapTable.getString(k).trim();
099: contentHandler.characters(theValue
100: .toCharArray(), 0, theValue
101: .length());
102: contentHandler.endElement(Web3.URI,
103: Web3.FIELD_ELEM, Web3.FIELD_ELEM);
104: }
105: contentHandler.endElement(Web3.URI,
106: Web3.ROW_ELEM, Web3.ROW_ELEM);
107: }
108: contentHandler.endElement(Web3.URI,
109: Web3.TABLE_ELEM, Web3.TABLE_ELEM);
110: }
111: }
112: }
113: contentHandler.endElement(Web3.URI, Web3.TABLES_ELEM,
114: Web3.TABLES_ELEM);
115: contentHandler.endElement(Web3.URI, Web3.INCLUDE_ELEM,
116: Web3.INCLUDE_ELEM);
117: }
118:
119: protected void streamParameterList(JCO.ParameterList pList,
120: ContentHandler contentHandler) throws SAXException {
121:
122: AttributesImpl attributes = new AttributesImpl();
123: if (pList != null) {
124: for (int i = 0; i < pList.getFieldCount(); i++) {
125: attributes.clear();
126:
127: JCO.Field theField = pList.getField(i);
128: if (theField.isStructure()) {
129: JCO.Structure sapStructure = pList
130: .getStructure(pList.getName(i));
131: attributes.addAttribute(Web3.URI,
132: Web3.STRUCTURE_NAME_ATTR,
133: Web3.STRUCTURE_NAME_ATTR, "CDATA", pList
134: .getName(i).toUpperCase());
135: contentHandler.startElement(Web3.URI,
136: Web3.STRUCTURE_ELEM, Web3.STRUCTURE_ELEM,
137: attributes);
138: for (int j = 0; j < sapStructure.getFieldCount(); j++) {
139: attributes.clear();
140: attributes.addAttribute(Web3.URI,
141: Web3.FIELD_NAME_ATTR,
142: Web3.FIELD_NAME_ATTR, "CDATA",
143: sapStructure.getName(j).toUpperCase());
144: contentHandler.startElement(Web3.URI,
145: Web3.FIELD_ELEM, Web3.FIELD_ELEM,
146: attributes);
147: String theValue = (sapStructure.getString(j) == null) ? ""
148: : sapStructure.getString(j).trim();
149: contentHandler.characters(theValue
150: .toCharArray(), 0, theValue.length());
151: contentHandler.endElement(Web3.URI,
152: Web3.FIELD_ELEM, Web3.FIELD_ELEM);
153: }
154: contentHandler.endElement(Web3.URI,
155: Web3.STRUCTURE_ELEM, Web3.STRUCTURE_ELEM);
156: } else {
157: attributes.addAttribute(Web3.URI,
158: Web3.FIELD_NAME_ATTR, Web3.FIELD_NAME_ATTR,
159: "CDATA", pList.getName(i).toUpperCase());
160: contentHandler.startElement(Web3.URI,
161: Web3.FIELD_ELEM, Web3.FIELD_ELEM,
162: attributes);
163: String theValue = (pList.getString(i) == null) ? ""
164: : pList.getString(i).trim();
165: contentHandler.characters(theValue.toCharArray(),
166: 0, theValue.length());
167: contentHandler.endElement(Web3.URI,
168: Web3.FIELD_ELEM, Web3.FIELD_ELEM);
169: }
170: }
171: }
172: }
173:
174: }
|