Search in sources :

Example 26 with Factory

use of com.opensymphony.xwork2.inject.Factory in project struts by apache.

the class PrefixBasedActionProxyFactory method init.

@Override
public void init() {
    for (String factory : prefixes) {
        String[] thisFactory = factory.split(":");
        if (thisFactory.length == 2) {
            String factoryPrefix = thisFactory[0].trim();
            String factoryName = thisFactory[1].trim();
            ActionProxyFactory obj = container.getInstance(ActionProxyFactory.class, factoryName);
            if (obj != null) {
                actionProxyFactories.put(factoryPrefix, obj);
            } else {
                LOG.warn("Invalid PrefixBasedActionProxyFactory config entry: [{}]", factory);
            }
        }
    }
}
Also used : ActionProxyFactory(com.opensymphony.xwork2.ActionProxyFactory) DefaultActionProxyFactory(com.opensymphony.xwork2.DefaultActionProxyFactory)

Example 27 with Factory

use of com.opensymphony.xwork2.inject.Factory in project struts by apache.

the class DummyFileManager method testCreateDummyFileManager.

public void testCreateDummyFileManager() throws Exception {
    // given
    fileManager = new DummyFileManager();
    DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
    factory.setFileManager(new DefaultFileManager());
    factory.setContainer(new DummyContainer());
    // when
    FileManager fm = factory.getFileManager();
    // then
    assertTrue(fm instanceof DummyFileManager);
}
Also used : FileManager(com.opensymphony.xwork2.FileManager)

Example 28 with Factory

use of com.opensymphony.xwork2.inject.Factory in project struts by apache.

the class PortletFreemarkerResult method createModel.

/**
 * <p>
 * Build the instance of the ScopesHashModel, including JspTagLib support
 * </p>
 *
 * <p>Objects added to the model are:</p>
 *
 * <ul>
 * <li>Application - servlet context attributes hash model
 * <li>JspTaglibs - jsp tag lib factory model
 * <li>Request - request attributes hash model
 * <li>Session - session attributes hash model
 * <li>request - the HttpServletRequst object for direct access
 * <li>response - the HttpServletResponse object for direct access
 * <li>stack - the OgnLValueStack instance for direct access
 * <li>ognl - the instance of the OgnlTool
 * <li>action - the action itself
 * <li>exception - optional : the JSP or Servlet exception as per the
 * servlet spec (for JSP Exception pages)
 * <li>struts - instance of the StrutsUtil class
 * </ul>
 *
 * @return freemarker template model
 *
 * @throws TemplateModelException in case of template model errors
 */
protected TemplateModel createModel() throws TemplateModelException {
    ServletContext servletContext = ServletActionContext.getServletContext();
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();
    ValueStack stack = ServletActionContext.getContext().getValueStack();
    return freemarkerManager.buildTemplateModel(stack, invocation.getAction(), servletContext, request, response, wrapper);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ValueStack(com.opensymphony.xwork2.util.ValueStack) ServletContext(javax.servlet.ServletContext) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 29 with Factory

use of com.opensymphony.xwork2.inject.Factory in project struts by apache.

the class StrutsResultFactoryTest method testUseCustomResultBuilder.

public void testUseCustomResultBuilder() throws Exception {
    // given
    initDispatcherWithConfigs("struts-default.xml,struts-object-factory-result-builder.xml");
    // when
    ResultFactory actual = container.getInstance(ResultFactory.class);
    // then
    assertTrue(actual instanceof MyResultFactory);
}
Also used : ResultFactory(com.opensymphony.xwork2.factory.ResultFactory)

Example 30 with Factory

use of com.opensymphony.xwork2.inject.Factory in project struts by apache.

the class SetPropertiesTest method testAddingToCollectionBasedOnPermission.

public void testAddingToCollectionBasedOnPermission() {
    final MockObjectTypeDeterminer determiner = new MockObjectTypeDeterminer(Long.class, Bar.class, "id", true);
    loadConfigurationProviders(new StubConfigurationProvider() {

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            builder.factory(ObjectTypeDeterminer.class, new Factory() {

                public Object create(Context context) throws Exception {
                    return determiner;
                }

                @Override
                public Class type() {
                    return determiner.getClass();
                }
            }, Scope.SINGLETON);
        }
    });
    Collection barColl = new HashSet();
    ValueStack vs = ActionContext.getContext().getValueStack();
    ReflectionContextState.setCreatingNullObjects(vs.getContext(), true);
    ReflectionContextState.setReportingConversionErrors(vs.getContext(), true);
    Foo foo = new Foo();
    foo.setBarCollection(barColl);
    vs.push(foo);
    String bar1Title = "title";
    vs.setValue("barCollection(11).title", bar1Title);
    assertEquals(1, barColl.size());
    Object bar = barColl.iterator().next();
    assertTrue(bar instanceof Bar);
    assertEquals(((Bar) bar).getTitle(), bar1Title);
    assertEquals(((Bar) bar).getId(), new Long(11));
    // now test where there is no permission
    determiner.setShouldCreateIfNew(false);
    String bar2Title = "another title";
    vs.setValue("barCollection(22).title", bar1Title);
    assertEquals(1, barColl.size());
    bar = barColl.iterator().next();
    assertTrue(bar instanceof Bar);
    assertEquals(((Bar) bar).getTitle(), bar1Title);
    assertEquals(((Bar) bar).getId(), new Long(11));
}
Also used : Context(com.opensymphony.xwork2.inject.Context) ActionContext(com.opensymphony.xwork2.ActionContext) ValueStack(com.opensymphony.xwork2.util.ValueStack) StubConfigurationProvider(com.opensymphony.xwork2.test.StubConfigurationProvider) Foo(com.opensymphony.xwork2.util.Foo) MockObjectTypeDeterminer(com.opensymphony.xwork2.mock.MockObjectTypeDeterminer) Factory(com.opensymphony.xwork2.inject.Factory) Bar(com.opensymphony.xwork2.util.Bar) ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) ObjectTypeDeterminer(com.opensymphony.xwork2.conversion.ObjectTypeDeterminer) MockObjectTypeDeterminer(com.opensymphony.xwork2.mock.MockObjectTypeDeterminer) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException)

Aggregations

ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)10 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)7 ValueStack (com.opensymphony.xwork2.util.ValueStack)5 DefaultFileManagerFactory (com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory)5 ActionProxyFactory (com.opensymphony.xwork2.ActionProxyFactory)4 InterceptorMapping (com.opensymphony.xwork2.config.entities.InterceptorMapping)4 Context (com.opensymphony.xwork2.inject.Context)4 ArrayList (java.util.ArrayList)4 StrutsException (org.apache.struts2.StrutsException)4 ActionContext (com.opensymphony.xwork2.ActionContext)3 DefaultActionProxyFactory (com.opensymphony.xwork2.DefaultActionProxyFactory)3 FileManager (com.opensymphony.xwork2.FileManager)3 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)3 Factory (com.opensymphony.xwork2.inject.Factory)3 StubConfigurationProvider (com.opensymphony.xwork2.test.StubConfigurationProvider)3 DefaultFileManager (com.opensymphony.xwork2.util.fs.DefaultFileManager)3 LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3