Changeset 694
- Timestamp:
- 03/05/10 21:56:13 (6 months ago)
- Location:
- trunk/src/com/calenco
- Files:
-
- 1 added
- 9 edited
-
CalencoV2App.java (modified) (4 diffs)
-
addon/db5/DocBook5AddOnBase.java (modified) (3 diffs)
-
resource/system/LanguagesResource.java (modified) (3 diffs)
-
resource/system/ToolchainsResource.java (modified) (1 diff)
-
resource/workspace/ClassificationsResource.java (modified) (1 diff)
-
resource/workspace/ContentStylesheetsResource.java (modified) (4 diffs)
-
resource/workspace/ContentToolchainsResource.java (added)
-
resource/workspace/PublicationsResource.java (modified) (3 diffs)
-
staticres/workspace-html.ftl (modified) (5 diffs)
-
staticres/workspaces-html.ftl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/calenco/CalencoV2App.java
r692 r694 45 45 import com.calenco.resource.workspace.ContentRevhistoryResource; 46 46 import com.calenco.resource.workspace.ContentStylesheetsResource; 47 import com.calenco.resource.workspace.ContentToolchainsResource; 47 48 import com.calenco.resource.workspace.DepsTreeResource; 48 49 import com.calenco.resource.workspace.LanguageResource; … … 126 127 wrouter.attach("/{wksp}/content/{langOrFile}/revhistory", ContentRevhistoryResource.class); 127 128 wrouter.attach("/{wksp}/content/{lang}/{file}/revhistory", ContentRevhistoryResource.class); 128 wrouter.attach("/{wksp}/content/{langOrFile}/stylesheets", ContentStylesheetsResource.class); 129 wrouter.attach("/{wksp}/content/{lang}/{file}/stylesheets", ContentStylesheetsResource.class); 129 wrouter.attach("/{wksp}/content/{langOrFile}/stylesheets/{tchain}", ContentStylesheetsResource.class); 130 wrouter.attach("/{wksp}/content/{lang}/{file}/stylesheets/{tchain}", ContentStylesheetsResource.class); 131 wrouter.attach("/{wksp}/content/{langOrFile}/toolchains", ContentToolchainsResource.class); 132 wrouter.attach("/{wksp}/content/{lang}/{file}/toolchains", ContentToolchainsResource.class); 130 133 wrouter.attach("/{wksp}/content", ContentResource.class); 131 134 wrouter.attach("/{wksp}/content/{langOrFile}", ContentResource.class); … … 134 137 wrouter.attach("/{wksp}/languages/{lang}", LanguageResource.class); 135 138 wrouter.attach("/{wksp}/publications", PublicationsResource.class); 136 wrouter.attach("/{wksp}/publications{.fmt}", PublicationsResource.class);137 139 wrouter.attach("/{wksp}/publications/{pub}", PublicationResource.class); 138 140 wrouter.attach("/{wksp}/pubsqueue", PublicationQueueResource.class); … … 158 160 srouter.setRoutingMode(Router.MODE_BEST_MATCH); 159 161 srouter.attach("/toolchains", ToolchainsResource.class); 160 srouter.attach("/toolchains{.fmt}", ToolchainsResource.class);161 162 srouter.attach("/toolchains/{tchain}", ToolchainResource.class); 162 163 srouter.attach("/addons/{addon}/{kind}", AddOnResource.class); 163 164 srouter.attach("/languages", com.calenco.resource.system.LanguagesResource.class); 164 srouter.attach("/languages{.fmt}", com.calenco.resource.system.LanguagesResource.class);165 165 srouter.attach("/users", UsersResource.class); 166 166 srouter.attach("/users/{user}", UserResource.class); -
trunk/src/com/calenco/addon/db5/DocBook5AddOnBase.java
r693 r694 86 86 87 87 public DocBook5AddOnBase() throws XMLProcessingException { 88 canDiff = deltaXMLComparatorPresent();89 88 try { 90 89 //the toolchains … … 95 94 toolchains.put(XHTMLSingleToolchain.NAME, new XHTMLSingleToolchain()); 96 95 toolchains.put(XHTMLChunkToolchain.NAME, new XHTMLChunkToolchain()); 97 t oolchains.put(CHMToolchain.NAME, new CHMToolchain());98 if (canDiff) {96 try { 97 Class.forName("com.calenco.nonfree.db5.DeltaXMLComparator"); 99 98 toolchains.put(DiffToolchain.NAME, new DiffToolchain()); 99 } catch (ClassNotFoundException cannotDiff) { 100 100 } 101 101 … … 199 199 } 200 200 201 public boolean deltaXMLComparatorPresent() {202 try {203 Class.forName("com.calenco.nonfree.db5.DeltaXMLComparator");204 } catch (ClassNotFoundException ex) {205 return false;206 }207 return true;208 }209 210 201 } -
trunk/src/com/calenco/resource/system/LanguagesResource.java
r640 r694 35 35 import org.restlet.ext.xml.DomRepresentation; 36 36 import org.restlet.representation.Representation; 37 import org.restlet.representation.Variant;38 37 import org.restlet.resource.Get; 39 38 import org.restlet.resource.ResourceException; … … 59 58 } 60 59 61 @Get 62 @Override 63 /** 64 * GET handler with custom content negotiation logic: 65 * <ul> 66 * <li>if no {.fmt} and no Accept header present, return the preferred 67 * (working fine on IE) representation</li> 68 * <li>if Accept header present, return that representation if 69 * available, the preferred one otherwise</li> 70 * <li>if {.fmt} is present, return the corresponding representation 71 * if available, the preferred one otherwise</li> 72 * <li>if both Accept and {.fmt} are present, {.fmt} (more specific) has 73 * preference 74 * </ul> 75 * 76 */ 77 public Representation get(Variant variant) throws ResourceException { 78 String format = (String) getRequestAttributes().get(".fmt"); 79 if (format == null) { 80 String accept = getHttpHeader("Accept"); 81 MediaType mt = variant.getMediaType(); 82 if (accept != null) { 83 mt = new MediaType(accept); 84 } 85 if (MediaType.APPLICATION_XML.equals(mt) || MediaType.TEXT_XML.equals(mt)) { 86 format = ".xml"; 87 } 88 } 89 if (".xml".equals(format)) { 90 return toXML(); 91 } else { 92 return toJSON(); // Preferred representation 93 } 94 } 95 96 Representation toJSON() throws ResourceException { 60 @Get("json") 61 public Representation toJSON() throws ResourceException { 97 62 try { 98 63 JSONObject syslangsj = new JSONObject(); … … 118 83 } 119 84 120 Representation toXML() throws ResourceException { 85 @Get("xml") 86 public Representation toXML() throws ResourceException { 121 87 try { 122 88 DomRepresentation rep = new DomRepresentation(MediaType.TEXT_XML); -
trunk/src/com/calenco/resource/system/ToolchainsResource.java
r677 r694 83 83 MediaType mt = variant.getMediaType(); 84 84 if (accept != null) { 85 mt = new MediaType(accept); 85 try { 86 mt = new MediaType(accept); 87 } catch (Exception ignored) { 88 } 86 89 } 87 90 if (MediaType.TEXT_HTML.equals(mt) || MediaType.APPLICATION_XHTML.equals(mt)) { 88 91 fmt = ".html"; // NOI18N 89 } else if (MediaType. APPLICATION_JSON.equals(mt)) {90 fmt = ". json"; // NOI18N92 } else if (MediaType.TEXT_XML.equals(mt) || MediaType.APPLICATION_XML.equals(mt)) { 93 fmt = ".xml"; // NOI18N 91 94 } 92 95 } 93 if (". json".equals(fmt)) { // NOI18N94 return to JSON();96 if (".xml".equals(fmt)) { // NOI18N 97 return toXML(); 95 98 } else if (".html".equals(fmt)) { // NOI18N 96 99 return toXHTML(); 97 100 } else { 98 return to XML(); // Preferred representation101 return toJSON(); // Preferred representation 99 102 } 100 103 } -
trunk/src/com/calenco/resource/workspace/ClassificationsResource.java
r677 r694 139 139 MediaType mt = variant.getMediaType(); 140 140 if (accept != null) { 141 mt = new MediaType(accept); 141 try { 142 mt = new MediaType(accept); 143 } catch (Exception ignored) { 144 } 142 145 } 143 146 if (MediaType.TEXT_HTML.equals(mt) || MediaType.APPLICATION_XHTML.equals(mt)) { 144 147 fmt = ".html"; // NOI18N 145 } else if (MediaType. APPLICATION_JSON.equals(mt)) {146 fmt = ". json"; // NOI18N147 } 148 } 149 if (". json".equals(fmt)) { // NOI18N150 return to JSON();148 } else if (MediaType.TEXT_XML.equals(mt) || MediaType.APPLICATION_XML.equals(mt)) { 149 fmt = ".xml"; // NOI18N 150 } 151 } 152 if (".xml".equals(fmt)) { // NOI18N 153 return toXML(); 151 154 } else if (".html".equals(fmt)) { // NOI18N 152 155 return toXHTML(); 153 156 } else { 154 return to XML(); // Preferred representation157 return toJSON(); // Preferred representation 155 158 } 156 159 } -
trunk/src/com/calenco/resource/workspace/ContentStylesheetsResource.java
r692 r694 56 56 String fileName = null; 57 57 String path = null; 58 String tchain = null; 58 59 59 60 @Override 60 61 void init() throws RepositoryException { 61 langOrFile = Reference.decode((String)getRequest().getAttributes().get("langOrFile")); // NOI18N 62 lang = Reference.decode((String)getRequest().getAttributes().get("lang")); // NOI18N 63 file = Reference.decode((String)getRequest().getAttributes().get("file")); // NOI18N 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 65 tchain = Reference.decode((String)getRequestAttributes().get("tchain")); // NOI18N 64 66 if (langOrFile == null && lang == null && file == null) { // Intl folder 65 67 fileName = Language.INTL; … … 89 91 AssociationDAO adao = new AssociationDAO(session, workspace); 90 92 String cco_xmlType = null; 91 List<Toolchain> toolchains = null;92 93 try { 93 94 cco_xmlType = dao.getProperty(path, "cco_xmltype").getString(); // NOI18N … … 96 97 if (cco_xmlType != null) { 97 98 AddOnsManager aom = AddOnsManager.getInstance(); 98 toolchains = aom.getToolchains(cco_xmlType); 99 for (Toolchain toolchain: toolchains) { 100 String to = String.format("%s|%s", aom.getAddOn(cco_xmlType).getType(), toolchain.getName()); 101 Set<Association> xslAssocs = adao.findByKindTo(Association.HAS_TOOLCHAIN, to); 102 for (Association xslAssoc: xslAssocs) { 103 Content xsl = dao.retrieve(xslAssoc.getFrom(), null); 104 if (xsl != null) { 105 stylesheets.add(xsl); 106 } 99 String to = String.format("%s|%s", aom.getAddOn(cco_xmlType).getType(), tchain); // NOI18N 100 Set<Association> xslAssocs = adao.findByKindTo((Association.HAS_TOOLCHAIN), to); 101 for (Association xslAssoc: xslAssocs) { 102 Content xsl = dao.retrieve(xslAssoc.getFrom(), null); 103 if (xsl != null) { 104 stylesheets.add(xsl); 107 105 } 108 106 } … … 112 110 xsls.put("label", "name"); // NOI18N 113 111 JSONArray xsla = new JSONArray(); 114 if (cco_xmlType != null && toolchains != null && !toolchains.isEmpty()) {115 xsla.put(new JSONObject().put("name", "[ DEFAULT ]").put("href", "DEFAULT")); // NOI18N116 }117 112 for (Content stylesheet: stylesheets) { 118 113 JSONObject xsl = new JSONObject(); -
trunk/src/com/calenco/resource/workspace/PublicationsResource.java
r687 r694 50 50 import org.restlet.representation.Representation; 51 51 import org.restlet.representation.StringRepresentation; 52 import org.restlet.representation.Variant;53 52 import org.restlet.resource.Get; 54 53 import org.restlet.resource.Post; … … 248 247 } 249 248 250 @Get 251 @Override 252 public Representation get(Variant variant) throws ResourceException { 253 String fmt = (String) getRequestAttributes().get(".fmt"); // NOI18N 254 if (fmt == null) { 255 String accept = getHttpHeader("Accept"); // NOI18N 256 MediaType mt = variant.getMediaType(); 257 if (accept != null) { 258 mt = new MediaType(accept); 259 } 260 if (MediaType.APPLICATION_JSON.equals(mt)) { 261 fmt = ".json"; // NOI18N 262 } 263 } 264 if (".json".equals(fmt)) { // NOI18N 265 return toJSON(); 266 } else { 267 return toXML(); // Preferred representation 268 } 269 } 270 271 private Representation toJSON() throws ResourceException { 249 @Get("json") 250 public Representation toJSON() throws ResourceException { 272 251 try { 273 252 JSONObject pubsj = new JSONObject(); … … 288 267 } 289 268 290 private Representation toXML() throws ResourceException { 269 @Get("xml") 270 public Representation toXML() throws ResourceException { 291 271 try { 292 272 DomRepresentation rep = new DomRepresentation(MediaType.TEXT_XML); -
trunk/src/com/calenco/staticres/workspace-html.ftl
r692 r694 174 174 } 175 175 }); 176 /* Fill TC list */177 var tcStore = new dojo.data.ItemFileReadStore({url: "/system/toolchains.json"});178 tcStore.fetch({179 query: {}, start: 0, count: 1, onComplete: function(res) {180 tcsel = new dijit.form.FilteringSelect({181 name: "toolchain",182 store: tcStore,183 searchAttr: "desc",184 value: tcStore.getIdentity(res[0]),185 invalidMessage: "Not valid, please select one of the available values only"186 }).placeAt("ptoolchain");187 }188 });189 /* Fill XSLs list */190 var xslStore = new dojo.data.ItemFileReadStore({url: "/workspaces/${wksp}/stylesheets"});191 xslStore.fetch({192 query: {}, start: 0, count: 1, onComplete: function(res) {193 xslsel = new dijit.form.FilteringSelect({194 store: xslStore,195 searchAttr: "desc",196 value: xslStore.getIdentity(res[0])197 }, "pxsl");198 }199 });200 176 /* Fetch system(-wide available) languages */ 201 177 dojo.xhrGet({ 202 url: "/system/languages.json", 178 url: "/system/languages", 179 headers: {Accept: "application/json"}, 203 180 handleAs: "json", 204 181 load: function(response, ioArgs) { … … 591 568 </div> 592 569 <div class="pfctrl"> 593 < input id="pxsl" name="xsl" dojotype="dijit.form.FilteringSelect" invalidmessage="Not valid, please select one of the available values only" />570 <div id="pxsl"></div> 594 571 </div> 595 572 </div> … … 1295 1272 var fname = new String(selectedFile).replace(noPathRE, ""); 1296 1273 dojo.xhrGet({ 1297 url: "/workspaces/${wksp}/publications .json?file=" + selectedFile,1274 url: "/workspaces/${wksp}/publications?file=" + selectedFile, 1298 1275 preventCache: true, 1276 headers: {Accept: "application/json"}, 1299 1277 handleAs: "json", 1300 1278 handle: function(response, ioArgs) { … … 1406 1384 function createPub() { 1407 1385 dijit.byId("plist.dlg").hide(); 1386 // Fill XSL with just the default XSL 1387 var xslStore = new dojo.data.ItemFileReadStore({ 1388 data: {count: 1, label: "name", identifier: "href", items: [{name: "[ DEFAULT ]", href: "DEFAULT"}]}, 1389 clearOnClose: true 1390 }); 1391 xslStore.fetch({ 1392 query: {}, onComplete: function(res) { 1393 dojo.empty("pxsl"); 1394 if (xslsel) { 1395 xslsel.destroyRecursive(false); 1396 } 1397 xslsel = new dijit.form.FilteringSelect({ 1398 name: "xsl", 1399 store: xslStore, 1400 searchAttr: "name", 1401 value: xslStore.getIdentity(res[0]), 1402 invalidMessage: "Not valid, please select one of the available values only" 1403 }).placeAt("pxsl"); 1404 } 1405 }); 1406 // Fill TC list with possible TCs for the selected file 1407 var tcStore = new dojo.data.ItemFileReadStore({ 1408 url: selectedFile + "/toolchains", 1409 urlPreventCache: true, 1410 clearOnClose: true 1411 }); 1412 tcStore.fetch({ 1413 query: {}, sort: [{attribute: "desc"}], onComplete: function(res) { 1414 dojo.empty("ptoolchain"); 1415 if (tcsel) { 1416 tcsel.destroyRecursive(false); 1417 } 1418 tcsel = new dijit.form.FilteringSelect({ 1419 name: "toolchain", 1420 store: tcStore, 1421 searchAttr: "desc", 1422 invalidMessage: "Not valid, please select one of the available values only", 1423 onChange: function(item) { 1424 dojo.xhrGet({ // Not the most efficient way, but it just works(TM) 1425 url: selectedFile + "/stylesheets/" + item, 1426 handleAs: "json", 1427 handle: function(response, ioArgs) { 1428 if (ioArgs.xhr.status != 200) { 1429 console.warn("Cannot retrieve XSLs matching the given toolchain and file", response, ioArgs); 1430 } else { 1431 var xslData = {count: 1, label: "name", identifier: "href", items: [{name: "[ DEFAULT ]", href: "DEFAULT"}]}; 1432 if (response.count > 0) { 1433 for (var i = 0; i < response.count; i++) { 1434 xslData.items.push(response.items[i]); 1435 } 1436 } 1437 xslData.count += response.count; 1438 xslStore.close(); 1439 var xslStore2 = new dojo.data.ItemFileReadStore({ 1440 data: xslData, 1441 clearOnClose: true 1442 }); 1443 xslStore2.fetch({ 1444 query: {}, onComplete: function(res) { 1445 dojo.empty("pxsl"); 1446 if (xslsel) { 1447 xslsel.destroyRecursive(false); 1448 } 1449 xslsel = new dijit.form.FilteringSelect({ 1450 name: "xsl", 1451 store: xslStore2, 1452 searchAttr: "name", 1453 value: xslStore2.getIdentity(res[0]), 1454 invalidMessage: "Not valid, please select one of the available values only" 1455 }).placeAt("pxsl"); 1456 } 1457 }); 1458 } 1459 return response; 1460 } 1461 }); 1462 } 1463 }).placeAt("ptoolchain"); 1464 tcsel.attr("value", tcStore.getIdentity(res[0])); // Set value and update XSL list accordingly 1465 } 1466 }); 1408 1467 var nform = dojo.byId("pnewf"); 1409 1468 nform.reset(); 1410 1469 dojo.byId("pinput-file").value = selectedFile; 1411 fillXsl("pxsl");1412 1470 var dlg = dijit.byId("pnew"); 1413 1471 dlg.attr("title", "Create Publication for " + selectedFile); 1414 dojo.connect(dlg, "onCancel", function(e) { dijit.byId("plist.dlg").show();});1472 dojo.connect(dlg, "onCancel", function(e) {if (tcsel) {tcsel.destroyRecursive(false);} if (xslsel) {xslsel.destroyRecursive(false);} dijit.byId("plist.dlg").show();}); 1415 1473 dlg.show(); 1416 1474 } … … 1573 1631 } 1574 1632 1575 function fillXsl(/* String */selId) {1576 var xslStore = new dojo.data.ItemFileReadStore({url: selectedFile + "/stylesheets"});1577 xslStore.fetch({1578 query: {}, start: 0, count: 1, onComplete: function(res) {1579 xslsel = dijit.byId(selId);1580 xslsel.attr("store", xslStore);1581 xslsel.attr("searchAttr", "name");1582 xslsel.attr("value", xslStore.getIdentity(res[0]));1583 }1584 });1585 }1586 1587 1633 function fillLangs(/* String */selId) { 1588 1634 var langDS = new dojo.data.ItemFileReadStore({url: "/workspaces/${wksp}/languages"}); -
trunk/src/com/calenco/staticres/workspaces-html.ftl
r687 r694 70 70 function init() { 71 71 dojo.xhrGet({ 72 url: "/system/languages.json", 72 url: "/system/languages", 73 headers: {Accept: "application/json"}, 73 74 handleAs: "json", 74 75 load: function(response, ioArgs) {
Note: See TracChangeset
for help on using the changeset viewer.
