01: /*
02: * Copyright 2004 Clinton Begin
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 com.ibatis.sqlmap.engine.mapping.sql.dynamic.elements;
17:
18: public abstract class BaseTagHandler implements SqlTagHandler {
19:
20: public int doStartFragment(SqlTagContext ctx, SqlTag tag,
21: Object parameterObject) {
22: ctx.pushRemoveFirstPrependMarker(tag);
23: return SqlTagHandler.INCLUDE_BODY;
24: }
25:
26: public int doEndFragment(SqlTagContext ctx, SqlTag tag,
27: Object parameterObject, StringBuffer bodyContent) {
28: if (tag.isCloseAvailable()
29: && !(tag.getHandler() instanceof IterateTagHandler)) {
30: if (bodyContent.toString().trim().length() > 0) {
31: bodyContent.append(tag.getCloseAttr());
32: }
33: }
34: return SqlTagHandler.INCLUDE_BODY;
35: }
36:
37: public void doPrepend(SqlTagContext ctx, SqlTag tag,
38: Object parameterObject, StringBuffer bodyContent) {
39:
40: if (tag.isOpenAvailable()
41: && !(tag.getHandler() instanceof IterateTagHandler)) {
42: if (bodyContent.toString().trim().length() > 0) {
43: bodyContent.insert(0, tag.getOpenAttr());
44: }
45: }
46:
47: if (tag.isPrependAvailable()) {
48: if (bodyContent.toString().trim().length() > 0) {
49: if (tag.getParent() != null
50: && ctx.peekRemoveFirstPrependMarker(tag)) {
51: ctx.disableRemoveFirstPrependMarker();
52: } else {
53: bodyContent.insert(0, tag.getPrependAttr());
54: }
55: }
56: }
57:
58: }
59: }
|