/** @see org.wyona.yanel.core.api.attributes.CreatableV2#create(HttpServletRequest) */ public void create(HttpServletRequest request) { try { Repository repo = getRealm().getRepository(); if (request instanceof HttpRequest) { HttpRequest yanelRequest = (HttpRequest) request; if (yanelRequest.isMultipartRequest()) { Enumeration parameters = yanelRequest.getFileNames(); if (parameters.hasMoreElements()) { String name = (String) parameters.nextElement(); Node newNode = org.wyona.yanel.core.util.YarepUtil.addNodes( repo, getPath().toString(), org.wyona.yarep.core.NodeType.RESOURCE); OutputStream output = newNode.getOutputStream(); InputStream is = yanelRequest.getInputStream(name); Streams.copy(is, output, true); uploadMimeType = yanelRequest.getContentType(name); String suffix = org.wyona.commons.io.PathUtil.getSuffix(newNode.getPath()); if (suffix != null) { if (!getMimeTypeBySuffix(suffix).equals(uploadMimeType)) { log.warn( "Upload request content type '" + uploadMimeType + "' is NOT the same as the guessed mime type '" + getMimeTypeBySuffix(suffix) + "' based on the suffix (Path: " + newNode.getPath() + ")"); } } newNode.setMimeType(uploadMimeType); } } else { log.error("this is NOT a multipart request"); } } else { log.error("this is NOT a HttpRequest"); } // TODO: Introspection should not be hardcoded! /* String name = new org.wyona.commons.io.Path(getPath()).getName(); String parent = new org.wyona.commons.io.Path(getPath()).getParent().toString(); String nameWithoutSuffix = name; int lastIndex = name.lastIndexOf("."); if (lastIndex > 0) nameWithoutSuffix = name.substring(0, lastIndex); String introspectionPath = parent + "/introspection-" + nameWithoutSuffix + ".xml"; org.wyona.yanel.core.util.YarepUtil.addNodes(repo, introspectionPath, org.wyona.yarep.core.NodeType.RESOURCE); writer = new java.io.OutputStreamWriter(repo.getNode(introspectionPath).getOutputStream()); writer.write(getIntrospection(name)); writer.close();*/ } catch (Exception e) { log.error(e.getMessage(), e); } }
/** @see org.wyona.yanel.core.api.attributes.CreatableV2#getCreateName(String) */ public String getCreateName(String suggestedName) { if (suggestedName != null && !suggestedName.equals("")) return suggestedName; if (request instanceof HttpRequest) { HttpRequest yanelRequest = (HttpRequest) request; if (yanelRequest.isMultipartRequest()) { Enumeration parameters = yanelRequest.getFileNames(); if (parameters.hasMoreElements()) { return fixAssetName(yanelRequest.getFilesystemName((String) parameters.nextElement())); } } else { log.error("this is NOT a multipart request"); } } else { log.error("this is NOT a HttpRequest"); } return null; }