Changeset 696


Ignore:
Timestamp:
03/09/10 13:10:11 (6 months ago)
Author:
fabman
Message:

tkt #185 done
Refactoring of resource classes
KNOWN_ISSUES updated

Location:
trunk
Files:
1 added
35 edited

Legend:

Unmodified
Added
Removed
  • trunk/KNOWN_ISSUES

    r657 r696  
    88- There's some problems with the UI on Internet Explorer 7/8, we're working hard 
    99 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  
    2626import com.calenco.repository.PooledRepoManager; 
    2727import com.calenco.repository.dao.UserDAO; 
    28 import javax.jcr.RepositoryException; 
    2928import javax.jcr.Session; 
    3029import org.restlet.data.Form; 
     
    6665            init(); 
    6766            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            } 
    7175        } finally { 
    7276            repoMgr.releaseSessionRO(session); 
     
    97101    } 
    98102 
    99     abstract void init() throws RepositoryException; 
     103    abstract void init() throws Exception; 
    100104 
    101105    abstract boolean canRequest(Method method); 
  • trunk/src/com/calenco/resource/system/AddOnResource.java

    r585 r696  
    2626import com.calenco.addon.AddOnsManager; 
    2727import java.io.File; 
    28 import javax.jcr.RepositoryException; 
    2928import org.apache.commons.io.FilenameUtils; 
    3029import org.restlet.data.MediaType; 
     
    5352 
    5453    @Override 
    55     void init() throws RepositoryException { 
     54    void init() throws Exception { 
    5655        kind = Reference.decode((String) getRequest().getAttributes().get("kind")); // NOI18N 
    5756        addonName = Reference.decode((String) getRequest().getAttributes().get("addon")); // NOI18N 
  • trunk/src/com/calenco/resource/system/AdminPasswordResource.java

    r679 r696  
    2323package com.calenco.resource.system; 
    2424 
    25 import com.calenco.CalencoV2; 
    2625import com.calenco.security.SUSecurityManager; 
    27 import javax.jcr.RepositoryException; 
    2826import org.restlet.data.Form; 
    2927import org.restlet.data.Method; 
     
    4139 
    4240    @Override 
    43     void init() throws RepositoryException { 
     41    void init() throws Exception { 
    4442    } 
    4543 
  • trunk/src/com/calenco/resource/system/ControlResource.java

    r585 r696  
    2424 
    2525import com.calenco.CalencoV2App; 
    26 import javax.jcr.RepositoryException; 
    2726import org.restlet.data.Method; 
    2827import org.restlet.data.Status; 
     
    4140 
    4241    @Override 
    43     void init() throws RepositoryException { 
     42    void init() throws Exception { 
    4443        String host = getRequest().getClientInfo().getAddress(); 
    4544        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  
    2626import com.calenco.repository.dao.LanguageDAO; 
    2727import java.util.Set; 
    28 import javax.jcr.RepositoryException; 
    2928import org.json.JSONArray; 
    3029import org.json.JSONObject; 
     
    4847 
    4948    @Override 
    50     void init() throws RepositoryException { 
     49    void init() throws Exception { 
    5150        LanguageDAO dao = new LanguageDAO(session); 
    5251        languages = dao.findAll(); 
  • trunk/src/com/calenco/resource/system/RepositoryResource.java

    r585 r696  
    2727import java.util.HashMap; 
    2828import java.util.Map; 
    29 import javax.jcr.RepositoryException; 
    3029import org.restlet.data.CharacterSet; 
    3130import org.restlet.data.MediaType; 
     
    4948 
    5049    @Override 
    51     void init() throws RepositoryException { 
    52         /* Do nothing */ 
     50    void init() throws Exception { 
    5351    } 
    5452 
  • trunk/src/com/calenco/resource/system/ToolchainResource.java

    r585 r696  
    2727import com.calenco.utils.XhtmlHelper; 
    2828import java.io.IOException; 
    29 import javax.jcr.RepositoryException; 
    3029import org.restlet.data.MediaType; 
    3130import org.restlet.data.Method; 
     
    4948 
    5049    @Override 
    51     void init() throws RepositoryException { 
     50    void init() throws Exception { 
    5251        tcname = Reference.decode((String) getRequest().getAttributes().get("tchain")); // NOI18N 
    5352        tchain = AddOnsManager.getInstance().getToolchain(tcname); 
    5453        if (tchain == null) { 
    5554            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); 
    5756        } 
    5857    } 
  • trunk/src/com/calenco/resource/system/ToolchainsResource.java

    r694 r696  
    2828import java.io.IOException; 
    2929import java.util.List; 
    30 import javax.jcr.RepositoryException; 
    3130import org.json.JSONArray; 
    3231import org.json.JSONObject; 
     
    5453 
    5554    @Override 
    56     void init() throws RepositoryException { 
     55    void init() throws Exception { 
    5756        Form query = getRequest().getResourceRef().getQueryAsForm(); 
    5857        cco_xmltype = query.getFirstValue("cco_xmltype"); // NOI18N 
  • trunk/src/com/calenco/resource/system/UserResource.java

    r637 r696  
    2929import com.calenco.security.JcrVerifier; 
    3030import com.calenco.utils.XhtmlHelper; 
    31 import javax.jcr.RepositoryException; 
    3231import org.restlet.data.Form; 
    3332import org.restlet.data.MediaType; 
     
    5352 
    5453    @Override 
    55     void init() throws RepositoryException { 
     54    void init() throws Exception { 
    5655        email = (String) getRequest().getAttributes().get("user"); // NOI18N 
    5756        String identifier = getRequest().getChallengeResponse().getIdentifier(); 
  • trunk/src/com/calenco/resource/system/UserRightsResource.java

    r637 r696  
    3232import java.util.List; 
    3333import java.util.Set; 
    34 import javax.jcr.RepositoryException; 
    3534import org.json.JSONArray; 
    3635import org.json.JSONObject; 
     
    6059 
    6160    @Override 
    62     void init() throws RepositoryException { 
     61    void init() throws Exception { 
    6362        email = Reference.decode((String)getRequest().getAttributes().get("user")); // NOI18N 
    6463        if (email == null || "".equals(email)) { 
  • trunk/src/com/calenco/resource/system/UsersResource.java

    r631 r696  
    3232import com.calenco.utils.XhtmlHelper; 
    3333import java.util.Set; 
    34 import javax.jcr.RepositoryException; 
    3534import org.json.JSONArray; 
    3635import org.json.JSONObject; 
     
    5756 
    5857    @Override 
    59     void init() throws RepositoryException { 
     58    void init() throws Exception { 
    6059        users = new UserDAO(session).findAll(); 
    6160    } 
  • trunk/src/com/calenco/resource/system/WorkspaceResource.java

    r637 r696  
    6060 
    6161    @Override 
    62     void init() throws RepositoryException { 
     62    void init() throws Exception { 
    6363        wksp = Reference.decode((String)getRequest().getAttributes().get("wksp")); // NOI18N 
    6464        workspace = new WorkspaceDAO(session).findByName(wksp); 
  • trunk/src/com/calenco/resource/system/WorkspacesResource.java

    r681 r696  
    3737import java.util.Set; 
    3838import java.util.TreeSet; 
    39 import javax.jcr.RepositoryException; 
    4039import org.json.JSONArray; 
    4140import org.json.JSONObject; 
     
    6463 
    6564    @Override 
    66     void init() throws RepositoryException { 
     65    void init() throws Exception { 
    6766        WorkspaceDAO dao = new WorkspaceDAO(session); 
    6867        if (isSysAdmin) { 
  • trunk/src/com/calenco/resource/workspace/AbstractWorkspaceResource.java

    r631 r696  
    3232import java.io.UnsupportedEncodingException; 
    3333import java.net.URLEncoder; 
    34 import javax.jcr.RepositoryException; 
    3534import javax.jcr.Session; 
    3635import org.restlet.Request; 
     
    9392                throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, msg); 
    9493            } 
     94            Method method = req.getMethod(); 
    9595            if (!user.isSysAdmin) { 
    9696                /* Check user can access (use) workspace */ 
     
    101101                    throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, msg); 
    102102                } 
    103                 Method method = req.getMethod(); 
    104103                if (user.isPubUser() && Method.GET.equals(method) && req.getResourceRef().getPath().indexOf("/content") != -1) { 
    105104                    String host = req.getClientInfo().getAddress(); 
     
    122121                 * init() 
    123122                 */ 
    124                 if (!canRequest(req.getMethod())) { 
     123                if (!canRequest(method)) { 
    125124                    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); 
    126125                    getLogger().warning(msg); 
     
    129128            } 
    130129            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            } 
    134138        } finally { 
    135139            repoMgr.releaseSessionRO(session); 
     
    202206     * Concrete resource classes extending this one must implement this method 
    203207     * to perform resource-specific initialization. If there's a problem 
    204      * initializing the resource the implementation must call setStatus() with 
    205      * the proper HTTP status code, and throw an Exception with a human-readable 
     208     * initializing the resource the implementation must throw a 
     209     * ResourceException with proper HTTP status code and a human-readable 
    206210     * error message. 
    207211     * 
    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; 
    211216 
    212217    /** 
  • trunk/src/com/calenco/resource/workspace/AssociationResource.java

    r620 r696  
    2626import com.calenco.repository.dao.AssociationDAO; 
    2727import java.io.IOException; 
    28 import javax.jcr.RepositoryException; 
    2928import org.restlet.data.MediaType; 
    3029import org.restlet.data.Method; 
     
    4645 
    4746    @Override 
    48     void init() throws RepositoryException { 
     47    void init() throws Exception { 
    4948        AssociationDAO adao = new AssociationDAO(session, workspace); 
    5049        aname = Reference.decode((String)getRequest().getAttributes().get("assoc")); // NOI18N 
  • trunk/src/com/calenco/resource/workspace/AssociationsResource.java

    r620 r696  
    6969 
    7070    @Override 
    71     void init() throws RepositoryException { 
     71    void init() throws Exception { 
    7272        /* Get Query Params */ 
    7373        Form query = getRequest().getResourceRef().getQueryAsForm(); 
  • trunk/src/com/calenco/resource/workspace/ClassificationResource.java

    r639 r696  
    3737import java.util.Set; 
    3838import java.util.TreeSet; 
    39 import javax.jcr.RepositoryException; 
    4039import org.json.JSONArray; 
    4140import org.json.JSONException; 
     
    7069 
    7170    @Override 
    72     void init() throws RepositoryException { 
     71    void init() throws Exception { 
    7372        /* Get format parameter from the request */ 
    7473        Form query = getRequest().getResourceRef().getQueryAsForm(); 
  • trunk/src/com/calenco/resource/workspace/ClassificationsResource.java

    r694 r696  
    6060 
    6161    @Override 
    62     void init() throws RepositoryException { 
     62    void init() throws Exception { 
    6363        ClassificationDAO dao = new ClassificationDAO(session, workspace); 
    6464        classifications = dao.findAll(); 
  • trunk/src/com/calenco/resource/workspace/ContentPropertiesResource.java

    r637 r696  
    5959 * @author fabman 
    6060 */ 
    61 public class ContentPropertiesResource extends AbstractWorkspaceResource { 
    62     String langOrFile = null; 
    63     String lang = null; 
    64     String file = null; 
     61public class ContentPropertiesResource extends AbstractContentResource { 
    6562    String pname = null; 
    6663    String pattern = null; 
    6764 
    6865    @Override 
    69     void init() throws RepositoryException { 
     66    void initResource() throws Exception { 
    7067        /* Get request params */ 
    7168        Map<String, Object> requestParams = getRequest().getAttributes(); 
    72         langOrFile = Reference.decode((String)requestParams.get("langOrFile")); // NOI18N 
    73         lang = Reference.decode((String)requestParams.get("lang")); // NOI18N 
    74         file = Reference.decode((String)requestParams.get("file")); // NOI18N 
    7569        pname = Reference.decode((String)requestParams.get("pname")); // NOI18N 
    7670        Form query = getRequest().getResourceRef().getQueryAsForm(); 
     
    8276 
    8377    @Override 
    84     boolean canRequest(Method method) { 
     78    boolean canPerformRequest(Method method) { 
    8579        if (pname == null || "".equals(pname)) { 
    8680            return Method.GET.equals(method); 
  • trunk/src/com/calenco/resource/workspace/ContentResource.java

    r695 r696  
    112112 * @author fabman 
    113113 */ 
    114 public class ContentResource extends AbstractWorkspaceResource { 
     114public class ContentResource extends AbstractContentResource { 
    115115    final static String DAVNS = Constants.DAVNS; 
    116     String langOrFile = null; 
    117     String lang = null; 
    118     String file = null; 
    119116    String rev = null; // Means get the HEAD revision (JCR baseVersion) 
    120117    // If true, try to provide the means to get a savedlg file (different content disposition, should pop up "Save as" browser dialog) 
     
    122119    MetadataService mds = null; 
    123120    int contentPathIndex = -1; 
    124     String path = null; 
    125     String fileName = null; 
    126121    File tempFile = null; 
    127122 
    128123    @Override 
    129     void init() throws RepositoryException { 
     124    void initResource() throws Exception { 
    130125        contentPathIndex = ContentDAO.getContentPath(workspace).length() + 1; 
    131126        /* Get request params */ 
    132         langOrFile = Reference.decode((String)getRequest().getAttributes().get("langOrFile")); // NOI18N 
    133         lang = Reference.decode((String)getRequest().getAttributes().get("lang")); // NOI18N 
    134         file = Reference.decode((String)getRequest().getAttributes().get("file")); // NOI18N 
    135127        Form query = getRequest().getResourceRef().getQueryAsForm(); 
    136128        rev = query.getFirstValue("rev"); // NOI18N 
     
    165157        getAllowedMethods().add(Method.DELETE); 
    166158        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); 
    175161        setOnSent(new CleanupTempFile()); 
    176162    } 
    177163 
    178164    @Override 
    179     boolean canRequest(Method method) { 
     165    boolean canPerformRequest(Method method) { 
    180166        return 
    181167                Method.OPTIONS.equals(method) || 
     
    187173                Method.POST.equals(method) || 
    188174                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); 
    190176    } 
    191177 
     
    193179    @Override 
    194180    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 { 
    195227        session = null; 
    196228        try { 
     
    281313            return new StringRepresentation(msg); 
    282314        } 
    283         String lcode = (langOrFile == null ? lang : Language.INTL); 
    284         String fname = (langOrFile == null ? file : langOrFile); 
    285315        session = null; 
    286316        try { 
     
    297327            File f = new File(Constants.IO_TMPDIR, fname); 
    298328            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); 
    301331            /* 
    302332             * From now on, code is very similar to that in the POST handler, 
    303333             * make sure you synchronize both as needed! 
    304334             */ 
    305             setAuthor(href, getRequest().getChallengeResponse().getIdentifier(), dao); 
     335            setAuthor(href, getRequest().getChallengeResponse().getIdentifier(), cdao); 
    306336            updateHeadRelease(); // TODO: Do we REALLY need this now? Deprecate? 
    307             addOnProcessing(lcode, f, href, dao); 
     337            addOnProcessing(lcode, f, href, cdao); 
    308338            FileUtils.deleteQuietly(f); 
    309339            // Fire r2d2 to update publications depending on the uploaded file 
     
    326356    @Override 
    327357    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 { 
    328441        String lcode = null; 
    329442        if (langOrFile != null) { 
     
    351464                for (FileItem fitem: fitems) { 
    352465                    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()); 
    356467                    } 
    357468                } 
     
    406517                } 
    407518                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)); 
    409520                return rep; 
    410521            } catch (Exception e) { 
     
    825936    @Propfind 
    826937    public Representation propfind() throws ResourceException { 
    827         String depth = getHttpHeader("Depth"); // NOI18N 
    828         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"); // NOI18N 
    833             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) on 
    852          * purpose. The spec basically states that when clients are lazy enough 
    853          * and don't spec a depth (minimum effort), the server must treat that 
    854          * as if Infinity was specified (maximum effort). This is far from 
    855          * optimum and puts an unneeded load burden on the server. Also, 
    856          * Infinity is 'cut' at a certain reasonable depth level, for the same 
    857          * reason. 
    858          */ 
    859         int idepth = 1; 
    860         if ("0".equals(depth)) { // NOI18N 
    861             idepth = 0; 
    862         } 
    863         if ("1".equals(depth)) { // NOI18N 
    864             idepth = 1; 
    865         } 
    866         if ("Infinity".equals(depth)) { // NOI18N 
    867             idepth = 32; 
    868         } 
    869938        session = null; 
    870939        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 
    872985            Document doc = rep.getDocument(); 
    873986            Element multiStatus = doc.createElementNS(DAVNS, "multistatus"); // NOI18N 
    874987            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); 
    878989            doc.normalizeDocument(); 
    879990            setStatus(Status.SUCCESS_MULTI_STATUS); // HTTP 207 
     
    9391050                properties.put("resourcetype", resourceType); // NOI18N 
    9401051 
    941                 String fname = content.getFname(); 
     1052                String cfname = content.getFname(); 
    9421053                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)); 
    9441055                properties.put("name", name); // NOI18N 
    9451056 
     
    9521063 
    9531064                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)); 
    9551066                properties.put("displayname", displayName); // NOI18N 
    9561067 
     
    11501261    private void addOnProcessing(String lcode, File f, String href, ContentDAO dao) throws Exception { 
    11511262        AddOnsManager aom = AddOnsManager.getInstance(); 
    1152         String fname = f.getName(); 
     1263        //String fname = f.getName(); 
    11531264        try { 
    11541265            AddOn addOn = aom.getAddOn(f); 
  • trunk/src/com/calenco/resource/workspace/ContentRevhistoryResource.java

    r620 r696  
    3333import java.util.List; 
    3434import java.util.Properties; 
    35 import javax.jcr.RepositoryException; 
    3635import org.json.JSONArray; 
    3736import org.json.JSONObject; 
    3837import org.restlet.data.Method; 
    39 import org.restlet.data.Reference; 
    4038import org.restlet.data.Status; 
    4139import org.restlet.ext.json.JsonRepresentation; 
     
    4947 * @author fabman 
    5048 */ 
    51 public class ContentRevhistoryResource extends AbstractWorkspaceResource { 
    52     String langOrFile = null; 
    53     String lang = null; 
    54     String file = null; 
     49public class ContentRevhistoryResource extends AbstractContentResource { 
    5550 
    5651    @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 { 
    6253    } 
    6354 
    6455    @Override 
    65     boolean canRequest(Method method) { 
     56    boolean canPerformRequest(Method method) { 
    6657        return Method.GET.equals(method); 
    6758    } 
  • trunk/src/com/calenco/resource/workspace/ContentStylesheetsResource.java

    r694 r696  
    2525import com.calenco.Association; 
    2626import com.calenco.Content; 
    27 import com.calenco.Language; 
    2827import com.calenco.addon.AddOnsManager; 
    29 import com.calenco.addon.Toolchain; 
    3028import com.calenco.repository.ContentDAO; 
    3129import com.calenco.repository.dao.AssociationDAO; 
     
    3331import java.util.List; 
    3432import java.util.Set; 
    35 import javax.jcr.RepositoryException; 
    3633import org.json.JSONArray; 
    3734import org.json.JSONObject; 
     
    5047 * @author fabman 
    5148 */ 
    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; 
     49public class ContentStylesheetsResource extends AbstractContentResource { 
    5850    String tchain = null; 
    5951 
    6052    @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 { 
    6554        tchain = Reference.decode((String)getRequestAttributes().get("tchain")); // NOI18N 
    66         if (langOrFile == null && lang == null && file == null) { // Intl folder 
    67             fileName = Language.INTL; 
    68         } else if (langOrFile != null && lang == null && file == null) { // Folder or file of intl folder 
    69             fileName = langOrFile; 
    70         } else if (langOrFile == null && lang != null && file != null) { // File in given lang 
    71             fileName = String.format("%s/%s", lang, file); // NOI18N 
    72         } 
    73         path = String.format("%s/content%s", workspace.href, Language.INTL.equals(fileName) ? fileName : "/" + fileName); // NOI18N 
    7455    } 
    7556 
    7657    @Override 
    77     boolean canRequest(Method method) { 
     58    boolean canPerformRequest(Method method) { 
    7859        return Method.GET.equals(method); 
    7960    } 
  • trunk/src/com/calenco/resource/workspace/ContentToolchainsResource.java

    r694 r696  
    2323package com.calenco.resource.workspace; 
    2424 
    25 import com.calenco.Language; 
    2625import com.calenco.addon.AddOnsManager; 
    2726import com.calenco.addon.Toolchain; 
    2827import com.calenco.repository.ContentDAO; 
    2928import java.util.List; 
    30 import javax.jcr.RepositoryException; 
    3129import org.json.JSONArray; 
    3230import org.json.JSONObject; 
    3331import org.restlet.data.Method; 
    34 import org.restlet.data.Reference; 
    3532import org.restlet.data.Status; 
    3633import org.restlet.ext.json.JsonRepresentation; 
     
    4542 * @author fabman 
    4643 */ 
    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; 
     44public class ContentToolchainsResource extends AbstractContentResource { 
    5345 
    5446    @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 { 
    6748    } 
    6849 
    6950    @Override 
    70     boolean canRequest(Method method) { 
     51    boolean canPerformRequest(Method method) { 
    7152        return Method.GET.equals(method); 
    7253    } 
     
    120101        } 
    121102    } 
     103 
    122104} 
  • trunk/src/com/calenco/resource/workspace/DepsTreeResource.java

    r620 r696  
    5656 
    5757    @Override 
    58     void init() throws RepositoryException { 
     58    void init() throws Exception { 
    5959        /* Get request params */ 
    6060        Form query = getRequest().getResourceRef().getQueryAsForm(); 
  • trunk/src/com/calenco/resource/workspace/LanguageResource.java

    r620 r696  
    4444 
    4545    @Override 
    46     void init() throws RepositoryException { 
     46    void init() throws Exception { 
    4747        lang = (String)getRequest().getAttributes().get("lang"); // NOI18N 
    4848        LanguageDAO dao = new LanguageDAO(session, workspace); 
  • trunk/src/com/calenco/resource/workspace/LanguagesResource.java

    r620 r696  
    5353 
    5454    @Override 
    55     void init() throws RepositoryException { 
     55    void init() throws Exception { 
    5656        LanguageDAO dao = new LanguageDAO(session, workspace); 
    5757        languages = dao.findAll(); 
  • trunk/src/com/calenco/resource/workspace/PublicationOutputResource.java

    r633 r696  
    5555 
    5656    @Override 
    57     void init() throws RepositoryException { 
     57    void init() throws Exception { 
    5858        oname = Reference.decode((String) getRequest().getAttributes().get("out")); // NOI18N 
    5959    } 
  • trunk/src/com/calenco/resource/workspace/PublicationQueueResource.java

    r637 r696  
    2727import com.calenco.transform.PublicationManager; 
    2828import java.util.Collection; 
    29 import javax.jcr.RepositoryException; 
    3029import org.restlet.data.Form; 
    3130import org.restlet.data.Method; 
     
    5150 
    5251    @Override 
    53     void init() throws RepositoryException { 
     52    void init() throws Exception { 
    5453        pubs = new PublicationDAO(session, workspace).findAll(); 
    5554    } 
  • trunk/src/com/calenco/resource/workspace/PublicationResource.java

    r620 r696  
    5959 
    6060    @Override 
    61     void init() throws RepositoryException { 
     61    void init() throws Exception { 
    6262        pname = Reference.decode((String) getRequest().getAttributes().get("pub")); // NOI18N 
    6363        pub = new PublicationDAO(session, workspace).findByName(pname); 
  • trunk/src/com/calenco/resource/workspace/PublicationsResource.java

    r694 r696  
    3939import java.util.Set; 
    4040import javax.jcr.PropertyIterator; 
    41 import javax.jcr.RepositoryException; 
    4241import org.json.JSONArray; 
    4342import org.json.JSONObject; 
     
    7170 
    7271    @Override 
    73     void init() throws RepositoryException { 
     72    void init() throws Exception { 
    7473        Form query = getRequest().getResourceRef().getQueryAsForm(); 
    7574        forFile = query.getFirstValue("file"); // NOI18N 
  • trunk/src/com/calenco/resource/workspace/ReleaseFileResource.java

    r620 r696  
    3030import java.io.FileOutputStream; 
    3131import javax.jcr.PathNotFoundException; 
    32 import javax.jcr.RepositoryException; 
    3332import org.apache.commons.io.FileUtils; 
    3433import org.apache.commons.io.IOUtils; 
     
    5655 
    5756    @Override 
    58     void init() throws RepositoryException { 
     57    void init() throws Exception { 
    5958        rname = Reference.decode((String)getRequest().getAttributes().get("rel")); // NOI18N 
    6059        release = new ReleaseDAO(session, workspace).findByName(rname); 
  • trunk/src/com/calenco/resource/workspace/ReleaseResource.java

    r620 r696  
    4242 
    4343    @Override 
    44     void init() throws RepositoryException { 
     44    void init() throws Exception { 
    4545        rname = (String) getRequest().getAttributes().get("rel"); // NOI18N 
    4646        release = new ReleaseDAO(session, workspace).findByName(rname); 
  • trunk/src/com/calenco/resource/workspace/ReleasesResource.java

    r620 r696  
    4949 
    5050    @Override 
    51     void init() throws RepositoryException { 
     51    void init() throws Exception { 
    5252        releases = new ReleaseDAO(session, workspace).findAll(); 
    5353    } 
  • trunk/src/com/calenco/resource/workspace/StylesheetsResource.java

    r585 r696  
    2626import com.calenco.repository.ContentDAO; 
    2727import java.util.List; 
    28 import javax.jcr.RepositoryException; 
    2928import org.json.JSONArray; 
    3029import org.json.JSONObject; 
     
    4544 
    4645    @Override 
    47     void init() throws RepositoryException { 
     46    void init() throws Exception { 
    4847        stylesheets = new ContentDAO(session, workspace).findByType(MediaType.APPLICATION_W3C_XSLT.toString()); 
    4948    } 
Note: See TracChangeset for help on using the changeset viewer.