Explorar o código

优化调整参数

KeYuan %!s(int64=8) %!d(string=hai) anos
pai
achega
b7b93989dc

+ 33 - 2
src/main/java/com/key/common/utils/DiaowenProperty.java

@@ -1,9 +1,13 @@
 package com.key.common.utils;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
+import com.key.common.utils.web.Struts2Utils;
 import org.apache.struts2.ServletActionContext;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@@ -12,6 +16,8 @@ import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
 import com.baidu.ueditor.ConfigManager;
 import com.sun.org.apache.xml.internal.security.Init;
 
+import javax.servlet.ServletContext;
+
 /**
  * 
  * @author keyuan
@@ -30,6 +36,7 @@ public class DiaowenProperty extends
 	public static String UPLOADFILE_BACKET = null;
 	public static String UPLOADFILE_JM_BACKET = null;
 
+	public static String contentCopyright = null;
 //	private static Map<String, String> ctxPropertiesMap;
 
 	@Override
@@ -56,7 +63,11 @@ public class DiaowenProperty extends
 			ctxPropertiesMap.put(keyStr, value);
 		}
 		*/
-		
+		contentCopyright = props.getProperty("contentCopyright");
+		if(contentCopyright!=null){
+			contentCopyright = unicode2String(contentCopyright);
+		}
+		System.out.println("contentCopyright:"+contentCopyright);
 	}
 /*
 	public static String getContextProperty(String name) {
@@ -67,5 +78,25 @@ public class DiaowenProperty extends
 		System.out.println("系统初始化方法。。。");
 		System.out.println(ServletActionContext.getContext());
 	}
-	
+
+	/**
+	 * unicode 转字符串
+	 */
+	public static String unicode2String(String unicode) {
+
+		StringBuffer string = new StringBuffer();
+
+		String[] hex = unicode.split("\\\\u");
+
+		for (int i = 1; i < hex.length; i++) {
+
+			// 转换出每一个代码点
+			int data = Integer.parseInt(hex[i], 16);
+
+			// 追加成string
+			string.append((char) data);
+		}
+
+		return string.toString();
+	}
 }

+ 103 - 33
src/main/java/com/key/common/utils/ToHtmlServlet.java

@@ -1,43 +1,41 @@
 package com.key.common.utils;
 
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
+import java.io.*;
+import java.util.Properties;
+
+import javax.servlet.*;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponseWrapper;
 
+import com.itextpdf.text.log.SysoCounter;
 import com.key.common.plugs.aliyun.AliyunOSS;
 import com.key.common.plugs.baiduyun.BaiduBOS;
+import com.key.common.utils.web.Struts2Utils;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.select.Elements;
 
 public class ToHtmlServlet extends HttpServlet {
 	
 	private static final long serialVersionUID = -9118659583515649615L;
-	
+	private static String contentCopyright = null;
 	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 		ServletContext sc = getServletContext();
 		String url=request.getParameter("url");
 		String filePath=request.getParameter("filePath");
 		String fileName=request.getParameter("fileName");
-//		System.out.println(url+":"+filePath+":"+fileName);
 		//url = "/design/my-survey-design!previewDev.action?surveyId=402880ea4675ac62014675ac7b3a0000";
 		// 这是生成的html文件名,如index.htm
 		filePath = filePath.replace("/", File.separator);
 		filePath = filePath.replace("\\", File.separator);
 		String fileRealPath = sc.getRealPath("/") +File.separator+ filePath;
+
+//		String content = exeDown(url);
+//		printStream(fileRealPath,fileName,content);
 		RequestDispatcher rd = sc.getRequestDispatcher(url);
 		final ByteArrayOutputStream os = new ByteArrayOutputStream();
-
 		final ServletOutputStream stream = new ServletOutputStream() {
 			public void write(byte[] data, int offset, int length) {
 				os.write(data, offset, length);
@@ -46,10 +44,10 @@ public class ToHtmlServlet extends HttpServlet {
 			public void write(int b) throws IOException {
 				os.write(b);
 			}
-		};
 
-		final PrintWriter pw = new PrintWriter(new OutputStreamWriter(os,"utf-8"));
+		};
 
+		final PrintWriter pw = new PrintWriter(new OutputStreamWriter(os,"UTF-8"));
 		HttpServletResponse rep = new HttpServletResponseWrapper(response) {
 			public ServletOutputStream getOutputStream() {
 				return stream;
@@ -58,27 +56,35 @@ public class ToHtmlServlet extends HttpServlet {
 			public PrintWriter getWriter() {
 				return pw;
 			}
+
 		};
 
 		//rd.include(request, rep);
 		rd.forward(request, rep);
 		pw.flush();
-		
-		
-		// 把jsp输出的内容写到xxx.htm
-		File file=jspWriteLocal(fileName, fileRealPath, os);
-		
-		if("aliyunOSS".equals(DiaowenProperty.DWSTORAGETYPE)){
-			// 阿里云支持 将文件写入到aliyun oss
-			AliyunOSS.putObject(DiaowenProperty.WENJUANHTML_BACKET,file,fileName);
-			//delete本地服务器文件
-			file.delete();
-		}else if("baiduBOS".equals(DiaowenProperty.DWSTORAGETYPE)){
-			BaiduBOS.putObject(DiaowenProperty.WENJUANHTML_BACKET,file,fileName);
-			//delete本地服务器文件
-			file.delete();
+
+		Document document = Jsoup.parse(os.toString());
+		Elements elements = document.getElementsByTag("a");
+
+		String contentCopyrightStr = "";
+		//自定义问卷内容的版权,可以在设置中设置名称,然后就自动显示
+		if(DiaowenProperty.contentCopyright!=null){
+			contentCopyrightStr = "内容版权 <a href=\"/\" style=\"text-decoration: none;color: gray;\">"+DiaowenProperty.contentCopyright+"</a>";
 		}
-		
+		// 修改说明:
+		// 前部分是DWSurvey官网的保留声明,虽然这块目前是法律的灰色地带,但从维护一个健康的开源社区,从DWSurvey帮助到您的角度,请您能保留下来。
+		// 后部分 contentCopyright 是关于问卷内容的版权声明,这个不用说肯定属于您或您公司,写法示例如:调问网
+		Elements elements1 = document.getElementsByClass("footer-copyright").remove();
+		document.body().append("<div class=\"footer-copyright\" data-role=\"footer\" style=\"color: gray;padding-bottom: 5px;\"> \n" +
+				"   <!-- 尊重开源,保留声明 BEGIN --> Powered by \n" +
+				"   <a href=\"http://www.diaowen.net\" style=\"text-decoration: none;color: gray;\">DwSurvey</a>&nbsp; \n" +
+				"   <!-- 尊重开源,保留声明 END --> \n" + contentCopyrightStr +
+				"   </div>");
+		// 把jsp输出的内容写到xxx.htm
+
+//		File file=jspWriteLocal(fileName, fileRealPath, os);
+		printStream(fileRealPath,fileName,document.html());
+
 		response.setContentType("text/html;charset=utf-8");
 		PrintWriter out = response.getWriter();
 		out.print("<p align=center><font size=3 color=red>首页已经成功生成!Andrew</font></p>");
@@ -106,9 +112,73 @@ public class ToHtmlServlet extends HttpServlet {
 		}
 		FileOutputStream fos = new FileOutputStream(file);
 		os.writeTo(fos);
+		//fos.write("http://www.diaowen.net/wenjuan/u2qhavhgufi.html".getBytes());
 		fos.close();
 		return file;
 	}
-	
 
+	private File jspWriteLocal(String fileName, String fileRealPath,
+							   final String doc) throws IOException,
+			FileNotFoundException {
+		File file2 = new File(fileRealPath);
+		if (!file2.exists() || !file2.isDirectory()) {
+			file2.mkdirs();
+		}
+		File file = new File(fileRealPath + fileName);
+		if (!file.exists()) {
+			file.createNewFile();
+		}
+		FileOutputStream fos = new FileOutputStream(file);
+//		os.writeTo(fos);
+		OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
+		System.out.println(doc);
+		osw.write(doc);
+		//fos.write("http://www.diaowen.net/wenjuan/u2qhavhgufi.html".getBytes());
+		fos.close();
+		return file;
+	}
+
+	public static String exeDown(String url){
+		String content="";
+		Document doc;
+		try {
+			doc = Jsoup.connect(url)
+					.data("query", "nnd")
+					.userAgent("Mozilla")
+					.cookie("auth", "token")
+					.timeout(5000)
+					.post();
+			content=doc.html();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return content;
+	}
+
+
+	public static void printStream(String savePath,String fileName,String content) throws IOException{
+		createFile(savePath);
+		FileOutputStream out=null;
+		try {
+			out=new FileOutputStream(savePath+File.separator+fileName);
+			out.write(content.getBytes());
+		}catch (Exception e){
+			e.printStackTrace();;
+		}finally{
+			if(out!=null){
+				try {
+					out.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+	}
+
+	private static void createFile(String rootPath) {
+		File file=new File(rootPath);
+		if(!file.exists()){
+			file.mkdirs();
+		}
+	}
 }

+ 60 - 11
src/main/java/com/key/dwsurvey/action/SysPropertyAction.java

@@ -14,6 +14,10 @@ import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 
 import com.itextpdf.text.log.SysoCounter;
+import com.key.common.utils.DiaowenProperty;
+import com.key.common.utils.EncodeUtils;
+import org.apache.commons.codec.binary.StringUtils;
+import org.apache.poi.util.StringUtil;
 import org.apache.struts2.convention.annotation.Namespace;
 import org.apache.struts2.convention.annotation.Namespaces;
 import org.apache.struts2.convention.annotation.Result;
@@ -61,6 +65,7 @@ public class SysPropertyAction extends ActionSupport{
 		   String icpCode = p.getProperty("icpCode");
 		   String tongjiCode = p.getProperty("tongjiCode");
 		   String loginBgImg = p.getProperty("loginBgImg");
+		   String contentCopyright = p.getProperty("contentCopyright");
 
 		   request.setAttribute("adminEmail", adminEmail);
 		   request.setAttribute("adminQQ", adminQQ);
@@ -68,6 +73,7 @@ public class SysPropertyAction extends ActionSupport{
 		   request.setAttribute("icpCode", icpCode);
 		   request.setAttribute("tongjiCode", tongjiCode);
 		   request.setAttribute("loginBgImg", loginBgImg);
+			request.setAttribute("contentCopyright", contentCopyright);
 	    } catch (IOException e1) {
 	        e1.printStackTrace();
 	    }
@@ -84,20 +90,22 @@ public class SysPropertyAction extends ActionSupport{
 		//网站备案信息代码
 		String icpCode = Struts2Utils.getParameter("icpCode");
 		//网站备案信息代码
-		String tongjiCode = Struts2Utils.getParameter("tongjiCode");
 		String loginBgImg = Struts2Utils.getParameter("loginBgImg");
-		
+		String contentCopyright = Struts2Utils.getParameter("contentCopyright");
+
 		String siteFilePath = "/WEB-INF/classes/conf/site/site.properties".replace("/", File.separator);
 
-		StringBuffer siteData=new StringBuffer();
-		siteData.append("\r\nadminEmail=").append(adminEmail);
-		siteData.append("\r\nadminQQ=").append(adminQQ);
-		siteData.append("\r\nadminTelephone=").append(adminTelephone);
-		siteData.append("\r\nicpCode=").append(icpCode);
-		siteData.append("\r\ntongjiCode=").append(tongjiCode);
-		siteData.append("\r\nloginBgImg=").append(loginBgImg);
-		writeData(siteFilePath, siteData.toString());
-		
+		Properties props = new Properties();
+		props.put("adminEmail",adminEmail!=null?adminEmail:"");
+		props.put("adminQQ",adminQQ!=null?adminQQ:"");
+		props.put("adminTelephone",adminTelephone!=null?adminTelephone:"");
+		props.put("icpCode",icpCode!=null?string2Unicode(icpCode):"");
+		props.put("loginBgImg",loginBgImg!=null?loginBgImg:"");
+		props.put("contentCopyright",contentCopyright!=null?string2Unicode(contentCopyright):"");
+
+		writeData(siteFilePath, props);
+
+		DiaowenProperty.contentCopyright = contentCopyright;
 		//写LOGO DATA文件
 		String headerData="<a href=\"${ctx }\"><img alt=\"\" src=\"${ctx }/images/logo/LOGO.png\" align=\"middle\" height=\"46\" ><span class=\"titleTempSpan\">OSS</span></a> ";
 		String headerDataPath="/WEB-INF/page/layouts/logo-img.jsp".replace("/", File.separator);
@@ -152,5 +160,46 @@ public class SysPropertyAction extends ActionSupport{
 
 	}
 
+	private void writeData(String filePath,Properties props) {
+		OutputStreamWriter fw = null;
+		try {
+			ServletContext sc = Struts2Utils.getSession().getServletContext();
+			String fileRealPath = sc.getRealPath("/") + filePath;
+			File file = new File(fileRealPath);
+			if (!file.exists()) {
+				file.createNewFile();
+			}
+			fw = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
+			props.store(fw,"UTF-8");
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			if (fw != null) {
+				try {
+					fw.close();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}
+
+	}
+
+	public static String string2Unicode(String string) {
+
+		StringBuffer unicode = new StringBuffer();
+
+		for (int i = 0; i < string.length(); i++) {
+
+			// 取出每一个字符
+			char c = string.charAt(i);
+
+			// 转换为unicode
+			unicode.append("\\u" + Integer.toHexString(c));
+		}
+
+		return unicode.toString();
+	}
+
 
 }

+ 1 - 1
src/main/resources/conf/application.properties

@@ -25,7 +25,7 @@ dw.yunos.endpoint =
 #diaowenwebfile.gz.bcebos.com
 #dw.storage.url_prefix =
 dw.storage.url_prefix = http://localhost:8080/diaowen3.0
-	
+
 ###-------------------------------------DW------------------------------###
 #site email settings
 #dw.mail.smtp_host = smtpcloud.sohu.com

+ 1 - 0
src/main/resources/conf/applicationContext.xml

@@ -23,6 +23,7 @@
 				<!-- 本地开发环境配置 -->
 				<value>classpath*:/conf/application.local.properties</value>
 				<!-- 服务器生产环境配置 -->
+				<value>classpath*:/conf/site/site.properties</value>
 			</list>
 		</property>
 	</bean>

+ 2 - 0
src/main/resources/conf/site/site.properties

@@ -4,6 +4,8 @@ adminQQ=
 adminTelephone=010-00000000000
 icpCode=\u4EACICP\u590713050030\u53F7-3
 loginBgImg=/images/style-model/login_bg/2.jpg
+#内容版权声明
+contentCopyright=
 #site settings
 dw.site.admin_email=keyuan258@gmail.net
 dw.site.admin_qq=

+ 1 - 1
src/main/webapp/WEB-INF/page/content/diaowen-design/answer-survey-mobile.jsp

@@ -825,7 +825,7 @@ $(document).ready(function(){
 		</div>
   </div>
 
-  <div data-role="footer">
+  <div data-role="footer" class="footer-copyright" >
 	  <%--请保留以下内容--%>
   	<h3>Powered by <a href="http://diaowen.net/index-m.jsp" style="text-decoration: none;" rel="external">DWSurvey</a></h3>
   </div>

+ 10 - 3
src/main/webapp/WEB-INF/page/content/diaowen-design/answer-survey.jsp

@@ -13,7 +13,7 @@
 <link href="${ctx }/js/plugs/uploadify-v3.1/uploadify.css" rel="stylesheet" type="text/css" />
 <script type="text/javascript" src="${ctx }/js/plugs/uploadify-v3.1/jquery.uploadify-3.1.js"></script>
 <script type="text/javascript" src="${ctx }/js/dw/uploadify.js"></script>
-
+<script type="text/javascript" src="${ctx }/js/dw/address.js"></script>
 <link href="${ctx }/css/preview-dev.css" rel="stylesheet" type="text/css" />
 <link rel="stylesheet" href="${ctx }/js/plugs/colpick-jQuery/css/colpick.css" type="text/css"/>
 
@@ -1302,6 +1302,12 @@ label.error{
 														<c:when test="${en.answerInputRow > 1 }">
 															<textarea name="qu_${en.quType }_${en.id }" rows="${en.answerInputRow }" style="width:${empty(en.answerInputWidth)?'300':en.answerInputWidth}px;"class="inputSytle_2 fillblankInput" ></textarea>
 														</c:when>
+														<c:when test="${en.contactsField eq 8}">
+															<select style="padding: 5px;" class="hat_province"><option>--选择省--</option> </select>
+															<select style="padding: 5px;" class="hat_city"><option>--选择市--</option> </select>
+															<select style="padding: 5px;" class="hat_area"><option>--选择区--</option> </select>
+															<input type="text" name="qu_${en.quType }_${en.id }" class="fbk_input" style="display: none;" >
+														</c:when>
 														<c:otherwise>
 															<input type="text" name="qu_${en.quType }_${en.id }" style="width:${empty(en.answerInputWidth)?'300':en.answerInputWidth}px;" class="inputSytle_1 fillblankInput" >
 														</c:otherwise>
@@ -1871,10 +1877,11 @@ label.error{
 
 </div>
 
+
 <div class="footer-copyright" style="color: gray;padding-bottom: 5px;">
-		<!-- 尊重开源、保护开源,保留DWSurvey BEGIN -->
+		尊重开源、保护开源,保留DWSurvey BEGIN
 		Powered by <a href="http://www.diaowen.net" style="text-decoration: none;color: gray;">DWSurvey</a>&nbsp;
-		<!-- 尊重开源、保护开源,保留DWSurvey END -->
+		尊重开源、保护开源,保留DWSurvey END
 		<%--内容版权 <a href="http://www.diaowen.net" style="text-decoration: none;color: gray;">调问网</a>--%>
 </div>
 		

+ 5 - 4
src/main/webapp/WEB-INF/page/content/diaowen-system/property-input.jsp

@@ -105,10 +105,11 @@ $(document).ready(function(){
 													<td width="80" align="right" >备案代码</td>
 													<td class="ac-input-td"><input type="text" name="icpCode" value="${icpCode }"> </td>
 												</tr>
-												<%-- <tr>
-													<td width="80" align="right" valign="top">统计代码</td>
-													<td class="ac-input-td"><textarea name="tongjiCode" rows="3" cols="25" style="border-radius: 2px;border: 1px solid #B2B2B2;font-size: 18px;color: #727779;width: 320px;padding: 5px;outline: none;" >${tongjiCode }</textarea> </td>
-												</tr> --%>
+												<tr>
+													<td width="80" align="right" >内容版权</td>
+													<td class="ac-input-td"><input type="text" name="contentCopyright" value="${contentCopyright }" ></td>
+												</tr>
+												<tr><td>&nbsp;</td><td class="ac-input-td" valign="top" style="padding-top: 0px;">所属机构名称如:调问网 </td></tr>
 											</table>
 										</td>
 										<td valign="top" align="left" >