Changeset 696
- Timestamp:
- 03/09/10 13:10:11 (6 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 35 edited
-
KNOWN_ISSUES (modified) (1 diff)
-
src/com/calenco/resource/system/AbstractSystemResource.java (modified) (3 diffs)
-
src/com/calenco/resource/system/AddOnResource.java (modified) (2 diffs)
-
src/com/calenco/resource/system/AdminPasswordResource.java (modified) (2 diffs)
-
src/com/calenco/resource/system/ControlResource.java (modified) (2 diffs)
-
src/com/calenco/resource/system/LanguagesResource.java (modified) (2 diffs)
-
src/com/calenco/resource/system/RepositoryResource.java (modified) (2 diffs)
-
src/com/calenco/resource/system/ToolchainResource.java (modified) (2 diffs)
-
src/com/calenco/resource/system/ToolchainsResource.java (modified) (2 diffs)
-
src/com/calenco/resource/system/UserResource.java (modified) (2 diffs)
-
src/com/calenco/resource/system/UserRightsResource.java (modified) (2 diffs)
-
src/com/calenco/resource/system/UsersResource.java (modified) (2 diffs)
-
src/com/calenco/resource/system/WorkspaceResource.java (modified) (1 diff)
-
src/com/calenco/resource/system/WorkspacesResource.java (modified) (2 diffs)
-
src/com/calenco/resource/workspace/AbstractContentResource.java (added)
-
src/com/calenco/resource/workspace/AbstractWorkspaceResource.java (modified) (6 diffs)
-
src/com/calenco/resource/workspace/AssociationResource.java (modified) (2 diffs)
-
src/com/calenco/resource/workspace/AssociationsResource.java (modified) (1 diff)
-
src/com/calenco/resource/workspace/ClassificationResource.java (modified) (2 diffs)
-
src/com/calenco/resource/workspace/ClassificationsResource.java (modified) (1 diff)
-
src/com/calenco/resource/workspace/ContentPropertiesResource.java (modified) (2 diffs)
-
src/com/calenco/resource/workspace/ContentResource.java (modified) (14 diffs)
-
src/com/calenco/resource/workspace/ContentRevhistoryResource.java (modified) (2 diffs)
-
src/com/calenco/resource/workspace/ContentStylesheetsResource.java (modified) (3 diffs)
-
src/com/calenco/resource/workspace/ContentToolchainsResource.java (modified) (3 diffs)
-
src/com/calenco/resource/workspace/DepsTreeResource.java (modified) (1 diff)
-
src/com/calenco/resource/workspace/LanguageResource.java (modified) (1 diff)
-
src/com/calenco/resource/workspace/LanguagesResource.java (modified) (1 diff)
-
src/com/calenco/resource/workspace/PublicationOutputResource.java (modified) (1 diff)
-
src/com/calenco/resource/workspace/PublicationQueueResource.java (modified) (2 diffs)
-
src/com/calenco/resource/workspace/PublicationResource.java (modified) (1 diff)
-
src/com/calenco/resource/workspace/PublicationsResource.java (modified) (2 diffs)
-
src/com/calenco/resource/workspace/ReleaseFileResource.java (modified) (2 diffs)
-
src/com/calenco/resource/workspace/ReleaseResource.java (modified) (1 diff)
-
src/com/calenco/resource/workspace/ReleasesResource.java (modified) (1 diff)
-
src/com/calenco/resource/workspace/StylesheetsResource.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/KNOWN_ISSUES
r657 r696 8 8 - There's some problems with the UI on Internet Explorer 7/8, we're working hard 9 9 to fix them all. 10 11 - Dependencies are not tracked taking into account revisions. For example, I 12 upload file F with deps A and B; I then upload file F again, but this time 13 only with dep A: dep B is still recorded for file F and the deps tree view 14 still shows B as a dep of F, while it's not a dep anymore. -
trunk/src/com/calenco/resource/system/AbstractSystemResource.java
r640 r696 26 26 import com.calenco.repository.PooledRepoManager; 27 27 import com.calenco.repository.dao.UserDAO; 28 import javax.jcr.RepositoryException;29 28 import javax.jcr.Session; 30 29 import org.restlet.data.Form; … … 66 65 init(); 67 66 setExisting(true); 68 } catch (RepositoryException re) { 69 String msg = String.format("Cannot initialize system resource %s: %s", getClass().getName(), re.getMessage()); 70 throw new ResourceException(Status.SERVER_ERROR_INTERNAL, msg); 67 } catch (Exception e) { 68 if (e instanceof ResourceException) { // Rethrow 69 ResourceException re = (ResourceException) e; 70 throw re; 71 } else { // Other exception -> HTTP 500 72 String msg = String.format("Cannot initialize system resource %s: %s", getClass().getName(), e.getMessage()); 73 throw new ResourceException(Status.SERVER_ERROR_INTERNAL, msg); 74 } 71 75 } finally { 72 76 repoMgr.releaseSessionRO(session); … … 97 101 } 98 102 99 abstract void init() throws RepositoryException;103 abstract void init() throws Exception; 100 104 101 105 abstract boolean canRequest(Method method); -
trunk/src/com/calenco/resource/system/AddOnResource.java
r585 r696 26 26 import com.calenco.addon.AddOnsManager; 27 27 import java.io.File; 28 import javax.jcr.RepositoryException;29 28 import org.apache.commons.io.FilenameUtils; 30 29 import org.restlet.data.MediaType; … … 53 52 54 53 @Override 55 void init() throws RepositoryException {54 void init() throws Exception { 56 55 kind = Reference.decode((String) getRequest().getAttributes().get("kind")); // NOI18N 57 56 addonName = Reference.decode((String) getRequest().getAttributes().get("addon")); // NOI18N -
trunk/src/com/calenco/resource/system/AdminPasswordResource.java
r679 r696 23 23 package com.calenco.resource.system; 24 24 25 import com.calenco.CalencoV2;26 25 import com.calenco.security.SUSecurityManager; 27 import javax.jcr.RepositoryException;28 26 import org.restlet.data.Form; 29 27 import org.restlet.data.Method; … … 41 39 42 40 @Override 43 void init() throws RepositoryException {41 void init() throws Exception { 44 42 } 45 43 -
trunk/src/com/calenco/resource/system/ControlResource.java
r585 r696 24 24 25 25 import com.calenco.CalencoV2App; 26 import javax.jcr.RepositoryException;27 26 import org.restlet.data.Method; 28 27 import org.restlet.data.Status; … … 41 40 42 41 @Override 43 void init() throws RepositoryException {42 void init() throws Exception { 44 43 String host = getRequest().getClientInfo().getAddress(); 45 44 if (!(("127.0.0.1").equals(host) || ("0:0:0:0:0:0:0:1").equals(host))) { // NOI18N -
trunk/src/com/calenco/resource/system/LanguagesResource.java
r694 r696 26 26 import com.calenco.repository.dao.LanguageDAO; 27 27 import java.util.Set; 28 import javax.jcr.RepositoryException;29 28 import org.json.JSONArray; 30 29 import org.json.JSONObject; … … 48 47 49 48 @Override 50 void init() throws RepositoryException {49 void init() throws Exception { 51 50 LanguageDAO dao = new LanguageDAO(session); 52 51 languages = dao.findAll(); -
trunk/src/com/calenco/resource/system/RepositoryResource.java
r585 r696 27 27 import java.util.HashMap; 28 28 import java.util.Map; 29 import javax.jcr.RepositoryException;30 29 import org.restlet.data.CharacterSet; 31 30 import org.restlet.data.MediaType; … … 49 48 50 49 @Override 51 void init() throws RepositoryException { 52 /* Do nothing */ 50 void init() throws Exception { 53 51 } 54 52 -
trunk/src/com/calenco/resource/system/ToolchainResource.java
r585 r696 27 27 import com.calenco.utils.XhtmlHelper; 28 28 import java.io.IOException; 29 import javax.jcr.RepositoryException;30 29 import org.restlet.data.MediaType; 31 30 import org.restlet.data.Method; … … 49 48 50 49 @Override 51 void init() throws RepositoryException {50 void init() throws Exception { 52 51 tcname = Reference.decode((String) getRequest().getAttributes().get("tchain")); // NOI18N 53 52 tchain = AddOnsManager.getInstance().getToolchain(tcname); 54 53 if (tchain == null) { 55 54 String msg = String.format("Toolchain \"%s\" unknown", tcname); 56 throw new ResourceException(Status.CLIENT_ERROR_ BAD_REQUEST, msg);55 throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, msg); 57 56 } 58 57 } -
trunk/src/com/calenco/resource/system/ToolchainsResource.java
r694 r696 28 28 import java.io.IOException; 29 29 import java.util.List; 30 import javax.jcr.RepositoryException;31 30 import org.json.JSONArray; 32 31 import org.json.JSONObject; … … 54 53 55 54 @Override 56 void init() throws RepositoryException {55 void init() throws Exception { 57 56 Form query = getRequest().getResourceRef().getQueryAsForm(); 58 57 cco_xmltype = query.getFirstValue("cco_xmltype"); // NOI18N -
trunk/src/com/calenco/resource/system/UserResource.java
r637 r696 29 29 import com.calenco.security.JcrVerifier; 30 30 import com.calenco.utils.XhtmlHelper; 31 import javax.jcr.RepositoryException;32 31 import org.restlet.data.Form; 33 32 import org.restlet.data.MediaType; … … 53 52 54 53 @Override 55 void init() throws RepositoryException {54 void init() throws Exception { 56 55 email = (String) getRequest().getAttributes().get("user"); // NOI18N 57 56 String identifier = getRequest().getChallengeResponse().getIdentifier(); -
trunk/src/com/calenco/resource/system/UserRightsResource.java
r637 r696 32 32 import java.util.List; 33 33 import java.util.Set; 34 import javax.jcr.RepositoryException;35 34 import org.json.JSONArray; 36 35 import org.json.JSONObject; … … 60 59 61 60 @Override 62 void init() throws RepositoryException {61 void init() throws Exception { 63 62 email = Reference.decode((String)getRequest().getAttributes().get("user")); // NOI18N 64 63 if (email == null || "".equals(email)) { -
trunk/src/com/calenco/resource/system/UsersResource.java
r631 r696 32 32 import com.calenco.utils.XhtmlHelper; 33 33 import java.util.Set; 34 import javax.jcr.RepositoryException;35 34 import org.json.JSONArray; 36 35 import org.json.JSONObject; … … 57 56 58 57 @Override 59 void init() throws RepositoryException {58 void init() throws Exception { 60 59 users = new UserDAO(session).findAll(); 61 60 } -
trunk/src/com/calenco/resource/system/WorkspaceResource.java
r637 r696 60 60 61 61 @Override 62 void init() throws RepositoryException {62 void init() throws Exception { 63 63 wksp = Reference.decode((String)getRequest().getAttributes().get("wksp")); // NOI18N 64 64 workspace = new WorkspaceDAO(session).findByName(wksp); -
trunk/src/com/calenco/resource/system/WorkspacesResource.java
r681 r696 37 37 import java.util.Set; 38 38 import java.util.TreeSet; 39 import javax.jcr.RepositoryException;40 39 import org.json.JSONArray; 41 40 import org.json.JSONObject; … … 64 63 65 64 @Override 66 void init() throws RepositoryException {65 void init() throws Exception { 67 66 WorkspaceDAO dao = new WorkspaceDAO(session); 68 67 if (isSysAdmin) { -
trunk/src/com/calenco/resource/workspace/AbstractWorkspaceResource.java
r631 r696 32 32 import java.io.UnsupportedEncodingException; 33 33 import java.net.URLEncoder; 34 import javax.jcr.RepositoryException;35 34 import javax.jcr.Session; 36 35 import org.restlet.Request; … … 93 92 throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, msg); 94 93 } 94 Method method = req.getMethod(); 95 95 if (!user.isSysAdmin) { 96 96 /* Check user can access (use) workspace */ … … 101 101 throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, msg); 102 102 } 103 Method method = req.getMethod();104 103 if (user.isPubUser() && Method.GET.equals(method) && req.getResourceRef().getPath().indexOf("/content") != -1) { 105 104 String host = req.getClientInfo().getAddress(); … … 122 121 * init() 123 122 */ 124 if (!canRequest( req.getMethod())) {123 if (!canRequest(method)) { 125 124 String msg = String.format("%s: User %s, identified by %s, cannot issue %s requests on workspace %s", getClass().getName(), user.getName(), identifier, req.getMethod(), wksp); 126 125 getLogger().warning(msg); … … 129 128 } 130 129 setExisting(true); 131 } catch (RepositoryException re) { 132 String msg = String.format("Cannot initialize resource for workspace %s: %s", wksp, re.getMessage()); 133 throw new ResourceException(Status.SERVER_ERROR_INTERNAL, msg); 130 } catch (Exception e) { 131 if (e instanceof ResourceException) { // Rethrow 132 ResourceException re = (ResourceException) e; 133 throw re; 134 } else { // Other exception -> HTTP 500 135 String msg = String.format("Cannot initialize resource for workspace %s: %s", wksp, e.getMessage()); 136 throw new ResourceException(Status.SERVER_ERROR_INTERNAL, msg); 137 } 134 138 } finally { 135 139 repoMgr.releaseSessionRO(session); … … 202 206 * Concrete resource classes extending this one must implement this method 203 207 * to perform resource-specific initialization. If there's a problem 204 * initializing the resource the implementation must call setStatus() with205 * the proper HTTP status code, and throw an Exception witha human-readable208 * initializing the resource the implementation must throw a 209 * ResourceException with proper HTTP status code and a human-readable 206 210 * error message. 207 211 * 208 * @throws Exception if there are problems initializing the resource 209 */ 210 abstract void init() throws RepositoryException; 212 * @throws Exception a catch-all for possible exceptions (XML, repository, 213 * etc.) thrown by init() implementations 214 */ 215 abstract void init() throws Exception; 211 216 212 217 /** -
trunk/src/com/calenco/resource/workspace/AssociationResource.java
r620 r696 26 26 import com.calenco.repository.dao.AssociationDAO; 27 27 import java.io.IOException; 28 import javax.jcr.RepositoryException;29 28 import org.restlet.data.MediaType; 30 29 import org.restlet.data.Method; … … 46 45 47 46 @Override 48 void init() throws RepositoryException {47 void init() throws Exception { 49 48 AssociationDAO adao = new AssociationDAO(session, workspace); 50 49 aname = Reference.decode((String)getRequest().getAttributes().get("assoc")); // NOI18N -
trunk/src/com/calenco/resource/workspace/AssociationsResource.java
r620 r696 69 69 70 70 @Override 71 void init() throws RepositoryException {71 void init() throws Exception { 72 72 /* Get Query Params */ 73 73 Form query = getRequest().getResourceRef().getQueryAsForm(); -
trunk/src/com/calenco/resource/workspace/ClassificationResource.java
r639 r696 37 37 import java.util.Set; 38 38 import java.util.TreeSet; 39 import javax.jcr.RepositoryException;40 39 import org.json.JSONArray; 41 40 import org.json.JSONException; … … 70 69 71 70 @Override 72 void init() throws RepositoryException {71 void init() throws Exception { 73 72 /* Get format parameter from the request */ 74 73 Form query = getRequest().getResourceRef().getQueryAsForm(); -
trunk/src/com/calenco/resource/workspace/ClassificationsResource.java
r694 r696 60 60 61 61 @Override 62 void init() throws RepositoryException {62 void init() throws Exception { 63 63 ClassificationDAO dao = new ClassificationDAO(session, workspace); 64 64 classifications = dao.findAll(); -
trunk/src/com/calenco/resource/workspace/ContentPropertiesResource.java
r637 r696 59 59 * @author fabman 60 60 */ 61 public class ContentPropertiesResource extends AbstractWorkspaceResource { 62 String langOrFile = null; 63 String lang = null; 64 String file = null; 61 public class ContentPropertiesResource extends AbstractContentResource { 65 62 String pname = null; 66 63 String pattern = null; 67 64 68 65 @Override 69 void init () throws RepositoryException {66 void initResource() throws Exception { 70 67 /* Get request params */ 71 68 Map<String, Object> requestParams = getRequest().getAttributes(); 72 langOrFile = Reference.decode((String)requestParams.get("langOrFile")); // NOI18N73 lang = Reference.decode((String)requestParams.get("lang")); // NOI18N74 file = Reference.decode((String)requestParams.get("file")); // NOI18N75 69 pname = Reference.decode((String)requestParams.get("pname")); // NOI18N 76 70 Form query = getRequest().getResourceRef().getQueryAsForm(); … … 82 76 83 77 @Override 84 boolean can Request(Method method) {78 boolean canPerformRequest(Method method) { 85 79 if (pname == null || "".equals(pname)) { 86 80 return Method.GET.equals(method); -
trunk/src/com/calenco/resource/workspace/ContentResource.java
r695 r696 112 112 * @author fabman 113 113 */ 114 public class ContentResource extends Abstract WorkspaceResource {114 public class ContentResource extends AbstractContentResource { 115 115 final static String DAVNS = Constants.DAVNS; 116 String langOrFile = null;117 String lang = null;118 String file = null;119 116 String rev = null; // Means get the HEAD revision (JCR baseVersion) 120 117 // If true, try to provide the means to get a savedlg file (different content disposition, should pop up "Save as" browser dialog) … … 122 119 MetadataService mds = null; 123 120 int contentPathIndex = -1; 124 String path = null;125 String fileName = null;126 121 File tempFile = null; 127 122 128 123 @Override 129 void init () throws RepositoryException {124 void initResource() throws Exception { 130 125 contentPathIndex = ContentDAO.getContentPath(workspace).length() + 1; 131 126 /* Get request params */ 132 langOrFile = Reference.decode((String)getRequest().getAttributes().get("langOrFile")); // NOI18N133 lang = Reference.decode((String)getRequest().getAttributes().get("lang")); // NOI18N134 file = Reference.decode((String)getRequest().getAttributes().get("file")); // NOI18N135 127 Form query = getRequest().getResourceRef().getQueryAsForm(); 136 128 rev = query.getFirstValue("rev"); // NOI18N … … 165 157 getAllowedMethods().add(Method.DELETE); 166 158 getAllowedMethods().add(Method.HEAD); 167 if (langOrFile == null && lang == null && file == null) { // Intl folder 168 fileName = ""; 169 } else if (langOrFile != null && lang == null && file == null) { // Folder or file of intl folder 170 fileName = langOrFile; 171 } else if (langOrFile == null && lang != null && file != null) { // File in given lang 172 fileName = String.format("%s/%s", lang, file); 173 } 174 path = String.format("%s/content%s", workspace.href, "".equals(fileName) ? fileName : "/" + fileName); 159 getAllowedMethods().add(Method.LOCK); 160 getAllowedMethods().add(Method.UNLOCK); 175 161 setOnSent(new CleanupTempFile()); 176 162 } 177 163 178 164 @Override 179 boolean can Request(Method method) {165 boolean canPerformRequest(Method method) { 180 166 return 181 167 Method.OPTIONS.equals(method) || … … 187 173 Method.POST.equals(method) || 188 174 Method.PUT.equals(method) || 189 Method.DELETE.equals(method) && ((langOrFile == null && lang != null && file != null) || (langOrFile != null && lang == null && file == null));175 (Method.DELETE.equals(method) && isFile); 190 176 } 191 177 … … 193 179 @Override 194 180 public Representation delete() throws ResourceException { 181 session = null; 182 try { 183 session = repoMgr.getSessionRW(); 184 ContentDAO cdao = new ContentDAO(session, workspace); 185 String fpath = null; 186 if (isIntlFileOrLangFolder) { 187 fpath = cdao.delete(Language.INTL, langOrFile); 188 } else { 189 Language l = new LanguageDAO(session, workspace).findByCode(lang); 190 if (!l.isActive) { 191 String msg = String.format("Ignoring DELETE request for file \"%s\" of inactive language \"%s\" for workspace %s", file, lang, wksp); 192 getLogger().warning(msg); 193 setStatus(Status.CLIENT_ERROR_BAD_REQUEST); 194 return new StringRepresentation(msg); 195 } 196 fpath = cdao.delete(lang, file); 197 } 198 if (fpath != null) { 199 // Wipe all associations having this file as a source/target 200 AssociationDAO adao = new AssociationDAO(session, workspace); 201 Properties props = new Properties(); 202 if (isIntlFileOrLangFolder) { 203 fpath += "*"; // TODO: Why is this only needed for intl files? 204 } 205 props.put("from", fpath); 206 adao.removeAll(adao.findByProperties(props)); 207 props.clear(); 208 props.put("to", fpath); 209 adao.removeAll(adao.findByProperties(props)); 210 } else { 211 getLogger().warning(String.format("Associations (dependencies) cannot be deleted for file %s. This may lead to problems with resources referencing this file!", path)); 212 } 213 setStatus(Status.SUCCESS_NO_CONTENT); 214 return new EmptyRepresentation(); 215 } catch (Exception e) { 216 String msg = String.format("Cannot delete %s from workspace %s", path, wksp); 217 throw new ResourceException(Status.SERVER_ERROR_INTERNAL, msg, e); 218 } finally { 219 repoMgr.releaseSessionRW(session); 220 long lstop = System.currentTimeMillis(); 221 getLogger().info(String.format("DELETE request processed in %2.3f sec.", (lstop - rstart) / 1000.0)); 222 } 223 } 224 225 @Deprecated 226 public Representation deleteOLD() throws ResourceException { 195 227 session = null; 196 228 try { … … 281 313 return new StringRepresentation(msg); 282 314 } 283 String lcode = (langOrFile == null ? lang : Language.INTL);284 String fname = (langOrFile == null ? file : langOrFile);285 315 session = null; 286 316 try { … … 297 327 File f = new File(Constants.IO_TMPDIR, fname); 298 328 IOUtils.copy(new AutoCloseInputStream((entity.getStream())), FileUtils.openOutputStream(f)); 299 ContentDAO dao = new ContentDAO(session, workspace);300 String href = dao.store(f, lcode);329 ContentDAO cdao = new ContentDAO(session, workspace); 330 String href = cdao.store(f, lcode); 301 331 /* 302 332 * From now on, code is very similar to that in the POST handler, 303 333 * make sure you synchronize both as needed! 304 334 */ 305 setAuthor(href, getRequest().getChallengeResponse().getIdentifier(), dao);335 setAuthor(href, getRequest().getChallengeResponse().getIdentifier(), cdao); 306 336 updateHeadRelease(); // TODO: Do we REALLY need this now? Deprecate? 307 addOnProcessing(lcode, f, href, dao);337 addOnProcessing(lcode, f, href, cdao); 308 338 FileUtils.deleteQuietly(f); 309 339 // Fire r2d2 to update publications depending on the uploaded file … … 326 356 @Override 327 357 public Representation post(Representation entity) throws ResourceException { 358 session = null; 359 try { 360 session = repoMgr.getSessionRW(); 361 if (!Language.INTL.equals(lcode)) { 362 // Bark if requested workspace lang is not active 363 Language l = new LanguageDAO(session, workspace).findByCode(lcode); 364 if (l == null || !l.isActive) { 365 String msg = String.format("Cannot store file into inactive or non-existing language \"%s\" for workspace \"%s\"", lcode, wksp); 366 getLogger().warning(msg); 367 setStatus(Status.CLIENT_ERROR_FORBIDDEN); 368 return new StringRepresentation(msg); 369 } 370 } 371 List<FileItem> fitems = new RestletFileUpload(new DiskFileItemFactory()).parseRepresentation(entity); 372 JSONObject details = new JSONObject(); 373 Map<String, String> fields = new HashMap<String, String>(); 374 for (FileItem fitem: fitems) { 375 if (fitem.isFormField()) { 376 fields.put(fitem.getFieldName(), fitem.getString()); 377 } 378 } 379 for (FileItem fitem: fitems) { 380 if (!fitem.isFormField()) { // It's an uploaded FILE, as opposed to a form field that may have come along with the uploaded files 381 long fsize = fitem.getSize(); 382 if (Constants.MAX_ALLOWED_FSIZE < fsize) { 383 String msg = String.format("Cannot store %d bytes, maximum upload size is %d bytes", fsize, Constants.MAX_ALLOWED_FSIZE); 384 getLogger().warning(msg); 385 setStatus(Status.CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE); // HTTP 413 386 return new StringRepresentation(msg); 387 } 388 File f = new File(Constants.IO_TMPDIR, fitem.getName()); // NOI18N 389 IOUtils.copy(new AutoCloseInputStream(fitem.getInputStream()), FileUtils.openOutputStream(f)); 390 ContentDAO cdao = new ContentDAO(session, workspace); 391 String href = cdao.store(f, lcode); 392 JSONObject uploadDetails = new JSONObject(); 393 uploadDetails.put("file", href); 394 uploadDetails.put("name", fitem.getName()); 395 uploadDetails.put("size", fsize); 396 uploadDetails.put("type", fitem.getContentType()); 397 details.put("status", "success"); 398 details.put("details", uploadDetails); 399 /* 400 * For now, the "upload script" (http://trac.calenco.com/ticket/93) 401 * will be implemented here, if we find the need for 402 * more operations at upload time, we can think on 403 * complicating the implementation 404 */ 405 // Store classif, if any 406 String cname = fields.get("cname"); 407 Classification classif = new ClassificationDAO(session, workspace).findByName(cname); 408 if (classif != null && !"Attic".equals(cname)) { 409 Association isClassifiedOnto = new Association(Association.IS_CLASSIFIED_ONTO); 410 isClassifiedOnto.setFrom(href); 411 isClassifiedOnto.setTo(classif.href); 412 new AssociationDAO(session, workspace).add(isClassifiedOnto);//adao.add(isClassifiedOnto); 413 } // else ALL_FILES or non-existant classification name, ends up in ALL_FILES 414 /* 415 * From now on, code is very similar to that in the PUT 416 * handler, make sure you synchronize both as needed! 417 */ 418 setAuthor(href, getRequest().getChallengeResponse().getIdentifier(), cdao); 419 updateHeadRelease(); // TODO: Do we REALLY need this now? Deprecate? 420 addOnProcessing(lcode, f, href, cdao); 421 FileUtils.deleteQuietly(f); 422 // Fire r2d2 to update publications depending on the uploaded file 423 new R2D2(workspace, href).start(); 424 } 425 } 426 StringRepresentation rep = new StringRepresentation(String.format("<html><body><textarea>%s</textarea></body></html>", details.toString()), MediaType.TEXT_HTML); 427 rep.setIdentifier(String.format("%s%s", getRequest().getResourceRef().getIdentifier(), Language.INTL.equals(lcode) ? fname : lcode + "/" + fname)); 428 return rep; 429 } catch (Exception e) { 430 String msg = String.format("Cannot upload file: %s", e); 431 throw new ResourceException(Status.SERVER_ERROR_INTERNAL, msg, e); 432 } finally { 433 repoMgr.releaseSessionRW(session); 434 long lstop = System.currentTimeMillis(); 435 getLogger().info(String.format("POST request processed in %2.3f sec.", (lstop - rstart) / 1000.0)); 436 } 437 } 438 439 @Deprecated 440 public Representation postOLD(Representation entity) throws ResourceException { 328 441 String lcode = null; 329 442 if (langOrFile != null) { … … 351 464 for (FileItem fitem: fitems) { 352 465 if (fitem.isFormField()) { 353 String fieldName = fitem.getFieldName(); 354 String fieldValue = fitem.getString(); 355 fields.put(fieldName, fieldValue); 466 fields.put(fitem.getFieldName(), fitem.getString()); 356 467 } 357 468 } … … 406 517 } 407 518 StringRepresentation rep = new StringRepresentation(String.format("<html><body><textarea>%s</textarea></body></html>", details.toString()), MediaType.TEXT_HTML); 408 rep.setIdentifier(String.format("%s%s", getRequest().getResourceRef().getIdentifier(), "".equals(fileName) ? fileName : "/" + fileName));519 rep.setIdentifier(String.format("%s%s", getRequest().getResourceRef().getIdentifier(), Language.INTL.equals(lcode) ? fname : lcode + "/" + fname)); 409 520 return rep; 410 521 } catch (Exception e) { … … 825 936 @Propfind 826 937 public Representation propfind() throws ResourceException { 827 String depth = getHttpHeader("Depth"); // NOI18N828 List<DavProperty> requestedProperties = new ArrayList<DavProperty>();829 try {830 final DomRepresentation reqXML = new DomRepresentation(getRequestEntity());831 getLogger().fine("XML Request Document: " + XMLTools.toXMLString(reqXML.getDocument()));832 Node propNode = reqXML.getNode("/propfind/prop"); // NOI18N833 if (propNode.getNodeType() == Node.ELEMENT_NODE) {834 NodeList props = propNode.getChildNodes();835 for (int i = 0; i < props.getLength(); i++) {836 Node n = props.item(i);837 if (n.getNodeType() == Node.ELEMENT_NODE) {838 Element e = (Element) n;839 DavProperty dp = new DavProperty(e.getTagName());840 requestedProperties.add(dp);841 }842 }843 }844 } catch (Exception e) {845 if (getLogger().getLevel() == Level.FINE) {846 e.printStackTrace();847 }848 getLogger().severe("Bad or no XML in the request body");849 }850 /*851 * The depth handling deviates from RFC4918 (WebDAV standard spec) on852 * purpose. The spec basically states that when clients are lazy enough853 * and don't spec a depth (minimum effort), the server must treat that854 * as if Infinity was specified (maximum effort). This is far from855 * optimum and puts an unneeded load burden on the server. Also,856 * Infinity is 'cut' at a certain reasonable depth level, for the same857 * reason.858 */859 int idepth = 1;860 if ("0".equals(depth)) { // NOI18N861 idepth = 0;862 }863 if ("1".equals(depth)) { // NOI18N864 idepth = 1;865 }866 if ("Infinity".equals(depth)) { // NOI18N867 idepth = 32;868 }869 938 session = null; 870 939 try { 871 DomRepresentation rep = new DomRepresentation(MediaType.APPLICATION_XML); // text/xml is deprecated in RFC 4918 940 session = repoMgr.getSessionRO(); 941 ContentDAO cdao = new ContentDAO(session, workspace); 942 String depth = getHttpHeader("Depth"); // NOI18N 943 List<DavProperty> requestedProperties = new ArrayList<DavProperty>(); 944 try { 945 final DomRepresentation reqXML = new DomRepresentation(getRequestEntity()); 946 getLogger().fine("XML Request Document: " + XMLTools.toXMLString(reqXML.getDocument())); 947 Node propNode = reqXML.getNode("/propfind/prop"); // NOI18N 948 if (propNode.getNodeType() == Node.ELEMENT_NODE) { 949 NodeList props = propNode.getChildNodes(); 950 for (int i = 0; i < props.getLength(); i++) { 951 Node n = props.item(i); 952 if (n.getNodeType() == Node.ELEMENT_NODE) { 953 Element e = (Element) n; 954 DavProperty dp = new DavProperty(e.getTagName()); 955 requestedProperties.add(dp); 956 } 957 } 958 } 959 } catch (Exception e) { 960 if (getLogger().getLevel() == Level.FINE) { 961 e.printStackTrace(); 962 } 963 getLogger().severe("Bad or no XML in the request body"); 964 } 965 /* 966 * Depth handling deviates from RFC4918 (WebDAV spec) on purpose. 967 * The spec basically states that when clients are lazy enough 968 * and don't spec a depth (minimum effort), the server must treat 969 * that as if Infinity was specified (maximum effort). This is far 970 * from optimum and puts an unneded burden on the server. Also, 971 * Infinity is 'cut' at a certain reasonable depth level, for the 972 * same reason. 973 */ 974 int idepth = 1; 975 if ("0".equals(depth)) { 976 idepth = 0; 977 } 978 if ("1".equals(depth)) { 979 idepth = 1; 980 } 981 if ("Infinity".equals(depth)) { 982 idepth = 32; 983 } 984 DomRepresentation rep = new DomRepresentation(MediaType.APPLICATION_XML); // text/xml is deprecated in RFC4918 872 985 Document doc = rep.getDocument(); 873 986 Element multiStatus = doc.createElementNS(DAVNS, "multistatus"); // NOI18N 874 987 doc.appendChild(multiStatus); 875 session = repoMgr.getSessionRO(); 876 ContentDAO dao = new ContentDAO(session, workspace); 877 insertPropfindResponse(path, idepth, requestedProperties, doc, multiStatus, dao); 988 insertPropfindResponse(path, idepth, requestedProperties, doc, multiStatus, cdao); 878 989 doc.normalizeDocument(); 879 990 setStatus(Status.SUCCESS_MULTI_STATUS); // HTTP 207 … … 939 1050 properties.put("resourcetype", resourceType); // NOI18N 940 1051 941 String fname = content.getFname();1052 String cfname = content.getFname(); 942 1053 Element name = doc.createElementNS(DAVNS, "name"); // NOI18N 943 name.appendChild(doc.createTextNode( fname.startsWith("/") ? fname.substring(1) :fname));1054 name.appendChild(doc.createTextNode(cfname.startsWith("/") ? cfname.substring(1) : cfname)); 944 1055 properties.put("name", name); // NOI18N 945 1056 … … 952 1063 953 1064 Element displayName = doc.createElementNS(DAVNS, "displayname"); // NOI18N 954 displayName.appendChild(doc.createTextNode( fname.startsWith("/") ? fname.substring(1) :fname));1065 displayName.appendChild(doc.createTextNode(cfname.startsWith("/") ? cfname.substring(1) : cfname)); 955 1066 properties.put("displayname", displayName); // NOI18N 956 1067 … … 1150 1261 private void addOnProcessing(String lcode, File f, String href, ContentDAO dao) throws Exception { 1151 1262 AddOnsManager aom = AddOnsManager.getInstance(); 1152 String fname = f.getName();1263 //String fname = f.getName(); 1153 1264 try { 1154 1265 AddOn addOn = aom.getAddOn(f); -
trunk/src/com/calenco/resource/workspace/ContentRevhistoryResource.java
r620 r696 33 33 import java.util.List; 34 34 import java.util.Properties; 35 import javax.jcr.RepositoryException;36 35 import org.json.JSONArray; 37 36 import org.json.JSONObject; 38 37 import org.restlet.data.Method; 39 import org.restlet.data.Reference;40 38 import org.restlet.data.Status; 41 39 import org.restlet.ext.json.JsonRepresentation; … … 49 47 * @author fabman 50 48 */ 51 public class ContentRevhistoryResource extends AbstractWorkspaceResource { 52 String langOrFile = null; 53 String lang = null; 54 String file = null; 49 public class ContentRevhistoryResource extends AbstractContentResource { 55 50 56 51 @Override 57 void init() throws RepositoryException { 58 /* Get request params */ 59 langOrFile = Reference.decode((String)getRequest().getAttributes().get("langOrFile")); // NOI18N 60 lang = Reference.decode((String)getRequest().getAttributes().get("lang")); // NOI18N 61 file = Reference.decode((String)getRequest().getAttributes().get("file")); // NOI18N 52 void initResource() throws Exception { 62 53 } 63 54 64 55 @Override 65 boolean can Request(Method method) {56 boolean canPerformRequest(Method method) { 66 57 return Method.GET.equals(method); 67 58 } -
trunk/src/com/calenco/resource/workspace/ContentStylesheetsResource.java
r694 r696 25 25 import com.calenco.Association; 26 26 import com.calenco.Content; 27 import com.calenco.Language;28 27 import com.calenco.addon.AddOnsManager; 29 import com.calenco.addon.Toolchain;30 28 import com.calenco.repository.ContentDAO; 31 29 import com.calenco.repository.dao.AssociationDAO; … … 33 31 import java.util.List; 34 32 import java.util.Set; 35 import javax.jcr.RepositoryException;36 33 import org.json.JSONArray; 37 34 import org.json.JSONObject; … … 50 47 * @author fabman 51 48 */ 52 public class ContentStylesheetsResource extends AbstractWorkspaceResource { 53 String langOrFile = null; 54 String lang = null; 55 String file = null; 56 String fileName = null; 57 String path = null; 49 public class ContentStylesheetsResource extends AbstractContentResource { 58 50 String tchain = null; 59 51 60 52 @Override 61 void init() throws RepositoryException { 62 langOrFile = Reference.decode((String)getRequestAttributes().get("langOrFile")); // NOI18N 63 lang = Reference.decode((String)getRequestAttributes().get("lang")); // NOI18N 64 file = Reference.decode((String)getRequestAttributes().get("file")); // NOI18N 53 void initResource() throws Exception { 65 54 tchain = Reference.decode((String)getRequestAttributes().get("tchain")); // NOI18N 66 if (langOrFile == null && lang == null && file == null) { // Intl folder67 fileName = Language.INTL;68 } else if (langOrFile != null && lang == null && file == null) { // Folder or file of intl folder69 fileName = langOrFile;70 } else if (langOrFile == null && lang != null && file != null) { // File in given lang71 fileName = String.format("%s/%s", lang, file); // NOI18N72 }73 path = String.format("%s/content%s", workspace.href, Language.INTL.equals(fileName) ? fileName : "/" + fileName); // NOI18N74 55 } 75 56 76 57 @Override 77 boolean can Request(Method method) {58 boolean canPerformRequest(Method method) { 78 59 return Method.GET.equals(method); 79 60 } -
trunk/src/com/calenco/resource/workspace/ContentToolchainsResource.java
r694 r696 23 23 package com.calenco.resource.workspace; 24 24 25 import com.calenco.Language;26 25 import com.calenco.addon.AddOnsManager; 27 26 import com.calenco.addon.Toolchain; 28 27 import com.calenco.repository.ContentDAO; 29 28 import java.util.List; 30 import javax.jcr.RepositoryException;31 29 import org.json.JSONArray; 32 30 import org.json.JSONObject; 33 31 import org.restlet.data.Method; 34 import org.restlet.data.Reference;35 32 import org.restlet.data.Status; 36 33 import org.restlet.ext.json.JsonRepresentation; … … 45 42 * @author fabman 46 43 */ 47 public class ContentToolchainsResource extends AbstractWorkspaceResource { 48 String langOrFile = null; 49 String lang = null; 50 String file = null; 51 String fileName = null; 52 String path = null; 44 public class ContentToolchainsResource extends AbstractContentResource { 53 45 54 46 @Override 55 void init() throws RepositoryException { 56 langOrFile = Reference.decode((String)getRequestAttributes().get("langOrFile")); // NOI18N 57 lang = Reference.decode((String)getRequestAttributes().get("lang")); // NOI18N 58 file = Reference.decode((String)getRequestAttributes().get("file")); // NOI18N 59 if (langOrFile == null && lang == null && file == null) { // Intl folder 60 fileName = Language.INTL; 61 } else if (langOrFile != null && lang == null && file == null) { // Folder or file of intl folder 62 fileName = langOrFile; 63 } else if (langOrFile == null && lang != null && file != null) { // File in given lang 64 fileName = String.format("%s/%s", lang, file); // NOI18N 65 } 66 path = String.format("%s/content%s", workspace.href, Language.INTL.equals(fileName) ? fileName : "/" + fileName); // NOI18N 47 void initResource() throws Exception { 67 48 } 68 49 69 50 @Override 70 boolean can Request(Method method) {51 boolean canPerformRequest(Method method) { 71 52 return Method.GET.equals(method); 72 53 } … … 120 101 } 121 102 } 103 122 104 } -
trunk/src/com/calenco/resource/workspace/DepsTreeResource.java
r620 r696 56 56 57 57 @Override 58 void init() throws RepositoryException {58 void init() throws Exception { 59 59 /* Get request params */ 60 60 Form query = getRequest().getResourceRef().getQueryAsForm(); -
trunk/src/com/calenco/resource/workspace/LanguageResource.java
r620 r696 44 44 45 45 @Override 46 void init() throws RepositoryException {46 void init() throws Exception { 47 47 lang = (String)getRequest().getAttributes().get("lang"); // NOI18N 48 48 LanguageDAO dao = new LanguageDAO(session, workspace); -
trunk/src/com/calenco/resource/workspace/LanguagesResource.java
r620 r696 53 53 54 54 @Override 55 void init() throws RepositoryException {55 void init() throws Exception { 56 56 LanguageDAO dao = new LanguageDAO(session, workspace); 57 57 languages = dao.findAll(); -
trunk/src/com/calenco/resource/workspace/PublicationOutputResource.java
r633 r696 55 55 56 56 @Override 57 void init() throws RepositoryException {57 void init() throws Exception { 58 58 oname = Reference.decode((String) getRequest().getAttributes().get("out")); // NOI18N 59 59 } -
trunk/src/com/calenco/resource/workspace/PublicationQueueResource.java
r637 r696 27 27 import com.calenco.transform.PublicationManager; 28 28 import java.util.Collection; 29 import javax.jcr.RepositoryException;30 29 import org.restlet.data.Form; 31 30 import org.restlet.data.Method; … … 51 50 52 51 @Override 53 void init() throws RepositoryException {52 void init() throws Exception { 54 53 pubs = new PublicationDAO(session, workspace).findAll(); 55 54 } -
trunk/src/com/calenco/resource/workspace/PublicationResource.java
r620 r696 59 59 60 60 @Override 61 void init() throws RepositoryException {61 void init() throws Exception { 62 62 pname = Reference.decode((String) getRequest().getAttributes().get("pub")); // NOI18N 63 63 pub = new PublicationDAO(session, workspace).findByName(pname); -
trunk/src/com/calenco/resource/workspace/PublicationsResource.java
r694 r696 39 39 import java.util.Set; 40 40 import javax.jcr.PropertyIterator; 41 import javax.jcr.RepositoryException;42 41 import org.json.JSONArray; 43 42 import org.json.JSONObject; … … 71 70 72 71 @Override 73 void init() throws RepositoryException {72 void init() throws Exception { 74 73 Form query = getRequest().getResourceRef().getQueryAsForm(); 75 74 forFile = query.getFirstValue("file"); // NOI18N -
trunk/src/com/calenco/resource/workspace/ReleaseFileResource.java
r620 r696 30 30 import java.io.FileOutputStream; 31 31 import javax.jcr.PathNotFoundException; 32 import javax.jcr.RepositoryException;33 32 import org.apache.commons.io.FileUtils; 34 33 import org.apache.commons.io.IOUtils; … … 56 55 57 56 @Override 58 void init() throws RepositoryException {57 void init() throws Exception { 59 58 rname = Reference.decode((String)getRequest().getAttributes().get("rel")); // NOI18N 60 59 release = new ReleaseDAO(session, workspace).findByName(rname); -
trunk/src/com/calenco/resource/workspace/ReleaseResource.java
r620 r696 42 42 43 43 @Override 44 void init() throws RepositoryException {44 void init() throws Exception { 45 45 rname = (String) getRequest().getAttributes().get("rel"); // NOI18N 46 46 release = new ReleaseDAO(session, workspace).findByName(rname); -
trunk/src/com/calenco/resource/workspace/ReleasesResource.java
r620 r696 49 49 50 50 @Override 51 void init() throws RepositoryException {51 void init() throws Exception { 52 52 releases = new ReleaseDAO(session, workspace).findAll(); 53 53 } -
trunk/src/com/calenco/resource/workspace/StylesheetsResource.java
r585 r696 26 26 import com.calenco.repository.ContentDAO; 27 27 import java.util.List; 28 import javax.jcr.RepositoryException;29 28 import org.json.JSONArray; 30 29 import org.json.JSONObject; … … 45 44 46 45 @Override 47 void init() throws RepositoryException {46 void init() throws Exception { 48 47 stylesheets = new ContentDAO(session, workspace).findByType(MediaType.APPLICATION_W3C_XSLT.toString()); 49 48 }
Note: See TracChangeset
for help on using the changeset viewer.
