use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WMultiFileWidget method doHandleUploadRequest.
/**
* The request is a targeted file upload request. Upload the file and respond with the file information.
*
* @param request the request being processed.
*/
protected void doHandleUploadRequest(final Request request) {
// Protect against client-side tampering of disabled/read-only fields.
if (isDisabled() || isReadOnly()) {
throw new SystemException("File widget cannot be updated.");
}
// Only process on a POST
if (!"POST".equals(request.getMethod())) {
throw new SystemException("File widget cannot be updated by " + request.getMethod() + ".");
}
// Check only one file item in the request
FileItem[] items = request.getFileItems(getId());
if (items.length > 1) {
throw new SystemException("More than one file item received on the request.");
}
// Check the client provided a fileID
String fileId = request.getParameter(FILE_UPLOAD_MULTI_PART_ID_KEY);
if (fileId == null) {
throw new SystemException("No file id provided for file upload.");
}
// Wrap the file item
FileItemWrap wrap = new FileItemWrap(items[0]);
FileWidgetUpload file = new FileWidgetUpload(fileId, wrap);
addFile(file);
// Set the file id to be used ion the renderer
setFileUploadRequestId(fileId);
setNewUpload(true);
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class WRepeater method preparePaintComponent.
/**
* Override preparePaintComponent to prepare each row for painting.
*
* @param request the request being responded to.
*/
@Override
protected void preparePaintComponent(final Request request) {
assertConfigured();
List beanList = getBeanList();
List<Integer> used = new ArrayList<>();
for (int i = 0; i < beanList.size(); i++) {
Object rowData = beanList.get(i);
// Each row has its own context. This is why we can reuse the same
// WComponent instance for each row.
UIContext rowContext = getRowContext(rowData, i);
// Check the context has not been used for another row
Integer subId = ((SubUIContext) rowContext).getContextId();
if (used.contains(subId)) {
Object rowId = ((SubUIContext) rowContext).getRowId();
String msg = "The row context for row id [" + rowId + "] has already been used for another row. " + "Either the row ID is not unique or the row bean has not implemented equals/hashcode " + "or no rowIdBeanProperty set on the repeater that uniquely identifies the row.";
throw new SystemException(msg);
}
used.add(subId);
UIContextHolder.pushContext(rowContext);
try {
prepareRow(request, i);
} finally {
UIContextHolder.popContext();
}
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class AbstractWComponent method registerId.
/**
* Helper method to be used by a {@link NamingContextable} to register a component.
*
* @param component the component to register
*/
void registerId(final WComponent component) {
if (!WebUtilities.isActiveNamingContext(this)) {
throw new SystemException("Can only register a component on an active NamingContext");
}
// Get registered id names
ComponentModel model = getOrCreateComponentModel();
Map<String, WComponent> ids = model.getContextIds();
if (ids == null) {
ids = new HashMap<>();
model.setContextIds(ids);
}
// Get id name
String idName = component.getIdName();
// Check if already used
WComponent mapped = ids.get(idName);
// Not in map
if (mapped == null) {
// Save ID / Component
ids.put(idName, component);
} else if (mapped != component) {
// Check is same component
String contextName = getId();
throw new SystemException("Duplicate ID. ID \"" + idName + "\" for " + component.getClass().getName() + " is already in use by " + mapped.getClass().getName() + " in context \"" + contextName + "\".");
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class ContentEscape method escape.
/**
* Writes the content to the response.
*
* @throws IOException if there is an error writing the content.
*/
@Override
public void escape() throws IOException {
LOG.debug("...ContentEscape escape()");
if (contentAccess == null) {
LOG.warn("No content to output");
} else {
String mimeType = contentAccess.getMimeType();
Response response = getResponse();
response.setContentType(mimeType);
if (isCacheable()) {
getResponse().setHeader("Cache-Control", CacheType.CONTENT_CACHE.getSettings());
} else {
getResponse().setHeader("Cache-Control", CacheType.CONTENT_NO_CACHE.getSettings());
}
if (contentAccess.getDescription() != null) {
String fileName = WebUtilities.encodeForContentDispositionHeader(contentAccess.getDescription());
if (displayInline) {
response.setHeader("Content-Disposition", "inline; filename=" + fileName);
} else {
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
}
}
if (contentAccess instanceof ContentStreamAccess) {
InputStream stream = null;
try {
stream = ((ContentStreamAccess) contentAccess).getStream();
if (stream == null) {
throw new SystemException("ContentAccess returned null stream, access=" + contentAccess);
}
StreamUtil.copy(stream, response.getOutputStream());
} finally {
StreamUtil.safeClose(stream);
}
} else {
byte[] bytes = contentAccess.getBytes();
if (bytes == null) {
throw new SystemException("ContentAccess returned null data, access=" + contentAccess);
}
response.getOutputStream().write(bytes);
}
}
}
use of com.github.bordertech.wcomponents.util.SystemException in project wcomponents by BorderTech.
the class TestServlet method addIndirectJar.
/**
* @param jarname the jar name to add
*/
public void addIndirectJar(final String jarname) {
try (JarFile jarfile = new JarFile(jarname)) {
Manifest man = jarfile.getManifest();
Attributes atts = man.getMainAttributes();
String jarlist = atts.getValue("Class-Path");
StringTokenizer tokenizer = new StringTokenizer(jarlist, " ", false);
while (tokenizer.hasMoreTokens()) {
String tokenUrl = tokenizer.nextToken();
union.add(Resource.newResource("jar:" + tokenUrl + "!/"));
LOG.info("Added webdocs at " + tokenUrl);
}
} catch (IOException ex) {
throw new SystemException("Could handle indirect jar " + jarname, ex);
}
}
Aggregations