Changeset 677


Ignore:
Timestamp:
02/25/10 19:22:16 (6 months ago)
Author:
fabman
Message:

Deprecated fmt query param for Classifications and Toolchains resources, added fmt as an extension on the URL, so instead of GET .../classifications?fmt=json, now one must say GET .../classifications.json

Location:
trunk/src/com/calenco
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/calenco/CalencoV2App.java

    r667 r677  
    139139        wrouter.attach("/{wksp}/releases/{rel}/{lang}/{file}", ReleaseFileResource.class); 
    140140        wrouter.attach("/{wksp}/classifications", ClassificationsResource.class); 
     141        wrouter.attach("/{wksp}/classifications{.fmt}", ClassificationsResource.class); 
    141142        wrouter.attach("/{wksp}/classifications/{classif}", ClassificationResource.class); 
    142143        wrouter.attach("/{wksp}/associations", AssociationsResource.class); 
     
    153154        srouter.setRoutingMode(Router.MODE_BEST_MATCH); 
    154155        srouter.attach("/toolchains", ToolchainsResource.class); 
     156        srouter.attach("/toolchains{.fmt}", ToolchainsResource.class); 
    155157        srouter.attach("/toolchains/{tchain}", ToolchainResource.class); 
    156158        srouter.attach("/addons/{addon}/{kind}", AddOnResource.class); 
  • trunk/src/com/calenco/resource/system/ToolchainsResource.java

    r585 r677  
    2727import com.calenco.utils.XhtmlHelper; 
    2828import java.io.IOException; 
    29 import java.util.ArrayList; 
    3029import java.util.List; 
    3130import javax.jcr.RepositoryException; 
     
    5352    List<Toolchain> toolchains = null; 
    5453    String cco_xmltype = null; 
    55     String format = null; 
    5654 
    5755    @Override 
     
    5957        Form query = getRequest().getResourceRef().getQueryAsForm(); 
    6058        cco_xmltype = query.getFirstValue("cco_xmltype"); // NOI18N 
    61         format = query.getFirstValue("fmt"); // NOI18N 
    6259        AddOnsManager aom = AddOnsManager.getInstance(); 
    6360        if (cco_xmltype == null) { 
     
    7168            } 
    7269        } 
    73         /* Add variants, for content negotiation */ 
    74         List<Variant> variants = getVariants(); 
    75         if (variants == null) { 
    76             variants = new ArrayList<Variant>(); 
    77         } 
    78         variants.add(new Variant(MediaType.TEXT_XML)); 
    79         variants.add(new Variant(MediaType.APPLICATION_XML)); 
    80         variants.add(new Variant(MediaType.APPLICATION_JSON)); 
    81         variants.add(new Variant(MediaType.TEXT_HTML)); 
    82         variants.add(new Variant(MediaType.APPLICATION_XHTML)); 
    8370    } 
    8471 
     
    9178    @Override 
    9279    public Representation get(Variant variant) throws ResourceException { 
    93         // Content negotiation, prioritizing the optional 'fmt' query param 
    94         MediaType mt = variant.getMediaType(); 
    95         MediaType fmt = null; 
    96         if ("xml".equals(format)) { 
    97             fmt = MediaType.TEXT_XML; 
    98         } else if ("html".equals(format)) { 
    99             fmt = MediaType.TEXT_HTML; 
    100         } else if ("json".equals(format)) { 
    101             fmt = MediaType.APPLICATION_JSON; 
    102         } // else ignore bogus fmt param value 
    103         if (fmt != null) { 
    104             mt = fmt; // Override preferred variant (HTTP header: Accept) 
     80        String fmt = (String) getRequestAttributes().get(".fmt"); // NOI18N 
     81        if (fmt == null) { 
     82            String accept = getHttpHeader("Accept"); // NOI18N 
     83            MediaType mt = variant.getMediaType(); 
     84            if (accept != null) { 
     85                mt = new MediaType(accept); 
     86            } 
     87            if (MediaType.TEXT_HTML.equals(mt) || MediaType.APPLICATION_XHTML.equals(mt)) { 
     88                fmt = ".html"; // NOI18N 
     89            } else if (MediaType.APPLICATION_JSON.equals(mt)) { 
     90                fmt = ".json"; // NOI18N 
     91            } 
    10592        } 
    106         if (MediaType.APPLICATION_JSON.equals(mt)) { 
     93        if (".json".equals(fmt)) { // NOI18N 
    10794            return toJSON(); 
    108         } else if (MediaType.TEXT_HTML.equals(mt) || MediaType.APPLICATION_XHTML.equals(mt)) { 
     95        } else if (".html".equals(fmt)) { // NOI18N 
    10996            return toXHTML(); 
    110         } else { // Return XML by default 
    111             return toXML(); 
     97        } else { 
     98            return toXML(); // Preferred representation 
    11299        } 
    113100    } 
  • trunk/src/com/calenco/resource/workspace/ClassificationsResource.java

    r622 r677  
    2929import com.calenco.utils.XhtmlHelper; 
    3030import java.io.IOException; 
    31 import java.util.ArrayList; 
    3231import java.util.HashSet; 
    33 import java.util.List; 
    3432import java.util.Set; 
    3533import javax.jcr.RepositoryException; 
     
    6058    public static final String ALL_FILES = "ALL_FILES"; 
    6159    Set<Classification> classifications = null; 
    62     String format = null; 
    6360 
    6461    @Override 
    6562    void init() throws RepositoryException { 
    66         /* Get format parameter from the request */ 
    67         Form query = getRequest().getResourceRef().getQueryAsForm(); 
    68         format = query.getFirstValue("fmt"); // NOI18N 
    69         /* Get classifications */ 
    7063        ClassificationDAO dao = new ClassificationDAO(session, workspace); 
    7164        classifications = dao.findAll(); 
    72         if (Method.GET.equals(getMethod())) { 
    73             /* Add variants, for content negotiation */ 
    74             List<Variant> variants = getVariants(); 
    75             if (variants == null) { 
    76                 variants = new ArrayList<Variant>(); 
    77             } 
    78             variants.add(new Variant(MediaType.TEXT_XML)); 
    79             variants.add(new Variant(MediaType.APPLICATION_XML)); 
    80             variants.add(new Variant(MediaType.APPLICATION_JSON)); 
    81             variants.add(new Variant(MediaType.TEXT_HTML)); 
    82             variants.add(new Variant(MediaType.APPLICATION_XHTML)); 
    83         } 
    8465    } 
    8566 
     
    153134    @Override 
    154135    public Representation get(Variant variant) throws ResourceException { 
    155         // Content negotiation, prioritizing the optional 'fmt' query param 
    156         MediaType mt = variant.getMediaType(); 
    157         MediaType fmt = null; 
    158         if ("xml".equals(format)) { 
    159             fmt = MediaType.TEXT_XML; 
    160         } else if ("html".equals(format)) { 
    161             fmt = MediaType.TEXT_HTML; 
    162         } else if ("json".equals(format)) { 
    163             fmt = MediaType.APPLICATION_JSON; 
    164         } // else ignore bogus fmt param value 
    165         if (fmt != null) { 
    166             mt = fmt; // Override preferred variant (HTTP header: Accept) 
    167         } 
    168         if (MediaType.APPLICATION_JSON.equals(mt)) { 
     136        String fmt = (String) getRequestAttributes().get(".fmt"); // NOI18N 
     137        if (fmt == null) { 
     138            String accept = getHttpHeader("Accept"); // NOI18N 
     139            MediaType mt = variant.getMediaType(); 
     140            if (accept != null) { 
     141                mt = new MediaType(accept); 
     142            } 
     143            if (MediaType.TEXT_HTML.equals(mt) || MediaType.APPLICATION_XHTML.equals(mt)) { 
     144                fmt = ".html"; // NOI18N 
     145            } else if (MediaType.APPLICATION_JSON.equals(mt)) { 
     146                fmt = ".json"; // NOI18N 
     147            } 
     148        } 
     149        if (".json".equals(fmt)) { // NOI18N 
    169150            return toJSON(); 
    170         } else if (MediaType.TEXT_HTML.equals(mt) || MediaType.APPLICATION_XHTML.equals(mt)) { 
     151        } else if (".html".equals(fmt)) { // NOI18N 
    171152            return toXHTML(); 
    172         } else { // Return XML by default 
    173             return toXML(); 
     153        } else { 
     154            return toXML(); // Preferred representation 
    174155        } 
    175156    } 
  • trunk/src/com/calenco/staticres/workspace-html.ftl

    r676 r677  
    3434            dojo.require("dojo.parser"); 
    3535            dojo.require("dojo.data.ItemFileReadStore"); 
    36             dojo.require("dojo.data.ItemFileWriteStore"); 
    3736            dojo.require("dojo.io.iframe"); 
    3837            dojo.require("dijit.Toolbar"); 
     
    167166                }); 
    168167                /* Fill TC list */ 
    169                 var tcStore = new dojo.data.ItemFileReadStore({url: "/system/toolchains?fmt=json"}); 
     168                var tcStore = new dojo.data.ItemFileReadStore({url: "/system/toolchains.json"}); 
    170169                tcStore.fetch({ 
    171170                    query: {}, start: 0, count: 1, onComplete: function(res) { 
     
    998997                dojo.query("#filesMenuBar").style("display", "none"); 
    999998                dojo.query("#filesTree").style("display", "none"); 
    1000                 cdstore = new dojo.data.ItemFileWriteStore({url: "/workspaces/${wksp}/classifications?fmt=json"}); 
     999                cdstore = new dojo.data.ItemFileReadStore({url: "/workspaces/${wksp}/classifications.json"}); 
    10011000                cmdl = new dijit.tree.ForestStoreModel({ 
    10021001                    store: cdstore, 
Note: See TracChangeset for help on using the changeset viewer.