use of org.jaffa.applications.jaffa.modules.admin.components.roleseditor.ui.exceptions.RolesEditorException in project jaffa-framework by jaffa-projects.
the class RolesEditorComponent method performSave.
/**
* This will perform the following tasks.
* - Saves the contents to roles.xml.
* - clears the PolicyCache
* @param request The request we are processing.
* @throws FrameworkException,ApplicationExceptions if any error occurs.
*/
protected void performSave(HttpServletRequest request) throws FrameworkException, ApplicationExceptions {
ApplicationExceptions appExps = new ApplicationExceptions();
String prop = PolicyCache.getFileLocation();
BufferedWriter writer = null;
try {
// Create a URL for the resource file...
String absoluteFileName = URLHelper.newExtendedURL(prop).getPath();
// update the contents of the file
writer = new BufferedWriter(new FileWriter(absoluteFileName));
writer.write(getFileContents());
writer.flush();
// Clear the cache
PolicyManager.clearCache();
// clear the Menu Navigation cache and refresh the Menu
clearCacheAndRefreshMenu(request);
} catch (MalformedURLException e) {
appExps.add(new RolesEditorException(RolesEditorException.PROP_BADURL_ERROR, prop, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
} catch (IOException e) {
appExps.add(new RolesEditorException(RolesEditorException.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);
appExps.add(new RolesEditorException(RolesEditorException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
}
}
}
use of org.jaffa.applications.jaffa.modules.admin.components.roleseditor.ui.exceptions.RolesEditorException in project jaffa-framework by jaffa-projects.
the class RolesEditorComponent method retrieveFileContents.
/**
* This retrieves the the file contents of the roles.xml file specified in the Configuration properties file.
* @throws FrameworkException , ApplicationExceptions if any error occurs.
*/
protected void retrieveFileContents() throws FrameworkException, ApplicationExceptions {
ApplicationExceptions appExps = new ApplicationExceptions();
String prop = PolicyCache.getFileLocation();
BufferedReader reader = null;
try {
// clear the widget cache
getUserSession().getWidgetCache(getComponentId()).clear();
// Create a URL for the resource file...
String absoluteFileName = URLHelper.newExtendedURL(prop).getPath();
// read the contents of the file
reader = new BufferedReader(new FileReader(absoluteFileName));
StringBuffer buf = new StringBuffer();
String str = null;
while ((str = reader.readLine()) != null) {
buf.append(str);
buf.append("\r\n");
}
m_fileContents = buf.toString();
} catch (MalformedURLException e) {
appExps.add(new RolesEditorException(RolesEditorException.PROP_BADURL_ERROR, prop, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
} catch (IOException e) {
appExps.add(new RolesEditorException(RolesEditorException.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);
appExps.add(new RolesEditorException(RolesEditorException.PROP_FILEREAD_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
}
}
}
use of org.jaffa.applications.jaffa.modules.admin.components.roleseditor.ui.exceptions.RolesEditorException in project jaffa-framework by jaffa-projects.
the class RolesEditorForm method doValidate.
/**
* This method should be invoked to copy the fields from the FormBean to the component after successful validation.
* @return true of the values are copied successfully
*/
public boolean doValidate() throws FrameworkException, ApplicationExceptions {
String value = null;
ApplicationExceptions appExps = new ApplicationExceptions();
value = getFileContentsWM().getValue();
if (value == null || (value != null && value.trim().length() == 0)) {
appExps.add(new RolesEditorException(RolesEditorException.PROP_XML_FILE_PARSE_ERROR, StringHelper.convertToHTML(MessageHelper.findMessage("label.Jaffa.Admin.RoleEditor.NoContent", null))));
throw appExps;
}
try {
// Create a factory object for creating DOM parsers
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Specifies that the parser produced by this factory will validate documents as they are parsed.
factory.setValidating(true);
// Now use the factory to create a DOM parser
DocumentBuilder parser = factory.newDocumentBuilder();
// Specifies the EntityResolver onceto resolve DTD used in XML documents
parser.setEntityResolver(new DefaultEntityResolver());
// Specifies the ErrorHandler to handle warning/error/fatalError conditions
parser.setErrorHandler(new DefaultErrorHandler());
Document document = parser.parse(new InputSource(new StringReader(value)));
} catch (ParserConfigurationException e) {
// Cannot pass e.toString() and pass as parameter as the the meesage contains quotes
// which dows not work properly with displaying the messages
appExps.add(new RolesEditorException(RolesEditorException.PROP_XML_FILE_PARSE_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
} catch (SAXException e) {
appExps.add(new RolesEditorException(RolesEditorException.PROP_XML_FILE_PARSE_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
} catch (IOException e) {
appExps.add(new RolesEditorException(RolesEditorException.PROP_XML_FILE_PARSE_ERROR, StringHelper.convertToHTML(e.getMessage())));
throw appExps;
}
setFileContents(value);
return true;
}
Aggregations