Java Code Examples for javax.servlet.http.HttpServletRequest#getServerPort()

The following examples show how to use javax.servlet.http.HttpServletRequest#getServerPort() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: SuperBoot   File: RequestUtil.java    License: MIT License 6 votes vote down vote up
/**
 * 获取请求basePath
 *
 * @param request
 * @return
 */
public static String getBasePath(HttpServletRequest request) {
    StringBuffer basePath = new StringBuffer();
    String scheme = request.getScheme();
    String domain = request.getServerName();
    int port = request.getServerPort();
    basePath.append(scheme);
    basePath.append("://");
    basePath.append(domain);
    if ("http".equalsIgnoreCase(scheme) && 80 != port) {
        basePath.append(":").append(String.valueOf(port));
    } else if ("https".equalsIgnoreCase(scheme) && port != 443) {
        basePath.append(":").append(String.valueOf(port));
    }
    return basePath.toString();
}
 
Example 2
Source Project: wangmarket   File: AllInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
  	
  	//第一次访问时,先判断system数据表中,ATTACHMENT_FILE_URL有没有设置,若没有设置,第一次访问的同时,会设置此参数。
  	if(Global.get("ATTACHMENT_FILE_URL") == null || Global.get("ATTACHMENT_FILE_URL").length() == 0){
  		String url="http://" + request.getServerName() //服务器地址    
      	        + ":"     
      	        + request.getServerPort()           //端口号    
      	        + "/";    
      	Log.info("project request url : " + url);
      	Global.system.put("ATTACHMENT_FILE_URL", url);
  	}
  	
  	if(useExecuteTime){
	long startTime = System.currentTimeMillis();  
       request.setAttribute("startTime", startTime);  
}
  	
      return true;
  }
 
Example 3
Source Project: apiman   File: WarPlatform.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Determine gateway endpoint
 * @return gateway endpoint as StringBuilder
 */
private StringBuilder getGatewayEndpoint() {
    String endpoint = WarGateway.config.getConfigProperty(APIMAN_GATEWAY_ENDPOINT, null);
    StringBuilder builder = new StringBuilder();
    if (endpoint == null) {
        HttpServletRequest currentRequest = HttpRequestThreadLocalFilter.getCurrentRequest();
        if (currentRequest == null) {
            throw new RuntimeException("No current request available.  Missing HttpRequestThreadLocalFilter from the web.xml?"); //$NON-NLS-1$
        }
        builder.append(currentRequest.getScheme());
        builder.append("://"); //$NON-NLS-1$
        builder.append(currentRequest.getServerName());
        int serverPort = currentRequest.getServerPort();
        if (serverPort != 80 && serverPort != 443) {
            builder.append(":").append(serverPort); //$NON-NLS-1$
        }
        builder.append("/apiman-gateway/"); //$NON-NLS-1$
    } else {
        builder.append(endpoint);
        if (!endpoint.endsWith("/")) { //$NON-NLS-1$
            builder.append("/"); //$NON-NLS-1$
        }
    }
    return builder;
}
 
Example 4
/**
 * 转向信息页面(此方法废弃,移动到WeixinNewsController)
 * @param request
 * @return
 * @throws Exception 
 */
@Deprecated
@RequestMapping(value = "goContent", method = {RequestMethod.GET,RequestMethod.POST})
public void goContent(HttpServletRequest request,HttpServletResponse response) throws Exception{
	VelocityContext velocityContext = new VelocityContext();
	String id = request.getParameter("id");
	WeixinNewsitem newsItem = this.weixinNewsitemService.queryById(id);
	WeixinNewstemplate weixinNewstemplate = weixinNewstemplateService.queryById(newsItem.getNewstemplateId());
	velocityContext.put("newsItem", newsItem);
	String jwid = weixinNewstemplate.getJwid();
	velocityContext.put("jwid",jwid);
	MyJwWebJwid myJwWeb = myJwWebJwidService.queryByJwid(jwid);
	velocityContext.put("myJwWeb", myJwWeb);
	//设置分享后用户点击的url
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();
	String url = basePath + "/weixin/back/weixinCommon/goContent.do?id="+id+"&jwid="+jwid;
	velocityContext.put("url", url);
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	String createTime = sdf.format(newsItem.getCreateTime());
	velocityContext.put("createTime", createTime);
	//图文分享
	velocityContext.put("domain", basePath);
	velocityContext.put("appid", myJwWeb.getWeixinAppId());
	velocityContext.put("nonceStr", WeiXinHttpUtil.nonceStr);
	velocityContext.put("timestamp", WeiXinHttpUtil.timestamp);
	velocityContext.put("signature",WeiXinHttpUtil.getRedisSignature(request, jwid));
	String viewName = "weixin/back/newsContent.vm";
	ViewVelocity.view(request,response,viewName,velocityContext);
}
 
Example 5
private void confirmEmail(UserInfo userInfo, HttpServletRequest req, HttpServletResponse resp) throws IOException {
	if (userInfo.getProperty(UserConstants.EMAIL_CONFIRMATION_ID) == null) {
		resp.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
		resp.setContentType(ProtocolConstants.CONTENT_TYPE_HTML);
		resp.getWriter().write("<html><body><p>Your email address has already been confirmed. Thank you!</p></body></html>");
		return;
	}

	if (req.getParameter(UserConstants.EMAIL_CONFIRMATION_ID) == null
			|| !req.getParameter(UserConstants.EMAIL_CONFIRMATION_ID).equals(userInfo.getProperty(UserConstants.EMAIL_CONFIRMATION_ID))) {
		resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Email could not be confirmed.");
		return;
	}

	try {
		userInfo.setProperty(UserConstants.EMAIL_CONFIRMATION_ID, null);
		userInfo.setProperty(UserConstants.BLOCKED, null);
		OrionConfiguration.getMetaStore().updateUser(userInfo);
	} catch (CoreException e) {
		LogHelper.log(e);
		resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
		return;
	}

	resp.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$
	resp.setContentType(ProtocolConstants.CONTENT_TYPE_HTML);
	StringBuffer host = new StringBuffer();
	String scheme = req.getScheme();
	host.append(scheme);
	host.append(":////");
	String servername = req.getServerName();
	host.append(servername);
	host.append(":");
	int port = req.getServerPort();
	host.append(port);
	resp.getWriter().write("<html><body><p>Your email address has been confirmed. Thank you! <a href=\"" + host
			+ "\">Click here</a> to continue and login to your account.</p></body></html>");
	return;
}
 
Example 6
Source Project: Tomcat7.0.67   File: CorsFilter.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isLocalOrigin(HttpServletRequest request, String origin) {

        // Build scheme://host:port from request
        StringBuilder target = new StringBuilder();
        String scheme = request.getScheme();
        if (scheme == null) {
            return false;
        } else {
            scheme = scheme.toLowerCase(Locale.ENGLISH);
        }
        target.append(scheme);
        target.append("://");

        String host = request.getServerName();
        if (host == null) {
            return false;
        }
        target.append(host);

        int port = request.getServerPort();
        if ("http".equals(scheme) && port != 80 ||
                "https".equals(scheme) && port != 443) {
            target.append(':');
            target.append(port);
        }

        return origin.equalsIgnoreCase(target.toString());
    }
 
Example 7
/**
 * Return the URL of this servlet.
 *
 * @param request HTTP servlet request
 * @return URL of this servlet
 */
private String getServletUrl(HttpServletRequest request) {
    return request.getScheme() + "://"
            + // "http" + "://
            request.getServerName()
            + // "myhost"
            ":"
            + // ":"
            request.getServerPort()
            + // "8080"
            request.getContextPath()
            + "/Consumer/";
}
 
Example 8
/**
 * 人工阅卷
 * @param model
 * @param request
 * @param examhistoryId
 * @return
 */
@RequestMapping(value = "/teacher/exam/mark-exampaper/{examhistoryId}", method = RequestMethod.GET)
private String markExampaperPage(Model model, HttpServletRequest request, @PathVariable int examhistoryId) {
	
	ExamHistory history = examService.getUserExamHistListByHistId(examhistoryId);
	int examPaperId = history.getExamPaperId();
	
	String strUrl = "http://" + request.getServerName() // 服务器地址
			+ ":" + request.getServerPort() + "/";
	
	ExamPaper examPaper = examPaperService.getExamPaperById(examPaperId);
	StringBuilder sb = new StringBuilder();
	if(examPaper.getContent() != null && !examPaper.getContent().equals("")){
		Gson gson = new Gson();
		String content = examPaper.getContent();
		List<QuestionQueryResult> questionList = gson.fromJson(content, new TypeToken<List<QuestionQueryResult>>(){}.getType());
		
		for(QuestionQueryResult question : questionList){
			QuestionAdapter adapter = new QuestionAdapter(question,strUrl);
			sb.append(adapter.getStringFromXML());
		}
	}
	
	model.addAttribute("htmlStr", sb);
	model.addAttribute("exampaperid", examPaperId);
	model.addAttribute("examHistoryId", history.getHistId());
	model.addAttribute("exampapername", examPaper.getName());
	model.addAttribute("examId", history.getExamId());
	return "exampaper-mark";
}
 
Example 9
Source Project: Tomcat8-Source-Read   File: TestRemoteIpFilter.java    License: MIT License 5 votes vote down vote up
@Test
public void testInvokeXforwardedHost() throws Exception {
    // PREPARE
    FilterDef filterDef = new FilterDef();
    filterDef.addInitParameter("hostHeader", "x-forwarded-host");
    filterDef.addInitParameter("portHeader", "x-forwarded-port");
    filterDef.addInitParameter("protocolHeader", "x-forwarded-proto");

    MockHttpServletRequest request = new MockHttpServletRequest();
    // client ip
    request.setRemoteAddr("192.168.0.10");
    request.setRemoteHost("192.168.0.10");
    // protocol
    request.setSecure(false);
    request.setServerPort(8080);
    request.setScheme("http");
    // host and port
    request.getCoyoteRequest().serverName().setString("10.0.0.1");
    request.setHeader("x-forwarded-host", "example.com");
    request.setHeader("x-forwarded-port", "8443");
    request.setHeader("x-forwarded-proto", "https");

    // TEST
    HttpServletRequest actualRequest = testRemoteIpFilter(filterDef, request).getRequest();

    // VERIFY
    // protocol
    String actualServerName = actualRequest.getServerName();
    Assert.assertEquals("postInvoke serverName", "example.com", actualServerName);

    String actualScheme = actualRequest.getScheme();
    Assert.assertEquals("postInvoke scheme", "https", actualScheme);

    int actualServerPort = actualRequest.getServerPort();
    Assert.assertEquals("postInvoke serverPort", 8443, actualServerPort);

    boolean actualSecure = actualRequest.isSecure();
    Assert.assertTrue("postInvoke secure", actualSecure);
}
 
Example 10
private static String getOAuthCodeCallbackHandlerUrl(HttpServletRequest request) {
    String scheme = request.getScheme() + "://";
    String serverName = request.getServerName();
    String serverPort = request.getServerPort() == 80 ? "" : ":" + request.getServerPort();
    String contextPath = request.getContextPath();
    String servletPath = URL_MAPPING;
    String pathInfo = request.getPathInfo() == null ? "" : request.getPathInfo();
    return scheme + serverName + serverPort + contextPath + servletPath + pathInfo;
}
 
Example 11
private void indexHandler(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("text/html; charset=utf-8");
    response.setStatus(HttpServletResponse.SC_OK);
    baseRequest.setHandled(true);

    int port = request.getServerPort();
    String html = "<h1>Hello,This is a Jrebel & JetBrains License Server!</h1>";
    html += "<p>License Server started at http://localhost:" + port;
    html += "<p>JetBrains Activation address was: <span style='color:red'>http://localhost:" + port + "/";
    html += "<p>JRebel 7.1 and earlier version Activation address was: <span style='color:red'>http://localhost:" + port + "/{tokenname}</span>, with any email.";
    html += "<p>JRebel 2018.1 and later version Activation address was: http://localhost:" + port + "/{guid}(eg:<span style='color:red'>http://localhost:" + port + "/"+ UUID.randomUUID().toString()+"</span>), with any email.";

    response.getWriter().println(html);

}
 
Example 12
Source Project: glowroot   File: DetailCapture.java    License: Apache License 2.0 5 votes vote down vote up
public static @Nullable RequestHostAndPortDetail captureRequestHostAndPortDetail(
        HttpServletRequest request, RequestInvoker requestInvoker) {
    if (ServletPluginProperties.captureSomeRequestHostAndPortDetail()) {
        RequestHostAndPortDetail requestHostAndPortDetail = new RequestHostAndPortDetail();
        if (ServletPluginProperties.captureRequestRemoteAddress()) {
            requestHostAndPortDetail.remoteAddress = request.getRemoteAddr();
        }
        if (ServletPluginProperties.captureRequestRemoteHostname()) {
            requestHostAndPortDetail.remoteHostname = request.getRemoteHost();
        }
        if (ServletPluginProperties.captureRequestRemotePort()) {
            requestHostAndPortDetail.remotePort = requestInvoker.getRemotePort(request);
        }
        if (ServletPluginProperties.captureRequestLocalAddress()) {
            requestHostAndPortDetail.localAddress = requestInvoker.getLocalAddr(request);
        }
        if (ServletPluginProperties.captureRequestLocalHostname()) {
            requestHostAndPortDetail.localHostname = requestInvoker.getLocalName(request);
        }
        if (ServletPluginProperties.captureRequestLocalPort()) {
            requestHostAndPortDetail.localPort = requestInvoker.getLocalPort(request);
        }
        if (ServletPluginProperties.captureRequestServerHostname()) {
            requestHostAndPortDetail.serverHostname = request.getServerName();
        }
        if (ServletPluginProperties.captureRequestServerPort()) {
            requestHostAndPortDetail.serverPort = request.getServerPort();
        }
        return requestHostAndPortDetail;
    } else {
        // optimized for common case
        return null;
    }
}
 
Example 13
/**
 * 学员试卷
 * @param model
 * @param request
 * @param examhistoryId
 * @return
 */
@RequestMapping(value = "/admin/exam/student-answer-sheet/{histId}", method = RequestMethod.GET)
private String studentAnswerSheetPage(Model model, HttpServletRequest request, @PathVariable int histId) {
	
	ExamHistory history = examService.getUserExamHistListByHistId(histId);
	int examPaperId = history.getExamPaperId();
	
	String strUrl = "http://" + request.getServerName() // 服务器地址
			+ ":" + request.getServerPort() + "/";
	
	ExamPaper examPaper = examPaperService.getExamPaperById(examPaperId);
	StringBuilder sb = new StringBuilder();
	if(examPaper.getContent() != null && !examPaper.getContent().equals("")){
		Gson gson = new Gson();
		String content = examPaper.getContent();
		List<QuestionQueryResult> questionList = gson.fromJson(content, new TypeToken<List<QuestionQueryResult>>(){}.getType());
		
		for(QuestionQueryResult question : questionList){
			QuestionAdapter adapter = new QuestionAdapter(question,strUrl);
			sb.append(adapter.getStringFromXML());
		}
	}
	
	model.addAttribute("htmlStr", sb);
	model.addAttribute("exampaperid", examPaperId);
	model.addAttribute("examHistoryId", history.getHistId());
	model.addAttribute("exampapername", examPaper.getName());
	model.addAttribute("examId", history.getExamId());
	return "student-answer-sheet";
}
 
Example 14
public void postJspToHtml(String postUrl, String filePath,String fileName) throws Exception{
	HttpServletRequest request=Struts2Utils.getRequest();
	//${pageContext.request.scheme}://${pageContext.request.serverName }:${pageContext.request.serverPort} pageContext.request.contextPath
	String reqTarget = request.getScheme()+"://"+request.getServerName()+(request.getServerPort()==80?"":":"+request.getServerPort())+request.getContextPath();
	reqTarget =reqTarget+"/toHtml";
	//?url="+postUrl+"&filePath="+filePath+"&fileName="+fileName;
	Map<String, String> map=new HashMap<String, String>();
	map.put("url", postUrl);
	map.put("filePath", filePath);
	map.put("fileName", fileName);
	Connection connection = Jsoup.connect(reqTarget);
	connection.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31");
	connection.data(map);
	Document doc=connection.timeout(8000).get();
}
 
Example 15
Source Project: charging_pile_cloud   File: HttpRequestUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 获取请求路径
 * @return
 */

public static String getReqHttpAndHttpsPath() {
    HttpServletRequest request =getHttpServletRequest();
    String reqUrl = "";
    //获取服务器名,localhost;
    String serverName = request.getServerName();
    //获取服务器端口号,8080;
    Integer serverPort = request.getServerPort();
    reqUrl = "http://" + serverName + ":" + serverPort;
    return reqUrl;
}
 
Example 16
public static ServletContainerRequest create(final HttpServletRequest req) {
    // If the URL is forwarded, obtain the forwarding information
    final URL forwardedUrl = getForwardedUrl(req);
    String host;
    int port;
    if (forwardedUrl == null) {
        host = req.getServerName();
        port = req.getServerPort();
    } else {
        host = forwardedUrl.getHost();
        port = forwardedUrl.getPort();
        if (port < 0) {
            port = forwardedUrl.getDefaultPort();
        }
        LOG.debug("Assuming forwarded URL: {}", forwardedUrl);
    }

    // The common URI prefix for both baseUri and requestUri
    final StringBuilder commonUriBuilder = new StringBuilder();
    final String scheme = getScheme(req);
    commonUriBuilder.append(scheme);
    commonUriBuilder.append("://");
    commonUriBuilder.append(host);
    if (!(port < 0 || (port == 80 && "http".equals(scheme)) || (port == 443 && "https".equals(scheme)))) {
        commonUriBuilder.append(':');
        commonUriBuilder.append(port);
    }
    final String commonUriPrefix = commonUriBuilder.toString();

    // The Base URI - up to the servlet path
    final StringBuilder baseUriBuilder = new StringBuilder(commonUriPrefix);
    baseUriBuilder.append(req.getContextPath());
    baseUriBuilder.append(req.getServletPath());
    final URI baseUri = URI.create(baseUriBuilder.toString());

    // The RequestURI - everything in the URL
    final StringBuilder requestUriBuilder = new StringBuilder(commonUriPrefix);
    requestUriBuilder.append(req.getRequestURI());
    final String queryString = req.getQueryString();
    if (queryString != null) {
        requestUriBuilder.append('?');
        requestUriBuilder.append(queryString);
    }
    final URI requestUri = URI.create(requestUriBuilder.toString());
    return new ServletContainerRequest(getMethod(req), requestUri, baseUri, getEntityStream(req), getHeaders(req),
                                       getSecurityContext(req));
}
 
Example 17
Source Project: jcart   File: WebUtils.java    License: MIT License 4 votes vote down vote up
public static String getURLWithContextPath(HttpServletRequest request)
{
	return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath();
}
 
Example 18
Source Project: jeewx   File: QywxGzuserinfoServiceImpl.java    License: Apache License 2.0 4 votes vote down vote up
public void saveGzuserinfo(QywxGzuserinfo qywxGzuserinfo,MultipartFile uploadfile,HttpServletRequest request){
		  //把值赋值给用户
		  User user=new User();
		  user.setUserid(qywxGzuserinfo.getUserid());
		  user.setName(qywxGzuserinfo.getName());
		  if(!StringUtils.isBlank(qywxGzuserinfo.getDepartment())){
			  user.setDepartment(new Integer[]{Integer.parseInt(qywxGzuserinfo.getDepartment())});  
		  }
		  user.setPosition(qywxGzuserinfo.getPosition());
		  user.setMobile(qywxGzuserinfo.getMobile());
//		  user.setGender((Integer.parseInt(qywxGzuserinfo.getGender())+1)+"");
		  user.setGender(qywxGzuserinfo.getGender());
		  user.setEmail(qywxGzuserinfo.getEmail());
		  user.setWeixinid(qywxGzuserinfo.getWeixinid());
//		  user.setEnable(1);
//		  user.setAvatar_mediaid(qywxGzuserinfo.getAvatar());
		  user.setAvatar(qywxGzuserinfo.getAvatar());
		  //状态
		  if(!StringUtils.isBlank(qywxGzuserinfo.getSubscribeStatus())){
			  user.setStatus(Integer.valueOf(qywxGzuserinfo.getSubscribeStatus()) );
		  }
//		  user.setExtattr(JSONObject.);// 扩展属性
		  AccessToken accessToken = accountService.getAccessToken();
		  //还要进行头像更新哦
		  //上传图片
	      if(null!=uploadfile && !uploadfile.isEmpty()){
			try {
				 byte[] bytes_array = uploadfile.getBytes();
//				 String current_dir=;//当前路径
				 String current_dir=request.getServletContext().getRealPath("/upload");//当前路径
		    	 String extension_name=uploadfile.getOriginalFilename().substring(uploadfile.getOriginalFilename().lastIndexOf("."));
		    	 //写入到临时文件
		    	 String filename=UUID.randomUUID().toString().replace("-", "")+extension_name;
		    	 WXUpload.writeFile(bytes_array, current_dir, filename, false);
		    	 //说明我们要对图片进行解析了
//		    	 JSONObject jsonobject = WXUpload.upload(accessToken.getAccesstoken(), "image", current_dir+"//"+filename);
//		    	 String url_temp = "http://127.0.0.1:8080/jeecg-p3-web/upload/"+filename;
//		    	 String url_temp = "http://127.0.0.1:8080/jeecg-p3-web/upload/"+filename;
		    	 String url_temp = "http://"+request.getServerName()+":"+request.getServerPort()+ "/jeecg-p3-web" + "/upload/"+filename;
		    	 JSONObject jsonobject = WXUpload.upload(accessToken.getAccesstoken(), "image", url_temp);
		    	 if(!StringUtils.isBlank(jsonobject.getString("media_id")) ){
		    		 user.setAvatar_mediaid(jsonobject.getString("media_id"));
		    		 user.setAvatar(url_temp);
		    		 qywxGzuserinfo.setAvatar(url_temp);
		    	 }
//		    	 User temp_user =  JwUserAPI.getUserByUserid(user.getUserid(), accessToken.getAccesstoken());
//		    	 if(temp_user)
			} catch (IOException e) {
				e.printStackTrace();
			}
	      }
	      int result = JwUserAPI.createUser(user, accessToken.getAccesstoken());
		  //只有保存成功了才把成员插入到本地数据库中
		  if(result==0){
			 //不知道这个事物怎么控制哦
			 qywxGzuserinfoDao.insert(qywxGzuserinfo);
		  }else{
			  throw new RuntimeException("微信添加成员失败,错误代码="+result);
		  }
	 }
 
Example 19
Source Project: wangmarket   File: TemplateController.java    License: Apache License 2.0 4 votes vote down vote up
/**
	 * 获取指定模版页面的内容,用于iframe内,htmledit修改
	 * @param pageName 要获取的模版页面名字,对应 {@link TemplatePage}.name
	 * @throws IOException
	 */
	@RequestMapping("getTemplatePageText${url.suffix}")
	public String getTemplatePageText(Model model,HttpServletRequest request,
			@RequestParam(value = "pageName", required = true) String pageName
			) throws IOException{
		Site site = getSite();
		String html = null;
		pageName = filter(pageName);
		
		TemplatePageVO vo = templateService.getTemplatePageByNameForCache(request, pageName);
		if(vo.getResult() - TemplatePageVO.FAILURE == 0){
			return error(model, vo.getInfo());
		}
		
		//判断一下,是否这个模版页面是刚建立的,还没有模版页内容
		if(vo.getTemplatePageData() == null){
			//没有模版页的内容。
//			if(vo.getTemplatePage().getEditMode() != null || vo.getTemplatePage().getEditMode() - TemplatePage.EDIT_MODE_VISUAL == 0){
				//判断一下,如果是可视化模式,需要增加默认的html模版页面
				vo.setTemplatePageData(new TemplatePageData());
				vo.getTemplatePageData().setText(Template.newHtml);
//			}else{
//				//如果是代码模式,那么就是空字符串就行了
//				vo.setTemplatePageData(new TemplatePageData());
//				vo.getTemplatePageData().setText("");
//			}
		}
		
		//判断是代码模式,还是智能模式
		if(vo.getTemplatePage().getEditMode() != null && vo.getTemplatePage().getEditMode() - TemplatePage.EDIT_MODE_CODE == 0){
			//代码模式,那么直接赋予 templatePageData.text 即可
			html = vo.getTemplatePageData().getText();
			AliyunLog.addActionLog(vo.getTemplatePageData().getId(), "代码编辑获取指定模版页内容", pageName);
		}else{
			//如果是智能模式,那么要装载模版变量、可视化编辑等
			//装载模版变量
			if(Func.getUserBeanForShiroSession().getTemplateVarMapForOriginal() == null){
				//判断一下,缓存中是否有模版变量,若所没有,那么要缓存
				templateService.getTemplateVarAndDateListByCache();
			}
			
			com.xnx3.wangmarket.admin.cache.TemplateCMS temp = new com.xnx3.wangmarket.admin.cache.TemplateCMS(site, true);
			html = temp.assemblyTemplateVar(vo.getTemplatePageData().getText());
			
			// {templatePath} 替换
			TemplateCMS templateCMS = new TemplateCMS(site, TemplateUtil.getTemplateByName(site.getTemplateName()));
			html = html.replaceAll(TemplateCMS.regex("templatePath"), templateCMS.getTemplatePath());
			
			//自动在</head>之前,加入htmledit.js
			String yuming = "//"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
			html = html.replace("</head>", "<!--XNX3HTMLEDIT--><script>var masterSiteUrl='"+Global.get("MASTER_SITE_URL")+"'; var htmledit_upload_url='"+yuming+"template/uploadImage.do?t="+DateUtil.timeForUnix13()+"'; </script><script src=\""+StaticResource.getPath()+"module/htmledit/htmledit.js\"></script></head>");
			
			AliyunLog.addActionLog(vo.getTemplatePageData().getId(), "可视化编辑获取指定模版页内容", pageName);
		}
		
		model.addAttribute("pageName", pageName);
		model.addAttribute("html", html);
		return "template/getTemplatePageText";
	}
 
Example 20
/**
 * Create PDF render option.
 * 
 * @param servletPath
 * @param request
 * @param pageOverflow
 * @param isDesigner
 * @return the PDF render option
 */
private PDFRenderOption createPDFRenderOption( String servletPath,
		HttpServletRequest request, int pageOverflow, boolean isDesigner,
		boolean isPDF )
{
	String baseURL = null;
	// try to get base url from config file
	if ( !isDesigner )
		baseURL = ParameterAccessor.getBaseURL( );

	if ( baseURL == null )
	{
		if ( ParameterAccessor.isOpenAsAttachment( request ) )
		{
			baseURL = request.getScheme( ) + "://" //$NON-NLS-1$
					+ request.getServerName( )
					+ ":" //$NON-NLS-1$
					+ request.getServerPort( );
		}
		else
		{
			baseURL = ""; //$NON-NLS-1$		
		}
	}

	// append application context path
	baseURL += request.getContextPath( );

	PDFRenderOption renderOption = new PDFRenderOption( );
	renderOption.setBaseURL( baseURL );
	if ( servletPath == null || servletPath.length( ) == 0 )
	{
		servletPath = IBirtConstants.SERVLET_PATH_RUN;
	}
	renderOption.setOption( IBirtConstants.SERVLET_PATH, servletPath );
	renderOption.setSupportedImageFormats( isPDF ? "PNG;GIF;JPG;BMP;SVG" : "PNG;GIF;JPG;BMP" ); //$NON-NLS-1$ //$NON-NLS-2$

	// page overflow setting
	switch ( pageOverflow )
	{
		case IBirtConstants.PAGE_OVERFLOW_AUTO :
			renderOption.setOption( PDFRenderOption.PAGE_OVERFLOW,
					Integer.valueOf( PDFRenderOption.OUTPUT_TO_MULTIPLE_PAGES ) );
			break;
		case IBirtConstants.PAGE_OVERFLOW_ACTUAL :
			renderOption.setOption( PDFRenderOption.PAGE_OVERFLOW,
					Integer.valueOf( PDFRenderOption.ENLARGE_PAGE_SIZE ) );
			break;
		case IBirtConstants.PAGE_OVERFLOW_FITTOPAGE :
			renderOption.setOption( PDFRenderOption.FIT_TO_PAGE,
					Boolean.TRUE );
			break;
		default :
			renderOption.setOption( PDFRenderOption.PAGE_OVERFLOW,
					Integer.valueOf( PDFRenderOption.OUTPUT_TO_MULTIPLE_PAGES ) );
	}

	// pagebreak pagination only setting
	// Bug 238716
	renderOption.setOption( PDFRenderOption.PAGEBREAK_PAGINATION_ONLY,
			Boolean.FALSE );

	return renderOption;
}