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.ARPString;
012: import com.hp.hpl.jena.rdf.arp.impl.AbsXMLContext;
013:
014: public class WantLiteralValueOrDescription extends
015: AbsWantLiteralValueOrDescription {
016:
017: boolean seenAnElement = false;
018:
019: public WantLiteralValueOrDescription(WantsObjectFrameI s,
020: AbsXMLContext x) {
021: super (s, x);
022: }
023:
024: public FrameI startElement(String uri, String localName,
025: String rawName, Attributes atts) throws SAXParseException {
026: if (seenAnElement) {
027: warning(ERR_SYNTAX_ERROR,
028: "Multiple children of property element");
029: }
030: seenAnElement = true;
031: if (bufIsSet()) {
032: if (!isWhite(getBuf())) {
033:
034: seenNonWhiteText = true;
035: warning(
036: ERR_NOT_WHITESPACE,
037: "Cannot have both string data \""
038: + getBuf().toString()
039: + "\" and XML data <"
040: + rawName
041: + "> inside a property element. Maybe you want rdf:parseType='Literal'.");
042: // setBuf(null);
043: } else {
044: setBuf(null);
045: }
046: }
047: FrameI rslt = super .startElement(uri, localName, rawName, atts);
048: ((WantsObjectFrameI) getParent()).theObject(subject);
049: return rslt;
050:
051: }
052:
053: /** flag for seen non-white.
054: * Note: buf may have non-white text in, even if this falg is false.
055: * The following holds:
056: * seenAnElement && non white text as occurred => seenNonWhiteText
057: */
058: private boolean seenNonWhiteText = false;
059:
060: public void characters(char[] ch, int start, int length)
061: throws SAXParseException {
062: if (seenAnElement) {
063: if (!isWhite(ch, start, length)) {
064: seenNonWhiteText = true;
065: warning(
066: ERR_NOT_WHITESPACE,
067: "Cannot have both string data: \""
068: + new String(ch, start, length)
069: + "\"and XML data inside a property element. "
070: + suggestParsetypeLiteral());
071: }
072: }
073: super .characters(ch, start, length);
074: }
075:
076: public void endElement() throws SAXParseException {
077: if ((!seenAnElement) || seenNonWhiteText) {
078: ARPString literal = new ARPString(this ,
079: getBuf().toString(), xml);
080: if (taint.isTainted() || seenAnElement)
081: literal.taint();
082: ((WantsObjectFrameI) getParent()).theObject(literal);
083: }
084: super .endElement();
085: }
086:
087: }
088:
089: /*
090: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP All rights
091: * reserved.
092: *
093: * Redistribution and use in source and binary forms, with or without
094: * modification, are permitted provided that the following conditions are met:
095: * 1. Redistributions of source code must retain the above copyright notice,
096: * this list of conditions and the following disclaimer. 2. Redistributions in
097: * binary form must reproduce the above copyright notice, this list of
098: * conditions and the following disclaimer in the documentation and/or other
099: * materials provided with the distribution. 3. The name of the author may not
100: * be used to endorse or promote products derived from this software without
101: * specific prior written permission.
102: *
103: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
104: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
105: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
106: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
107: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
108: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
109: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
110: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
111: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
112: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
113: */
|