/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.rendering.internal;

import org.xwiki.bridge.DocumentAccessBridge;
import org.xwiki.component.descriptor.ComponentDescriptor;
import org.xwiki.component.descriptor.DefaultComponentDescriptor;

/**
 * Mock {@link DocumentAccessBridge} implementation used for testing, since we don't want to pull any dependency on the
 * Model/Skin/etc for the Rendering module's unit tests.
 * 
 * @version $Id: $
 * @since 18RC2
 */
public class MockDocumentAccessBridge implements DocumentAccessBridge
{
    /**
     * Create and return a descriptor for this component.
     * 
     * @return the descriptor of the component.
     */
    public static ComponentDescriptor getComponentDescriptor()
    {
        DefaultComponentDescriptor componentDescriptor = new DefaultComponentDescriptor();

        componentDescriptor.setRole(DocumentAccessBridge.ROLE);
        componentDescriptor.setRoleHint("default");
        componentDescriptor.setImplementation(MockDocumentAccessBridge.class.getName());

        return componentDescriptor;
    }

    public String getDocumentContent(String documentName) throws Exception
    {
        return "Some content";
    }

    public String getDocumentContent(String documentName, String language) throws Exception
    {
        return "Some translated content";
    }

    public boolean exists(String documentName)
    {
        return (documentName.equals("XWiki.Admin") || documentName.equals("XWiki.ExistingUserWithoutAvatar"));
    }

    public String getURL(String documentName, String action, String queryString, String anchor)
    {
        String result = "/xwiki/bin/view/" + (documentName == null ? "currentdoc" : documentName.replace(".", "/"));
        if (anchor != null) {
            result = result + "#" + anchor;
        }
        if (queryString != null) {
            result = result + "?" + queryString;
        }
        return result;
    }

    public String getAttachmentURL(String documentName, String attachmentName)
    {
        return "/xwiki/bin/download/" + (documentName == null ? "currentdoc" : documentName.replace(".", "/")) + "/"
            + attachmentName;
    }

    public String getProperty(String documentName, String className, int objectNumber, String propertyName)
        throws Exception
    {
        throw new RuntimeException("Not implemented");
    }

    public String getProperty(String documentName, String className, String propertyName) throws Exception
    {
        return documentName.equals("XWiki.Admin") && 
            className.equals("XWiki.XWikiUsers") && propertyName.equals("avatar") 
            ? "mockAvatar.png"
            : null;
    }

    public String getProperty(String documentName, String propertyName) throws Exception
    {
        throw new RuntimeException("Not implemented");
    }

    public String getPropertyType(String className, String propertyName) throws Exception
    {
        throw new RuntimeException("Not implemented");
    }

    public boolean isPropertyCustomMapped(String className, String propertyName) throws Exception
    {
        throw new RuntimeException("Not implemented");
    }

    public byte[] getAttachmentContent(String documentName, String attachmentName) throws Exception
    {
        throw new RuntimeException("Not implemented");
    }

    public boolean hasProgrammingRights()
    {
        return true;
    }

    public String getDocumentContentForDefaultLanguage(String arg0) throws Exception
    {
        throw new RuntimeException("Not implemented");
    }

    public boolean isDocumentViewable(String arg0)
    {
        throw new RuntimeException("Not implemented");
    }

    public String getCurrentUser()
    {
        throw new RuntimeException("Not implemented");
    }

    public String getDefaultEncoding()
    {
        throw new RuntimeException("Not implemented");
    }

    public String getDocumentSyntaxId(String arg0) throws Exception
    {
        throw new RuntimeException("Not implemented");
    }

    public boolean isDocumentEditable(String arg0)
    {
        throw new RuntimeException("Not implemented");
    }

    public void setAttachmentContent(String arg0, String arg1, byte[] arg2) throws Exception
    {
        throw new RuntimeException("Not implemented");
    }

    public void setDocumentContent(String arg0, String arg1, String arg2, boolean arg3) throws Exception
    {
        throw new RuntimeException("Not implemented");
    }

    public void setDocumentSyntaxId(String arg0, String arg1) throws Exception
    {
        throw new RuntimeException("Not implemented");
    }
}

@@ -972,16 +972,99 @@
 Bridge;%0A
+import org.xwiki.bridge.DocumentModelBridge;%0Aimport org.xwiki.bridge.DocumentName;%0A
 import o
@@ -5570,11 +5570,289 @@
 );%0A    %7D
+%0A%0A    public DocumentModelBridge getDocument(String documentName) throws Exception%0A    %7B%0A        throw new RuntimeException(%22Not implemented%22);%0A    %7D%0A%0A    public DocumentName getDocumentName(String documentName)%0A    %7B%0A        throw new RuntimeException(%22Not implemented%22);%0A    %7D
 %0A%7D%0A

Make link label generation configurable when no label is specified for a link XTCONFRES-31: Add example for configuring Link label generation when labels are not specified