use of org.apache.struts.tiles.DefinitionsFactoryException in project sonar-java by SonarSource.
the class ReloadableDefinitionsFactory method createFactoryFromClassname.
/**
* Create Definition factory from provided classname.
* If a factory class name is provided, a factory of this class is created. Otherwise,
* a default factory is created.
* Factory must have a constructor taking ServletContext and Map as parameter.
* @param classname Class name of the factory to create.
* @param servletContext Servlet Context passed to newly created factory.
* @param properties Map of name/property passed to newly created factory.
* @return newly created factory.
* @throws DefinitionsFactoryException If an error occur while initializing factory
*/
public ComponentDefinitionsFactory createFactoryFromClassname(ServletContext servletContext, Map properties, String classname) throws DefinitionsFactoryException {
if (classname == null) {
return createFactory(servletContext, properties);
}
// Try to create from classname
try {
Class factoryClass = RequestUtils.applicationClass(classname);
ComponentDefinitionsFactory factory = (ComponentDefinitionsFactory) factoryClass.newInstance();
factory.initFactory(servletContext, properties);
return factory;
} catch (ClassCastException ex) {
// Bad classname
throw new DefinitionsFactoryException("Error - createDefinitionsFactory : Factory class '" + classname + " must implements 'ComponentDefinitionsFactory'.", ex);
} catch (ClassNotFoundException ex) {
// Bad classname
throw new DefinitionsFactoryException("Error - createDefinitionsFactory : Bad class name '" + classname + "'.", ex);
} catch (InstantiationException ex) {
// Bad constructor or error
throw new DefinitionsFactoryException(ex);
} catch (IllegalAccessException ex) {
throw new DefinitionsFactoryException(ex);
}
}
use of org.apache.struts.tiles.DefinitionsFactoryException in project sonar-java by SonarSource.
the class DefinitionDispatcherAction method execute.
/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it),
* with provision for handling exceptions thrown by the business logic.
*
* @param mapping The ActionMapping used to select this instance
* @param form The optional ActionForm bean for this request (if any)
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
*
* @exception Exception if the application business logic throws
* an exception
* @since Struts 1.1
*/
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
// Identify the request parameter containing the method name
// If none defined, use "def"
String parameter = mapping.getParameter();
if (parameter == null) {
parameter = "def";
}
// Identify the method name to be dispatched to
String name = request.getParameter(parameter);
if (name == null) {
log.error("Can't get parameter '" + parameter + "'.");
return mapping.findForward("error");
}
// Try to dispatch to requested definition
try {
// Read definition from factory, but we can create it here.
ComponentDefinition definition = TilesUtil.getDefinition(name, request, getServlet().getServletContext());
if (log.isDebugEnabled()) {
log.debug("Get Definition " + definition);
}
DefinitionsUtil.setActionDefinition(request, definition);
} catch (FactoryNotFoundException e) {
log.error("Can't get definition factory.", e);
return mapping.findForward("error");
} catch (NoSuchDefinitionException e) {
log.error("Can't get definition '" + name + "'.", e);
return mapping.findForward("error");
} catch (DefinitionsFactoryException e) {
log.error("General Factory error '" + e.getMessage() + "'.", e);
return mapping.findForward("error");
} catch (Exception e) {
log.error("General error '" + e.getMessage() + "'.", e);
return mapping.findForward("error");
}
return mapping.findForward("success");
}
use of org.apache.struts.tiles.DefinitionsFactoryException in project sonar-java by SonarSource.
the class ReloadDefinitionsAction method execute.
/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it),
* with provision for handling exceptions thrown by the business logic.
*
* @param mapping The ActionMapping used to select this instance
* @param form The optional ActionForm bean for this request (if any)
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
*
* @exception Exception if the application business logic throws
* an exception
* @since Struts 1.1
*/
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
try {
ServletContext context = getServlet().getServletContext();
DefinitionsFactory factory = TilesUtil.getDefinitionsFactory(request, context);
factory.setConfig(factory.getConfig(), context);
writer.println("OK");
} catch (ClassCastException e) {
writer.println("FAIL - " + e.toString());
getServlet().log("ReloadAction", e);
} catch (DefinitionsFactoryException e) {
writer.println("FAIL - " + e.toString());
getServlet().log("ReloadAction", e);
}
writer.flush();
writer.close();
return (null);
}
use of org.apache.struts.tiles.DefinitionsFactoryException in project sonar-java by SonarSource.
the class ComponentDefinitionsFactoryWrapper method createFactoryInstance.
/**
* Create Definition factory from provided classname which must implement {@link ComponentDefinitionsFactory}.
* Factory class must extend {@link DefinitionsFactory}.
* @param classname Class name of the factory to create.
* @return newly created factory.
* @throws DefinitionsFactoryException If an error occur while initializing factory
*/
protected ComponentDefinitionsFactory createFactoryInstance(String classname) throws DefinitionsFactoryException {
try {
Class factoryClass = RequestUtils.applicationClass(classname);
Object factory = factoryClass.newInstance();
return (ComponentDefinitionsFactory) factory;
} catch (ClassCastException ex) {
// Bad classname
throw new DefinitionsFactoryException("Error - createDefinitionsFactory : Factory class '" + classname + " must implement 'DefinitionsFactory'.", ex);
} catch (ClassNotFoundException ex) {
// Bad classname
throw new DefinitionsFactoryException("Error - createDefinitionsFactory : Bad class name '" + classname + "'.", ex);
} catch (InstantiationException ex) {
// Bad constructor or error
throw new DefinitionsFactoryException(ex);
} catch (IllegalAccessException ex) {
throw new DefinitionsFactoryException(ex);
}
}
use of org.apache.struts.tiles.DefinitionsFactoryException in project sonar-java by SonarSource.
the class I18nFactorySet method parseXmlFile.
/**
* Parse specified xml file and add definition to specified definitions set.
* This method is used to load several description files in one instances list.
* If filename exists and definition set is <code>null</code>, create a new set. Otherwise, return
* passed definition set (can be <code>null</code>).
* @param servletContext Current servlet context. Used to open file.
* @param filename Name of file to parse.
* @param xmlDefinitions Definitions set to which definitions will be added. If null, a definitions
* set is created on request.
* @return XmlDefinitionsSet The definitions set created or passed as parameter.
* @throws DefinitionsFactoryException On errors parsing file.
*/
protected XmlDefinitionsSet parseXmlFile(ServletContext servletContext, String filename, XmlDefinitionsSet xmlDefinitions) throws DefinitionsFactoryException {
try {
InputStream input = servletContext.getResourceAsStream(filename);
// Patch proposed Houston, Stephen (LIT) on 5 Apr 2002
if (null == input) {
try {
input = new java.io.FileInputStream(servletContext.getRealPath(filename));
} catch (Exception e) {
}
}
// which allows the config files to be stored in a jar
if (input == null) {
input = getClass().getResourceAsStream(filename);
}
// If still nothing found, this mean no config file is associated
if (input == null) {
if (log.isDebugEnabled()) {
log.debug("Can't open file '" + filename + "'");
}
return xmlDefinitions;
}
// if( xmlParser == null )
if (true) {
xmlParser = new XmlParser();
xmlParser.setValidating(isValidatingParser);
}
// Check if definition set already exist.
if (xmlDefinitions == null) {
xmlDefinitions = new XmlDefinitionsSet();
}
xmlParser.parse(input, xmlDefinitions);
} catch (SAXException ex) {
if (log.isDebugEnabled()) {
log.debug("Error while parsing file '" + filename + "'.");
ex.printStackTrace();
}
throw new DefinitionsFactoryException("Error while parsing file '" + filename + "'. " + ex.getMessage(), ex);
} catch (IOException ex) {
throw new DefinitionsFactoryException("IO Error while parsing file '" + filename + "'. " + ex.getMessage(), ex);
}
return xmlDefinitions;
}
Aggregations