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.ANode;
012: import com.hp.hpl.jena.rdf.arp.impl.ARPResource;
013: import com.hp.hpl.jena.rdf.arp.impl.AbsXMLContext;
014: import com.hp.hpl.jena.rdf.arp.impl.AttributeLexer;
015: import com.hp.hpl.jena.rdf.arp.impl.ElementLexer;
016: import com.hp.hpl.jena.rdf.arp.impl.URIReference;
017: import com.hp.hpl.jena.rdf.arp.impl.XMLHandler;
018:
019: abstract public class WantDescription extends Frame implements
020: HasSubjectFrameI {
021:
022: public WantDescription(FrameI s, AbsXMLContext x) {
023: super (s, x);
024: }
025:
026: public WantDescription(FrameI s, AttributeLexer x)
027: throws SAXParseException {
028: super (s, x);
029: }
030:
031: public WantDescription(XMLHandler handler, AbsXMLContext x) {
032: super (handler, x);
033: }
034:
035: ANode subject;
036: boolean subjectIsBlank = false;
037:
038: public FrameI startElement(String uri, String localName,
039: String rawName, Attributes atts) throws SAXParseException {
040: clearSubject();
041:
042: if (uri == null || uri.equals("")) {
043: warning(WARN_UNQUALIFIED_ELEMENT,
044: "Unqualified typed nodes are not allowed. Type treated as a relative URI.");
045: }
046: AttributeLexer ap = new AttributeLexer(this , A_XMLLANG
047: | A_XMLBASE | A_XML_OTHER |
048: // legal rdf:
049: A_ID | A_NODEID | A_ABOUT | A_TYPE,
050: // bad rdf:
051: A_BADATTRS);
052:
053: ap.processSpecials(taint, atts);
054:
055: AbsXMLContext x = ap.xml(xml);
056:
057: if (ap.id != null) {
058: subject = URIReference.fromID(this , x, ap.id);
059: }
060: if (ap.about != null) {
061: if (subject != null)
062: warning(ERR_SYNTAX_ERROR, "Both ID and about");
063: subject = URIReference.resolve(this , x, ap.about);
064:
065: }
066: if (ap.nodeID != null) {
067: if (subject != null) {
068: if (ap.about != null)
069: warning(ERR_SYNTAX_ERROR, "Both nodeID and about");
070: if (ap.id != null)
071: warning(ERR_SYNTAX_ERROR, "Both ID and nodeID");
072: }
073: subject = new ARPResource(arp, ap.nodeID);
074: checkXMLName(subject, ap.nodeID);
075: subjectIsBlank = true;
076: }
077: if (subject == null) {
078: subject = new ARPResource(arp);
079: subjectIsBlank = true;
080: }
081: ElementLexer el = new ElementLexer(taint, this , uri, localName,
082: rawName, E_DESCRIPTION, CoreAndOldTerms | E_LI, true);
083: if (taint.isTainted())
084: subject.taint();
085: if (!el.goodMatch) {
086: URIReference type = URIReference.fromQName(this , uri,
087: localName);
088: if (el.badMatch && taint.isTainted()) {
089: type.taint();
090: }
091: triple(subject, RDF_TYPE, type);
092: }
093:
094: processPropertyAttributes(ap, atts, x);
095:
096: return new WantPropertyElement(this , x);
097: }
098:
099: private void clearSubject() {
100: if (subjectIsBlank)
101: arp.endLocalScope(subject);
102: subject = null;
103: subjectIsBlank = false;
104: }
105:
106: public void aPredAndObj(ANode p, ANode o) {
107: triple(subject, p, o);
108:
109: }
110:
111: public void makeSubjectReificationWith(ANode r) {
112: triple(r, RDF_SUBJECT, subject);
113: }
114:
115: public void endElement() throws SAXParseException {
116: clearSubject();
117: }
118:
119: public void abort() {
120: clearSubject();
121: }
122: }
123:
124: /*
125: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
126: * All rights reserved.
127: *
128: * Redistribution and use in source and binary forms, with or without
129: * modification, are permitted provided that the following conditions
130: * are met:
131: * 1. Redistributions of source code must retain the above copyright
132: * notice, this list of conditions and the following disclaimer.
133: * 2. Redistributions in binary form must reproduce the above copyright
134: * notice, this list of conditions and the following disclaimer in the
135: * documentation and/or other materials provided with the distribution.
136: * 3. The name of the author may not be used to endorse or promote products
137: * derived from this software without specific prior written permission.
138: *
139: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
140: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
141: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
142: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
143: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
144: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
145: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
146: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
147: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
148: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
149: */
|