/** * Unzips a zip a file to a specified directory, deleting the zip file after unpacking. * * @param zipFile The zip file. * @param outputDirectory The directory to unpack the contents to. * @throws IOException Any I/O errors that occur. * <p>TODO: move this to IOUtils */ public static void unzipFile( org.geoserver.platform.resource.Resource zipFile, org.geoserver.platform.resource.Resource outputDirectory) throws IOException { unzipFile(zipFile, outputDirectory, null, null, null, null, false); }
/** * Convenience method for subclasses to look up the (URL-decoded)value of * an attribute from the request, ie {@link Request#getAttributes()}. * * @param attribute The name of the attribute to lookup. * * @return The value as a string, or null if the attribute does not exist * or cannot be url-decoded. */ protected String getAttribute(Request request, String attribute) { return RESTUtils.getAttribute(request, attribute); } //@Override
/** * Reads content from the body of a request and writes it to a file. * * @param fileName The name of the file to write out. * @param directory The directory to write the file to. * @param deleteDirectoryContent Delete directory content if the file already exists. * @param request The request. * @return The file object representing the newly written file. * @throws IOException Any I/O errors that occur. * <p>TODO: move this to IOUtils. */ public static org.geoserver.platform.resource.Resource handleBinUpload( String fileName, org.geoserver.platform.resource.Resource directory, boolean deleteDirectoryContent, HttpServletRequest request) throws IOException { return handleBinUpload(fileName, directory, deleteDirectoryContent, request, null); }
String method = (String) getRequest().getResourceRef().getLastSegment(); if (method != null && method.toLowerCase().startsWith("file.")) { uploadedFile = RESTUtils.handleBinUpload(store + "." + format, directory, getRequest()); uploadedFile = RESTUtils.handleURLUpload(store, format, getRequest()); uploadedFile = RESTUtils.handleEXTERNALUpload(getRequest()); if (mediaType!=null && RESTUtils.isZipMediaType( mediaType ) ) { RESTUtils.unzipFile(uploadedFile, directory );
: null; if (mediaType == null || !isZipMediaType(mediaType)) { String baseName = FilenameUtils.getBaseName(fileName); String itemName = FilenameUtils.getName(fileName); remapping(workSpace, baseName, itemPath, itemName, storeParams);
/** * Convenience method for subclasses to look up the (URL-decoded) value of a value specified * in the request query string. * * @param key The name of the value to lookup. * * @return The converted value, or <code>null</code> if the value was not specified. */ protected String getQueryStringValue(String key) { return RESTUtils.getQueryStringValue(getRequest(), key); }
/** * Handles the upload of a dataset using the URL method. * * @param datasetName the name of the uploaded dataset. * @param extension the extension of the uploaded dataset. * @param request the incoming request. * @return a {@link File} that points to the final uploaded dataset. * * @throws IOException * @throws ConfigurationException * * @deprecated use {@link #handleURLUpload(String, File, Request)}. */ public static File handleURLUpload(String datasetName, String extension, Request request) throws IOException, ConfigurationException { //// // // Get the dir where to write and create a file there // //// File dir = GeoserverDataDirectory.findCreateConfigDir("data"); return handleURLUpload(datasetName + "." + extension, dir, request); }
/** * Fetch a request attribute as a String, accounting for URL-encoding. * * @param request the Restlet Request object that might contain the attribute * @param name the name of the attribute to retrieve * @return the attribute, URL-decoded, if it exists and is a valid URL-encoded string, or null * otherwise */ public static String getAttribute(HttpServletRequest request, String name) { Object o = request.getAttribute(name); return decode(o); }
RESTUtils.handleBinUpload( filename, directory, cleanPreviousContents, request, workspace); } else if (method == UploadMethod.url) { uploadedFile = RESTUtils.handleURLUpload( buildUploadedFilename(store, format), workspace, request); } else if (method == UploadMethod.external) { uploadedFile = RESTUtils.handleEXTERNALUpload(request); external = true; } else { if (RESTUtils.isZipMediaType(request)) { RESTUtils.unzipFile( uploadedFile, directory, workspace, store, request, files, external);
: MediaType.valueOf(request.getContentType()); if (mediaType == null || !isZipMediaType(mediaType)) { String baseName = FilenameUtils.getBaseName(fileName); String itemName = FilenameUtils.getName(fileName); remapping(workSpace, baseName, itemPath, itemName, storeParams);
protected static MediaType getFormat(HttpServletRequest request) { return getFormat(RESTUtils.getQueryStringValue(request, "format")); }
public static String getQueryStringValue(HttpServletRequest request, String key) { String value = request.getParameter(key); return decode(value); }
public static String[] getDirectoryPath(Request request) { String workspace = RESTUtils.getAttribute(request, "workspace"); String datastore = RESTUtils.getAttribute(request, "datastore"); String featureType = RESTUtils.getAttribute(request, "featuretype"); String coveragestore = RESTUtils.getAttribute(request, "coveragestore"); String coverage = RESTUtils.getAttribute(request, "coverage"); List<String> path = new ArrayList<String>(); path.add("workspaces"); if (workspace != null) { path.add(workspace); if (datastore != null) { path.add(datastore); if (featureType != null) { path.add(featureType); } } else if (coveragestore != null) { path.add(coveragestore); if (coverage != null) { path.add(coverage); } } } return path.toArray(new String[] {}); } }
/** * Unzip a zipped dataset. * * @param storeName the name of the store to handle. * @param zipFile the zipped archive * @return null if the zip file does not point to a valid zip file, the output directory otherwise. * * @deprecated use {@link #unzipFile(File, File)} * */ public static File unpackZippedDataset(String storeName, File zipFile) throws IOException, ConfigurationException { File outputDirectory = new File(GeoserverDataDirectory.findCreateConfigDir("data"), storeName); unzipFile(zipFile, outputDirectory); return outputDirectory; }
/** * Reads content from the body of a request and writes it to a file in the given directory. * * If the file already exists, the directory content will be deleted recursively * before creating the new file. * * @param fileName The name of the file to write out. * @param directory The directory to write the file to. * @param request The request. * * @return The file object representing the newly written file. * * @throws IOException Any I/O errors that occur. * * @deprecated use {@link #handleBinUpload(String, File, boolean, Request)}. */ public static File handleBinUpload(String fileName, File directory, Request request) throws IOException { return handleBinUpload(fileName, directory, true, request); }
String targetDataStoreFormat = RESTUtils.getQueryStringValue(getRequest(), "target"); if (targetDataStoreFormat == null) {
/** * Fetch a request attribute as a String, accounting for URL-encoding. * * @param request the Restlet Request object that might contain the attribute * @param name the name of the attribute to retrieve * * @return the attribute, URL-decoded, if it exists and is a valid URL-encoded string, or null * otherwise */ public static String getAttribute(Request request, String name) { Object o = request.getAttributes().get(name); return decode(o); }
/** * Convenience method for subclasses to look up the (URL-decoded)value of * an attribute from the request, ie {@link Request#getAttributes()}. * * @param attribute THe name of the attribute to lookup. * * @return The value as a string, or null if the attribute does not exist * or cannot be url-decoded. */ protected String getAttribute(String attribute) { return RESTUtils.getAttribute(getRequest(), attribute); }
private Resource readMosaic() throws FactoryException, IOException { // Select the zip file containing the mosaic URL mosaicZip = getClass().getResource("test-data/watertemp2.zip"); Resource zipFile = Files.asResource(URLs.urlToFile(mosaicZip)); // Creation of another zip file which is a copy of the one before Resource newZip = zipFile.parent().get("watertemp2_temp.zip"); // Copy the content of the first zip to the second IOUtils.copyStream(zipFile.in(), newZip.out(), true, true); Resource mosaic = zipFile.parent().get("mosaic"); mosaic.delete(); RESTUtils.unzipFile(newZip, mosaic); return mosaic; }
/** * This function gets the stream of the request to copy it into a file. * @deprecated use {@link #handleBinUpload(String, File, Request)}. */ public static File handleBinUpload(String datasetName, String extension, Request request) throws IOException, ConfigurationException { final File dir = GeoserverDataDirectory.findCreateConfigDir("data"); return handleBinUpload( datasetName + "." + extension, dir, request ); }