You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArchivaDavLocatorFactory.java 2.6KB

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