Changeset 623:6012fe93f78c in documentViewer


Ignore:
Timestamp:
Dec 15, 2014, 3:10:05 PM (9 years ago)
Author:
casties
Branch:
default
Message:

better scheme-less URL code.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • SrvTxtUtils.py

    r622 r623  
    88import stat
    99import urllib
     10from urlparse import urlparse, urlunparse
    1011import logging
    1112import time
     
    2223import xml.etree.ElementTree as ET
    2324
    24 srvTxtUtilsVersion = "1.12.3"
     25srvTxtUtilsVersion = "1.13"
    2526
    2627map_months = {'en': [u"",
     
    371372
    372373
     374def sslifyUrl(url, app=None, force=False):
     375    """returns URL with http or https scheme.
     376   
     377    Looks at app.REQUEST.URL to find the scheme of the current page.
     378    Changes only schemeless (starting with //) URLs unless force=True. 
     379    """
     380    thatUrl = urlparse(url)
     381    if hasattr(app, 'REQUEST'):
     382        # get current page URL
     383        thisUrl = urlparse(app.REQUEST['URL'])
     384        if thatUrl.scheme == '':
     385            # schemeless URL -> use this scheme
     386            return "%s:%s"%(thisUrl.scheme, url)
     387        elif force:
     388            # use this scheme
     389            if thisUrl.scheme != thatUrl.scheme:
     390                return urlunparse((thisUrl.scheme,)+thatUrl[1:])
     391            else:
     392                # keep scheme
     393                return url
     394           
     395        else:
     396            # keep scheme
     397            return url
     398       
     399    else:
     400        # no current page URL
     401        if force:
     402            # use https for force
     403            return urlunparse(('https',)+thatUrl[1:])
     404       
     405    return url
  • documentViewer.py

    r622 r623  
    1717from Products.MetaDataProvider import MetaDataFolder
    1818
    19 from SrvTxtUtils import getInt, utf8ify, getText, getHttpData, refreshingImageFileIndexHtml
     19from SrvTxtUtils import getInt, utf8ify, getText, getHttpData, refreshingImageFileIndexHtml, sslifyUrl
    2020   
    2121
    2222def getMDText(node):
    2323    """returns the @text content from the MetaDataProvider metadata node"""
    24 
    25    
    26 
    2724    if isinstance(node, dict):
    2825        return node.get('@text', None)
     
    3431                return node.get('@text',None)
    3532        return None
    36 
    37 
    3833
    3934    return node
     
    174169            self.digilibViewerUrl = digilibBaseUrl + '/jquery/digilib.html'
    175170           
    176        
     171
    177172    # proxy text server methods to fulltextclient
    178173    def getTextPage(self, **args):
    179174        """returns full text content of page"""
    180        
    181175        return self.template.fulltextclient.getTextPage(**args)
    182    
    183    
    184    
    185176
    186177    def getSearchResults(self, **args):
     
    234225                       
    235226        if not self.digilibBaseUrl:
    236             self.digilibBaseUrl = self.findDigilibUrl() or "http://nausikaa.mpiwg-berlin.mpg.de/digitallibrary"
     227            self.digilibBaseUrl = self.findDigilibUrl() or "http://digilib.mpiwg-berlin.mpg.de/digitallibrary"
    237228           
    238229        docinfo = self.getDocinfo(mode=mode,url=url)
     
    268259            logging.error("template folder missing!")
    269260            return "ERROR: template folder missing!"
    270        
    271        
    272261
    273262        if not getattr(self, 'digilibBaseUrl', None):
     
    307296            viewMode = 'image'
    308297            self.REQUEST['viewMode'] = 'image'
    309            
    310        
    311            
    312298
    313299        # safe viewLayer in userinfo
     
    334320        """try to get the digilib URL from zogilib"""
    335321        url = self.template.zogilib.getDLBaseUrl()
    336         return url
     322        return sslifyUrl(url, self, force=True)
    337323   
    338324    def getScalerUrl(self, fn=None, pn=None, dw=100, dh=100, docinfo=None):
     
    765751        # old style text URL
    766752        textUrl = getMDText(texttool.get('text', None))
    767 
    768        
    769 
    770753
    771754        if textUrl and docPath:
     
    11621145        """returns list of groups {name:*, id:*} on the annotation server for the user"""
    11631146        groups = []
    1164         if annotationServerUrl.startswith('//'):
    1165             # add matching http(s) from our URL
    1166             myUrl = self.REQUEST['URL']
    1167             logging.debug("my URL: %s"%myUrl)
    1168             if myUrl.startswith('https:'):
    1169                 annotationServerUrl = "https:%s"%annotationServerUrl
    1170             else:
    1171                 annotationServerUrl = "http:%s"%annotationServerUrl
     1147        # add matching http(s) from our URL
     1148        annotationServerUrl = sslifyUrl(annotationServerUrl, self)
    11721149           
    11731150        groupsUrl = "%s/annotator/groups?user=%s"%(annotationServerUrl,user)
     
    12061183        if RESPONSE is not None:
    12071184            RESPONSE.redirect('manage_main')
     1185           
    12081186       
    12091187def manage_AddDocumentViewerForm(self):
Note: See TracChangeset for help on using the changeset viewer.