http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNGetHandler.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNGetHandler.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNGetHandler.java deleted file mode 100644 index c619883..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNGetHandler.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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.product.handlers.ofsn; - -//JDK imports -import java.util.Properties; - -//OODT imports -import org.apache.oodt.product.ProductException; - -/** - * - * The default OFSN handler for getting remote data. - * - * @author mattmann - * @version $Revision$ - * - */ -public interface OFSNGetHandler { - - /** - * Retrieves a chunk of data from the remote file. - * - * @param filepath - * The path to the remote file. - * @param offset - * The offset in the remote data to retrieve. - * @param length - * The length of data to read - * @return The byte[] data, read, or null otherwise. - * @throws ProductException - * If any error occurs. - */ - byte[] retrieveChunk(String filepath, long offset, int length) - throws ProductException; - - /** - * Returns the size of the remote data, which may be the entire file in - * question, or some subset/transformation on it. - * - * @param filepath - * The remote file in question. - * @return The size of the remote file, potentially after a remote - * transformation has occured. - */ - long sizeOf(String filepath); - - /** - * Configures this handler with the provided configuration stored in a - * {@link Properties} object. - * - * @param conf - * The configuration for this list handler. - */ - void configure(Properties conf); - -}
http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNHandlerConfig.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNHandlerConfig.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNHandlerConfig.java deleted file mode 100644 index 8c8aa18..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNHandlerConfig.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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.product.handlers.ofsn; - -//JDK imports -import java.util.Properties; - -/** - * - * A configuration element in the XML config file for the OFSN handler. - * - * @author mattmann - * @version $Revision$ - * - */ -public class OFSNHandlerConfig { - - private String className; - - private String type; - - private String name; - - private Properties handlerConf; - - /** - * @param className - * @param type - * @param name - */ - public OFSNHandlerConfig(String className, String type, String name) { - super(); - this.className = className; - this.type = type; - this.name = name; - this.handlerConf = new Properties(); - } - - /** - * - */ - public OFSNHandlerConfig() { - super(); - } - - /** - * @return the className - */ - public String getClassName() { - return className; - } - - /** - * @param className - * the className to set - */ - public void setClassName(String className) { - this.className = className; - } - - /** - * @return the type - */ - public String getType() { - return type; - } - - /** - * @param type - * the type to set - */ - public void setType(String type) { - this.type = type; - } - - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @param name - * the name to set - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return the handlerConf - */ - public Properties getHandlerConf() { - return handlerConf; - } - - /** - * @param handlerConf the handlerConf to set - */ - public void setHandlerConf(Properties handlerConf) { - this.handlerConf = handlerConf; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNListHandler.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNListHandler.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNListHandler.java deleted file mode 100644 index 5e23d58..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/OFSNListHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.product.handlers.ofsn; - -//JDK imports -import java.io.File; -import java.util.Properties; - -//OODT imports -import org.apache.oodt.product.ProductException; - -/** - * <p> - * Classes that implement this interface define how to return file listings on a - * remote server from an <code>ofsn</code>. - * </p> - * - * @author mattmann - * @version $Revision$ - * - */ -public interface OFSNListHandler { - - /** - * Handlers that implement this method take an <code>O</code>nline - * <code>F</code>ile <code>S</code>pecification <code>N</code>ame and return - * back a listing of files on the remote server. - * - * @param ofsn - * The OFSN path to list files from. - * @return An array of {@link File} objects. - * @throws ProductException - * If any error occurs performing the listing on the server side. - */ - File[] getListing(String ofsn) throws ProductException; - - /** - * Configures this handler with the provided configuration stored in a - * {@link Properties} object. - * - * @param conf - * The configuration for this list handler. - */ - void configure(Properties conf); -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/RawSizeListHandler.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/RawSizeListHandler.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/RawSizeListHandler.java deleted file mode 100644 index 883e1b5..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/RawSizeListHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.product.handlers.ofsn; - -//JDK imports -import java.io.File; -import java.util.Properties; - -//OODT imports -import org.apache.oodt.product.ProductException; - -/** - * - * Handles a listing request for the raw size of a file. This listing - * returns a single file or directory, which will then have its size - * computed. - * - * @author mattmann - * @version $Revision$ - * - */ -public class RawSizeListHandler implements OFSNListHandler { - - /* (non-Javadoc) - * @see org.apache.oodt.product.handlers.ofsn.OFSNListHandler#configure(java.util.Properties) - */ - public void configure(Properties conf) { - // TODO Auto-generated method stub - // nothing yet - - } - - /* (non-Javadoc) - * @see org.apache.oodt.product.handlers.ofsn.OFSNListHandler#getListing(java.lang.String) - */ - public File[] getListing(String ofsn) throws ProductException { - if (!new File(ofsn).exists()) { - throw new ProductException("file: [" + ofsn - + "] does not exist!"); - } - return new File[] { new File(ofsn) }; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/SingleFileListHandler.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/SingleFileListHandler.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/SingleFileListHandler.java deleted file mode 100644 index 45d559c..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/SingleFileListHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.product.handlers.ofsn; - -//JDK imports -import java.io.File; -import java.util.Properties; - -import org.apache.oodt.product.ProductException; - -/** - * - * Returns a single remote file listing of the given ofsn. - * - * @author mattmann - * @version $Revision$ - * - */ -public class SingleFileListHandler implements OFSNListHandler { - - /* - * (non-Javadoc) - * - * @see - * org.apache.oodt.product.handlers.ofsn.OFSNListHandler#configure(java. - * util.Properties) - */ - public void configure(Properties conf) { - // TODO Auto-generated method stub - // nothing yet - - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.oodt.product.handlers.ofsn.OFSNListHandler#getListing(java - * .lang.String) - */ - public File[] getListing(String ofsn) throws ProductException { - if (!new File(ofsn).exists()) { - throw new ProductException("file: [" + ofsn + "] does not exist!"); - } - return new File[] { new File(ofsn) }; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/SingleZipFileListHandler.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/SingleZipFileListHandler.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/SingleZipFileListHandler.java deleted file mode 100644 index 748a534..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/SingleZipFileListHandler.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.product.handlers.ofsn; - -//OODT imports -import org.apache.oodt.product.handlers.ofsn.util.OFSNUtils; -import org.apache.oodt.product.ProductException; - -//JDK imports -import java.io.File; -import java.util.Properties; - - -/** - * - * Generates a listing of the size of a remote file identified by its OFSN as a - * zip would be. - * - * @author mattmann - * @version $Revision$ - * - */ -public class SingleZipFileListHandler implements OFSNListHandler { - - private String cacheRoot; - - /* - * (non-Javadoc) - * - * @see - * org.apache.oodt.product.handlers.ofsn.OFSNListHandler#configure(java. - * util.Properties) - */ - public void configure(Properties conf) { - // TODO Auto-generated method stub - - this.cacheRoot = conf.getProperty("cacheDirRoot"); - - if (this.cacheRoot == null) { - this.cacheRoot = "/tmp"; - } - - if (!this.cacheRoot.endsWith("/")) { - this.cacheRoot += "/"; - } - - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.oodt.product.handlers.ofsn.OFSNListHandler#getListing(java - * .lang.String) - */ - public File[] getListing(String ofsn) throws ProductException { - if (!new File(ofsn).exists()) { - throw new ProductException("file: [" + ofsn + "] does not exist!"); - } - - String zipFilePath = this.cacheRoot + new File(ofsn).getName() + ".zip"; - File zipFile = OFSNUtils.buildZipFile(zipFilePath, new File[] { new File( - ofsn) }); - return new File[] { zipFile }; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/StdOFSNGetHandler.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/StdOFSNGetHandler.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/StdOFSNGetHandler.java deleted file mode 100644 index cb344e9..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/StdOFSNGetHandler.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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.product.handlers.ofsn; - -//JDK imports - -import org.apache.oodt.product.ProductException; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; - -//OODT imports - -/** - * - * Standard way of retrieving a file without performing - * any transformation on it. - * - * @author mattmann - * @version $Revision$ - * - */ -public class StdOFSNGetHandler implements OFSNGetHandler { - private static Logger LOG = Logger.getLogger(StdOFSNGetHandler.class.getName()); - /* - * (non-Javadoc) - * - * @see - * org.apache.oodt.product.handlers.ofsn.OFSNGetHandler#retrieveChunk(java - * .lang.String, long, int) - */ - public byte[] retrieveChunk(String filepath, long offset, int length) - throws ProductException { - InputStream in = null; - byte[] buf = null; - - try { - in = new FileInputStream(new File(filepath)); - - buf = new byte[length]; - int numRead; - long numSkipped; - numSkipped = in.skip(offset); - if (numSkipped != offset) { - throw new ProductException("Was not able to skip: [" + offset - + "] bytes into product: num actually skipped: [" + numSkipped - + "]"); - } - - numRead = in.read(buf, 0, length); - - if (numRead != length) { - throw new ProductException("Was not able to read: [" + length - + "] bytes from product: num actually read: [" + numRead + "]"); - } - } catch (IOException e) { - LOG.log(Level.SEVERE, e.getMessage()); - throw new ProductException("IO exception retrieving chunk of product: [" - + filepath + "]: Message: " + e.getMessage()); - } finally { - if (in != null) { - try { - in.close(); - } catch (Exception ignore) { - } - - } - } - - return buf; - } - - /* - * (non-Javadoc) - * - * @see - * org.apache.oodt.product.handlers.ofsn.OFSNGetHandler#sizeOf(java.lang - * .String) - */ - public long sizeOf(String filepath) { - return new File(filepath).length(); - } - - /* (non-Javadoc) - * @see org.apache.oodt.product.handlers.ofsn.OFSNGetHandler#configure(java.util.Properties) - */ - public void configure(Properties conf) { - // no properties to configure - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/URLGetHandler.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/URLGetHandler.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/URLGetHandler.java deleted file mode 100644 index 20944f3..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/URLGetHandler.java +++ /dev/null @@ -1,252 +0,0 @@ -/* - * 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.product.handlers.ofsn; - -//JDK imports -import java.io.ByteArrayInputStream; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Properties; -import java.util.logging.Logger; - -//OODT imports -import org.apache.oodt.product.ProductException; -import org.apache.oodt.product.handlers.ofsn.AbstractCrawlLister; -import org.apache.oodt.product.handlers.ofsn.OFSNGetHandler; - -/** - * A {@link OFSNGetHandler} for returning a URL listing pointing to files within an OFSN - * - * NOTE: Configuration parameters for this class include: - * 1. Server hostname - * 2. Server port - * 3. Webapp context-root - * 4. Path to product-root - * 5. Return type desired for URLs - * - * @author rverma - * @version $Revision$ - * - */ -public class URLGetHandler extends AbstractCrawlLister implements OFSNGetHandler { - - Logger LOG = Logger.getLogger(URLGetHandler.class.getName()); - - // Constants - private static final String PROD_SERVER_HOSTNAME = "prodServerHostname"; - private static final String PROD_SERVER_PORT = "prodServerPort"; - private static final String PROD_SERVER_CONTEXT = "prodServerContextRoot"; - private static final String PRODUCT_ROOT = "productRoot"; - private static final String RETURN_TYPE = "returnType"; - - protected static final String DEFAULT_RETURN_VALUE=""; - protected static final String DEFAULT_PROD_SERVER_HOSTNAME = "localhost"; - protected static final String DEFAULT_PROD_SERVER_PORT = "8080"; - protected static final String DEFAULT_PROD_SERVER_CONTEXT = "web-grid"; - protected static final String DEFAULT_PRODUCT_ROOT = "/some/path"; - protected static final String DEFAULT_RETURN_TYPE = "RAW"; - - // Instance - private String prodServerHostname = ""; - private String prodServerPort = ""; - private String prodServerContext = ""; - private String productRoot = ""; - private String returnType = ""; - - /* - * (non-Javadoc) - * @see org.apache.oodt.product.handlers.ofsn.AbstractCrawlLister#configure(java.util.Properties) - */ - public void configure(Properties prop) { - - if (prop != null) { - if (prop.getProperty(PROD_SERVER_HOSTNAME) != null) { - this.prodServerHostname = prop.getProperty(PROD_SERVER_HOSTNAME); - } else { - LOG.warning("Configuration property ["+PROD_SERVER_HOSTNAME+"] not specified, using default"); - this.prodServerHostname = DEFAULT_PROD_SERVER_HOSTNAME; - } - LOG.info("Property ["+PROD_SERVER_HOSTNAME+"] set with value ["+this.prodServerHostname+"]"); - - if (prop.getProperty(PROD_SERVER_PORT) != null) { - this.prodServerPort = prop.getProperty(PROD_SERVER_PORT); - } else { - LOG.warning("Configuration property ["+PROD_SERVER_PORT+"] not specified, using default"); - this.prodServerPort = DEFAULT_PROD_SERVER_PORT; - } - LOG.info("Property ["+PROD_SERVER_PORT+"] set with value ["+this.prodServerPort+"]"); - - if (prop.getProperty(PROD_SERVER_CONTEXT) != null) { - this.prodServerContext = prop.getProperty(PROD_SERVER_CONTEXT); - } else { - LOG.warning("Configuration property ["+PROD_SERVER_CONTEXT+"] not specified, using default"); - this.prodServerContext = DEFAULT_PROD_SERVER_CONTEXT; - } - LOG.info("Property ["+PROD_SERVER_CONTEXT+"] set with value ["+this.prodServerContext+"]"); - - if (prop.getProperty(PRODUCT_ROOT) != null) { - this.productRoot = prop.getProperty(PRODUCT_ROOT); - } else { - LOG.warning("Configuration property ["+PRODUCT_ROOT+"] not specified, using default"); - this.productRoot = DEFAULT_PRODUCT_ROOT; - } - LOG.info("Property ["+PRODUCT_ROOT+"] set with value ["+this.productRoot+"]"); - - if (prop.getProperty(RETURN_TYPE) != null) { - this.returnType = prop.getProperty(RETURN_TYPE); - } else { - LOG.warning("Configuration property ["+RETURN_TYPE+"] not specified, using default"); - this.returnType = DEFAULT_RETURN_TYPE; - } - LOG.info("Property ["+RETURN_TYPE+"] set with value ["+this.returnType+"]"); - - } else { - LOG.warning("Configuration properties could not be loaded"); - } - - } - - /* - * (non-Javadoc) - * @see org.apache.oodt.product.handlers.ofsn.OFSNGetHandler#retrieveChunk(java.lang.String, long, int) - */ - public byte[] retrieveChunk(String filepath, long offset, int length) - throws ProductException { - - LOG.info("Retrieving chunk of URL listing for path: ["+filepath+"] at offset " - + offset+" for "+length+" bytes"); - - String urlListing = DEFAULT_RETURN_VALUE; - try { - urlListing = getURLListing(filepath); - } catch (ProductException e) { - LOG.warning("Unable to obtain byte chunk ("+offset+" - "+(offset+length)+") " - + "for filepath listing ["+filepath+"]"); - LOG.warning(e.getMessage()); - } catch (IllegalArgumentException e) { - LOG.warning("Unable to obtain byte chunk ("+offset+" - "+(offset+length)+") " - + "for filepath listing ["+filepath+"]"); - LOG.warning(e.getMessage()); - } - - // Convert listing to bytes - byte[] retBytes = new byte[length]; - byte[] metBytes = urlListing.getBytes(); - ByteArrayInputStream is = new ByteArrayInputStream(metBytes); - is.skip(offset); - is.read(retBytes, 0, length); - - return retBytes; - } - - /** - * Returns a new-line separated list of URLs for all files located under the given filepath - * - * @param filePath the absolute path to a root-directory to get a product listing for - * @return a string containing a new-line separated list of URLs - * @throws ProductException - */ - private String getURLListing(String filePath) throws ProductException, - IllegalArgumentException { - - // crawl and collect all files (including within subdirs) under filepath - File[] fileListing = getListing(filePath); - - // convert each crawled file's path into an OFSN download link - StringBuilder stringBuilder = new StringBuilder(); - for (File aFileListing : fileListing) { - File file = (File) aFileListing; - stringBuilder.append(buildOFSNURL(file).toString()); - stringBuilder.append("\n"); - } - - return stringBuilder.toString(); - } - - /** - * Returns a URL object representing the URL associated with this particular product file. - * - * The URL is defined to have items such as: hostname, server port, server context root, - * and return type configured based upon a product server configuration file - * - * @param file the product file - * @return a URL - */ - private URL buildOFSNURL(File file) { - URL url = null; - - String fileRelativePath = file.getAbsolutePath().substring(this.productRoot.length()); - - // construct a URL for the file, optionally using a port if available - String ofsnPath; - if (this.prodServerPort != null) { - if (!this.prodServerPort.isEmpty()) { - ofsnPath = "http://" + this.prodServerHostname - + ":" + this.prodServerPort + "/" + this.prodServerContext - + "/prod?q=OFSN=" + fileRelativePath + "+AND+RT%3D" + this.returnType; - } else { - ofsnPath = "http://" + this.prodServerHostname - + "/" + this.prodServerContext + "/prod?q=OFSN=" + fileRelativePath - + "+AND+RT%3D" + this.returnType; - } - } else { - ofsnPath = "http://" + this.prodServerHostname - + "/" + this.prodServerContext + "/prod?q=OFSN=" + fileRelativePath - + "+AND+RT%3D" + this.returnType; - } - - try { - url = new URL(ofsnPath); - } catch (MalformedURLException e) { - LOG.warning(e.getMessage()); - } - - return url; - } - - /* - * (non-Javadoc) - * @see org.apache.oodt.product.handlers.ofsn.OFSNGetHandler#sizeOf(java.lang.String) - */ - public long sizeOf(String filepath) { - String urlListing = DEFAULT_RETURN_VALUE; - try { - urlListing = getURLListing(filepath); - } catch (ProductException e) { - LOG.warning("Unable to obtain size information for filepath listing ["+filepath+"]"); - LOG.warning(e.getMessage()); - } catch (IllegalArgumentException e) { - LOG.warning("Unable to obtain size information for filepath listing ["+filepath+"]"); - LOG.warning(e.getMessage()); - } - - return urlListing.getBytes().length; - } - - /* - * (non-Javadoc) - * @see org.apache.oodt.product.handlers.ofsn.AbstractCrawlLister#getListing(java.lang.String) - */ - public File[] getListing(String filePath) throws ProductException, - IllegalArgumentException { - return crawlFiles(new File(filePath), true, false); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNMetKeys.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNMetKeys.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNMetKeys.java deleted file mode 100644 index e56d7aa..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNMetKeys.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.product.handlers.ofsn.metadata; - -/** - * Met keys for use in OFSN handler definition. - * - * @author mattmann - * @version $Revision$ - * - */ -public interface OFSNMetKeys { - - String LISTING_CMD = "listing"; - - String GET_CMD = "get"; - - String OFSN_XML_CONF_FILE_KEY = "org.apache.oodt.product.handlers.ofsn.xmlConfigFilePath"; - - String OFSN_COMPUTE_DIR_SIZE = "org.apache.oodt.product.handlers.ofsn.computeDirSize"; - - String OFSN_COMPUTE_FILE_SIZE = "org.apache.oodt.product.handlers.ofsn.computeFileSize"; - - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLConfigMetKeys.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLConfigMetKeys.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLConfigMetKeys.java deleted file mode 100644 index f4f8c53..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLConfigMetKeys.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.product.handlers.ofsn.metadata; - - -/** - * - * Met Keys for the {@link org.apache.oodt.product.handlers.ofsn.OFSNFileHandlerConfigurationReader} - * - * @author mattmann - * @version $Revision$ - * - */ -public interface OFSNXMLConfigMetKeys { - - String OFSN_CFG_ID_ATTR = "id"; - - String OFSN_CFG_NAME_ATTR = "name"; - - String OFSN_PRODUCT_ROOT_ATTR = "productRoot"; - - String HANDLER_TAG = "handler"; - - String HANDLER_CLASSNAME_ATTR = "class"; - - String HANDLER_NAME_ATTR = "name"; - - String HANDLER_TYPE_ATTR = "type"; - - String PROPERTY_TAG = "property"; - - String PROPERTY_NAME_ATTR = "name"; - - String PROPERTY_VALUE_ATTR = "value"; - - /* optional handler property attributes supported by all handlers */ - String PROPERTY_MIMETYPE_ATTR = "mimeType"; - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLMetKeys.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLMetKeys.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLMetKeys.java deleted file mode 100644 index 0bcdd75..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OFSNXMLMetKeys.java +++ /dev/null @@ -1,43 +0,0 @@ - -/* - * 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.product.handlers.ofsn.metadata; - -/** - * @author mattmann - * @version $Revision$ - * - * <p>Describe your class here</p>. - */ -public interface OFSNXMLMetKeys { - - String DIR_RESULT_TAG = "dirResult"; - - String DIR_ENTRY_TAG = "dirEntry"; - - String OFSN_TAG = "OFSN"; - - String FILE_SIZE_TAG = "fileSize"; - - String XML_MIME_TYPE = "text/xml"; - - // FIXME: change namespace URI? - String DIR_LISTING_NS = "http://oodt.jpl.nasa.gov/xml/namespaces/dirlist/1.0"; - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OODTMetKeys.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OODTMetKeys.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OODTMetKeys.java deleted file mode 100644 index 56ff703..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/OODTMetKeys.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.product.handlers.ofsn.metadata; - -/** - * @author mattmann - * @version $Revision$ - * - * <p>Describe your class here</p>. - */ -public interface OODTMetKeys { - - String XMLQUERY_QUERYELEM_ROLE_ELEM = "elemName"; - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/XMLQueryMetKeys.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/XMLQueryMetKeys.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/XMLQueryMetKeys.java deleted file mode 100644 index b9f1f79..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/metadata/XMLQueryMetKeys.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.product.handlers.ofsn.metadata; - -/** - * @author mattmann - * @version $Revision$ - * - * <p>Describe your class here</p>. - */ -public interface XMLQueryMetKeys { - - String OFSN = "OFSN"; - - String RETURN_TYPE = "RT"; -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/util/OFSNObjectFactory.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/util/OFSNObjectFactory.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/util/OFSNObjectFactory.java deleted file mode 100644 index 6de92e9..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/util/OFSNObjectFactory.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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.product.handlers.ofsn.util; - -//OODT imports -import org.apache.oodt.product.handlers.ofsn.OFSNGetHandler; -import org.apache.oodt.product.handlers.ofsn.OFSNListHandler; - -//JDK imports -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * The Object factory to use in the OFSN product server. - * - * @author mattmann - * @version $Revision$ - * - */ -public final class OFSNObjectFactory { - - private static final Logger LOG = Logger.getLogger(OFSNObjectFactory.class - .getName()); - - /** - * <p> - * Constructs a new {@link OFSNListHandler} from the specified - * <code>className</code>. - * </p> - * - * @param className - * The class name of the OFSNListHandler object to create. - * @return A newly constructed {@link OFSNListHandler} object. - */ - public static OFSNListHandler getListHandler(String className) { - try { - Class<OFSNListHandler> listHandler = (Class<OFSNListHandler>) Class - .forName(className); - return listHandler.newInstance(); - } catch (ClassNotFoundException e) { - LOG.log(Level.SEVERE, e.getMessage()); - LOG.log(Level.WARNING, - "ClassNotFoundException when loading list handler class " + className - + " Message: " + e.getMessage()); - } catch (InstantiationException e) { - LOG.log(Level.SEVERE, e.getMessage()); - LOG.log(Level.WARNING, - "InstantiationException when loading list handler class " + className - + " Message: " + e.getMessage()); - } catch (IllegalAccessException e) { - LOG.log(Level.SEVERE, e.getMessage()); - LOG.log(Level.WARNING, - "IllegalAccessException when loading list handler class " + className - + " Message: " + e.getMessage()); - } - - return null; - } - - /** - * <p> - * Constructs a new {@link OFSNGetHandler} from the specified - * <code>className</code>. - * </p> - * - * @param className - * The class name of the OFSNGetHandler object to create. - * @return A newly constructed {@link OFSNGetHandler} object. - */ - public static OFSNGetHandler getGetHandler(String className) { - try { - Class<OFSNGetHandler> getHandler = (Class<OFSNGetHandler>) Class - .forName(className); - return getHandler.newInstance(); - } catch (ClassNotFoundException e) { - LOG.log(Level.SEVERE, e.getMessage()); - LOG.log(Level.WARNING, - "ClassNotFoundException when loading get handler class " + className - + " Message: " + e.getMessage()); - } catch (InstantiationException e) { - LOG.log(Level.SEVERE, e.getMessage()); - LOG.log(Level.WARNING, - "InstantiationException when loading get handler class " + className - + " Message: " + e.getMessage()); - } catch (IllegalAccessException e) { - LOG.log(Level.SEVERE, e.getMessage()); - LOG.log(Level.WARNING, - "IllegalAccessException when loading get handler class " + className - + " Message: " + e.getMessage()); - } - - return null; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/product/handlers/ofsn/util/OFSNUtils.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/util/OFSNUtils.java b/product/src/main/java/org/apache/oodt/product/handlers/ofsn/util/OFSNUtils.java deleted file mode 100644 index b8b4583..0000000 --- a/product/src/main/java/org/apache/oodt/product/handlers/ofsn/util/OFSNUtils.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * 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.product.handlers.ofsn.util; - -//OODT imports - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.oodt.commons.xml.XMLUtils; -import org.apache.oodt.product.handlers.ofsn.OFSNHandlerConfig; -import org.apache.oodt.product.handlers.ofsn.metadata.OFSNMetKeys; -import org.apache.oodt.product.handlers.ofsn.metadata.OFSNXMLMetKeys; -import org.apache.oodt.product.handlers.ofsn.metadata.OODTMetKeys; -import org.apache.oodt.xmlquery.QueryElement; -import org.apache.oodt.xmlquery.XMLQuery; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Iterator; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -//JDK imports -//APACHE imports - -/** - * - * - * @author mattmann - * @version $Revision$ - * - */ -public final class OFSNUtils implements OODTMetKeys, OFSNXMLMetKeys, - OFSNMetKeys { - public static final int INT = 1024; - private static Logger LOG = Logger.getLogger(OFSNUtils.class.getName()); - public static String extractFieldFromQuery(XMLQuery query, String name) { - for (Iterator<QueryElement> i = query.getWhereElementSet().iterator(); i - .hasNext();) { - QueryElement element = i.next(); - if (element.getRole().equals(XMLQUERY_QUERYELEM_ROLE_ELEM) - && element.getValue().equalsIgnoreCase(name)) { - // get the next element and ensure that it is a LITERAL, and - // return that - QueryElement litElement = i.next(); - return litElement.getValue(); - } - } - - return null; - } - - public static Document getOFSNDoc(List<File> fileList, OFSNHandlerConfig cfg, - String productRoot, boolean showDirSize, boolean showFileSize) { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - Document document; - - try { - DocumentBuilder builder = factory.newDocumentBuilder(); - document = builder.newDocument(); - - Element root = (Element) document.createElement(DIR_RESULT_TAG); - XMLUtils.addAttribute(document, root, "xmlns", DIR_LISTING_NS); - document.appendChild(root); - - for (File file : fileList) { - Element dirEntryElem = XMLUtils.addNode(document, root, DIR_ENTRY_TAG); - String ofsn = toOFSN(file.getAbsolutePath(), productRoot); - //This ensures that we get ofsn names with unix style separators. - //On a Windows machine, the product server would return '\' - //separators. - String unixStyleOFSN = FilenameUtils.separatorsToUnix(ofsn); - if (cfg.getType().equals(LISTING_CMD)) { - if (!Boolean.valueOf(cfg.getHandlerConf().getProperty("isSizeCmd"))) { - XMLUtils.addNode(document, dirEntryElem, OFSN_TAG, unixStyleOFSN); - } - } - - long size = Long.MIN_VALUE; - - if (file.isDirectory()) { - if (showDirSize) { - size = FileUtils.sizeOfDirectory(file); - } - } else { - if (showFileSize) { - size = file.length(); - } - } - - if (size != Long.MIN_VALUE) { - XMLUtils.addNode(document, dirEntryElem, FILE_SIZE_TAG, String - .valueOf(size)); - } - } - - return document; - } catch (ParserConfigurationException e) { - LOG.log(Level.SEVERE, e.getMessage()); - return null; - } - - } - - public static String relativeize(String path, String productRoot) { - return productRoot + (path.startsWith("/") ? path.substring(1) : path); - } - - public static File buildZipFile(String zipFileFullPath, File[] files) { - // Create a buffer for reading the files - byte[] buf = new byte[INT]; - ZipOutputStream out = null; - - try { - // Create the ZIP file - out = new ZipOutputStream(new FileOutputStream(zipFileFullPath)); - - for (File file : files) { - FileInputStream in = new FileInputStream(file); - - // Add ZIP entry to output stream. - out.putNextEntry(new ZipEntry(file.getName())); - - // Transfer bytes from the file to the ZIP file - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - - // Complete the entry - out.closeEntry(); - in.close(); - } - } catch (IOException e) { - LOG.log(Level.SEVERE, e.getMessage()); - } finally { - if (out != null) { - try { - out.close(); - } catch (Exception ignore) { - } - - } - } - - return new File(zipFileFullPath); - - } - - public static boolean validateOFSN(String ofsn) { - if (ofsn == null) { - return false; - } else { - return !ofsn.equals("") && !ofsn.matches(".*\\.\\..*"); - } - } - - private static String toOFSN(String absolutePath, String productRootPath) { - if (absolutePath.startsWith(productRootPath)) { - return absolutePath.substring(productRootPath.length()); - } else { - // must have been a *.zip file, generated in some cache dir - // just return the file name - return new File(absolutePath).getName(); - } - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/xmlquery/ChunkedProductInputStream.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/xmlquery/ChunkedProductInputStream.java b/product/src/main/java/org/apache/oodt/xmlquery/ChunkedProductInputStream.java deleted file mode 100644 index f4376f0..0000000 --- a/product/src/main/java/org/apache/oodt/xmlquery/ChunkedProductInputStream.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * 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.xmlquery; - -import org.apache.oodt.product.ProductException; -import org.apache.oodt.product.Retriever; - -import java.io.IOException; -import java.io.InputStream; - -/** - * Streamer for chunked products. - * - * This streamer starts a background thread to repeatedly read chunks of a product into a - * bounded buffer. Reads read from chunks in the buffer. - * - * @author Kelly - * @version $Revision: 1.5 $ - */ -final class ChunkedProductInputStream extends InputStream { - /** - * Creates a new <code>ChunkedProductInputStream</code> instance. - * - * @param id Product ID. - * @param retriever Retriever to use. - * @param size How big the product is. - */ - ChunkedProductInputStream(String id, Retriever retriever, long size) { - this.id = id; // Save product ID - this.size = size; // Save size - this.retriever = retriever; // And the retriever used to get chunks - open = true; // Start out open - eof = false; // And not yet reached EOF, even if size=0 - } - - - /** - * Read a single byte. - * - * This method reads from a chunk stored in the bounded buffer. It may block if - * there are no more blocks in the buffer. - * - * @return Byte, or -1 if at end of file. - * @throws IOException if an error occurs. - */ - public int read() throws IOException { - checkOpen(); // Make sure the stream's open - if (eof) { - throw new IOException("End of file"); // Already reached EOF? You lose. - } - fetchBlock(); // Get a block. - if (eof) { - return -1; // No more blocks? Signal EOF. - } - return block[blockIndex++]; // Yield next byte (promoted) from block. - } - - /** - * Read into an array. - * - * This method reads from a chunk stored in the bounded buffer. It may block if - * there are no more blocks in the buffer. - * - * @param b a <code>byte[]</code> value. - * @param offset Where in <var>b</var> to save read bytes. - * @param length How many bytes to try to read. - * @return Number of bytes actually read, or -1 at end of file. - * @throws IOException if an error occurs. - */ - public int read(byte[] b, int offset, int length) throws IOException { - checkOpen(); // Check if open - if (offset < 0 || offset > b.length || length < 0 || (offset + length) > b.length || (offset + length) < 0) { - throw new IllegalArgumentException("Illegal offset=" + offset + "/length=" + length - + " for byte array of length " + b.length); - } else if (length == 0) // Want zero? - { - return 0; // Then you get zero - } - if (eof) { - throw new IOException("End of file"); // Already reached EOF? You lose. - } - fetchBlock(); // Get a block. - if (eof) { - return -1; // No more blocks? Signal EOF. - } - int amount = Math.min(length, block.length - blockIndex); // Return requested amount or whatever's left - System.arraycopy(block, blockIndex, b, offset, amount); // Transfer - blockIndex += amount; // Advance - return amount; // Done - } - - /** - * Fetch another block. - * - * @throws IOException if an error occurs. - */ - private void fetchBlock() throws IOException { - if (block == null || blockIndex == block.length) { - try { // No block, or current block exhausted? - if (productIndex == size) { // No more blocks left to get? - block = null; // Drop current block - eof = true; // Signal EOF - } else { // Otherwise there are more blocks - int x = (int) Math.min(BLOCK_SIZE, size - productIndex); // Can only fetch so much - block = retriever.retrieveChunk(id, productIndex, x); // Get x's worth of data - blockIndex = 0; // Start at block's beginning - productIndex += block.length; // Advance product index by block size - } - } catch (ProductException ex) { - throw new IOException(ex.getMessage()); - } - } - } - - /** - * Return number of bytes currently available. - * - * If we have a block, the amount of available bytes is whatever's in the block. - * Otherwise we don't know how many bytes, and we could block, so say zero are available. - * - * @return an <code>int</code> value. - * @throws IOException if an error occurs. - */ - public int available() throws IOException { - checkOpen(); // Open? - return block == null? 0 : block.length - blockIndex; // If no current block, you can only get 0 - } - - public void close() throws IOException { - checkOpen(); // Open? - retriever.close(id); // Tell retriever we're done - open = false; // Flag it - } - - /** - * Mark is not supported. - * - * @param limit Unused parameter. - */ - public void mark(int limit) { - throw new UnsupportedOperationException("Mark not supported"); - } - - /** - * Reset is not supported. - */ - public void reset() { - throw new UnsupportedOperationException("Reset not supported"); - } - - /** - * Mark/reset operations are not supported. - * - * @return False. - */ - public boolean markSuppoted() { - return false; - } - - /** - * Throw an exception if the stream's closed. - * - * @throws IOException if the stream's closed. - */ - private void checkOpen() throws IOException { - if (open) { - return; - } - throw new IOException("Stream closed"); - } - - /** Product ID. */ - private String id; - - /** What can retrieve the product. */ - private Retriever retriever; - - /** How big the product is. */ - private long size; - - /** Current block or null if there's no current block. */ - private byte[] block; - - /** From where in <code>block</code> to read. */ - private int blockIndex; - - /** From where in the product to read the next block. */ - private long productIndex = 0L; - - /** True if we got to the end of file. */ - private boolean eof; - - /** Is the stream open? */ - private boolean open; - - public static final int VAL = 4096; - /** Size of chunks. */ - private static final int BLOCK_SIZE = Integer.getInteger("org.apache.oodt.xmlquery.blockSize", VAL); -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/main/java/org/apache/oodt/xmlquery/LargeResult.java ---------------------------------------------------------------------- diff --git a/product/src/main/java/org/apache/oodt/xmlquery/LargeResult.java b/product/src/main/java/org/apache/oodt/xmlquery/LargeResult.java deleted file mode 100644 index 316650d..0000000 --- a/product/src/main/java/org/apache/oodt/xmlquery/LargeResult.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * 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.xmlquery; - -import java.util.List; -import java.util.StringTokenizer; -import java.io.InputStream; -import java.io.IOException; - -// FIXME: change MIME type application/vnd.jpl.large-product? - -/** - * A <em>large</em> result is a result for <em>large</em> products. - * - * What is large? Some might say large is something that exceeds most other things of - * like kind in bulk, capacity, quantity, superficial dimensions, or number of constituent - * units. Large might be big, great, capacious, extensive. Large might be opposed to - * small; as, a large horse; a large house or room; a large lake or pool; a large jug or - * spoon; a large vineyard; a large army; a large city. Some might say that particularly - * if they're named Webster. - * - * @author Kelly - * @version $Revision: 1.2 $ - */ -public class LargeResult extends Result { - /** - * Creates a new <code>LargeResult</code> instance. - * - * @param result a <code>Result</code> value. - */ - public LargeResult(Result result) { - super(result.getID(), "application/vnd.jpl.large-product", result.getProfileID(), result.getResourceID(), - result.getHeaders(), transformMimeType(result)); - StringTokenizer st = new StringTokenizer((String) value); - st.nextToken(); - this.size = Long.parseLong(st.nextToken()); - } - - /** - * Creates a new <code>LargeResult</code> instance. - * - * @param id Result ID. - * @param mimeType MIME type. - * @param profileID Profile ID. - * @param resourceID Resource ID. - * @param headers Headers. - * @param size Size of the product. - */ - public LargeResult(String id, String mimeType, String profileID, String resourceID, List headers, long size) { - super(id, "application/vnd.jpl.large-product", profileID, resourceID, headers, mimeType + " " + size); - this.size = size; - } - - /** - * Get the size of the product. - * - * @return Its size. - */ - public final long getSize() { - return size; - } - - public final String getMimeType() { - return new StringTokenizer((String) value).nextToken(); - } - - /** - * Return the result's value. - * - * @return a String. - * @deprecated This method always treats its value as if it were a String. Worse, - * for very large results, it cannot contain the entire result in memory. Use - * {@link #getInputStream} instead to perform stream processing on result data. - */ - public final Object getValue() { - Object value = null; - InputStream in = null; - try { - if (size > Integer.MAX_VALUE) { - throw new IllegalStateException("Cannot use getValue() for this product, result is too large; " - + "use LargeResult.getInputStream instead"); - } - int sizeToRead = (int) size; - byte[] buf = new byte[sizeToRead]; - int index = 0; - int num; - in = getInputStream(); - while ((num = in.read(buf, index, sizeToRead)) != -1) { - index += num; - sizeToRead -= num; - if (sizeToRead == 0) { - break; - } - } - - // OK, this sucks. Sucks sucks sucks. Look, getValue is not to - // be used anyway. It sucks. But dammit, there's some annoying - // code over in EDRN which is using it when they should be using - // getInputStream. Basically, if you call this, you're a hoser. - // And if you call it and you're not expecting a String, you're a - // loser/hoser. DEPRECATED! - value = new String(buf); - - } catch (IOException ex) { - throw new IllegalStateException("Unexpected IOException: " + ex.getMessage()); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException ignore) { - } - } - } - return value; - } - - /** Size of the product. */ - private long size; - - /** - * Get an input stream that streams the result from the product server. - * - * @return an <code>InputStream</code> value. - * @throws IOException if an error occurs. - */ - public InputStream getInputStream() throws IOException { - return new ChunkedProductInputStream(id, retriever, size); - } - - /** - * Given an existing <code>Result</code> yield its MIME type. - * - * The existing <code>Result</code> might be a <code>LargeResult</code>, in which - * case the real MIME type is hidden in the value. Otherwise, it's directly in - * the object. - * - * @param result a <code>Result</code> value. - * @return The MIME type. - */ - private static String transformMimeType(Result result) { - if ("application/vnd.jpl.large-product".equals(result.mimeType)) { - return (String) result.value; - } else { - return result.mimeType + " 0"; - } - } - - /** Serial version unique ID. */ - static final long serialVersionUID = -969838775595705444L; -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/site/resources/images/delegation.png ---------------------------------------------------------------------- diff --git a/product/src/site/resources/images/delegation.png b/product/src/site/resources/images/delegation.png deleted file mode 100644 index aea86e3..0000000 Binary files a/product/src/site/resources/images/delegation.png and /dev/null differ http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/site/resources/images/delegation.psd ---------------------------------------------------------------------- diff --git a/product/src/site/resources/images/delegation.psd b/product/src/site/resources/images/delegation.psd deleted file mode 100644 index 9b74dca..0000000 Binary files a/product/src/site/resources/images/delegation.psd and /dev/null differ http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/site/resources/images/grid-product.jpg ---------------------------------------------------------------------- diff --git a/product/src/site/resources/images/grid-product.jpg b/product/src/site/resources/images/grid-product.jpg deleted file mode 100644 index 7b1126e..0000000 Binary files a/product/src/site/resources/images/grid-product.jpg and /dev/null differ http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/site/site.xml ---------------------------------------------------------------------- diff --git a/product/src/site/site.xml b/product/src/site/site.xml deleted file mode 100644 index 0b2c94c..0000000 --- a/product/src/site/site.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one or more contributor -license agreements. See the NOTICE.txt 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. ---> -<project name="Product Service"> - - <body> - <links> - <item name="OODT" href="../oodt-site/"/> - <item name="Grid" href="../grid/"/> - </links> - - <menu ref="reports" inherit="bottom"/> - <menu name="User's Guide"> - <item name="Tutorials" href="tutorials/"/> - <item name="Product Servlet" href="servlet/"/> - </menu> - </body> -</project> http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/site/xdoc/servlet/index.xml ---------------------------------------------------------------------- diff --git a/product/src/site/xdoc/servlet/index.xml b/product/src/site/xdoc/servlet/index.xml deleted file mode 100644 index 22f9bd5..0000000 --- a/product/src/site/xdoc/servlet/index.xml +++ /dev/null @@ -1,243 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<document> - <properties> - <title>Using the Product Servlet</title> - <author email="[email protected]">Sean Kelly</author> - </properties> - - <body> - <section name="Using the Product Servlet"> - <p>The query servlet is nice for general purpose queries, but for - those who just want to retrieve products, it's a bit annoying to - have to process all that XML and do base-64 conversions. Is there - a simpler way? Absolutely. The product servlet deals with just - products, and delivers them in their appropriate form direct over - HTTP. - </p> - </section> - <section name="Requirements"> - - <p>The product servlet provides HTTP access to products, so - naturally, you'll need to use a language or system that supports - HTTP client access to HTTP servers. Where can you find such a - system? Your handy-dandy web browser is one! Most programming - languages also have HTTP APIs either built-in or freely available. - </p> - - <p>You also need to know</p> - - <ul> - <li>The URL of the product servlet that has access to the - product server you want to query.</li> - <li>The object name of the product server you want to - access.</li> - <li>The keyword query expression that can be understood by the - product server.</li> - </ul> - </section> - <section name="Making a Query"> - - <p>The product servlet accepts either <code>GET</code> or - <code>POST</code> requests of URL-encoded form data. In - response, it delivers a matching product (if any can be found) - in the format appropriate to the product's MIME type. You can - also request a specific MIME type. If there's no matching - product, you get HTTP error 404 (not found). - </p> - - <p>The parameters that the servlet expects are:</p> - - <table border="0" cellpadding="3" cellspacing="0"> - - <thead> - <tr> - <th>Parameter Name</th> - <th>Obligation</th> - <th>Meaning</th> - </tr> - </thead> - - <tbody> - <tr> - <td><code>object</code></td> - <td>Once</td> - <td>Names the product server to receive the query. This - parameter must be specified exactly once and takes the form - <code>urn:eda:<var>proto</var>:<var>name</var></code>, such - as <code>urn:eda:rmi:PDS.Atmos.Product</code> for the - RMI-accessed Atmoshpheres node of the Planetary Data System. - </td> - - </tr> - - <tr> - <td><code>keywordQuery</code></td> - <td>Once</td> - <td>Lists the keyword query expression to pass to the - product server, such as <code>PatientID = 19928</code> or - <code>ONLINE_FILE_SPECIFICATION_NAME = - data/images/mars.jpg</code>. - </td> - - </tr> - - <tr> - <td><code>id</code></td> - <td>None or Once</td> - <td>Optional parameter that identifies a single product to - retrieve if more than one product match. A product server - may return multiple matching products. By default, the - product servlet returns the first matching product only. By - specifying the <code>id</code> parameter, you can select a - specific product when more than one match. (In practice, - not a single product server <em>to date</em> has ever - returned more than one match.) - </td> - - </tr> - - <tr> - <td><code>mimeType</code></td> - <td>Zero to Many</td> - <td>Optional parameter that lists acceptable MIME types for - the product (see below). - </td> - - </tr> - - </tbody> - </table> - </section> - <section name="MIME Types"> - - <p>Many product servers are capable of conversion of products from - a system-specific storage medium into an Internet-standard - interoperable format. Internet-standard MIME types are what - drives this mechanism. The product servlet can take a list of - specific MIME types and pass them to the product server for - consideration in retrieving your products. - </p> - - <p>MIME type conversions are like <em>suggestions</em> to product - servers. Product servers are not obligated to honor all - conversions, and indeed you may well receive 404 (not found) for a - conversion that makes no sense to a particular product server - (such as an audio clip to <code>text/html</code>). - </p> - - <p>The <code>mimeType</code> parameter is what drives this - mechanism. By specifying one or more <code>mimeType</code> - parameters in your <code>GET</code> or <code>POST</code> request, - you list the preferred MIME types in which you would like the - product delivered. Furthermore, you can use wildcards to further - enable a product server to satisfy you. The ordering of the - parameters is significant. - </p> - - <p>Here are some examples. Suppose the request URI part of the - URL contained:</p> - - <pre>...mimeType=text/rtf&mimeType=text/*...</pre> - - <p>This specifies two MIME types:</p> - - <ol> - <li><code>text/rtf</code>, the Rich Text Format, is the - preferred format for delivering products. - </li> - - <li><code>text/*</code> means any text type. Any text is better - than no text if for some reason the product server can't give a - Rich Text Format product. - </li> - </ol> - - <p>Here's another example:</p> - - <pre>...mimeType=image/png&mimeType=image/jpeg...</pre> - - <p>This indicates that you'd like a Portable Network Graphic - format image, if possible, but will settle for a JPEG-JFIF format - image. No other image format (especially not the proprietary and - ancient GIF format) is acceptable. Adding an additional - <code>&mimeType=image/*</code> would mean any image format - would be fine. Adding <code>&mimeType=*/*</code> means - <em>any format</em> would be acceptable, be it audio, video, text, - image, or otherwise. - </p> - - <p>If there are <em>no</em> <code>mimeType</code> parameters, then - the product servlet uses a default list containing just - <code>*/*</code>, meaning any type is fine. - </p> - </section> - <section name="Example"> - - <p>To retrieve an image of Mars from the PDS product server at the - Imaging Node, in PNG format if possible and any image format - otherwise, try the following: - </p> - - <p><code><a - href="http://starbrite.jpl.nasa.gov/prod?mimeType=image/png&mimeType=image/*&object=urn:eda:rmi:PDS.Img.Product&keywordQuery=ONLINE_FILE_SPECIFICATION_NAME+%3D+thumbnail/mgs-m-moc-na_wa-2-sdp-l0-v1.0/mgsc_1082/m09063/m0906352.imq.jpg">http://starbrite.jpl.nasa.gov/prod?<br/>mimeType=image/png&<br/>mimeType=image/*&<br/>object=urn:eda:rmi:PDS.Img.Product&<br/>keywordQuery=OFSN+%3D+thumbnail/mgs-m-moc-na_wa-2-sdp-l0-v1.0/mgsc_1082/m09063/m0906352.imq.jpg</a></code></p> - - <p>This URL contains linebreaks for readability only. Let's take - this URL apart to see what's going on: - </p> - - <ul> - <li>The URL to the product servlet in this case is - <code>http://starbrite.jpl.nasa.gov/prod</code>. Often the URL - will take this form, or may be - <code>http://<var>hostname</var>/servlet/jpl.oodt.servlets.ProductServlet</code>. - Most people prefer the shorter form. - </li> - - <li>The question mark <code>?</code> separates the request URI - from its parameters. - </li> - - <li>The first parameter, <code>mimeType=image/png</code>, says - that Portable Network Graphics images are preferred. - </li> - - <li>The second parameter, <code>mimeType=image/*</code>, says - that if the product server can't convert to or other provide - Portable Network Graphics format images, then <em>any image - format</em> is acceptable. - </li> - - <li>The third parameter, - <code>object=urn:eda:rmi:PDS.Img.Product</code>, identifies the - product server. - </li> - - <li>The fourth parameter, <code>keywordQuery=...</code> names - the query expression. In this case, it's <code>OFSN = - thumbnail/mgs-m-moc-na_wa-2-sdp-l0-v1.0/mgsc_1082/m09063/m0906352.imq.jpg</code>. - </li> - </ul> - - <p>The response to this URL's GET request is a JPEG-JFIF image - (sorry, PNG's not yet available from the PDS Image Node) - containing a picture of some planetary surface. Neat, huh? - </p> - </section> - </body> -</document> http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/product/src/site/xdoc/tutorials/index.xml ---------------------------------------------------------------------- diff --git a/product/src/site/xdoc/tutorials/index.xml b/product/src/site/xdoc/tutorials/index.xml deleted file mode 100755 index e130ea9..0000000 --- a/product/src/site/xdoc/tutorials/index.xml +++ /dev/null @@ -1,36 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<document> - <properties> - <title>Product Service Tutorials</title> - <author email="[email protected]">Sean Kelly</author> - </properties> - - <body> - <section name="Product Service Tutorials"> - <p>The following tutorials are available:</p> - <ul> - <li><a href="./ps">Your First Product Service</a></li> - <li><a href="./qh">Developing a Query Handler</a></li> - <li><a href="./lh">Serving Large Products</a></li> - </ul> - </section> - </body> -</document> - -
