Changeset 677
- Timestamp:
- 02/25/10 19:22:16 (6 months ago)
- Location:
- trunk/src/com/calenco
- Files:
-
- 4 edited
-
CalencoV2App.java (modified) (2 diffs)
-
resource/system/ToolchainsResource.java (modified) (5 diffs)
-
resource/workspace/ClassificationsResource.java (modified) (3 diffs)
-
staticres/workspace-html.ftl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/calenco/CalencoV2App.java
r667 r677 139 139 wrouter.attach("/{wksp}/releases/{rel}/{lang}/{file}", ReleaseFileResource.class); 140 140 wrouter.attach("/{wksp}/classifications", ClassificationsResource.class); 141 wrouter.attach("/{wksp}/classifications{.fmt}", ClassificationsResource.class); 141 142 wrouter.attach("/{wksp}/classifications/{classif}", ClassificationResource.class); 142 143 wrouter.attach("/{wksp}/associations", AssociationsResource.class); … … 153 154 srouter.setRoutingMode(Router.MODE_BEST_MATCH); 154 155 srouter.attach("/toolchains", ToolchainsResource.class); 156 srouter.attach("/toolchains{.fmt}", ToolchainsResource.class); 155 157 srouter.attach("/toolchains/{tchain}", ToolchainResource.class); 156 158 srouter.attach("/addons/{addon}/{kind}", AddOnResource.class); -
trunk/src/com/calenco/resource/system/ToolchainsResource.java
r585 r677 27 27 import com.calenco.utils.XhtmlHelper; 28 28 import java.io.IOException; 29 import java.util.ArrayList;30 29 import java.util.List; 31 30 import javax.jcr.RepositoryException; … … 53 52 List<Toolchain> toolchains = null; 54 53 String cco_xmltype = null; 55 String format = null;56 54 57 55 @Override … … 59 57 Form query = getRequest().getResourceRef().getQueryAsForm(); 60 58 cco_xmltype = query.getFirstValue("cco_xmltype"); // NOI18N 61 format = query.getFirstValue("fmt"); // NOI18N62 59 AddOnsManager aom = AddOnsManager.getInstance(); 63 60 if (cco_xmltype == null) { … … 71 68 } 72 69 } 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 70 } 84 71 … … 91 78 @Override 92 79 public Representation get(Variant variant) throws ResourceException { 93 // Content negotiation, prioritizing the optional 'fmt' query param94 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 value103 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 } 105 92 } 106 if ( MediaType.APPLICATION_JSON.equals(mt)) {93 if (".json".equals(fmt)) { // NOI18N 107 94 return toJSON(); 108 } else if ( MediaType.TEXT_HTML.equals(mt) || MediaType.APPLICATION_XHTML.equals(mt)) {95 } else if (".html".equals(fmt)) { // NOI18N 109 96 return toXHTML(); 110 } else { // Return XML by default111 return toXML(); 97 } else { 98 return toXML(); // Preferred representation 112 99 } 113 100 } -
trunk/src/com/calenco/resource/workspace/ClassificationsResource.java
r622 r677 29 29 import com.calenco.utils.XhtmlHelper; 30 30 import java.io.IOException; 31 import java.util.ArrayList;32 31 import java.util.HashSet; 33 import java.util.List;34 32 import java.util.Set; 35 33 import javax.jcr.RepositoryException; … … 60 58 public static final String ALL_FILES = "ALL_FILES"; 61 59 Set<Classification> classifications = null; 62 String format = null;63 60 64 61 @Override 65 62 void init() throws RepositoryException { 66 /* Get format parameter from the request */67 Form query = getRequest().getResourceRef().getQueryAsForm();68 format = query.getFirstValue("fmt"); // NOI18N69 /* Get classifications */70 63 ClassificationDAO dao = new ClassificationDAO(session, workspace); 71 64 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 }84 65 } 85 66 … … 153 134 @Override 154 135 public Representation get(Variant variant) throws ResourceException { 155 // Content negotiation, prioritizing the optional 'fmt' query param156 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 value165 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 169 150 return toJSON(); 170 } else if ( MediaType.TEXT_HTML.equals(mt) || MediaType.APPLICATION_XHTML.equals(mt)) {151 } else if (".html".equals(fmt)) { // NOI18N 171 152 return toXHTML(); 172 } else { // Return XML by default173 return toXML(); 153 } else { 154 return toXML(); // Preferred representation 174 155 } 175 156 } -
trunk/src/com/calenco/staticres/workspace-html.ftl
r676 r677 34 34 dojo.require("dojo.parser"); 35 35 dojo.require("dojo.data.ItemFileReadStore"); 36 dojo.require("dojo.data.ItemFileWriteStore");37 36 dojo.require("dojo.io.iframe"); 38 37 dojo.require("dijit.Toolbar"); … … 167 166 }); 168 167 /* 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"}); 170 169 tcStore.fetch({ 171 170 query: {}, start: 0, count: 1, onComplete: function(res) { … … 998 997 dojo.query("#filesMenuBar").style("display", "none"); 999 998 dojo.query("#filesTree").style("display", "none"); 1000 cdstore = new dojo.data.ItemFile WriteStore({url: "/workspaces/${wksp}/classifications?fmt=json"});999 cdstore = new dojo.data.ItemFileReadStore({url: "/workspaces/${wksp}/classifications.json"}); 1001 1000 cmdl = new dijit.tree.ForestStoreModel({ 1002 1001 store: cdstore,
Note: See TracChangeset
for help on using the changeset viewer.
