Мелоч

This commit is contained in:
2021-09-03 10:39:53 +06:00
parent c19e513a5e
commit 9648554d7c
9 changed files with 90 additions and 86 deletions

View File

@ -1,5 +1,4 @@
//
package kz.goodssales.GoodsSales.dbms;
package kz.locust.CCALM; //Главная
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
@ -9,13 +8,12 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
//import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.io.Reader;
import java.io.StringWriter;
//import java.io.UnsupportedEncodingException;
import java.io.Writer;
//import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
@ -79,8 +77,9 @@ import tctable.Tools;
import tools.EmailUtility;
import tools.User;
@Controller
@SessionAttributes( { "user" }) //Сесионный объект!
@SessionAttributes( { "user" }) //Сесионный объект
public class DBMSRecords implements ServletContextAware {
//private static final Logger logger = LoggerFactory.getLogger(Translation.class);
@ -124,10 +123,10 @@ public class DBMSRecords implements ServletContextAware {
try {
//String fullPath = context.getRealPath("/WEB-INF/config.xml");
//File fXmlFile = new File(fullPath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(new ClassPathResource("config.xml").getInputStream());
//Document doc = dBuilder.parse(fXmlFile);
Document doc = dBuilder.parse(new ClassPathResource("config.xml").getInputStream());
Element nMain = doc.getDocumentElement();
NodeList nl = nMain.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
@ -205,7 +204,7 @@ public class DBMSRecords implements ServletContextAware {
try {
Statement stt0 = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
//st.executeUpdate("SET TIME ZONE 'UTC';");
//st.executeUpdate("SET TIME ZONE 'UTC';"); зачем коментил?
stt0.executeUpdate("SET TIME ZONE 'Asia/Almaty';");
stt0.close();
} catch (SQLException ex) {
@ -396,7 +395,7 @@ public class DBMSRecords implements ServletContextAware {
xml += "<metadata fn=\"0\"></metadata>";
}
result=getText(xml,user,conn);
result=getText(conn,xml,user);
} else if (fn != null && fn.equals("1")) {
String typename = "";
@ -570,7 +569,6 @@ public class DBMSRecords implements ServletContextAware {
} catch (XPathExpressionException ex) {
logger.info(ex.getMessage());
}
if (nodeList!=null && nodeList.getLength() > 0) {
vt = nodeList.item(0).getAttributes().getNamedItem("vt").getNodeValue();
//If this "file" is then copy it from the temporary folder to the specified path
@ -1149,7 +1147,6 @@ public class DBMSRecords implements ServletContextAware {
{
String user_id = "";
String cmd="";
String window_id = "";
String login = "";
String password = "";
String hash = "";
@ -1165,7 +1162,6 @@ public class DBMSRecords implements ServletContextAware {
try {
cmd = (String) xpath.compile("//metadata/cmd/text()").evaluate(reqNode, XPathConstants.STRING);
window_id = (String) xpath.compile("//metadata/window_id/text()").evaluate(reqNode, XPathConstants.STRING);
login = (String) xpath.compile("//metadata/login/text()").evaluate(reqNode, XPathConstants.STRING);
password = (String) xpath.compile("//metadata/password/text()").evaluate(reqNode, XPathConstants.STRING);
hash = (String) xpath.compile("//metadata/hash/text()").evaluate(reqNode, XPathConstants.STRING); //Сессия для авто логина если не пустая то сначала пытаемся авторизоваться по ней
@ -1217,7 +1213,7 @@ public class DBMSRecords implements ServletContextAware {
boolean mEerror = false;
String recipient = login;
String subject = "New password for CCALM from http://www.locust.kz";
String subject = "New password for CCALM from http://www.ccalm.org";
String content = "Login is: "+ email.toLowerCase()+"\n<br> New password: " + newPass;
@ -1309,8 +1305,6 @@ public class DBMSRecords implements ServletContextAware {
}
String val;
val = getSQLValue("i4", window_id);
sql_query = Tools.replaceAll(sql_query,"${window_id}", val);
val = getSQLValue("i4", user_id);
sql_query = Tools.replaceAll(sql_query,"${user_id}", val);
val = getSQLValue("string", login);
@ -1403,7 +1397,7 @@ public class DBMSRecords implements ServletContextAware {
//Отправляем пароль на Email
String recipient = email;
String subject = "Password for new user on http://www.locust.kz";
String subject = "Password for new user on http://www.ccalm.org";
String content = "Login is: "+ email.toLowerCase()+"\n<br> Password: " + newPass;
//String answer = "";
@ -1594,8 +1588,8 @@ public class DBMSRecords implements ServletContextAware {
writer.write(" </head>\n");
writer.write(" <body>\n");
writer.write("<b>" + __("Time_and_date_of_generation",user,conn) + ": </b><i>" + (new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date())) + "</i><br>");
writer.write("<b>" + __("Creator",user,conn) + ": </b>" + uName);
writer.write("<b>" + __(conn,"Time_and_date_of_generation",user) + ": </b><i>" + (new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date())) + "</i><br>");
writer.write("<b>" + __(conn,"Creator",user) + ": </b>" + uName);
//writer.write(filter);
@ -1605,7 +1599,7 @@ public class DBMSRecords implements ServletContextAware {
expr = xpath.compile("objects-list/@d");
writer.write(" <table border=\"1\" cellspacing=\"0\">\n");
writer.write(" <caption><b>" + getText("" + expr.evaluate(nTypeS, XPathConstants.STRING),user,conn) + "</b></caption>\n");
writer.write(" <caption><b>" + getText(conn,"" + expr.evaluate(nTypeS, XPathConstants.STRING),user) + "</b></caption>\n");
writer.write(" <thead>\n");
writer.write(" <tr>");
@ -1613,7 +1607,7 @@ public class DBMSRecords implements ServletContextAware {
Object exprResult = expr.evaluate(nTypeS, XPathConstants.NODESET);
nodeList = (NodeList) exprResult;
for (int i = 0; i < nodeList.getLength(); i++) {
writer.write("<td bgcolor=\"#d1d1d1\" width=\"" + nodeList.item(i).getAttributes().getNamedItem("width").getNodeValue() + "px\"><b>" + getText(nodeList.item(i).getAttributes().getNamedItem("d").getNodeValue(),user,conn)
writer.write("<td bgcolor=\"#d1d1d1\" width=\"" + nodeList.item(i).getAttributes().getNamedItem("width").getNodeValue() + "px\"><b>" + getText(conn,nodeList.item(i).getAttributes().getNamedItem("d").getNodeValue(),user)
+ "</b></td>");
}
writer.write(" </tr>\n");
@ -1770,7 +1764,7 @@ public class DBMSRecords implements ServletContextAware {
public void setServletContext(ServletContext context) {
this.context=context;
}
/**
* Example request: http://localhost:8080/CCALM/download?t=FrmLocust&f=image_name1&i=1298
*/
@ -1778,8 +1772,6 @@ public class DBMSRecords implements ServletContextAware {
@ResponseBody
public FileSystemResource home(HttpServletResponse response,@ModelAttribute User user,@RequestParam(required=false,name="t") String typename,@RequestParam(required=false,name="f") String field,@RequestParam(required=false,name="i") String id) {
//logger.info("user.id="+user.id+" user.name="+user.name+" user.lng="+user.language_id);
String metadata_file = "";
String db_url = "";
String db_login = "";
@ -1787,12 +1779,12 @@ public class DBMSRecords implements ServletContextAware {
//String data_dir = "";
//Load DB configuration from "config.xml"
try {
String fullPath = context.getRealPath("/WEB-INF/config.xml");
File fXmlFile = new File(fullPath);
//String fullPath = context.getRealPath("/WEB-INF/config.xml");
//File fXmlFile = new File(fullPath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
//Document doc = dBuilder.parse(fXmlFile);
Document doc = dBuilder.parse(new ClassPathResource("config.xml").getInputStream());
Element nMain = doc.getDocumentElement();
NodeList nl = nMain.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
@ -1907,10 +1899,15 @@ public class DBMSRecords implements ServletContextAware {
if(conn!=null){try{conn.close();}catch(SQLException ex){}}
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename="+afterFirst(filename,"_"));
response.setHeader("Cache-Control", "no-cache");
return new FileSystemResource(file);
if(file!=null) {
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename="+afterFirst(filename,"_"));
response.setHeader("Cache-Control", "no-cache");
return new FileSystemResource(file);
}else {
response.setContentType("text/html");
return null;
}
}
@ -1923,12 +1920,12 @@ public class DBMSRecords implements ServletContextAware {
try {
String fullPath = context.getRealPath("/WEB-INF/config.xml");
File fXmlFile = new File(fullPath);
//String fullPath = context.getRealPath("/WEB-INF/config.xml");
//File fXmlFile = new File(fullPath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
//Document doc = dBuilder.parse(fXmlFile);
Document doc = dBuilder.parse(new ClassPathResource("config.xml").getInputStream());
Element nMain = doc.getDocumentElement();
NodeList nl = nMain.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
@ -2010,12 +2007,12 @@ public class DBMSRecords implements ServletContextAware {
String data_dir = "";
//Load DB configuration from "config.xml"
try {
String fullPath = context.getRealPath("/WEB-INF/config.xml");
File fXmlFile = new File(fullPath);
//String fullPath = context.getRealPath("/WEB-INF/config.xml");
//File fXmlFile = new File(fullPath);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
//Document doc = dBuilder.parse(fXmlFile);
Document doc = dBuilder.parse(new ClassPathResource("config.xml").getInputStream());
Element nMain = doc.getDocumentElement();
NodeList nl = nMain.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
@ -2046,8 +2043,6 @@ public class DBMSRecords implements ServletContextAware {
String getSQLValue(String t, String v) {
//if($t=='object' && (strtoupper($v)!='NULL' && gettype($v)=='string')) $t='string'; //Если id шники uuid
//if(t.equals("object")) t="string";
if (t.equals("object") || t.equals("uid")) {
if (v.equals(""))
v = "NULL";
@ -2161,7 +2156,7 @@ public class DBMSRecords implements ServletContextAware {
}
//Перевести слово по идентификатору из базы
public String __(String key,User user,Connection conn)
public String __(Connection conn,String key,User user)
{
String result="";
ResultSet rs=null;
@ -2175,7 +2170,7 @@ public class DBMSRecords implements ServletContextAware {
result = rs.getString(1);
}
}
} catch( SQLException ex )
} catch( SQLException ex )
{
logger.info(ex.getMessage());
}finally{
@ -2183,7 +2178,8 @@ public class DBMSRecords implements ServletContextAware {
if(rs!=null) try{rs.close();}catch(SQLException ex) {}
}
/*if(result.equals(""))
/* закоментил так как теперь цифровые id и всё перенесено в базу
if(result.equals(""))
{
if(m_props==null || !user.language_id.equals(m_props_loc))
{
@ -2210,7 +2206,7 @@ public class DBMSRecords implements ServletContextAware {
}
//Translate text by patterns
public String getText(String text,User user,Connection conn) {
public String getText(Connection conn,String text,User user) {
int pos1 = 0;
while (true) {
pos1 = text.indexOf("_('", pos1);
@ -2220,7 +2216,7 @@ public class DBMSRecords implements ServletContextAware {
if (pos2 == -1)
break;
text = text.substring(0, pos1) + __(text.substring(pos1 + 3, pos2),user,conn) + text.substring(pos2 + 2);
text = text.substring(0, pos1) + __(conn,text.substring(pos1 + 3, pos2),user) + text.substring(pos2 + 2);
}
return text;
}