Changeset 694


Ignore:
Timestamp:
03/05/10 21:56:13 (6 months ago)
Author:
fabman
Message:

tkts #166, #172, #173 done
cleanups and fixes here and there

Location:
trunk/src/com/calenco
Files:
1 added
9 edited

Legend:

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

    r692 r694  
    4545import com.calenco.resource.workspace.ContentRevhistoryResource; 
    4646import com.calenco.resource.workspace.ContentStylesheetsResource; 
     47import com.calenco.resource.workspace.ContentToolchainsResource; 
    4748import com.calenco.resource.workspace.DepsTreeResource; 
    4849import com.calenco.resource.workspace.LanguageResource; 
     
    126127        wrouter.attach("/{wksp}/content/{langOrFile}/revhistory", ContentRevhistoryResource.class); 
    127128        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); 
    130133        wrouter.attach("/{wksp}/content", ContentResource.class); 
    131134        wrouter.attach("/{wksp}/content/{langOrFile}", ContentResource.class); 
     
    134137        wrouter.attach("/{wksp}/languages/{lang}", LanguageResource.class); 
    135138        wrouter.attach("/{wksp}/publications", PublicationsResource.class); 
    136         wrouter.attach("/{wksp}/publications{.fmt}", PublicationsResource.class); 
    137139        wrouter.attach("/{wksp}/publications/{pub}", PublicationResource.class); 
    138140        wrouter.attach("/{wksp}/pubsqueue", PublicationQueueResource.class); 
     
    158160        srouter.setRoutingMode(Router.MODE_BEST_MATCH); 
    159161        srouter.attach("/toolchains", ToolchainsResource.class); 
    160         srouter.attach("/toolchains{.fmt}", ToolchainsResource.class); 
    161162        srouter.attach("/toolchains/{tchain}", ToolchainResource.class); 
    162163        srouter.attach("/addons/{addon}/{kind}", AddOnResource.class); 
    163164        srouter.attach("/languages", com.calenco.resource.system.LanguagesResource.class); 
    164         srouter.attach("/languages{.fmt}", com.calenco.resource.system.LanguagesResource.class); 
    165165        srouter.attach("/users", UsersResource.class); 
    166166        srouter.attach("/users/{user}", UserResource.class); 
  • trunk/src/com/calenco/addon/db5/DocBook5AddOnBase.java

    r693 r694  
    8686 
    8787    public DocBook5AddOnBase() throws XMLProcessingException { 
    88         canDiff = deltaXMLComparatorPresent(); 
    8988        try { 
    9089            //the toolchains 
     
    9594            toolchains.put(XHTMLSingleToolchain.NAME, new XHTMLSingleToolchain()); 
    9695            toolchains.put(XHTMLChunkToolchain.NAME, new XHTMLChunkToolchain()); 
    97             toolchains.put(CHMToolchain.NAME, new CHMToolchain()); 
    98             if (canDiff) { 
     96            try { 
     97                Class.forName("com.calenco.nonfree.db5.DeltaXMLComparator"); 
    9998                toolchains.put(DiffToolchain.NAME, new DiffToolchain()); 
     99            } catch (ClassNotFoundException cannotDiff) { 
    100100            } 
    101101 
     
    199199    } 
    200200 
    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  
    210201} 
  • trunk/src/com/calenco/resource/system/LanguagesResource.java

    r640 r694  
    3535import org.restlet.ext.xml.DomRepresentation; 
    3636import org.restlet.representation.Representation; 
    37 import org.restlet.representation.Variant; 
    3837import org.restlet.resource.Get; 
    3938import org.restlet.resource.ResourceException; 
     
    5958    } 
    6059 
    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 { 
    9762        try { 
    9863            JSONObject syslangsj = new JSONObject(); 
     
    11883    } 
    11984 
    120     Representation toXML() throws ResourceException { 
     85    @Get("xml") 
     86    public Representation toXML() throws ResourceException { 
    12187        try { 
    12288            DomRepresentation rep = new DomRepresentation(MediaType.TEXT_XML); 
  • trunk/src/com/calenco/resource/system/ToolchainsResource.java

    r677 r694  
    8383            MediaType mt = variant.getMediaType(); 
    8484            if (accept != null) { 
    85                 mt = new MediaType(accept); 
     85                try { 
     86                    mt = new MediaType(accept); 
     87                } catch (Exception ignored) { 
     88                } 
    8689            } 
    8790            if (MediaType.TEXT_HTML.equals(mt) || MediaType.APPLICATION_XHTML.equals(mt)) { 
    8891                fmt = ".html"; // NOI18N 
    89             } else if (MediaType.APPLICATION_JSON.equals(mt)) { 
    90                 fmt = ".json"; // NOI18N 
     92            } else if (MediaType.TEXT_XML.equals(mt) || MediaType.APPLICATION_XML.equals(mt)) { 
     93                fmt = ".xml"; // NOI18N 
    9194            } 
    9295        } 
    93         if (".json".equals(fmt)) { // NOI18N 
    94             return toJSON(); 
     96        if (".xml".equals(fmt)) { // NOI18N 
     97            return toXML(); 
    9598        } else if (".html".equals(fmt)) { // NOI18N 
    9699            return toXHTML(); 
    97100        } else { 
    98             return toXML(); // Preferred representation 
     101            return toJSON(); // Preferred representation 
    99102        } 
    100103    } 
  • trunk/src/com/calenco/resource/workspace/ClassificationsResource.java

    r677 r694  
    139139            MediaType mt = variant.getMediaType(); 
    140140            if (accept != null) { 
    141                 mt = new MediaType(accept); 
     141                try { 
     142                    mt = new MediaType(accept); 
     143                } catch (Exception ignored) { 
     144                } 
    142145            } 
    143146            if (MediaType.TEXT_HTML.equals(mt) || MediaType.APPLICATION_XHTML.equals(mt)) { 
    144147                fmt = ".html"; // NOI18N 
    145             } else if (MediaType.APPLICATION_JSON.equals(mt)) { 
    146                 fmt = ".json"; // NOI18N 
    147             } 
    148         } 
    149         if (".json".equals(fmt)) { // NOI18N 
    150             return toJSON(); 
     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(); 
    151154        } else if (".html".equals(fmt)) { // NOI18N 
    152155            return toXHTML(); 
    153156        } else { 
    154             return toXML(); // Preferred representation 
     157            return toJSON(); // Preferred representation 
    155158        } 
    156159    } 
  • trunk/src/com/calenco/resource/workspace/ContentStylesheetsResource.java

    r692 r694  
    5656    String fileName = null; 
    5757    String path = null; 
     58    String tchain = null; 
    5859 
    5960    @Override 
    6061    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 
    6466        if (langOrFile == null && lang == null && file == null) { // Intl folder 
    6567            fileName = Language.INTL; 
     
    8991                AssociationDAO adao = new AssociationDAO(session, workspace); 
    9092                String cco_xmlType = null; 
    91                 List<Toolchain> toolchains = null; 
    9293                try { 
    9394                    cco_xmlType = dao.getProperty(path, "cco_xmltype").getString(); // NOI18N 
     
    9697                if (cco_xmlType != null) { 
    9798                    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); 
    107105                        } 
    108106                    } 
     
    112110                xsls.put("label", "name"); // NOI18N 
    113111                JSONArray xsla = new JSONArray(); 
    114                 if (cco_xmlType != null && toolchains != null && !toolchains.isEmpty()) { 
    115                     xsla.put(new JSONObject().put("name", "[ DEFAULT ]").put("href", "DEFAULT")); // NOI18N 
    116                 } 
    117112                for (Content stylesheet: stylesheets) { 
    118113                    JSONObject xsl = new JSONObject(); 
  • trunk/src/com/calenco/resource/workspace/PublicationsResource.java

    r687 r694  
    5050import org.restlet.representation.Representation; 
    5151import org.restlet.representation.StringRepresentation; 
    52 import org.restlet.representation.Variant; 
    5352import org.restlet.resource.Get; 
    5453import org.restlet.resource.Post; 
     
    248247    } 
    249248 
    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 { 
    272251        try { 
    273252            JSONObject pubsj = new JSONObject(); 
     
    288267    } 
    289268 
    290     private Representation toXML() throws ResourceException { 
     269    @Get("xml") 
     270    public Representation toXML() throws ResourceException { 
    291271        try { 
    292272            DomRepresentation rep = new DomRepresentation(MediaType.TEXT_XML); 
  • trunk/src/com/calenco/staticres/workspace-html.ftl

    r692 r694  
    174174                    } 
    175175                }); 
    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                 }); 
    200176                /* Fetch system(-wide available) languages */ 
    201177                dojo.xhrGet({ 
    202                     url: "/system/languages.json", 
     178                    url: "/system/languages", 
     179                    headers: {Accept: "application/json"}, 
    203180                    handleAs: "json", 
    204181                    load: function(response, ioArgs) { 
     
    591568                                            </div> 
    592569                                            <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> 
    594571                                            </div> 
    595572                                        </div> 
     
    12951272                var fname = new String(selectedFile).replace(noPathRE, ""); 
    12961273                dojo.xhrGet({ 
    1297                     url: "/workspaces/${wksp}/publications.json?file=" + selectedFile, 
     1274                    url: "/workspaces/${wksp}/publications?file=" + selectedFile, 
    12981275                    preventCache: true, 
     1276                    headers: {Accept: "application/json"}, 
    12991277                    handleAs: "json", 
    13001278                    handle: function(response, ioArgs) { 
     
    14061384            function createPub() { 
    14071385                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                }); 
    14081467                var nform = dojo.byId("pnewf"); 
    14091468                nform.reset(); 
    14101469                dojo.byId("pinput-file").value = selectedFile; 
    1411                 fillXsl("pxsl"); 
    14121470                var dlg = dijit.byId("pnew"); 
    14131471                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();}); 
    14151473                dlg.show(); 
    14161474            } 
     
    15731631            } 
    15741632 
    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  
    15871633            function fillLangs(/* String */selId) { 
    15881634                var langDS = new dojo.data.ItemFileReadStore({url: "/workspaces/${wksp}/languages"}); 
  • trunk/src/com/calenco/staticres/workspaces-html.ftl

    r687 r694  
    7070            function init() { 
    7171                dojo.xhrGet({ 
    72                     url: "/system/languages.json", 
     72                    url: "/system/languages", 
     73                    headers: {Accept: "application/json"}, 
    7374                    handleAs: "json", 
    7475                    load: function(response, ioArgs) { 
Note: See TracChangeset for help on using the changeset viewer.