svn commit: r524298 [5/5] - in /jakarta/slide/trunk/proposals/purexmladapter: ./ slide/ slide/com/ slide/com/ibm/ slide/com/ibm/db2/ slide/com/ibm/db2/purexml/ slide/dbsetup/
[email protected] Fri, 30 Mar 2007 22:24:28 -0000
| Newsgroups | gmane.comp.jakarta.slide.devel |
|---|---|
| Message-ID | <[email protected]> |
Added: jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/JDBCAwareInputStream.java
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/JDBCAwareInputStream.java?view=auto&rev=524298
==============================================================================
--- jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/JDBCAwareInputStream.java (added)
+++ jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/JDBCAwareInputStream.java Fri Mar 30 15:24:26 2007
@@ -0,0 +1,117 @@
+/*
+ * $Header: /cvs/slide/src/stores/com/ibm/db2/purexml/JDBCAwareInputStream.java,v 1.1 2006/11/28 19:44:20 zocourto Exp $
+ * $Revision: 1.1 $
+ * $Date: 2006/11/28 19:44:20 $
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2002 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.ibm.db2.purexml;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * Wrapper for an input stream that has come from a JDBC connection. This
+ * wrapper also closes the underlying JDBC result set - freeing precious system
+ * resources - or at least Oracle cursors ;-)
+ *
+ * @version $Revision: 1.1 $
+ */
+class JDBCAwareInputStream
+ extends FilterInputStream {
+
+
+ // ---------------------------------------------------------- Instance Data
+
+
+ /**
+ * The JDBC statement that will be closed along with its result set when the
+ * input stream is told to close itself.
+ */
+ private Statement stmt = null;
+ private ResultSet rs = null;
+ private Connection connection = null;
+
+
+ // ----------------------------------------------------------- Constructors
+
+
+ /**
+ * Creates an input stream that closes a statmenet, a resultset and a connection
+ * when the stream itself is closed.
+ *
+ */
+ public JDBCAwareInputStream(InputStream in, Statement stmt, ResultSet rs, Connection connection) {
+ super(in);
+
+ this.stmt = stmt;
+ this.rs = rs;
+ this.connection = connection;
+ }
+
+
+ // --------------------------------------------- InputStream Implementation
+
+
+ /**
+ * Overridden to close the associated JDBC statement, result set and connection together with the
+ * input stream.
+ */
+ public void close() throws IOException {
+ try {
+ if (rs != null) {
+ rs.close();
+ }
+ } catch (SQLException e) {
+ throw new IOException(e.getMessage());
+ } finally {
+ try {
+ if (stmt != null) {
+ stmt.close();
+ }
+ } catch (SQLException e) {
+ throw new IOException(e.getMessage());
+ } finally {
+ try {
+ if (connection != null) {
+ try {
+ connection.commit();
+ } catch (SQLException e) {
+ throw new IOException(e.getMessage());
+ } finally {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+ }
+ } finally {
+ super.close();
+ }
+ }
+ }
+ }
+}
+
Added: jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/PureXMLAdapter.java
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/PureXMLAdapter.java?view=auto&rev=524298
==============================================================================
--- jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/PureXMLAdapter.java (added)
+++ jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/PureXMLAdapter.java Fri Mar 30 15:24:26 2007
@@ -0,0 +1,734 @@
+/*
+ * $Header$
+ * $Revision: $
+ * $Date: $
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2003 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package com.ibm.db2.purexml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.slide.common.Service;
+import org.apache.slide.common.ServiceAccessException;
+import org.apache.slide.common.UnknownObjectClassException;
+import org.apache.slide.content.NodeProperty;
+import org.apache.slide.content.NodeRevisionDescriptor;
+import org.apache.slide.content.NodeRevisionDescriptors;
+import org.apache.slide.content.NodeRevisionNumber;
+import org.apache.slide.lock.NodeLock;
+import org.apache.slide.security.NodePermission;
+import org.apache.slide.store.impl.rdbms.StandardRDBMSAdapter;
+import org.apache.slide.structure.LinkNode;
+import org.apache.slide.structure.ObjectNode;
+import org.apache.slide.structure.ObjectNotFoundException;
+import org.apache.slide.util.logger.Logger;
+import org.jdom.Attribute;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+/**
+ * Adapter for DB2 pureXML.
+ *
+ * @version $Revision: $
+ */
+public class PureXMLAdapter extends StandardRDBMSAdapter {
+
+ protected static final String PATH_EXTENSION = ".def.xml";
+ protected final Format outputFormat;
+ protected SimpleDateFormat dateFormat;
+ protected String characterEncoding = "UTF-8";
+ protected String uri;
+
+ /** Stored object.*/
+ protected ObjectNode object;
+
+ /** Permissions vector. */
+ protected Vector permissions;
+
+ /** Locks vector.*/
+ protected Vector locks;
+
+ /** Revision descriptors.*/
+ protected NodeRevisionDescriptors revisionDescriptors;
+
+ /** Revision descriptor hashtable.*/
+ protected Hashtable descriptor;
+
+ public PureXMLAdapter(Service service, Logger logger){
+ super(service, logger);
+ bcompress = false;
+
+ outputFormat = Format.getPrettyFormat();
+ outputFormat.setEncoding(characterEncoding);
+
+ dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z");
+ }
+
+ protected String getLoadPath(){
+ return this.uri + PATH_EXTENSION;
+ }
+
+ protected boolean contentExists(Connection cnn, String uri)throws ServiceAccessException{
+ boolean isFound = false;
+ try{
+ PreparedStatement statement = null;
+ ResultSet res = null;
+ CollectionInfo cInfo = PureXMLUtilities.getCollectionInfo(PureXMLUtilities.getParentUri(this.getLoadPath(), cnn), cnn);
+
+ try{
+ String strSQL = "SELECT 1 FROM " + cInfo.getTableSchema() + "." + cInfo.getTableName() +
+ " WHERE " + cInfo.getColumnIDName() + " = ?";
+ statement = cnn.prepareStatement(strSQL);//"SELECT 1 FROM WEBDAV.DATADEFAULT WHERE ID = ?");
+ statement.setString(1,PureXMLUtilities.getResourceID(uri, cnn));
+ res = statement.executeQuery();
+ isFound = res.next();
+ }finally{
+ close(statement,res);
+ }
+ }catch(SQLException e){
+ throw createException(e,uri.toString());
+ }
+ return isFound;
+ }
+
+ protected boolean metadataExists(Connection cnn)throws ServiceAccessException{
+ boolean isFound = false;
+ try{
+ PreparedStatement statement = null;
+ ResultSet res = null;
+ try{
+ statement = cnn.prepareStatement("SELECT * FROM WEBDAV.SLIDEMETADATA WHERE URI = ?");
+ statement.setString(1,getLoadPath());
+ res = statement.executeQuery();
+ isFound = res.next();
+ }finally{
+ close(statement,res);
+ }
+ }catch(SQLException e){
+ throw createException(e,uri.toString());
+ }
+ return isFound;
+ }
+
+ protected void init() throws ServiceAccessException {
+ // need to set this null, as AbstractUriProperties.retrieveObject relies on it
+ object = null;
+ permissions = new Vector();
+ locks = new Vector();
+ revisionDescriptors =
+ new NodeRevisionDescriptors(uri, null, new Hashtable(), new Hashtable(), new Hashtable(), false);
+ descriptor = new Hashtable();
+ }
+
+ protected void save(Connection cnn) throws ServiceAccessException{
+ Element aRoot = encode();
+ Document aDocument = new Document(aRoot);
+
+ XMLOutputter aOutputter = new XMLOutputter(outputFormat);
+ String xmlDoc = aOutputter.outputString(aDocument);
+
+ CollectionInfo info = null;
+ try{
+ PreparedStatement statement = null;
+ try{
+ if(metadataExists(cnn)){
+ statement = cnn.prepareStatement("UPDATE WEBDAV.SLIDEMETADATA SET METADATA = ? WHERE URI = ?");
+ statement.setString(1,xmlDoc);
+ statement.setString(2,this.getLoadPath());
+ statement.executeUpdate();
+ if(PureXMLUtilities.isCollection(descriptor)){
+ if(!PureXMLUtilities.isExposedCollection(descriptor)){
+ info = PureXMLUtilities.getCollectionInfo(PureXMLUtilities.getParentUri(object), cnn);
+ PureXMLUtilities.updateCollectionInfo(info, this.getLoadPath(), cnn);//if not exposed but may be a subfolder not create by SP
+ if(PureXMLUtilities.isExposedCollection(PureXMLUtilities.getParentUri(this.getLoadPath(), cnn), cnn)){
+ PureXMLUtilities.updateExposedCollection(this.getLoadPath(),cnn);
+ }
+ }else if(PureXMLUtilities.isExposedCollection(PureXMLUtilities.getParentUri(this.getLoadPath(), cnn), cnn)){
+ info = PureXMLUtilities.getCollectionInfo(PureXMLUtilities.getParentUri(object), cnn);
+ PureXMLUtilities.updateCollectionInfo(info, this.getLoadPath(), cnn);
+ }
+ }
+ if(PureXMLUtilities.isVersioningMetadata(this.getLoadPath())){
+ boolean isXML = PureXMLUtilities.isVersionedDocXML(this.getLoadPath(), cnn);
+ info = PureXMLUtilities.getCollectionInfo(this.getLoadPath(), cnn);
+ PureXMLUtilities.updateCollectionInfo(info, PureXMLUtilities.getParentUri(this.getLoadPath(), cnn), cnn);
+ PureXMLUtilities.updateResourceInfo(PureXMLUtilities.getHistoryResourceInfo(this.getLoadPath(),isXML), this.getLoadPath(), cnn);
+ }
+ }
+ else{
+ statement = cnn.prepareStatement("INSERT INTO WEBDAV.SLIDEMETADATA(URI,METADATA) VALUES(?,?)");
+ statement.setString(1,this.getLoadPath());
+ statement.setString(2,xmlDoc);
+ statement.executeUpdate();
+ }
+ }finally{
+ close(statement);
+ }
+ }catch(SQLException e){
+ throw createException(e, uri.toString());
+ }
+ }
+
+ protected void delete(Connection cnn) throws ServiceAccessException{
+ try{
+ PreparedStatement statement = null;
+ try{
+ statement = cnn.prepareStatement("DELETE FROM WEBDAV.SLIDEMETADATA WHERE URI = ?");
+ statement.setString(1,this.getLoadPath());
+ statement.executeUpdate();
+ }finally{
+ close(statement);
+ }
+ }catch(SQLException e){
+ throw createException(e, uri.toString());
+ }
+ }
+
+
+ protected void load(InputStream is)throws ServiceAccessException, IOException, JDOMException{
+ SAXBuilder aBuilder = new SAXBuilder();
+ Document aDocument = aBuilder.build(is);
+ decode(aDocument.getRootElement());
+ }
+
+ protected void load(Connection cnn) throws ServiceAccessException, ObjectNotFoundException{
+ PreparedStatement statement = null;
+ ResultSet rs = null;
+ InputStream is = null;
+ try{
+ if(this.metadataExists(cnn)){
+ statement = cnn.prepareStatement("SELECT METADATA FROM WEBDAV.SLIDEMETADATA WHERE URI = ?");
+ statement.setString(1,this.getLoadPath());
+ rs = statement.executeQuery();
+ while(rs.next()){
+ is = rs.getBinaryStream(1);
+ }
+ load(is);
+ }
+ else{
+ init();
+ }
+ }catch(SQLException e){
+ throw new ObjectNotFoundException(uri.toString()); //XXX May need the createException instead.
+ }catch (IOException ioe) {
+ getLogger().log(ioe, LOG_CHANNEL, Logger.ERROR);
+ throw new ServiceAccessException(service, ioe);
+ }catch (JDOMException je) {
+ throw createException(je, uri.toString());
+ }
+ finally{
+ close(statement,rs);
+ try{ if(is!=null) is.close();}
+ catch(IOException e){}
+ }
+ }
+
+ protected static String booleanToString(boolean aBoolean) {
+ return aBoolean ? "true" : "false";
+ }
+
+ protected static Element createBindings(String aParent, String aChild, Enumeration aEnum) {
+ Element aElement = new Element(aParent);
+ Element childNode;
+ ObjectNode.Binding binding;
+ while (aEnum.hasMoreElements()) {
+ binding = (ObjectNode.Binding) aEnum.nextElement();
+ childNode = new Element(aChild);
+ childNode.setAttribute(new Attribute("name", binding.getName()));
+ childNode.setAttribute(new Attribute("uuri", binding.getUuri()));
+ aElement.addContent(childNode);
+ }
+ return aElement;
+ }
+
+ protected static Element createElements(String aParent, String aChild, Enumeration aEnum) {
+ Element aElement = new Element(aParent);
+ while (aEnum.hasMoreElements()) {
+ Object aObject = aEnum.nextElement();
+ Element aItem = new Element(aChild);
+ aItem.setAttribute("val", aObject.toString());
+ aElement.addContent(aItem);
+ }
+ return aElement;
+ }
+
+ protected static NodePermission decodePermission(Element aElement, String aUri) {
+ String aRevisionNumber = aElement.getAttributeValue("revisionNumber");
+ String aSubject = aElement.getAttributeValue("subjectUri");
+ String aAction = aElement.getAttributeValue("actionUri");
+ boolean aInheritable = new Boolean(aElement.getAttributeValue("inheritable")).booleanValue();
+ boolean aNegative = new Boolean(aElement.getAttributeValue("negative")).booleanValue();
+ return new NodePermission(aUri, aRevisionNumber, aSubject, aAction, aInheritable, aNegative);
+
+ }
+
+ protected static Element encodeNodePermission(NodePermission aPermission) {
+ Element aElementPermission = new Element("permission");
+ NodeRevisionNumber aRevisionNumber = aPermission.getRevisionNumber();
+ if (aRevisionNumber != null) {
+ aElementPermission.setAttribute("revisionNumber", encodeRevisionNumber(aRevisionNumber));
+ }
+ aElementPermission.setAttribute("subjectUri", aPermission.getSubjectUri());
+ aElementPermission.setAttribute("actionUri", aPermission.getActionUri());
+ aElementPermission.setAttribute("inheritable", booleanToString(aPermission.isInheritable()));
+ aElementPermission.setAttribute("negative", booleanToString(aPermission.isNegative()));
+ return aElementPermission;
+ }
+
+ protected static Element encodeRevisionDescriptor(NodeRevisionDescriptor aDescriptor) {
+ Element aRevisions = new Element("revisions");
+ aRevisions.setAttribute("branchName", aDescriptor.getBranchName());
+ aRevisions.setAttribute("number", encodeRevisionNumber(aDescriptor.getRevisionNumber()));
+ aRevisions.addContent(createElements("labels", "label", aDescriptor.enumerateLabels()));
+ Element aProperties = new Element("properties");
+
+ for (Enumeration aEnum = aDescriptor.enumerateProperties(); aEnum.hasMoreElements();) {
+ Object aObject = aEnum.nextElement();
+ NodeProperty aProp = (NodeProperty) aObject;
+ aProperties.addContent(encodeNodeProperty(aProp));
+ }
+ aRevisions.addContent(aProperties);
+ return aRevisions;
+ }
+
+ protected static Element encodeNodeProperty(NodeProperty aProp) {
+ Element aElement = new Element("property");
+ aElement.setAttribute("name", aProp.getName());
+ aElement.setAttribute("namespace", aProp.getNamespace());
+ aElement.setAttribute("value", aProp.getValue().toString());
+ aElement.setAttribute("type", aProp.getType());
+ aElement.setAttribute("protected", booleanToString(aProp.isProtected()));
+ Element aPermissions = new Element("permissions");
+
+ for (Enumeration aEnum = aProp.enumeratePermissions(); aEnum.hasMoreElements();) {
+ NodePermission aPermission = (NodePermission) aEnum.nextElement();
+ aPermissions.addContent(encodeNodePermission(aPermission));
+ }
+ aElement.addContent(aPermissions);
+ return aElement;
+ }
+
+ protected static Vector createVector(Element aElement, String aParentName, String aChildName) {
+ Element aParent = aElement.getChild(aParentName);
+ Vector aRet = new Vector();
+ List aList = aParent.getChildren(aChildName);
+ for (int i = 0; i < aList.size(); i++) {
+ Element aChild = (Element) aList.get(i);
+ aRet.addElement(aChild.getAttributeValue("val"));
+ }
+ return aRet;
+ }
+
+ protected static Vector createBindingVector(
+ Element aElement,
+ String aParentName,
+ String aChildName,
+ boolean parentBindings) {
+ Element aParent = aElement.getChild(aParentName);
+ Vector aRet = new Vector();
+ // System.out.println("--------- createVector aParentName="+aParentName+" aChildName="+aChildName);
+ Iterator it = aParent.getChildren().iterator();
+ while (it.hasNext()) {
+ Element aChild = (Element) it.next();
+ String name = aChild.getAttributeValue("name");
+ String uuri = aChild.getAttributeValue("uuri");
+ if (parentBindings) {
+ aRet.add(new ObjectNode.ParentBinding(name, uuri));
+ } else {
+ aRet.add(new ObjectNode.Binding(name, uuri));
+ }
+ }
+ return aRet;
+ }
+
+ protected static String encodeRevisionNumber(NodeRevisionNumber aRevisionNumber) {
+ return aRevisionNumber.getMajor() + "." + aRevisionNumber.getMinor();
+ }
+
+ protected static Object createObject(String aNomClasse, Class aTypes[], Object aArgs[])
+ throws UnknownObjectClassException {
+ Class aClasse = null;
+ try {
+ // First, load the object's class
+ aClasse = Class.forName(aNomClasse);
+ Constructor aConstructor = aClasse.getConstructor(aTypes);
+ if (aConstructor == null)
+ aConstructor = aClasse.getSuperclass().getConstructor(aTypes);
+ return aConstructor.newInstance(aArgs);
+
+ } catch (Exception e) {
+ throw new UnknownObjectClassException(aNomClasse);
+ }
+ }
+
+ protected static NodeRevisionNumber decodeRevisionNumber(Element aElement) {
+ Element aElementRevision = aElement.getChild("revision");
+ return new NodeRevisionNumber(
+ Integer.parseInt(aElementRevision.getAttributeValue("major")),
+ Integer.parseInt(aElementRevision.getAttributeValue("minor")));
+ }
+
+ protected static NodeRevisionNumber decodeRevisionNumber(String aStr) {
+ return (aStr == null ? null : new NodeRevisionNumber(aStr));
+ }
+
+ protected static NodeProperty decodeNodeProperty(Element aElement, String aUri) {
+ String aName = aElement.getAttributeValue("name");
+ String aValue = aElement.getAttributeValue("value");
+ String aNamespace = aElement.getAttributeValue("namespace");
+ String aType = aElement.getAttributeValue("type");
+ boolean aProtected = new Boolean(aElement.getAttributeValue("protected")).booleanValue();
+
+ Element aPermisionsElement = aElement.getChild("permissions");
+ List aList = aPermisionsElement.getChildren();
+ Vector aPermission = new Vector();
+ for (int i = 0; i < aList.size(); i++) {
+ Element aChild = (Element) aList.get(i);
+ aPermission.addElement(decodePermission(aChild, aUri));
+ }
+ return new NodeProperty(aName, aValue, aNamespace, aType, aProtected);
+ }
+
+ /**
+ * Forms the *.def.xml document/metadata
+ *
+ * @return <code>aRoot</code> XML document
+ */
+ protected Element encode() throws ServiceAccessException {
+ Element aRoot = new Element("data");
+ aRoot.addContent(encodeObject());
+ aRoot.addContent(encodePermissions());
+ aRoot.addContent(encodeLocks());
+ aRoot.addContent(encodeRevisionDescriptors());
+ aRoot.addContent(encodeRevisionDescriptor());
+ return aRoot;
+ }
+
+ protected Element encodeObject() {
+ Element aElementObjectNode = new Element("objectnode");
+ if (object != null) {
+ aElementObjectNode.setAttribute("classname", object.getClass().getName());
+ aElementObjectNode.setAttribute("uri", object.getUri());
+ if (object instanceof LinkNode) {
+ aElementObjectNode.setAttribute("linkTo", ((LinkNode) object).getLinkedUri());
+ }
+ aElementObjectNode.addContent(createBindings("children", "child", object.enumerateBindings()));
+ aElementObjectNode.addContent(createBindings("parents", "parent", object.enumerateParentBindings()));
+ aElementObjectNode.addContent(createElements("links", "link", object.enumerateLinks()));
+ } else {
+ // for null locks
+ aElementObjectNode.setAttribute("classname", "null");
+ aElementObjectNode.setAttribute("uri", uri.toString());
+ }
+ return aElementObjectNode;
+ }
+
+ protected Element encodePermissions() {
+ Element aPermissions = new Element("permissions");
+ if (permissions == null)
+ return aPermissions;
+
+ for (int aSize = permissions.size(), i = 0; i < aSize; i++) {
+ NodePermission aPermission = (NodePermission) permissions.elementAt(i);
+ aPermissions.addContent(encodeNodePermission(aPermission));
+ }
+ return aPermissions;
+ }
+
+ protected Element encodeLocks() {
+ Element aElementLocks = new Element("locks");
+ if (locks == null)
+ return aElementLocks;
+
+ for (int aSize = locks.size(), i = 0; i < aSize; i++) {
+ NodeLock aLock = (NodeLock) locks.elementAt(i);
+ Element aElementLock = new Element("lock");
+ aElementLock.setAttribute("subjectUri", aLock.getSubjectUri());
+ aElementLock.setAttribute("typeUri", aLock.getTypeUri());
+ aElementLock.setAttribute("date", dateFormat.format(aLock.getExpirationDate()));
+ aElementLock.setAttribute("inheritance", booleanToString(aLock.isInheritable()));
+ aElementLock.setAttribute("exclusive", booleanToString(aLock.isExclusive()));
+ aElementLock.setAttribute("lockId", aLock.getLockId());
+ aElementLock.setAttribute("owner",
+ aLock.getOwnerInfo() == null ? "" : aLock.getOwnerInfo());
+ aElementLocks.addContent(aElementLock);
+ }
+ return aElementLocks;
+ }
+
+ protected Element encodeRevisionDescriptors() {
+
+ Element aRevisionsHistory = new Element("revisionsHistory");
+ if (revisionDescriptors == null)
+ return aRevisionsHistory;
+
+ aRevisionsHistory.setAttribute(
+ "initialRevision",
+ encodeRevisionNumber(revisionDescriptors.getInitialRevision()));
+ aRevisionsHistory.setAttribute("useVersioning", booleanToString(revisionDescriptors.isVersioned()));
+
+ // System.out.println("---------- encodeRevisionDescriptors getLatestRevision="+
+ // revisionDescriptors.getLatestRevision());
+
+ Element aBranchesElement = new Element("branches");
+ Enumeration aBranches = revisionDescriptors.enumerateBranchNames();
+ while (aBranches.hasMoreElements()) {
+ String aBranchName = (String) aBranches.nextElement();
+ Element aElementBranch = new Element("branch");
+ aElementBranch.setAttribute("name", aBranchName);
+ NodeRevisionNumber aRevisionNumber = revisionDescriptors.getLatestRevision(aBranchName);
+ aElementBranch.setAttribute("lastestRevision", encodeRevisionNumber(aRevisionNumber));
+ aBranchesElement.addContent(aElementBranch);
+ }
+ aRevisionsHistory.addContent(aBranchesElement);
+
+ Element aRevisionsElement = new Element("revisions");
+ Enumeration aRevisions = revisionDescriptors.enumerateRevisionNumbers();
+ while (aRevisions.hasMoreElements()) {
+ NodeRevisionNumber aRevisionNumber = (NodeRevisionNumber) aRevisions.nextElement();
+ Element aRevisionElement = new Element("branch");
+ aRevisionElement.setAttribute("start", encodeRevisionNumber(aRevisionNumber));
+
+ Enumeration aSuccessors = revisionDescriptors.getSuccessors(aRevisionNumber);
+ while (aSuccessors.hasMoreElements()) {
+ NodeRevisionNumber aSuccessorRevisionNumber = (NodeRevisionNumber) aSuccessors.nextElement();
+ Element aSuccessorRevisionElement = new Element("revision");
+ aSuccessorRevisionElement.setAttribute("number", encodeRevisionNumber(aSuccessorRevisionNumber));
+ aRevisionElement.addContent(aSuccessorRevisionElement);
+ }
+ aRevisionsElement.addContent(aRevisionElement);
+ }
+ aRevisionsHistory.addContent(aRevisionsElement);
+
+ return aRevisionsHistory;
+ }
+
+ protected Element encodeRevisionDescriptor() {
+ Element aRet = new Element("descriptor");
+ if (descriptor == null)
+ return aRet;
+
+ for (Enumeration aEnum = descriptor.elements(); aEnum.hasMoreElements();) {
+ NodeRevisionDescriptor aRevisionDescriptor = (NodeRevisionDescriptor) aEnum.nextElement();
+ aRet.addContent(encodeRevisionDescriptor(aRevisionDescriptor));
+ }
+ return aRet;
+ }
+
+ protected void decode(Element aRoot) throws ServiceAccessException {
+ decodeObject(aRoot);
+ decodePermissions(aRoot);
+ decodeLocks(aRoot);
+ decodeRevisionDescriptors(aRoot);
+ decodeRevisionDescriptor(aRoot);
+ }
+
+ protected void decodeObject(Element aElement) throws ServiceAccessException {
+ Element aElementObjectNode = aElement.getChild("objectnode");
+ String aClasseName = aElementObjectNode.getAttributeValue("classname");
+ if (!"null".equals(aClasseName)) {
+ try {
+ String aUri = aElementObjectNode.getAttributeValue("uri");
+ Vector aChilds = createBindingVector(aElementObjectNode, "children", "child", false);
+ Vector aParents = createBindingVector(aElementObjectNode, "parents", "parent", true);
+ Vector aLinks = createVector(aElementObjectNode, "links", "link");
+ // System.out.println("--------- decodeObject aChilds="+aChilds);
+ // System.out.println("--------- decodeObject aLinks="+aLinks);
+ Class aTypes[] = null;
+ Object aArgs[] = null;
+
+ if (aClasseName.equals(LinkNode.class.getName())) {
+ String aLinkTo = aElementObjectNode.getAttributeValue("linkTo");
+ aTypes = new Class[] { String.class, Vector.class, Vector.class, String.class };
+ aArgs = new Object[] { aUri, aChilds, aLinks, aLinkTo };
+ } else {
+ aTypes = new Class[] { String.class, Vector.class, Vector.class, Vector.class };
+ aArgs = new Object[] { aUri, aChilds, aParents, aLinks };
+ }
+ object = (ObjectNode) createObject(aClasseName, aTypes, aArgs);
+ object.setUri(object.getUuri());
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ServiceAccessException(null, e);
+ }
+ uri = object.getUri();
+ } else {
+ object = null;
+ uri = aElementObjectNode.getAttributeValue("uri");
+ }
+ }
+
+ protected void decodePermissions(Element aElement) {
+ permissions = new Vector();
+ Element aPermissions = aElement.getChild("permissions");
+ List aList = aPermissions.getChildren();
+ for (int i = 0; i < aList.size(); i++) {
+ Element aChild = (Element) aList.get(i);
+ permissions.addElement(decodePermission(aChild, uri));
+ }
+ }
+
+ protected void decodeLocks(Element aElement) throws ServiceAccessException {
+ try {
+ locks = new Vector();
+ Element aElementLocks = aElement.getChild("locks");
+ List aList = aElementLocks.getChildren();
+
+ for (int i = 0; i < aList.size(); i++) {
+ Element aChild = (Element) aList.get(i);
+ String aSubject = aChild.getAttributeValue("subjectUri");
+ String aType = aChild.getAttributeValue("typeUri");
+ Date aDateExpiration = dateFormat.parse(aChild.getAttributeValue("date"));
+ boolean aInheritable = new Boolean(aChild.getAttributeValue("inheritance")).booleanValue();
+ boolean aNegative = new Boolean(aChild.getAttributeValue("exclusive")).booleanValue();
+ String aLockId = aChild.getAttributeValue("lockId");
+ String ownerInfo = aChild.getAttributeValue("owner");
+
+ locks.addElement(
+ new NodeLock(aLockId, uri, aSubject, aType, aDateExpiration, aInheritable, aNegative, ownerInfo));
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new ServiceAccessException(null, e);
+ }
+
+ }
+
+ protected void decodeRevisionDescriptors(Element aElement) {
+ Element aRevisionsHistory = aElement.getChild("revisionsHistory");
+
+ NodeRevisionNumber aInitialRevision =
+ decodeRevisionNumber(aRevisionsHistory.getAttributeValue("initialRevision"));
+ boolean aUseVersionning = new Boolean(aRevisionsHistory.getAttributeValue("useVersioning")).booleanValue();
+
+ Element aBranchesElement = aRevisionsHistory.getChild("branches");
+ if (aBranchesElement == null) {
+ revisionDescriptors =
+ new NodeRevisionDescriptors(
+ uri,
+ aInitialRevision,
+ new Hashtable(),
+ new Hashtable(),
+ new Hashtable(),
+ aUseVersionning);
+ return;
+ }
+
+ List aList = aBranchesElement.getChildren();
+ Hashtable aLastestRevisions = new Hashtable();
+ for (int i = 0; i < aList.size(); i++) {
+ Element aChild = (Element) aList.get(i);
+ String aName = aChild.getAttributeValue("name");
+ NodeRevisionNumber aRevisionNumber = decodeRevisionNumber(aChild.getAttributeValue("lastestRevision"));
+ aLastestRevisions.put(aName, aRevisionNumber);
+ }
+ Hashtable aBranches = new Hashtable();
+ Element aRevisionsElement = aRevisionsHistory.getChild("revisions");
+ aList = aRevisionsElement.getChildren();
+ for (int i = 0; i < aList.size(); i++) {
+ Element aChild = (Element) aList.get(i);
+ NodeRevisionNumber aStartNumber = decodeRevisionNumber(aChild.getAttributeValue("start"));
+ List aSuccessors = aChild.getChildren();
+ Vector aSuccessorsNumbers = new Vector();
+ for (int k = 0; k < aSuccessors.size(); k++) {
+ Element aSuccessor = (Element) aSuccessors.get(k);
+ NodeRevisionNumber aRevisionNumber = decodeRevisionNumber(aSuccessor.getAttributeValue("number"));
+ aSuccessorsNumbers.addElement(aRevisionNumber);
+ }
+ aBranches.put(aStartNumber, aSuccessorsNumbers);
+ }
+ revisionDescriptors =
+ new NodeRevisionDescriptors(
+ uri,
+ aInitialRevision,
+ new Hashtable(),
+ aLastestRevisions,
+ aBranches,
+ aUseVersionning);
+ }
+
+ protected void decodeRevisionDescriptor(Element aParent) {
+ descriptor = new Hashtable();
+
+ Element aElement = aParent.getChild("descriptor");
+ if (aElement == null)
+ return;
+
+ List aList = aElement.getChildren();
+
+ for (int i = 0; i < aList.size(); i++) {
+ Element aChild = (Element) aList.get(i);
+ String aBranchName = aChild.getAttributeValue("branchName");
+ NodeRevisionNumber aRevisionNumber = decodeRevisionNumber(aChild.getAttributeValue("number"));
+
+ Vector aLabels = new Vector();
+ Element aLabelsElement = (Element) aChild.getChild("labels");
+ List aLabelList = aLabelsElement.getChildren();
+ for (int k = 0; k < aLabelList.size(); k++) {
+ Element aLabel = (Element) aLabelList.get(k);
+ aLabels.addElement(aLabel.getAttributeValue("val"));
+ }
+
+ Hashtable aProperties = new Hashtable();
+ Element aPropertiesElement = (Element) aChild.getChild("properties");
+ List aPropertiesList = aPropertiesElement.getChildren();
+ for (int k = 0; k < aPropertiesList.size(); k++) {
+ Element aProperty = (Element) aPropertiesList.get(k);
+ NodeProperty aProp = decodeNodeProperty(aProperty, uri);
+ String key = aProperty.getAttributeValue("namespace") + aProperty.getAttributeValue("name");
+ aProperties.put(key, aProp);
+ }
+ NodeRevisionDescriptor aNode =
+ new NodeRevisionDescriptor(aRevisionNumber, aBranchName, aLabels, aProperties);
+ descriptor.put(aRevisionNumber.toString(), aNode);
+ }
+ }
+
+ protected ServiceAccessException createException(JDOMException e, String uri) {
+ getLogger().log(
+ "JDOM error on " + uri + ": " + e.getMessage(),
+ LOG_CHANNEL,
+ Logger.ERROR);
+ return new ServiceAccessException(service, e);
+ }
+
+ protected ServiceAccessException createException(ObjectNotFoundException e, String uri) {
+ getLogger().log(
+ "JDOM error on " + uri + ": " + e.getMessage(),
+ LOG_CHANNEL,
+ Logger.ERROR);
+ return new ServiceAccessException(service, e);
+ }
+}
Added: jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/PureXMLUtilities.java
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/PureXMLUtilities.java?view=auto&rev=524298
==============================================================================
--- jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/PureXMLUtilities.java (added)
+++ jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/PureXMLUtilities.java Fri Mar 30 15:24:26 2007
@@ -0,0 +1,333 @@
+
+package com.ibm.db2.purexml;
+
+import java.sql.*;
+import java.io.*;
+import java.util.*;
+import java.util.regex.Pattern;
+
+import org.jdom.input.*;
+import org.jdom.*;
+
+import org.apache.slide.content.*;
+import org.apache.slide.structure.ObjectNode;
+
+public class PureXMLUtilities {
+
+ public static String getResourceID(String uri, Connection cnn)throws SQLException{
+ if(uri.startsWith("/history"))
+ return uri;
+ PreparedStatement stmt = null;
+ String docID = null;
+ ResultSet rs = null;
+ String strSQL = "SELECT ID FROM WEBDAV.SLIDEMETADATA WHERE URI = ?";
+ stmt = cnn.prepareStatement(strSQL);
+ stmt.setString(1, uri);
+ rs = stmt.executeQuery();
+ while(rs.next())
+ docID = rs.getString(1);
+ return docID;
+ }
+
+ public static int getColumnSQLType(Connection cnn, String schema, String tableName, String columnName)throws SQLException{
+ ResultSet rs = null;
+ Object sqlType = null;
+ rs = cnn.getMetaData().getColumns(null,schema,tableName,columnName);
+ if(rs.next()){
+ sqlType = rs.getObject(5);
+ }
+ rs.close();
+
+ return Integer.parseInt(sqlType.toString());
+ }
+
+ public static boolean isVersioningMetadata(String uri){
+ return Pattern.matches("^/history/\\d{1,}/\\d{1,}\\.\\d{1,}\\.def\\.xml$", uri.trim());
+ }
+
+ public static boolean isDocXML(String mimeType){
+ return mimeType.equalsIgnoreCase("text/xml");
+ }
+
+ public static boolean isVersionedDocXML(String uri, Connection cnn)throws SQLException{
+ String parentUri = getParentUri(uri,cnn);
+ boolean isXML = false;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ String strSQL = "SELECT 1 FROM WEBDAV.SLIDEMETADATA as SLIDE WHERE " +
+ "XMLExists('$n/data/descriptor/revisions/properties[property/@value = \"text/xml\"]' " +
+ "passing slide.metadata as \"n\") AND slide.uri = ?";
+ stmt = cnn.prepareStatement(strSQL);
+ stmt.setString(1, parentUri);
+ rs = stmt.executeQuery();
+ isXML = rs.next();
+ close(stmt);
+ return isXML;
+ }
+
+ public static boolean isExcelDoc(Connection cnn, CollectionInfo cInfo, ResourceInfo rInfo){
+ String strSQL = "SELECT 1 FROM "+cInfo.getTableSchema()+"."+cInfo.getTableName() +
+ " WHERE XMLEXISTS('declare default element namespace \"urn:schemas-microsoft-com:office:excel\";" +
+ " $d//ExcelWorkbook' passing "+rInfo.getColumnContentName()+ " as \"d\") AND " + cInfo.getColumnIDName() +" = ?";
+ boolean isExcel = false;
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ try{
+ stmt = cnn.prepareStatement(strSQL);
+ stmt.setString(1, rInfo.getDocID());
+ rs = stmt.executeQuery();
+ isExcel = rs.next();
+ }catch(Exception ex){
+ //System.out.println(ex.toString());
+ }finally{
+ try{
+ stmt.close();
+ rs.close();}
+ catch(Exception ex){}
+ }
+ return isExcel;
+ }
+
+ private static String formatMetadataUriToHistoryUri(String uri){
+ uri = uri.substring(0,uri.indexOf(".def.xml"));
+ String tmp1 = uri.substring(0,uri.lastIndexOf("/"));
+ String tmp2 = uri.substring(uri.lastIndexOf("/")+1,uri.length());
+ return tmp1 + "_" + tmp2;
+ }
+
+ public static ResourceInfo getHistoryResourceInfo(String versionedUri, boolean isXML){
+ String columnName = (isXML) ? "DATA" : "ATTACHMENT";
+ String uri = formatMetadataUriToHistoryUri(versionedUri);
+ return new ResourceInfo(uri,columnName);
+ }
+
+ public static void updateResourceInfo(ResourceInfo info, String uri, Connection cnn)throws SQLException{
+ PreparedStatement stmt = null;
+ String strSQL = "UPDATE WEBDAV.SLIDEMETADATA SET COLUMNCONTENTNAME = ?, ID = ? WHERE URI = ?";
+ stmt = cnn.prepareStatement(strSQL);
+ stmt.setString(1, info.getColumnContentName());
+ stmt.setString(2,info.getDocID());
+ stmt.setString(3, uri);
+ stmt.executeUpdate();
+ close(stmt);
+ }
+
+ public static void updateCollectionInfo(CollectionInfo info, String uri, Connection cnn)throws SQLException{
+ PreparedStatement stmt = null;
+ String strSQL = "UPDATE WEBDAV.SLIDEMETADATA SET TABLESCHEMA = ?, TABLENAME = ?, COLUMNIDNAME = ?" +
+ " WHERE URI = ?";
+ //try{
+ stmt = cnn.prepareStatement(strSQL);
+ stmt.setString(1, info.getTableSchema());
+ stmt.setString(2, info.getTableName());
+ //stmt.setString(3, info.getColumnName());
+ stmt.setString(3, info.getColumnIDName());
+ stmt.setString(4, uri);
+ stmt.executeUpdate();
+ //}catch(Exception ex){
+ //System.out.println(ex.toString());
+ //}
+ //finally{
+ close(stmt);
+ //}
+ }
+
+ public static boolean isExposedCollection(Hashtable descriptor){
+ if (descriptor != null){
+ for (Enumeration aEnum = descriptor.elements(); aEnum.hasMoreElements();) {
+ NodeRevisionDescriptor aRevisionDescriptor = (NodeRevisionDescriptor) aEnum.nextElement();
+ NodeProperty prop = aRevisionDescriptor.getProperty("isExposedCollection");
+ if(prop != null)
+ return true;
+ //String resourceType = aRevisionDescriptor.getResourceType();
+ //if(resourceType.indexOf("<collection/>") > -1)
+ //return true;
+ }
+ }
+ return false;
+ }
+
+ public static void updateExposedCollection(String uri, Connection cnn)throws SQLException{
+ CallableStatement proc = null;
+
+ String strCommand = "<updates>" +
+ "<update col=\"1\" action=\"append\" path=\"data/descriptor/revisions/properties \">" +
+ "<property name=\"columncontentname\" namespace=\"DAV:\" value=\""+PureXMLUtilities.getExposedColumnContentName(PureXMLUtilities.getParentUri(uri, cnn), cnn)+"\" type=\"\" protected=\"false\">"+
+ "<permissions/>"+
+ "</property>"+
+ "</update>" +
+ "</updates>";
+
+ String strCommand2 = "<updates>" +
+ "<update col=\"1\" action=\"append\" path=\"data/descriptor/revisions/properties \">" +
+ "<property name=\"isExposedCollection\" namespace=\"DAV:\" value=\"true\" type=\"\" protected=\"false\">"+
+ "<permissions/>"+
+ "</property>"+
+ "</update>" +
+ "</updates>";
+
+ String strQuery = "SELECT METADATA FROM WEBDAV.SLIDEMETADATA WHERE URI = '"+ uri +"'";
+ String strUpdate = "UPDATE WEBDAV.SLIDEMETADATA SET METADATA = ? WHERE URI = '"+ uri +"'";
+
+ proc = cnn.prepareCall("{ call WEBDAV.XMLUpdate(?,?,?,?,?) }");
+ proc.setString(1,strCommand);
+ proc.setString(2,strQuery);
+ proc.setString(3,strUpdate);
+ proc.registerOutParameter(4, Types.INTEGER);
+ proc.registerOutParameter(5, Types.VARCHAR);
+ proc.execute();
+
+ proc.setString(1, strCommand2);
+ proc.execute();
+
+ }
+
+ public static String getExposedColumnContentName(String uri, Connection cnn)throws SQLException{
+ String strSQL = "SELECT xmlquery('$i//property[@name=\"columncontentname\"]' passing METADATA as \"i\") FROM WEBDAV.SLIDEMETADATA WHERE URI= ? ";
+ String retValue = null;
+ Document xmlDoc = null;
+ Element rootElem = null;
+ SAXBuilder sax = new SAXBuilder();
+ PreparedStatement stmt = cnn.prepareStatement(strSQL);
+ stmt.setString(1,uri);
+ ResultSet rs = stmt.executeQuery();
+ while(rs.next()){
+ retValue = rs.getString(1);
+ }
+ close(stmt);
+ if(retValue != null){
+ try{
+ xmlDoc = sax.build(new StringReader(retValue));
+ rootElem = xmlDoc.getRootElement();
+ retValue = rootElem.getAttributeValue("value");
+ }catch(JDOMException ex){
+ }catch(IOException io){}
+ }
+ return retValue;
+ }
+
+ public static boolean isExposedCollection(String uri, Connection cnn)throws SQLException{
+ boolean isExposed = false;
+ String strSQL = "SELECT 1 FROM WEBDAV.SLIDEMETADATA as SLIDE " +
+ "WHERE XMLExists('$n/data/descriptor/revisions/properties[property/@name = \"isExposedCollection\"]' " +
+ "passing slide.metadata as \"n\") AND slide.uri = ?";
+
+ PreparedStatement stmt = null;
+ stmt = cnn.prepareStatement(strSQL);
+ stmt.setString(1, uri);
+ ResultSet rs = stmt.executeQuery();
+ isExposed = rs.next();
+
+ close(stmt);
+ return isExposed;
+ }
+
+ public static boolean isCollection(Hashtable descriptor){
+ if (descriptor != null){
+ for (Enumeration aEnum = descriptor.elements(); aEnum.hasMoreElements();) {
+ NodeRevisionDescriptor aRevisionDescriptor = (NodeRevisionDescriptor) aEnum.nextElement();
+ String resourceType = aRevisionDescriptor.getResourceType();
+ if(resourceType.indexOf("<collection/>") > -1)
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static ResourceInfo getResourceInfo(String uri, Connection cnn)throws SQLException{
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ ResourceInfo rInfo = null;
+ String tmpColName = (uri.startsWith("/history")) ? "ID" : "URI";
+ String strSQL = "SELECT ID, COLUMNCONTENTNAME FROM WEBDAV.SLIDEMETADATA WHERE "+tmpColName+" = ?";
+ stmt = cnn.prepareStatement(strSQL);
+ stmt.setString(1, uri);
+ rs = stmt.executeQuery();
+ while(rs.next()){
+ rInfo = new ResourceInfo(rs.getString(1), rs.getString(2));
+ }
+ close(stmt);
+ return rInfo;
+ }
+
+ public static CollectionInfo getCollectionInfo(String uri, Connection cnn)throws SQLException{
+ if(uri==null)
+ return null;
+ if(uri.equals("/.def.xml"))
+ return new CollectionInfo(uri);
+ if(uri.startsWith("/history"))
+ return new CollectionInfo(uri);
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ CollectionInfo info = null;
+ String strSQL = "SELECT TABLESCHEMA, TABLENAME, COLUMNIDNAME FROM WEBDAV.SLIDEMETADATA WHERE URI = ?";
+ //try{
+ stmt = cnn.prepareStatement(strSQL);
+ stmt.setString(1, uri);
+ rs = stmt.executeQuery();
+ while(rs.next())
+ info = new CollectionInfo(rs.getString(1), rs.getString(2), rs.getString(3));
+ //}catch(Exception ex){
+ //System.out.println(ex.toString());
+ //}
+ //finally{
+ close(stmt);
+ //}
+ return info;
+ }
+
+ public static String getXMLQueryString(boolean isExcelDoc, CollectionInfo cInfo, ResourceInfo rInfo){
+ if(isExcelDoc){
+ return "SELECT XMLSERIALIZE(" + rInfo.getColumnContentName() + " AS BLOB(1000M) INCLUDING XMLDECLARATION)" +
+ " FROM " + cInfo.getTableSchema() + "." + cInfo.getTableName() + " WHERE " +
+ cInfo.getColumnIDName() + " = ?";
+ }
+ return "SELECT XMLSERIALIZE(" + rInfo.getColumnContentName() + " AS BLOB(1000M))" +
+ " FROM " + cInfo.getTableSchema() + "." + cInfo.getTableName() + " WHERE " +
+ cInfo.getColumnIDName() + " = ?";
+
+ /*if(isExcelDoc){
+ return "SELECT XMLSERIALIZE(DATA AS BLOB(1M) INCLUDING XMLDECLARATION) FROM WEBDAV.DATADEFAULT WHERE " +
+ "ID = ?";
+ }
+ return "SELECT XMLSERIALIZE(DATA AS BLOB(1M)) FROM WEBDAV.DATADEFAULT WHERE ID = ?";*/
+ }
+
+ public static String getParentUri(String resourceUri, Connection cnn)throws SQLException{
+ PreparedStatement stmt = null;
+ String uri = null;
+ ResultSet rs = null;
+ String strSQL = "SELECT XMLQUERY('fn:data($m[1]/data/objectnode/parents/parent/@uuri)' " +
+ "passing by ref SLIDE.METADATA as \"m\" returning sequence) FROM " +
+ "WEBDAV.SLIDEMETADATA as SLIDE WHERE " +
+ "SLIDE.URI = ?";
+ stmt = cnn.prepareStatement(strSQL);
+ stmt.setString(1, resourceUri);
+ rs = stmt.executeQuery();
+ while(rs.next())
+ uri = rs.getString(1);
+ close(stmt);
+ return (uri==null) ? null : (uri + ".def.xml");
+ }
+
+ public static String getParentUri(ObjectNode obj){
+ if(obj.getUri().equals("/"))
+ return "/.def.xml";
+ if(obj.getUri().startsWith("/history"))
+ return "/history.def.xml";
+ Enumeration aEnum = obj.enumerateParentBindings();
+ ObjectNode.Binding binding = null;
+ String tmpUri = null;
+ while (aEnum.hasMoreElements()) {
+ binding = (ObjectNode.Binding) aEnum.nextElement();
+ tmpUri = binding.getUuri() + ".def.xml";
+ }
+ return tmpUri;
+ }
+
+ private static void close(PreparedStatement stmt){
+ try{
+ stmt.close();
+ }catch(Exception ex){}
+ }
+}
\ No newline at end of file
Added: jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/ResourceInfo.java
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/ResourceInfo.java?view=auto&rev=524298
==============================================================================
--- jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/ResourceInfo.java (added)
+++ jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/ResourceInfo.java Fri Mar 30 15:24:26 2007
@@ -0,0 +1,21 @@
+
+package com.ibm.db2.purexml;
+
+public class ResourceInfo {
+
+ private String _columnContentName;
+ private String _docID;
+
+ public ResourceInfo(String docID, String columnContentName){
+ this._columnContentName = columnContentName;
+ this._docID = docID;
+ }
+
+ public String getDocID(){
+ return this._docID;
+ }
+
+ public String getColumnContentName(){
+ return this._columnContentName;
+ }
+}
Added: jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/StoreContentZip.java
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/StoreContentZip.java?view=auto&rev=524298
==============================================================================
--- jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/StoreContentZip.java (added)
+++ jakarta/slide/trunk/proposals/purexmladapter/slide/com/ibm/db2/purexml/StoreContentZip.java Fri Mar 30 15:24:26 2007
@@ -0,0 +1,149 @@
+/*
+ * $Header: /cvs/slide/src/stores/com/ibm/db2/purexml/StoreContentZip.java,v 1.1 2006/11/28 19:44:20 zocourto Exp $
+ * $Revision: 1.1 $
+ * $Date: 2006/11/28 19:44:20 $
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2003 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.ibm.db2.purexml;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * Title: StoreContentZip
+ *
+ * This util class can generally be used to zip/unzip an inputstream
+ * Returns the zip/unzip data as both output/input streams. This is used
+ * in the J2EEContentStore
+ * @version $Revision: 1.1 $
+ */
+
+class StoreContentZip {
+
+ protected static final int ZIP_BUFFER = 2048;
+ private long contentLength = 0;
+ private long initialContentLength = -1;
+ private OutputStream theOS = null;
+
+ /**
+ * Constructor for StoreContentZip.
+ */
+ public StoreContentZip() {
+ super();
+ contentLength = 0;
+ }
+
+ /**
+ * This method compress the input stream and returns the outputstream
+ * @param InputStream inIPS
+ * @exception IOException,ZipException
+ * @return the compressed OutputStream
+ */
+
+ public void Zip(InputStream inIPS)
+ throws IOException, ZipException{
+ int byteCount = 0;
+ contentLength = 0;
+ initialContentLength = 0;
+ byte data[] = new byte[ZIP_BUFFER];
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ZipOutputStream zoutp = new ZipOutputStream(baos);
+ zoutp.putNextEntry(new ZipEntry("zippedfile"));
+ while((byteCount = inIPS.read(data,0,ZIP_BUFFER)) != -1 ) {
+ zoutp.write(data,0,byteCount);
+ initialContentLength += byteCount;
+ }
+ zoutp.finish();
+ zoutp.flush();
+ zoutp.close();
+ baos.flush();
+ baos.close();
+ contentLength = (long)baos.size();
+ theOS = baos;
+ }
+
+ /**
+ * This method decompress the input stream and returns the outputstream
+ * @param InputStream inIPS
+ * @exception IOException,ZipException
+ * @return the decompressed OutputStream
+ */
+ public void UnZip(InputStream inIPS)
+ throws IOException, ZipException{
+ int byteCount = 0;
+ contentLength = 0;
+ byte indata[] = new byte[ZIP_BUFFER];
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ZipInputStream zinp = new ZipInputStream(inIPS);
+ while (zinp.getNextEntry() != null) {
+ while ((byteCount = zinp.read(indata,0,ZIP_BUFFER)) != -1 ) {
+ baos.write(indata,0,byteCount);
+ }
+ }
+ contentLength = (long)baos.size();
+ baos.flush();
+ baos.close();
+ zinp.close();
+ theOS = baos;
+ }
+
+ /**
+ * This method returns the compressed/decompressed stream as InputStream
+ * @param void
+ * @exception IOException,ZipException
+ * @return the processed InputStream
+ */
+ public InputStream getInputStream()
+ throws IOException, ZipException{
+ return new ByteArrayInputStream(
+ ((ByteArrayOutputStream)theOS).toByteArray());
+ }
+
+ /**
+ * This method returns the compressed/decompressed stream as O/PStream
+ * @param void
+ * @exception IOException,ZipException
+ * @return the processed InputStream
+ */
+ public OutputStream getOutputStream()
+ throws IOException, ZipException{
+ return theOS;
+ }
+
+ /**
+ * Gets the length.
+ * @return return the length of the un/compressed Stream
+ */
+ public long getContentLength() {
+ return contentLength;
+ }
+
+ public long getInitialContentLength() {
+ return initialContentLength;
+ }
+
+}
Added: jakarta/slide/trunk/proposals/purexmladapter/slide/db2purexml-stores-1.0.jar
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/proposals/purexmladapter/slide/db2purexml-stores-1.0.jar?view=auto&rev=524298
==============================================================================
Binary file - no diff available.
Propchange: jakarta/slide/trunk/proposals/purexmladapter/slide/db2purexml-stores-1.0.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: jakarta/slide/trunk/proposals/purexmladapter/slide/dbsetup/DB2XMLFUNCTIONS.jar
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/proposals/purexmladapter/slide/dbsetup/DB2XMLFUNCTIONS.jar?view=auto&rev=524298
==============================================================================
Binary file - no diff available.
Propchange: jakarta/slide/trunk/proposals/purexmladapter/slide/dbsetup/DB2XMLFUNCTIONS.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: jakarta/slide/trunk/proposals/purexmladapter/slide/dbsetup/PUREXMLSP.jar
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/proposals/purexmladapter/slide/dbsetup/PUREXMLSP.jar?view=auto&rev=524298
==============================================================================
Binary file - no diff available.
Propchange: jakarta/slide/trunk/proposals/purexmladapter/slide/dbsetup/PUREXMLSP.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: jakarta/slide/trunk/proposals/purexmladapter/slide/dbsetup/setup.db2
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/proposals/purexmladapter/slide/dbsetup/setup.db2?view=auto&rev=524298
==============================================================================
--- jakarta/slide/trunk/proposals/purexmladapter/slide/dbsetup/setup.db2 (added)
+++ jakarta/slide/trunk/proposals/purexmladapter/slide/dbsetup/setup.db2 Fri Mar 30 15:24:26 2007
@@ -0,0 +1,135 @@
+-- To run this file type "db2 -tvf setup.db2" from the DB2 command line processor.
+--
+--echo ~~~~~~~~~~~~~~~~~;
+--echo ~ Create XML DB ~;
+--echo ~~~~~~~~~~~~~~~~~;
+
+create database SLIDEXML using codeset utf-8 territory us;
+
+--echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~;
+--echo ~ Configuring DB2 Server ~;
+--echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~;
+
+--update database configuration for SLIDEXML using app_ctl_heap_sz 8192;
+--update database configuration for SLIDEXML using LOGFILSIZ 4000;
+--update database configuration for SLIDEXML using applheapsz 8192;
+--update dbm cfg using JAVA_HEAP_SZ 4096;
+
+--echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
+--echo ~ Restart DB for configuration to take place ~;
+--echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
+
+--db2stop;
+--db2start;
+
+echo ~~~~~~~~~~~~~~~~~;
+echo ~ CONNECT TO DB ~;
+echo ~~~~~~~~~~~~~~~~~;
+
+connect to SLIDEXML;
+
+echo ~~~~~~~~~~~~~~~~~~~~~~~;
+echo ~ DROP STORAGE TABLES ~;
+echo ~~~~~~~~~~~~~~~~~~~~~~~;
+
+DROP TABLE WEBDAV.SLIDEMETADATA;
+DROP TABLE WEBDAV.DATADEFAULT;
+DROP TABLE WEBDAV.HISTORY;
+
+echo ~~~~~~~~~~~~~~~~~~~~~~~~~~;
+echo ~ DROP STORED PROCEDURES ~;
+echo ~~~~~~~~~~~~~~~~~~~~~~~~~~;
+
+DROP PROCEDURE WEBDAV.enable;
+DROP PROCEDURE WEBDAV.registerColumn;
+DROP PROCEDURE WEBDAV.createCollection;
+DROP PROCEDURE WEBDAV.XMLUPDATE;
+
+echo ~~~~~~~~~~~~~~~~~~~~~~~~~~;
+echo ~ CREATE TABLES ~;
+echo ~~~~~~~~~~~~~~~~~~~~~~~~~~;
+CREATE TABLE WEBDAV.SLIDEMETADATA
+(
+ URI VARCHAR(500) not null,
+ METADATA XML not null,
+ ID VARCHAR(500) DEFAULT '0',
+ TABLESCHEMA VARCHAR(256),
+ TABLENAME VARCHAR(256),
+ COLUMNCONTENTNAME VARCHAR(256),
+ COLUMNIDNAME VARCHAR(256),
+ CONSTRAINT "URI_PK" primary key(URI)
+);
+
+CREATE TABLE WEBDAV.DATADEFAULT
+(
+ ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ DATA XML,
+ ABOUT XML,
+ ATTACHMENT BLOB(1000m),
+ CONSTRAINT "ID_PK" primary key(ID)
+);
+
+CREATE TABLE WEBDAV.HISTORY
+(
+ URI VARCHAR(500) not null,
+ DATA XML,
+ ATTACHMENT BLOB(1000m),
+ CONSTRAINT "HISTID_PK" primary key(URI)
+);
+
+echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
+echo ~ SETUP JARs FOR STORED PROCEDURES ~;
+echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
+
+CALL SQLJ.REMOVE_JAR('WEBDAV.PUREXML_SLIDESP');
+CALL SQLJ.REMOVE_JAR('WEBDAV.DB2XMLFUNCTIONS');
+
+CALL SQLJ.INSTALL_JAR('file:c:/slide/dbsetup/PUREXMLSP.jar','WEBDAV.PUREXML_SLIDESP');
+CALL SQLJ.INSTALL_JAR('file:c:/slide/dbsetup/DB2XMLFUNCTIONS.jar','WEBDAV.db2xmlfunctions');
+
+echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
+echo ~ CREATE STORED PROCEDURES ~;
+echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
+
+CREATE PROCEDURE WEBDAV.enable( )
+ DYNAMIC RESULT SETS 0
+ LANGUAGE JAVA
+ EXTERNAL NAME 'WEBDAV.PUREXML_SLIDESP:com.ibm.db2.purexml.storeproc.PUREXMLSP.enable'
+ PARAMETER STYLE JAVA
+ NO DBINFO
+ NOT FENCED;
+
+CREATE PROCEDURE WEBDAV.registerColumn(IN SCHEMANAME VARCHAR(256), IN TABLENAME VARCHAR(256), IN COLUMNIDNAME VARCHAR(256),
+ IN COLUMNCONTENTNAME VARCHAR(256), IN CREATOR VARCHAR(100), IN AUTOVERSIONING VARCHAR(5), OUT outputMessage VARCHAR(32000))
+ DYNAMIC RESULT SETS 0
+ LANGUAGE JAVA
+ EXTERNAL NAME 'WEBDAV.PUREXML_SLIDESP:com.ibm.db2.purexml.storeproc.PUREXMLSP.registerColumn'
+ PARAMETER STYLE JAVA
+ NO DBINFO
+ NOT FENCED;
+
+CREATE PROCEDURE WEBDAV.createCollection(IN PARENTPATH VARCHAR(200), IN COLLECTIONNAME VARCHAR(200), IN SCHEMANAME VARCHAR(256),
+ IN TABLENAME VARCHAR(256), IN COLUMNIDNAME VARCHAR(256), IN COLUMNCONTENTNAME VARCHAR(256), IN CREATOR VARCHAR(200))
+ DYNAMIC RESULT SETS 0
+ LANGUAGE JAVA
+ EXTERNAL NAME 'WEBDAV.PUREXML_SLIDESP:com.ibm.db2.purexml.storeproc.PUREXMLSP.createCollection'
+ PARAMETER STYLE JAVA
+ NO DBINFO
+ NOT FENCED;
+
+CREATE PROCEDURE WEBDAV.XMLUPDATE(IN COMMANDSQL VARCHAR(32000), IN QUERYSQL VARCHAR(32000), IN UPDATESQL VARCHAR(32000),
+ OUT errorCode INTEGER, OUT errorMsg VARCHAR(32000))
+ DYNAMIC RESULT SETS 0
+ LANGUAGE JAVA
+ PARAMETER STYLE JAVA
+ NO DBINFO
+ FENCED
+ EXTERNAL NAME 'WEBDAV.db2xmlfunctions:com.ibm.db2.xml.functions.XMLUpdate.Update';
+
+CALL SQLJ.REFRESH_CLASSES();
+
+
+echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
+echo ~ CALL STORE PROCEDURE TO ENABLE ~;
+echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
+--db2 call webdav.enable
\ No newline at end of file