def GenSubjectNav(self): subjectService = __spring__.getBean("subjectService") mGradeId = subjectService.getGradeIdList() 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) map.put("SiteUrl", CommonUtil.getContextUrl(request)) templateProcessor = __spring__.getBean("templateProcessor") str = templateProcessor.processTemplate(map, "/WEB-INF/ftl/site_subject_nav.ftl", "utf-8") rootPath = JitarRequestContext.getRequestContext().getServletContext().getRealPath("/") fileIndex = rootPath + "html" + File.separator + "subject_nav.html" try: file = File(fileIndex) fw = OutputStreamWriter(FileOutputStream(file), "utf-8") # fw = FileWriter(file, False) fw.flush() fw.write(str) fw.close() finally: file = None fw = None
def process(self, input_stream, output_stream): try: writer = OutputStreamWriter(output_stream, "UTF-8") reader = BufferedReader(InputStreamReader(input_stream, "UTF-8")) line = reader.readLine() found_quote_flag = False while line != None: # Write the line always writer.write(line) # If there is an odd number of double quotes (free text field) # then there is a newline somewhere in one of the column fields. # Raise the flag to not add any newlines until we've found the matching # line that contains an odd number of quotes if line.count('"') % 2 != 0: found_quote_flag = not found_quote_flag if not found_quote_flag: writer.write('\n') line = reader.readLine() writer.flush() writer.close() reader.close() except: traceback.print_exc(file=sys.stdout) raise
def process(self, inputStream, outputStream): try: self.total = 0 reader = InputStreamReader(inputStream, "UTF-8") bufferedReader = BufferedReader(reader) writer = OutputStreamWriter(outputStream, "UTF-8") line = bufferedReader.readLine() while line != None: ChangedRec = line.upper() writer.write(ChangedRec) writer.write('\n') a = line.split(",") for valu in a: b = valu.strip() self.total += int(b) line = bufferedReader.readLine() print("Summation of Records are %s ", self.total) writer.flush() writer.close() reader.close() bufferedReader.close() except: print "Exception in Reader:" print '-' * 60 traceback.print_exc(file=sys.stdout) print '-' * 60 raise session.transfer(flowFile, ExecuteScript.REL_FAILURE) finally: if bufferedReader is not None: bufferedReader.close() if reader is not None: reader.close()
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"
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
def create_subject_nav(self): 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) map.put("SiteUrl", request.getContextPath() + "/") templateProcessor = __spring__.getBean("templateProcessor") str = templateProcessor.processTemplate(map, "/WEB-INF/ftl/site_subject_nav.ftl", "utf-8") rootPath = JitarRequestContext.getRequestContext().getServletContext().getRealPath("/") fileIndex = rootPath + "html" + File.separator + "subject_nav.html" try: file = File(fileIndex) fw = OutputStreamWriter(FileOutputStream(file), "utf-8") #fw = FileWriter(file, False) fw.flush() fw.write(str) fw.close() finally: file = None fw = None request.setAttribute("errorMessage", u"生成学科导航缓存文件完毕!")
def GenSubjectNav(self, strPath): # 先得到年级 subjectService = __spring__.getBean("subjectService") mGradeId = subjectService.getGradeIdList() 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) map.put("SiteUrl", self.get_context_url()) templateProcessor = __spring__.getBean("templateProcessor") str = templateProcessor.processTemplate( map, "/WEB-INF/ftl/site_subject_nav.ftl", "utf-8") try: file = File(strPath) fw = OutputStreamWriter(FileOutputStream(file), "utf-8") fw.flush() fw.write(str) fw.close() finally: file = None fw = None