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);
}
}
}
}
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);
}
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);
}
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);
}
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));
}
Aggregations