Ejemplo n.º 1
0
    def __search(self):
        recordsPerPage = self.__portal.recordsPerPage

        query = formData.get("query")
        if query is None or query == "":
            query = "*:*"
        req = SearchRequest(query)
        req.setParam("facet", "true")
        req.setParam("rows", str(recordsPerPage))
        req.setParam("facet.field", self.__portal.facetFieldList)
        req.setParam("facet.sort", "true")
        req.setParam("facet.limit", str(self.__portal.facetCount))
        req.setParam("sort", "f_dc_title asc")
        
        # setup facets
        action = formData.get("action")
        value = formData.get("value")
        fq = sessionState.get("fq")
        if fq is not None:
            self.__pageNum = 1
            req.setParam("fq", fq)
        if action == "add_fq":
            self.__pageNum = 1
            name = formData.get("name")
            print " * add_fq: %s" % value
            req.addParam("fq", URLDecoder.decode(value, "UTF-8"))
        elif action == "remove_fq":
            self.__pageNum = 1
            req.removeParam("fq", URLDecoder.decode(value, "UTF-8"))
        elif action == "clear_fq":
            self.__pageNum = 1
            req.removeParam("fq")
        elif action == "select-page":
            self.__pageNum = int(value)
        req.addParam("fq", 'item_type:"object"')
        
        portalQuery = self.__portal.query
        print " * portalQuery=%s" % portalQuery
        if portalQuery:
            req.addParam("fq", portalQuery)
        
        self.__selected = req.getParams("fq")

        sessionState.set("fq", self.__selected)
        sessionState.set("pageNum", self.__pageNum)

        req.setParam("start", str((self.__pageNum - 1) * recordsPerPage))
        
        print " * search.py:", req.toString(), self.__pageNum

        out = ByteArrayOutputStream()
        Services.indexer.search(req, out)
        self.__result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
        if self.__result is not None:
            self.__paging = Pagination(self.__pageNum,
                                       int(self.__result.get("response/numFound")),
                                       self.__portal.recordsPerPage)
Ejemplo n.º 2
0
    def getRequestURI(self):
        # 先尝试从 attribute['javax.servlet.forward.request_uri'] 获取, 如果有则解码返回.
        uri = request.getAttribute('javax.servlet.forward.request_uri')
        if uri != None and uri != "":
            return URLDecoder.decode(uri, 'UTF-8')

        # 否则直接用 request 对象里面的.
        uri = request.requestURI
        if uri != None:
            return URLDecoder.decode(uri, 'UTF-8')
        raise Error, "Can't get requestURI"
Ejemplo n.º 3
0
 def readAsServer_0(cls, socket):
     """ generated source for method readAsServer_0 """
     br = BufferedReader(InputStreamReader(socket.getInputStream()))
     #  The first line of the HTTP request is the request line.
     requestLine = br.readLine()
     if requestLine == None:
         raise IOException("The HTTP request was empty.")
     message = str()
     if requestLine.toUpperCase().startsWith("GET "):
         message = requestLine.substring(5, requestLine.lastIndexOf(' '))
         message = URLDecoder.decode(message, "UTF-8")
         message = message.replace(str(13), ' ')
     elif requestLine.toUpperCase().startsWith("POST "):
         message = readContentFromPOST(br)
     elif requestLine.toUpperCase().startsWith("OPTIONS "):
         #  Web browsers can send an OPTIONS request in advance of sending
         #  real XHR requests, to discover whether they should have permission
         #  to send those XHR requests. We want to handle this at the network
         #  layer rather than sending it up to the actual player, so we write
         #  a blank response (which will include the headers that the browser
         #  is interested in) and throw an exception so the player ignores the
         #  rest of this request.
         HttpWriter.writeAsServer(socket, "")
         raise IOException("Drop this message at the network layer.")
     else:
         HttpWriter.writeAsServer(socket, "")
         raise IOException("Unexpected request type: " + requestLine)
     return message
Ejemplo n.º 4
0
 def __uploadMedia(self, oid, doc, content, elem, attr):
     links = doc.getElementsByTagName(elem)
     for i in range(0, links.getLength()):
         elem = links.item(i)
         attrValue = elem.getAttribute(attr)
         pid = attrValue
         payload = Services.getStorage().getPayload(oid, pid)
         if payload is None:
             pid = URLDecoder.decode(pid, "UTF-8")
             payload = Services.getStorage().getPayload(oid, pid)
         if payload is not None:
             #HACK to upload PDFs
             contentType = payload.getContentType().replace("application/", "image/")
             entry = self.__postMedia(payload.getLabel(), contentType,
                                      payload.getInputStream())
             if entry is not None:
                 id = entry.getId()
                 print " * blog.py: replacing %s with %s" % (attrValue, id)
                 content = content.replace('%s="%s"' % (attr, attrValue),
                                           '%s="%s"' % (attr, id))
                 content = content.replace("%s='%s'" % (attr, attrValue),
                                           "%s='%s'" % (attr, id))
             else:
                 print " * blog.py: failed to upload %s" % pid
     return content
Ejemplo n.º 5
0
 def __init__(self):
     print "**** formData: ", formData.get("func")
     if formData.get("func") == "open-file":
         self.__openFile()
         writer = response.getPrintWriter("text/plain")
         writer.println("{}")
         writer.close()
     else:
         self.__storage = Services.storage
         uri = URLDecoder.decode(request.getAttribute("RequestURI"))
         basePath = portalId + "/" + pageName
         self.__oid = uri[len(basePath) + 1 :]
         slash = self.__oid.rfind("/")
         self.__pid = self.__oid[slash + 1 :]
         payload = self.__storage.getPayload(self.__oid, self.__pid)
         if payload is not None:
             self.__mimeType = payload.contentType
         else:
             self.__mimeType = "application/octet-stream"
         self.__metadata = JsonConfigHelper()
         print " * detail.py: uri='%s' oid='%s' pid='%s' mimeType='%s'" % (
             uri,
             self.__oid,
             self.__pid,
             self.__mimeType,
         )
         self.__search()
Ejemplo n.º 6
0
    def _loadForm(self):
        """ Display the form and prepare the saved assessment from this assessor if exists
            The uri has to be http(s)://root/portal/assess/oid 
        """
        uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
        matches = re.match("^(.*?)/(.*?)/(.*?)$", uri)
        if matches and matches.group(3):
            self.oid = matches.group(3)
            storedObj = self.storage.getObject(self.oid)
            
            payloadList = storedObj.getPayloadIdList()
            self.assessment = None

            tfpackage = None
            for pid in payloadList:
                if pid.endswith(".tfpackage"):
                    tfpackage = pid
                    break
            if tfpackage:
                self.reviewers = self._readReviewers(storedObj, tfpackage)
            else:
                raise("No tfpakcage has been found.")
            if payloadList.contains(self.PAYLOAD):
                committeeResponses = self.getResponses(storedObj)
                self.assessment = committeeResponses.get(self.assessor) 
        else:
            self.oid = "null"
Ejemplo n.º 7
0
    def clearAllStaticCacheFile(self):
        #删除可能存在的静态文件
        strRootDir = request.getServletContext().getRealPath("/")
        strRootDir = URLDecoder.decode(strRootDir, "utf-8")
        #删除首页
        file = File(strRootDir + "index.html")
        if file.exists() and file.isFile():
            file.delete()
        file = File(strRootDir + "index.htm")
        if file.exists() and file.isFile():
            file.delete()

        strFile = strRootDir + "html" + File.separator + "subject_nav.html"
        file = File(strFile)
        if file.exists() and file.isFile():
            file.delete()

        strFile = strRootDir + "html" + File.separator + "user" + File.separator
        file = File(strFile)
        if file.exists():
            self.deleteDirectory(strFile)

        strFile = strRootDir + "html" + File.separator + "unit" + File.separator
        file = File(strFile)
        if file.exists():
            self.deleteDirectory(strFile)
        file = None
Ejemplo n.º 8
0
 def __init__(self):
     self.__storage = Services.storage
     uri = request.getAttribute("RequestURI")
     basePath = portalId + "/" + pageName
     self.__oid = URLDecoder.decode(uri[len(basePath)+1:])
     self.__dcRdf = None
     self.__metadata = JsonConfigHelper()
     self.__search()
Ejemplo n.º 9
0
 def __activate__(self, context):
     self.sessionState = context["sessionState"]
     self.services = context["Services"]
     self.security = context["security"]
     self.request = context["request"]
     self.portalId = context["portalId"]
     uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
     self.__relPath = "/".join(uri.split("/")[1:])
     self.authentication = AuthenticationData()
     self.authentication.__activate__(context)
Ejemplo n.º 10
0
 def __init__(self):
     basePath = portalId + "/" + pageName
     uri = request.getAttribute("RequestURI")
     print " * download.py: basePath=%s uri=%s" % (basePath, uri)
     uri = uri[len(basePath) + 1 :]
     if uri.find("%2F") == -1:
         slash = uri.rfind("/")
     else:
         slash = uri.find("/")
     oid = URLDecoder.decode(uri[:slash])
     pid = URLDecoder.decode(uri[slash + 1 :])
     print " * download.py: oid=%s pid=%s" % (oid, pid)
     payload = Services.storage.getPayload(oid, pid)
     filename = os.path.split(pid)[1]
     mimeType = payload.contentType
     if mimeType == "application/octet-stream":
         response.setHeader("Content-Disposition", "attachment; filename=%s" % filename)
     out = response.getOutputStream(payload.contentType)
     IOUtils.copy(payload.inputStream, out)
     out.close()
Ejemplo n.º 11
0
 def __activate__(self, context):
     self.velocityContext = context
     self.vc("sessionState").remove("fq")
     self.services = self.vc("Services")
     self.request = self.vc("request")
     self.log = context["log"]
     self.__harvestedRecords = None
     
     uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
     self.__harvestId = os.path.basename(uri)
     self.__search()
Ejemplo n.º 12
0
 def __activate__(self, context):
     self.velocityContext = context
     self.log = context["log"]
     self.sessionState = context["sessionState"]
     self.services = context["Services"]
     self.security = context["security"]
     self.request = context["request"]
     self.portalId = context["portalId"]
     uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
     self.__relPath = "/".join(uri.split("/")[1:])
     self.authentication = AuthenticationData()
     self.authentication.__activate__(context)
Ejemplo n.º 13
0
    def execute(self):
        if self.loginUser == None:
            return ActionResult.LOGIN

        accessControlService = __spring__.getBean("accessControlService")
        if accessControlService.isSystemAdmin(self.loginUser) == False:
            self.addActionError(u"没有管理站点配置的权限,只有超级管理员才能进行管理。")
            return ActionResult.ERROR

        strFile = request.getServletContext().getRealPath("/")
        strFile = strFile + "html" + File.separator
        strFile = URLDecoder.decode(strFile, "utf-8")
        file = File(strFile)
        if file.exists() == False:
            file.mkdirs()
        #创建学科导航
        strFile = strFile + "updateinfo.htm"
        file = File(strFile)
        if request.getMethod() == "POST":
            params = ParamUtil(request)
            html = params.safeGetStringParam("updateInfo")
            fw = OutputStreamWriter(FileOutputStream(file), "utf-8")
            fw.flush()
            fw.write(html)
            fw.close()
            siteIndexPartService = __spring__.getBean("siteIndexPartService")
            if html == "":
                siteIndexPart = siteIndexPartService.getSiteIndexPartByModuleName(
                    u"系统维护通知")
                if siteIndexPart != None:
                    siteIndexPartService.deleteSiteIndexPart(siteIndexPart)
            else:
                siteIndexPart = siteIndexPartService.getSiteIndexPartByModuleName(
                    u"系统维护通知")
                if siteIndexPart == None:
                    siteIndexPart = SiteIndexPart()
                siteIndexPart.setModuleName(u"系统维护通知")
                siteIndexPart.setModuleZone(1)
                siteIndexPart.setModuleOrder(0)
                siteIndexPart.setModuleDisplay(1)
                siteIndexPart.setModuleHeight(0)
                siteIndexPart.setContent(html)
                siteIndexPart.setPartType(100)
                siteIndexPart.setShowType(0)
                siteIndexPart.setShowBorder(0)
                siteIndexPartService.saveOrUpdateSiteIndexPart(siteIndexPart)
            request.setAttribute("deleteCache", "1")
        else:
            html = CommonUtil.readFile(file.getCanonicalPath(), "UTF-8")
            request.setAttribute("deleteCache", "0")

        request.setAttribute("updateInfo", html)
        return "/WEB-INF/ftl/admin/admin_site_update.ftl"
Ejemplo n.º 14
0
 def __init__(self):
     basePath = portalId + "/" + pageName
     fullUri = URLDecoder.decode(request.getAttribute("RequestURI"))
     uri = fullUri[len(basePath) + 1 :]
     try:
         object, payload = self.__resolve(uri)
         if object == None:
             response.sendRedirect(contextPath + "/" + fullUri + "/")
             return
         print "URI='%s' OID='%s' PID='%s'" % (uri, object.getId(), payload.getId())
     except StorageException, e:
         payload = None
         print "Failed to get object: %s" % (str(e))
Ejemplo n.º 15
0
    def __activate__(self, context):
        self.velocityContext = context
        self.services = context["Services"]
        self.request = context["request"]
        self.response = context["response"]
        self.contextPath = context["contextPath"]
        self.formData = context["formData"]
        self.page = context["page"]

        self.uaActivated = False
        useDownload = Boolean.parseBoolean(self.formData.get("download", "true"))
        self.__isPreview = Boolean.parseBoolean(self.formData.get("preview", "false"))
        self.__previewPid = None
        self.__hasPid = False

        uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
        matches = re.match("^(.*?)/(.*?)/(?:(.*?)/)?(.*)$", uri)
        if matches and matches.group(3):
            oid = matches.group(3)
            pid = matches.group(4)

            self.__metadata = JsonConfigHelper()
            self.__object = self.__getObject(oid)
            self.__oid = oid

            # If we have a PID
            if pid:
                self.__hasPid = True
                if useDownload:
                    # Download the payload to support relative links
                    download = DownloadData()
                    download.__activate__(context)
                else:
                    # Render the detail screen with the alternative preview
                    self.__readMetadata(oid)
                    self.__previewPid = pid
            # Otherwise, render the detail screen
            else:
                self.__readMetadata(oid)
                self.__previewPid = self.getPreview()

            if self.__previewPid:
                self.__previewPid = URLEncoder.encode(self.__previewPid, "UTF-8")
        else:
            # require trailing slash for relative paths
            q = ""
            if self.__isPreview:
                q = "?preview=true"
            self.response.sendRedirect("%s/%s/%s" % (self.contextPath, uri, q))
Ejemplo n.º 16
0
 def __getJson(self):
     data = {}
     basePath = portalId + "/" + pageName
     uri = URLDecoder.decode(request.getAttribute("RequestURI"))
     oid = uri[len(basePath)+1:]
     payload = Services.storage.getPayload(oid, "imsmanifest.xml")
     if payload is not None:
         try:
             from xml.etree import ElementTree as ElementTree
             #xml = ElementTree()
             #IOUtils.copy(payload.inputStream, out)
             sb = StringBuilder()
             inputStream = payload.inputStream
             reader = BufferedReader(InputStreamReader(inputStream,
                         "UTF-8"))
             while True:
                 line=reader.readLine()
                 if line is None:
                     break
                 sb.append(line).append("\n")
             inputStream.close()
             xmlStr =  sb.toString()
             xml = ElementTree.XML(xmlStr)
             ns = xml.tag[:xml.tag.find("}")+1]
             resources = {}
             for res in xml.findall(ns+"resources/"+ns+"resource"):
                 resources[res.attrib.get("identifier")] = res.attrib.get("href")
             #print resources
             organizations = xml.find(ns+"organizations")
             defaultName = organizations.attrib.get("default")
             organizations = organizations.findall(ns+"organization")
             organizations = [o for o in organizations if o.attrib.get("identifier")==defaultName]
             organization = organizations[0]
             title = organization.find(ns+"title").text
             data["title"] = title
             items = []
             for item in organization.findall(ns+"item"):
                 a = item.attrib
                 isVisible = a.get("isvisible")
                 idr = a.get("identifierref")
                 id = resources.get(idr)
                 iTitle = item.find(ns+"title").text
                 if isVisible and id and id.endswith(".htm"):
                     items.append({"attributes":{"id":id}, "data":iTitle})
             data["nodes"] = items
         except Exception, e:
              data["error"] = "Error - %s" % str(e)
              print data["error"]
Ejemplo n.º 17
0
 def GenSubjectNav(self):
     strFile = request.getServletContext().getRealPath("/")
     strFile = URLDecoder.decode(strFile, "utf-8")
     strSubjectFile = strFile + "html" + File.separator
     file = File(strSubjectFile)
     if file.exists() == False:
         file.mkdirs()
     #创建学科导航
     strSubjectFile = strSubjectFile + "subject_nav.html"
     file = File(strSubjectFile)
     #先得到年级
     subjectService = __spring__.getBean("subjectService")
     qry = Command(
         " SELECT DISTINCT metaGrade.gradeId FROM Subject Order By metaGrade.gradeId ASC"
     )
     mGradeId = qry.open()
     MetaGrade = ArrayList()
     metaSubject = ArrayList()
     for grade in mGradeId:
         mGrade = subjectService.getGrade(int(grade))
         MetaGrade.add(mGrade)
         subj = subjectService.getSubjectByGradeId(int(grade))
         m = ArrayList()
         if subj != None:
             for sj in range(0, subj.size()):
                 m.add(subj[sj].metaSubject)
             metaSubject.add({
                 "gradeName": mGrade.gradeName,
                 "gradeId": grade,
                 "metaSubject": m
             })
     map = HashMap()
     map.put("metaGrade", MetaGrade)
     map.put("meta_Grade", MetaGrade)
     map.put("SubjectNav", metaSubject)
     templateProcessor = __spring__.getBean("templateProcessor")
     str = templateProcessor.processTemplate(
         map, "/WEB-INF/ftl/site_subject_nav.ftl", "utf-8")
     try:
         fw = OutputStreamWriter(FileOutputStream(file), "utf-8")
         fw.flush()
         fw.write(str)
         fw.close()
     finally:
         file = None
         fw = None
Ejemplo n.º 18
0
 def __init__(self):
     self.__storage = Services.storage
     uri = URLDecoder.decode(request.getAttribute("RequestURI"))
     basePath = portalId + "/" + pageName
     self.__oid = uri[len(basePath)+1:]
     slash = self.__oid.rfind("/")
     self.__pid = self.__oid[slash+1:]
     print " * detail.py: uri='%s' oid='%s' pid='%s'" % (uri, self.__oid, self.__pid)
     if formData.get("verb") == "open":
         self.__openFile()
     else:
         payload = self.__storage.getPayload(self.__oid, self.__pid)
         if payload is not None:
             self.__mimeType = payload.contentType
         else:
             self.__mimeType = "application/octet-stream"
         self.__metadata = JsonConfigHelper()
         self.__search()
Ejemplo n.º 19
0
 def __init__(self):
     self.__portal = Services.portalManager.get(portalId)
     self.__result = JsonConfigHelper()
     self.__pageNum = sessionState.get("pageNum", 1)
     self.__selected = []
     self.__storage = Services.storage
     uri = URLDecoder.decode(request.getAttribute("RequestURI"))
     basePath = portalId + "/" + pageName
     self.__oid = uri[len(basePath)+1:]
     slash = self.__oid.rfind("/")
     self.__pid = self.__oid[slash+1:]
     payload = self.__storage.getPayload(self.__oid, self.__pid)
     if payload is not None:
         self.__mimeType = payload.contentType
     else:
         self.__mimeType = "application/octet-stream"
     self.__metadata = JsonConfigHelper()
     print " * combined.py: uri='%s' oid='%s' pid='%s' mimeType='%s'" % (uri, self.__oid, self.__pid, self.__mimeType)
     self.__search()
Ejemplo n.º 20
0
    def getObject(self):
        if self.__object is None:
            # Grab the URL
            req = self.vc("request").getAttribute("RequestURI")
            uri = URLDecoder.decode(req)
            # Cut everything down to the OID
            basePath = self.vc("portalId") + "/" + self.vc("pageName")
            oid = uri[len(basePath)+1:]
            # Trim a trailing slash
            if oid.endswith("/"):
                oid = oid[:-1]

            # Now get the object
            if oid is not None:
                try:
                    self.__object = Services.storage.getObject(oid)
                    return self.__object
                except StorageException, e:
                    self.vc("log").error("Failed to retrieve object : " + e.getMessage())
                    return None
Ejemplo n.º 21
0
    def getObject(self):
        if self.__object is None:
            # Grab the URL
            req = self.vc("request").getAttribute("RequestURI")
            uri = URLDecoder.decode(req)
            # Cut everything down to the OID
            basePath = self.vc("portalId") + "/" + self.vc("pageName")
            oid = uri[len(basePath) + 1:]
            # Trim a trailing slash
            if oid.endswith("/"):
                oid = oid[:-1]

            # Now get the object
            if oid is not None:
                try:
                    self.__object = Services.storage.getObject(oid)
                    return self.__object
                except StorageException, e:
                    self.vc("log").error("Failed to retrieve object : " +
                                         e.getMessage())
                    return None
Ejemplo n.º 22
0
 def __init__(self):
     basePath = portalId + "/" + pageName
     uri = URLDecoder.decode(request.getAttribute("RequestURI"))
     uri = uri[len(basePath)+1:]
     oid, pid, payload = self.__resolve(uri)
     print """ * download.py: uri='%s'
             oid='%s'
             pid='%s'
             payload='%s'""" % (uri, oid, pid, payload)
     if payload is not None:
         filename = os.path.split(pid)[1]
         mimeType = payload.contentType
         if mimeType == "application/octet-stream":
             response.setHeader("Content-Disposition", "attachment; filename=%s" % filename)
         out = response.getOutputStream(payload.contentType)
         IOUtils.copy(payload.inputStream, out)
         out.close()
     else:
         response.setStatus(404)
         writer = response.getPrintWriter("text/plain")
         writer.println("Not found: uri='%s'" % uri)
         writer.close()
Ejemplo n.º 23
0
 def __parseUri(self, uri):
     page = 1
     fq = []
     fqParts = []
     if uri != "":
         parts = uri.split("/")
         partType = None
         facetKey = None
         facetValues = None
         for part in parts:
             if partType == "page":
                 facetKey = None
                 page = int(part)
             elif partType == "category":
                 partType = "category-value"
                 facetValues = None
                 facetKey = part
             elif partType == "category-value":
                 if facetValues is None:
                     facetValues = []
                 if part in ["page", "category"]:
                     partType = part
                     facetQuery = '%s:"%s"' % (facetKey,
                                               "/".join(facetValues))
                     fq.append(facetQuery)
                     fqParts.append("category/%s/%s" %
                                    (facetKey, "/".join(facetValues)))
                     facetKey = None
                     facetValues = None
                 else:
                     facetValues.append(URLDecoder.decode(part))
             else:
                 partType = part
         if partType == "category-value":
             facetQuery = '%s:"%s"' % (facetKey, "/".join(facetValues))
             fq.append(facetQuery)
             fqParts.append("category/%s/%s" %
                            (facetKey, "/".join(facetValues)))
     return page, fq, fqParts
 def __activate__(self, context):
     self.request = context["request"]
     self.services = context["Services"]
     
     self.__metadata = JsonSimple()
     
     # get the oid
     uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
     matches = re.match("^(.*?)/(.*?)/(?:(.*?)/)?(.*)$", uri)
     if matches and matches.group(3):
         oid = matches.group(3)
         
     self.__object = self.services.getStorage().getObject(oid)
     
     self.__mergeData()
     
     response = context["response"]
     response.setHeader("Content-Disposition", "attachment; filename=metadata.json")
     writer = response.getPrintWriter("application/json; charset=UTF-8")
     #Content-Disposition
     writer.println(self.__metadata)
     writer.close()
Ejemplo n.º 25
0
 def __uploadMedia(self, oid, doc, content, elem, attr):
     links = doc.getElementsByTagName(elem)
     for i in range(0, links.getLength()):
         elem = links.item(i)
         attrValue = elem.getAttribute(attr)
         if attrValue == '' or attrValue.startswith("#") \
             or attrValue.startswith("mailto:") \
             or attrValue.find("://") != -1:
             continue
         pid = attrValue
         print "uploading '%s' (%s, %s)" % (pid, elem.tagName, attr)
         found = False
         try:
             payload = self.__getObject(oid).getPayload(pid)
             found = True
         except Exception, e:
             pid = URLDecoder.decode(pid, "UTF-8")
             try:
                 payload = self.__getObject(oid).getPayload(pid)
                 found = True
             except Exception, e:
                 print "payload not found '%s'" % pid
Ejemplo n.º 26
0
 def __parseUri(self, uri):
     page = 1
     fq = []
     fqParts = []
     if uri != "":
         parts = uri.split("/")
         partType = None
         facetKey = None
         facetValues = None
         for part in parts:
             if partType == "page":
                 facetKey = None
                 facetValue = None
                 page = int(part)
             elif partType == "category":
                 partType = "category-value"
                 facetValues = None
                 facetKey = part
             elif partType == "category-value":
                 if facetValues is None:
                     facetValues = []
                 if part in ["page", "category"]:
                     partType = part
                     facetQuery = '%s:"%s"' % (facetKey, "/".join(facetValues))
                     fq.append(facetQuery)
                     fqParts.append("category/%s/%s" % (facetKey, "/".join(facetValues)))
                     facetKey = None
                     facetValues = None
                 else:
                     facetValues.append(URLDecoder.decode(part))
             else:
                 partType = part
         if partType == "category-value":
             facetQuery = '%s:"%s"' % (facetKey, "/".join(facetValues))
             fq.append(facetQuery)
             fqParts.append("category/%s/%s" % (facetKey, "/".join(facetValues)))
     return page, fq, fqParts
Ejemplo n.º 27
0
    def __search(self):
        requireEscape = False
        recordsPerPage = self.__portal.recordsPerPage
        uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
        query = None
        pagePath = self.__portal.getName() + "/" + self.pageName
        if query is None or query == "":
            query = self.formData.get("query")
            requireEscape = True
        if query is None or query == "":
            query = "*:*"

        if query == "*:*":
            self.__query = ""
        else:
            self.__query = query
            if requireEscape:
                query = self.__escapeQuery(query)
            query = "%s:%s" % (self.__searchField, query)
        self.sessionState.set("query", self.__query)

        # find objects with annotations matching the query
        if query != "*:*":
            anotarQuery = self.__query
            if requireEscape:
                anotarQuery = self.__escapeQuery(anotarQuery)
            annoReq = SearchRequest(anotarQuery)
            annoReq.setParam("facet", "false")
            annoReq.setParam("rows", str(99999))
            annoReq.setParam("sort", "dateCreated asc")
            annoReq.setParam("start", str(0))
            anotarOut = ByteArrayOutputStream()
            self.services.indexer.annotateSearch(annoReq, anotarOut)
            resultForAnotar = SolrResult(
                ByteArrayInputStream(anotarOut.toByteArray()))
            resultForAnotar = resultForAnotar.getResults()
            ids = HashSet()
            for annoDoc in resultForAnotar:
                annotatesUri = annoDoc.getFirst("annotatesUri")
                ids.add(annotatesUri)
                self.log.debug("Found annotation for %s" % annotatesUri)
            # add annotation ids to query
            query += ' OR id:("' + '" OR "'.join(ids) + '")'

        portalSearchQuery = self.__portal.searchQuery
        if portalSearchQuery == "":
            portalSearchQuery = query
        else:
            if query != "*:*":
                query += " AND " + portalSearchQuery
            else:
                query = portalSearchQuery

        req = SearchRequest(query)
        req.setParam("facet", "true")
        req.setParam("rows", str(recordsPerPage))
        req.setParam("facet.field", self.__portal.facetFieldList)
        req.setParam("facet.sort",
                     Boolean.toString(self.__portal.getFacetSort()))
        req.setParam("facet.limit", str(self.__portal.facetCount))
        req.setParam("sort", self.__sortBy)

        # setup facets
        if self.__useSessionNavigation:
            action = self.formData.get("verb")
            value = self.formData.get("value")
            fq = self.sessionState.get("fq")
            if fq is not None:
                self.__pageNum = 1
                req.setParam("fq", fq)
            if action == "add_fq":
                self.__pageNum = 1
                req.addParam("fq", URLDecoder.decode(value, "UTF-8"))
            elif action == "remove_fq":
                self.__pageNum = 1
                req.removeParam("fq", URLDecoder.decode(value, "UTF-8"))
            elif action == "clear_fq":
                self.__pageNum = 1
                req.removeParam("fq")
            elif action == "select-page":
                self.__pageNum = int(value)
        else:
            navUri = uri[len(pagePath):]
            self.__pageNum, fq, self.__fqParts = self.__parseUri(navUri)
            savedfq = self.sessionState.get("savedfq")
            limits = []
            if savedfq:
                limits.extend(savedfq)
            if fq:
                limits.extend(fq)
                self.sessionState.set("savedfq", limits)
                for q in fq:
                    req.addParam("fq", URLDecoder.decode(q, "UTF-8"))

        portalQuery = self.__portal.query
        if portalQuery:
            req.addParam("fq", portalQuery)
        req.addParam("fq", 'item_type:"object"')
        if req.getParams("fq"):
            self.__selected = ArrayList(req.getParams("fq"))

        if self.__useSessionNavigation:
            self.sessionState.set("fq", self.__selected)
            self.sessionState.set("searchQuery", portalSearchQuery)
            self.sessionState.set("pageNum", self.__pageNum)

        # Make sure 'fq' has already been set in the session
        if not self.page.authentication.is_admin():
            current_user = self.page.authentication.get_username()
            security_roles = self.page.authentication.get_roles_list()
            security_filter = 'security_filter:("' + '" OR "'.join(
                security_roles) + '")'
            security_exceptions = 'security_exception:"' + current_user + '"'
            owner_query = 'owner:"' + current_user + '"'
            security_query = "(" + security_filter + ") OR (" + security_exceptions + ") OR (" + owner_query + ")"
            req.addParam("fq", security_query)
        ## uncomment to ensure guest users not logged in cannot see alerts in browse page
        # self.filterOutWorkflowStepForUnAuth(req, "inbox")

        req.setParam("start", str((self.__pageNum - 1) * recordsPerPage))

        self.log.debug(" * search.py: %s, page: %s" %
                       (req.toString(), self.__pageNum))

        out = ByteArrayOutputStream()
        self.services.indexer.search(req, out)
        self.__result = SolrResult(ByteArrayInputStream(out.toByteArray()))
        if self.__result is not None:
            self.__paging = Pagination(self.__pageNum,
                                       self.__result.getNumFound(),
                                       self.__portal.recordsPerPage)
Ejemplo n.º 28
0
    def __search(self):
        recordsPerPage = self.__portal.recordsPerPage
        
        uri = URLDecoder.decode(request.getAttribute("RequestURI"))
        query = None
        pagePath = portalId + "/" + pageName
        if uri != pagePath:
            query = uri[len(pagePath)+1:]
        if query is None or query == "":
            query = formData.get("query")
        if query is None or query == "":
            query = "*:*"
        
        if query == "*:*":
            self.__query = ""
        else:
            self.__query = query
        sessionState.set("query", self.__query)
        
        # find objects with annotations matching the query
        if query != "*:*":
            anotarQuery = self.__query
            annoReq = SearchRequest(anotarQuery)
            annoReq.setParam("facet", "false")
            annoReq.setParam("rows", str(99999))
            annoReq.setParam("sort", "dateCreated asc")
            annoReq.setParam("start", str(0))        
            anotarOut = ByteArrayOutputStream()
            Services.indexer.annotateSearch(annoReq, anotarOut)
            resultForAnotar = JsonConfigHelper(ByteArrayInputStream(anotarOut.toByteArray()))
            resultForAnotar = resultForAnotar.getJsonList("response/docs")
            ids = HashSet()
            for annoDoc in resultForAnotar:
                annotatesUri = annoDoc.get("annotatesUri")
                ids.add(annotatesUri)
                print "Found annotation for %s" % annotatesUri
            # add annotation ids to query
            query += ' OR id:("' + '" OR "'.join(ids) + '")'

        portalSearchQuery = self.__portal.searchQuery
        if portalSearchQuery == "":
            portalSearchQuery = query
        else:
            if query != "*:*":
                query += " AND " + portalSearchQuery
            else:
                query = portalSearchQuery

        req = SearchRequest(query)
        req.setParam("facet", "true")
        req.setParam("rows", str(recordsPerPage))
        req.setParam("facet.field", self.__portal.facetFieldList)
        req.setParam("facet.sort", "true")
        req.setParam("facet.limit", str(self.__portal.facetCount))
        req.setParam("sort", "f_dc_title asc")
        
        # setup facets
        action = formData.get("verb")
        value = formData.get("value")
        fq = sessionState.get("fq")
        if fq is not None:
            self.__pageNum = 1
            req.setParam("fq", fq)
        if action == "add_fq":
            self.__pageNum = 1
            name = formData.get("name")
            print " * add_fq: %s" % value
            req.addParam("fq", URLDecoder.decode(value, "UTF-8"))
        elif action == "remove_fq":
            self.__pageNum = 1
            req.removeParam("fq", URLDecoder.decode(value, "UTF-8"))
        elif action == "clear_fq":
            self.__pageNum = 1
            req.removeParam("fq")
        elif action == "select-page":
            self.__pageNum = int(value)
        req.addParam("fq", 'item_type:"object"')
        
        portalQuery = self.__portal.query
        print " * portalQuery=%s" % portalQuery
        if portalQuery:
            req.addParam("fq", portalQuery)
        
        self.__selected = list(req.getParams("fq"))

        sessionState.set("fq", self.__selected)
        sessionState.set("searchQuery", portalSearchQuery)
        sessionState.set("pageNum", self.__pageNum)
        
        # Make sure 'fq' has already been set in the session
        if not page.authentication.is_admin():
            security_roles = page.authentication.get_roles_list()
            security_query = 'security_filter:("' + '" OR "'.join(security_roles) + '")'
            current_user = page.authentication.get_username()
            owner_query = 'owner:"' + current_user + '"'
            req.addParam("fq", "(" + security_query + ") OR (" + owner_query + ")")

        req.setParam("start", str((self.__pageNum - 1) * recordsPerPage))
        
        print " * search.py:", req.toString(), self.__pageNum
        
        out = ByteArrayOutputStream()
        Services.indexer.search(req, out)
        self.__result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
        if self.__result is not None:
            self.__paging = Pagination(self.__pageNum,
                                       int(self.__result.get("response/numFound")),
                                       self.__portal.recordsPerPage)
Ejemplo n.º 29
0
    def __search(self):
        recordsPerPage = self.__portal.recordsPerPage

        query = None
        if query is None or query == "":
            query = formData.get("query")
        if query is None or query == "":
            query = "*:*"

        req = SearchRequest(query)
        req.setParam("facet", "true")
        req.setParam("rows", "1000")
        req.setParam("facet.field", self.__portal.facetFieldList)
        req.setParam("facet.sort", "true")
        req.setParam("facet.limit", str(self.__portal.facetCount))
        req.setParam("sort", "f_dc_title asc")

        # setup facets
        action = formData.get("verb")
        value = formData.get("value")
        fq = sessionState.get("fq")
        if fq is not None:
            self.__pageNum = 1
            req.setParam("fq", fq)
        if action == "add_fq":
            self.__pageNum = 1
            name = formData.get("name")
            print " * add_fq: %s" % value
            req.addParam("fq", URLDecoder.decode(value, "UTF-8"))
        elif action == "remove_fq":
            self.__pageNum = 1
            req.removeParam("fq", URLDecoder.decode(value, "UTF-8"))
        elif action == "clear_fq":
            self.__pageNum = 1
            req.removeParam("fq")
        elif action == "select-page":
            self.__pageNum = int(value)
        req.addParam("fq", 'item_type:"object"')

        portalQuery = self.__portal.query
        print " * portalQuery=%s" % portalQuery
        if portalQuery:
            req.addParam("fq", portalQuery)

        self.__selected = req.getParams("fq")

        sessionState.set("fq", self.__selected)
        sessionState.set("pageNum", self.__pageNum)

        req.setParam("start", str((self.__pageNum - 1) * recordsPerPage))

        print " * single.py:", req.toString(), self.__pageNum

        out = ByteArrayOutputStream()
        Services.indexer.search(req, out)
        self.__result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
        if self.__result is not None:
            self.__paging = Pagination(
                self.__pageNum, int(self.__result.get("response/numFound")), self.__portal.recordsPerPage
            )
            print " * single.py: updating manifest..."
            portal = self.getPortal()
            manifest = portal.getJsonMap("manifest")
            # add new items from search
            for doc in self.__result.getList("response/docs"):
                hashId = md5.new(doc.get("id")).hexdigest()
                node = portal.get("manifest//node-%s" % hashId)
                if node is None:
                    portal.set("manifest/node-%s/title" % hashId, doc.get("dc_title").get(0))
                    portal.set("manifest/node-%s/id" % hashId, doc.get("id"))
            # remove manifest items missing from search result
            # print manifest
            for key in manifest.keySet():
                item = manifest.get(key)
                id = item.get("id")
                doc = self.__result.getList('response/docs[@id="%s"]' % id)
                if len(doc) == 0:
                    portal.removePath("manifest//%s" % key)
            Services.getPortalManager().save(portal)
 def __activate__(self, context):
     self.velocityContext = context
     self.log = self.vc("log")
     self.systemConfig = self.vc("systemConfig")
     self.session = self.vc("sessionState")
     self.response = self.vc("response")
     self.request = self.vc("request")
     self.msg = ""
     self.appId = None
     
     uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
     matches = re.match("^(.*?)/(.*?)/(.*?)/(.*?)/(.*?)$", uri)
     if matches and matches.group(5):    
         self.appId = matches.group(5)
         
     if not self.appId:
         self.msg = "No appId specified"
         self.log.error(self.msg)
         return
     self.log.debug("Getting configuration for: " + self.appId)
     self.consumerName = self.systemConfig.getString(None, "authserver", self.appId, "name")
     self.sharedKey = self.systemConfig.getString(None, "authserver", self.appId, "sharedKey")
     self.aud = self.systemConfig.getString(None, "authserver", self.appId, "aud")
     self.iss = self.systemConfig.getString(None, "authserver", self.appId, "iss")
     self.expiry = self.systemConfig.getInteger(None, "authserver", self.appId, "expiry")
     self.logoutUrl = self.systemConfig.getString(None, "authserver", self.appId, "logoutUrl")
     logout = self.request.getParameter("logout")
     if logout == "1":
         self.session.invalidate()
         self.response.sendRedirect(self.logoutUrl)
         return
     if not self.consumerName:
         self.msg = "Invalid configuration, no app name"
         self.log.error(self.msg)
         return
     if not self.sharedKey:
         self.msg = "Invalid shared Key"
         self.log.error(self.msg)
         return
     if not self.aud:
         self.msg = "Invalid aud"
         self.log.error(self.msg)
         return
     if not self.iss:
         self.msg = "Invalid iss"
         self.log.error(self.msg)
         return
     if not self.expiry:
         self.msg = "Invalid expiry"
         self.log.error(self.msg)
         return
                         
     # Because we don't trust the configuration
     current_user = self.vc("page").authentication.get_username()
     isAdmin = self.vc("page").authentication.is_admin()
     # Admin only... 
     if not isAdmin:
         self.msg = "Sorry, this page is only for administrators."
         self.log.error(self.msg)
         return
     # Get the roles...
     typ = "[\"" + "\",\"".join(self.vc("page").authentication.get_roles_list()) + "\"]"
     # Generating signature...
     dtNow = Date().getTime()
     now = dtNow / 1000
     iat = now
     nbf = now - 1
     exp = now + self.expiry
     secRandom = SecureRandom()
     jti = Long.toString(dtNow) + "_" + Integer.toString(secRandom.nextInt())
     payload = Payload('{"iss":"%s",  "sub":"%s", "aud":"%s", "iat":"%s", "nbf":"%s", "exp":"%s", "jti":"%s", "typ":%s}' % (self.iss, current_user, self.aud, iat, nbf, exp, jti, typ))
     jwsHeader = JWSHeader(JWSAlgorithm.HS256)
     macSigner = MACSigner(self.sharedKey)
     jwsObject = JWSObject(jwsHeader, payload)
     jwsObject.sign(macSigner)
     self.jws = jwsObject.serialize()
Ejemplo n.º 31
0
 def getName(self):
     name = URLDecoder.decode(self.__value, "UTF-8")
     slash = name.rfind("/")
     return name[slash+1:]
Ejemplo n.º 32
0
    def __activate__(self, context):
        self.velocityContext = context
        self.log = self.vc("log")
        self.systemConfig = self.vc("systemConfig")
        self.session = self.vc("sessionState")
        self.response = self.vc("response")
        self.request = self.vc("request")
        self.msg = ""
        self.appId = None

        uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
        matches = re.match("^(.*?)/(.*?)/(.*?)/(.*?)/(.*?)$", uri)
        if matches and matches.group(5):
            self.appId = matches.group(5)

        if not self.appId:
            self.msg = "No appId specified"
            self.log.error(self.msg)
            return
        self.log.debug("Getting configuration for: " + self.appId)
        self.consumerName = self.systemConfig.getString(
            None, "authserver", self.appId, "name")
        self.sharedKey = self.systemConfig.getString(None, "authserver",
                                                     self.appId, "sharedKey")
        self.aud = self.systemConfig.getString(None, "authserver", self.appId,
                                               "aud")
        self.iss = self.systemConfig.getString(None, "authserver", self.appId,
                                               "iss")
        self.expiry = self.systemConfig.getInteger(None, "authserver",
                                                   self.appId, "expiry")
        self.logoutUrl = self.systemConfig.getString(None, "authserver",
                                                     self.appId, "logoutUrl")
        logout = self.request.getParameter("logout")
        if logout == "1":
            self.session.invalidate()
            self.response.sendRedirect(self.logoutUrl)
            return
        if not self.consumerName:
            self.msg = "Invalid configuration, no app name"
            self.log.error(self.msg)
            return
        if not self.sharedKey:
            self.msg = "Invalid shared Key"
            self.log.error(self.msg)
            return
        if not self.aud:
            self.msg = "Invalid aud"
            self.log.error(self.msg)
            return
        if not self.iss:
            self.msg = "Invalid iss"
            self.log.error(self.msg)
            return
        if not self.expiry:
            self.msg = "Invalid expiry"
            self.log.error(self.msg)
            return

        # Because we don't trust the configuration
        current_user = self.vc("page").authentication.get_username()
        isAdmin = self.vc("page").authentication.is_admin()
        # Admin only...
        if not isAdmin:
            self.msg = "Sorry, this page is only for administrators."
            self.log.error(self.msg)
            return
        # Get the roles...
        typ = "[\"" + "\",\"".join(
            self.vc("page").authentication.get_roles_list()) + "\"]"
        # Generating signature...
        dtNow = Date().getTime()
        now = dtNow / 1000
        iat = now
        nbf = now - 1
        exp = now + self.expiry
        secRandom = SecureRandom()
        jti = Long.toString(dtNow) + "_" + Integer.toString(
            secRandom.nextInt())
        payload = Payload(
            '{"iss":"%s",  "sub":"%s", "aud":"%s", "iat":"%s", "nbf":"%s", "exp":"%s", "jti":"%s", "typ":%s}'
            % (self.iss, current_user, self.aud, iat, nbf, exp, jti, typ))
        jwsHeader = JWSHeader(JWSAlgorithm.HS256)
        macSigner = MACSigner(self.sharedKey)
        jwsObject = JWSObject(jwsHeader, payload)
        jwsObject.sign(macSigner)
        self.jws = jwsObject.serialize()
Ejemplo n.º 33
0
 def __search(self):
     recordsPerPage = self.__portal.recordsPerPage
     
     query = None
     if query is None or query == "":
         query = formData.get("query")
     if query is None or query == "":
         query = "*:*"
     
     req = SearchRequest(query)
     req.setParam("facet", "true")
     req.setParam("rows", "1000")
     req.setParam("facet.field", self.__portal.facetFieldList)
     req.setParam("facet.sort", "true")
     req.setParam("facet.limit", str(self.__portal.facetCount))
     req.setParam("sort", "f_dc_title asc")
     
     # setup facets
     action = formData.get("verb")
     value = formData.get("value")
     fq = sessionState.get("fq")
     if fq is not None:
         self.__pageNum = 1
         req.setParam("fq", fq)
     if action == "add_fq":
         self.__pageNum = 1
         name = formData.get("name")
         print " * add_fq: %s" % value
         req.addParam("fq", URLDecoder.decode(value, "UTF-8"))
     elif action == "remove_fq":
         self.__pageNum = 1
         req.removeParam("fq", URLDecoder.decode(value, "UTF-8"))
     elif action == "clear_fq":
         self.__pageNum = 1
         req.removeParam("fq")
     elif action == "select-page":
         self.__pageNum = int(value)
     req.addParam("fq", 'item_type:"object"')
     
     portalQuery = self.__portal.query
     print " * portalQuery=%s" % portalQuery
     if portalQuery:
         req.addParam("fq", portalQuery)
     
     self.__selected = req.getParams("fq")
     
     sessionState.set("fq", self.__selected)
     sessionState.set("pageNum", self.__pageNum)
     
     req.setParam("start", str((self.__pageNum - 1) * recordsPerPage))
     
     print " * combined.py:", req.toString(), self.__pageNum
     
     out = ByteArrayOutputStream()
     Services.indexer.search(req, out)
     self.__result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
     if self.__result is not None:
         self.__paging = Pagination(self.__pageNum,
                                    int(self.__result.get("response/numFound")),
                                    self.__portal.recordsPerPage)
         print " * combined.py: updating manifest..."
         portal = self.getPortal()
         manifest = portal.getJsonMap("manifest")
         #add new items from search
         for doc in self.__result.getList("response/docs"):
             hashId = md5.new(doc.get("id")).hexdigest()
             node = portal.get("manifest//node-%s" % hashId)
             print " ********node=", node
             if node is None:
                 portal.set("manifest/node-%s/title" % hashId, doc.get("dc_title").get(0))
                 portal.set("manifest/node-%s/id" % hashId, doc.get("id"))
         #remove manifest items missing from search result
         print manifest
         for key in manifest.keySet():
             item = manifest.get(key)
             id = item.get("id")
             doc = self.__result.getList('response/docs[@id="%s"]' % id)
             if len(doc) == 0:
                 portal.removePath("manifest//%s" % key)
         Services.getPortalManager().save(portal)
Ejemplo n.º 34
0
 def getId(self):
     return md5.new(URLDecoder.decode(self.getFacetQuery(), "UTF-8")).hexdigest()
Ejemplo n.º 35
0
 def __search(self):
     requireEscape = False
     recordsPerPage = self.__portal.recordsPerPage
     uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
     query = None
     pagePath = self.__portal.getName() + "/" + self.pageName
     if query is None or query == "":
         query = self.formData.get("query")
         requireEscape = True
     if query is None or query == "":
         query = "*:*"
     
     if query == "*:*":
         self.__query = ""
     else:
         self.__query = query
         if requireEscape:
             query = self.__escapeQuery(query)
         query = "%s:%s" % (self.__searchField, query)
     self.sessionState.set("query", self.__query)
     
     # find objects with annotations matching the query
     if query != "*:*":
         anotarQuery = self.__query
         if requireEscape:
             anotarQuery = self.__escapeQuery(anotarQuery)
         annoReq = SearchRequest(anotarQuery)
         annoReq.setParam("facet", "false")
         annoReq.setParam("rows", str(99999))
         annoReq.setParam("sort", "dateCreated asc")
         annoReq.setParam("start", str(0))
         anotarOut = ByteArrayOutputStream()
         self.services.indexer.annotateSearch(annoReq, anotarOut)
         resultForAnotar = SolrResult(ByteArrayInputStream(anotarOut.toByteArray()))
         resultForAnotar = resultForAnotar.getResults()
         ids = HashSet()
         for annoDoc in resultForAnotar:
             annotatesUri = annoDoc.getFirst("annotatesUri")
             ids.add(annotatesUri)
             self.log.debug("Found annotation for %s" % annotatesUri)
         # add annotation ids to query
         query += ' OR id:("' + '" OR "'.join(ids) + '")'
     
     portalSearchQuery = self.__portal.searchQuery
     if portalSearchQuery == "":
         portalSearchQuery = query
     else:
         if query != "*:*":
             query += " AND " + portalSearchQuery
         else:
             query = portalSearchQuery
     
     req = SearchRequest(query)
     req.setParam("facet", "true")
     req.setParam("rows", str(recordsPerPage))
     req.setParam("facet.field", self.__portal.facetFieldList)
     req.setParam("facet.sort", Boolean.toString(self.__portal.getFacetSort()))
     req.setParam("facet.limit", str(self.__portal.facetCount))
     req.setParam("sort", self.__sortBy)
     
     # setup facets
     if self.__useSessionNavigation:
         action = self.formData.get("verb")
         value = self.formData.get("value")
         fq = self.sessionState.get("fq")
         if fq is not None:
             self.__pageNum = 1
             req.setParam("fq", fq)
         if action == "add_fq":
             self.__pageNum = 1
             req.addParam("fq", URLDecoder.decode(value, "UTF-8"))
         elif action == "remove_fq":
             self.__pageNum = 1
             req.removeParam("fq", URLDecoder.decode(value, "UTF-8"))
         elif action == "clear_fq":
             self.__pageNum = 1
             req.removeParam("fq")
         elif action == "select-page":
             self.__pageNum = int(value)
     else:
         navUri = uri[len(pagePath):]
         self.__pageNum, fq, self.__fqParts = self.__parseUri(navUri)
         savedfq = self.sessionState.get("savedfq")
         limits = []
         if savedfq:
             limits.extend(savedfq)
         if fq:
             limits.extend(fq)
             self.sessionState.set("savedfq", limits)
             for q in fq:
                 req.addParam("fq", URLDecoder.decode(q, "UTF-8"))
     
     portalQuery = self.__portal.query
     if portalQuery:
         req.addParam("fq", portalQuery)
     req.addParam("fq", 'item_type:"object"')
     if req.getParams("fq"):
         self.__selected = ArrayList(req.getParams("fq"))
     
     if self.__useSessionNavigation:
         self.sessionState.set("fq", self.__selected)
         self.sessionState.set("searchQuery", portalSearchQuery)
         self.sessionState.set("pageNum", self.__pageNum)
     
     # Make sure 'fq' has already been set in the session
     if not self.page.authentication.is_admin():
         current_user = self.page.authentication.get_username()
         security_roles = self.page.authentication.get_roles_list()
         security_filter = 'security_filter:("' + '" OR "'.join(security_roles) + '")'
         security_exceptions = 'security_exception:"' + current_user + '"'
         owner_query = 'owner:"' + current_user + '"'
         security_query = "(" + security_filter + ") OR (" + security_exceptions + ") OR (" + owner_query + ")"
         req.addParam("fq", security_query)
     
     req.setParam("start", str((self.__pageNum - 1) * recordsPerPage))
     
     #print " * search.py:", req.toString(), self.__pageNum
     
     out = ByteArrayOutputStream()
     self.services.indexer.search(req, out)
     self.__result = SolrResult(ByteArrayInputStream(out.toByteArray()))
     if self.__result is not None:
         self.__paging = Pagination(self.__pageNum,
                                    self.__result.getNumFound(),
                                    self.__portal.recordsPerPage)