Return-Path: Delivered-To: apmail-incubator-jackrabbit-commits-archive@www.apache.org Received: (qmail 18491 invoked from network); 5 Apr 2005 15:58:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 5 Apr 2005 15:58:22 -0000 Received: (qmail 84006 invoked by uid 500); 5 Apr 2005 15:58:14 -0000 Mailing-List: contact jackrabbit-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jackrabbit-dev@incubator.apache.org Delivered-To: mailing list jackrabbit-commits@incubator.apache.org Received: (qmail 83912 invoked by uid 500); 5 Apr 2005 15:58:13 -0000 Delivered-To: apmail-incubator-jackrabbit-cvs@incubator.apache.org Received: (qmail 83896 invoked by uid 99); 5 Apr 2005 15:58:13 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 05 Apr 2005 08:58:09 -0700 Received: (qmail 17799 invoked by uid 65534); 5 Apr 2005 15:58:08 -0000 Message-ID: <20050405155807.17796.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Tue, 05 Apr 2005 15:58:07 -0000 Subject: svn commit: r160189 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: SessionImpl.java WorkspaceImpl.java xml/DocViewImportHandler.java xml/ImportHandler.java xml/SysViewImportHandler.java To: jackrabbit-cvs@incubator.apache.org From: stefan@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: stefan Date: Tue Apr 5 08:58:06 2005 New Revision: 160189 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D160189 Log: - ImportHandler & specialized friends now rely on default SAX2 Namespace su= pport - Doc/SysViewImportHandler are now processing ignorableWhitespace events Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionI= mpl.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Workspac= eImpl.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocV= iewImportHandler.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/Impo= rtHandler.java incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysV= iewImportHandler.java Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Se= ssionImpl.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/= apache/jackrabbit/core/SessionImpl.java?view=3Ddiff&r1=3D160188&r2=3D160189 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionI= mpl.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionI= mpl.java Tue Apr 5 08:58:06 2005 @@ -1008,9 +1008,15 @@ =20 ImportHandler handler =3D (ImportHandler) getImportContentHandler(= parentAbsPath); try { - XMLReader parser =3D XMLReaderFactory.createXMLReader("org.apa= che.xerces.parsers.SAXParser"); + XMLReader parser =3D + XMLReaderFactory.createXMLReader("org.apache.xerces.pa= rsers.SAXParser"); parser.setContentHandler(handler); parser.setErrorHandler(handler); + // being paranoid... + parser.setFeature("http://xml.org/sax/features/namespaces", tr= ue); + parser.setFeature("http://xml.org/sax/features/namespace-prefi= xes", + false); + parser.parse(new InputSource(in)); } catch (SAXException se) { // check for wrapped repository exception Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Wo= rkspaceImpl.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/= apache/jackrabbit/core/WorkspaceImpl.java?view=3Ddiff&r1=3D160188&r2=3D1601= 89 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Workspac= eImpl.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/Workspac= eImpl.java Tue Apr 5 08:58:06 2005 @@ -1645,6 +1645,11 @@ XMLReaderFactory.createXMLReader("org.apache.xerces.pa= rsers.SAXParser"); parser.setContentHandler(handler); parser.setErrorHandler(handler); + // being paranoid... + parser.setFeature("http://xml.org/sax/features/namespaces", tr= ue); + parser.setFeature("http://xml.org/sax/features/namespace-prefi= xes", + false); + parser.parse(new InputSource(in)); } catch (SAXException se) { // check for wrapped repository exception Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xm= l/DocViewImportHandler.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/= apache/jackrabbit/core/xml/DocViewImportHandler.java?view=3Ddiff&r1=3D16018= 8&r2=3D160189 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocV= iewImportHandler.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/DocV= iewImportHandler.java Tue Apr 5 08:58:06 2005 @@ -17,10 +17,8 @@ package org.apache.jackrabbit.core.xml; =20 import org.apache.jackrabbit.core.BaseException; -import org.apache.jackrabbit.core.IllegalNameException; import org.apache.jackrabbit.core.NamespaceResolver; import org.apache.jackrabbit.core.QName; -import org.apache.jackrabbit.core.UnknownPrefixException; import org.apache.jackrabbit.core.util.ISO9075; import org.apache.log4j.Logger; import org.xml.sax.Attributes; @@ -30,6 +28,7 @@ import javax.jcr.RepositoryException; import java.util.ArrayList; import java.util.Stack; +import java.io.IOException; =20 /** * DocViewImportHandler processes Document View XML SAX events @@ -119,18 +118,7 @@ } =20 try { - QName nodeName; - if (namespaceURI !=3D null && !"".equals(namespaceURI)) { - nodeName =3D new QName(namespaceURI, localName); - } else { - try { - nodeName =3D QName.fromJCRName(qName, nsContext); - } catch (IllegalNameException ine) { - throw new SAXException("illegal node name: " + qName, = ine); - } catch (UnknownPrefixException upe) { - throw new SAXException("illegal node name: " + qName, = upe); - } - } + QName nodeName =3D new QName(namespaceURI, localName); // decode node name nodeName =3D ISO9075.decode(nodeName); =20 @@ -141,20 +129,7 @@ =20 ArrayList props =3D new ArrayList(atts.getLength()); for (int i =3D 0; i < atts.getLength(); i++) { - QName propName; - if (atts.getURI(i) !=3D null && !"".equals(atts.getURI(i))= ) { - propName =3D new QName(atts.getURI(i), atts.getLocalNa= me(i)); - } else { - try { - propName =3D QName.fromJCRName(atts.getQName(i), n= sContext); - } catch (IllegalNameException ine) { - throw new SAXException("illegal property name: " - + atts.getQName(i), ine); - } catch (UnknownPrefixException upe) { - throw new SAXException("illegal property name: " - + atts.getQName(i), upe); - } - } + QName propName =3D new QName(atts.getURI(i), atts.getLocal= Name(i)); // decode property name propName =3D ISO9075.decode(propName); =20 @@ -224,6 +199,21 @@ /** * buffer character data; will be processed * in endElement and startElement method + */ + if (textHandler =3D=3D null) { + textHandler =3D new StringBufferValue(); + } + textHandler.append(ch, start, length); + } + + /** + * {@inheritDoc} + */ + public void ignorableWhitespace(char ch[], int start, int length) + throws SAXException { + /** + * buffer data reported by the ignorableWhitespace event; + * will be processed in endElement and startElement method */ if (textHandler =3D=3D null) { textHandler =3D new StringBufferValue(); Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xm= l/ImportHandler.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/= apache/jackrabbit/core/xml/ImportHandler.java?view=3Ddiff&r1=3D160188&r2=3D= 160189 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/Impo= rtHandler.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/Impo= rtHandler.java Tue Apr 5 08:58:06 2005 @@ -16,11 +16,9 @@ */ package org.apache.jackrabbit.core.xml; =20 -import org.apache.jackrabbit.core.BaseException; import org.apache.jackrabbit.core.Constants; import org.apache.jackrabbit.core.NamespaceRegistryImpl; import org.apache.jackrabbit.core.NamespaceResolver; -import org.apache.jackrabbit.core.QName; import org.apache.log4j.Logger; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; @@ -35,12 +33,19 @@ =20 /** * An ImportHandler instance can be used to import serialized - * data in System View XML or Document View XML. Processing of the XML is = handled - * by specialized ContentHandlers (i.e. SysViewImportHa= ndler - * and DocViewImportHandler). + * data in System View XML or Document View XML. Processing of the XML is + * handled by specialized ContentHandlers + * (i.e. SysViewImportHandler and DocViewImportHandler<= /code>). *

* The actual task of importing though is delegated to the implementation = of * the {@link Importer} interface. + *

+ * Important Note: + *

+ * These SAX Event Handlers expect that Namespace URI's and local names are + * reported in the start/endElement events and that + * start/endPrefixMapping events are reported + * (i.e. default SAX2 Namespace processing). */ public class ImportHandler extends DefaultHandler { =20 @@ -213,21 +218,7 @@ if (!initialized) { // the namespace of the first element determines the type of X= ML // (system view/document view) - String nsURI; - if (namespaceURI !=3D null && !"".equals(namespaceURI)) { - nsURI =3D namespaceURI; - } else { - try { - nsURI =3D QName.fromJCRName(qName, nsResolver).getName= spaceURI(); - } catch (BaseException e) { - // should never happen... - String msg =3D "internal error: failed to parse/resolv= e element name " - + qName; - log.debug(msg); - throw new SAXException(msg, e); - } - } - systemViewXML =3D Constants.NS_SV_URI.equals(nsURI); + systemViewXML =3D Constants.NS_SV_URI.equals(namespaceURI); =20 if (systemViewXML) { targetHandler =3D new SysViewImportHandler(importer, nsCon= text); Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xm= l/SysViewImportHandler.java URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/= apache/jackrabbit/core/xml/SysViewImportHandler.java?view=3Ddiff&r1=3D16018= 8&r2=3D160189 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysV= iewImportHandler.java (original) +++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SysV= iewImportHandler.java Tue Apr 5 08:58:06 2005 @@ -16,7 +16,6 @@ */ package org.apache.jackrabbit.core.xml; =20 -import org.apache.jackrabbit.core.BaseException; import org.apache.jackrabbit.core.IllegalNameException; import org.apache.jackrabbit.core.NamespaceResolver; import org.apache.jackrabbit.core.QName; @@ -117,34 +116,19 @@ public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { - String elemName; - String nsURI; - if (namespaceURI !=3D null && !"".equals(namespaceURI)) { - nsURI =3D namespaceURI; - elemName =3D localName; - } else { - try { - nsURI =3D QName.fromJCRName(qName, nsContext).getNamespace= URI(); - elemName =3D QName.fromJCRName(qName, nsContext).getLocalN= ame(); - } catch (BaseException e) { - // should never happen... - String msg =3D "internal error: failed to parse/resolve el= ement name " + qName; - log.debug(msg); - throw new SAXException(msg, e); - } - } // check namespace - if (!NS_SV_URI.equals(nsURI)) { - throw new SAXException(new InvalidSerializedDataException("inv= alid namespace for element in system view xml document: " + nsURI)); + if (!NS_SV_URI.equals(namespaceURI)) { + throw new SAXException(new InvalidSerializedDataException("inv= alid namespace for element in system view xml document: " + + namespaceURI)); } // check element name - if (SysViewSAXEventGenerator.NODE_ELEMENT.equals(elemName)) { + if (SysViewSAXEventGenerator.NODE_ELEMENT.equals(localName)) { // sv:node element =20 // node name (value of sv:name attribute) String name =3D atts.getValue(SysViewSAXEventGenerator.PREFIXE= D_NAME_ATTRIBUTE); if (name =3D=3D null) { - throw new SAXException(new InvalidSerializedDataException(= "missing mandatory sv:name attributeof element sv:node")); + throw new SAXException(new InvalidSerializedDataException(= "missing mandatory sv:name attribute of element sv:node")); } =20 if (!stack.isEmpty()) { @@ -167,7 +151,7 @@ throw new SAXException(new InvalidSerializedDataException(= "illegal node name: " + name, upe)); } stack.push(state); - } else if (SysViewSAXEventGenerator.PROPERTY_ELEMENT.equals(elemNa= me)) { + } else if (SysViewSAXEventGenerator.PROPERTY_ELEMENT.equals(localN= ame)) { // sv:property element =20 // reset temp fields @@ -176,7 +160,7 @@ // property name (value of sv:name attribute) String name =3D atts.getValue(SysViewSAXEventGenerator.PREFIXE= D_NAME_ATTRIBUTE); if (name =3D=3D null) { - throw new SAXException(new InvalidSerializedDataException(= "missing mandatory sv:name attributeof element sv:property")); + throw new SAXException(new InvalidSerializedDataException(= "missing mandatory sv:name attribute of element sv:property")); } try { currentPropName =3D QName.fromJCRName(name, nsContext); @@ -188,10 +172,10 @@ // property type (sv:type attribute) String type =3D atts.getValue(SysViewSAXEventGenerator.PREFIXE= D_TYPE_ATTRIBUTE); if (type =3D=3D null) { - throw new SAXException(new InvalidSerializedDataException(= "missing mandatory sv:type attributeof element sv:property")); + throw new SAXException(new InvalidSerializedDataException(= "missing mandatory sv:type attribute of element sv:property")); } currentPropType =3D PropertyType.valueFromName(type); - } else if (SysViewSAXEventGenerator.VALUE_ELEMENT.equals(elemName)= ) { + } else if (SysViewSAXEventGenerator.VALUE_ELEMENT.equals(localName= )) { // sv:value element =20 // reset temp fields @@ -200,15 +184,18 @@ try { currentPropValue =3D new CLOBValue(); } catch (IOException ioe) { - throw new SAXException("error while processing propert= y value", - ioe); + String msg =3D "error while processing property value " + + currentPropName; + log.debug(msg, ioe); + throw new SAXException(msg, ioe); } } else { // 'normal' value; use StringBuffer-backed value appender currentPropValue =3D new StringBufferValue(); } } else { - throw new SAXException(new InvalidSerializedDataException("une= xpected element found in system view xml document: " + elemName)); + throw new SAXException(new InvalidSerializedDataException("une= xpected element found in system view xml document: " + + localName)); } } =20 @@ -231,24 +218,30 @@ /** * {@inheritDoc} */ - public void endElement(String namespaceURI, String localName, String q= Name) + public void ignorableWhitespace(char ch[], int start, int length) throws SAXException { - String elemName; - if (localName !=3D null && !"".equals(localName)) { - elemName =3D localName; - } else { + if (currentPropValue !=3D null) { + // property value + + // data reported by the ignorableWhitespace event within + // sv:value tags is considered part of the value try { - elemName =3D QName.fromJCRName(qName, nsContext).getLocalN= ame(); - } catch (BaseException e) { - // should never happen... - String msg =3D "internal error: failed to parse/resolve el= ement name " + qName; - log.debug(msg); - throw new SAXException(msg, e); + currentPropValue.append(ch, start, length); + } catch (IOException ioe) { + throw new SAXException("error while processing property va= lue", + ioe); } } + } + + /** + * {@inheritDoc} + */ + public void endElement(String namespaceURI, String localName, String q= Name) + throws SAXException { // check element name ImportState state =3D (ImportState) stack.peek(); - if (SysViewSAXEventGenerator.NODE_ELEMENT.equals(elemName)) { + if (SysViewSAXEventGenerator.NODE_ELEMENT.equals(localName)) { // sv:node element if (!state.started) { // need to start & end current node @@ -260,7 +253,7 @@ } // pop current state from stack stack.pop(); - } else if (SysViewSAXEventGenerator.PROPERTY_ELEMENT.equals(elemNa= me)) { + } else if (SysViewSAXEventGenerator.PROPERTY_ELEMENT.equals(localN= ame)) { // sv:property element =20 // check if all system properties (jcr:primaryType, jcr:uuid e= tc.) @@ -283,7 +276,8 @@ state.mixinNames =3D new ArrayList(currentPropValues.s= ize()); } for (int i =3D 0; i < currentPropValues.size(); i++) { - AppendableValue val =3D (AppendableValue) currentPropV= alues.get(0); + AppendableValue val =3D + (AppendableValue) currentPropValues.get(0); String s =3D null; try { s =3D val.retrieve(); @@ -314,13 +308,13 @@ } // reset temp fields currentPropValues.clear(); - } else if (SysViewSAXEventGenerator.VALUE_ELEMENT.equals(elemName)= ) { + } else if (SysViewSAXEventGenerator.VALUE_ELEMENT.equals(localName= )) { // sv:value element currentPropValues.add(currentPropValue); // reset temp fields currentPropValue =3D null; } else { - throw new SAXException(new InvalidSerializedDataException("inv= alid element in system view xml document: " + elemName)); + throw new SAXException(new InvalidSerializedDataException("inv= alid element in system view xml document: " + localName)); } } =20