Source Code Cross Referenced for SourceJammerClient.java in  » Source-Control » sourcejammer » org » sourcejammer » client » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Source Control » sourcejammer » org.sourcejammer.client 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  Copyright (C) 2001, 2002 Robert MacGrogan
0003:         *
0004:         *  This library is free software; you can redistribute it and/or
0005:         *  modify it under the terms of the GNU Lesser General Public
0006:         *  License as published by the Free Software Foundation; either
0007:         *  version 2.1 of the License, or (at your option) any later version.
0008:         *
0009:         *  This library is distributed in the hope that it will be useful,
0010:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0011:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0012:         *  Lesser General Public License for more details.
0013:         *
0014:         *  You should have received a copy of the GNU Lesser General Public
0015:         *  License along with this library; if not, write to the Free Software
0016:         *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0017:         *
0018:         *
0019:         * $Archive: SourceJammer$
0020:         * $FileName: SourceJammerClient.java$
0021:         * $FileID: 4191$
0022:         *
0023:         * Last change:
0024:         * $AuthorName: Rob MacGrogan$
0025:         * $Date: 9/17/03 1:15 PM$
0026:         * $VerID: 10365$
0027:         * $Comment: $
0028:         */
0029:
0030:        package org.sourcejammer.client;
0031:
0032:        import org.sourcejammer.xml.XMLUtil;
0033:        import java.io.File;
0034:        import java.io.IOException;
0035:        import java.util.ArrayList;
0036:        import java.util.Iterator;
0037:
0038:        import org.xml.sax.SAXException;
0039:        import org.sourcejammer.client.event.FileEventListenerPluginPool;
0040:        import org.sourcejammer.client.gui.conf.Plugin;
0041:        import org.sourcejammer.client.plugin.SJClientFileEventListener;
0042:        import org.sourcejammer.util.AppConfig;
0043:        import org.sourcejammer.util.SJFileDataSource;
0044:        import org.w3c.dom.Document;
0045:        import org.w3c.dom.Element;
0046:        import org.w3c.dom.Node;
0047:        import org.w3c.dom.NodeList;
0048:        import org.sourcejammer.util.TempDirectoryManager;
0049:        import java.awt.Color;
0050:        import java.awt.Font;
0051:
0052:        import javax.xml.parsers.ParserConfigurationException;
0053:        import javax.xml.transform.TransformerException;
0054:
0055:        import org.sourcejammer.xml.XMLNodeDoesNotExistException;
0056:        import org.sourcejammer.util.ConfigurationException;
0057:
0058:        /**
0059:         * Title:        $FileName: SourceJammerClient.java$
0060:         * @version      $VerNum: 19$
0061:         * @author       $AuthorName: Rob MacGrogan$<br><br>
0062:         * $Description: $</br>
0063:         * $KeyWordsOff: $
0064:         */
0065:        public class SourceJammerClient {
0066:            public static final String VERSION = "2.1.0.0";
0067:
0068:            private static final String CONF_FILE = "clientconf.xml";
0069:
0070:            public static final class ConfXMLNodes {
0071:                public static final String ROOT = "SJConfig";
0072:                public static final String DEFAULT_END_OF_LINE = "DefaultEndOfLine";
0073:                public static final String DEFAULT_FILE_TYPE = "DefaultFileType";
0074:                public static final String MAKE_WRITABLE = "MakeWritableCommand";
0075:                public static final String ZIP_IF_LARGER_THAN = "ZipIfLargerThan";
0076:                public static final String INITIAL_LOOK_AND_FEEL = "InitialLookAndFeel";
0077:                public static final String DEFAULT_EOL_TYPE = "DefaultEOLType";
0078:                public static final String MAX_FILE_SEND_CHUNK_SIZE = "MaxFileSendChunkSize";
0079:                public static final String DISPLAY_TEXT_PROPERTIES_FILE = "DisplayTextPropsFileName";
0080:                public static final String FILE_DIALOG_TYPE = "FileDialogType";
0081:                public static final String HIDE_FILE_COMMAND = "HideFileCommand";
0082:                public static final String SHOW_FILE_COMMAND = "ShowFileCommand";
0083:
0084:                public static final String ADDED_COLOR = "AddedColor";
0085:                public static final String DELETED_COLOR = "DeletedColor";
0086:                public static final String MODIFIED_COLOR = "ModifiedColor";
0087:
0088:                public static final String NOT_IN_ARCHIVE_COLOR = "NotInArchiveColor";
0089:                public static final String NOT_IN_SYNC_COLOR = "NotInSyncColor";
0090:                public static final String NOT_IN_LOCAL_COLOR = "NotInLocalColor";
0091:
0092:                public static final String R_VAL_ATTRIB = "r";
0093:                public static final String G_VAL_ATTRIB = "g";
0094:                public static final String B_VAL_ATTRIB = "b";
0095:
0096:                public static final String LOCAL_FILE_ACTION = "LocalFileAction";
0097:                //Following nodes can have values in the "lfa_" constants.
0098:                public static final String ADD_FILE = "AddFile";
0099:                public static final String CHECK_IN_FILE = "CheckInFile";
0100:                public static final String GET_FILE = "GetFile";
0101:                //Following can only be get latest or no special action.
0102:                public static final String FILE_MODIFIED_ON_CHECKIN = "FileModifiedOnCheckin";
0103:
0104:                public static final String MONO_FONT = "MonoFont";
0105:                public static final String FONT_NAME_ATTRIB = "name";
0106:                public static final String FONT_STYLE_ATTRIB = "style";
0107:                public static final String FONT_SIZE_ATTRIB = "size";
0108:                public static final String TAB_SIZE_ATTRIB = "tabsize";
0109:
0110:                public static final String KEYSTORE = "KeyStore";
0111:            }
0112:
0113:            public static final String lfa_SET_READ_ONLY = "set-read-only";
0114:            public static final String lfa_DELETE = "delete";
0115:            public static final String lfa_GET_LATEST = "get-latest";
0116:            public static final String lfa_NO_SPECIAL_ACTION = "no-special-action";
0117:
0118:            public static final String TREE_FILE_DIALOG = "tree";
0119:            public static final String J_FILE_CHOOSER = "chooser";
0120:
0121:            public static final String PLAIN = "plain";
0122:            public static final String BOLD = "bold";
0123:            public static final String ITALIC = "italic";
0124:            public static final String BOLDITALIC = "bolditalic";
0125:
0126:            private static SourceJammerClient instance = null;
0127:            private char[] defaultEndOfLine = { '\r', '\n' };
0128:            private int defaultFileType = AppConfig.FileTypes.BINARY;
0129:            private String[] makeWritableCommand = { "attrib", "-r " }; // for linux: chmod +w
0130:            private int zipIfLargerThan = 10240;
0131:            private String initialLookAndFeel = AppConfig.LookAndFeel.METAL;
0132:            private int defaultEOLType = AppConfig.EndOfLineType.LINE_FEED;
0133:            private int maxFileSendChunkSize = 1024 * 10; //10K
0134:            private String displayTextPropertiesFileName = "english.props";
0135:            private String fileDialogType = J_FILE_CHOOSER;
0136:            private String[] hideFileCommand = null;
0137:            private String[] showFileCommand = null;
0138:
0139:            private Color deletedColor = Color.red;
0140:            private Color addedColor = Color.yellow;
0141:            private Color modifiedColor = Color.green;
0142:
0143:            private Color notInArchiveColor = Color.RED;
0144:            private Color notInSyncColor = new Color(0, 85, 0);
0145:            private Color notInLocalColor = new Color(0, 0, 138);
0146:
0147:            private String onAddFileAction = lfa_SET_READ_ONLY;
0148:            private String onCheckInFileAction = lfa_SET_READ_ONLY;
0149:            private String onGetFileAction = lfa_SET_READ_ONLY;
0150:            private String onFileModifiedOnCheckin = lfa_NO_SPECIAL_ACTION;
0151:
0152:            private ArrayList plugins = new ArrayList();
0153:
0154:            private FileEventListenerPluginPool filePool = new FileEventListenerPluginPool();
0155:
0156:            private Font monoFont = new Font("Monospaced", Font.PLAIN, 12);
0157:            private int tabSize = 2;
0158:
0159:            private String keyStoreFile = System.getProperty("java.home")
0160:                    + File.separator + "bin" + File.separator + "sj.keystore";
0161:
0162:            private File confFile = null;
0163:
0164:            private SourceJammerClient() {
0165:            }
0166:
0167:            public FileEventListenerPluginPool getFileListeners() {
0168:                return filePool;
0169:            }
0170:
0171:            private synchronized void load(String sBasePath)
0172:                    throws IOException, SAXException {
0173:
0174:                File flConf = null;
0175:                if (sBasePath == null) {
0176:                    flConf = new File(CONF_FILE);
0177:                } else {
0178:                    flConf = new File(sBasePath, CONF_FILE);
0179:                }
0180:                this .confFile = flConf;
0181:                System.out.println("cc - " + flConf.getAbsolutePath());
0182:
0183:                if (flConf.exists()) {
0184:                    Document docConf = null;
0185:                    try {
0186:                        docConf = XMLUtil.getXMLDoc(flConf);
0187:                    } catch (ParserConfigurationException ex) {
0188:                        throw new SAXException(
0189:                                "Parser exception in reading config xml doc.",
0190:                                ex);
0191:                    }
0192:                    Element elmRoot = docConf.getDocumentElement();
0193:
0194:                    //File Type
0195:                    String sDefFileType = XMLUtil.getValue(
0196:                            ConfXMLNodes.DEFAULT_FILE_TYPE, elmRoot);
0197:                    defaultFileType = Integer.parseInt(sDefFileType.trim());
0198:
0199:                    //Make writable command
0200:                    String sMakeWritable = XMLUtil.getValue(
0201:                            ConfXMLNodes.MAKE_WRITABLE, elmRoot);
0202:                    if (sMakeWritable != null) {
0203:                        java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(
0204:                                sMakeWritable, " ", false);
0205:                        int iNumCmds = tokenizer.countTokens();
0206:                        makeWritableCommand = new String[iNumCmds];
0207:                        int iCounter = 0;
0208:                        while (tokenizer.hasMoreTokens()) {
0209:                            makeWritableCommand[iCounter] = tokenizer
0210:                                    .nextToken();
0211:                            iCounter++;
0212:                        }
0213:                    }
0214:
0215:                    //Zip size
0216:                    String sNumBytes = XMLUtil.getValue(
0217:                            ConfXMLNodes.ZIP_IF_LARGER_THAN, elmRoot);
0218:                    if (sNumBytes != null) {
0219:                        try {
0220:                            zipIfLargerThan = Integer.parseInt(sNumBytes);
0221:                        } catch (NumberFormatException ex) {
0222:                            //ignore and leave default value
0223:                        }
0224:                    }
0225:
0226:                    //Max Send Byte Chunk Size
0227:                    sNumBytes = XMLUtil.getValue(
0228:                            ConfXMLNodes.MAX_FILE_SEND_CHUNK_SIZE, elmRoot);
0229:                    if (sNumBytes != null) {
0230:                        try {
0231:                            maxFileSendChunkSize = Integer.parseInt(sNumBytes);
0232:                        } catch (NumberFormatException ex) {
0233:                            //ignore and leave default value
0234:                        }
0235:                    }
0236:
0237:                    //LAF
0238:                    String sLookAndFeel = XMLUtil.getValue(
0239:                            ConfXMLNodes.INITIAL_LOOK_AND_FEEL, elmRoot);
0240:                    if (sLookAndFeel != null) {
0241:                        initialLookAndFeel = sLookAndFeel;
0242:                    }
0243:
0244:                    //EOL
0245:                    String sEndOfLine = XMLUtil.getValue(
0246:                            ConfXMLNodes.DEFAULT_EOL_TYPE, elmRoot);
0247:                    if (sNumBytes != null) {
0248:                        try {
0249:                            defaultEOLType = Integer.parseInt(sEndOfLine);
0250:                            if (defaultEOLType == AppConfig.EndOfLineType.CARRIAGE_RETURN_LINE_FEED) {
0251:                                defaultEndOfLine = AppConfig.EndOfLines.CARRIAGE_RETURN_LINE_FEED;
0252:                            } else {
0253:                                defaultEndOfLine = AppConfig.EndOfLines.LINE_FEED;
0254:                            }
0255:                        } catch (NumberFormatException ex) {
0256:                            //ignore and leave default value
0257:                        }
0258:                    }
0259:
0260:                    //Display Text File
0261:                    String sDisplayFile = XMLUtil.getValue(
0262:                            ConfXMLNodes.DISPLAY_TEXT_PROPERTIES_FILE, elmRoot);
0263:                    if (sDisplayFile != null) {
0264:                        displayTextPropertiesFileName = sDisplayFile;
0265:                    }
0266:
0267:                    //File Dialog Type
0268:                    String sDialogType = XMLUtil.getValue(
0269:                            ConfXMLNodes.FILE_DIALOG_TYPE, elmRoot);
0270:                    if (sDialogType != null) {
0271:                        fileDialogType = sDialogType;
0272:                    }
0273:
0274:                    //Hide file command
0275:                    String sHideFile = XMLUtil.getValue(
0276:                            ConfXMLNodes.HIDE_FILE_COMMAND, elmRoot);
0277:                    if (sHideFile != null) {
0278:                        java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(
0279:                                sHideFile, " ", false);
0280:                        int iNumCmds = tokenizer.countTokens();
0281:                        hideFileCommand = new String[iNumCmds];
0282:                        int iCounter = 0;
0283:                        while (tokenizer.hasMoreTokens()) {
0284:                            hideFileCommand[iCounter] = tokenizer.nextToken();
0285:                            iCounter++;
0286:                        }
0287:                    }
0288:                    //Show file command
0289:                    String sShowFile = XMLUtil.getValue(
0290:                            ConfXMLNodes.SHOW_FILE_COMMAND, elmRoot);
0291:                    if (sShowFile != null) {
0292:                        java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(
0293:                                sShowFile, " ", false);
0294:                        int iNumCmds = tokenizer.countTokens();
0295:                        showFileCommand = new String[iNumCmds];
0296:                        int iCounter = 0;
0297:                        while (tokenizer.hasMoreTokens()) {
0298:                            showFileCommand[iCounter] = tokenizer.nextToken();
0299:                            iCounter++;
0300:                        }
0301:                    }
0302:
0303:                    //Deleted Color.
0304:                    try {
0305:                        Element elmDeletedColor = XMLUtil.getChildElement(
0306:                                ConfXMLNodes.DELETED_COLOR, elmRoot);
0307:                        if (elmDeletedColor != null) {
0308:                            deletedColor = getColorFromElement(elmDeletedColor);
0309:                        }
0310:                    } catch (XMLNodeDoesNotExistException ex) {
0311:                        //ignore.
0312:                    }
0313:
0314:                    //Added Color.
0315:                    try {
0316:                        Element elmAddedColor = XMLUtil.getChildElement(
0317:                                ConfXMLNodes.ADDED_COLOR, elmRoot);
0318:                        if (elmAddedColor != null) {
0319:                            addedColor = getColorFromElement(elmAddedColor);
0320:                        }
0321:                    } catch (XMLNodeDoesNotExistException ex) {
0322:                        //ignore.
0323:                    }
0324:
0325:                    //Modified Color.
0326:                    try {
0327:                        Element elmModifiedColor = XMLUtil.getChildElement(
0328:                                ConfXMLNodes.MODIFIED_COLOR, elmRoot);
0329:                        if (elmModifiedColor != null) {
0330:                            modifiedColor = getColorFromElement(elmModifiedColor);
0331:                        }
0332:                    } catch (XMLNodeDoesNotExistException ex) {
0333:                        //ignore.
0334:                    }
0335:
0336:                    //Not in archive Color.
0337:                    try {
0338:                        Element elmNotInArchiveColor = XMLUtil.getChildElement(
0339:                                ConfXMLNodes.NOT_IN_ARCHIVE_COLOR, elmRoot);
0340:                        if (elmNotInArchiveColor != null) {
0341:                            notInArchiveColor = getColorFromElement(elmNotInArchiveColor);
0342:                        }
0343:                    } catch (XMLNodeDoesNotExistException ex) {
0344:                        //ignore.
0345:                    }
0346:
0347:                    //Not in sync color.
0348:                    try {
0349:                        Element elmNotInSyncColor = XMLUtil.getChildElement(
0350:                                ConfXMLNodes.NOT_IN_SYNC_COLOR, elmRoot);
0351:                        if (elmNotInSyncColor != null) {
0352:                            notInSyncColor = getColorFromElement(elmNotInSyncColor);
0353:                        }
0354:                    } catch (XMLNodeDoesNotExistException ex) {
0355:                        //ignore.
0356:                    }
0357:
0358:                    //Not in local color.
0359:                    try {
0360:                        Element elmNotInLocalColor = XMLUtil.getChildElement(
0361:                                ConfXMLNodes.NOT_IN_LOCAL_COLOR, elmRoot);
0362:                        if (elmNotInLocalColor != null) {
0363:                            notInLocalColor = getColorFromElement(elmNotInLocalColor);
0364:                        }
0365:                    } catch (XMLNodeDoesNotExistException ex) {
0366:                        //ignore.
0367:                    }
0368:
0369:                    //Mono font.
0370:                    try {
0371:                        Element elmMonoFont = XMLUtil.getChildElement(
0372:                                ConfXMLNodes.MONO_FONT, elmRoot);
0373:                        if (elmMonoFont != null) {
0374:                            monoFont = getFontFromElement(elmMonoFont);
0375:                            String sTab = elmMonoFont
0376:                                    .getAttribute(ConfXMLNodes.TAB_SIZE_ATTRIB);
0377:                            try {
0378:                                tabSize = Integer.parseInt(sTab);
0379:                            } catch (Exception ex) {
0380:                                //Ignore
0381:                            }
0382:                        }
0383:                    } catch (XMLNodeDoesNotExistException ex) {
0384:                        //ignore.
0385:                    }
0386:
0387:                    //Keystore.
0388:                    try {
0389:                        Element elmKeyStore = XMLUtil.getChildElement(
0390:                                ConfXMLNodes.KEYSTORE, elmRoot);
0391:                        if (elmKeyStore != null) {
0392:                            keyStoreFile = XMLUtil.getValue(
0393:                                    ConfXMLNodes.KEYSTORE, elmRoot);
0394:                        }
0395:                    } catch (XMLNodeDoesNotExistException ex) {
0396:                        //ignore.
0397:                    }
0398:
0399:                    //Local File Actions.
0400:                    try {
0401:                        Element elmLocalFileActions = XMLUtil.getChildElement(
0402:                                ConfXMLNodes.LOCAL_FILE_ACTION, elmRoot);
0403:                        if (elmLocalFileActions != null) {
0404:                            onAddFileAction = elmLocalFileActions
0405:                                    .getAttribute(ConfXMLNodes.ADD_FILE);
0406:                            onCheckInFileAction = elmLocalFileActions
0407:                                    .getAttribute(ConfXMLNodes.CHECK_IN_FILE);
0408:                            onGetFileAction = elmLocalFileActions
0409:                                    .getAttribute(ConfXMLNodes.GET_FILE);
0410:                            onFileModifiedOnCheckin = elmLocalFileActions
0411:                                    .getAttribute(ConfXMLNodes.FILE_MODIFIED_ON_CHECKIN);
0412:                        }
0413:                    } catch (XMLNodeDoesNotExistException ex) {
0414:                        //ignore.
0415:                    }
0416:
0417:                    loadPlugins(elmRoot);
0418:
0419:                }//end if file exists
0420:            }
0421:
0422:            private String commandToString(String[] s) {
0423:                StringBuffer str = new StringBuffer();
0424:
0425:                str.append(makeWritableCommand[0]);
0426:
0427:                for (int i = 1; i < s.length; i++) {
0428:                    str.append(" ").append(makeWritableCommand[i]);
0429:                }
0430:                return str.toString();
0431:            }
0432:
0433:            public void save() throws TransformerException, IOException {
0434:                Document xml = XMLUtil.newDocument();
0435:                Element elmRoot = XMLUtil
0436:                        .addRootElement(ConfXMLNodes.ROOT, xml);
0437:
0438:                //File Type
0439:                if (defaultFileType != -1) {
0440:                    XMLUtil.addNewChildElement(ConfXMLNodes.DEFAULT_FILE_TYPE,
0441:                            Integer.toString(defaultFileType), elmRoot);
0442:                }
0443:
0444:                //Make writable command
0445:                if (makeWritableCommand != null) {
0446:                    XMLUtil.addNewChildElement(ConfXMLNodes.MAKE_WRITABLE,
0447:                            commandToString(makeWritableCommand), elmRoot);
0448:                }
0449:
0450:                //Zip size
0451:                if (zipIfLargerThan > -1) {
0452:                    XMLUtil.addNewChildElement(ConfXMLNodes.ZIP_IF_LARGER_THAN,
0453:                            Integer.toString(zipIfLargerThan), elmRoot);
0454:                }
0455:
0456:                //Max Send Byte Chunk Size
0457:                if (maxFileSendChunkSize > -1) {
0458:                    XMLUtil.addNewChildElement(
0459:                            ConfXMLNodes.MAX_FILE_SEND_CHUNK_SIZE, Integer
0460:                                    .toString(maxFileSendChunkSize), elmRoot);
0461:                }
0462:
0463:                //LAF
0464:                if (initialLookAndFeel != null) {
0465:                    XMLUtil.addNewChildElement(
0466:                            ConfXMLNodes.INITIAL_LOOK_AND_FEEL,
0467:                            initialLookAndFeel, elmRoot);
0468:                }
0469:
0470:                //EOL
0471:                if (defaultEOLType > -1) {
0472:                    XMLUtil.addNewChildElement(ConfXMLNodes.DEFAULT_EOL_TYPE,
0473:                            Integer.toString(defaultEOLType), elmRoot);
0474:                }
0475:
0476:                //Display Text File
0477:                if (displayTextPropertiesFileName != null) {
0478:                    XMLUtil.addNewChildElement(
0479:                            ConfXMLNodes.DISPLAY_TEXT_PROPERTIES_FILE,
0480:                            displayTextPropertiesFileName, elmRoot);
0481:                }
0482:
0483:                //File Dialog Type
0484:                if (fileDialogType != null) {
0485:                    XMLUtil.addNewChildElement(ConfXMLNodes.FILE_DIALOG_TYPE,
0486:                            fileDialogType, elmRoot);
0487:                }
0488:
0489:                //Hide file command
0490:                if (hideFileCommand != null) {
0491:                    XMLUtil.addNewChildElement(ConfXMLNodes.MAKE_WRITABLE,
0492:                            commandToString(hideFileCommand), elmRoot);
0493:                }
0494:
0495:                //Show file command
0496:                if (showFileCommand != null) {
0497:                    XMLUtil.addNewChildElement(ConfXMLNodes.MAKE_WRITABLE,
0498:                            commandToString(showFileCommand), elmRoot);
0499:                }
0500:
0501:                //Deleted Color.
0502:                if (deletedColor != null) {
0503:                    Element elm = XMLUtil.addNewChildElement(
0504:                            ConfXMLNodes.DELETED_COLOR, elmRoot);
0505:                    colorToElement(deletedColor, elm);
0506:                }
0507:
0508:                //Added Color.
0509:                if (addedColor != null) {
0510:                    Element elm = XMLUtil.addNewChildElement(
0511:                            ConfXMLNodes.ADDED_COLOR, elmRoot);
0512:                    colorToElement(addedColor, elm);
0513:                }
0514:
0515:                //Modified Color.
0516:                if (modifiedColor != null) {
0517:                    Element elm = XMLUtil.addNewChildElement(
0518:                            ConfXMLNodes.MODIFIED_COLOR, elmRoot);
0519:                    colorToElement(modifiedColor, elm);
0520:                }
0521:
0522:                //Not in archive Color.
0523:                if (notInArchiveColor != null) {
0524:                    Element elm = XMLUtil.addNewChildElement(
0525:                            ConfXMLNodes.NOT_IN_ARCHIVE_COLOR, elmRoot);
0526:                    colorToElement(notInArchiveColor, elm);
0527:                }
0528:
0529:                //Not in sync color.
0530:                if (notInSyncColor != null) {
0531:                    Element elm = XMLUtil.addNewChildElement(
0532:                            ConfXMLNodes.NOT_IN_SYNC_COLOR, elmRoot);
0533:                    colorToElement(notInSyncColor, elm);
0534:                }
0535:
0536:                //Not in local color.
0537:                if (notInLocalColor != null) {
0538:                    Element elm = XMLUtil.addNewChildElement(
0539:                            ConfXMLNodes.NOT_IN_LOCAL_COLOR, elmRoot);
0540:                    colorToElement(notInLocalColor, elm);
0541:                }
0542:
0543:                //Mono font.
0544:                if (monoFont != null) {
0545:                    Element elm = XMLUtil.addNewChildElement(
0546:                            ConfXMLNodes.MONO_FONT, elmRoot);
0547:                    elm.setAttribute(ConfXMLNodes.TAB_SIZE_ATTRIB, Integer
0548:                            .toString(tabSize));
0549:                    elm.setAttribute(ConfXMLNodes.FONT_NAME_ATTRIB, monoFont
0550:                            .getName());
0551:                    elm.setAttribute(ConfXMLNodes.FONT_SIZE_ATTRIB, Integer
0552:                            .toString(monoFont.getSize()));
0553:                    elm.setAttribute(ConfXMLNodes.FONT_STYLE_ATTRIB, Integer
0554:                            .toString(monoFont.getStyle()));
0555:                }
0556:
0557:                //Keystore.
0558:                if (keyStoreFile != null) {
0559:                    XMLUtil.addNewChildElement(ConfXMLNodes.KEYSTORE,
0560:                            keyStoreFile, elmRoot);
0561:
0562:                }
0563:
0564:                //Local File Actions.
0565:                if (onAddFileAction != null || onCheckInFileAction != null
0566:                        || onGetFileAction != null
0567:                        || onFileModifiedOnCheckin != null) {
0568:                    Element elm = XMLUtil.addNewChildElement(
0569:                            ConfXMLNodes.LOCAL_FILE_ACTION, elmRoot);
0570:                    addAttribIfNotNull(ConfXMLNodes.ADD_FILE, onAddFileAction,
0571:                            elm);
0572:                    addAttribIfNotNull(ConfXMLNodes.CHECK_IN_FILE,
0573:                            onCheckInFileAction, elm);
0574:                    addAttribIfNotNull(ConfXMLNodes.GET_FILE, onGetFileAction,
0575:                            elm);
0576:                    addAttribIfNotNull(ConfXMLNodes.FILE_MODIFIED_ON_CHECKIN,
0577:                            onFileModifiedOnCheckin, elm);
0578:                }
0579:
0580:                savePlugins(elmRoot);
0581:
0582:                XMLUtil.writeXMLDocToFileSys(xml, confFile, true);
0583:            }
0584:
0585:            private void addAttribIfNotNull(String attrib, String value,
0586:                    Element elm) {
0587:                if (value != null) {
0588:                    elm.setAttribute(attrib, value);
0589:                }
0590:            }
0591:
0592:            private void colorToElement(Color color, Element elm) {
0593:                int r = color.getRed();
0594:                int g = color.getGreen();
0595:                int b = color.getBlue();
0596:
0597:                elm
0598:                        .setAttribute(ConfXMLNodes.R_VAL_ATTRIB, Integer
0599:                                .toString(r));
0600:                elm
0601:                        .setAttribute(ConfXMLNodes.G_VAL_ATTRIB, Integer
0602:                                .toString(g));
0603:                elm
0604:                        .setAttribute(ConfXMLNodes.B_VAL_ATTRIB, Integer
0605:                                .toString(b));
0606:            }
0607:
0608:            public ArrayList getPlugins() {
0609:                return plugins;
0610:            }
0611:
0612:            private void loadPlugins(Element configRootElement) {
0613:                try {
0614:                    Element plugins = XMLUtil.getChildElement(
0615:                            Plugin.XMLNodes.PLUGINS, configRootElement);
0616:                    NodeList list = plugins.getChildNodes();
0617:                    for (int i = 0; i < list.getLength(); i++) {
0618:                        Node nd = list.item(i);
0619:                        if (nd instanceof  Element) {
0620:                            Element elmPlugin = (Element) nd;
0621:                            Plugin pl = new Plugin(elmPlugin);
0622:                            this .plugins.add(pl);
0623:
0624:                            //Add to file pool, if needed.
0625:                            if (pl.isType(Plugin.PluginType.FILE_EVENT)) {
0626:                                SJClientFileEventListener fileListener = (SJClientFileEventListener) pl
0627:                                        .getPlugin();
0628:                                filePool.addListener(fileListener);
0629:                            }
0630:                        }
0631:                    }
0632:                } catch (XMLNodeDoesNotExistException ex) {
0633:                    //ignore
0634:                }
0635:            }
0636:
0637:            private void savePlugins(Element elmRoot) {
0638:                if (plugins.size() > 0) {
0639:                    Element elmPlugins = XMLUtil.addNewChildElement(
0640:                            Plugin.XMLNodes.PLUGINS, elmRoot);
0641:                    Iterator itr = plugins.iterator();
0642:                    while (itr.hasNext()) {
0643:                        Plugin p = (Plugin) itr.next();
0644:                        Element elmPlugin = p.writePluginElement(elmPlugins);
0645:                    }
0646:                }
0647:            }
0648:
0649:            public String getKeyStoreFile() {
0650:                return keyStoreFile;
0651:            }
0652:
0653:            private Font getFontFromElement(Element elm) {
0654:                Font fnt = null;
0655:                String sName = elm.getAttribute(ConfXMLNodes.FONT_NAME_ATTRIB);
0656:                String sStyle = elm
0657:                        .getAttribute(ConfXMLNodes.FONT_STYLE_ATTRIB);
0658:                String sSize = elm.getAttribute(ConfXMLNodes.FONT_SIZE_ATTRIB);
0659:
0660:                int size = -1;
0661:                try {
0662:                    size = Integer.parseInt(sSize);
0663:                } catch (Exception ex) {
0664:                    throw new ConfigurationException("Invalid size value in "
0665:                            + elm.getNodeName() + ".", ex);
0666:                }
0667:
0668:                int style = Font.PLAIN;
0669:                if (sStyle.equalsIgnoreCase(BOLD)) {
0670:                    style = Font.BOLD;
0671:                } else if (sStyle.equalsIgnoreCase(ITALIC)) {
0672:                    style = Font.ITALIC;
0673:                } else if (sStyle.equalsIgnoreCase(BOLDITALIC)) {
0674:                    style = Font.BOLD | Font.ITALIC;
0675:                }
0676:
0677:                fnt = new Font(sName, style, size);
0678:
0679:                return fnt;
0680:            }
0681:
0682:            /**
0683:             * Looks for r, g, and b attributes in elm and builds a Color based on the values.
0684:             */
0685:            private Color getColorFromElement(Element elm) {
0686:                Color color = null;
0687:                String sR = elm.getAttribute(ConfXMLNodes.R_VAL_ATTRIB);
0688:                int r = -1;
0689:                try {
0690:                    r = Integer.parseInt(sR.trim());
0691:                } catch (Exception ex) {
0692:                    throw new ConfigurationException("Invalid r value in "
0693:                            + elm.getNodeName() + ".", ex);
0694:                }
0695:
0696:                String sG = elm.getAttribute(ConfXMLNodes.G_VAL_ATTRIB);
0697:                int g = -1;
0698:                try {
0699:                    g = Integer.parseInt(sG.trim());
0700:                } catch (Exception ex) {
0701:                    throw new ConfigurationException("Invalid g value in "
0702:                            + elm.getNodeName() + ".", ex);
0703:                }
0704:
0705:                String sB = elm.getAttribute(ConfXMLNodes.B_VAL_ATTRIB);
0706:                int b = -1;
0707:                try {
0708:                    b = Integer.parseInt(sB.trim());
0709:                } catch (Exception ex) {
0710:                    throw new ConfigurationException("Invalid b value in "
0711:                            + elm.getNodeName() + ".", ex);
0712:                }
0713:
0714:                color = new Color(r, g, b);
0715:                return color;
0716:            }
0717:
0718:            public static SourceJammerClient getInstance() {
0719:                return instance;
0720:            }
0721:
0722:            public static SourceJammerClient getInstance(String confPath) {
0723:                try {
0724:                    instance = new SourceJammerClient();
0725:                    instance.load(confPath);
0726:                    TempDirectoryManager.clearAllTempFiles();
0727:                } catch (Exception ex) {
0728:                    System.out.println("!!!Error in Client Config!!!");
0729:                    ex.printStackTrace();
0730:                }
0731:                return instance;
0732:            }
0733:
0734:            /**
0735:             * Returns the addedColor.
0736:             * @return Color
0737:             */
0738:            public Color getAddedColor() {
0739:                return addedColor;
0740:            }
0741:
0742:            /**
0743:             * Returns the defaultEndOfLine.
0744:             * @return char[]
0745:             */
0746:            public char[] getDefaultEndOfLine() {
0747:                return defaultEndOfLine;
0748:            }
0749:
0750:            /**
0751:             * Returns the defaultEOLType.
0752:             * @return int
0753:             */
0754:            public int getDefaultEOLType() {
0755:                return defaultEOLType;
0756:            }
0757:
0758:            /**
0759:             * Returns the defaultFileType.
0760:             * @return int
0761:             */
0762:            public int getDefaultFileType() {
0763:                return defaultFileType;
0764:            }
0765:
0766:            /**
0767:             * Returns the deletedColor.
0768:             * @return Color
0769:             */
0770:            public Color getDeletedColor() {
0771:                return deletedColor;
0772:            }
0773:
0774:            /**
0775:             * Returns the displayTextPropertiesFileName.
0776:             * @return String
0777:             */
0778:            public String getDisplayTextPropertiesFileName() {
0779:                return displayTextPropertiesFileName;
0780:            }
0781:
0782:            /**
0783:             * Returns the fileDialogType.
0784:             * @return String
0785:             */
0786:            public String getFileDialogType() {
0787:                return fileDialogType;
0788:            }
0789:
0790:            /**
0791:             * Returns the filePool.
0792:             * @return FileEventListenerPluginPool
0793:             */
0794:            public FileEventListenerPluginPool getFilePool() {
0795:                return filePool;
0796:            }
0797:
0798:            /**
0799:             * Returns the hideFileCommand.
0800:             * @return String[]
0801:             */
0802:            public String[] getHideFileCommand() {
0803:                return hideFileCommand;
0804:            }
0805:
0806:            /**
0807:             * Returns the initialLookAndFeel.
0808:             * @return String
0809:             */
0810:            public String getInitialLookAndFeel() {
0811:                return initialLookAndFeel;
0812:            }
0813:
0814:            /**
0815:             * Returns the makeWritableCommand.
0816:             * @return String[]
0817:             */
0818:            public String[] getMakeWritableCommand() {
0819:                return makeWritableCommand;
0820:            }
0821:
0822:            /**
0823:             * Returns the maxFileSendChunkSize.
0824:             * @return int
0825:             */
0826:            public int getMaxFileSendChunkSize() {
0827:                return maxFileSendChunkSize;
0828:            }
0829:
0830:            /**
0831:             * Returns the modifiedColor.
0832:             * @return Color
0833:             */
0834:            public Color getModifiedColor() {
0835:                return modifiedColor;
0836:            }
0837:
0838:            /**
0839:             * Returns the monoFont.
0840:             * @return Font
0841:             */
0842:            public Font getMonoFont() {
0843:                return monoFont;
0844:            }
0845:
0846:            /**
0847:             * Returns the notInArchiveColor.
0848:             * @return Color
0849:             */
0850:            public Color getNotInArchiveColor() {
0851:                return notInArchiveColor;
0852:            }
0853:
0854:            /**
0855:             * Returns the notInLocalColor.
0856:             * @return Color
0857:             */
0858:            public Color getNotInLocalColor() {
0859:                return notInLocalColor;
0860:            }
0861:
0862:            /**
0863:             * Returns the notInSyncColor.
0864:             * @return Color
0865:             */
0866:            public Color getNotInSyncColor() {
0867:                return notInSyncColor;
0868:            }
0869:
0870:            /**
0871:             * Returns the onAddFileAction.
0872:             * @return String
0873:             */
0874:            public String getOnAddFileAction() {
0875:                return onAddFileAction;
0876:            }
0877:
0878:            /**
0879:             * Returns the onCheckInFileAction.
0880:             * @return String
0881:             */
0882:            public String getOnCheckInFileAction() {
0883:                return onCheckInFileAction;
0884:            }
0885:
0886:            /**
0887:             * Returns the onFileModifiedOnCheckin.
0888:             * @return String
0889:             */
0890:            public String getOnFileModifiedOnCheckin() {
0891:                return onFileModifiedOnCheckin;
0892:            }
0893:
0894:            /**
0895:             * Returns the onGetFileAction.
0896:             * @return String
0897:             */
0898:            public String getOnGetFileAction() {
0899:                return onGetFileAction;
0900:            }
0901:
0902:            /**
0903:             * Returns the showFileCommand.
0904:             * @return String[]
0905:             */
0906:            public String[] getShowFileCommand() {
0907:                return showFileCommand;
0908:            }
0909:
0910:            /**
0911:             * Returns the tabSize.
0912:             * @return int
0913:             */
0914:            public int getTabSize() {
0915:                return tabSize;
0916:            }
0917:
0918:            /**
0919:             * Returns the zipIfLargerThan.
0920:             * @return int
0921:             */
0922:            public int getZipIfLargerThan() {
0923:                return zipIfLargerThan;
0924:            }
0925:
0926:            /**
0927:             * Sets the addedColor.
0928:             * @param addedColor The addedColor to set
0929:             */
0930:            public void setAddedColor(Color addedColor) {
0931:                this .addedColor = addedColor;
0932:            }
0933:
0934:            /**
0935:             * Sets the defaultEndOfLine.
0936:             * @param defaultEndOfLine The defaultEndOfLine to set
0937:             */
0938:            public void setDefaultEndOfLine(char[] defaultEndOfLine) {
0939:                this .defaultEndOfLine = defaultEndOfLine;
0940:            }
0941:
0942:            /**
0943:             * Sets the defaultEOLType.
0944:             * @param defaultEOLType The defaultEOLType to set
0945:             */
0946:            public void setDefaultEOLType(int defaultEOLType) {
0947:                this .defaultEOLType = defaultEOLType;
0948:            }
0949:
0950:            /**
0951:             * Sets the defaultFileType.
0952:             * @param defaultFileType The defaultFileType to set
0953:             */
0954:            public void setDefaultFileType(int defaultFileType) {
0955:                this .defaultFileType = defaultFileType;
0956:            }
0957:
0958:            /**
0959:             * Sets the deletedColor.
0960:             * @param deletedColor The deletedColor to set
0961:             */
0962:            public void setDeletedColor(Color deletedColor) {
0963:                this .deletedColor = deletedColor;
0964:            }
0965:
0966:            /**
0967:             * Sets the displayTextPropertiesFileName.
0968:             * @param displayTextPropertiesFileName The displayTextPropertiesFileName to set
0969:             */
0970:            public void setDisplayTextPropertiesFileName(
0971:                    String displayTextPropertiesFileName) {
0972:                this .displayTextPropertiesFileName = displayTextPropertiesFileName;
0973:            }
0974:
0975:            /**
0976:             * Sets the fileDialogType.
0977:             * @param fileDialogType The fileDialogType to set
0978:             */
0979:            public void setFileDialogType(String fileDialogType) {
0980:                this .fileDialogType = fileDialogType;
0981:            }
0982:
0983:            /**
0984:             * Sets the filePool.
0985:             * @param filePool The filePool to set
0986:             */
0987:            public void setFilePool(FileEventListenerPluginPool filePool) {
0988:                this .filePool = filePool;
0989:            }
0990:
0991:            /**
0992:             * Sets the hideFileCommand.
0993:             * @param hideFileCommand The hideFileCommand to set
0994:             */
0995:            public void setHideFileCommand(String[] hideFileCommand) {
0996:                this .hideFileCommand = hideFileCommand;
0997:            }
0998:
0999:            /**
1000:             * Sets the initialLookAndFeel.
1001:             * @param initialLookAndFeel The initialLookAndFeel to set
1002:             */
1003:            public void setInitialLookAndFeel(String initialLookAndFeel) {
1004:                this .initialLookAndFeel = initialLookAndFeel;
1005:            }
1006:
1007:            /**
1008:             * Sets the keyStoreFile.
1009:             * @param keyStoreFile The keyStoreFile to set
1010:             */
1011:            public void setKeyStoreFile(String keyStoreFile) {
1012:                this .keyStoreFile = keyStoreFile;
1013:            }
1014:
1015:            /**
1016:             * Sets the makeWritableCommand.
1017:             * @param makeWritableCommand The makeWritableCommand to set
1018:             */
1019:            public void setMakeWritableCommand(String[] makeWritableCommand) {
1020:                this .makeWritableCommand = makeWritableCommand;
1021:            }
1022:
1023:            /**
1024:             * Sets the maxFileSendChunkSize.
1025:             * @param maxFileSendChunkSize The maxFileSendChunkSize to set
1026:             */
1027:            public void setMaxFileSendChunkSize(int maxFileSendChunkSize) {
1028:                this .maxFileSendChunkSize = maxFileSendChunkSize;
1029:            }
1030:
1031:            /**
1032:             * Sets the modifiedColor.
1033:             * @param modifiedColor The modifiedColor to set
1034:             */
1035:            public void setModifiedColor(Color modifiedColor) {
1036:                this .modifiedColor = modifiedColor;
1037:            }
1038:
1039:            /**
1040:             * Sets the monoFont.
1041:             * @param monoFont The monoFont to set
1042:             */
1043:            public void setMonoFont(Font monoFont) {
1044:                this .monoFont = monoFont;
1045:            }
1046:
1047:            /**
1048:             * Sets the notInArchiveColor.
1049:             * @param notInArchiveColor The notInArchiveColor to set
1050:             */
1051:            public void setNotInArchiveColor(Color notInArchiveColor) {
1052:                this .notInArchiveColor = notInArchiveColor;
1053:            }
1054:
1055:            /**
1056:             * Sets the notInLocalColor.
1057:             * @param notInLocalColor The notInLocalColor to set
1058:             */
1059:            public void setNotInLocalColor(Color notInLocalColor) {
1060:                this .notInLocalColor = notInLocalColor;
1061:            }
1062:
1063:            /**
1064:             * Sets the notInSyncColor.
1065:             * @param notInSyncColor The notInSyncColor to set
1066:             */
1067:            public void setNotInSyncColor(Color notInSyncColor) {
1068:                this .notInSyncColor = notInSyncColor;
1069:            }
1070:
1071:            /**
1072:             * Sets the onAddFileAction.
1073:             * @param onAddFileAction The onAddFileAction to set
1074:             */
1075:            public void setOnAddFileAction(String onAddFileAction) {
1076:                this .onAddFileAction = onAddFileAction;
1077:            }
1078:
1079:            /**
1080:             * Sets the onCheckInFileAction.
1081:             * @param onCheckInFileAction The onCheckInFileAction to set
1082:             */
1083:            public void setOnCheckInFileAction(String onCheckInFileAction) {
1084:                this .onCheckInFileAction = onCheckInFileAction;
1085:            }
1086:
1087:            /**
1088:             * Sets the onFileModifiedOnCheckin.
1089:             * @param onFileModifiedOnCheckin The onFileModifiedOnCheckin to set
1090:             */
1091:            public void setOnFileModifiedOnCheckin(
1092:                    String onFileModifiedOnCheckin) {
1093:                this .onFileModifiedOnCheckin = onFileModifiedOnCheckin;
1094:            }
1095:
1096:            /**
1097:             * Sets the onGetFileAction.
1098:             * @param onGetFileAction The onGetFileAction to set
1099:             */
1100:            public void setOnGetFileAction(String onGetFileAction) {
1101:                this .onGetFileAction = onGetFileAction;
1102:            }
1103:
1104:            /**
1105:             * Sets the showFileCommand.
1106:             * @param showFileCommand The showFileCommand to set
1107:             */
1108:            public void setShowFileCommand(String[] showFileCommand) {
1109:                this .showFileCommand = showFileCommand;
1110:            }
1111:
1112:            /**
1113:             * Sets the tabSize.
1114:             * @param tabSize The tabSize to set
1115:             */
1116:            public void setTabSize(int tabSize) {
1117:                this .tabSize = tabSize;
1118:            }
1119:
1120:            /**
1121:             * Sets the zipIfLargerThan.
1122:             * @param zipIfLargerThan The zipIfLargerThan to set
1123:             */
1124:            public void setZipIfLargerThan(int zipIfLargerThan) {
1125:                this.zipIfLargerThan = zipIfLargerThan;
1126:            }
1127:
1128:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.