Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java程序分享区 » 工具  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to topicflat modethreaded modego to previous topicgo to next topicgo to back
话题被移动
该话题已被移动 - tzutolin , 2005-12-13 14:12
如果您尚不清楚该话题被移动的原因,请参考论坛规则以及本版公告或者联系本版版主。
作者 color4j [精华]
Jove



CJSDN高级会员


发贴: 1228
于 2004-03-17 14:03 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Jute的code标签不太好看,用这个软件会稍微好一点

下载地址
其中包含源文件,允许任何形式的修改和传播

Quick Start:


自定义显示风格请用文本编辑器打开style.cfg

产生的代码如:

001 package jove.color4j;
002 
003 import java.awt.*;
004 import java.awt.datatransfer.*;
005 import java.awt.event.*;
006 
007 import javax.swing.*;
008 import javax.swing.event.*;
009 
010 import snoozesoft.systray4j.*;
011 
012 /**
013  * @author Jove
014  */
015 public class Color4jGUI extends JFrame implements SysTrayMenuListener {
016 
017     public static void main(String[] args) {
018         try {
019             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
020         } catch (Exception e) {}
021 
022         new Color4jGUI().show();
023     }
024 
025     private static void showMessage(String msg) {
026         JFrame dummy = new JFrame("Color4j");
027         dummy.setLocation(400, 300);
028         dummy.show();
029         JOptionPane.showMessageDialog(dummy, msg);
030         dummy.dispose();
031     }
032     private CheckableMenuItem checkMenuUbb, checkMenuAnsi;
033 ...

[readme]
color4j,曾用名java2ansi,java2ubb

作用: 把Java代码(其实也可以是其他语言的代码)转化为有字体信息的UBB或ANSI
其中UBB就是很多Web论坛使用的伪html代码,如【b】【color=red】 red 【/color】【/b】
而ANSI则是BBS等Term中的特殊控制字,如*[1;31m red *[m

算法来源: JR-Lib javaresearch.org的一个开源项目
Java语法素材来源: editplus第三方语法高亮包

下载地址:
解压后直接运行exe即可
其中包含源文件,允许任何形式的修改和传播

使用方法:
运行后出现窗口可以输入Java代码,按F9将输入框内的代码转换为对应的UBB或ANSI码
保存到系统剪贴板,按F8可以从剪贴板读入代码并作转换
同时提供系统托盘区的执行方式
自定义显示风格请用文本编辑器打开style.cfg

Change Log:
2004-3-17
  考虑到易用性,专为Windows设计。(不过*NIX上应该也能用,需要另外下载systray的so)
  把ANSI和UBB的式样从硬编码改为读取配置文件
  专为cjsdn改进UBB的样式,主要是去处黑色的【code】标签,使用Editplus的配色方案
  去处生成文件锁的功能,依赖exe4j来达到系统单实例
  去处转换完成后的提示框,在转换期间Title为<converting>
  
  
2004-3-12
最小化到系统托盘区
F9从文本框读入代码,F8从系统剪贴板读入
产生临时文件,防止运行多个实例
重构代码,增加StyleSet抽象类

2004-3-10
Initial Release

color4j-20040317-win.zip (196.24k)


Jove edited on 2004-03-17 15:13

作者 Re:color4j [Re:Jove]
Jove



CJSDN高级会员


发贴: 1228
于 2004-03-17 14:04 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list


1.png (20.72k)


Jove edited on 2004-03-17 14:28

作者 Re:color4j [Re:Jove]
dapan



CJSDN高级会员


发贴: 929
于 2004-03-17 14:59 user profilesend a private message to usersend email to dapanreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看起来很美!

不过代码加上行号,在复制时还要处理一下,稍有麻烦。
有相应的设置吗?

^_^



作者 Re:color4j [Re:dapan]
Jove



CJSDN高级会员


发贴: 1228
于 2004-03-17 15:08 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ubb.line.num.format=[ color=cccccc]000[/color]' '
在style.cfg中,把这行注释掉,就不会产生行号
自定义行号的显示样式也是这个地方设置


Jove edited on 2004-03-17 15:14

作者 Re:color4j [Re:Jove]
rainman

阿熊

元老


发贴: 5644
于 2004-03-17 15:14 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看样子Jute要直接支持这个语法加亮了 Thumbs up



作者 Re:color4j [Re:rainman]
Jove



CJSDN高级会员


发贴: 1228
于 2004-03-17 15:19 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不过或许会增加系统负担 Big Smile
如果要增加,建议作为[java][/java]标签,保留原来的code标签。因为有时我们会贴xml等别的代码

btw,rainman什么时候有空能修改一下jute上swf显示的那段代码吗
就是上次说的问题, 目前swf的宽度和长度是订死的550和400, 改成和<param>标签内的数字一样就可以了

上次用viewlet做了个demo,上传后发现显示尺寸不对..
//bow


Jove edited on 2004-03-17 15:32

作者 Re:color4j [Re:Jove]
rainman

阿熊

元老


发贴: 5644
于 2004-03-17 15:46 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
新版本改过了,cjsdn还未更新过。



作者 Re:color4j [Re:Jove]
freeman_z





发贴: 8
于 2004-03-25 04:30 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
001 package jove.color4j;
002 
003 import java.awt.*;
004 import java.awt.datatransfer.*;
005 import java.awt.event.*;
006 
007 import javax.swing.*;
008 import javax.swing.event.*;
009 
010 import snoozesoft.systray4j.*;
011 
012 /**
013  * @author Jove
014  */
015 public class Color4jGUI extends JFrame implements SysTrayMenuListener {
016 
017     public static void main(String[] args) {
018         /*
019         使用exe4j来保证单实例
020         File f = new File("file.lock");
021         if (f.exists()) {
022           showMessage("Warning: A instance has existed.");
023           System.exit(0);
024         }
025         try {
026           f.createNewFile();
027         } catch (IOException e) {
028           e.printStackTrace();
029           System.exit(1);
030         }
031         f.deleteOnExit();
032         */
033         try {
034             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
035         } catch (Exception e) {}
036 
037         new Color4jGUI().show();
038     }
039 
040     private static void showMessage(String msg) {
041         JFrame dummy = new JFrame("Color4j");
042         dummy.setLocation(400, 300);
043         dummy.show();
044         JOptionPane.showMessageDialog(dummy, msg);
045         dummy.dispose();
046     }
047     private CheckableMenuItem checkMenuUbb, checkMenuAnsi;
048     private Color4j color4j;
049     private SysTrayMenuIcon icon;
050     private Color[] labelColor = { Color.RED, Color.BLUE };
051 
052     private String[] labelText =
053         {
054             "  Press F9 to convert and save result to clipboard",
055             "  Press F8 to read data from clipboard and convert" };
056     private boolean labelTextFlag = true;
057     private SysTrayMenu menu;
058     private JRadioButton radioUbb, radioAnsi;
059 
060     private Color4jGUI() {
061         super("Java Code Formatter");
062         setBounds(100, 100, 500, 400);
063         addWindowListener(new WindowListener() {
064             public void windowActivated(WindowEvent e) {}
065             public void windowClosed(WindowEvent e) {}
066             public void windowClosing(WindowEvent e) {
067                 //hide();
068                 dispose();
069                 System.exit(0);
070             }
071             public void windowDeactivated(WindowEvent e) {}
072             public void windowDeiconified(WindowEvent e) {}
073             public void windowIconified(WindowEvent e) {
074                 hide();
075             }
076             public void windowOpened(WindowEvent e) {}
077         });
078 
079         Container con = getContentPane();
080         Box box = Box.createHorizontalBox();
081         final JLabel label = new JLabel(labelText[0]);
082         label.setForeground(labelColor[0]);
083         box.add(label);
084         Timer timer = new Timer(5000, new ActionListener() {
085             public void actionPerformed(ActionEvent e) {
086                 if (labelTextFlag) {
087                     label.setText(labelText[1]);
088                     label.setForeground(labelColor[1]);
089                 } else {
090                     label.setText(labelText[0]);
091                     label.setForeground(labelColor[0]);
092                 }
093                 labelTextFlag = !labelTextFlag;
094             }
095         });
096         timer.start();
097         box.add(Box.createHorizontalGlue());
098         radioUbb = new JRadioButton("UBB"true);
099         radioAnsi = new JRadioButton("ANSI");
100         ChangeListener cListener = new ChangeListener() {
101             public void stateChanged(ChangeEvent e) {
102                 boolean isUbb = radioUbb.isSelected();
103                 checkMenuUbb.setState(isUbb);
104                 checkMenuAnsi.setState(!isUbb);
105             }
106         };
107         radioUbb.addChangeListener(cListener);
108         radioAnsi.addChangeListener(cListener);
109         box.add(radioUbb);
110         box.add(radioAnsi);
111         box.add(Box.createHorizontalStrut(5));
112         ButtonGroup group = new ButtonGroup();
113         group.add(radioUbb);
114         group.add(radioAnsi);
115         con.add(box, BorderLayout.SOUTH);
116         final JTextArea textSource = new JTextArea();
117         JScrollPane sp = new JScrollPane(textSource);
118         JPanel p = new JPanel();
119         p.setLayout(new BorderLayout());
120         p.setBorder(BorderFactory.createTitledBorder("Source Code"));
121         p.add(sp);
122         con.add(p);
123         color4j = new Color4j();
124         KeyListener listener = new KeyAdapter() {
125             public void keyPressed(KeyEvent e) {
126                 if (e.getKeyCode() == KeyEvent.VK_F9) {
127                     convert(textSource.getText());
128                 } else if (e.getKeyCode() == KeyEvent.VK_F8) {
129                     convertFromCB();
130                 }
131             }
132         };
133         textSource.addKeyListener(listener);
134         radioAnsi.addKeyListener(listener);
135         radioUbb.addKeyListener(listener);
136 
137         icon = new SysTrayMenuIcon(getClass().getResource("icon.ico"));
138         icon.addSysTrayMenuListener(this);
139         createMenu();
140     }
141 
142     private void convert(String code) {
143       String oldTitle=getTitle();
144       setTitle(oldTitle+" <converting>");
145         if (radioUbb.isSelected()) {
146             color4j.setStyleSet(StyleSet.UBB);
147         } else {
148             color4j.setStyleSet(StyleSet.ANSI);
149         }
150         code = color4j.convert(code);
151         Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
152             new StringSelection(code),
153             null);
154         //不再显示Message  
155         //showMessage("data have been sent to system clipboard.");
156         setTitle(oldTitle);
157     }
158 
159     private void convertFromCB() {
160         Transferable clip =
161             Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
162         String code = null;
163         try {
164             code = (Stringclip.getTransferData(DataFlavor.stringFlavor);
165         } catch (Exception e) {
166             e.printStackTrace();
167         }
168         convert(code);
169     }
170 
171     private void createMenu() {
172         // create an exit item
173         SysTrayMenuItem itemExit = new SysTrayMenuItem("Exit""exit");
174         itemExit.addSysTrayMenuListener(this);
175 
176         // create an about item
177         SysTrayMenuItem itemAbout = new SysTrayMenuItem("About...""about");
178         itemAbout.addSysTrayMenuListener(this);
179 
180         SysTrayMenuItem itemConvert =
181             new SysTrayMenuItem("Convert code from clipboard""convert");
182         itemConvert.addSysTrayMenuListener(this);
183 
184         SubMenu subMenu = new SubMenu("Type");
185         checkMenuUbb = new CheckableMenuItem("UBB""ubb");
186         checkMenuUbb.addSysTrayMenuListener(this);
187         checkMenuUbb.setState(true);
188         checkMenuAnsi = new CheckableMenuItem("Ansi""ansi");
189         checkMenuAnsi.addSysTrayMenuListener(this);
190         subMenu.addItem(checkMenuAnsi);
191         subMenu.addItem(checkMenuUbb);
192 
193         menu = new SysTrayMenu(icon, "Color4j");
194         menu.addItem(itemExit);
195         menu.addSeparator();
196         menu.addItem(itemAbout);
197         menu.addSeparator();
198         menu.addItem(itemConvert);
199         menu.addItem(subMenu);
200     }
201 
202     public void iconLeftClicked(SysTrayMenuEvent e) {
203         if (isVisible()) {
204             hide();
205         } else {
206             show();
207             setState(Frame.NORMAL);
208             toFront();
209         }
210     }
211 
212     public void iconLeftDoubleClicked(SysTrayMenuEvent e) {}
213 
214     public void menuItemSelected(SysTrayMenuEvent e) {
215         if (e.getActionCommand().equals("exit"))
216             System.exit(0);
217         else if (e.getActionCommand().equals("about")) {
218             JOptionPane.showMessageDialog(
219                 this,
220                 "Color4j. \nWith SysTray for Java v" + SysTrayMenu.VERSION);
221         } else if (e.getActionCommand().equals("ubb")) {
222             checkMenuUbb.setState(true);
223             checkMenuAnsi.setState(false);
224             radioUbb.setSelected(true);
225         } else if (e.getActionCommand().equals("ansi")) {
226             checkMenuUbb.setState(false);
227             checkMenuAnsi.setState(true);
228             radioAnsi.setSelected(true);
229         } else if (e.getActionCommand().equals("convert")) {
230             convertFromCB();
231         } else
232             JOptionPane.showMessageDialog(this, e.getActionCommand());
233     }
234 }



作者 Re:color4j [Re:freeman_z]
nothing

天外飞仙.....

CJSDN高级会员


发贴: 1636
于 2004-03-25 05:31 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
COOL!



躲得过的怪物,躲不过的刺激

作者 Re:color4j [Re:Jove]
Starcraft

Think Liquid!



发贴: 376
于 2004-04-11 12:13 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
感谢jove兄,学习中Smile


Think BIG while I am still SMALL.
作者 Re:color4j [Re:Jove]
alexyu2000

我是多罗,我很可爱

Jute Pro User


发贴: 405
于 2004-04-13 09:06 user profilesend a private message to usersend email to alexyu2000reply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
首先我支持语法加亮显示,不过应该系统会有负担,不过这个功能能提升专业性,建议支持,不过我喜欢将JUTE代码显示改为这样,还有行数显示,挺方便的,听说rainman有这个意思,不知道进展的如何?


Click here to open a new window



[img]http://www.nhacks.com/email/email.php?mail_e=q8UtjGduMME%3D&iv=ICTOzCo%3D&domain=TVNO&ext=0[/img][img]http://bbs.dongman.org:8080/post-85-10950836311.gif[/img]
[img]http://bbs.8080.net/upload/17957/17957.jpg[/img]
作者 Re:color4j [Re:Jove]
文夕



发贴: 0
于 2004-04-22 19:58 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
001 public class HelloS
002 {
003 public static void main(String [] args)
004 {
005 System.out.println("asd");
006 }
007 }



作者 Re:color4j [Re:文夕]
ditty

负资产小资

CJSDN高级会员


发贴: 1038
于 2004-04-22 20:20 user profilesend a private message to usersend email to dittyreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不错不错~~~

001 package com.jivesoftware.forum.action;
002 
003 import com.jivesoftware.base.UnauthorizedException;
004 import com.jivesoftware.base.JiveGlobals;
005 import com.jivesoftware.forum.*;
006 import com.jivesoftware.util.ByteFormat;
007 import com.jivesoftware.util.MultipartParamUtils;
008 import com.jivesoftware.webwork.action.CommandDriven;
009 
010 import java.io.IOException;
011 import java.io.InputStream;
012 import java.util.*;
013 import javax.servlet.http.HttpSession;
014 
015 public class AttachAction extends PostAction
016         implements CommandDriven {
017 
018     public AttachAction() {
019         maxRequestSize = 0;
020         attachID = -1L;
021     }
022 
023     public String getDoAttachFiles() {
024         return doAttachFiles;
025     }
026 
027     public void setDoAttachFiles(String doAttachFiles) {
028         if (doAttachFiles != null && !"".equals(doAttachFiles.trim()))
029             this.doAttachFiles = "true";
030     }
031 
032     public void addErrorMessage(String message) {
033         super.addErrorMessage(message);
034     }
035 
036     public int[] getDeleteAttachIDs() {
037         return deleteAttachIDs;
038     }
039 
040     public void setDeleteAttachIDs(int deleteAttachIDs[]) {
041         this.deleteAttachIDs = deleteAttachIDs;
042     }
043 
044     public long getAttachID() {
045         return attachID;
046     }
047 
048     public void setAttachID(long attachID) {
049         this.attachID = attachID;
050     }
051 
052     public String getEncSubject() {
053         return encSubject;
054     }
055 
056     public void setEncSubject(String encSubject) {
057         if (encSubject != null && !"".equals(encSubject))
058             this.encSubject = encSubject;
059     }
060 
061     public String getEncBody() {
062         return encBody;
063     }
064 
065     public void setEncBody(String encBody) {
066         if (encBody != null && !"".equals(encBody))
067             this.encBody = encBody;
068     }
069 
070     public AttachmentManager getAttachmentManager() {
071         return getForumFactory().getAttachmentManager();
072     }
073 
074     public String getName() {
075         return (String) getServletRequest().getSession().getAttribute("jive.post.name." + getSessionSuffix());
076     }
077 
078     public String getEmail() {
079         return (String) getServletRequest().getSession().getAttribute("jive.post.email." + getSessionSuffix());
080     }
081 
082     public String getSubject() {
083         return (String) getServletRequest().getSession().getAttribute("jive.post.subject." + getSessionSuffix());
084     }
085 
086     public String getBody() {
087         return (String) getServletRequest().getSession().getAttribute("jive.post.body." + getSessionSuffix());
088     }
089 
090     public boolean isReply() {
091         Boolean replyVal = (Boolean) getServletRequest().getSession().getAttribute("jive.post.reply." + getSessionSuffix());
092         return replyVal != null && replyVal.booleanValue();
093     }
094 
095     public String getDoCancel() {
096         String doCancel = params.getParameter("doCancel");
097         if (doCancel != null && !"".equals(doCancel.trim()))
098             return "true";
099         else
100             return null;
101     }
102 
103 /*    public boolean isEdit()
104     {
105         return false;
106     }
107 */
108 
109     protected void doValidation() {
110         AttachmentManager manager = getAttachmentManager();
111         int requestSize = getServletRequest().getContentLength();
112         if (requestSize > maxRequestSize) {
113             ByteFormat byteFormat = new ByteFormat();
114             List args = new ArrayList();
115             args.add(byteFormat.format(new Long(manager.getMaxAttachmentSize() * 1024)));
116             addErrorMessage(getText("attach.error_generic", args));
117             return;
118         }
119         boolean hasValid = false;
120         int i = 0;
121         do {
122             if (i >= manager.getMaxAttachmentsPerMessage())
123                 break;
124             String contentType = params.getParameterContentType("attachFile" + (i + 1));
125             int attachSize = params.getParameterSize("attachFile" + (i + 1));
126             if (manager.isValidType(contentType)) {
127                 hasValid = true;
128                 break;
129             }
130             if (attachSize < manager.getMaxAttachmentSize() * 1024) {
131                 hasValid = true;
132                 break;
133             }
134             i++;
135         } while (true);
136         if (!hasValid)
137             addErrorMessage(getText("attach.error_content_type"));
138     }
139 
140     public String doDefault() {
141         try {
142             if (!loadJiveObjects()) {
143                 return ERROR;
144             }
145         } catch (UnauthorizedException e) {
146             setLoginAttributes();
147             addErrorMessage(getText("attach.error_unauth"));
148             return LOGIN;
149         }
150         if (!getCanAttach(getForum())) {
151             setLoginAttributes();
152             addErrorMessage(getText("attach.error_unauth"));
153             return LOGIN;
154         }
155         return INPUT;
156     }
157 
158     public String doDelete() {
159         try {
160             if (!loadJiveObjects()) {
161                 return ERROR;
162             }
163         } catch (UnauthorizedException e) {
164             setLoginAttributes();
165             addErrorMessage(getText("attach.error_unauth"));
166             return LOGIN;
167         }
168 
169         if (this.attachID == -1L) {
170             addErrorMessage(getText("attach.error_unable_delete"));
171             return "error";
172         }
173         ForumMessage msg = getMessage();
174         Attachment attachment = null;
175         Iterator attachments = msg.getAttachments();
176         long attachID;
177 
178         do {
179             if (!attachments.hasNext())
180                 break;
181             attachment = (Attachment) attachments.next();
182             attachID = attachment.getID();
183         } while (this.attachID != attachID);
184         try {
185             msg.deleteAttachment(attachment);
186         } catch (AttachmentException ae) {
187             addErrorMessage(ae.getMessage());
188             return ERROR;
189         } catch (UnauthorizedException ue) {
190             addErrorMessage(ue.getMessage());
191             return ERROR;
192         }
193         getServletRequest().setAttribute("partialURL", getPartialURL());
194         return "success-delete";
195     }
196 
197     public String doExecute() {
198         try {
199             if (loadJiveObjects() == false) {
200                 return "error";
201             }
202         } catch (UnauthorizedException e) {
203             setLoginAttributes();
204             addErrorMessage(getText("attach.error_unauth"));
205             return "login";
206         }
207         if ("true".equals(getDoCancel())) {
208             request.setAttribute("tid", getTid());
209             if (isReply()) {
210                 return "cancel-reply";
211             }
212             return "cancel-topic";
213         }
214         if (getCanAttach(getForum()) == false) {
215             setLoginAttributes();
216             addErrorMessage(getText("attach.error_unauth"));
217             return "login";
218         }
219         if (isNothingSelected()) {
220             addErrorMessage(getText("attach.error_at_least_one"));
221             request.setAttribute("tid", getTid());
222             return "input";
223         }
224         if (!isEdit()) {
225             /*try{
226             addAttachments();
227             }catch(UnauthorizedException ue){
228                 ue.printStackTrace();
229                 addErrorMessage(getText("attach.error_unauth"));
230                 return "error";
231             }*/
232             addAttachments();
233             if (getHasErrors()) {
234                 return ERROR;
235             }
236             request.setAttribute("tid", getTid());
237             if (isReply())
238                 return "success-reply";
239             request.setAttribute("tid", getTid());
240             if (isReply())
241                 return "success-reply";
242             else
243                 return "success-topic";
244 
245         } else {
246             try {
247                 addAttachments(getMessage());
248                 if (getHasErrors())
249                     return "error";
250                 else
251                     return "success-edit";
252             } catch (UnauthorizedException ue) {
253                 ue.printStackTrace();
254                 addErrorMessage(getText("attach.error_unauth"));
255                 return ERROR;
256             }
257         }
258     }
259 
260     protected int getExtraParamCount() {
261         return 0;
262     }
263 
264     protected boolean loadJiveObjects()
265             throws UnauthorizedException {
266         boolean success = true;
267         AttachmentManager manager = getAttachmentManager();
268         maxRequestSize = (manager.getMaxAttachmentsPerMessage() * manager.getMaxAttachmentSize() + manager.getMaxAttachmentsPerMessage() * 16 + getExtraParamCount() * 16) * 1024;
269         try {
270             params = new MultipartParamUtils(getServletRequest(), maxRequestSize);
271         } catch (IOException ioe) {
272             addErrorMessage(ioe.getMessage());
273             success = false;
274         }
275         if (success)
276             return super.loadJiveObjects();
277         else
278             return success;
279     }
280 
281     protected void addAttachments() {
282         AttachmentManager manager;
283         HttpSession session;
284         String key;
285         List attachIDs;
286         manager = getAttachmentManager();
287         session = request.getSession();
288         String suffix = getSessionSuffix();
289         key = "jive.post.tempAttachIDs" + suffix;
290         attachIDs = (List) session.getAttribute(key);
291         if (attachIDs == null) attachIDs = new ArrayList(5);
292         for (int i = 0; i < manager.getMaxAttachmentsPerMessage(); i++) {
293 
294             String attachmentName;
295             String contentType;
296             InputStream in;
297             attachmentName = params.getParameter("attachFile" + (i + 1));
298             contentType = params.getParameterContentType("attachFile" + (i + 1));
299             in = null;
300             in = params.getParameterData("attachFile" + (i + 1));
301             try {
302                 try {
303                     if (attachmentName != null && contentType != null && in != null) {
304                         attachmentName = getCanonicalName(attachmentName);
305                         Attachment attach = manager.createTempAttachment(attachmentName, contentType, in);
306                         attachIDs.add(new Long(attach.getID()));
307                     }
308                     in.close();
309                 } catch (AttachmentException ae) {
310                     if (ae.getErrorType() == 0)
311                         addError("attachFile" + (i + 1), getText("attach.error_too_large_field"));
312                     else if (ae.getErrorType() == 2)
313                         addError("attachFile" + (i + 1), getText("attach.error_content_type"));
314                     else if (ae.getErrorType() == 1)
315                         addError("attachFile" + (i + 1), getText("attach.error_too_many"));
316                     else
317                         addError("attachFile" + (i + 1), getText("attach.error_no_read_perm"));
318                 }
319             } catch (Exception e) {
320                 e.printStackTrace();
321             }
322             if (attachIDs.size() > 0) session.setAttribute(key, attachIDs);
323         }
324 
325     }
326 
327     protected void addAttachments(ForumMessage forumMessage) throws UnauthorizedException {
328         AttachmentManager manager = getAttachmentManager();
329         for (int i = 0; i < manager.getMaxAttachmentsPerMessage(); i++) {
330             String attachmentName = params.getParameter("attachFile" + (i + 1));
331             String contentType = params.getParameterContentType("attachFile" + (i + 1));
332             InputStream in = null;
333             try {
334                 // Try adding the attachment to the message
335                 in = params.getParameterData("attachFile" + (i + 1));
336                 if (attachmentName != null && contentType != null && in != null) {
337                     // Adjust the name (we only want the canonical name of the file)
338                     attachmentName = getCanonicalName(attachmentName);
339                     forumMessage.createAttachment(attachmentName, contentType, in);
340                 }
341             }
342                     /*catch(UnauthorizedException ue)*/ catch (AttachmentException ae) {
343                 if (ae.getErrorType() == AttachmentException.TOO_LARGE) {
344                     addError("attachFile" + (i + 1), getText("attach.error_too_large_field"));
345                 } else if (ae.getErrorType() == AttachmentException.BAD_CONTENT_TYPE) {
346                     addError("attachFile" + (i + 1), getText("attach.error_content_type"));
347                 } else if (ae.getErrorType() == AttachmentException.TOO_MANY_ATTACHMENTS) {
348                     addError("attachFile" + (i + 1), getText("attach.error_too_many"));
349                 } else {
350                     addError("attachFile" + (i + 1), getText("attach.error_no_read_perm"));
351                 }
352             } finally {
353                 try {
354                     in.close();
355                 } catch (Exception e) {
356                 }
357             }
358         }
359     }
360 
361     private boolean isNothingSelected() {
362         boolean nothing = true;
363         AttachmentManager manager = getAttachmentManager();
364         for (int i = 0; i < manager.getMaxAttachmentsPerMessage(); i++) {
365             String attachmentName = params.getParameter("attachFile" + (i + 1));
366             if (attachmentName != null)
367                 nothing = false;
368         }
369 
370         return nothing;
371     }
372 
373 /*    private String getCanonicalName(String filename) {
374         int forwardSlash = filename.lastIndexOf("/");
375         int backwardSlash = filename.lastIndexOf("\\");
376         if (forwardSlash != -1 && forwardSlash > backwardSlash)
377             filename = filename.substring(forwardSlash + 1, filename.length());
378         else if (backwardSlash != -1 && backwardSlash >= forwardSlash)
379             filename = filename.substring(backwardSlash + 1, filename.length());
380         return filename;
381     }
382 */
383     private String getCanonicalName(String filename)
384     {
385         int forwardSlash = filename.lastIndexOf("/");
386         int backwardSlash = filename.lastIndexOf("\\");
387         if(forwardSlash != -1 && forwardSlash > backwardSlash)
388             filename = filename.substring(forwardSlash + 1, filename.length());
389         else
390         if(backwardSlash != -1 && backwardSlash >= forwardSlash)
391             filename = filename.substring(backwardSlash + 1, filename.length());
392         if(JiveGlobals.getCharacterEncoding().equalsIgnoreCase("UTF-8") && JiveGlobals.getLocale().getCountry().equalsIgnoreCase("CN"))
393             try
394             {
395                 filename = new String(filename.getBytes("ISO-8859-1"), "UTF-8");
396             }
397             catch(Exception e) { }
398         return filename;
399     }
400 
401     public static String SUCCESS_TOPIC = "success-topic";
402     public static String SUCCESS_MESSAGE = "success-message";
403     protected MultipartParamUtils params;
404     private int maxRequestSize;
405     private int deleteAttachIDs[];
406     private long attachID;
407     private String doAttachFiles;
408     private String encSubject;
409     private String encBody;
410 }



内忧外患的时代,洗心革面,阿咪豆腐~
作者 Re:color4j [Re:Jove]
fnhufoz



发贴: 0
于 2004-05-22 00:05 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不赖


作者 Re:color4j [Re:Jove]
littledeer1974

Garbage Collector

CJSDN高级会员


发贴: 1517
于 2005-01-06 12:39 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
一直很关注这个小软件,觉得很有意思,不知道最近有什么新消息没有?
顺便说一下,觉得界面还可以做的更容易操作一些
Smile


littledeer1974 edited on 2005-01-06 12:46

Surround yourself with people who are open to change

作者 Re:color4j [Re:Jove]
chenyajun5

一日不倒,每天都打

CJSDN高级会员


发贴: 643
于 2005-01-26 10:59 user profilesend a private message to usersend email to chenyajun5reply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
001 package com.cnjsp.cnjbb.mysql;
002 
003 
004 /**
005  * 点击量管理器
006  * 
007  * @author Sager
008  */
009 public class DbHitsManager {
010   protected final static int MESSAGE_HITS = 0;
011 
012   private final static int HITS_COUNT = 1;
013   private Hits[] hits = null;
014 
015   protected DbHitsManager() {
016     hits = new Hits[HITS_COUNT];
017     hits[MESSAGE_HITS] = new MessageHits();
018   }
019   public void addHit(int typeObject key) {
020     if (type >= 0 && type < HITS_COUNT)
021       hits[type].addHit(key);
022   }
023 }



想干的人找一个方法,不想干的人找一个借口。
作者 Re:color4j [Re:Jove]
chenyajun5

一日不倒,每天都打

CJSDN高级会员


发贴: 643
于 2005-01-26 11:00 user profilesend a private message to usersend email to chenyajun5reply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
修改样式表,让保留字加粗。。


想干的人找一个方法,不想干的人找一个借口。
作者 Re:color4j [Re:Jove]
alexyu2000

我是多罗,我很可爱

Jute Pro User


发贴: 405
于 2005-01-26 11:14 user profilesend a private message to usersend email to alexyu2000reply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
还有进展吗??看下jute最近的进展截图,ok?


[img]http://www.nhacks.com/email/email.php?mail_e=q8UtjGduMME%3D&iv=ICTOzCo%3D&domain=TVNO&ext=0[/img][img]http://bbs.dongman.org:8080/post-85-10950836311.gif[/img]
[img]http://bbs.8080.net/upload/17957/17957.jpg[/img]

reply to topicflat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923