01: /*
02: * Copyright 2007 Outerthought bvba and Schaubroeck nv
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 org.outerj.daisy.i18n.impl;
17:
18: import org.xml.sax.ContentHandler;
19: import org.xml.sax.SAXException;
20: import org.outerj.daisy.xmlutil.SaxBuffer;
21: import org.outerj.daisy.i18n.I18nMessage;
22:
23: public class I18nMessageImpl implements I18nMessage {
24: private final SaxBuffer buffer;
25: private final String text;
26:
27: public I18nMessageImpl(SaxBuffer buffer) {
28: this .buffer = buffer;
29:
30: StringBuilder tmp = new StringBuilder();
31: for (SaxBuffer.SaxBit bit : buffer.getBits()) {
32: if (bit instanceof SaxBuffer.Characters) {
33: SaxBuffer.Characters charbit = (SaxBuffer.Characters) bit;
34: tmp.append(charbit.ch, 0, charbit.ch.length);
35: }
36: }
37: this .text = tmp.toString();
38: }
39:
40: public String getText() {
41: return text;
42: }
43:
44: public void generateSaxFragment(ContentHandler contentHandler)
45: throws SAXException {
46: buffer.toSAX(contentHandler);
47: }
48:
49: public String toString() {
50: return text;
51: }
52: }
|