package playRepository;

import java.io.File;
import java.util.Enumeration;

import javax.servlet.*;

import org.codehaus.jackson.node.ObjectNode;
import org.tigris.subversion.javahl.ClientException;
import org.tmatesoft.svn.core.internal.server.dav.DAVServlet;

import controllers.SvnApp;

public class SVNRepository implements PlayRepository {
    public static final String REPO_PREFIX = "repo/svn/";

    private static DAVServlet davServlet = new DAVServlet();

    private DAVServlet servlet;

    private String projectName;

    private String userName;

    public SVNRepository(final String userName, String projectName) throws ServletException {
        this.servlet = new DAVServlet();
        davServlet.init(new ServletConfig() {

            @Override
            public String getInitParameter(String name) {
                if (name.equals("SVNParentPath")) {
                    return new File(REPO_PREFIX + userName + "/").getAbsolutePath();
                } else {
                    return play.Configuration.root().getString("application." + name);
                }
            }

            @Override
            public Enumeration<String> getInitParameterNames() {
                throw new UnsupportedOperationException();
            }

            @Override
            public ServletContext getServletContext() {
                throw new UnsupportedOperationException();
            }

            @Override
            public String getServletName() {
                throw new UnsupportedOperationException();
            }

        });
        this.userName = userName;
        this.projectName = projectName;
    }

    public static void create1(String userName, String projectName) throws ClientException {
        String svnPath = new File(SvnApp.REPO_PREFIX + userName + "/" + projectName)
                .getAbsolutePath();
        new org.tigris.subversion.javahl.SVNAdmin().create(svnPath, false, false, null, "fsfs");
    }

    public void create(String userName, String projectName) throws ClientException {
        String svnPath = new File(SvnApp.REPO_PREFIX + userName + "/" + projectName)
                .getAbsolutePath();
        new org.tigris.subversion.javahl.SVNAdmin().create(svnPath, false, false, null, "fsfs");
    }

    public static DAVServlet getDavServlet(final String userName) throws ServletException {
        davServlet.init(new ServletConfig() {

            @Override
            public String getInitParameter(String name) {
                if (name.equals("SVNParentPath")) {
                    return new File(REPO_PREFIX + userName + "/").getAbsolutePath();
                } else {
                    return play.Configuration.root().getString("application." + name);
                }
            }

            @Override
            public Enumeration<String> getInitParameterNames() {
                throw new UnsupportedOperationException();
            }

            @Override
            public ServletContext getServletContext() {
                throw new UnsupportedOperationException();
            }

            @Override
            public String getServletName() {
                throw new UnsupportedOperationException();
            }

        });
        return davServlet;
    }

    public byte[] getRawFile(String path) {
        return null;

    }

    public ObjectNode findFileInfo(String path) {
        return null;
    }

    @Override
    public void create() throws ClientException {
        String svnPath = new File(SvnApp.REPO_PREFIX + userName + "/" + projectName)
                .getAbsolutePath();
        new org.tigris.subversion.javahl.SVNAdmin().create(svnPath, false, false, null, "fsfs");
    }

    @Override
    public DAVServlet getCore() {
        return servlet;
    }

}

@@ -402,70 +402,8 @@
 %22;%0A%0A
-    private static DAVServlet davServlet = new DAVServlet();%0A%0A
     
@@ -629,36 +629,33 @@
 vlet();%0A        
-davS
+s
 ervlet.init(new 
@@ -2214,1008 +2214,8 @@
  %7D%0A%0A
-    public static DAVServlet getDavServlet(final String userName) throws ServletException %7B%0A        davServlet.init(new ServletConfig() %7B%0A%0A            @Override%0A            public String getInitParameter(String name) %7B%0A                if (name.equals(%22SVNParentPath%22)) %7B%0A                    return new File(REPO_PREFIX + userName + %22/%22).getAbsolutePath();%0A                %7D else %7B%0A                    return play.Configuration.root().getString(%22application.%22 + name);%0A                %7D%0A            %7D%0A%0A            @Override%0A            public Enumeration%3CString%3E getInitParameterNames() %7B%0A                throw new UnsupportedOperationException();%0A            %7D%0A%0A            @Override%0A            public ServletContext getServletContext() %7B%0A                throw new UnsupportedOperationException();%0A            %7D%0A%0A            @Override%0A            public String getServletName() %7B%0A                throw new UnsupportedOperationException();%0A            %7D%0A%0A        %7D);%0A        return davServlet;%0A    %7D%0A
 %0A   

fix svn Repository