use of org.apache.struts2.StrutsException in project struts by apache.
the class DefaultClassFinder method readClassDef.
private void readClassDef(String className) {
if (!className.endsWith(".class")) {
className = className.replace('.', '/') + ".class";
}
try {
URL resource = classLoaderInterface.getResource(className);
if (resource != null) {
try (InputStream in = resource.openStream()) {
ClassReader classReader = new ClassReader(in);
classReader.accept(new InfoBuildingVisitor(this), ClassReader.SKIP_DEBUG);
}
} else {
throw new StrutsException("Could not load " + className);
}
} catch (IOException e) {
throw new StrutsException("Could not load " + className, e);
}
}
use of org.apache.struts2.StrutsException in project struts by apache.
the class VelocityManager method newVelocityEngine.
/**
* <p>
* Instantiates a new VelocityEngine.
* </p>
* <p>
* The following is the default Velocity configuration
* </p>
*
* <pre>
* resource.loader = file, class
* file.resource.loader.path = real path of webapp
* class.resource.loader.description = Velocity Classpath Resource Loader
* class.resource.loader.class = org.apache.struts2.views.velocity.StrutsResourceLoader
* </pre>
* <p>
* this default configuration can be overridden by specifying a struts.velocity.configfile property in the
* struts.properties file. the specified config file will be searched for in the following order:
* </p>
*
* <ul>
* <li>relative to the servlet context path</li>
* <li>relative to the WEB-INF directory</li>
* <li>on the classpath</li>
* </ul>
*
* @param context the current ServletContext. may <b>not</b> be null
* @return the new velocity engine
*/
protected VelocityEngine newVelocityEngine(ServletContext context) {
if (context == null) {
String gripe = "Error attempting to create a new VelocityEngine from a null ServletContext!";
LOG.error(gripe);
throw new IllegalArgumentException(gripe);
}
Properties p = loadConfiguration(context);
VelocityEngine velocityEngine = new VelocityEngine();
// Set the velocity attribute for the servlet context
// if this is not set the webapp loader WILL NOT WORK
velocityEngine.setApplicationAttribute(ServletContext.class.getName(), context);
try {
velocityEngine.init(p);
} catch (Exception e) {
throw new StrutsException("Unable to instantiate VelocityEngine!", e);
}
return velocityEngine;
}
use of org.apache.struts2.StrutsException in project struts by apache.
the class AdapterFactory method constructAdapterInstance.
/**
* Create an instance of an adapter dynamically and set its context via
* the AdapterNode interface.
*
* @param adapterClass adapter class
* @param parent parent adapter node
* @param propertyName the property name
* @param propertyValue the property value
*
* @return the new node
*/
private Node constructAdapterInstance(Class adapterClass, AdapterNode parent, String propertyName, Object propertyValue) {
// Check to see if the class has a no-args constructor
try {
adapterClass.getConstructor(new Class[] {});
} catch (NoSuchMethodException e1) {
throw new StrutsException("Adapter class: " + adapterClass + " does not have a no-args constructor.");
}
try {
AdapterNode adapterNode = (AdapterNode) adapterClass.newInstance();
adapterNode.setAdapterFactory(this);
adapterNode.setParent(parent);
adapterNode.setPropertyName(propertyName);
adapterNode.setPropertyValue(propertyValue);
return adapterNode;
} catch (IllegalAccessException | InstantiationException e) {
throw new StrutsException("Cannot adapt " + propertyValue + " (" + propertyName + ") :" + e.getMessage(), e);
}
}
use of org.apache.struts2.StrutsException in project struts by apache.
the class I18n method start.
public boolean start(Writer writer) {
boolean result = super.start(writer);
try {
String name = this.findString(this.name, "name", "Resource bundle name is required. Example: foo or foo_en");
ResourceBundle bundle = defaultTextProvider.getTexts(name);
if (bundle == null) {
LocaleProvider localeProvider = localeProviderFactory.createLocaleProvider();
bundle = localizedTextProvider.findResourceBundle(name, localeProvider.getLocale());
}
if (bundle != null) {
textProvider = textProviderFactory.createInstance(bundle);
getStack().push(textProvider);
pushed = true;
}
} catch (Exception e) {
throw new StrutsException("Could not find the bundle " + name, e);
}
return result;
}
use of org.apache.struts2.StrutsException in project struts by apache.
the class Debug method start.
public boolean start(Writer writer) {
boolean result = super.start(writer);
if (showDebug()) {
ValueStack stack = getStack();
Iterator iter = stack.getRoot().iterator();
List stackValues = new ArrayList(stack.getRoot().size());
while (iter.hasNext()) {
Object o = iter.next();
Map values;
try {
values = reflectionProvider.getBeanMap(o);
} catch (Exception e) {
throw new StrutsException("Caught an exception while getting the property values of " + o, e);
}
stackValues.add(new DebugMapEntry(o.getClass().getName(), values));
}
addParameter("stackValues", stackValues);
}
return result;
}
Aggregations