From 79c77136b99e4b7b06fad7c8d6e92d38d37a187f Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Thu, 9 May 2019 09:40:15 +0200 Subject: [PATCH] Adding interface for request path handling. --- .../repository/ManagedRepositoryContent.java | 2 + .../repository/RepositoryRequestInfo.java | 145 ++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java index bf47b472d..816b57766 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java @@ -30,6 +30,8 @@ import java.util.Set; /** * ManagedRepositoryContent interface for interacting with a managed repository in an abstract way, * without the need for processing based on filesystem paths, or working with the database. + * + * This interface */ public interface ManagedRepositoryContent extends RepositoryContent { diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java new file mode 100644 index 000000000..043c09cce --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryRequestInfo.java @@ -0,0 +1,145 @@ +package org.apache.archiva.repository; + +/* + * 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. + */ + +import org.apache.archiva.model.ArtifactReference; +import org.apache.archiva.repository.features.RepositoryFeature; + +/** + * This interface is for mapping web request paths to artifacts. + * The file system storage may differ from the paths used for web access. + * + * @author Martin Stockhammer + */ +public interface RepositoryRequestInfo +{ + + /** + * Returns the artifact reference for a given path. + * Takes an incoming requested path (in "/" format) and gleans the layout + * and ArtifactReference appropriate for that content. + * + * @param requestPath The path of the web request + * @return The artifact reference + * @throws LayoutException + */ + ArtifactReference toArtifactReference( String requestPath ) throws LayoutException; + + /** + *

+ * Tests the path to see if it conforms to the expectations of a metadata request. + *

+ *

+ * NOTE: The implementation may do only a cursory check on the path's extension. A result of true + * from this method is not a guarantee that the support resource is in a valid format, or + * that it even contains data. + *

+ * + * @param requestPath the path to test. + * @return true if the requestedPath is likely a metadata request. + */ + boolean isMetadata( String requestPath ); + + /** + * Returns true, if the given request points to a archetype catalog. + * + * @param requestPath + * @return true if the requestedPath is likely an archetype catalog request. + */ + boolean isArchetypeCatalog( String requestPath ); + + /** + *

+ * Tests the path to see if it conforms to the expectations of a support file request. Support files are used + * for signing and validating the artifact files. + *

+ *

+ * May test for certain extensions like .sha1, .md5, .asc, and .php. + *

+ *

+ * NOTE: The implementation may do only a cursory check on the path's extension. A result of true + * from this method is not a guarantee that the support resource is in a valid format, or + * that it even contains data. + *

+ * + * @param requestPath the path to test. + * @return true if the requestedPath is likely that of a support file request. + */ + boolean isSupportFile( String requestPath ); + + /** + *

+ * Tests the path to see if it conforms to the expectations of a support file request of the metadata file. + *

+ *

+ * May test for certain extensions like .sha1, .md5, .asc, and .php. + *

+ *

+ * NOTE: The implementation may do only a cursory check on the path's extension. A result of true + * from this method is not a guarantee that the support resource is in a valid format, or + * that it even contains data. + *

+ * + * @param requestPath the path to test. + * @return true if the requestedPath is likely that of a support file request. + */ + boolean isMetadataSupportFile( String requestPath ); + + /** + * Returns the likely layout type for the given request. + * Implementations may only check the path elements for this. To make sure, the path is valid, + * you should call {@link #toArtifactReference(String)} + * + * @return + */ + String getLayout( String requestPath ); + + /** + * Adjust the requestedPath to conform to the native layout of the provided {@link org.apache.archiva.repository.ManagedRepositoryContent}. + * + * @param requestPath the incoming requested path. + * @return the adjusted (to native) path. + * @throws LayoutException if the path cannot be parsed. + */ + void toNativePath( String requestPath); + + /** + * Extension method that allows to provide different features that are not supported by all + * repository types. + * + * @param clazz The feature class that is requested + * @param This is the class of the feature + * @return The feature implementation for this repository instance, if it is supported + * @throws UnsupportedFeatureException if the feature is not supported by this repository type + */ + > RepositoryFeature getFeature( Class clazz ) throws UnsupportedFeatureException; + + + /** + * Returns true, if the requested feature is supported by this repository. + * + * @param clazz The requested feature class + * @param The requested feature class + * @return True, if the feature is supported, otherwise false. + */ + > boolean supportsFeature( Class clazz ); + + +} -- 2.39.5