You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2010/12/23 03:48:11 UTC
svn commit: r1052148 [9/17] - in /oodt/branches/wengine-branch/filemgr: ./
.settings/ src/ src/main/ src/main/assembly/ src/main/bin/ src/main/java/
src/main/java/gov/ src/main/java/gov/nasa/ src/main/java/gov/nasa/jpl/
src/main/java/gov/nasa/jpl/oodt/...
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/ConnectionException.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/ConnectionException.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/ConnectionException.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/ConnectionException.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.exceptions;
+
+/**
+ * @author woollard
+ * @version $Revision$
+ *
+ * <p>An exception that is thrown when a connection cannot
+ * be established by a client.</p>
+ *
+ */
+public class ConnectionException extends Exception {
+
+ private static final long serialVersionUID = -7260478787886603401L;
+
+ /**
+ * <p>Default Constructor</p>
+ */
+ public ConnectionException() {
+ super();
+ }
+
+ /**
+ * @param message The message for this exception.
+ */
+ public ConnectionException(String message) {
+ super(message);
+ }
+
+ public ConnectionException(String message, Throwable t) {
+ super(message, t);
+ }
+
+}
\ No newline at end of file
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/DataTransferException.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/DataTransferException.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/DataTransferException.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/DataTransferException.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.exceptions;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ *
+ * <p>An exception thrown during data transfer.</p>
+ *
+ */
+public class DataTransferException extends Exception {
+
+ /* serial version UID */
+ private static final long serialVersionUID = 3976741354426479924L;
+
+ /**
+ *
+ */
+ public DataTransferException() {
+ super();
+ }
+
+ /**
+ * @param message
+ */
+ public DataTransferException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public DataTransferException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public DataTransferException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/IngestException.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/IngestException.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/IngestException.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/IngestException.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.exceptions;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ *
+ * <p>An exception when ingesting a product.</p>
+ *
+ */
+public class IngestException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4134078866650777281L;
+
+ /**
+ *
+ */
+ public IngestException() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param arg0
+ */
+ public IngestException(String arg0) {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param arg0
+ * @param arg1
+ */
+ public IngestException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param arg0
+ */
+ public IngestException(Throwable arg0) {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/QueryFormulationException.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/QueryFormulationException.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/QueryFormulationException.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/QueryFormulationException.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.exceptions;
+
+/**
+ * @author woollard
+ * @version $Revision$
+ *
+ * <p>A generic exception that occured when dealing with the
+ * Catalog.</p>
+ *
+ */
+public class QueryFormulationException extends Exception {
+
+ private static final long serialVersionUID = 1641381629886581382L;
+
+ /**
+ * <p>Default Constructor</p>
+ */
+ public QueryFormulationException() {
+ super();
+ }
+
+ /**
+ * @param message The message for this exception.
+ */
+ public QueryFormulationException(String message) {
+ super(message);
+ }
+
+ public QueryFormulationException(String message, Throwable t) {
+ super(message, t);
+ }
+
+}
\ No newline at end of file
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/RepositoryManagerException.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/RepositoryManagerException.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/RepositoryManagerException.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/RepositoryManagerException.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.exceptions;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ *
+ * <p>An exception thrown from the RepositoryManager interface.</p>
+ *
+ */
+public class RepositoryManagerException extends Exception {
+
+ private static final long serialVersionUID = 3688502208018920497L;
+
+ /**
+ *
+ */
+ public RepositoryManagerException() {
+ super();
+ }
+
+ /**
+ * @param message
+ */
+ public RepositoryManagerException(String message) {
+ super(message);
+ }
+
+ public RepositoryManagerException(String message, Throwable t) {
+ super(message, t);
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/ValidationLayerException.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/ValidationLayerException.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/ValidationLayerException.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/ValidationLayerException.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.exceptions;
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ *
+ * <p>An exception thrown by the validation layer.</p>
+ *
+ */
+public class ValidationLayerException extends Exception {
+
+ /* serial version UID */
+ private static final long serialVersionUID = -929293299393L;
+
+ /**
+ *
+ */
+ public ValidationLayerException() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param arg0
+ */
+ public ValidationLayerException(String arg0) {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param arg0
+ * @param arg1
+ */
+ public ValidationLayerException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param arg0
+ */
+ public ValidationLayerException(Throwable arg0) {
+ super(arg0);
+ // TODO Auto-generated constructor stub
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/VersioningException.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/VersioningException.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/VersioningException.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/exceptions/VersioningException.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.exceptions;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.versioning.Versioner;
+
+
+/**
+ * @author mattmann
+ * @version $Revision$
+ *
+ * <p>An exception thrown during Versioning by a {@link Versioner}.</p>
+ *
+ */
+public class VersioningException extends Exception {
+
+ /* default serial UID */
+ private static final long serialVersionUID = 3256999960552615984L;
+
+ /**
+ *
+ */
+ public VersioningException() {
+ super();
+ }
+
+ /**
+ * @param message
+ */
+ public VersioningException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public VersioningException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public VersioningException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeType.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeType.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeType.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeType.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,369 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.mime;
+
+import java.util.ArrayList;
+
+/**
+ * Defines a Mime Content Type. Based on original class written by
+ * J. Charron and H. Kodungallur with the
+ * <a href="http://lucene.apache.org/nutch">Apache Nutch</a> project
+ *
+ * @author ahart
+ * @author bfoster
+ */
+public final class MimeType {
+
+ /** The primary and sub types separator */
+ private final static String SEPARATOR = "/";
+
+ /** The parameters separator */
+ private final static String PARAMS_SEP = ";";
+
+ /** Special characters not allowed in content types. */
+ private final static String SPECIALS = "()<>@,;:\\\"/[]?=";
+
+ /** The Mime-Type full name */
+ private String name = null;
+
+ /** The Mime-Type primary type */
+ private String primary = null;
+
+ /** The Mime-Type sub type */
+ private String sub = null;
+
+ /** The Mime-Type description */
+ private String description = null;
+
+ /** The Mime-Type associated extensions */
+ private ArrayList<String> extensions = null;
+
+ /** The magic bytes associated to this Mime-Type */
+ private ArrayList<Magic> magics = null;
+
+ /** The minimum length of data to provides for magic analyzis */
+ private int minLength = 0;
+
+ /**
+ * Creates a MimeType from a String.
+ *
+ * @param name
+ * the MIME content type String.
+ */
+ public MimeType(String name) throws MimeTypeException {
+
+ if (name == null || name.length() <= 0) {
+ throw new MimeTypeException("The type can not be null or empty");
+ }
+
+ // Split the two parts of the Mime Content Type
+ String[] parts = name.split(SEPARATOR, 2);
+
+ // Checks validity of the parts
+ if (parts.length != 2) {
+ throw new MimeTypeException("Invalid Content Type " + name);
+ }
+ init(parts[0], parts[1]);
+ }
+
+ /**
+ * Creates a MimeType with the given primary type and sub type.
+ *
+ * @param primary
+ * the content type primary type.
+ * @param sub
+ * the content type sub type.
+ */
+ public MimeType(String primary, String sub) throws MimeTypeException {
+ init(primary, sub);
+ }
+
+ /** Init method used by constructors. */
+ private void init(String primary, String sub) throws MimeTypeException {
+
+ // Preliminary checks...
+ if ((primary == null) || (primary.length() <= 0) || (!isValid(primary))) {
+ throw new MimeTypeException("Invalid Primary Type " + primary);
+ }
+ // Remove optional parameters from the sub type
+ String clearedSub = null;
+ if (sub != null) {
+ clearedSub = sub.split(PARAMS_SEP)[0];
+ }
+ if ((clearedSub == null) || (clearedSub.length() <= 0)
+ || (!isValid(clearedSub))) {
+ throw new MimeTypeException("Invalid Sub Type " + clearedSub);
+ }
+
+ // All is ok, assign values
+ this.name = primary + SEPARATOR + clearedSub;
+ this.primary = primary;
+ this.sub = clearedSub;
+ this.extensions = new ArrayList<String>();
+ this.magics = new ArrayList<Magic>();
+ }
+
+ /**
+ * Cleans a content-type. This method cleans a content-type by removing its
+ * optional parameters and returning only its
+ * <code>primary-type/sub-type</code>.
+ *
+ * @param type
+ * is the content-type to clean.
+ * @return the cleaned version of the specified content-type.
+ * @throws MimeTypeException
+ * if something wrong occurs during the parsing/cleaning of the
+ * specified type.
+ */
+ public final static String clean(String type) throws MimeTypeException {
+ return (new MimeType(type)).getName();
+ }
+
+ /**
+ * Return the name of this mime-type.
+ *
+ * @return the name of this mime-type.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Return the primary type of this mime-type.
+ *
+ * @return the primary type of this mime-type.
+ */
+ public String getPrimaryType() {
+ return primary;
+ }
+
+ /**
+ * Return the sub type of this mime-type.
+ *
+ * @return the sub type of this mime-type.
+ */
+ public String getSubType() {
+ return sub;
+ }
+
+ // Inherited Javadoc
+ public String toString() {
+ return getName();
+ }
+
+ /**
+ * Indicates if an object is equal to this mime-type. The specified object
+ * is equal to this mime-type if it is not null, and it is an instance of
+ * MimeType and its name is equals to this mime-type.
+ *
+ * @param object
+ * the reference object with which to compare.
+ * @return <code>true</code> if this mime-type is equal to the object
+ * argument; <code>false</code> otherwise.
+ */
+ public boolean equals(Object object) {
+ try {
+ return ((MimeType) object).getName().equals(this.name);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ // Inherited Javadoc
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ /**
+ * Return the description of this mime-type.
+ *
+ * @return the description of this mime-type.
+ */
+ String getDescription() {
+ return description;
+ }
+
+ /**
+ * Set the description of this mime-type.
+ *
+ * @param description
+ * the description of this mime-type.
+ */
+ void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * Add a supported extension.
+ *
+ * @param the
+ * extension to add to the list of extensions associated to this
+ * mime-type.
+ */
+ void addExtension(String ext) {
+ extensions.add(ext.toUpperCase());
+ }
+
+ /**
+ * Return the extensions of this mime-type
+ *
+ * @return the extensions associated to this mime-type.
+ */
+ String[] getExtensions() {
+ return (String[]) extensions.toArray(new String[extensions.size()]);
+ }
+
+ void addMagic(int offset, String type, String magic) {
+ // Some preliminary checks...
+ if ((magic == null) || (magic.length() < 1)) {
+ return;
+ }
+ Magic m = new Magic(offset, type, magic);
+ if (m != null) {
+ magics.add(m);
+ minLength = Math.max(minLength, m.size());
+ }
+ }
+
+ int getMinLength() {
+ return minLength;
+ }
+
+ public boolean hasMagic() {
+ return (magics.size() > 0);
+ }
+
+ public boolean matches(String url) {
+ boolean match = false;
+ int index = url.lastIndexOf('.');
+ if ((index != -1) && (index < url.length() - 1)) {
+ // There's an extension, so try to find if it matches mines
+ match = extensions.contains(url.substring(index + 1));
+ }
+ return match;
+ }
+
+ public boolean matches(byte[] data) {
+ if (!hasMagic()) {
+ return false;
+ }
+
+ Magic tested = null;
+ for (int i = 0; i < magics.size(); i++) {
+ tested = (Magic) magics.get(i);
+ if (tested.matches(data)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /** Checks if the specified primary or sub type is valid. */
+ private boolean isValid(String type) {
+ return (type != null) && (type.trim().length() > 0)
+ && !hasCtrlOrSpecials(type);
+ }
+
+ /** Checks if the specified string contains some special characters. */
+ private boolean hasCtrlOrSpecials(String type) {
+ int len = type.length();
+ int i = 0;
+ while (i < len) {
+ char c = type.charAt(i);
+ if (c <= '\032' || SPECIALS.indexOf(c) > 0) {
+ return true;
+ }
+ i++;
+ }
+ return false;
+ }
+
+ private class Magic {
+
+ private int offset;
+
+ private byte[] magic = null;
+
+ Magic(int offset, String type, String magic) {
+ this.offset = offset;
+
+ if ((type != null) && (type.equals("byte"))) {
+ this.magic = readBytes(magic);
+ } else {
+ this.magic = magic.getBytes();
+ }
+ }
+
+ int size() {
+ return (offset + magic.length);
+ }
+
+ boolean matches(byte[] data) {
+ if (data == null) {
+ return false;
+ }
+
+ int idx = offset;
+ if ((idx + magic.length) > data.length) {
+ return false;
+ }
+
+ for (int i = 0; i < magic.length; i++) {
+ if (magic[i] != data[idx++]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private byte[] readBytes(String magic) {
+ byte[] data = null;
+
+ if ((magic.length() % 2) == 0) {
+ String tmp = magic.toLowerCase();
+ data = new byte[tmp.length() / 2];
+ int byteValue = 0;
+ for (int i = 0; i < tmp.length(); i++) {
+ char c = tmp.charAt(i);
+ int number;
+ if (c >= '0' && c <= '9') {
+ number = c - '0';
+ } else if (c >= 'a' && c <= 'f') {
+ number = 10 + c - 'a';
+ } else {
+ throw new IllegalArgumentException();
+ }
+ if ((i % 2) == 0) {
+ byteValue = number * 16;
+ } else {
+ byteValue += number;
+ data[i / 2] = (byte) byteValue;
+ }
+ }
+ }
+ return data;
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append("[").append(offset).append("/").append(magic)
+ .append("]");
+ return buf.toString();
+ }
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeTypeException.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeTypeException.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeTypeException.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeTypeException.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.mime;
+
+/**
+ * A class to encapsulate MimeType related exceptions. Based on original
+ * class written by J. Charron and H. Kodungallur with the
+ * <a href="http://lucene.apache.org/nutch">Apache Nutch</a> project
+ *
+ * @author ahart
+ * @author bfoster
+ */
+public class MimeTypeException extends Exception {
+
+ private static final long serialVersionUID = -9041812649674899544L;
+
+ /**
+ * Constructs a MimeTypeException with no specified detail message.
+ */
+ public MimeTypeException() {
+ super();
+ }
+
+ /**
+ * Constructs a MimeTypeException with the specified detail message.
+ * @param msg the detail message.
+ */
+ public MimeTypeException(String msg) {
+ super(msg);
+ }
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeTypes.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeTypes.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeTypes.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeTypes.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,276 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.mime;
+
+// JDK imports
+import java.io.File;
+import java.net.URL;
+import java.util.Map;
+import java.util.List;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.ArrayList;
+
+/**
+ * This class is a MimeType repository.
+ * It gathers a set of MimeTypes and enables to retrieves a content-type
+ * from a specified file extension, or from a magic character sequence (or both).
+ * Based on original class written by J. Charron and H. Kodungallur with the
+ * <a href="http://lucene.apache.org/nutch">Apache Nutch</a> project
+ *
+ * @author ahart
+ * @author bfoster
+ */
+public final class MimeTypes {
+
+ /** The default <code>application/octet-stream</code> MimeType */
+ public final static String DEFAULT = "application/octet-stream";
+
+ /** All the registered MimeTypes */
+ private ArrayList<MimeType> types = new ArrayList<MimeType>();
+
+ /** All the registered MimeType indexed by name */
+ private HashMap<String, MimeType> typesIdx = new HashMap<String, MimeType>();
+
+ /** MimeTypes indexed on the file extension */
+ private Map<String, List<MimeType>> extIdx = new HashMap<String, List<MimeType>>();
+
+ /** List of MimeTypes containing a magic char sequence */
+ private List<MimeType> magicsIdx = new ArrayList<MimeType>();
+
+ /** The minimum length of data to provide to check all MimeTypes */
+ private int minLength = 0;
+
+ /**
+ * My registered instances
+ * There is one instance associated for each specified file while
+ * calling the {@link #get(String)} method.
+ * Key is the specified file path in the {@link #get(String)} method.
+ * Value is the associated MimeType instance.
+ */
+ private static Map<String, MimeTypes> instances = new HashMap<String, MimeTypes>();
+
+
+ /** Should never be instanciated from outside */
+ private MimeTypes(String filepath) {
+ MimeTypesReader reader = new MimeTypesReader();
+ add(reader.read(filepath));
+ }
+
+
+ /**
+ * Return a MimeTypes instance.
+ * @param filepath is the mime-types definitions xml file.
+ * @return A MimeTypes instance for the specified filepath xml file.
+ */
+ public static MimeTypes buildRepository(String filepath) {
+ MimeTypes instance = null;
+ synchronized(instances) {
+ instance = instances.get(filepath);
+ if (instance == null) {
+ instance = new MimeTypes(filepath);
+ instances.put(filepath, instance);
+ }
+ }
+ return instance;
+ }
+
+
+ /**
+ * Find the Mime Content Type of a file.
+ * @param file to analyze.
+ * @return the Mime Content Type of the specified file, or
+ * <code>null</code> if none is found.
+ */
+ public MimeType getMimeType(File file) {
+ return getMimeType(file.getName());
+ }
+
+ /**
+ * Find the Mime Content Type of a document from its URL.
+ * @param url of the document to analyze.
+ * @return the Mime Content Type of the specified document URL, or
+ * <code>null</code> if none is found.
+ */
+ public MimeType getMimeType(URL url) {
+ MimeType blah = getMimeType(url.getPath());
+ return blah;
+ }
+
+ /**
+ * Find the Mime Content Type of a document from its name.
+ * @param name of the document to analyze.
+ * @return the Mime Content Type of the specified document name, or
+ * <code>null</code> if none is found.
+ */
+ public MimeType getMimeType(String name) {
+ MimeType[] founds = getMimeTypes(name);
+ if ((founds == null) || (founds.length <1)) {
+ // No mapping found, just return null
+ return null;
+ } else {
+ // Arbitraly returns the first mapping
+ return founds[0];
+ }
+ }
+
+ /**
+ * Find the Mime Content Type of a stream from its content.
+ *
+ * @param data are the first bytes of data of the content to analyze.
+ * Depending on the length of provided data, all known MimeTypes are
+ * checked. If the length of provided data is greater or egals to
+ * the value returned by {@link #getMinLength()}, then all known
+ * MimeTypes are checked, otherwise only the MimeTypes that could be
+ * analyzed with the length of provided data are analyzed.
+ *
+ * @return The Mime Content Type found for the specified data, or
+ * <code>null</code> if none is found.
+ * @see #getMinLength()
+ */
+ public MimeType getMimeType(byte[] data) {
+ // Preliminary checks
+ if ((data == null) || (data.length < 1)) {
+ return null;
+ }
+ Iterator<MimeType> iter = magicsIdx.iterator();
+ MimeType type = null;
+ // TODO: This is a very naive first approach (scanning all the magic
+ // bytes since one is matching.
+ // A first improvement could be to use a search path on the magic
+ // bytes.
+ // TODO: A second improvement could be to search for the most qualified
+ // (the longest) magic sequence (not the first that is matching).
+ while (iter.hasNext()) {
+ type = iter.next();
+ if (type.matches(data)) {
+ return type;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Find the Mime Content Type of a document from its name and its content.
+ *
+ * @param name of the document to analyze.
+ * @param data are the first bytes of the document's content.
+ * @return the Mime Content Type of the specified document, or
+ * <code>null</code> if none is found.
+ * @see #getMinLength()
+ */
+ public MimeType getMimeType(String name, byte[] data) {
+
+ // First, try to get the mime-type from the name
+ MimeType mimeType = null;
+ MimeType[] mimeTypes = getMimeTypes(name);
+ if (mimeTypes == null) {
+ // No mime-type found, so trying to analyse the content
+ mimeType = getMimeType(data);
+ } else if (mimeTypes.length > 1) {
+ // TODO: More than one mime-type found, so trying magic resolution
+ // on these mime types
+ //mimeType = getMimeType(data, mimeTypes);
+ // For now, just get the first one
+ mimeType = mimeTypes[0];
+ } else {
+ mimeType = mimeTypes[0];
+ }
+ return mimeType;
+ }
+
+ /**
+ * Return a MimeType from its name.
+ */
+ public MimeType forName(String name) {
+ return (MimeType) typesIdx.get(name);
+ }
+
+ /**
+ * Return the minimum length of data to provide to analyzing methods
+ * based on the document's content in order to check all the known
+ * MimeTypes.
+ * @return the minimum length of data to provide.
+ * @see #getMimeType(byte[])
+ * @see #getMimeType(String, byte[])
+ */
+ public int getMinLength() {
+ return minLength;
+ }
+
+
+ /**
+ * Add the specified mime-types in the repository.
+ * @param types are the mime-types to add.
+ */
+ void add(MimeType[] types) {
+ if (types == null) { return; }
+ for (int i=0; i<types.length; i++) {
+ add(types[i]);
+ }
+ }
+
+ /**
+ * Add the specified mime-type in the repository.
+ * @param type is the mime-type to add.
+ */
+ void add(MimeType type) {
+ typesIdx.put(type.getName(), type);
+ types.add(type);
+ // Update minLentgth
+ minLength = Math.max(minLength, type.getMinLength());
+ // Update the extensions index...
+ String[] exts = type.getExtensions();
+ if (exts != null) {
+ for (int i=0; i<exts.length; i++) {
+ List<MimeType> list = extIdx.get(exts[i].toUpperCase());
+ if (list == null) {
+ // No type already registered for this extension...
+ // So, create a list of types
+ list = new ArrayList<MimeType>();
+ extIdx.put(exts[i].toUpperCase(), list);
+ }
+ list.add(type);
+ }
+ }
+ // Update the magics index...
+ if (type.hasMagic()) {
+ magicsIdx.add(type);
+ }
+ }
+
+ /**
+ * Returns an array of matching MimeTypes from the specified name
+ * (many MimeTypes can have the same registered extensions).
+ */
+ private MimeType[] getMimeTypes(String name) {
+ List<MimeType> mimeTypes = null;
+ int index = name.lastIndexOf('.');
+ if ((index != -1) && (index != name.length()-1)) {
+ // There's an extension, so try to find
+ // the corresponding mime-types
+ String ext = name.substring(index + 1);
+
+ mimeTypes = extIdx.get(ext.toUpperCase());
+ }
+
+ return (mimeTypes != null)
+ ? (MimeType[]) mimeTypes.toArray(new MimeType[mimeTypes.size()])
+ : null;
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeTypesReader.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeTypesReader.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeTypesReader.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/mime/MimeTypesReader.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.mime;
+
+// DOM imports
+import org.w3c.dom.Text;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Node;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.NamedNodeMap;
+import org.xml.sax.InputSource;
+
+// JDK imports
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+
+/**
+ * A reader for the mime-types DTD compliant XML files.
+ * Based on original class written by J. Charron with the
+ * <a href="http://lucene.apache.org/nutch">Apache Nutch</a>project
+ *
+ * @author ahart
+ * @author bfoster
+ */
+
+final class MimeTypesReader {
+
+
+ MimeTypesReader() {
+
+ }
+
+ MimeType[] read(String filepath) {
+ URL repoUrl = null;
+ InputStream is = null;
+
+ try {
+ repoUrl = new File(filepath).toURL();
+ is = repoUrl.openStream();
+
+ } catch (MalformedURLException e1) {
+ return new MimeType[0];
+ } catch (IOException e) {
+ //TODO: print we're SOL here
+ //TODO: add LOG class to this
+ }
+
+ return read(is);
+
+ }
+
+ MimeType[] read(InputStream stream) {
+ MimeType[] types = null;
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document document = builder.parse(new InputSource(stream));
+ types = visit(document);
+ } catch (Exception e) {
+
+ //TODO: add message about error while loading mime types
+ types = new MimeType[0];
+ }
+ return types;
+ }
+
+ /** Scan through the document. */
+ private MimeType[] visit(Document document) {
+ MimeType[] types = null;
+ Element element = document.getDocumentElement();
+ if ((element != null) && element.getTagName().equals("mime-types")) {
+ types = readMimeTypes(element);
+ }
+ return (types == null) ? (new MimeType[0]) : types;
+ }
+
+ /** Read Element named mime-types. */
+ private MimeType[] readMimeTypes(Element element) {
+ ArrayList<MimeType> types = new ArrayList<MimeType>();
+ NodeList nodes = element.getChildNodes();
+ for (int i=0; i<nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ Element nodeElement = (Element) node;
+ if (nodeElement.getTagName().equals("mime-type")) {
+ MimeType type = readMimeType(nodeElement);
+ if (type != null) { types.add(type); }
+ }
+ }
+ }
+ return (MimeType[]) types.toArray(new MimeType[types.size()]);
+ }
+
+ /** Read Element named mime-type. */
+ private MimeType readMimeType(Element element) {
+ String name = null;
+ String description = null;
+ MimeType type = null;
+ NamedNodeMap attrs = element.getAttributes();
+ for (int i=0; i<attrs.getLength(); i++) {
+ Attr attr = (Attr) attrs.item(i);
+ if (attr.getName().equals("name")) {
+ name = attr.getValue();
+ } else if (attr.getName().equals("description")) {
+ description = attr.getValue();
+ }
+ }
+ if ((name == null) || (name.trim().equals(""))) {
+ return null;
+ }
+
+ try {
+ type = new MimeType(name);
+ } catch (MimeTypeException mte) {
+ // Mime Type not valid... just ignore it
+ // TODO: add message about ignoring mime type
+ return null;
+ }
+ type.setDescription(description);
+
+ NodeList nodes = element.getChildNodes();
+ for (int i=0; i<nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ Element nodeElement = (Element) node;
+ if (nodeElement.getTagName().equals("ext")) {
+ readExt(nodeElement, type);
+ } else if (nodeElement.getTagName().equals("magic")) {
+ readMagic(nodeElement, type);
+ }
+ }
+ }
+ return type;
+ }
+
+ /** Read Element named ext. */
+ private void readExt(Element element, MimeType type) {
+ NodeList nodes = element.getChildNodes();
+ for (int i=0; i<nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ if (node.getNodeType() == Node.TEXT_NODE) {
+ type.addExtension(((Text) node).getData());
+ }
+ }
+ }
+
+ /** Read Element named magic. */
+ private void readMagic(Element element, MimeType mimeType) {
+ // element.getValue();
+ String offset = null;
+ String content = null;
+ String type = null;
+ NamedNodeMap attrs = element.getAttributes();
+ for (int i=0; i<attrs.getLength(); i++) {
+ Attr attr = (Attr) attrs.item(i);
+ if (attr.getName().equals("offset")) {
+ offset = attr.getValue();
+ } else if (attr.getName().equals("type")) {
+ type = attr.getValue();
+ } else if (attr.getName().equals("value")) {
+ content = attr.getValue();
+ }
+ }
+ if ((offset != null) && (content != null)) {
+ mimeType.addMagic(Integer.parseInt(offset), type, content);
+ }
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/ComplexQuery.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/ComplexQuery.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/ComplexQuery.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/ComplexQuery.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.query;
+
+//JDK imports
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.Query;
+import org.apache.oodt.cas.filemgr.structs.QueryCriteria;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * A Complex query allows for querying the filemgr across multiple product-types,
+ * reducing the metadata queried for, filtering the results, and sorting the results
+ * in a single query
+ * </p>
+ */
+public class ComplexQuery extends Query {
+
+ private List<String> reducedProductTypeNames;
+ private List<String> reducedMetadata;
+ private QueryFilter queryFilter;
+ private String sortByMetKey;
+
+ public ComplexQuery() {
+ super();
+ }
+
+ public ComplexQuery(List<QueryCriteria> criteria) {
+ super(criteria);
+ }
+
+ public List<String> getReducedProductTypeNames() {
+ return reducedProductTypeNames;
+ }
+
+ public void setReducedProductTypeNames(List<String> reducedProductTypeNames) {
+ this.reducedProductTypeNames = reducedProductTypeNames;
+ }
+
+ public List<String> getReducedMetadata() {
+ return reducedMetadata;
+ }
+
+ public void setReducedMetadata(List<String> reducedMetadata) {
+ this.reducedMetadata = reducedMetadata;
+ if (this.sortByMetKey != null && this.reducedMetadata != null
+ && !this.reducedMetadata.contains(this.sortByMetKey))
+ this.reducedMetadata.add(this.sortByMetKey);
+ }
+
+ public QueryFilter getQueryFilter() {
+ return queryFilter;
+ }
+
+ public void setQueryFilter(QueryFilter queryFilter) {
+ this.queryFilter = queryFilter;
+ }
+
+ public String getSortByMetKey() {
+ return sortByMetKey;
+ }
+
+ public void setSortByMetKey(String sortByMetKey) {
+ this.sortByMetKey = sortByMetKey;
+ if (this.reducedMetadata != null && this.sortByMetKey != null
+ && !this.reducedMetadata.contains(this.sortByMetKey))
+ this.reducedMetadata.add(this.sortByMetKey);
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/QueryFilter.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/QueryFilter.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/QueryFilter.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/QueryFilter.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.query;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.query.conv.AsciiSortableVersionConverter;
+import org.apache.oodt.cas.filemgr.structs.query.conv.VersionConverter;
+import org.apache.oodt.cas.filemgr.structs.query.filter.FilterAlgor;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * A query filter that allows user to filter results in a complex query
+ * <p>
+ */
+public class QueryFilter {
+
+ private String startDateTimeMetKey, endDateTimeMetKey, priorityMetKey;
+ private FilterAlgor filterAlgor;
+ private VersionConverter converter;
+
+ public QueryFilter(String startDateTimeMetKey, String endDateTimeMetKey,
+ String priorityMetKey, FilterAlgor filterAlgor) {
+ this.startDateTimeMetKey = startDateTimeMetKey;
+ this.endDateTimeMetKey = endDateTimeMetKey;
+ this.priorityMetKey = priorityMetKey;
+ this.filterAlgor = filterAlgor;
+ this.converter = new AsciiSortableVersionConverter();
+ }
+
+ public String getStartDateTimeMetKey() {
+ return startDateTimeMetKey;
+ }
+
+ public void setStartDateTimeMetKey(String startDateTimeMetKey) {
+ this.startDateTimeMetKey = startDateTimeMetKey;
+ }
+
+ public String getEndDateTimeMetKey() {
+ return endDateTimeMetKey;
+ }
+
+ public void setEndDateTimeMetKey(String endDateTimeMetKey) {
+ this.endDateTimeMetKey = endDateTimeMetKey;
+ }
+
+ public String getPriorityMetKey() {
+ return priorityMetKey;
+ }
+
+ public void setPriorityMetKey(String priorityMetKey) {
+ this.priorityMetKey = priorityMetKey;
+ }
+
+ public FilterAlgor getFilterAlgor() {
+ return filterAlgor;
+ }
+
+ public void setFilterAlgor(FilterAlgor filterAlgor) {
+ if (filterAlgor != null)
+ this.filterAlgor = filterAlgor;
+ }
+
+ public VersionConverter getConverter() {
+ return converter;
+ }
+
+ public void setConverter(VersionConverter converter) {
+ if (converter != null)
+ this.converter = converter;
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/QueryResult.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/QueryResult.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/QueryResult.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/QueryResult.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.query;
+
+//JDK imports
+import java.util.List;
+import java.util.Set;
+import java.util.Map.Entry;
+
+//Spring imports
+import org.springframework.util.StringUtils;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.metadata.Metadata;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * A combination of a Product and its Metadata
+ * <p>
+ */
+public class QueryResult {
+
+ private Product product;
+ private Metadata metadata;
+
+ public QueryResult(Product product, Metadata metadata) {
+ this.metadata = metadata;
+ this.product = product;
+ }
+
+ public Product getProduct() {
+ return this.product;
+ }
+
+ public void setProduct(Product product) {
+ this.product = product;
+ }
+
+ public Metadata getMetadata() {
+ return this.metadata;
+ }
+
+ public void setMetadata(Metadata metadata) {
+ this.metadata = metadata;
+ }
+
+ private static String convertMetadataToString(Metadata metadata,
+ String format) {
+ if (format == null)
+ return concatMetadataIntoString(metadata);
+ String outputString = format;
+ for (String key : metadata.getAllKeys())
+ outputString = outputString.replaceAll("\\$" + key, StringUtils
+ .collectionToDelimitedString(metadata.getAllMetadata(key),
+ ","));
+ return outputString;
+ }
+
+ private static String concatMetadataIntoString(Metadata metadata) {
+ String outputString = "";
+ for (String key : metadata.getAllKeys())
+ outputString += StringUtils.collectionToDelimitedString(metadata
+ .getAllMetadata(key), ",")
+ + ",";
+ return outputString.substring(0, outputString.length() - 1);
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/QueryResultComparator.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/QueryResultComparator.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/QueryResultComparator.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/QueryResultComparator.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.query;
+
+//JDK imports
+import java.util.Comparator;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * A Comparator that allows for sorting of QueryResults based on a
+ * Metadata element
+ * <p>
+ */
+public class QueryResultComparator implements Comparator<QueryResult> {
+
+ private String sortByMetKey;
+
+ public String getSortByMetKey() {
+ return sortByMetKey;
+ }
+
+ public void setSortByMetKey(String sortByMetKey) {
+ this.sortByMetKey = sortByMetKey;
+ }
+
+ public int compare(QueryResult qr1, QueryResult qr2) {
+ return qr1.getMetadata().getMetadata(this.sortByMetKey).compareTo(
+ qr2.getMetadata().getMetadata(sortByMetKey));
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/conv/AsciiSortableVersionConverter.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/conv/AsciiSortableVersionConverter.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/conv/AsciiSortableVersionConverter.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/conv/AsciiSortableVersionConverter.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.query.conv;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * Converts a ascii sortable String version into a priority number
+ * <p>
+ */
+public class AsciiSortableVersionConverter implements VersionConverter {
+
+ public double convertToPriority(String version) throws Exception {
+ double priority = 0;
+ char[] versionCharArray = version.toCharArray();
+ for (int i = 0, j = versionCharArray.length - 1; i < versionCharArray.length; i++, j--)
+ priority += (((int) versionCharArray[i]) * Math.pow(10, j));
+ return priority;
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/conv/VersionConverter.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/conv/VersionConverter.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/conv/VersionConverter.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/conv/VersionConverter.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.query.conv;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * An interface for converting a String version into a priority number
+ * <p>
+ */
+public interface VersionConverter {
+
+ public double convertToPriority(String version) throws Exception;
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/filter/FilterAlgor.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/filter/FilterAlgor.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/filter/FilterAlgor.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/filter/FilterAlgor.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.query.filter;
+
+//JDK imports
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.commons.filter.TimeEvent;
+
+/**
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ * <p>
+ * An algorithm interface for defining how QueryFilter filters query results
+ * <p>
+ */
+public abstract class FilterAlgor {
+
+ protected long epsilon;
+
+ public FilterAlgor() {
+ this.epsilon = 0;
+ }
+
+ public void setEpsilon(long epsilon) {
+ this.epsilon = epsilon;
+ }
+
+ public long getEpsilon() {
+ return this.epsilon;
+ }
+
+ public abstract List<? extends TimeEvent> filterEvents(List<? extends TimeEvent> events);
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/filter/TakeEarliestEventFilterAlgor.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/filter/TakeEarliestEventFilterAlgor.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/filter/TakeEarliestEventFilterAlgor.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/filter/TakeEarliestEventFilterAlgor.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.query.filter;
+
+//JDK imports
+import java.util.Collections;
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.query.filter.FilterAlgor;
+import org.apache.oodt.commons.filter.TimeEvent;
+
+/**
+ * @author bfoster
+ * @version $Revision$
+ *
+ */
+public class TakeEarliestEventFilterAlgor extends FilterAlgor {
+
+ @Override
+ public List<? extends TimeEvent> filterEvents(List<? extends TimeEvent> events) {
+ if (events.size() > 0) {
+ Collections.sort(events);
+ return Collections.singletonList(events.get(events.size() - 1));
+ }else {
+ return Collections.emptyList();
+ }
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/filter/WeightedHashFilterAlgor.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/filter/WeightedHashFilterAlgor.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/filter/WeightedHashFilterAlgor.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/query/filter/WeightedHashFilterAlgor.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.query.filter;
+
+//OODT imports
+import org.apache.oodt.commons.filter.TimeEvent;
+import org.apache.oodt.commons.filter.TimeEventWeightedHash;
+
+//JDK imports
+import java.util.List;
+
+/**
+ *
+ * @author bfoster
+ *
+ */
+public class WeightedHashFilterAlgor extends FilterAlgor {
+
+ @Override
+ public List<? extends TimeEvent> filterEvents(List<? extends TimeEvent> events) {
+ TimeEventWeightedHash hash = TimeEventWeightedHash.buildHash(events, this.epsilon);
+ return hash.getGreatestWeightedPathAsOrderedList();
+ }
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/type/TypeHandler.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/type/TypeHandler.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/type/TypeHandler.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/type/TypeHandler.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.type;
+
+//JDK imports
+import java.util.LinkedList;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.Query;
+import org.apache.oodt.cas.filemgr.structs.QueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.RangeQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.TermQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.exceptions.QueryFormulationException;
+import org.apache.oodt.cas.metadata.Metadata;
+
+/**
+ * A Metadata modification class that intercepts all Metadata flowing in and out
+ * of the Catalog. Allows the Catalog to contain additional Metadata or modified
+ * Metadata while keeping it invisible to the user. The purpose it to create
+ * String queriable Metadata so that the Catalog can be queries accurately and
+ * without extra knowledge required on the user end.
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ */
+public abstract class TypeHandler {
+
+ protected String elementName;
+
+ /**
+ * Sets the Element name that this TypeHandler is responsible for handling
+ * @param elementName The Element name for this TypeHandler
+ */
+ public void setElementName(String elementName) {
+ this.elementName = elementName;
+ }
+
+ /**
+ * Get the Element name that this TypeHandler is responsible for handling
+ * @return The Element name for this TypeHandler
+ */
+ public String getElementName() {
+ return this.elementName;
+ }
+
+ /**
+ * Converts this TypeHandler's element in the given Query into a Query
+ * with the necessary elements and values so the Catalog can be queried.
+ *
+ * NOTE: Original Query is modified . . . the argument query becomes
+ * equal to the returned query (return of query is a convenience).
+ *
+ * @param query Query for which the Catalog Query will be returned
+ * @return A Query with Catalog element values
+ * @throws QueryFormulationException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ */
+ public Query preQueryHandle(Query query) throws QueryFormulationException {
+ LinkedList<QueryCriteria> qcList = new LinkedList<QueryCriteria>();
+ for (QueryCriteria qc : query.getCriteria())
+ qcList.add(this.handleQueryCriteria(qc));
+ query.setCriteria(qcList);
+ return query;
+ }
+
+ private QueryCriteria handleQueryCriteria(QueryCriteria qc) throws QueryFormulationException {
+ if (qc instanceof BooleanQueryCriteria) {
+ LinkedList<QueryCriteria> qcList = new LinkedList<QueryCriteria>();
+ for (QueryCriteria criteria : ((BooleanQueryCriteria) qc).getTerms())
+ qcList.add(this.handleQueryCriteria(criteria));
+ BooleanQueryCriteria bqc = new BooleanQueryCriteria();
+ bqc.setOperator(((BooleanQueryCriteria) qc).getOperator());
+ bqc.setElementName(qc.getElementName());
+ for (QueryCriteria criteria : qcList)
+ bqc.addTerm(criteria);
+ return bqc;
+ }else if (qc.getElementName().equals(elementName) && qc instanceof TermQueryCriteria) {
+ return this.handleTermQueryCriteria((TermQueryCriteria) qc);
+ }else if (qc.getElementName().equals(elementName) && qc instanceof RangeQueryCriteria) {
+ return this.handleRangeQueryCriteria((RangeQueryCriteria) qc);
+ }else {
+ return qc;
+ }
+ }
+
+ /**
+ * Handles converting any Catalog metadata element values to their original values.
+ * Metadata elements can be added, modified, or replaced.
+ *
+ * @param metadata The Catalog Metadata
+ */
+ public abstract void postGetMetadataHandle(Metadata metadata);
+
+ /**
+ * Handles converting any metadata element to Catalog element values.
+ * Metadata elements can be added, modified, or replaced.
+ *
+ * @param metadata The Original Metadata
+ */
+ public abstract void preAddMetadataHandle(Metadata metadata);
+
+ /**
+ * Converts the given RangeQueryCriteria into a QueryCriteria with the necessary
+ * Catalog elements and values to perform the query
+ *
+ *
+ * @param qc
+ * @return
+ */
+ protected abstract QueryCriteria handleRangeQueryCriteria(RangeQueryCriteria qc);
+
+ /**
+ * Converts the given TermQueryCriteria into a QueryCriteria with the necessary
+ * Catalog elements and values to perform the query
+ *
+ * @param qc
+ * @return
+ */
+ protected abstract QueryCriteria handleTermQueryCriteria(TermQueryCriteria qc);
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/type/ValueReplaceTypeHandler.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/type/ValueReplaceTypeHandler.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/type/ValueReplaceTypeHandler.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/type/ValueReplaceTypeHandler.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.type;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.QueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.RangeQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.TermQueryCriteria;
+import org.apache.oodt.cas.metadata.Metadata;
+
+/**
+ * A Subset-TypeHandler which only allows for metadata value modification.
+ * It will automatically detected and replace the metadata values for
+ * the metadata element which it is responsible for. All the developer
+ * needs to supply is the convertion method between the original value
+ * and the Catalog value
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ */
+public abstract class ValueReplaceTypeHandler extends TypeHandler {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void postGetMetadataHandle(Metadata metadata) {
+ if (metadata.containsKey(elementName)) {
+ metadata.replaceMetadata(elementName,
+ this.getOrigValue(metadata.getMetadata(elementName)));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void preAddMetadataHandle(Metadata metadata) {
+ if (metadata.containsKey(elementName)) {
+ metadata.replaceMetadata(elementName,
+ this.getCatalogValue(metadata.getMetadata(elementName)));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected QueryCriteria handleRangeQueryCriteria(RangeQueryCriteria rqc) {
+ if (rqc.getEndValue() != null)
+ rqc.setEndValue(this.getCatalogValue(rqc.getEndValue()));
+ if (rqc.getStartValue() != null)
+ rqc.setStartValue(this.getCatalogValue(rqc.getStartValue()));
+ return rqc;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected QueryCriteria handleTermQueryCriteria(TermQueryCriteria tqc) {
+ if (tqc.getValue() != null)
+ tqc.setValue(this.getCatalogValue(tqc.getValue()));
+ return tqc;
+ }
+
+ /**
+ * Converts the metadata element, for this TypeHandler, value to the
+ * Catalog value
+ * @param origValue The value for the element which this TypeHandler
+ * is responsible for
+ * @return The Catalog value
+ */
+ protected abstract String getCatalogValue(String origValue);
+
+ /**
+ * Converts the metadata element, for this TypeHandler, value from the
+ * Catalog value to the original value
+ * @param origValue The value for the element which this TypeHandler
+ * is responsible for
+ * @return The original value
+ */
+ protected abstract String getOrigValue(String databaseValue);
+
+}
Added: oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/type/examples/MajorMinorVersionTypeHandler.java
URL: http://svn.apache.org/viewvc/oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/type/examples/MajorMinorVersionTypeHandler.java?rev=1052148&view=auto
==============================================================================
--- oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/type/examples/MajorMinorVersionTypeHandler.java (added)
+++ oodt/branches/wengine-branch/filemgr/src/main/java/org/apache/oodt/cas/filemgr/structs/type/examples/MajorMinorVersionTypeHandler.java Thu Dec 23 02:48:02 2010
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.oodt.cas.filemgr.structs.type.examples;
+
+//APACHE imports
+import org.apache.commons.lang.StringUtils;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.type.ValueReplaceTypeHandler;
+
+/**
+ * Handler metadata element values whose original format is: \d{1,2}.\d{0,2}
+ *
+ * Return Catalog value format: \d\d.\d\d
+ * Return original value format: \d{1,2}.\d{1,2}
+ *
+ * @author bfoster
+ * @version $Revision$
+ *
+ */
+public class MajorMinorVersionTypeHandler extends ValueReplaceTypeHandler {
+
+
+ @Override
+ protected String getCatalogValue(String origValue) {
+ String[] origValueSplit = origValue.split("\\.");
+ String majorVersion = origValueSplit[0];
+ String minorVersion = origValueSplit[1];
+ return StringUtils.leftPad(majorVersion, 2, "0") + "."
+ + StringUtils.rightPad(minorVersion, 2, "0");
+ }
+
+ @Override
+ protected String getOrigValue(String databaseValue) {
+ return Double.toString(Double.parseDouble(databaseValue));
+ }
+
+}