List of usage examples for java.util.regex Pattern split
public String[] split(CharSequence input)
From source file:com.krawler.formbuilder.servlet.workflowHandler.java
private void expwriteXml(JSONObject jsonobj, String containerId, String processId, JSONObject linejson) throws TransformerConfigurationException, TransformerException, JSONException { JSONArray jarr = jsonobj.getJSONArray("data"); JSONArray linearr = linejson.getJSONArray("data"); String split = ":"; for (int i = 0; i < jarr.length(); i++) { Pattern p = Pattern.compile(split); JSONObject jobj = jarr.getJSONObject(i); String id = jobj.getString("id"); String value = jobj.getString("value"); String[] ObjectVal = null; ObjectVal = p.split(value); if (ObjectVal[0].equals("process-swim")) { ObjectInfo obj = new ObjectInfo(); obj.objId = ObjectVal[1];/*w w w.j av a 2 s. c o m*/ obj.name = ObjectVal[2]; obj.xpos = ObjectVal[3]; obj.ypos = ObjectVal[4]; obj.width = ObjectVal[5]; obj.height = ObjectVal[6]; obj.parentId = ObjectVal[7]; obj.type = "Pool"; obj.handId = ""; obj.refId = ObjectVal[8]; this.poolContainer.add(obj); } else if (ObjectVal[0].equals("lane-swim")) { ObjectInfo obj = new ObjectInfo(); obj.objId = ObjectVal[1]; obj.name = ObjectVal[2]; obj.xpos = ObjectVal[3]; obj.ypos = ObjectVal[4]; obj.width = ObjectVal[5]; obj.height = ObjectVal[6]; obj.parentId = ObjectVal[7]; obj.processId = ObjectVal[8]; obj.refId = ObjectVal[9]; obj.type = "Lane"; obj.handId = ""; this.poolContainer.add(obj); } else { ObjectInfo obj = new ObjectInfo(); if (ObjectVal[0].equals("task-activity")) { obj.type = "task"; } else if (ObjectVal[0].equals("start")) { obj.type = "start"; obj.handId = ObjectVal[7]; } else if (ObjectVal[0].equals("end")) { obj.type = "end"; obj.handId = ObjectVal[7]; } obj.objId = ObjectVal[1]; obj.name = ObjectVal[2]; obj.xpos = ObjectVal[3]; obj.ypos = ObjectVal[4]; obj.width = ObjectVal[5]; obj.height = ObjectVal[6]; obj.parentId = ObjectVal[7]; obj.processId = ObjectVal[8]; obj.refId = ObjectVal[9]; obj.hasStart = ObjectVal[10]; obj.hasEnd = ObjectVal[11]; obj.startRefId = ObjectVal[12]; obj.endRefId = ObjectVal[13]; obj.derivationRule = ObjectVal[14]; obj.domEl = ObjectVal[15]; this.taskContainer.add(obj); } } Element rootElet = dom.createElement("Package"); rootElet.setAttribute("xmlns", "http://www.wfmc.org/2008/XPDL2.1"); dom.appendChild(rootElet); Element ele = dom.createElement("PackageHeader"); Element childElement = dom.createElement("XPDLVersion"); Text text = dom.createTextNode("2.1"); childElement.appendChild(text); ele.appendChild(childElement); rootElet.appendChild(ele); expaddPools(rootElet, containerId, processId); expaddWorkflow(rootElet, processId, linearr); }
From source file:com.krawler.formbuilder.servlet.workflowHandler.java
private void expwritebpel(JSONObject jsonobj, String containerId, String processId, JSONObject linejson) throws TransformerConfigurationException, TransformerException, JSONException { JSONArray jarr = jsonobj.getJSONArray("data"); JSONArray linearr = linejson.getJSONArray("data"); String split = ":"; for (int i = 0; i < jarr.length(); i++) { Pattern p = Pattern.compile(split); JSONObject jobj = jarr.getJSONObject(i); String id = jobj.getString("id"); String value = jobj.getString("value"); String[] ObjectVal = null; ObjectVal = p.split(value); if (ObjectVal[0].equals("process-swim")) { ObjectInfo obj = new ObjectInfo(); obj.objId = ObjectVal[1];/*from w w w . j a v a 2s.c o m*/ obj.name = ObjectVal[2]; obj.xpos = ObjectVal[3]; obj.ypos = ObjectVal[4]; obj.width = ObjectVal[5]; obj.height = ObjectVal[6]; obj.parentId = ObjectVal[7]; obj.type = "Pool"; obj.handId = ""; obj.refId = ObjectVal[8]; this.poolContainer.add(obj); } else if (ObjectVal[0].equals("lane-swim")) { ObjectInfo obj = new ObjectInfo(); obj.objId = ObjectVal[1]; obj.name = ObjectVal[2]; obj.xpos = ObjectVal[3]; obj.ypos = ObjectVal[4]; obj.width = ObjectVal[5]; obj.height = ObjectVal[6]; obj.parentId = ObjectVal[7]; obj.processId = ObjectVal[8]; obj.refId = ObjectVal[9]; obj.type = "Lane"; obj.handId = ""; this.poolContainer.add(obj); } else { ObjectInfo obj = new ObjectInfo(); if (ObjectVal[0].equals("task-activity")) { obj.type = "task"; } else if (ObjectVal[0].equals("start")) { obj.type = "start"; obj.handId = ObjectVal[7]; } else if (ObjectVal[0].equals("end")) { obj.type = "end"; obj.handId = ObjectVal[7]; } obj.objId = ObjectVal[1]; obj.name = ObjectVal[2]; obj.xpos = ObjectVal[3]; obj.ypos = ObjectVal[4]; obj.width = ObjectVal[5]; obj.height = ObjectVal[6]; obj.parentId = ObjectVal[7]; obj.processId = ObjectVal[8]; obj.refId = ObjectVal[9]; obj.hasStart = ObjectVal[10]; obj.hasEnd = ObjectVal[11]; obj.startRefId = ObjectVal[12]; obj.endRefId = ObjectVal[13]; obj.derivationRule = ObjectVal[14]; obj.domEl = ObjectVal[15]; this.taskContainer.add(obj); } } Element rootElet = dom.createElement("process"); rootElet.setAttribute("name", "mybiz_flow"); rootElet.setAttribute("targetNamespace", "http://ibm/dw/ode/bpel/executor"); rootElet.setAttribute("xmlns", "http://docs.oasis-open.org/wsbpel/2.0/process/executable"); rootElet.setAttribute("xmlns:tns", "http://ibm/dw/ode/bpel/executor"); rootElet.setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); rootElet.setAttribute("xmlns:test", "http://ibm/dw/ode/bpel/executor.wsdl"); rootElet.setAttribute("xmlns:sns", "http://ibm/dw/ode/bpel/service.wsdl"); rootElet.setAttribute("queryLanguage", "urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"); rootElet.setAttribute("expressionLanguage", "urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0"); dom.appendChild(rootElet); Element partnerLinksele = dom.createElement("partnerLinks"); Element childink1 = dom.createElement("partnerLink"); childink1.setAttribute("name", "mybiz_flowPartnerLink"); childink1.setAttribute("partnerLinkType", "test:mybiz_flowPartnerLinkType"); childink1.setAttribute("myRole", "executor"); partnerLinksele.appendChild(childink1); Element childink2 = dom.createElement("partnerLink"); childink2.setAttribute("name", "mybiz_flow_servicePartnerLink"); childink2.setAttribute("partnerLinkType", "sns:mybiz_flow_servicePartnerLinkType"); childink2.setAttribute("partnerRole", "service"); childink2.setAttribute("initializePartnerRole", "yes"); partnerLinksele.appendChild(childink2); rootElet.appendChild(partnerLinksele); //expaddPools(rootElet, containerId, processId); expanddWorkflow(rootElet, processId, linearr); }
From source file:com.tao.realweb.util.StringUtil.java
/** * ?? /*ww w.j a va2 s . c o m*/ * * @param str * ? * @param ms * ? * @return */ public static String[] splitString(String str, String ms) { String regEx = ms; Pattern p = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE); String[] sp = p.split(str); return sp; }
From source file:au.org.ala.names.search.ALANameIndexer.java
/** * Adds an ANBG CSV file of common names to the common name index. * * @param fileName The file name to add to the common name index * @param iw The index writer to write the common documents to * @param currentSearcher The searcher to find a scientific name * @param idSearcher The searcher to find an lsid * @param recordSep The record separator for the CSV file * @throws Exception/* ww w . j a v a 2 s .c om*/ */ private void addAnbgCommonNames(String fileName, IndexWriter iw, IndexSearcher currentSearcher, IndexSearcher idSearcher, char recordSep) throws Exception { File namesFile = new File(fileName); Pattern p = Pattern.compile(","); if (namesFile.exists()) { CSVReader reader = new CSVReader(new FileReader(namesFile), recordSep, '"', '\\');//CSVReader.build(namesFile,"UTF-8","\t", '"' , 1); int count = 0; String[] values = reader.readNext(); while ((values = reader.readNext()) != null) { if (values != null && values.length >= 4) { //all ANBG records should have the highest boost as they are our authoritive source //we only want to add an ANBG record if the taxon concept LSID exists in the taxonConcepts.txt export if (doesTaxonConceptExist(currentSearcher, values[3]) || doesTaxonConceptExist(idSearcher, values[3])) { //each common name could be a comma separated list if (!values[2].contains(",") || values[2].toLowerCase().contains(" and ")) { iw.addDocument(getCommonNameDocument(values[2], null, values[3], 2.0f)); count++; } else { //we need to process each common name in the list String[] names = p.split(values[2]); for (String name : names) { iw.addDocument(getCommonNameDocument(name, null, values[3], 2.0f)); count++; } } } else { System.out.println("Unable to locate LSID " + values[3] + " in current dump"); } } } log.info("Finished indexing " + count + " common names from " + fileName); } else log.warn("Unable to index common names. Unable to locate : " + fileName); }
From source file:com.tao.realweb.util.StringUtil.java
/** * html????? //from w ww .j a v a 2 s .co m * * @param str * html * @param pt * table * @return */ public static String fomateToFullForm(String str, String pt) { String regEx = "<" + pt + "\\s+([\\S&&[^<>]]*)/>"; Pattern p = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(str); String[] sa = null; String sf = ""; String sf2 = ""; String sf3 = ""; for (; m.find();) { sa = p.split(str); if (sa == null) { break; } sf = str.substring(sa[0].length(), str.indexOf("/>", sa[0].length())); sf2 = sf + "></" + pt + ">"; sf3 = str.substring(sa[0].length() + sf.length() + 2); str = sa[0] + sf2 + sf3; sa = null; } return str; }
From source file:de.dmarcini.submatix.pclogger.gui.MainCommGUI.java
/** * Ackuwert des SPX anzeigen Project: SubmatixBTConfigPC Package: de.dmarcini.submatix.pclogger.gui * /*from w w w .j ava2s.c o m*/ * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 22.01.2012 */ private void setAckuValue(String vl) { lg.debug("Value: <" + vl + ">"); double ackuValue = 0.0; Pattern fieldPatternDp = Pattern.compile(":"); String[] fields = fieldPatternDp.split(vl); if (fields.length > 1) { int val = Integer.parseInt(fields[1], 16); ackuValue = (float) (val / 100.0); // Hauptfenster frmMainWindow.setTitle(LangStrings.getString("MainCommGUI.frmMainwindowtitle.title") + " " + String.format(LangStrings.getString("MainCommGUI.akkuLabel.text"), ackuValue)); lg.debug(String.format("Acku value: %02.02f", ackuValue)); } }
From source file:wjhk.jupload2.policies.DefaultUploadPolicy.java
/** * The default behavior (see {@link DefaultUploadPolicy}) is to check that * the stringUploadSuccess applet parameter is present in the response from * the server. The return is tested, in the order below: <DIR> <LI>False, if * the stringUploadError is found. An error message is then displayed. <LI> * True, if the stringUploadSuccess is null or empty (no test at all). <LI> * True, if the stringUploadSuccess string is present in the * serverOutputBody. <LI>True, If previous condition is not filled, but the * HTTP header "HTTP(.*)200OK$" is present: the test is currently non * blocking, because I can not test all possible HTTP configurations.<BR> * <LI>False if the previous conditions are not fullfilled. </DIR> <BR> * This method also looks for the stringUploadWarning regular expression. * Each time it is matched, the found message is displayed to the user. * /* www. j av a2 s . c om*/ * @param status * The HTTP response code * @param msg * The status message from the first line of the response (e.g. * "200 OK"). * @param body * The body of the HTTP answer. * @return True or False, indicating if the upload is a success or not. * @see UploadPolicy#checkUploadSuccess(int, String, String) */ public boolean checkUploadSuccess(int status, String msg, String body) throws JUploadException { boolean bReturn = false; if (getDebugLevel() > 100) { // Let's have a little time to check the upload messages written on // the progress bar. try { Thread.sleep(300); } catch (InterruptedException e) { } } this.lastResponseBody = body; this.lastResponseMessage = msg; displayDebug("HTTP status: " + msg, 30); // HTTP-100 correction, thanks to Marc Reidy if ((status != 200) && (status != 100)) throw new JUploadExceptionUploadFailed("Received HTTP status " + msg); // HTTP-100 "continue", in case we're uploading // to an ASP.NET development server. We should // continue sending... if (status == 100) return true; // Let's analyze the body returned, line by line. The end of line // character may be CR, LF, or CRLF. We navigate through the body, and // replace any end of line character by a uniform CRLF. Matcher matcherError, matcherWarning; String line; Pattern p = Pattern.compile("[\\r\\n]", Pattern.MULTILINE); String[] lines = p.split(body); StringBuffer sbBodyWithUniformCRLF = new StringBuffer(body.length()); for (int i = 0; i < lines.length; i += 1) { line = lines[i]; sbBodyWithUniformCRLF.append(line).append("\r\n"); boolean bStatus = true; List<Map<String, String>> uploads = null; try { JSONArray jsonArray = new JSONArray(line); uploads = new ArrayList<Map<String, String>>(jsonArray.length()); for (int j = 0; j < jsonArray.length(); j++) { JSONObject jsonObj = jsonArray.getJSONObject(j); Map<String, String> map = new HashMap<String, String>(); String[] names = JSONObject.getNames(jsonObj); for (String name : names) map.put(name, jsonObj.getString(name)); uploads.add(map); if (!"SUCCESS".equals(map.get("status"))) { bStatus = false; } else { System.out.println("Upload of " + map.get("name") + " completed successfully"); } } } catch (JSONException e) { e.printStackTrace(); } // FIXME some empty lines are given by the server // Let's remove the empty line: with the p pattern, a multiline is // generated each time a \r\n is received, that is: for each line. if (line == null || line.equals("")) { // An empty line. Let's go the next line. continue; } // Check if this is a success // The success string should be in the http body if (getStringUploadSuccess() != null && !getStringUploadSuccess().equals("")) { if (this.patternSuccess.matcher(line).matches()) { // We go on. There may be some WARNING message, hereafter. bReturn = true; } } if (bStatus) bReturn = true; // Check if this is an error if (getStringUploadError() != null && !getStringUploadError().equals("")) { matcherError = this.patternError.matcher(line); if (matcherError.matches()) { String errmsg = "An error occurs during upload (but the applet couldn't find the error message)"; if (matcherError.groupCount() > 0) { if (!matcherError.group(1).equals("")) { // Let's do a (very simple) formatting: one line to // 100 characters errmsg = formatMessage(matcherError.group(1)); } } this.lastResponseMessage = errmsg; throw new JUploadExceptionUploadFailed(errmsg); } } // getStringUploadError // Check if this is an warning if (getStringUploadWarning() != null && !getStringUploadWarning().equals("")) { matcherWarning = this.patternWarning.matcher(line); if (matcherWarning.matches()) { String warnmsg = "A warning occurs during upload (but the applet couldn't find the warning message)"; if (matcherWarning.groupCount() > 0) { if (!matcherWarning.group(1).equals("")) { warnmsg = formatMessage(matcherWarning.group(1)); } } this.lastResponseMessage = warnmsg; displayWarn(warnmsg); alertStr(warnmsg); } } // getStringUploadWarning } // while(st.hasMoreTokens()) if (bReturn) { return true; } // We found no stringUploadSuccess nor stringUploadError if (getStringUploadSuccess() == null || getStringUploadSuccess().equals("")) { // No chance to check the correctness of this upload. -> Assume Ok return true; } // stringUploadSuccess was defined but we did not find it. // This is most certainly an error as http-status 200 does *not* refer // to the correctness of the content. It merely means that the protocol // handling was ok. -> throw an exception throw new JUploadExceptionUploadFailedSuccessNotFound( getClass().getName() + ".checkUploadSuccess(): The regexp string \"" + getStringUploadSuccess() + "\" was not found in the response body"); }
From source file:com.clustercontrol.ping.factory.RunMonitorPing.java
/** * fping???IP??????<BR>/*from w ww. jav a 2 s . c o m*/ * nodeMap?????public * * @param hosts fping??? * @param message * @param count ping * @return (IP ??)?? */ public Hashtable<String, PingResult> wrapUpFping(ArrayList<String> messages, int count, int version) { Hashtable<String, PingResult> ret = new Hashtable<String, PingResult>(); HashMap<String, String> normalMap = new HashMap<String, String>(); //IP, HashMap<String, String> aberrantMap = new HashMap<String, String>(); //IP, HashSet<String> hostSet = new HashSet<String>(); /** * ????????5? * ??? * **/ String msg; String msgOrg; int lost; float average = 0; float reachRatio; //IP??? Pattern patternIp; if (version == 6) { patternIp = Pattern.compile("^([0-9].*)|^(\\:\\:.*)"); } else { patternIp = Pattern.compile("^([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}.*)"); } //fping?? Pattern patternSp = Pattern.compile("(\\s:\\s|\\s)+"); //? Pattern patternNormal = Pattern.compile("([0-9]+\\.[0-9]+|-)"); //IP Matcher matcherIp; Matcher matcherValue; String message; /* * fping??? * ??? 127.0.0.1 : 0.10 1.23 * ???? 127.0.0.1 : - - * ???(?IP???) 127.0.0.1 : duplicate for [0], xx bytes, x.xx ms * ???(GW??????) 127.0.0.1 : () * ?? * ???????????????????? * 2???????????? * ???????IP???????? * ????? */ /* * ????? */ Iterator<String> itr = messages.iterator(); m_log.debug("wrapUpFping(): start logic: " + messages.size()); while (itr.hasNext()) { message = itr.next(); m_log.debug("wrapUpFping(): checkpoint"); //IP?????????? boolean bValidIP = false; if (version == 6) { m_log.debug("wrapUpFping(): into IPv6 loop"); String[] strs = message.split(" "); try { InetAddress.getByName(strs[0]); bValidIP = true; } catch (Exception e) { m_log.warn("wrapUpFping() invalid IPv6 adress: original message: " + message, e); m_log.warn("wrapUpFping() stack trace: " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); } } else { matcherIp = patternIp.matcher(message); if (matcherIp.matches()) { bValidIP = true; } } if (bValidIP) { //?IP???????? String[] strs = patternSp.split(message); //?IP??? boolean isNormal = true; for (int i = 1; i < strs.length; i++) { matcherValue = patternNormal.matcher(strs[i]); if (!matcherValue.matches()) { isNormal = false; } } if (isNormal) { normalMap.put(strs[0], message); m_log.debug("wrapUpFping() : normalValue : " + message); } else { // ??IP??????? if (aberrantMap.get(strs[0]) != null && !(aberrantMap.get(strs[0])).equals("")) { String aberrantMessage = aberrantMap.get(strs[0]); aberrantMessage = aberrantMessage + "\n" + message; aberrantMap.put(strs[0], aberrantMessage); } else { aberrantMap.put(strs[0], message); } m_log.debug("wrapUpFping() : aberrantValue : " + message); } hostSet.add(strs[0]); } } /* * ?????????? */ itr = hostSet.iterator(); m_log.debug("wrapUpFping() : before into check result append loop"); while (itr.hasNext()) { m_log.debug("wrapUpFping() : after into check result append loop"); String host = itr.next(); String normalMessage = normalMap.get(host); String aberrantMessage = aberrantMap.get(host); if (normalMessage != null && !normalMessage.equals("")) { // String ?? String[] strs = patternSp.split(normalMessage); /*????????*/ float max = 0; //(?0) float min = Float.MAX_VALUE; //?(?Float?) int num = 0; //? //???????? for (int i = 1; i <= count; i++) { if (strs[i].equals("-")) { //?-???????? } else { //?count up num++; //??? if (max < Float.parseFloat(strs[i])) { max = Float.parseFloat(strs[i]); } //???? if (min > Float.parseFloat(strs[i])) { min = Float.parseFloat(strs[i]); } //? average += Float.parseFloat(strs[i]); } } //????????????? average /= num; /* * ??? */ StringBuffer buffer = new StringBuffer(); buffer.append("Pinging " + host + " (" + host + ") .\n\n"); // ??0?? if (num == 0) { //??0??lost100 reach0 lost = 100; reachRatio = 0; for (int i = 0; i < count; i++) // buffer.append("From " + strs[0] + " icmp_seq="+ index +" Destination Host Unreachable"); buffer.append("Reply from " + host + " icmp_seq=" + i + " Destination Host Unreachable\n"); buffer.append("\nPing statistics for " + host + ":\n"); buffer.append("Packets: Sent = " + count + ", Received = " + num + ", Lost = " + (count - num) + " (" + lost + "% loss),"); } else { lost = (count - num) * 100 / count; reachRatio = (float) num * 100 / count; buffer.append("\nPing statistics for " + host + ":\n"); buffer.append("Packets: Sent = " + count + ", Received = " + num + ", Lost = " + (count - num) + " (" + lost + "% loss),"); buffer.append("Approximate round trip times in milli-seconds:\n"); buffer.append( "\tMinimum = " + min + "ms, Maximum = " + max + "ms, Average = " + average + "ms\n"); } // ?????msgOrg? if (aberrantMessage != null && !aberrantMessage.equals("")) { buffer.append("\n\n" + aberrantMessage + "\n"); } msgOrg = buffer.toString(); msg = "Packets: Sent = " + count + ", Received = " + num + ", Lost = " + (count - num) + " (" + lost + "% loss)"; PingResult res = new PingResult(host, msg, msgOrg, lost, average, reachRatio); ret.put(host, res); m_log.debug("wrapUpFping() : success msg = " + msg + ", msgOrg = " + msgOrg); msg = ""; msgOrg = ""; lost = 100; average = 0; reachRatio = 0; } // ?????? else { msg = "Failed to get a value."; msgOrg = "Failed to get a value."; if (aberrantMessage != null && !aberrantMessage.equals("")) { msgOrg = msgOrg + "\n\n" + aberrantMessage; } PingResult res = new PingResult(host, msg, msgOrg, -1, -1, -1); ret.put(host, res); m_log.debug("wrapUpFping() : failure msg = " + msg + ", msgOrg = " + msgOrg); msg = ""; msgOrg = ""; } } return ret; }
From source file:com.tmwsoft.sns.web.action.MainAction.java
public ActionForward cp_magic(HttpServletRequest request, HttpServletResponse response) { Map<String, Object> sGlobal = (Map<String, Object>) request.getAttribute("sGlobal"); Map<String, Object> sConfig = (Map<String, Object>) request.getAttribute("sConfig"); Map<Integer, String> sNames = (Map<Integer, String>) request.getAttribute("sNames"); String op = request.getParameter("op"); op = Common.empty(op) ? "view" : op; String mid = Common.trim(request.getParameter("mid")); int supe_uid = (Integer) sGlobal.get("supe_uid"); int timestamp = (Integer) sGlobal.get("timestamp"); Map<String, Object> space = Common.getSpace(request, sGlobal, sConfig, supe_uid); if (!Common.checkPerm(request, response, "allowmagic")) { MessageVO msgVO = Common.ckSpaceLog(request); if (msgVO != null) { return showMessage(request, response, msgVO); }/* w w w . j a va 2s .c o m*/ return showMessage(request, response, "magic_groupid_not_allowed"); } Map<String, Object> magic = null; if (!mid.equals("")) { Object result = propsService.magic_get(mid); if (result instanceof MessageVO) { return showMessage(request, response, (MessageVO) result); } magic = (Map<String, Object>) result; } boolean sc_buysubmit = false; boolean sc_presentsubmit = false; try { sc_buysubmit = submitCheck(request, "buysubmit"); if (!sc_buysubmit) { sc_presentsubmit = submitCheck(request, "presentsubmit"); } } catch (Exception e) { return showMessage(request, response, e.getMessage()); } if (sc_buysubmit) { if (mid.equals("")) { return showMessage(request, response, "unknown_magic"); } Object result = propsService.magic_buy_get(request, response, magic, sGlobal, space); if (result instanceof MessageVO) { return showMessage(request, response, (MessageVO) result); } Map<String, Object> datas = (Map<String, Object>) result; Map<String, Object> magicstore = (Map<String, Object>) datas.get("magicstore"); Map<String, Object> coupon = (Map<String, Object>) datas.get("coupon"); result = propsService.magic_buy_post(request, response, sGlobal, space, magic, magicstore, coupon); if (result instanceof MessageVO) { return showMessage(request, response, (MessageVO) result); } int charge = (Integer) result; if ((Integer) magic.get("experience") != 0) { String buynumS = request.getParameter("buynum"); int buynum = buynumS != null ? Common.intval(buynumS.trim()) : 0; return showMessage(request, response, "magicbuy_success_with_experence", request.getParameter("refer"), 0, charge + "", ((Integer) magic.get("experience") * buynum) + ""); } else { return showMessage(request, response, "magicbuy_success", request.getParameter("refer"), 0, charge + ""); } } else if (sc_presentsubmit) { if (mid.equals("")) { return showMessage(request, response, "unknown_magic"); } if (mid.equals("license")) { return showMessage(request, response, "magic_can_not_be_presented"); } String fusername = request.getParameter("fusername"); fusername = fusername == null ? fusername : fusername.trim(); if (Common.empty(fusername)) { return showMessage(request, response, "bad_friend_username_given"); } try { fusername = Common.getStr(fusername, 15, false, false, false, 0, 0, request, response); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } List<Map<String, Object>> query = dataBaseService.executeQuery( "SELECT * FROM sns_friend WHERE uid = '" + supe_uid + "' AND fusername='" + fusername + "'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; if (value == null) { return showMessage(request, response, "bad_friend_username_given"); } int fuid = (Integer) value.get("fuid"); Map<String, Map<String, Object>> usermagics = new HashMap<String, Map<String, Object>>(); query = dataBaseService.executeQuery("SELECT * FROM sns_usermagic WHERE uid='" + supe_uid + "' AND mid IN('license', '" + mid + "')"); for (Map<String, Object> value_ : query) { usermagics.put((String) value_.get("mid"), value_); } Map<String, Object> tempMap = usermagics.get("license"); if (tempMap == null || (Integer) tempMap.get("count") == 0) { return showMessage(request, response, "has_no_more_present_magic"); } tempMap = usermagics.get(mid); if (tempMap == null || (Integer) tempMap.get("count") == 0) { return showMessage(request, response, "has_no_more_magic", null, 0, (String) magic.get("name"), "a_buy_" + mid, "main.action?ac=magic&op=buy&mid=" + mid); } dataBaseService.execute("UPDATE sns_usermagic SET count = count - 1 WHERE uid = '" + supe_uid + "' AND mid IN ('license', '" + mid + "')"); query = dataBaseService .executeQuery("SELECT * FROM sns_usermagic WHERE uid='" + fuid + "' AND mid='" + mid + "'"); value = query.size() > 0 ? query.get(0) : null; int count = value != null ? (Integer) value.get("count") + 1 : 1; Map<String, Object> insertData = new HashMap<String, Object>(); insertData.put("uid", fuid); insertData.put("username", fusername); insertData.put("mid", mid); insertData.put("count", count); dataBaseService.insertTable("sns_usermagic", insertData, false, true); insertData.clear(); insertData.put("uid", fuid); insertData.put("username", fusername); insertData.put("mid", mid); insertData.put("count", 1); insertData.put("type", 2); insertData.put("fromid", supe_uid); insertData.put("credit", 0); insertData.put("dateline", timestamp); dataBaseService.insertTable("sns_magicinlog", insertData, false, false); String note = Common.getMessage(request, "cp_magic_present_note", (String) magic.get("name"), "main.action?ac=magic&view=me&mid=" + mid); note = note == null ? "magic_present_note" : note; mainService.addNotification(request, sGlobal, sConfig, fuid, "magic", note, false); return showMessage(request, response, "magicpresent_success", request.getParameter("refer"), 0, fusername); } if ("buy".equals(op)) { Object result = propsService.magic_buy_get(request, response, magic, sGlobal, space); if (result instanceof MessageVO) { return showMessage(request, response, (MessageVO) result); } Map<String, Object> datas = (Map<String, Object>) result; Map<String, Object> magicstore = (Map<String, Object>) datas.get("magicstore"); Map<String, Object> coupon = (Map<String, Object>) datas.get("coupon"); request.setAttribute("mid", mid); request.setAttribute("magicstore", magicstore); request.setAttribute("coupon", coupon); request.setAttribute("discount", datas.get("discount")); request.setAttribute("charge", datas.get("charge")); String ac = request.getParameter("ac"); request.setAttribute("ac", ac != null ? ac.trim() : ""); request.setAttribute("magic", magic); } else if ("present".equals(op)) { if (mid.equals("license")) { return showMessage(request, response, "magic_can_not_be_presented"); } Map<String, Map<String, Object>> usermagics = new HashMap<String, Map<String, Object>>(); List<Map<String, Object>> query = dataBaseService.executeQuery("SELECT * FROM sns_usermagic WHERE uid='" + supe_uid + "' AND mid IN('license', '" + mid + "')"); for (Map<String, Object> value : query) { usermagics.put((String) value.get("mid"), value); } Map<String, Object> tempMap = usermagics.get("license"); if (tempMap == null || (Integer) tempMap.get("count") == 0) { return showMessage(request, response, "has_no_more_present_magic"); } tempMap = usermagics.get(mid); if (tempMap == null || (Integer) tempMap.get("count") == 0) { return showMessage(request, response, "has_no_more_magic", null, 0, (String) magic.get("name"), "a_buy_" + mid, "main.action?ac=magic&op=buy&mid=" + mid); } request.setAttribute("mid", mid); request.setAttribute("magic", magic); } else if ("showusage".equals(op)) { if (mid.equals("")) { return showMessage(request, response, "unknown_magic"); } request.setAttribute("mid", mid); } else if ("receive".equals(op)) { String uidS = request.getParameter("uid"); int uid = uidS != null ? Common.intval(uidS.trim()) : 0; List<Map<String, Object>> query = dataBaseService .executeQuery("SELECT * FROM sns_magicuselog WHERE uid='" + uid + "' AND mid='gift' LIMIT 1"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; String value_data; if (value != null && (value_data = (String) value.get("data")) != null && !value_data.equals("")) { Map<String, Object> data = Serializer.unserialize(value_data, false); if ((Integer) data.get("left") <= 0) { return showMessage(request, response, "magic_gift_already_given_out"); } Map<Integer, Integer> receiver = (Map<Integer, Integer>) data.get("receiver"); if (receiver == null) { receiver = new HashMap<Integer, Integer>(); data.put("receiver", receiver); } int receiverIndex = 0; for (Entry<Integer, Integer> entry : receiver.entrySet()) { if (entry.getValue() == supe_uid) { return showMessage(request, response, "magic_had_got_gift"); } receiverIndex = Math.max(receiverIndex, entry.getKey()); } int data_left = (Integer) data.get("left"); int data_chunk = (Integer) data.get("chunk"); int credit = Math.min(data_chunk, data_left); receiver.put(++receiverIndex, supe_uid); data_left = data_left - credit; data.put("left", data_left); if (data_left > 0) { Map<String, Object> setData = new HashMap<String, Object>(); setData.put("data", Serializer.serialize(data)); Map<String, Object> whereData = new HashMap<String, Object>(); whereData.put("logid", value.get("logid")); dataBaseService.updateTable("sns_magicuselog", setData, whereData); } else { dataBaseService .execute("DELETE FROM sns_magicuselog WHERE logid = '" + value.get("logid") + "'"); } dataBaseService.execute( "UPDATE sns_space SET credit = credit + '" + credit + "' WHERE uid='" + supe_uid + "'"); return showMessage(request, response, "magic_got_gift", null, 0, credit + ""); } else { return showMessage(request, response, "magic_has_no_gift"); } } else if ("appear".equals(op)) { Map<String, Object> session_member = (Map<String, Object>) sGlobal.get("session"); if (session_member == null || (Integer) session_member.get("magichidden") == 0) { return showMessage(request, response, "magic_not_hidden_yet"); } boolean scb = false; try { scb = submitCheck(request, "appearsubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { Map<String, Object> setData = new HashMap<String, Object>(); Map<String, Object> whereData = new HashMap<String, Object>(); setData.put("magichidden", "0"); whereData.put("uid", supe_uid); dataBaseService.updateTable("sns_session", setData, whereData); setData.clear(); setData.put("expire", timestamp); whereData.put("mid", "invisible"); dataBaseService.updateTable("sns_magicuselog", setData, whereData); return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } } else if ("retrieve".equals(op)) { List<Map<String, Object>> query = dataBaseService .executeQuery("SELECT * FROM sns_magicuselog WHERE uid = '" + supe_uid + "' AND mid = 'gift'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; int leftcredit = 0; String dataS = null; if (value == null) { return showMessage(request, response, "not_set_gift"); } else if ((dataS = (String) value.get("data")) != null && !dataS.equals("")) { Map<String, Object> data = Serializer.unserialize(dataS, false); leftcredit = (Integer) data.get("left"); } boolean scb = false; try { scb = submitCheck(request, "retrievesubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { dataBaseService .execute("DELETE FROM sns_magicuselog WHERE uid = '" + supe_uid + "' AND mid = 'gift'"); dataBaseService.execute( "UPDATE sns_space SET credit = credit + " + leftcredit + " WHERE uid = '" + supe_uid + "'"); return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } request.setAttribute("leftcredit", leftcredit); } else if ("cancelsuperstar".equals(op)) { mid = "superstar"; List<Map<String, Object>> query = dataBaseService .executeQuery("SELECT * FROM sns_spacefield WHERE uid = '" + supe_uid + "'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; Integer magicstar; if (value == null || (magicstar = (Integer) value.get("magicstar")) == null || magicstar == 0) { return showMessage(request, response, "not_superstar_yet"); } boolean scb = false; try { scb = submitCheck(request, "cancelsubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { Map<String, Object> setData = new HashMap<String, Object>(); Map<String, Object> whereData = new HashMap<String, Object>(); setData.put("magicstar", 0); whereData.put("uid", supe_uid); dataBaseService.updateTable("sns_spacefield", setData, whereData); setData.clear(); setData.put("expire", timestamp); whereData.put("mid", "superstar"); dataBaseService.updateTable("sns_magicuselog", setData, whereData); return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } } else if ("cancelflicker".equals(op)) { mid = "flicker"; String idtype = "cid"; String idS = request.getParameter("id"); int id = idS != null ? Common.intval(idS.trim()) : 0; List<Map<String, Object>> query = dataBaseService.executeQuery( "SELECT * FROM sns_comment WHERE cid = '" + id + "' AND authorid = '" + supe_uid + "'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; Integer magicflicker; if (value == null || (magicflicker = (Integer) value.get("magicflicker")) == null || magicflicker == 0) { return showMessage(request, response, "no_flicker_yet"); } boolean scb = false; try { scb = submitCheck(request, "cancelsubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { Map<String, Object> setData = new HashMap<String, Object>(); setData.put("magicflicker", 0); Map<String, Object> whereData = new HashMap<String, Object>(); whereData.put("cid", id); whereData.put("authorid", supe_uid); dataBaseService.updateTable("sns_comment", setData, whereData); return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } request.setAttribute("id", id); request.setAttribute("idtype", idtype); request.setAttribute("mid", mid); } else if ("cancelcolor".equals(op)) { mid = "color"; String idS = request.getParameter("id"); int id = idS != null ? Common.intval(idS.trim()) : 0; String idtype = request.getParameter("idtype"); if (idtype == null) { return showMessage(request, response, "access error : 00001"); } idtype = idtype.trim(); Map<String, String> mapping = new HashMap<String, String>(); mapping.put("blogid", "sns_blogfield"); mapping.put("tid", "sns_thread"); String tablename = mapping.get(idtype); if (Common.empty(tablename)) { return showMessage(request, response, "no_color_yet"); } List<Map<String, Object>> query = dataBaseService.executeQuery("SELECT * FROM " + tablename + " WHERE " + idtype + " = '" + id + "' AND uid = '" + supe_uid + "'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; Integer magiccolor; if (value == null || (magiccolor = (Integer) value.get("magiccolor")) == null || magiccolor == 0) { return showMessage(request, response, "no_color_yet"); } boolean scb = false; try { scb = submitCheck(request, "cancelsubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { Map<String, Object> setData = new HashMap<String, Object>(); setData.put("magiccolor", 0); Map<String, Object> whereData = new HashMap<String, Object>(); whereData.put(idtype, id); dataBaseService.updateTable(tablename, setData, whereData); query = dataBaseService.executeQuery( "SELECT * FROM sns_feed WHERE id = '" + id + "' AND idtype = '" + idtype + "'"); Map<String, Object> feed = query.size() > 0 ? query.get(0) : null; if (feed != null) { String body_data = (String) feed.get("body_data"); Map body_data_subMap = Serializer.unserialize(body_data, false); body_data_subMap.remove("magic_color"); body_data = Serializer.serialize(body_data_subMap); setData.clear(); whereData.clear(); setData.put("body_data", body_data); whereData.put("feedid", feed.get("feedid")); dataBaseService.updateTable("sns_feed", setData, whereData); } return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } request.setAttribute("id", id); request.setAttribute("idtype", idtype); request.setAttribute("mid", mid); } else if ("cancelframe".equals(op)) { mid = "frame"; String idtype = "picid"; String idS = request.getParameter("id"); int id = idS != null ? Common.intval(idS.trim()) : 0; List<Map<String, Object>> query = dataBaseService .executeQuery("SELECT * FROM sns_pic WHERE picid = '" + id + "' AND uid = '" + supe_uid + "'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; Integer magicframe; if (value == null || (magicframe = (Integer) value.get("magicframe")) == null || magicframe == 0) { return showMessage(request, response, "no_frame_yet"); } boolean scb = false; try { scb = submitCheck(request, "cancelsubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { Map<String, Object> setData = new HashMap<String, Object>(); setData.put("magicframe", 0); Map<String, Object> whereData = new HashMap<String, Object>(); whereData.put("picid", id); dataBaseService.updateTable("sns_pic", setData, whereData); return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } request.setAttribute("id", id); request.setAttribute("idtype", idtype); request.setAttribute("mid", mid); } else if ("cancelbgimage".equals(op)) { mid = "bgimage"; String idtype = "blogid"; String idS = request.getParameter("id"); int id = idS != null ? Common.intval(idS.trim()) : 0; List<Map<String, Object>> query = dataBaseService.executeQuery( "SELECT * FROM sns_blogfield WHERE blogid = '" + id + "' AND uid = '" + supe_uid + "'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; Integer magicpaper; if (value == null || (magicpaper = (Integer) value.get("magicpaper")) == null || magicpaper == 0) { return showMessage(request, response, "no_bgimage_yet"); } boolean scb = false; try { scb = submitCheck(request, "cancelsubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { Map<String, Object> setData = new HashMap<String, Object>(); setData.put("magicpaper", 0); Map<String, Object> whereData = new HashMap<String, Object>(); whereData.put("blogid", id); dataBaseService.updateTable("sns_blogfield", setData, whereData); return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } request.setAttribute("id", id); request.setAttribute("idtype", idtype); request.setAttribute("mid", mid); } else { String view = request.getParameter("view"); if (view != null) { view = view.trim(); } if ("me".equals(view)) { Map<String, String> types = new HashMap<String, String>(); types.put("list", " class=\"active\""); request.setAttribute("types", types); Map<String, Map<String, Object>> list = null; StringBuilder ids = new StringBuilder(); Map<String, Map<String, Object>> magics = new HashMap<String, Map<String, Object>>(); List<Map<String, Object>> query = null; if (!mid.equals("")) { magics.put(mid, magic); ids.append("'"); ids.append(mid); ids.append("'"); } else { query = dataBaseService.executeQuery("SELECT * FROM sns_magic WHERE close = '0'"); String tempS; Pattern pattern = Pattern.compile(","); boolean existMid = false; for (Map<String, Object> value : query) { tempS = (String) value.get("forbiddengid"); if (tempS != null) { value.put("forbiddengid", pattern.split(tempS)); } else { value.put("forbiddengid", new String[0]); } tempS = (String) value.get("mid"); magics.put(tempS, value); if (existMid) { ids.append(","); } else { existMid = true; } ids.append("'"); ids.append(tempS); ids.append("'"); } } query = dataBaseService.executeQuery("SELECT * FROM sns_usermagic WHERE uid='" + supe_uid + "' AND mid IN (" + ids.toString() + ") AND count > 0"); if (query.size() > 0) { list = new LinkedHashMap<String, Map<String, Object>>(); for (Map<String, Object> value : query) { list.put((String) value.get("mid"), value); } } request.setAttribute("list", list); request.setAttribute("magics", magics); request.setAttribute("mid", mid); } else if ("log".equals(view)) { String type = request.getParameter("type"); type = type != null && ((type = type.trim()).equals("in") || type.equals("out") || type.equals("present")) ? type : "in"; request.setAttribute("gType", type); Map<String, String> types = new HashMap<String, String>(); types.put(type, " class=\"active\""); request.setAttribute("types", types); int perpage = 20; String pageGet = request.getParameter("page"); int page = Common.empty(pageGet) ? 0 : Common.intval(pageGet); if (page < 1) page = 1; int start = (page - 1) * perpage; int maxPage = (Integer) sConfig.get("maxpage"); String result = Common.ckStart(start, perpage, maxPage); if (result != null) { return showMessage(request, response, result); } List<Map<String, Object>> list = null; List<Map<String, Object>> query = null; int count = 0; if ("in".equals(type)) { List<Integer> uids = null; query = dataBaseService.executeQuery( "SELECT COUNT(*) AS cont FROM sns_magicinlog WHERE uid = '" + supe_uid + "'"); count = query.size() > 0 ? (Integer) query.get(0).get("cont") : 0; if (count != 0) { query = dataBaseService.executeQuery("SELECT * FROM sns_magicinlog WHERE uid = '" + supe_uid + "' ORDER BY dateline DESC LIMIT " + start + ", " + perpage); list = query.size() > 0 ? query : null; uids = new ArrayList<Integer>(); for (Map<String, Object> value : query) { value.put("dateline", Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("dateline"), true)); if ((Integer) value.get("type") == 2) { uids.add((Integer) value.get("fromid")); } } } if (uids != null && uids.size() > 0) { query = dataBaseService.executeQuery( "SELECT * FROM sns_member WHERE uid IN (" + Common.sImplode(uids) + ")"); } } else if ("present".equals(type)) { query = dataBaseService.executeQuery( "SELECT COUNT(*) AS cont FROM sns_magicinlog WHERE type = 2 AND fromid = '" + supe_uid + "'"); count = query.size() > 0 ? (Integer) query.get(0).get("cont") : 0; if (count != 0) { query = dataBaseService .executeQuery("SELECT * FROM sns_magicinlog WHERE type = 2 AND fromid = '" + supe_uid + "' ORDER BY dateline DESC LIMIT " + start + ", " + perpage); list = query.size() > 0 ? query : null; for (Map<String, Object> value : query) { value.put("dateline", Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("dateline"), true)); } } } else { query = dataBaseService.executeQuery( "SELECT COUNT(*) AS cont FROM sns_magicuselog WHERE uid = '" + supe_uid + "'"); count = query.size() > 0 ? (Integer) query.get(0).get("cont") : 0; if (count != 0) { query = dataBaseService.executeQuery("SELECT * FROM sns_magicuselog WHERE uid = '" + supe_uid + "' ORDER BY dateline DESC LIMIT " + start + ", " + perpage); list = query.size() > 0 ? query : null; for (Map<String, Object> value : query) { value.put("dateline", Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("dateline"), true)); value.put("data", Serializer.unserialize((String) value.get("data"), false)); value.put("expire", Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("expire"), false)); } } } String theurl = "main.action?ac=magic&view=log&type=" + type; String multi = Common.multi(request, count, perpage, page, maxPage, theurl, "", ""); request.setAttribute("multi", multi); request.setAttribute("list", list); } else { view = "store"; String order = request.getParameter("order"); if (order != null) { order = order.trim(); } order = "hot".equals(order) ? order : "default"; Map<String, String> orders = new HashMap<String, String>(); orders.put(order, " class=\"active\""); request.setAttribute("orders", orders); List<Map<String, Object>> query; Map<String, Map<String, Object>> magics = new HashMap<String, Map<String, Object>>(); List<String> ids = null; Map<String, Map<String, Object>> list = new LinkedHashMap<String, Map<String, Object>>(); String[] blacklist = { "coupon" }; if (!mid.equals("")) { magics.put(mid, magic); ids = new ArrayList<String>(1); ids.add(mid); } else { String orderby = order.equals("hot") ? "" : " ORDER BY displayorder"; query = dataBaseService.executeQuery("SELECT * FROM sns_magic" + orderby); String tempS; Pattern pattern = Pattern.compile(","); ids = new ArrayList<String>(query.size()); for (Map<String, Object> value : query) { if ((Integer) value.get("close") == 1 || Common.in_array(blacklist, value.get("mid"))) { continue; } tempS = (String) value.get("forbiddengid"); if (tempS != null) { value.put("forbiddengid", pattern.split(tempS)); } else { value.put("forbiddengid", new String[0]); } tempS = (String) value.get("mid"); magics.put(tempS, value); ids.add(tempS); } } if (Common.empty(magics)) { return showMessage(request, response, "magic_store_is_closed"); } String orderby = order.equals("hot") ? " ORDER BY sellcount DESC" : ""; query = dataBaseService.executeQuery( "SELECT * FROM sns_magicstore WHERE mid IN (" + Common.sImplode(ids) + ")" + orderby); String[] oldids = new String[query.size()]; int ti = 0; int providecount; String ts; for (Map<String, Object> value : query) { ts = (String) value.get("mid"); list.put(ts, value); oldids[ti++] = ts; providecount = (Integer) magics.get(ts).get("providecount"); if ((Integer) value.get("storage") < providecount && (Integer) value.get("lastprovide") + (Integer) magics.get(ts).get("provideperoid") < timestamp) { dataBaseService.execute("UPDATE sns_magicstore SET storage = '" + providecount + "', lastprovide = '" + timestamp + "' WHERE mid = '" + ts + "'"); list.get(ts).put("storage", providecount); } } List<String> newids = new ArrayList<String>(); for (String id : ids) { if (!Common.in_array(oldids, id)) { newids.add(id); } } int newidsSize = newids.size(); if (newidsSize > 0) { String[] inserts = new String[newidsSize]; ti = 0; StringBuilder builder = new StringBuilder(); Map<String, Object> listValue; for (String id : newids) { builder.delete(0, builder.length()); builder.append("('"); builder.append(id); builder.append("', '"); builder.append(magics.get(id).get("providecount")); builder.append("', '"); builder.append(timestamp); builder.append("')"); inserts[ti++] = builder.toString(); listValue = new HashMap<String, Object>(); listValue.put("mid", id); listValue.put("storage", magics.get(id).get("providecount")); listValue.put("lastprovide", timestamp); list.put(id, listValue); } dataBaseService.execute("INSERT INTO sns_magicstore (mid, storage, lastprovide) VALUES " + Common.implode(inserts, ",")); } if (order.equals("default")) { Map<String, Map<String, Object>> tempMap = new LinkedHashMap<String, Map<String, Object>>(); for (String id : ids) { tempMap.put(id, list.get(id)); } list = tempMap; } request.setAttribute("space", space); request.setAttribute("blacklist", blacklist); request.setAttribute("magics", magics); request.setAttribute("mid", mid); request.setAttribute("list", list); } Map<String, String> actives = new HashMap<String, String>(); actives.put(view, " class=\"active\""); request.setAttribute("actives", actives); } request.setAttribute("op", op); return include(request, response, sConfig, sGlobal, "cp_magic.jsp"); }
From source file:cn.jcenterhome.web.action.CpAction.java
public ActionForward cp_magic(HttpServletRequest request, HttpServletResponse response) { Map<String, Object> sGlobal = (Map<String, Object>) request.getAttribute("sGlobal"); Map<String, Object> sConfig = (Map<String, Object>) request.getAttribute("sConfig"); Map<Integer, String> sNames = (Map<Integer, String>) request.getAttribute("sNames"); String op = request.getParameter("op"); op = Common.empty(op) ? "view" : op; String mid = Common.trim(request.getParameter("mid")); int supe_uid = (Integer) sGlobal.get("supe_uid"); int timestamp = (Integer) sGlobal.get("timestamp"); Map<String, Object> space = Common.getSpace(request, sGlobal, sConfig, supe_uid); if (!Common.checkPerm(request, response, "allowmagic")) { MessageVO msgVO = Common.ckSpaceLog(request); if (msgVO != null) { return showMessage(request, response, msgVO); }/*from w ww. j a va 2 s . c o m*/ return showMessage(request, response, "magic_groupid_not_allowed"); } Map<String, Object> magic = null; if (!mid.equals("")) { Object result = magicService.magic_get(mid); if (result instanceof MessageVO) { return showMessage(request, response, (MessageVO) result); } magic = (Map<String, Object>) result; } boolean sc_buysubmit = false; boolean sc_presentsubmit = false; try { sc_buysubmit = submitCheck(request, "buysubmit"); if (!sc_buysubmit) { sc_presentsubmit = submitCheck(request, "presentsubmit"); } } catch (Exception e) { return showMessage(request, response, e.getMessage()); } if (sc_buysubmit) { if (mid.equals("")) { return showMessage(request, response, "unknown_magic"); } Object result = magicService.magic_buy_get(request, response, magic, sGlobal, space); if (result instanceof MessageVO) { return showMessage(request, response, (MessageVO) result); } Map<String, Object> datas = (Map<String, Object>) result; Map<String, Object> magicstore = (Map<String, Object>) datas.get("magicstore"); Map<String, Object> coupon = (Map<String, Object>) datas.get("coupon"); result = magicService.magic_buy_post(request, response, sGlobal, space, magic, magicstore, coupon); if (result instanceof MessageVO) { return showMessage(request, response, (MessageVO) result); } int charge = (Integer) result; if ((Integer) magic.get("experience") != 0) { String buynumS = request.getParameter("buynum"); int buynum = buynumS != null ? Common.intval(buynumS.trim()) : 0; return showMessage(request, response, "magicbuy_success_with_experence", request.getParameter("refer"), 0, charge + "", ((Integer) magic.get("experience") * buynum) + ""); } else { return showMessage(request, response, "magicbuy_success", request.getParameter("refer"), 0, charge + ""); } } else if (sc_presentsubmit) { if (mid.equals("")) { return showMessage(request, response, "unknown_magic"); } if (mid.equals("license")) { return showMessage(request, response, "magic_can_not_be_presented"); } String fusername = request.getParameter("fusername"); fusername = fusername == null ? fusername : fusername.trim(); if (Common.empty(fusername)) { return showMessage(request, response, "bad_friend_username_given"); } try { fusername = Common.getStr(fusername, 15, false, false, false, 0, 0, request, response); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } List<Map<String, Object>> query = dataBaseService .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("friend") + " WHERE uid = '" + supe_uid + "' AND fusername='" + fusername + "'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; if (value == null) { return showMessage(request, response, "bad_friend_username_given"); } int fuid = (Integer) value.get("fuid"); Map<String, Map<String, Object>> usermagics = new HashMap<String, Map<String, Object>>(); query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("usermagic") + " WHERE uid='" + supe_uid + "' AND mid IN('license', '" + mid + "')"); for (Map<String, Object> value_ : query) { usermagics.put((String) value_.get("mid"), value_); } Map<String, Object> tempMap = usermagics.get("license"); if (tempMap == null || (Integer) tempMap.get("count") == 0) { return showMessage(request, response, "has_no_more_present_magic"); } tempMap = usermagics.get(mid); if (tempMap == null || (Integer) tempMap.get("count") == 0) { return showMessage(request, response, "has_no_more_magic", null, 0, (String) magic.get("name"), "a_buy_" + mid, "cp.jsp?ac=magic&op=buy&mid=" + mid); } dataBaseService.execute( "UPDATE " + JavaCenterHome.getTableName("usermagic") + " SET count = count - 1 WHERE uid = '" + supe_uid + "' AND mid IN ('license', '" + mid + "')"); query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("usermagic") + " WHERE uid='" + fuid + "' AND mid='" + mid + "'"); value = query.size() > 0 ? query.get(0) : null; int count = value != null ? (Integer) value.get("count") + 1 : 1; Map<String, Object> insertData = new HashMap<String, Object>(); insertData.put("uid", fuid); insertData.put("username", fusername); insertData.put("mid", mid); insertData.put("count", count); dataBaseService.insertTable("usermagic", insertData, false, true); insertData.clear(); insertData.put("uid", fuid); insertData.put("username", fusername); insertData.put("mid", mid); insertData.put("count", 1); insertData.put("type", 2); insertData.put("fromid", supe_uid); insertData.put("credit", 0); insertData.put("dateline", timestamp); dataBaseService.insertTable("magicinlog", insertData, false, false); String note = Common.getMessage(request, "cp_magic_present_note", (String) magic.get("name"), "cp.jsp?ac=magic&view=me&mid=" + mid); note = note == null ? "magic_present_note" : note; cpService.addNotification(request, sGlobal, sConfig, fuid, "magic", note, false); return showMessage(request, response, "magicpresent_success", request.getParameter("refer"), 0, fusername); } if ("buy".equals(op)) { Object result = magicService.magic_buy_get(request, response, magic, sGlobal, space); if (result instanceof MessageVO) { return showMessage(request, response, (MessageVO) result); } Map<String, Object> datas = (Map<String, Object>) result; Map<String, Object> magicstore = (Map<String, Object>) datas.get("magicstore"); Map<String, Object> coupon = (Map<String, Object>) datas.get("coupon"); request.setAttribute("mid", mid); request.setAttribute("magicstore", magicstore); request.setAttribute("coupon", coupon); request.setAttribute("discount", datas.get("discount")); request.setAttribute("charge", datas.get("charge")); String ac = request.getParameter("ac"); request.setAttribute("ac", ac != null ? ac.trim() : ""); request.setAttribute("magic", magic); } else if ("present".equals(op)) { if (mid.equals("license")) { return showMessage(request, response, "magic_can_not_be_presented"); } Map<String, Map<String, Object>> usermagics = new HashMap<String, Map<String, Object>>(); List<Map<String, Object>> query = dataBaseService .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("usermagic") + " WHERE uid='" + supe_uid + "' AND mid IN('license', '" + mid + "')"); for (Map<String, Object> value : query) { usermagics.put((String) value.get("mid"), value); } Map<String, Object> tempMap = usermagics.get("license"); if (tempMap == null || (Integer) tempMap.get("count") == 0) { return showMessage(request, response, "has_no_more_present_magic"); } tempMap = usermagics.get(mid); if (tempMap == null || (Integer) tempMap.get("count") == 0) { return showMessage(request, response, "has_no_more_magic", null, 0, (String) magic.get("name"), "a_buy_" + mid, "cp.jsp?ac=magic&op=buy&mid=" + mid); } request.setAttribute("mid", mid); request.setAttribute("magic", magic); } else if ("showusage".equals(op)) { if (mid.equals("")) { return showMessage(request, response, "unknown_magic"); } request.setAttribute("mid", mid); } else if ("receive".equals(op)) { String uidS = request.getParameter("uid"); int uid = uidS != null ? Common.intval(uidS.trim()) : 0; List<Map<String, Object>> query = dataBaseService .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("magicuselog") + " WHERE uid='" + uid + "' AND mid='gift' LIMIT 1"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; String value_data; if (value != null && (value_data = (String) value.get("data")) != null && !value_data.equals("")) { Map<String, Object> data = Serializer.unserialize(value_data, false); if ((Integer) data.get("left") <= 0) { return showMessage(request, response, "magic_gift_already_given_out"); } Map<Integer, Integer> receiver = (Map<Integer, Integer>) data.get("receiver"); if (receiver == null) { receiver = new HashMap<Integer, Integer>(); data.put("receiver", receiver); } int receiverIndex = 0; for (Entry<Integer, Integer> entry : receiver.entrySet()) { if (entry.getValue() == supe_uid) { return showMessage(request, response, "magic_had_got_gift"); } receiverIndex = Math.max(receiverIndex, entry.getKey()); } int data_left = (Integer) data.get("left"); int data_chunk = (Integer) data.get("chunk"); int credit = Math.min(data_chunk, data_left); receiver.put(++receiverIndex, supe_uid); data_left = data_left - credit; data.put("left", data_left); if (data_left > 0) { Map<String, Object> setData = new HashMap<String, Object>(); setData.put("data", Serializer.serialize(data)); Map<String, Object> whereData = new HashMap<String, Object>(); whereData.put("logid", value.get("logid")); dataBaseService.updateTable("magicuselog", setData, whereData); } else { dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("magicuselog") + " WHERE logid = '" + value.get("logid") + "'"); } dataBaseService.execute("UPDATE " + JavaCenterHome.getTableName("space") + " SET credit = credit + '" + credit + "' WHERE uid='" + supe_uid + "'"); return showMessage(request, response, "magic_got_gift", null, 0, credit + ""); } else { return showMessage(request, response, "magic_has_no_gift"); } } else if ("appear".equals(op)) { Map<String, Object> session_member = (Map<String, Object>) sGlobal.get("session"); if (session_member == null || (Integer) session_member.get("magichidden") == 0) { return showMessage(request, response, "magic_not_hidden_yet"); } boolean scb = false; try { scb = submitCheck(request, "appearsubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { Map<String, Object> setData = new HashMap<String, Object>(); Map<String, Object> whereData = new HashMap<String, Object>(); setData.put("magichidden", "0"); whereData.put("uid", supe_uid); dataBaseService.updateTable("session", setData, whereData); setData.clear(); setData.put("expire", timestamp); whereData.put("mid", "invisible"); dataBaseService.updateTable("magicuselog", setData, whereData); return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } } else if ("retrieve".equals(op)) { List<Map<String, Object>> query = dataBaseService .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("magicuselog") + " WHERE uid = '" + supe_uid + "' AND mid = 'gift'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; int leftcredit = 0; String dataS = null; if (value == null) { return showMessage(request, response, "not_set_gift"); } else if ((dataS = (String) value.get("data")) != null && !dataS.equals("")) { Map<String, Object> data = Serializer.unserialize(dataS, false); leftcredit = (Integer) data.get("left"); } boolean scb = false; try { scb = submitCheck(request, "retrievesubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { dataBaseService.execute("DELETE FROM " + JavaCenterHome.getTableName("magicuselog") + " WHERE uid = '" + supe_uid + "' AND mid = 'gift'"); dataBaseService.execute("UPDATE " + JavaCenterHome.getTableName("space") + " SET credit = credit + " + leftcredit + " WHERE uid = '" + supe_uid + "'"); return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } request.setAttribute("leftcredit", leftcredit); } else if ("cancelsuperstar".equals(op)) { mid = "superstar"; List<Map<String, Object>> query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("spacefield") + " WHERE uid = '" + supe_uid + "'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; Integer magicstar; if (value == null || (magicstar = (Integer) value.get("magicstar")) == null || magicstar == 0) { return showMessage(request, response, "not_superstar_yet"); } boolean scb = false; try { scb = submitCheck(request, "cancelsubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { Map<String, Object> setData = new HashMap<String, Object>(); Map<String, Object> whereData = new HashMap<String, Object>(); setData.put("magicstar", 0); whereData.put("uid", supe_uid); dataBaseService.updateTable("spacefield", setData, whereData); setData.clear(); setData.put("expire", timestamp); whereData.put("mid", "superstar"); dataBaseService.updateTable("magicuselog", setData, whereData); return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } } else if ("cancelflicker".equals(op)) { mid = "flicker"; String idtype = "cid"; String idS = request.getParameter("id"); int id = idS != null ? Common.intval(idS.trim()) : 0; List<Map<String, Object>> query = dataBaseService .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("comment") + " WHERE cid = '" + id + "' AND authorid = '" + supe_uid + "'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; Integer magicflicker; if (value == null || (magicflicker = (Integer) value.get("magicflicker")) == null || magicflicker == 0) { return showMessage(request, response, "no_flicker_yet"); } boolean scb = false; try { scb = submitCheck(request, "cancelsubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { Map<String, Object> setData = new HashMap<String, Object>(); setData.put("magicflicker", 0); Map<String, Object> whereData = new HashMap<String, Object>(); whereData.put("cid", id); whereData.put("authorid", supe_uid); dataBaseService.updateTable("comment", setData, whereData); return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } request.setAttribute("id", id); request.setAttribute("idtype", idtype); request.setAttribute("mid", mid); } else if ("cancelcolor".equals(op)) { mid = "color"; String idS = request.getParameter("id"); int id = idS != null ? Common.intval(idS.trim()) : 0; String idtype = request.getParameter("idtype"); if (idtype == null) { return showMessage(request, response, "access error : 00001"); } idtype = idtype.trim(); Map<String, String> mapping = new HashMap<String, String>(); mapping.put("blogid", "blogfield"); mapping.put("tid", "thread"); String tablename = mapping.get(idtype); if (Common.empty(tablename)) { return showMessage(request, response, "no_color_yet"); } List<Map<String, Object>> query = dataBaseService .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName(tablename) + " WHERE " + idtype + " = '" + id + "' AND uid = '" + supe_uid + "'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; Integer magiccolor; if (value == null || (magiccolor = (Integer) value.get("magiccolor")) == null || magiccolor == 0) { return showMessage(request, response, "no_color_yet"); } boolean scb = false; try { scb = submitCheck(request, "cancelsubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { Map<String, Object> setData = new HashMap<String, Object>(); setData.put("magiccolor", 0); Map<String, Object> whereData = new HashMap<String, Object>(); whereData.put(idtype, id); dataBaseService.updateTable(tablename, setData, whereData); query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("feed") + " WHERE id = '" + id + "' AND idtype = '" + idtype + "'"); Map<String, Object> feed = query.size() > 0 ? query.get(0) : null; if (feed != null) { String body_data = (String) feed.get("body_data"); Map body_data_subMap = Serializer.unserialize(body_data, false); body_data_subMap.remove("magic_color"); body_data = Serializer.serialize(body_data_subMap); setData.clear(); whereData.clear(); setData.put("body_data", body_data); whereData.put("feedid", feed.get("feedid")); dataBaseService.updateTable("feed", setData, whereData); } return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } request.setAttribute("id", id); request.setAttribute("idtype", idtype); request.setAttribute("mid", mid); } else if ("cancelframe".equals(op)) { mid = "frame"; String idtype = "picid"; String idS = request.getParameter("id"); int id = idS != null ? Common.intval(idS.trim()) : 0; List<Map<String, Object>> query = dataBaseService .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("pic") + " WHERE picid = '" + id + "' AND uid = '" + supe_uid + "'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; Integer magicframe; if (value == null || (magicframe = (Integer) value.get("magicframe")) == null || magicframe == 0) { return showMessage(request, response, "no_frame_yet"); } boolean scb = false; try { scb = submitCheck(request, "cancelsubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { Map<String, Object> setData = new HashMap<String, Object>(); setData.put("magicframe", 0); Map<String, Object> whereData = new HashMap<String, Object>(); whereData.put("picid", id); dataBaseService.updateTable("pic", setData, whereData); return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } request.setAttribute("id", id); request.setAttribute("idtype", idtype); request.setAttribute("mid", mid); } else if ("cancelbgimage".equals(op)) { mid = "bgimage"; String idtype = "blogid"; String idS = request.getParameter("id"); int id = idS != null ? Common.intval(idS.trim()) : 0; List<Map<String, Object>> query = dataBaseService .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("blogfield") + " WHERE blogid = '" + id + "' AND uid = '" + supe_uid + "'"); Map<String, Object> value = query.size() > 0 ? query.get(0) : null; Integer magicpaper; if (value == null || (magicpaper = (Integer) value.get("magicpaper")) == null || magicpaper == 0) { return showMessage(request, response, "no_bgimage_yet"); } boolean scb = false; try { scb = submitCheck(request, "cancelsubmit"); } catch (Exception e) { e.printStackTrace(); return showMessage(request, response, e.getMessage()); } if (scb) { Map<String, Object> setData = new HashMap<String, Object>(); setData.put("magicpaper", 0); Map<String, Object> whereData = new HashMap<String, Object>(); whereData.put("blogid", id); dataBaseService.updateTable("blogfield", setData, whereData); return showMessage(request, response, "do_success", request.getParameter("refer"), 0); } request.setAttribute("id", id); request.setAttribute("idtype", idtype); request.setAttribute("mid", mid); } else { String view = request.getParameter("view"); if (view != null) { view = view.trim(); } if ("me".equals(view)) { Map<String, String> types = new HashMap<String, String>(); types.put("list", " class=\"active\""); request.setAttribute("types", types); Map<String, Map<String, Object>> list = null; StringBuilder ids = new StringBuilder(); Map<String, Map<String, Object>> magics = new HashMap<String, Map<String, Object>>(); List<Map<String, Object>> query = null; if (!mid.equals("")) { magics.put(mid, magic); ids.append("'"); ids.append(mid); ids.append("'"); } else { query = dataBaseService.executeQuery( "SELECT * FROM " + JavaCenterHome.getTableName("magic") + " WHERE close = '0'"); String tempS; Pattern pattern = Pattern.compile(","); boolean existMid = false; for (Map<String, Object> value : query) { tempS = (String) value.get("forbiddengid"); if (tempS != null) { value.put("forbiddengid", pattern.split(tempS)); } else { value.put("forbiddengid", new String[0]); } tempS = (String) value.get("mid"); magics.put(tempS, value); if (existMid) { ids.append(","); } else { existMid = true; } ids.append("'"); ids.append(tempS); ids.append("'"); } } query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("usermagic") + " WHERE uid='" + supe_uid + "' AND mid IN (" + ids.toString() + ") AND count > 0"); if (query.size() > 0) { list = new LinkedHashMap<String, Map<String, Object>>(); for (Map<String, Object> value : query) { list.put((String) value.get("mid"), value); } } request.setAttribute("list", list); request.setAttribute("magics", magics); request.setAttribute("mid", mid); } else if ("log".equals(view)) { String type = request.getParameter("type"); type = type != null && ((type = type.trim()).equals("in") || type.equals("out") || type.equals("present")) ? type : "in"; request.setAttribute("gType", type); Map<String, String> types = new HashMap<String, String>(); types.put(type, " class=\"active\""); request.setAttribute("types", types); int perpage = 20; String pageGet = request.getParameter("page"); int page = Common.empty(pageGet) ? 0 : Common.intval(pageGet); if (page < 1) page = 1; int start = (page - 1) * perpage; int maxPage = (Integer) sConfig.get("maxpage"); String result = Common.ckStart(start, perpage, maxPage); if (result != null) { return showMessage(request, response, result); } List<Map<String, Object>> list = null; List<Map<String, Object>> query = null; int count = 0; if ("in".equals(type)) { List<Integer> uids = null; query = dataBaseService.executeQuery("SELECT COUNT(*) AS cont FROM " + JavaCenterHome.getTableName("magicinlog") + " WHERE uid = '" + supe_uid + "'"); count = query.size() > 0 ? (Integer) query.get(0).get("cont") : 0; if (count != 0) { query = dataBaseService.executeQuery( "SELECT * FROM " + JavaCenterHome.getTableName("magicinlog") + " WHERE uid = '" + supe_uid + "' ORDER BY dateline DESC LIMIT " + start + ", " + perpage); list = query.size() > 0 ? query : null; uids = new ArrayList<Integer>(); for (Map<String, Object> value : query) { value.put("dateline", Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("dateline"), true)); if ((Integer) value.get("type") == 2) { uids.add((Integer) value.get("fromid")); } } } if (uids != null && uids.size() > 0) { query = dataBaseService .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("member") + " WHERE uid IN (" + Common.sImplode(uids) + ")"); for (Map<String, Object> value : query) { Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"), (String) value.get("username"), "", 0); } Common.realname_get(sGlobal, sConfig, sNames, space); } } else if ("present".equals(type)) { query = dataBaseService.executeQuery( "SELECT COUNT(*) AS cont FROM " + JavaCenterHome.getTableName("magicinlog") + " WHERE type = 2 AND fromid = '" + supe_uid + "'"); count = query.size() > 0 ? (Integer) query.get(0).get("cont") : 0; if (count != 0) { query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("magicinlog") + " WHERE type = 2 AND fromid = '" + supe_uid + "' ORDER BY dateline DESC LIMIT " + start + ", " + perpage); list = query.size() > 0 ? query : null; for (Map<String, Object> value : query) { value.put("dateline", Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("dateline"), true)); Common.realname_set(sGlobal, sConfig, sNames, (Integer) value.get("uid"), (String) value.get("username"), "", 0); } } Common.realname_get(sGlobal, sConfig, sNames, space); } else { query = dataBaseService.executeQuery("SELECT COUNT(*) AS cont FROM " + JavaCenterHome.getTableName("magicuselog") + " WHERE uid = '" + supe_uid + "'"); count = query.size() > 0 ? (Integer) query.get(0).get("cont") : 0; if (count != 0) { query = dataBaseService.executeQuery( "SELECT * FROM " + JavaCenterHome.getTableName("magicuselog") + " WHERE uid = '" + supe_uid + "' ORDER BY dateline DESC LIMIT " + start + ", " + perpage); list = query.size() > 0 ? query : null; for (Map<String, Object> value : query) { value.put("dateline", Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("dateline"), true)); value.put("data", Serializer.unserialize((String) value.get("data"), false)); value.put("expire", Common.sgmdate(request, "MM-dd HH:mm", (Integer) value.get("expire"), false)); } } } String theurl = "cp.jsp?ac=magic&view=log&type=" + type; String multi = Common.multi(request, count, perpage, page, maxPage, theurl, "", ""); request.setAttribute("multi", multi); request.setAttribute("list", list); } else { view = "store"; String order = request.getParameter("order"); if (order != null) { order = order.trim(); } order = "hot".equals(order) ? order : "default"; Map<String, String> orders = new HashMap<String, String>(); orders.put(order, " class=\"active\""); request.setAttribute("orders", orders); List<Map<String, Object>> query; Map<String, Map<String, Object>> magics = new HashMap<String, Map<String, Object>>(); List<String> ids = null; Map<String, Map<String, Object>> list = new LinkedHashMap<String, Map<String, Object>>(); String[] blacklist = { "coupon" }; if (!mid.equals("")) { magics.put(mid, magic); ids = new ArrayList<String>(1); ids.add(mid); } else { String orderby = order.equals("hot") ? "" : " ORDER BY displayorder"; query = dataBaseService .executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("magic") + orderby); String tempS; Pattern pattern = Pattern.compile(","); ids = new ArrayList<String>(query.size()); for (Map<String, Object> value : query) { if ((Integer) value.get("close") == 1 || Common.in_array(blacklist, value.get("mid"))) { continue; } tempS = (String) value.get("forbiddengid"); if (tempS != null) { value.put("forbiddengid", pattern.split(tempS)); } else { value.put("forbiddengid", new String[0]); } tempS = (String) value.get("mid"); magics.put(tempS, value); ids.add(tempS); } } if (Common.empty(magics)) { return showMessage(request, response, "magic_store_is_closed"); } String orderby = order.equals("hot") ? " ORDER BY sellcount DESC" : ""; query = dataBaseService.executeQuery("SELECT * FROM " + JavaCenterHome.getTableName("magicstore") + " WHERE mid IN (" + Common.sImplode(ids) + ")" + orderby); String[] oldids = new String[query.size()]; int ti = 0; int providecount; String ts; for (Map<String, Object> value : query) { ts = (String) value.get("mid"); list.put(ts, value); oldids[ti++] = ts; providecount = (Integer) magics.get(ts).get("providecount"); if ((Integer) value.get("storage") < providecount && (Integer) value.get("lastprovide") + (Integer) magics.get(ts).get("provideperoid") < timestamp) { dataBaseService.execute("UPDATE " + JavaCenterHome.getTableName("magicstore") + " SET storage = '" + providecount + "', lastprovide = '" + timestamp + "' WHERE mid = '" + ts + "'"); list.get(ts).put("storage", providecount); } } List<String> newids = new ArrayList<String>(); for (String id : ids) { if (!Common.in_array(oldids, id)) { newids.add(id); } } int newidsSize = newids.size(); if (newidsSize > 0) { String[] inserts = new String[newidsSize]; ti = 0; StringBuilder builder = new StringBuilder(); Map<String, Object> listValue; for (String id : newids) { builder.delete(0, builder.length()); builder.append("('"); builder.append(id); builder.append("', '"); builder.append(magics.get(id).get("providecount")); builder.append("', '"); builder.append(timestamp); builder.append("')"); inserts[ti++] = builder.toString(); listValue = new HashMap<String, Object>(); listValue.put("mid", id); listValue.put("storage", magics.get(id).get("providecount")); listValue.put("lastprovide", timestamp); list.put(id, listValue); } dataBaseService.execute("INSERT INTO " + JavaCenterHome.getTableName("magicstore") + "(mid, storage, lastprovide) VALUES " + Common.implode(inserts, ",")); } if (order.equals("default")) { Map<String, Map<String, Object>> tempMap = new LinkedHashMap<String, Map<String, Object>>(); for (String id : ids) { tempMap.put(id, list.get(id)); } list = tempMap; } request.setAttribute("space", space); request.setAttribute("blacklist", blacklist); request.setAttribute("magics", magics); request.setAttribute("mid", mid); request.setAttribute("list", list); } Map<String, String> actives = new HashMap<String, String>(); actives.put(view, " class=\"active\""); request.setAttribute("actives", actives); } request.setAttribute("op", op); return include(request, response, sConfig, sGlobal, "cp_magic.jsp"); }