- 更新日時:
- 2007/02/17 15:28:26 (5 年 前)
- ファイル:
-
- 1 変更
凡例:
- 変更なし
- 追加
- 削除
-
tPod/trunk/src/jp/tyzoh/rinza/folksonomy/tpod/tPod.java
r7 r8 11 11 import org.apache.commons.*; 12 12 import java.security.cert.X509Certificate; 13 //import jp.tyzoh.rinza.folksonomy.keyword.*;13 import jp.tyzoh.rinza.folksonomy.keyword.*; 14 14 15 15 /** … … 29 29 /** �C�����C���\���ɂ��邩�ۂ� */ 30 30 boolean isInline = true; 31 /** �C���[�W�̃T���l�[���̕\���T�C�Y�B�ǂ��炩�� 0 �̂Ƃ��͕\���Ȃ� */ 32 int thumbWidth = 0; 33 int thumbHeight = 0; 34 /** �R�����g�̃T�}���̕\�����i�����j���B0 �̂Ƃ��̓T�}���\���Ȃ� */ 35 int commentSummarySize = 0; 36 /** �L�[���[�h�̃T�}���̕\�����i�����j���B0 �̂Ƃ��̓T�}���\���Ȃ� */ 37 int keywordSummarySize = 0; 38 /** �����L�[���[�h���o��̐��B0 �̂Ƃ��͎������o���Ȃ� */ 39 int autoKeywordSize = 0; 31 40 32 41 /** �T�[�u���b�g��URL�iIE �o�O��/ … … 38 47 39 48 Engine engine = new Engine(); 40 //jp.tyzoh.rinza.folksonomy.keyword.Engine autoKeyword = new jp.tyzoh.rinza.folksonomy.keyword.Engine();49 jp.tyzoh.rinza.folksonomy.keyword.Engine autoKeyword = new jp.tyzoh.rinza.folksonomy.keyword.Engine(); 41 50 42 51 public void init() … … 53 62 servletURL = properties.getProperty("servletURL", servletURL); 54 63 isInline = properties.getProperty("inline", "true").equals("true"); 64 thumbWidth = parseInt(properties.getProperty("thumbWidth", "0")); 65 thumbHeight = parseInt(properties.getProperty("thumbHeight", "0")); 66 keywordSummarySize = parseInt(properties.getProperty("keywordSummarySize", "0")); 67 commentSummarySize = parseInt(properties.getProperty("commentSummarySize", "0")); 68 autoKeywordSize = parseInt(properties.getProperty("autoKeywordSize", "0")); 55 69 56 70 if (!engine.init(properties, out)) { … … 58 72 } 59 73 60 /*61 74 if (!autoKeyword.init(properties, out)) { 62 75 out.println("autoKeyword engine is not initialized"); 63 76 } 64 */65 77 66 78 contentTypeMap.put("", "text/plain"); … … 77 89 iconMap.put("xls", "xls.gif"); 78 90 iconMap.put("pdf", "pdf.gif"); 91 } 92 93 int parseInt(String value) 94 { 95 try { 96 return Integer.parseInt(value); 97 } catch(Exception ex) { 98 return 0; 99 } 79 100 } 80 101 … … 115 136 } else if (command.equals("regist")) { 116 137 regist(req, res, requestMap); 138 } else if (command.equals("registURL")) { 139 registURL(req, res, requestMap); 117 140 } else if (command.equals("download")) { 118 141 download(req, res, requestMap); … … 163 186 } else if (command.equals("regist")) { 164 187 regist(req, res); 188 } else if (command.equals("registURL")) { 189 registURL(req, res); 165 190 } else if (command.equals("registUser")) { 166 191 req.setCharacterEncoding(encodeType); … … 365 390 out.println(" <a href=\"../../tPod/servlet/tPod?command=regist&"+ 366 391 "uid="+uid+ 367 "\">�t�@�C���o�^</a><br>"); 392 "\">�t�@�C���o�^</a>"); 393 out.println(" <a href=\"../../tPod/servlet/tPod?command=registURL&"+ 394 "uid="+uid+ 395 "\">URL�o�^</a>"); 396 368 397 369 398 if (!isEasy) { … … 458 487 } 459 488 460 private int showAllKeywords(PrintWriter out, boolean isSelect) 461 { 462 return showAllKeywords(out, null, isSelect); 463 } 464 465 private int showAllKeywords(PrintWriter out, String filename, boolean isSelect) 466 { 489 String getCommentSummary(String filename, int length) 490 { 491 Comment[] commentArray = engine.getAllComments(filename); 492 engine.sortCommentTime(commentArray); 493 494 String summary = ""; 495 for(int i = 0; i < commentArray.length; i++) { 496 summary += "[" + commentArray[i].getComment() + "]"; 497 } 498 499 if (summary.length() >= length) { 500 summary = summary.substring(0, length-3); 501 summary += "..."; 502 } 503 504 return summary; 505 } 506 507 private int showAllKeywords(PrintWriter out, boolean isSelect) 508 { 509 return showAllKeywords(out, null, isSelect); 510 } 511 512 private int showAllKeywords(PrintWriter out, String filename, boolean isSelect) 513 { 467 514 return showAllKeywords(out, null, isSelect, false); 468 515 } 469 516 470 private int showAllKeywords(PrintWriter out, String filename, boolean isSelect, boolean isAuto)517 private int showAllKeywords(PrintWriter out, String filename, boolean isSelect, boolean useAuto) 471 518 { 472 519 boolean isAll = filename == null; … … 492 539 out.println("<br>"); 493 540 494 /* 495 if (isAuto) { 541 if (useAuto && autoKeywordSize > 0) { 496 542 out.println("<br>�������o���ꂽ�L�[���[�h��F<br>"); 497 543 Collection collection = autoKeyword.getKeywords(engine.getRealFile(filename).getAbsolutePath()); 498 int limit = 10;544 int limit = autoKeywordSize; 499 545 Iterator iterator = collection.iterator(); 500 546 while(iterator.hasNext()) { … … 507 553 out.println("<br>"); 508 554 } 509 */510 555 511 556 return spanNum; 557 } 558 559 String getKeywordSummary(String filename, int length) 560 { 561 Keyword[] keywordArray = engine.getAllKeywords(filename); 562 engine.sortKeywordTime(keywordArray); 563 564 String summary = ""; 565 for(int i = 0; i < keywordArray.length; i++) { 566 summary += "<" + keywordArray[i].value + ">"; 567 } 568 569 if (summary.length() >= length) { 570 summary = summary.substring(0, length-3); 571 summary += "..."; 572 } 573 574 return summary; 512 575 } 513 576 … … 671 734 } 672 735 String iconName = getIcon(filename); 673 out.print("<td><img src=\"/tPod/icon/"+iconName+"\" border=0></td>"); 674 out.println("<td><a href=\"tPod?command=download&file="+filename+"&orig="+origname+"\">"+origname+"</a></td>"); 736 out.println("<td><img src=\"/tPod/icon/"+iconName+"\" border=0></td>"); 737 if (engine.isURL(filename)) { 738 String name = engine.getURL(filename); 739 out.println("<td><a href=\""+name+"\">"+origname+"</a></td>"); 740 } else { 741 out.println("<td><a href=\"tPod?command=download&file="+filename+"&orig="+origname+"\">"+origname+"</a></td>"); 742 } 743 out.print("<td>"); 744 if (thumbWidth > 0 && thumbHeight > 0 && isFigure(filename)) { 745 out.print("<a href=\"tPod?command=download&file="+filename+"&orig="+origname+"\"><img src=\"tPod?command=download&file="+filename+"&orig="+origname+"\" width=\"" + thumbWidth + "\" height=\"" + thumbHeight + "\"></a>"); 746 } else { 747 out.print(" "); 748 } 749 out.print("</td>"); 750 675 751 out.println("<td>"+timeString+"</td>"); 676 752 677 753 out.println("</tr>"); 754 755 if (commentSummarySize > 0) { 756 String commentSummary = getCommentSummary(filename, commentSummarySize); 757 if (commentSummary.length() > 0) { 758 out.println("<tr><td> </td><td> </td><td> </td><td> </td><td> </td><td>" + getCommentSummary(filename, commentSummarySize) + "</td></tr>"); 759 } 760 } 761 762 if (keywordSummarySize > 0) { 763 out.println("<tr><td> </td><td> </td><td> </td><td> </td><td> </td><td>" + getKeywordSummary(filename, keywordSummarySize) + "</td></tr>"); 764 } 765 678 766 } 679 767 … … 686 774 } 687 775 776 private boolean isFigure(String filename) 777 { 778 String name = filename.toLowerCase(); 779 return 780 name.endsWith(".jpg") || name.endsWith(".jpeg") || 781 name.endsWith(".gif") || name.endsWith(".png"); 782 } 783 688 784 private String getIcon(String filename) 689 785 { 690 String iconName = (String)iconMap.get(getExt(filename.toLowerCase())); 691 return iconName == null ? "file.gif" : iconName; 786 if (engine.isURL(filename)) { 787 return "url.gif"; 788 } else { 789 String iconName = (String)iconMap.get(getExt(filename.toLowerCase())); 790 return iconName == null ? "file.gif" : iconName; 791 } 692 792 } 693 793 … … 945 1045 } 946 1046 947 private void addKeywordBody(String uid, String[] origname, String []filename, boolean isAuto, PrintWriter out)1047 private void addKeywordBody(String uid, String[] origname, String []filename, boolean useAuto, PrintWriter out) 948 1048 { 949 1049 int num = origname.length; … … 968 1068 for(int i = 0; i < num; i++) { 969 1069 out.println("<br><br>"+origname[i]+"�̃L�[���[�h�F<br>"); 970 showAllKeywords(out, filename[i], true, isAuto);1070 showAllKeywords(out, filename[i], true, useAuto); 971 1071 out.println("<br>"); 972 1072 } … … 1004 1104 out.println("</table>"); 1005 1105 out.println("<input type=submit name=ac value=\"�A�N�Z�X���ύX\"><br>"); 1006 1106 1107 if (num == 1) { 1108 String title = "�t�@�C����"; 1109 if (engine.isURL(filename[0])) { 1110 title = "�^�C�g��"; 1111 } 1112 out.println("<br>" + title + "�ύX<br>"); 1113 out.println("<input type=text name=title value=\"" + origname[0] + "\">"); 1114 out.println("<input type=submit name=ct value=\"" + title + "�ύX\"><br>"); 1115 } 1116 1007 1117 out.println("<br><input type=submit name=remove value=\"�t�@�C���폜\"> "); 1008 1118 … … 1028 1138 boolean isRemove = req.getParameter("remove") != null; 1029 1139 boolean isAC = req.getParameter("ac") != null; 1140 boolean isCT = req.getParameter("ct") != null; 1030 1141 1031 1142 res.setContentType("text/html; charset="+encodeType); … … 1068 1179 out.println("<tr><td>���̑��@������/td><td>"+(temp.getOtherWrite()?"����:"�s����)+"<td></tr>"); 1069 1180 out.println("<table>"); 1181 } else if (isCT) { 1182 String title = new String(req.getParameter("title").getBytes("iso-8859-1"), encodeType); 1183 engine.changeTitle(filename[i], title); 1184 origname[i] = title; 1070 1185 } 1071 1186 … … 1287 1402 1288 1403 /** 1404 * URL�o�^�� 1405 */ 1406 void /* Get */ registURL(HttpServletRequest req, HttpServletResponse res, Map requestMap) throws ServletException, IOException 1407 { 1408 String uid = (String)requestMap.get("uid"); 1409 1410 res.setContentType("text/html; charset="+encodeType); 1411 PrintWriter out = res.getWriter(); 1412 out.println("<html>"); 1413 out.println("<body>"); 1414 1415 out.println("<form method=\"POST\" action=\""+servletURL+"tPod/servlet/tPod\" target=\"lower\">"); 1416 out.println("�o�^ URL<br>"); 1417 out.println("<input type=text name=\"url\" value=\"\" size=\"60\"><br>"); 1418 out.println("�o�^ URL �̃^�C�g��<br>"); 1419 out.println("<input type=text name=\"title\" value=\"\" size=\"60\"><br>"); 1420 out.println("<input type=hidden name=\"command\" value=\"registURL\">"); 1421 out.println("<input type=hidden name=\"uid\" value=\""+uid+"\">"); 1422 out.print("�L�[���[�h<br>"); 1423 out.print("<input type=text name=\"keyword\" size=\"60\"><br>"); 1424 out.println("<input type=submit value=\"�o�^\"> "); 1425 out.println("</form>"); 1426 out.println("<a href=\"../../tPod/servlet/tPod?"+ 1427 "command=inspect&"+ 1428 "uid="+uid+ 1429 "\">tPod����> "); 1430 out.println("</body>"); 1431 out.println("</html>"); 1432 1433 } 1434 1435 /** 1436 * URL�o�^ 1437 */ 1438 void /* Post */ registURL(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException 1439 { 1440 String uid = req.getParameter("uid"); 1441 String url = req.getParameter("url"); 1442 String title = new String(req.getParameter("title").getBytes("iso-8859-1"), encodeType); 1443 String keyword = new String(req.getParameter("keyword").getBytes("iso-8859-1"), encodeType); 1444 1445 String time = ""; 1446 1447 res.setContentType("text/html; charset="+encodeType); 1448 PrintWriter out = res.getWriter(); 1449 out.println("<html>"); 1450 out.println("<body>"); 1451 1452 String registeredURL = engine.registerURL(url, title, uid, time, keyword, out); 1453 if (registeredURL != null) { 1454 out.println("�u" + url + "�v��^���܂����B<br>"); 1455 addKeywordBody(uid, new String[]{url}, new String[]{registeredURL}, out); 1456 } else { 1457 out.println("�u" + url + "�v�̓o�^�͎��s���܂����B<br>"); 1458 } 1459 out.println("</body>"); 1460 out.println("</html>"); 1461 } 1462 1463 /** 1289 1464 * �t�@�C���o�^�� 1290 1465 */ … … 1323 1498 String uid = ""; 1324 1499 String userName = ""; 1325 String group = "";1326 1500 String time = ""; 1327 1501 String keyword = "";
