1 package org.apache.maven.archiva.webdav;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.jackrabbit.webdav.DavLocatorFactory;
23 import org.apache.jackrabbit.webdav.DavResourceLocator;
24 import org.apache.jackrabbit.util.Text;
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.commons.lang.ArrayUtils;
27 import org.apache.maven.archiva.webdav.util.RepositoryPathUtil;
30 * @author <a href="mailto:james@atlassian.com">James William Dumay</a>
32 public class ArchivaDavLocatorFactory implements DavLocatorFactory
34 public DavResourceLocator createResourceLocator(String prefix, String href)
36 // build prefix string and remove all prefixes from the given href.
37 StringBuilder b = new StringBuilder();
38 if (prefix != null && prefix.length() > 0) {
40 if (!prefix.endsWith("/"))
44 if (href.startsWith(prefix)) {
45 href = href.substring(prefix.length());
49 // special treatment for root item, that has no name but '/' path.
50 if (href == null || "".equals(href)) {
54 final String repository = RepositoryPathUtil.getRepositoryName(href);
55 return new ArchivaDavResourceLocator(b.toString(), Text.unescape(href), repository, this);
58 public DavResourceLocator createResourceLocator(String prefix, String workspacePath, String resourcePath)
60 return createResourceLocator(prefix, workspacePath, resourcePath, true);
63 public DavResourceLocator createResourceLocator(String prefix, String workspacePath,
64 String path, boolean isResourcePath)
66 final String repository = RepositoryPathUtil.getRepositoryName(path);
67 return new ArchivaDavResourceLocator(prefix, path, repository, this);