Search in sources :

Example 1 with XWikiURLFactoryService

use of com.xpn.xwiki.web.XWikiURLFactoryService in project xwiki-platform by xwiki.

the class XWikiContextCopierTest method setup.

@Before
public void setup() throws Exception {
    Utils.setComponentManager(mocker);
    originalResponse = new XWikiServletResponseStub();
    original = new XWikiContext();
    // Set some values
    original.setWikiId("wiki");
    DocumentReference userReference = new DocumentReference("wiki", "Space", "Page");
    EntityReferenceSerializer<String> serializer = mocker.registerMockComponent(EntityReferenceSerializer.TYPE_STRING, "compactwiki");
    when(serializer.serialize(userReference)).thenReturn("wiki:Space.Page");
    mocker.registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed");
    original.setUserReference(userReference);
    // Set the mock request
    this.originalRequest = mock(XWikiRequest.class);
    original.setRequest(this.originalRequest);
    Copier<XWikiRequest> requestCopier = mocker.getInstance(new DefaultParameterizedType(null, Copier.class, XWikiRequest.class));
    when(requestCopier.copy(this.originalRequest)).thenReturn(this.originalRequest);
    // Set the stubbed response
    original.setResponse(originalResponse);
    // XWiki mock
    XWiki xwiki = mock(XWiki.class);
    original.setWiki(xwiki);
    // Store mock
    // Simulate the existence of a hibernate session in context
    original.put(HIBSESSION, "opened session");
    store = mock(XWikiStoreInterface.class);
    // clean up will remove the session in the given context
    doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) {
            XWikiContext context = (XWikiContext) invocation.getArguments()[0];
            context.put(HIBSESSION, null);
            return null;
        }
    }).when(store).cleanUp(any(XWikiContext.class));
    when(xwiki.getStore()).thenReturn(store);
    // URL factory mock
    XWikiURLFactory urlFactory = mock(XWikiURLFactory.class);
    XWikiURLFactoryService urlFactoryService = mock(XWikiURLFactoryService.class);
    when(urlFactoryService.createURLFactory(anyInt(), any(XWikiContext.class))).thenReturn(urlFactory);
    when(xwiki.getURLFactoryService()).thenReturn(urlFactoryService);
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) XWikiURLFactory(com.xpn.xwiki.web.XWikiURLFactory) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiURLFactoryService(com.xpn.xwiki.web.XWikiURLFactoryService) XWikiStoreInterface(com.xpn.xwiki.store.XWikiStoreInterface) XWikiServletResponseStub(com.xpn.xwiki.web.XWikiServletResponseStub) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 2 with XWikiURLFactoryService

use of com.xpn.xwiki.web.XWikiURLFactoryService in project xwiki-platform by xwiki.

the class XWiki method getURLFactoryService.

public XWikiURLFactoryService getURLFactoryService() {
    if (this.urlFactoryService == null) {
        synchronized (this.URLFACTORY_SERVICE_LOCK) {
            if (this.urlFactoryService == null) {
                LOGGER.info("Initializing URLFactory Service...");
                XWikiURLFactoryService factoryService = null;
                String urlFactoryServiceClass = getConfiguration().getProperty("xwiki.urlfactory.serviceclass");
                if (urlFactoryServiceClass != null) {
                    try {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug("Using custom URLFactory Service Class [" + urlFactoryServiceClass + "]");
                        }
                        factoryService = (XWikiURLFactoryService) Class.forName(urlFactoryServiceClass).getConstructor(new Class<?>[] { XWiki.class }).newInstance(new Object[] { this });
                    } catch (Exception e) {
                        factoryService = null;
                        LOGGER.warn("Failed to initialize URLFactory Service [" + urlFactoryServiceClass + "]", e);
                    }
                }
                if (factoryService == null) {
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Using default URLFactory Service Class [" + urlFactoryServiceClass + "]");
                    }
                    factoryService = new XWikiURLFactoryServiceImpl(this);
                }
                // Set the urlFactoryService object in one assignment to prevent threading
                // issues when checking for
                // null above.
                this.urlFactoryService = factoryService;
            }
        }
    }
    return this.urlFactoryService;
}
Also used : XWikiURLFactoryServiceImpl(com.xpn.xwiki.web.XWikiURLFactoryServiceImpl) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass) PasswordClass(com.xpn.xwiki.objects.classes.PasswordClass) MetaClass(com.xpn.xwiki.objects.meta.MetaClass) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) XWikiURLFactoryService(com.xpn.xwiki.web.XWikiURLFactoryService) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) ParseException(org.xwiki.rendering.parser.ParseException) QueryException(org.xwiki.query.QueryException) URIException(org.apache.commons.httpclient.URIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException)

Aggregations

XWikiURLFactoryService (com.xpn.xwiki.web.XWikiURLFactoryService)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)1 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)1 PasswordClass (com.xpn.xwiki.objects.classes.PasswordClass)1 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)1 MetaClass (com.xpn.xwiki.objects.meta.MetaClass)1 XWikiStoreInterface (com.xpn.xwiki.store.XWikiStoreInterface)1 XWikiRequest (com.xpn.xwiki.web.XWikiRequest)1 XWikiServletResponseStub (com.xpn.xwiki.web.XWikiServletResponseStub)1 XWikiURLFactory (com.xpn.xwiki.web.XWikiURLFactory)1 XWikiURLFactoryServiceImpl (com.xpn.xwiki.web.XWikiURLFactoryServiceImpl)1 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 NamingException (javax.naming.NamingException)1 URIException (org.apache.commons.httpclient.URIException)1