Source Code Cross Referenced for RepositoryFinder.java in  » Web-Server » Jigsaw » org » w3c » tools » offline » browse » 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 » Web Server » Jigsaw » org.w3c.tools.offline.browse 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // RepositoryFinder.java
002:        // $Id: RepositoryFinder.java,v 1.6 2002/02/04 17:28:12 cbournez Exp $
003:        // (c) COPYRIGHT MIT and INRIA, 2002.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.tools.offline.browse;
007:
008:        import org.w3c.tools.resources.serialization.Serializer;
009:        import org.w3c.tools.resources.Resource;
010:        import org.w3c.tools.resources.serialization.ResourceDescription;
011:        import org.w3c.tools.resources.serialization.AttributeDescription;
012:        import org.w3c.tools.resources.serialization.xml.XMLSerializer;
013:
014:        import org.w3c.tools.resources.AttributeHolder;
015:
016:        import java.io.BufferedReader;
017:        import java.io.BufferedWriter;
018:        import java.io.File;
019:        import java.io.FileReader;
020:        import java.io.FileWriter;
021:        import java.io.FilenameFilter;
022:        import java.io.IOException;
023:        import java.io.InputStream;
024:        import java.io.ObjectInputStream;
025:        import java.io.PrintStream;
026:        import java.io.Reader;
027:        import java.io.Serializable;
028:        import java.io.Writer;
029:
030:        import org.apache.oro.text.regex.Perl5Matcher;
031:        import org.apache.oro.text.regex.Perl5Compiler;
032:        import org.apache.oro.text.regex.Pattern;
033:        import org.apache.oro.text.regex.MalformedPatternException;
034:
035:        import java.util.Hashtable;
036:
037:        /**
038:         * <p>The finder that handles a given repository file.
039:         */
040:
041:        public class RepositoryFinder {
042:
043:            /** 
044:             * The relative directory name of the repository in the store 
045:             */
046:            protected String repository_dir = null;
047:
048:            /** 
049:             * The repository name in the repository directory 
050:             */
051:            protected String repository_name = null;
052:
053:            /** 
054:             * The store directory (relative to current path)
055:             */
056:            protected String store_dir = null;
057:
058:            /** 
059:             *  A resource lister instance that handles the repository resources
060:             */
061:            protected ResourceLister rl = null;
062:
063:            protected File file = null;
064:            protected Serializer serializer = null;
065:            private Hashtable containers = null;
066:            private AttributeHolder[] holders = null;
067:            private Reader reader = null;
068:            private Writer writer = null;
069:
070:            protected static Perl5Matcher pmatcher = new Perl5Matcher();
071:            protected static Perl5Compiler pcompiler = new Perl5Compiler();
072:
073:            /** 
074:             *  Initializes the finder.
075:             *  opens the file in the right directory, adds a resource lister 
076:             *  and a XML serializer, finds the containers.
077:             * @param storedir the store directory path
078:             * @param repname the repository filename.
079:             */
080:            public RepositoryFinder(String storedir, String repname)
081:                    throws InvalidStoreException {
082:
083:                //		System.out.println("I am repository finder for" +repname);
084:                int slash = repname.indexOf('/', 0);
085:                if (slash != -1) {
086:                    this .repository_dir = repname.substring(0, slash);
087:                    this .repository_name = repname.substring(slash + 1, repname
088:                            .length());
089:                } else {
090:                    this .repository_dir = "";
091:                    this .repository_name = repname;
092:                }
093:                this .store_dir = storedir;
094:                this .rl = new ResourceLister();
095:                this .containers = new Hashtable();
096:
097:                serializer = new org.w3c.tools.resources.serialization.xml.XMLSerializer();
098:                File file = new File(store_dir + "/" + repository_dir,
099:                        repository_name);
100:                // System.out.println("reading repository "+repository_name+"...\n");
101:
102:                try {
103:                    this .reader = new BufferedReader(new FileReader(file));
104:                    this .holders = serializer.readAttributeHolders(reader);
105:                    for (int i = 0; i < holders.length; i++) {
106:                        // rl.printAttributeHolder(holders[i]);
107:                        if (rl.getKeyFromHolder(holders[i]) != null) {
108:                            // store containers in a dedicated hashtable with key 
109:                            containers.put(rl.getKeyFromHolder(holders[i]),
110:                                    holders[i]);
111:                        }
112:                    }
113:                } catch (IOException ex) {
114:                    System.out.println("Unable to read repository");
115:                    throw new InvalidStoreException("inexistent repository");
116:                }
117:            }
118:
119:            /**
120:             * find a given resource
121:             * @param identifier the name of the resource to find
122:             * @return an AttributeHolder.
123:             */
124:            public AttributeHolder getAttributeHolder(String identifier) {
125:                for (int i = 0; i < holders.length; i++) {
126:                    if (rl.getIdentFromHolder(holders[i]).compareTo(identifier) == 0) {
127:                        return holders[i];
128:                    }
129:                }
130:                return null;
131:            }
132:
133:            public AttributeHolder[] getAttributeHolders() {
134:                return holders;
135:            }
136:
137:            public String getRep() {
138:                return (repository_dir + "/" + repository_name);
139:            }
140:
141:            /**
142:             * write changes into a tmp file and then commit to the real file 
143:             */
144:            public void writeHolders() {
145:                File tmp = new File(store_dir + "/" + repository_dir,
146:                        repository_name + ".tmp");
147:                File bak = new File(store_dir + "/" + repository_dir,
148:                        repository_name + ".bak");
149:
150:                File orig = new File(store_dir + "/" + repository_dir,
151:                        repository_name);
152:
153:                try {
154:                    this .writer = new BufferedWriter(new FileWriter(tmp));
155:                    //	this.writer	= new OutputStreamWriter( out );
156:                } catch (Exception ex) {
157:                    ex.printStackTrace();
158:                    throw new RuntimeException(
159:                            "Unable to open temp rep for write");
160:                }
161:                try {
162:                    serializer.writeResources(holders, writer);
163:                } catch (Exception ex) {
164:                    ex.printStackTrace();
165:                    throw new RuntimeException("Unable to write repository");
166:                }
167:
168:                if (!orig.renameTo(bak)) {
169:                    System.out.println("unable to rename " + orig + " to "
170:                            + bak);
171:                } else {
172:                    if (!tmp.renameTo(orig)) {
173:                        bak.renameTo(orig);
174:                        System.out.println("unable to rename " + tmp + " to "
175:                                + orig);
176:                    } else {
177:                        // System.out.println("Repository saved");
178:                    }
179:                }
180:
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.