version 1.175.2.16, 2011/08/03 19:04:18
|
version 1.175.2.21, 2011/08/05 17:04:20
|
Line 266 class documentViewer(Folder):
|
Line 266 class documentViewer(Folder):
|
|
|
|
|
security.declareProtected('View','index_html') |
security.declareProtected('View','index_html') |
def index_html(self,url,mode="texttool",viewMode="auto",tocMode="thumbs",start=None,pn=1,mk=None): |
def index_html(self,url,mode="texttool",viewMode="auto",viewType=None,tocMode="thumbs",start=1,pn=1): |
""" |
""" |
view it |
view page |
@param mode: defines how to access the document behind url |
|
@param url: url which contains display information |
@param url: url which contains display information |
@param viewMode: if images display images, if text display text, default is auto (text,images or auto) |
@param mode: defines how to access the document behind url |
|
@param viewMode: 'images': display images, 'text': display text, default is 'auto' |
|
@param viewType: sub-type of viewMode, e.g. 'dict' for viewMode='text' |
@param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) |
@param tocMode: type of 'table of contents' for navigation (thumbs, text, figures, none) |
""" |
""" |
|
|
logging.debug("documentViewer (index) mode: %s url:%s start:%s pn:%s"%(mode,url,start,pn)) |
logging.debug("documentViewer(index_html) mode=%s url=%s viewMode=%s viewType=%s start=%s pn=%s"%(mode,url,viewMode,viewType,start,pn)) |
|
|
if not hasattr(self, 'template'): |
if not hasattr(self, 'template'): |
# this won't work |
# this won't work |
Line 291 class documentViewer(Folder):
|
Line 292 class documentViewer(Folder):
|
# get table of contents |
# get table of contents |
docinfo = self.getToc(mode=tocMode, docinfo=docinfo) |
docinfo = self.getToc(mode=tocMode, docinfo=docinfo) |
|
|
# auto viewMode: text_dict if text else images |
# auto viewMode: text if there is a text else images |
if viewMode=="auto": |
if viewMode=="auto": |
if docinfo.get('textURL', None) or docinfo.get('textURLPath', None): |
if docinfo.get('textURL', None) or docinfo.get('textURLPath', None): |
viewMode="text_dict" |
viewMode = "text" |
|
viewType = "dict" |
else: |
else: |
viewMode="images" |
viewMode="images" |
|
|
pageinfo = self.getPageinfo(start=start, current=pn, docinfo=docinfo, viewMode=viewMode, tocMode=tocMode) |
elif viewMode == "text_dict": |
|
# legacy fix |
|
viewMode = "text" |
|
viewType = "dict" |
|
|
|
# stringify viewType |
|
if isinstance(viewType, list): |
|
viewType = ','.join([t for t in viewType if t]) |
|
|
|
pageinfo = self.getPageinfo(start=start, current=pn, docinfo=docinfo, viewMode=viewMode, viewType=viewType, tocMode=tocMode) |
|
|
|
# get template /template/viewer_$viewMode |
|
pt = getattr(self.template, 'viewer_%s'%viewMode, None) |
|
if pt is None: |
|
logging.error("No template for viewMode=%s!"%viewMode) |
|
# TODO: error page? |
|
return "No template for viewMode=%s!"%viewMode |
|
|
# get template /template/viewer_main |
|
pt = getattr(self.template, 'viewer_main') |
|
# and execute with parameters |
# and execute with parameters |
return pt(docinfo=docinfo, pageinfo=pageinfo, viewMode=viewMode, mk=self.generateMarks(mk)) |
return pt(docinfo=docinfo, pageinfo=pageinfo) |
|
|
def generateMarks(self,mk): |
def generateMarks(self,mk): |
ret="" |
ret="" |
Line 372 class documentViewer(Folder):
|
Line 388 class documentViewer(Folder):
|
"""returns URL to documentviewer with parameter param set to val or from dict params""" |
"""returns URL to documentviewer with parameter param set to val or from dict params""" |
urlParams = self.getParams(param=param, val=val, params=params) |
urlParams = self.getParams(param=param, val=val, params=params) |
# quote values and assemble into query string (not escaping '/') |
# quote values and assemble into query string (not escaping '/') |
ps = paramSep.join(["%s=%s"%(k,urllib.quote_plus(v,'/')) for (k, v) in urlParams.items()]) |
ps = paramSep.join(["%s=%s"%(k,urllib.quote_plus(unicode(v),'/')) for (k, v) in urlParams.items()]) |
if baseUrl is None: |
if baseUrl is None: |
baseUrl = self.getDocumentViewerURL() |
baseUrl = self.getDocumentViewerURL() |
|
|
Line 459 class documentViewer(Folder):
|
Line 475 class documentViewer(Folder):
|
|
|
docinfo['documentUrl'] = docUrl |
docinfo['documentUrl'] = docUrl |
# process index.meta contents |
# process index.meta contents |
if metaDom is not None: |
if metaDom is not None and metaDom.tag == 'resource': |
# document directory name and path |
# document directory name and path |
resource = self.metadataService.getResourceData(dom=metaDom) |
resource = self.metadataService.getResourceData(dom=metaDom) |
if resource: |
if resource: |
Line 664 class documentViewer(Folder):
|
Line 680 class documentViewer(Folder):
|
return docinfo |
return docinfo |
|
|
|
|
def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None, viewMode=None, tocMode=None): |
def getPageinfo(self, current, start=None, rows=None, cols=None, docinfo=None, viewMode=None, viewType=None, tocMode=None): |
"""returns pageinfo with the given parameters""" |
"""returns pageinfo with the given parameters""" |
pageinfo = {} |
pageinfo = {} |
|
pageinfo['viewMode'] = viewMode |
|
pageinfo['viewType'] = viewType |
|
pageinfo['tocMode'] = tocMode |
|
|
current = getInt(current) |
current = getInt(current) |
pageinfo['current'] = current |
pageinfo['current'] = current |
rows = int(rows or self.thumbrows) |
rows = int(rows or self.thumbrows) |
Line 687 class documentViewer(Folder):
|
Line 707 class documentViewer(Folder):
|
# numPages unknown - maybe we can get it from text page |
# numPages unknown - maybe we can get it from text page |
if docinfo.get('textURLPath', None): |
if docinfo.get('textURLPath', None): |
# cache text page as well |
# cache text page as well |
pageinfo['textPage'] = self.getTextPage(mode=viewMode, pn=pn, docinfo=docinfo, pageinfo=pageinfo) |
pageinfo['textPage'] = self.getTextPage(mode=viewType, pn=pn, docinfo=docinfo, pageinfo=pageinfo) |
np = int(docinfo.get('numPages', 0)) |
np = int(docinfo.get('numPages', 0)) |
|
|
pageinfo['end'] = min(pageinfo['end'], np) |
pageinfo['end'] = min(pageinfo['end'], np) |
Line 695 class documentViewer(Folder):
|
Line 715 class documentViewer(Folder):
|
if np % grpsize > 0: |
if np % grpsize > 0: |
pageinfo['numgroups'] += 1 |
pageinfo['numgroups'] += 1 |
|
|
pageinfo['viewMode'] = viewMode |
|
pageinfo['tocMode'] = tocMode |
|
pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') |
pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg') |
#pageinfo['optionToggle'] = self.REQUEST.get('optionToggle','1') |
|
pageinfo['query'] = self.REQUEST.get('query','') |
pageinfo['query'] = self.REQUEST.get('query','') |
pageinfo['queryType'] = self.REQUEST.get('queryType','') |
pageinfo['queryType'] = self.REQUEST.get('queryType','') |
pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext') |
pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext') |