001: /*
002: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * [See end of file]
004: */
005:
006: package com.hp.hpl.jena.rdf.arp.states;
007:
008: import org.xml.sax.Attributes;
009: import org.xml.sax.SAXParseException;
010:
011: import com.hp.hpl.jena.rdf.arp.impl.AbsXMLContext;
012: import com.hp.hpl.jena.rdf.arp.impl.AttributeLexer;
013:
014: abstract class AbsWantLiteralValueOrDescription extends WantDescription {
015:
016: private StringBuffer buf;
017:
018: private boolean checkComposingChar = true;
019:
020: public AbsWantLiteralValueOrDescription(FrameI s, AbsXMLContext x) {
021: super (s, x);
022: }
023:
024: public AbsWantLiteralValueOrDescription(FrameI s, AttributeLexer x)
025: throws SAXParseException {
026: super (s, x);
027: }
028:
029: /**
030: * It is unclear to jjc, whether we are obliged to copy the characters, or
031: * whether we know that they will not be overwritten after we return. For
032: * safety, I hence copy them. Normally, we have two interesting cases: a)
033: * characters is called once, then endElement, and we form a literal from
034: * the characters. This involves creating a string, if we used a char[] then
035: * we would have another char[] to char[] copy, which is one too many. Hence
036: * we use a StringBuffer. b) <eg:prop> <eg:typedNode /> </eg:prop> with two
037: * lots of characters both white. This case happens from within
038: * InsidePropertyElementFrame, and the second lot of characters do not get
039: * here.
040: */
041: public void characters(char[] ch, int start, int length)
042: throws SAXParseException {
043: if (checkComposingChar)
044: checkComposingChar(taint, ch, start, length);
045: checkComposingChar = false;
046: if (buf == null)
047: buf = new StringBuffer(length);
048: getBuf().append(ch, start, length);
049: }
050:
051: void setBuf(StringBuffer buf) {
052: this .buf = buf;
053: }
054:
055: StringBuffer getBuf() {
056: if (buf == null)
057: buf = new StringBuffer(0);
058: return buf;
059: }
060:
061: boolean bufIsSet() {
062: return buf != null;
063: }
064:
065: public FrameI startElement(String uri, String localName,
066: String rawName, Attributes atts) throws SAXParseException {
067: checkComposingChar = true;
068: return super .startElement(uri, localName, rawName, atts);
069: }
070:
071: public void comment(char ch[], int st, int lng) {
072: checkComposingChar = true;
073: }
074:
075: public void processingInstruction(String a, String b)
076: throws SAXParseException {
077: checkComposingChar = true;
078: super .processingInstruction(a, b);
079:
080: }
081:
082: }
083:
084: /*
085: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP All rights
086: * reserved.
087: *
088: * Redistribution and use in source and binary forms, with or without
089: * modification, are permitted provided that the following conditions are met:
090: * 1. Redistributions of source code must retain the above copyright notice,
091: * this list of conditions and the following disclaimer. 2. Redistributions in
092: * binary form must reproduce the above copyright notice, this list of
093: * conditions and the following disclaimer in the documentation and/or other
094: * materials provided with the distribution. 3. The name of the author may not
095: * be used to endorse or promote products derived from this software without
096: * specific prior written permission.
097: *
098: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
099: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
100: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
101: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
102: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
103: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
104: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
105: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
106: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
107: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
108: */
|