use of org.jaffa.exceptions.ApplicationExceptions in project jaffa-framework by jaffa-projects.
the class ValidationRulesEditorAction method do_ValidatorsUrls_Update_Clicked.
/**
* Invoked if a update button on a row is selected.
* @param rowId The selected row on the screen.
* @return The FormKey for the Update screen.
*/
public FormKey do_ValidatorsUrls_Update_Clicked(String rowId) {
ValidationRulesEditorForm myForm = (ValidationRulesEditorForm) form;
ValidationRulesEditorComponent myComp = (ValidationRulesEditorComponent) myForm.getComponent();
FormKey fk = null;
GridModel model = (GridModel) myForm.getValidatorsUrlsWM();
GridModelRow selectedRow = model.getRowById(Integer.parseInt(rowId));
if (selectedRow != null) {
try {
String fileName = (String) selectedRow.get("validatorsUrl");
if (!fileName.equals(myComp.getValidationRulesFile())) {
myComp.setFileContents(null);
myComp.setValidationRulesFile(fileName);
myComp.loadFileContents();
}
myComp.determineAndSetNextScreen();
} catch (ApplicationExceptions e) {
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
} catch (FrameworkException e) {
log.error(null, e);
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, "error.framework.general");
}
}
// Direct User back to current form
if (fk == null)
fk = myComp.determineFormKey();
return fk;
}
use of org.jaffa.exceptions.ApplicationExceptions in project jaffa-framework by jaffa-projects.
the class ValidationRulesEditorAction method do_Rules_Update_Clicked.
/**
* Invoked if a update button on a row is selected.
* @param rowId The selected row on the screen.
* @return The FormKey for the Update screen.
*/
public FormKey do_Rules_Update_Clicked(String rowId) {
ValidationRulesEditorForm myForm = (ValidationRulesEditorForm) form;
ValidationRulesEditorComponent myComp = (ValidationRulesEditorComponent) myForm.getComponent();
FormKey fk = null;
GridModel model = (GridModel) myForm.getRulesWM();
GridModelRow selectedRow = model.getRowById(Integer.parseInt(rowId));
if (selectedRow != null) {
try {
String fileName = (String) selectedRow.get("name");
if (!fileName.equals(myComp.getValidationRulesFile())) {
myComp.setFileContents(null);
myComp.setValidationRulesFile(fileName);
myComp.loadFileContents();
}
myComp.determineAndSetNextScreen();
} catch (ApplicationExceptions e) {
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
} catch (FrameworkException e) {
log.error(null, e);
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, "error.framework.general");
}
}
// Direct User back to current form
if (fk == null)
fk = myComp.determineFormKey();
return fk;
}
use of org.jaffa.exceptions.ApplicationExceptions in project jaffa-framework by jaffa-projects.
the class ValidationRulesEditorAction method do_Refresh_Clicked.
/**
* Clicked event handler for the field Refresh.
* @return The FormKey.
*/
public FormKey do_Refresh_Clicked() {
FormKey fk = null;
ValidationRulesEditorForm myForm = (ValidationRulesEditorForm) form;
ValidationRulesEditorComponent myComp = (ValidationRulesEditorComponent) myForm.getComponent();
myComp.setFileContents(null);
try {
myComp.loadFileContents();
} catch (ApplicationExceptions e) {
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, e);
} catch (FrameworkException e) {
log.error(null, e);
myForm.raiseError(request, ActionMessages.GLOBAL_MESSAGE, "error.framework.general");
}
if (fk == null)
fk = myComp.determineFormKey();
return fk;
}
use of org.jaffa.exceptions.ApplicationExceptions in project jaffa-framework by jaffa-projects.
the class ValidationRulesEditorComponent method performSave.
/**
* This will save the contents of the current file.
* @throws ApplicationExceptions if any error occurs while writing the file.
* @throws FrameworkException if any error occurs.
*/
void performSave() throws FrameworkException, ApplicationExceptions {
BufferedWriter writer = null;
try {
if (m_fileUpdateable) {
URL url = URLHelper.newExtendedURL(m_validationRulesFile);
File f = new File(url.getPath());
writer = new BufferedWriter(new FileWriter(f, false));
writer.write(getFileContents());
writer.flush();
if (log.isDebugEnabled())
log.debug("Saved contents to the file " + m_validationRulesFile);
// Clear cache so new rules are loaded.
RulesMetaDataService.clearCache();
} else {
if (log.isDebugEnabled())
log.debug("File cannot be updated since it cannot be read using File I/O. It is probably part of a JAR: " + m_validationRulesFile);
}
} catch (MalformedURLException e) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new ConfigException(ConfigException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
} catch (IOException e) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new ConfigException(ConfigException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
String str = "Exception thrown while closing the Writer Stream";
log.error(str, e);
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new ConfigException(ConfigException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
}
}
}
}
use of org.jaffa.exceptions.ApplicationExceptions in project jaffa-framework by jaffa-projects.
the class ValidationRulesEditorComponent method loadFileContents.
/**
* Load a file from a URL, which could be an Extended URL
* @throws ApplicationExceptions if any error occurs while reading the file.
* @throws FrameworkException if any error occurs.
*/
void loadFileContents() throws FrameworkException, ApplicationExceptions {
Reader reader = null;
try {
URL url = URLHelper.newExtendedURL(m_validationRulesFile);
File f = new File(url.getPath());
m_fileUpdateable = f.exists() && f.isFile();
reader = new BufferedReader(new InputStreamReader(url.openStream()));
StringBuffer buf = new StringBuffer();
int i;
while ((i = reader.read()) != -1) buf.append((char) i);
m_fileContents = buf.toString();
if (log.isDebugEnabled())
log.debug("Obtained contents from the file " + m_validationRulesFile);
// remove the EditBoxModel from the WidgetCache
getUserSession().getWidgetCache(getComponentId()).removeModel("fileContents");
} catch (MalformedURLException e) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new ConfigException(ConfigException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
} catch (IOException e) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new ConfigException(ConfigException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
String str = "Exception thrown while closing the Reader Stream";
log.error(str, e);
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new ConfigException(ConfigException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
}
}
}
}
Aggregations