Source Code Cross Referenced for LocalVersioningFileSystem.java in  » Content-Management-System » harmonise » org » openharmonise » localversioningfilesystem » 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 » Content Management System » harmonise » org.openharmonise.localversioningfilesystem 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * The contents of this file are subject to the 
0003:         * Mozilla Public License Version 1.1 (the "License"); 
0004:         * you may not use this file except in compliance with the License. 
0005:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
0006:         *
0007:         * Software distributed under the License is distributed on an "AS IS"
0008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
0009:         * See the License for the specific language governing rights and 
0010:         * limitations under the License.
0011:         *
0012:         * The Initial Developer of the Original Code is Simulacra Media Ltd.
0013:         * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
0014:         *
0015:         * All Rights Reserved.
0016:         *
0017:         * Contributor(s):
0018:         */
0019:        package org.openharmonise.localversioningfilesystem;
0020:
0021:        import java.io.*;
0022:        import java.net.*;
0023:        import java.util.*;
0024:
0025:        import javax.xml.parsers.*;
0026:
0027:        import org.openharmonise.commons.xml.*;
0028:        import org.openharmonise.commons.xml.namespace.*;
0029:        import org.openharmonise.localversioningfilesystem.value.*;
0030:        import org.openharmonise.vfs.*;
0031:        import org.openharmonise.vfs.authentication.*;
0032:        import org.openharmonise.vfs.metadata.*;
0033:        import org.openharmonise.vfs.metadata.range.*;
0034:        import org.openharmonise.vfs.search.*;
0035:        import org.openharmonise.vfs.status.*;
0036:        import org.w3c.dom.*;
0037:        import org.xml.sax.*;
0038:
0039:        /**
0040:         * 
0041:         * @author Matthew Large
0042:         * @version $Revision: 1.2 $
0043:         *
0044:         */
0045:        public class LocalVersioningFileSystem extends AbstractVersioningVFS {
0046:
0047:            private VirtualFileCache m_cache = null;
0048:
0049:            private VirtualFileSystemView m_vfView = null;
0050:
0051:            /**
0052:             * @param uri
0053:             * @param sPathSeparator
0054:             */
0055:            public LocalVersioningFileSystem(URI uri) {
0056:                super (uri);
0057:                this .setup();
0058:            }
0059:
0060:            /**
0061:             * @param uri
0062:             * @param authInfo
0063:             * @param sPathSeparator
0064:             */
0065:            public LocalVersioningFileSystem(URI uri, AuthInfo authInfo) {
0066:                super (uri, authInfo);
0067:                this .setup();
0068:            }
0069:
0070:            /**
0071:             * @param uri
0072:             * @param authStore
0073:             * @param sPathSeparator
0074:             */
0075:            public LocalVersioningFileSystem(URI uri,
0076:                    AbstractAuthenticationStore authStore) {
0077:                super (uri, authStore);
0078:                this .setup();
0079:            }
0080:
0081:            private void setup() {
0082:                this .m_sInitialPath = this .m_sInitialPath.substring(1,
0083:                        this .m_sInitialPath.length());
0084:
0085:                this .m_sInitialPath = this .m_sInitialPath.replace('/', '\\');
0086:                this .m_cache = new VirtualFileCache();
0087:            }
0088:
0089:            /* (non-Javadoc)
0090:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getOptions()
0091:             */
0092:            public List getOptions() {
0093:                return null;
0094:            }
0095:
0096:            /* (non-Javadoc)
0097:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getVirtualFile(java.lang.String)
0098:             */
0099:            public ResourceStatusWrapper getVirtualFile(String sFullPath) {
0100:                VirtualFile vfFile = null;
0101:
0102:                String sRealPath = this .getInitialPath() + sFullPath;
0103:                sRealPath = sRealPath.replace('/', File.separatorChar);
0104:
0105:                if (sFullPath != null && this .m_cache.hasFile(sFullPath)) {
0106:                    vfFile = this .m_cache.getFile(sFullPath);
0107:                } else if (sFullPath != null) {
0108:                    vfFile = new VersionedVirtualFile(sFullPath);
0109:                    vfFile.setVFS(this );
0110:                    File fRealFile = new File(sRealPath);
0111:                    this .populateVirtualFile(fRealFile, vfFile);
0112:                    this .m_cache.addFile(vfFile);
0113:                }
0114:
0115:                if (vfFile == null) {
0116:                    this .fireErrorEvent("FileNotFound", "The file " + sFullPath
0117:                            + " cannot be found.");
0118:                }
0119:
0120:                return new ResourceStatusWrapper(vfFile, new VFSStatus());
0121:            }
0122:
0123:            private void populateVirtualFile(File fRealFile, VirtualFile vfFile) {
0124:                vfFile.setIsDirectory(fRealFile.isDirectory());
0125:                if (vfFile.isDirectory()) {
0126:                    this .setOrderableDirectory(vfFile, true);
0127:                }
0128:
0129:                File[] children = fRealFile.listFiles();
0130:                if (children != null) {
0131:                    for (int i = 0; i < children.length; i++) {
0132:                        if (!children[i].getName().equals("CMHistory")
0133:                                && !children[i].getName().equals("CMPending")
0134:                                && !children[i].getName().equals("CMMetadata")
0135:                                && !children[i].getName().equals("CMOrder.xml")) {
0136:                            vfFile.addChild(vfFile.getFullPath() + "/"
0137:                                    + children[i].getName());
0138:                        }
0139:                    }
0140:                }
0141:                this .setFileChildrenPopulated(vfFile, true);
0142:                if (vfFile.isDirectory()) {
0143:                    this .orderChildren(vfFile);
0144:                }
0145:
0146:                if (!vfFile.getFilePath().equals("")) {
0147:                    VirtualFile vfParent = this .getVirtualFile(
0148:                            vfFile.getFilePath()).getResource();
0149:                    if (vfParent != null
0150:                            && vfParent.getFileName().equals("CMHistory")) {
0151:                        this .setFileState(vfFile, VirtualFile.STATE_HISTORICAL);
0152:                    }
0153:                }
0154:
0155:                File fPendingDir = new File(fRealFile.getParentFile()
0156:                        .getAbsolutePath()
0157:                        + File.separatorChar + "CMPending");
0158:                if (fPendingDir.exists() && fPendingDir.isDirectory()) {
0159:                    children = fPendingDir.listFiles();
0160:                    if (children != null) {
0161:                        for (int i = 0; i < children.length; i++) {
0162:                            if (children[i].getName().startsWith(
0163:                                    "p-" + fRealFile.getName())) {
0164:                                VersionedVirtualFile vfPending = (VersionedVirtualFile) this 
0165:                                        .getVirtualFile(
0166:                                                vfFile.getFilePath()
0167:                                                        + "/CMPending/"
0168:                                                        + children[i].getName())
0169:                                        .getResource();
0170:                                this .setFileState(vfPending,
0171:                                        VirtualFile.STATE_PENDING);
0172:                                this .setFileLiveVersionPath(
0173:                                        (VersionedVirtualFile) vfPending,
0174:                                        vfFile.getFullPath());
0175:                                this .setFilePendingVersionPath(
0176:                                        (VersionedVirtualFile) vfFile,
0177:                                        vfPending.getFullPath());
0178:                            } else if (children[i].getName().startsWith(
0179:                                    "n-" + fRealFile.getName())) {
0180:                                this .setFileState(vfFile,
0181:                                        VirtualFile.STATE_PENDING);
0182:                            }
0183:                        }
0184:                    }
0185:                } else if (!fPendingDir.exists()) {
0186:                    fPendingDir.mkdir();
0187:                }
0188:            }
0189:
0190:            /* (non-Javadoc)
0191:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#addVirtualFile(java.lang.String, com.simulacramedia.vfs.VirtualFile)
0192:             */
0193:            public ResourceStatusWrapper addVirtualFile(String sPath,
0194:                    VirtualFile content) {
0195:                VirtualFile vfFile = null;
0196:
0197:                String sFullPath = sPath + "/" + content.getFileName();
0198:
0199:                String sRealPath = this .getInitialPath() + sPath + "/"
0200:                        + content.getFileName();
0201:                sRealPath = sRealPath.replace('/', File.separatorChar);
0202:
0203:                if (this .m_cache.hasFile(sFullPath)) {
0204:                    // NO-OP
0205:                } else {
0206:                    File fRealFile = new File(sRealPath);
0207:                    try {
0208:                        FileOutputStream fos = new FileOutputStream(fRealFile);
0209:                        fos.write(content.getContent());
0210:                    } catch (FileNotFoundException e) {
0211:                        this 
0212:                                .fireErrorEvent(
0213:                                        "FileNotAdded",
0214:                                        "The file "
0215:                                                + sFullPath
0216:                                                + " cannot be added here, this might be because a file already exists here with the same name.");
0217:                        e.printStackTrace();
0218:                    } catch (IOException e) {
0219:                        this 
0220:                                .fireErrorEvent(
0221:                                        "FileNotAdded",
0222:                                        "The file "
0223:                                                + sFullPath
0224:                                                + " cannot be added here, this might be because a file already exists here with the same name.");
0225:                        e.printStackTrace();
0226:                    }
0227:                }
0228:
0229:                if (vfFile == null) {
0230:                    this 
0231:                            .fireErrorEvent(
0232:                                    "FileNotAdded",
0233:                                    "The file "
0234:                                            + sFullPath
0235:                                            + " cannot be added here, this might be because a file already exists here with the same name.");
0236:                }
0237:
0238:                return new ResourceStatusWrapper(vfFile, new VFSStatus());
0239:            }
0240:
0241:            /* (non-Javadoc)
0242:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#moveVirtualFile(java.lang.String, java.lang.String)
0243:             */
0244:            public StatusData moveVirtualFile(String sFromFullPath,
0245:                    String sToFullPath) {
0246:                VFSStatus retnStatus = new VFSStatus();
0247:
0248:                boolean bError = false;
0249:
0250:                String sRealFromPath = this .getInitialPath() + sFromFullPath;
0251:                sRealFromPath = sRealFromPath.replace('/', File.separatorChar);
0252:                String sRealToPath = this .getInitialPath() + sToFullPath;
0253:                sRealToPath = sRealToPath.replace('/', File.separatorChar);
0254:
0255:                VirtualFile vfFromFile = this .getVirtualFile(sFromFullPath)
0256:                        .getResource();
0257:                if (!vfFromFile.isDirectory()) {
0258:
0259:                    File from = new File(sRealFromPath);
0260:                    File to = new File(sRealToPath);
0261:
0262:                    bError = this .moveFile(from, to, true);
0263:                    if (!bError) {
0264:                        this .m_cache.removeFile(sFromFullPath);
0265:                    } else {
0266:                        this 
0267:                                .fireErrorEvent(
0268:                                        "FileNotMoved",
0269:                                        "The file "
0270:                                                + vfFromFile.getFullPath()
0271:                                                + " cannot be copied here, this might be because a file already exists here with the same name.");
0272:                    }
0273:                }
0274:
0275:                if (bError) {
0276:                    retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0277:                    retnStatus.setStatusCode(StatusData.STATUS_INVALID_REQUEST);
0278:                }
0279:
0280:                return retnStatus;
0281:            }
0282:
0283:            /* (non-Javadoc)
0284:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#copyVirtualFile(java.lang.String, java.lang.String)
0285:             */
0286:            public StatusData copyVirtualFile(String sFromFullPath,
0287:                    String sToFullPath) {
0288:                VFSStatus retnStatus = new VFSStatus();
0289:
0290:                boolean bError = false;
0291:
0292:                String sRealFromPath = this .getInitialPath() + sFromFullPath;
0293:                sRealFromPath = sRealFromPath.replace('/', File.separatorChar);
0294:                String sRealToPath = this .getInitialPath() + sToFullPath;
0295:                sRealToPath = sRealToPath.replace('/', File.separatorChar);
0296:
0297:                VirtualFile vfFromFile = this .getVirtualFile(sFromFullPath)
0298:                        .getResource();
0299:                if (!vfFromFile.isDirectory()) {
0300:                    File from = new File(sRealFromPath);
0301:                    File to = new File(sRealToPath);
0302:
0303:                    bError = this .moveFile(from, to, false);
0304:                    if (!bError) {
0305:                        this .m_cache.removeFile(sFromFullPath);
0306:                        this .m_cache.removeFile(this 
0307:                                .getParentPath(sFromFullPath));
0308:                        this .m_cache
0309:                                .removeFile(this .getParentPath(sToFullPath));
0310:                    } else {
0311:                        this 
0312:                                .fireErrorEvent(
0313:                                        "FileNotCopied",
0314:                                        "The file "
0315:                                                + vfFromFile.getFullPath()
0316:                                                + " cannot be copied here, this might be because a file already exists here with the same name.");
0317:                    }
0318:                }
0319:
0320:                if (bError) {
0321:                    retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0322:                    retnStatus.setStatusCode(StatusData.STATUS_INVALID_REQUEST);
0323:                }
0324:
0325:                return retnStatus;
0326:            }
0327:
0328:            private File getMetadataDir(File file) {
0329:                File fDir = new File(file.getParentFile().getAbsolutePath()
0330:                        + File.separatorChar + "CMMetadata");
0331:                if (!fDir.exists()) {
0332:                    fDir.mkdir();
0333:                }
0334:                return fDir;
0335:            }
0336:
0337:            private File getMetadataFile(File file) {
0338:                File fRetn = new File(this .getMetadataDir(file)
0339:                        .getAbsolutePath()
0340:                        + File.separatorChar + file.getName());
0341:
0342:                File fMetadataDir = this .getMetadataDir(file);
0343:                File[] children = fMetadataDir.listFiles();
0344:                for (int i = 0; i < children.length; i++) {
0345:                    File file2 = children[i];
0346:                    if (file2.getName().equals(file.getName())) {
0347:                        fRetn = file2;
0348:                        break;
0349:                    }
0350:                }
0351:                return fRetn;
0352:            }
0353:
0354:            private File getRealFile(VirtualFile vfFile) {
0355:                String sRealPath = this .getInitialPath() + vfFile.getFullPath();
0356:                sRealPath = sRealPath.replace('/', File.separatorChar);
0357:
0358:                File file = new File(sRealPath);
0359:                if (file.exists()) {
0360:                    return file;
0361:                } else {
0362:                    return null;
0363:                }
0364:            }
0365:
0366:            private File getOrderFile(File file) {
0367:                File fOrderFile = new File(file.getAbsolutePath()
0368:                        + File.separatorChar + "CMOrder.xml");
0369:
0370:                if (!fOrderFile.exists()) {
0371:                    try {
0372:                        fOrderFile.createNewFile();
0373:                        Document xml = null;
0374:                        try {
0375:                            DocumentBuilderFactory factory = DocumentBuilderFactory
0376:                                    .newInstance();
0377:                            factory.setNamespaceAware(true);
0378:                            xml = factory.newDocumentBuilder().newDocument();
0379:                        } catch (FactoryConfigurationError e) {
0380:                            e.printStackTrace();
0381:                        } catch (ParserConfigurationException e) {
0382:                            e.printStackTrace();
0383:                        }
0384:
0385:                        Element rootEl = xml
0386:                                .createElementNS(
0387:                                        "http://www.simulacramedia.com/harmoniseclient/propinstances",
0388:                                        "Order");
0389:                        xml.appendChild(rootEl);
0390:                        XMLPrettyPrint printer = new XMLPrettyPrint();
0391:                        printer.setNamespaceAware(true);
0392:                        printer.printNodeToFile(rootEl, fOrderFile);
0393:                    } catch (IOException e1) {
0394:                        e1.printStackTrace();
0395:                    }
0396:
0397:                }
0398:
0399:                return fOrderFile;
0400:            }
0401:
0402:            private void orderChildren(VirtualFile vfDir) {
0403:                File fDir = this .getRealFile(vfDir);
0404:                File fOrderFile = this .getOrderFile(fDir);
0405:
0406:                Document m_xml;
0407:                try {
0408:                    m_xml = DocumentBuilderFactory.newInstance()
0409:                            .newDocumentBuilder().parse(
0410:                                    new org.xml.sax.InputSource(
0411:                                            new FileInputStream(fOrderFile)));
0412:
0413:                    Element rootEl = m_xml.getDocumentElement();
0414:
0415:                    NodeList nlProps = rootEl.getChildNodes();
0416:
0417:                    ArrayList aOrderedPaths = new ArrayList();
0418:
0419:                    for (int i = 0; i < nlProps.getLength(); i++) {
0420:                        Node node = nlProps.item(i);
0421:                        if (node.getNodeType() != Node.ELEMENT_NODE) {
0422:                            continue;
0423:                        } else {
0424:                            Element elChild = (Element) node;
0425:                            String sPath = elChild.getFirstChild()
0426:                                    .getNodeValue();
0427:                            aOrderedPaths.add(sPath);
0428:                        }
0429:                    }
0430:
0431:                    List children = vfDir.getChildren();
0432:                    if (children.containsAll(aOrderedPaths)
0433:                            && aOrderedPaths.containsAll(children)) {
0434:                        this .clearVirtualFileChildren(vfDir);
0435:                        for (Iterator iter = aOrderedPaths.iterator(); iter
0436:                                .hasNext();) {
0437:                            String element = (String) iter.next();
0438:                            vfDir.addChild(element);
0439:                        }
0440:                    }
0441:                } catch (FileNotFoundException e) {
0442:                    e.printStackTrace();
0443:                } catch (SAXException e) {
0444:                    e.printStackTrace();
0445:                } catch (IOException e) {
0446:                    e.printStackTrace();
0447:                } catch (ParserConfigurationException e) {
0448:                    e.printStackTrace();
0449:                } catch (FactoryConfigurationError e) {
0450:                    e.printStackTrace();
0451:                }
0452:            }
0453:
0454:            private File getHistoryDir(File file) {
0455:                File fDir = new File(file.getParentFile().getAbsolutePath()
0456:                        + File.separatorChar + "CMHistory");
0457:                if (!fDir.exists()) {
0458:                    fDir.mkdir();
0459:                }
0460:                return fDir;
0461:            }
0462:
0463:            private List getHistoryFiles(File file) {
0464:                ArrayList aFiles = new ArrayList();
0465:                File fHistoryDir = this .getHistoryDir(file);
0466:                File[] children = fHistoryDir.listFiles();
0467:                for (int i = 0; i < children.length; i++) {
0468:                    File file2 = children[i];
0469:                    if (file2.getName().startsWith(file.getName())) {
0470:                        aFiles.add(file2);
0471:                    }
0472:                }
0473:
0474:                return aFiles;
0475:            }
0476:
0477:            private File getPendingDir(File file) {
0478:                File fDir = new File(file.getParentFile().getAbsolutePath()
0479:                        + File.separatorChar + "CMPending");
0480:                if (!fDir.exists()) {
0481:                    fDir.mkdir();
0482:                }
0483:                return fDir;
0484:            }
0485:
0486:            private File getPendingFile(File file) {
0487:                File fRetn = new File(this .getPendingDir(file)
0488:                        .getAbsolutePath()
0489:                        + File.separatorChar + "p-" + file.getName());
0490:
0491:                File fPendingDir = this .getPendingDir(file);
0492:                File[] children = fPendingDir.listFiles();
0493:                for (int i = 0; i < children.length; i++) {
0494:                    File file2 = children[i];
0495:                    if (file2.getName().equals("p-" + file.getName())) {
0496:                        fRetn = file2;
0497:                        break;
0498:                    }
0499:                }
0500:                return fRetn;
0501:            }
0502:
0503:            private File getNewMarkerFile(File file) {
0504:                File fRetn = new File(this .getPendingDir(file)
0505:                        .getAbsolutePath()
0506:                        + File.separatorChar + "n-" + file.getName());
0507:
0508:                File fPendingDir = this .getPendingDir(file);
0509:                File[] children = fPendingDir.listFiles();
0510:                for (int i = 0; i < children.length; i++) {
0511:                    File file2 = children[i];
0512:                    if (file2.getName().equals("n-" + file.getName())) {
0513:                        fRetn = file2;
0514:                        break;
0515:                    }
0516:                }
0517:                return fRetn;
0518:            }
0519:
0520:            private boolean moveFile(File from, File to, boolean bDelete) {
0521:                boolean bError = false;
0522:
0523:                bError = this .moveRealFile(from, to, bDelete);
0524:
0525:                File fMetadataFromDir = new File(from.getParentFile()
0526:                        .getAbsolutePath()
0527:                        + File.separatorChar + "CMMetadata");
0528:                File fMetadataToDir = new File(to.getParentFile()
0529:                        .getAbsolutePath()
0530:                        + File.separatorChar + "CMMetadata");
0531:                if (fMetadataFromDir.exists()) {
0532:                    File fMetadataFromFile = new File(fMetadataFromDir
0533:                            .getAbsolutePath()
0534:                            + File.separatorChar + from.getName());
0535:                    if (fMetadataFromFile.exists()) {
0536:                        if (!fMetadataToDir.exists()) {
0537:                            fMetadataToDir.mkdir();
0538:                        }
0539:                        File fMetadataToFile = new File(fMetadataToDir
0540:                                .getAbsolutePath()
0541:                                + File.separatorChar + from.getName());
0542:                        boolean bErrTemp = this .moveRealFile(fMetadataFromFile,
0543:                                fMetadataToFile, bDelete);
0544:                        if (bErrTemp) {
0545:                            bError = true;
0546:                        }
0547:                    }
0548:                } else {
0549:                    fMetadataFromDir.mkdir();
0550:                }
0551:
0552:                File fPendingFromDir = new File(from.getParentFile()
0553:                        .getAbsolutePath()
0554:                        + File.separatorChar + "CMPending");
0555:                File fPendingToDir = new File(to.getParentFile()
0556:                        .getAbsolutePath()
0557:                        + File.separatorChar + "CMPending");
0558:                if (fPendingFromDir.exists()) {
0559:                    File fPendingFromFile = new File(fPendingFromDir
0560:                            .getAbsolutePath()
0561:                            + File.separatorChar + "p-" + from.getName());
0562:                    if (fPendingFromFile.exists()) {
0563:                        if (!fPendingToDir.exists()) {
0564:                            fPendingToDir.mkdir();
0565:                        }
0566:                        File fPendingToFile = new File(fPendingToDir
0567:                                .getAbsolutePath()
0568:                                + File.separatorChar + "p-" + from.getName());
0569:                        boolean bErrTemp = this .moveFile(fPendingFromFile,
0570:                                fPendingToFile, bDelete);
0571:                        if (bErrTemp) {
0572:                            bError = true;
0573:                        }
0574:                    }
0575:                    fPendingFromFile = new File(fPendingFromDir
0576:                            .getAbsolutePath()
0577:                            + File.separatorChar + "n-" + from.getName());
0578:                    if (fPendingFromFile.exists()) {
0579:                        if (!fPendingToDir.exists()) {
0580:                            fPendingToDir.mkdir();
0581:                        }
0582:                        File fPendingToFile = new File(fPendingToDir
0583:                                .getAbsolutePath()
0584:                                + File.separatorChar + "n-" + from.getName());
0585:                        boolean bErrTemp = this .moveFile(fPendingFromFile,
0586:                                fPendingToFile, bDelete);
0587:                        if (bErrTemp) {
0588:                            bError = true;
0589:                        }
0590:                    }
0591:                } else {
0592:                    fPendingFromDir.mkdir();
0593:                }
0594:
0595:                File fHistoryFromDir = new File(from.getParentFile()
0596:                        .getAbsolutePath()
0597:                        + File.separatorChar + "CMHistory");
0598:                File fHistoryToDir = new File(to.getParentFile()
0599:                        .getAbsolutePath()
0600:                        + File.separatorChar + "CMHistory");
0601:                if (fHistoryFromDir.exists()) {
0602:                    if (!fPendingToDir.exists()) {
0603:                        fPendingToDir.mkdir();
0604:                    }
0605:                    File[] children = fHistoryFromDir.listFiles();
0606:                    for (int i = 0; i < children.length; i++) {
0607:                        if (children[i].getName().startsWith(from.getName())) {
0608:                            File fHistoryToFile = new File(fHistoryToDir
0609:                                    .getAbsolutePath()
0610:                                    + File.separatorChar
0611:                                    + children[i].getName());
0612:                            this .moveFile(children[i], fHistoryToFile, bDelete);
0613:                        }
0614:                    }
0615:
0616:                } else {
0617:                    fHistoryFromDir.mkdir();
0618:                }
0619:
0620:                return bError;
0621:            }
0622:
0623:            private boolean moveRealFile(File from, File to, boolean bDelete) {
0624:                boolean bError = false;
0625:
0626:                FileInputStream fi = null;
0627:                FileOutputStream fo = null;
0628:
0629:                try {
0630:                    Long lLength = new Long(from.length());
0631:                    byte[] bytes = new byte[lLength.intValue()];
0632:                    fi = new FileInputStream(from);
0633:                    fo = new FileOutputStream(to);
0634:
0635:                    fi.read(bytes);
0636:                    fo.write(bytes);
0637:
0638:                } catch (Exception e) {
0639:                    e.printStackTrace(System.out);
0640:                    bError = true;
0641:                } finally {
0642:                    try {
0643:                        fo.close();
0644:                        fi.close();
0645:                    } catch (IOException ioe) {
0646:                        bError = true;
0647:                        ioe.printStackTrace(System.out);
0648:                    }
0649:                }
0650:
0651:                if (!bError && bDelete) {
0652:                    from.delete();
0653:                }
0654:
0655:                return bError;
0656:            }
0657:
0658:            /* (non-Javadoc)
0659:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#deleteVirtualFile(java.lang.String)
0660:             */
0661:            public StatusData deleteVirtualFile(String sFullPath) {
0662:                VFSStatus retnStatus = new VFSStatus();
0663:
0664:                boolean bError = false;
0665:
0666:                String sRealPath = this .getInitialPath() + sFullPath;
0667:                sRealPath = sRealPath.replace('/', File.separatorChar);
0668:
0669:                File fRealFile = new File(sRealPath);
0670:
0671:                bError = this .deleteRealFile(fRealFile);
0672:
0673:                if (bError) {
0674:                    this .fireErrorEvent("FileNotDeleted", "The file "
0675:                            + sFullPath + " cannot be deleted.");
0676:                } else {
0677:                    this .m_cache.removeFile(sFullPath);
0678:                }
0679:
0680:                if (bError) {
0681:                    retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0682:                    retnStatus.setStatusCode(StatusData.STATUS_INVALID_REQUEST);
0683:                }
0684:
0685:                return retnStatus;
0686:            }
0687:
0688:            private boolean deleteRealFile(File fRealFile) {
0689:                boolean bError = false;
0690:
0691:                File fMetadata = this .getMetadataFile(fRealFile);
0692:                if (fMetadata.exists()) {
0693:                    if (!fMetadata.delete()) {
0694:                        bError = true;
0695:                    }
0696:                }
0697:
0698:                if (!bError) {
0699:                    File fPending = this .getPendingFile(fRealFile);
0700:                    if (fPending.exists()) {
0701:                        if (this .deleteRealFile(fPending)) {
0702:                            bError = true;
0703:                        }
0704:                    }
0705:                }
0706:
0707:                if (!bError) {
0708:                    File fNew = this .getNewMarkerFile(fRealFile);
0709:                    if (fNew.exists()) {
0710:                        if (this .deleteRealFile(fNew)) {
0711:                            bError = true;
0712:                        }
0713:                    }
0714:                }
0715:
0716:                if (!bError) {
0717:                    List aHistory = this .getHistoryFiles(fRealFile);
0718:                    Iterator itor = aHistory.iterator();
0719:                    while (itor.hasNext()) {
0720:                        File element = (File) itor.next();
0721:                        if (this .deleteRealFile(element)) {
0722:                            bError = true;
0723:                            break;
0724:                        }
0725:                    }
0726:                }
0727:
0728:                if (!bError) {
0729:                    bError = !fRealFile.delete();
0730:                }
0731:
0732:                return bError;
0733:            }
0734:
0735:            /* (non-Javadoc)
0736:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#lockVirtualFile(java.lang.String)
0737:             */
0738:            public StatusData lockVirtualFile(String sFullPath) {
0739:                VFSStatus retnStatus = new VFSStatus();
0740:
0741:                String sRealPath = this .getInitialPath() + sFullPath;
0742:                sRealPath = sRealPath.replace('/', File.separatorChar);
0743:                this .fireErrorEvent("FileNotLocked",
0744:                        "This server does not support the locking of files.");
0745:                return retnStatus;
0746:            }
0747:
0748:            /* (non-Javadoc)
0749:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#unlockVirtualFile(java.lang.String)
0750:             */
0751:            public StatusData unlockVirtualFile(String sFullPath) {
0752:                VFSStatus retnStatus = new VFSStatus();
0753:
0754:                String sRealPath = this .getInitialPath() + sFullPath;
0755:                sRealPath = sRealPath.replace('/', File.separatorChar);
0756:                this .fireErrorEvent("FileNotUnlocked",
0757:                        "This server does not support the locking of files.");
0758:                return retnStatus;
0759:            }
0760:
0761:            /* (non-Javadoc)
0762:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#createVirtualDirectory(java.lang.String)
0763:             */
0764:            public StatusData createVirtualDirectory(String sFullPath) {
0765:                VFSStatus retnStatus = new VFSStatus();
0766:
0767:                boolean bError = false;
0768:
0769:                String sRealPath = this .getInitialPath() + sFullPath;
0770:                sRealPath = sRealPath.replace('/', File.separatorChar);
0771:
0772:                File fRealDir = new File(sRealPath);
0773:
0774:                bError = fRealDir.mkdirs();
0775:
0776:                if (!bError) {
0777:                    this .fireErrorEvent("DirectoryNotCreated", "The directory "
0778:                            + sFullPath + " cannot be created.");
0779:                }
0780:
0781:                if (bError) {
0782:                    retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
0783:                    retnStatus.setStatusCode(StatusData.STATUS_INVALID_REQUEST);
0784:                }
0785:
0786:                return retnStatus;
0787:            }
0788:
0789:            /* (non-Javadoc)
0790:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#createShortcut(java.lang.String, java.lang.String)
0791:             */
0792:            public StatusData createShortcut(String sFullPath,
0793:                    String sToFullPath) {
0794:                VFSStatus retnStatus = new VFSStatus();
0795:
0796:                String sRealPath = this .getInitialPath() + sFullPath;
0797:                sRealPath = sRealPath.replace('/', File.separatorChar);
0798:                String sRealToPath = this .getInitialPath() + sToFullPath;
0799:                sRealToPath = sRealToPath.replace('/', File.separatorChar);
0800:                this .fireErrorEvent("ShortcutNotCreted",
0801:                        "This server does not support shortcuts.");
0802:                return retnStatus;
0803:            }
0804:
0805:            /* (non-Javadoc)
0806:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#search(com.simulacramedia.vfs.search.Query)
0807:             */
0808:            public ResourceListStatusWrapper search(Query query) {
0809:                return null;
0810:            }
0811:
0812:            /* (non-Javadoc)
0813:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getVirtualFileSystemView()
0814:             */
0815:            public VirtualFileSystemView getVirtualFileSystemView() {
0816:                if (this .m_vfView == null) {
0817:                    this .m_vfView = (VirtualFileSystemView) new LocalVersioningFileSystemView();
0818:                }
0819:
0820:                return this .m_vfView;
0821:            }
0822:
0823:            /* (non-Javadoc)
0824:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getVirtualFileContent(java.lang.String)
0825:             */
0826:            public byte[] getVirtualFileContent(String sFullPath) {
0827:                boolean bError = false;
0828:
0829:                String sRealPath = this .getInitialPath() + sFullPath;
0830:                sRealPath = sRealPath.replace('/', File.separatorChar);
0831:
0832:                byte[] content = null;
0833:
0834:                File from = new File(sRealPath);
0835:                FileInputStream fi = null;
0836:
0837:                try {
0838:                    Long lLength = new Long(from.length());
0839:                    content = new byte[lLength.intValue()];
0840:                    fi = new FileInputStream(from);
0841:
0842:                    fi.read(content);
0843:                    this .setFileContentPopulated(this .m_cache
0844:                            .getFile(sFullPath), true);
0845:
0846:                } catch (Exception e) {
0847:                    e.printStackTrace(System.out);
0848:                    this .fireErrorEvent("ContentNotRetrieved",
0849:                            "The content for " + sFullPath
0850:                                    + " could not be retrieved.");
0851:                    bError = true;
0852:                } finally {
0853:                    try {
0854:                        fi.close();
0855:                    } catch (IOException ioe) {
0856:                        this .fireErrorEvent("ContentNotRetrieved",
0857:                                "The content for " + sFullPath
0858:                                        + " could not be retrieved.");
0859:                        bError = true;
0860:                        ioe.printStackTrace(System.out);
0861:                    }
0862:                }
0863:
0864:                return content;
0865:            }
0866:
0867:            /* (non-Javadoc)
0868:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#fullyPopulateFileMetadata(com.simulacramedia.vfs.VirtualFile)
0869:             */
0870:            protected void fullyPopulateFileMetadata(VirtualFile vfFile) {
0871:                String sRealPath = this .getInitialPath() + vfFile.getFullPath();
0872:                sRealPath = sRealPath.replace('/', File.separatorChar);
0873:
0874:                File fRealFile = new File(sRealPath);
0875:
0876:                File fMetadataDir = new File(fRealFile.getParentFile()
0877:                        .getAbsolutePath()
0878:                        + File.separatorChar + "CMMetadata");
0879:
0880:                if (fMetadataDir.exists()
0881:                        && Arrays.asList(fMetadataDir.list()).contains(
0882:                                fRealFile.getName())) {
0883:
0884:                    File fMetadata = new File(fRealFile.getParentFile()
0885:                            .getAbsolutePath()
0886:                            + File.separatorChar
0887:                            + "CMMetadata"
0888:                            + File.separatorChar + fRealFile.getName());
0889:
0890:                    Document m_xml;
0891:                    try {
0892:                        m_xml = DocumentBuilderFactory
0893:                                .newInstance()
0894:                                .newDocumentBuilder()
0895:                                .parse(
0896:                                        new org.xml.sax.InputSource(
0897:                                                new FileInputStream(fMetadata)));
0898:
0899:                        Element rootEl = m_xml.getDocumentElement();
0900:
0901:                        NodeList nlProps = rootEl.getChildNodes();
0902:
0903:                        for (int i = 0; i < nlProps.getLength(); i++) {
0904:                            Node node = nlProps.item(i);
0905:                            if (node.getNodeType() != Node.ELEMENT_NODE) {
0906:                                continue;
0907:                            } else {
0908:                                Element propEl = (Element) node;
0909:                                String sPropName = propEl.getAttribute("name");
0910:                                String sPropNamespace = propEl
0911:                                        .getAttribute("namespace");
0912:
0913:                                PropertyInstance propInst = new PropertyInstance(
0914:                                        sPropNamespace, sPropName);
0915:
0916:                                ArrayList vVals = new ArrayList();
0917:
0918:                                NodeList nlVals = propEl.getChildNodes();
0919:                                for (int j = 0; j < nlVals.getLength(); j++) {
0920:                                    Node node2 = nlVals.item(j);
0921:                                    if (node2.getNodeType() != Node.ELEMENT_NODE) {
0922:                                        continue;
0923:                                    } else {
0924:                                        Element valEl = (Element) node2;
0925:                                        vVals.add(valEl.getFirstChild()
0926:                                                .getNodeValue());
0927:                                    }
0928:                                }
0929:
0930:                                propInst.setValues(vVals);
0931:
0932:                                vfFile.addProperty(propInst);
0933:                            }
0934:                        }
0935:                    } catch (FileNotFoundException e) {
0936:                        e.printStackTrace();
0937:                    } catch (SAXException e) {
0938:                        e.printStackTrace();
0939:                    } catch (IOException e) {
0940:                        e.printStackTrace();
0941:                    } catch (ParserConfigurationException e) {
0942:                        e.printStackTrace();
0943:                    } catch (FactoryConfigurationError e) {
0944:                        e.printStackTrace();
0945:                    }
0946:
0947:                } else if (!fMetadataDir.exists()) {
0948:                    fMetadataDir.mkdir();
0949:                }
0950:
0951:                this .setFileMetadataPopulated(vfFile, true);
0952:
0953:                if (vfFile.getFullPath().indexOf("/Properties/") > -1
0954:                        && vfFile.getProperty(NamespaceType.OHRM.getURI(),
0955:                                "domain") == null) {
0956:
0957:                }
0958:            }
0959:
0960:            /* (non-Javadoc)
0961:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#fullyPopulateFileChildren(com.simulacramedia.vfs.VirtualFile)
0962:             */
0963:            protected void fullyPopulateFileChildren(VirtualFile vfFile) {
0964:                if (vfFile.isDirectory()) {
0965:                    String sRealPath = this .getInitialPath()
0966:                            + vfFile.getFullPath();
0967:                    sRealPath = sRealPath.replace('/', File.separatorChar);
0968:
0969:                    File fRealFile = new File(sRealPath);
0970:
0971:                    File[] children = fRealFile.listFiles();
0972:                    if (children != null) {
0973:                        for (int i = 0; i < children.length; i++) {
0974:                            if (!children[i].getName().equals("CMHistory")
0975:                                    && !children[i].getName().equals(
0976:                                            "CMPending")
0977:                                    && !children[i].getName().equals(
0978:                                            "CMMetadata")
0979:                                    && !children[i].getName().equals(
0980:                                            "CMOrder.xml")) {
0981:                                vfFile.addChild(vfFile.getFullPath() + "/"
0982:                                        + children[i].getName());
0983:                            }
0984:                        }
0985:                    }
0986:                    this .setFileChildrenPopulated(vfFile, true);
0987:                    if (vfFile.isDirectory()) {
0988:                        this .orderChildren(vfFile);
0989:                    }
0990:                }
0991:            }
0992:
0993:            private Document generatePropertyXML(VirtualFile vfFile) {
0994:                Document xml = null;
0995:                try {
0996:                    DocumentBuilderFactory factory = DocumentBuilderFactory
0997:                            .newInstance();
0998:                    factory.setNamespaceAware(true);
0999:                    xml = factory.newDocumentBuilder().newDocument();
1000:                } catch (FactoryConfigurationError e) {
1001:                    e.printStackTrace();
1002:                } catch (ParserConfigurationException e) {
1003:                    e.printStackTrace();
1004:                }
1005:
1006:                Element rootEl = xml
1007:                        .createElementNS(
1008:                                "http://www.simulacramedia.com/harmoniseclient/propinstances",
1009:                                "Properties");
1010:                xml.appendChild(rootEl);
1011:
1012:                Iterator itor = vfFile.getProperties().iterator();
1013:                while (itor.hasNext()) {
1014:                    PropertyInstance propInst = (PropertyInstance) itor.next();
1015:                    if (!propInst.getName().equals("datemodified")
1016:                            && !propInst.getName().equals("filesize")) {
1017:                        rootEl.appendChild(this .generatePropXML(xml, propInst));
1018:                    }
1019:                }
1020:
1021:                return xml;
1022:            }
1023:
1024:            /**
1025:             * @param xml
1026:             * @param propInst
1027:             * @return
1028:             */
1029:            private Node generatePropXML(Document xml, PropertyInstance propInst) {
1030:                Element elProp = xml
1031:                        .createElementNS(
1032:                                "http://www.simulacramedia.com/harmoniseclient/propinstances",
1033:                                "Prop");
1034:                elProp.setAttribute("name", propInst.getName());
1035:                elProp.setAttribute("namespace",
1036:                        "http://www.simulacramedia.com/XRM/DAV");
1037:
1038:                Iterator itor = propInst.getValues().iterator();
1039:                while (itor.hasNext()) {
1040:                    String element = (String) itor.next();
1041:
1042:                    Element elVal = xml
1043:                            .createElementNS(
1044:                                    "http://www.simulacramedia.com/harmoniseclient/propinstances",
1045:                                    "Value");
1046:                    Text txt = xml.createTextNode(element);
1047:                    elVal.appendChild(txt);
1048:                    elProp.appendChild(elVal);
1049:                }
1050:
1051:                return elProp;
1052:            }
1053:
1054:            /* (non-Javadoc)
1055:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#synchroniseFile(com.simulacramedia.vfs.VirtualFile)
1056:             */
1057:            public StatusData synchroniseFile(VirtualFile vfFile) {
1058:                VFSStatus retnStatus = new VFSStatus();
1059:
1060:                boolean bError = false;
1061:
1062:                VersionedVirtualFile vfSyncFile = (VersionedVirtualFile) vfFile;
1063:
1064:                if (vfSyncFile.isChanged()) {
1065:                    if (vfSyncFile.getState().equals(VirtualFile.STATE_LIVE)
1066:                            && !vfSyncFile.hasPendingVersion()) {
1067:                        File file = this .getRealFile(vfSyncFile);
1068:                        File fPending = this .getPendingFile(file);
1069:                        if (this .moveFile(file, fPending, false)) {
1070:                            bError = true;
1071:                        } else {
1072:                            FileOutputStream fos = null;
1073:
1074:                            try {
1075:                                fos = new FileOutputStream(fPending
1076:                                        .getAbsolutePath());
1077:                                fos.write(vfSyncFile.getContent());
1078:                            } catch (FileNotFoundException e) {
1079:                                bError = true;
1080:                                e.printStackTrace();
1081:                            } catch (IOException e) {
1082:                                bError = true;
1083:                                e.printStackTrace();
1084:                            } finally {
1085:                                try {
1086:                                    fos.close();
1087:                                } catch (IOException e1) {
1088:                                    e1.printStackTrace();
1089:                                }
1090:                            }
1091:                        }
1092:                        if (!bError) {
1093:                            if (this .moveFile(this .getMetadataFile(file), this 
1094:                                    .getMetadataFile(fPending), false)) {
1095:                                bError = true;
1096:                            } else {
1097:                                Document xml = this 
1098:                                        .generatePropertyXML(vfSyncFile);
1099:                                XMLPrettyPrint printer = new XMLPrettyPrint();
1100:                                printer.setNamespaceAware(true);
1101:                                printer.printNodeToFile(xml
1102:                                        .getDocumentElement(), this 
1103:                                        .getMetadataFile(fPending));
1104:                            }
1105:                        }
1106:
1107:                        if (!bError) {
1108:                            this .m_cache.removeFile(vfSyncFile.getFullPath());
1109:                        }
1110:                    } else if (vfSyncFile.getState().equals(
1111:                            VirtualFile.STATE_PENDING)
1112:                            && vfSyncFile.getLiveVersionPath() == null) {
1113:                        String sFullPath = vfSyncFile.getFullPath();
1114:
1115:                        String sRealPath = this .getInitialPath() + sFullPath;
1116:                        sRealPath = sRealPath.replace('/', File.separatorChar);
1117:
1118:                        FileOutputStream fos = null;
1119:
1120:                        try {
1121:                            fos = new FileOutputStream(sRealPath);
1122:                            fos.write(vfSyncFile.getContent());
1123:                        } catch (FileNotFoundException e) {
1124:                            bError = true;
1125:                            e.printStackTrace();
1126:                        } catch (IOException e) {
1127:                            bError = true;
1128:                            e.printStackTrace();
1129:                        } finally {
1130:                            try {
1131:                                fos.close();
1132:                            } catch (IOException e1) {
1133:                                e1.printStackTrace();
1134:                            }
1135:                        }
1136:                        if (!bError) {
1137:                            Document xml = this .generatePropertyXML(vfSyncFile);
1138:                            XMLPrettyPrint printer = new XMLPrettyPrint();
1139:                            printer.setNamespaceAware(true);
1140:                            printer.printNodeToFile(xml.getDocumentElement(),
1141:                                    this .getMetadataFile(this 
1142:                                            .getRealFile(vfSyncFile)));
1143:                        }
1144:
1145:                        if (!bError) {
1146:                            this .m_cache.removeFile(vfSyncFile.getFullPath());
1147:                        }
1148:                    } else if (vfSyncFile.getState().equals(
1149:                            VirtualFile.STATE_PENDING)) {
1150:                        String sFullPath = vfSyncFile.getFullPath();
1151:
1152:                        String sRealPath = this .getInitialPath() + sFullPath;
1153:                        sRealPath = sRealPath.replace('/', File.separatorChar);
1154:
1155:                        FileOutputStream fos = null;
1156:
1157:                        try {
1158:                            fos = new FileOutputStream(sRealPath);
1159:                            fos.write(vfSyncFile.getContent());
1160:                        } catch (FileNotFoundException e) {
1161:                            bError = true;
1162:                            e.printStackTrace();
1163:                        } catch (IOException e) {
1164:                            bError = true;
1165:                            e.printStackTrace();
1166:                        } finally {
1167:                            try {
1168:                                fos.close();
1169:                            } catch (IOException e1) {
1170:                                e1.printStackTrace();
1171:                            }
1172:                        }
1173:                        if (!bError) {
1174:                            Document xml = this .generatePropertyXML(vfSyncFile);
1175:                            XMLPrettyPrint printer = new XMLPrettyPrint();
1176:                            printer.setNamespaceAware(true);
1177:                            printer.printNodeToFile(xml.getDocumentElement(),
1178:                                    this .getMetadataFile(this 
1179:                                            .getRealFile(vfSyncFile)));
1180:                        }
1181:
1182:                        if (!bError) {
1183:                            this .m_cache.removeFile(vfSyncFile.getFullPath());
1184:                            this .m_cache.removeFile(vfSyncFile
1185:                                    .getLiveVersionPath());
1186:                        }
1187:                    } else {
1188:                    }
1189:                }
1190:
1191:                if (bError) {
1192:                    retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1193:                    retnStatus.setStatusCode(StatusData.STATUS_INVALID_REQUEST);
1194:                }
1195:
1196:                return retnStatus;
1197:            }
1198:
1199:            /* (non-Javadoc)
1200:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#sunchroniseAllFiles()
1201:             */
1202:            public StatusData synchroniseAllFiles() {
1203:                VFSStatus retnStatus = new VFSStatus();
1204:
1205:                boolean bError = false;
1206:
1207:                Iterator itor = this .m_cache.getPaths().iterator();
1208:                while (itor.hasNext()) {
1209:                    String sFullPath = (String) itor.next();
1210:                    VirtualFile vfFile = this .m_cache.getFile(sFullPath);
1211:                    if (vfFile.isChanged()) {
1212:                        StatusData status = vfFile.sync();
1213:                        if (status.isOK()) {
1214:                            bError = true;
1215:                        }
1216:                    }
1217:                }
1218:
1219:                if (bError) {
1220:                    retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1221:                    retnStatus.setStatusCode(StatusData.STATUS_INVALID_REQUEST);
1222:                }
1223:
1224:                return retnStatus;
1225:            }
1226:
1227:            /* (non-Javadoc)
1228:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#exists(java.lang.String)
1229:             */
1230:            public boolean exists(String sFullPath) {
1231:                boolean bExists = true;
1232:
1233:                String sRealPath = this .getInitialPath() + sFullPath;
1234:                sRealPath = sRealPath.replace('/', File.separatorChar);
1235:
1236:                File file = new File(sRealPath);
1237:                bExists = file.exists();
1238:
1239:                return bExists;
1240:            }
1241:
1242:            /* (non-Javadoc)
1243:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#refreshChildren(com.simulacramedia.vfs.VirtualFile)
1244:             */
1245:            protected void refreshChildren(VirtualFile vfFile) {
1246:                Iterator itor = vfFile.getChildren().iterator();
1247:                while (itor.hasNext()) {
1248:                    String sChildPath = (String) itor.next();
1249:                    VirtualFile vfChild = this .getVirtualFile(sChildPath)
1250:                            .getResource();
1251:                    if (!vfChild.isChanged()) {
1252:                        this .m_cache.removeFile(sChildPath);
1253:                    }
1254:                }
1255:            }
1256:
1257:            /* (non-Javadoc)
1258:             * @see com.simulacramedia.vfs.AbstractVersioningVFS#checkoutVirtualFile(java.lang.String)
1259:             */
1260:            public StatusData checkoutVirtualFile(String sFullPath) {
1261:                VFSStatus retnStatus = new VFSStatus();
1262:                return retnStatus;
1263:            }
1264:
1265:            /* (non-Javadoc)
1266:             * @see com.simulacramedia.vfs.AbstractVersioningVFS#uncheckoutVirtualFile(java.lang.String)
1267:             */
1268:            public StatusData uncheckoutVirtualFile(String sFullPath) {
1269:                VFSStatus retnStatus = new VFSStatus();
1270:                return retnStatus;
1271:            }
1272:
1273:            /* (non-Javadoc)
1274:             * @see com.simulacramedia.vfs.AbstractVersioningVFS#checkinVirtualFile(java.lang.String)
1275:             */
1276:            public StatusData checkinVirtualFile(String sFullPath) {
1277:                VFSStatus retnStatus = new VFSStatus();
1278:
1279:                boolean bError = false;
1280:                VersionedVirtualFile vfFile = (VersionedVirtualFile) this 
1281:                        .getVirtualFile(sFullPath).getResource();
1282:
1283:                if (vfFile.getState().equals(VirtualFile.STATE_PENDING)) {
1284:                    if (vfFile.isChanged()) {
1285:                        vfFile.sync();
1286:                    }
1287:                    vfFile = (VersionedVirtualFile) this .getVirtualFile(
1288:                            sFullPath).getResource();
1289:                    if (vfFile.getLiveVersionPath() == null) {
1290:                        File fNewMarker = this .getNewMarkerFile(this 
1291:                                .getRealFile(vfFile));
1292:                        if (!fNewMarker.delete()) {
1293:                            bError = true;
1294:                        }
1295:                    } else {
1296:                        VirtualFile vfParent = this .getVirtualFile(
1297:                                vfFile.getLiveVersionPath()).getResource();
1298:                        File fRealFile = this .getRealFile(vfFile);
1299:                        File fParent = this .getRealFile(vfParent);
1300:                        File fHistorical = this .getNextHistoricalFile(fParent);
1301:
1302:                        if (!this .moveRealFile(this .getMetadataFile(fParent),
1303:                                this .getMetadataFile(fHistorical), false)) {
1304:                            if (!this .moveRealFile(fParent, fHistorical, false)) {
1305:                                if (!this .moveRealFile(this 
1306:                                        .getMetadataFile(fRealFile), this 
1307:                                        .getMetadataFile(fParent), true)) {
1308:                                    if (this .moveRealFile(fRealFile, fParent,
1309:                                            true)) {
1310:                                        bError = true;
1311:                                    }
1312:                                } else {
1313:                                    bError = true;
1314:                                }
1315:                            } else {
1316:                                bError = true;
1317:                            }
1318:                        } else {
1319:                            bError = true;
1320:                        }
1321:
1322:                        this .m_cache.removeFile(sFullPath);
1323:                        this .m_cache.removeFile(vfParent.getFullPath());
1324:
1325:                    }
1326:                } else {
1327:                    bError = false;
1328:                }
1329:
1330:                if (bError) {
1331:                    retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1332:                    retnStatus.setStatusCode(StatusData.STATUS_INVALID_REQUEST);
1333:                }
1334:
1335:                return retnStatus;
1336:            }
1337:
1338:            private File getNextHistoricalFile(File file) {
1339:                File fRetn = null;
1340:
1341:                int nVersion = 0;
1342:                Iterator iter = this .getHistoryFiles(file).iterator();
1343:                while (iter.hasNext()) {
1344:                    File element = (File) iter.next();
1345:                    String sName = element.getName();
1346:                    int nVerTemp = Integer.parseInt(sName.substring(sName
1347:                            .length() - 3));
1348:                    if (nVerTemp > nVersion) {
1349:                        nVersion = nVerTemp;
1350:                    }
1351:                }
1352:                nVersion++;
1353:
1354:                String sVerExt = "00" + nVersion;
1355:                if (nVersion > 9 && nVersion < 100) {
1356:                    sVerExt = "0" + nVersion;
1357:                } else if (nVersion > 99) {
1358:                    sVerExt = "" + nVersion;
1359:                }
1360:
1361:                fRetn = new File(this .getHistoryDir(file).getAbsolutePath()
1362:                        + File.separatorChar + file.getName() + ".v" + sVerExt);
1363:
1364:                return fRetn;
1365:            }
1366:
1367:            /* (non-Javadoc)
1368:             * @see com.simulacramedia.vfs.AbstractVersioningVFS#tagVirtualFile(java.lang.String, java.lang.String)
1369:             */
1370:            public StatusData tagVirtualFile(String sFullPath, String sTag) {
1371:                VFSStatus retnStatus = new VFSStatus();
1372:                return retnStatus;
1373:            }
1374:
1375:            /* (non-Javadoc)
1376:             * @see com.simulacramedia.vfs.AbstractVersioningVFS#reactivateVersion(java.lang.String)
1377:             */
1378:            public StatusData reactivateVersion(String sFullPath) {
1379:                VFSStatus retnStatus = new VFSStatus();
1380:
1381:                boolean bError = false;
1382:                VersionedVirtualFile vfFile = (VersionedVirtualFile) this 
1383:                        .getVirtualFile(sFullPath).getResource();
1384:
1385:                if (vfFile.getState().equals(VirtualFile.STATE_HISTORICAL)) {
1386:                    if (vfFile.getLiveVersionPath() == null
1387:                            || ((VersionedVirtualFile) this .getVirtualFile(
1388:                                    vfFile.getLiveVersionPath()).getResource())
1389:                                    .hasPendingVersion()) {
1390:                        bError = true;
1391:                    } else {
1392:                        File fRealFile = this .getRealFile(vfFile);
1393:                        File fLiveFile = this .getRealFile(this .getVirtualFile(
1394:                                vfFile.getLiveVersionPath()).getResource());
1395:
1396:                        File fNewPendingFile = this .getPendingFile(fLiveFile);
1397:
1398:                        if (!this .moveRealFile(this .getMetadataFile(fRealFile),
1399:                                this .getMetadataFile(fNewPendingFile), false)) {
1400:                            if (this .moveRealFile(fRealFile, fNewPendingFile,
1401:                                    false)) {
1402:                                bError = true;
1403:                            }
1404:                        } else {
1405:                            bError = true;
1406:                        }
1407:
1408:                        this .m_cache.removeFile(vfFile.getLiveVersionPath());
1409:
1410:                    }
1411:                } else {
1412:                    bError = false;
1413:                }
1414:
1415:                if (bError) {
1416:                    retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1417:                    retnStatus.setStatusCode(StatusData.STATUS_INVALID_REQUEST);
1418:                }
1419:
1420:                return retnStatus;
1421:            }
1422:
1423:            /* (non-Javadoc)
1424:             * @see com.simulacramedia.vfs.AbstractVersioningVFS#fullyPopulateFileHistory(com.simulacramedia.vfs.VersionedVirtualFile)
1425:             */
1426:            protected void fullyPopulateFileHistory(VersionedVirtualFile vfFile) {
1427:
1428:                String sRealPath = this .getInitialPath() + vfFile.getFullPath();
1429:                sRealPath = sRealPath.replace('/', File.separatorChar);
1430:                File fRealFile = new File(sRealPath);
1431:
1432:                File fHistoryDir = new File(fRealFile.getParentFile()
1433:                        .getAbsolutePath()
1434:                        + File.separatorChar + "CMHistory");
1435:                if (fHistoryDir.exists() && fHistoryDir.isDirectory()) {
1436:                    File[] children = fHistoryDir.listFiles();
1437:                    if (children != null) {
1438:                        for (int i = 0; i < children.length; i++) {
1439:                            if (children[i].getName().startsWith(
1440:                                    fRealFile.getName())) {
1441:                                VirtualFile vfHistorical = this .getVirtualFile(
1442:                                        vfFile.getFilePath() + "/CMHistory/"
1443:                                                + children[i].getName())
1444:                                        .getResource();
1445:                                this .setFileState(vfHistorical,
1446:                                        VirtualFile.STATE_HISTORICAL);
1447:                                this .setFileLiveVersionPath(
1448:                                        (VersionedVirtualFile) vfHistorical,
1449:                                        vfFile.getFullPath());
1450:                                this .addHistoricalVersionPath(vfFile,
1451:                                        vfHistorical.getFullPath());
1452:                            }
1453:                        }
1454:                    }
1455:                    this .setFileHistoryPopulated(vfFile, true);
1456:                } else if (!fHistoryDir.exists()) {
1457:                    fHistoryDir.mkdir();
1458:                }
1459:
1460:            }
1461:
1462:            /* (non-Javadoc)
1463:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#orderVirtualFileChildren(java.util.List, com.simulacramedia.vfs.VirtualFile)
1464:             */
1465:            public StatusData orderVirtualFileChildren(List aPaths,
1466:                    VirtualFile vfDir) {
1467:                VFSStatus retnStatus = new VFSStatus();
1468:
1469:                boolean bError = false;
1470:
1471:                File fDir = this .getRealFile(vfDir);
1472:                File fOrderFile = this .getOrderFile(fDir);
1473:
1474:                Document xml = null;
1475:                try {
1476:                    DocumentBuilderFactory factory = DocumentBuilderFactory
1477:                            .newInstance();
1478:                    factory.setNamespaceAware(true);
1479:                    xml = factory.newDocumentBuilder().newDocument();
1480:                } catch (FactoryConfigurationError e) {
1481:                    bError = true;
1482:                    e.printStackTrace();
1483:                } catch (ParserConfigurationException e) {
1484:                    bError = true;
1485:                    e.printStackTrace();
1486:                }
1487:
1488:                Element rootEl = xml
1489:                        .createElementNS(
1490:                                "http://www.simulacramedia.com/harmoniseclient/propinstances",
1491:                                "Order");
1492:                xml.appendChild(rootEl);
1493:
1494:                for (int i = 0; i < aPaths.size(); i++) {
1495:                    String sPath = (String) aPaths.get(i);
1496:                    Element elChild = xml
1497:                            .createElementNS(
1498:                                    "http://www.simulacramedia.com/harmoniseclient/propinstances",
1499:                                    "child");
1500:                    Text txt = xml.createTextNode(sPath);
1501:                    elChild.appendChild(txt);
1502:                    rootEl.appendChild(elChild);
1503:                }
1504:
1505:                XMLPrettyPrint printer = new XMLPrettyPrint();
1506:                printer.setNamespaceAware(true);
1507:                printer.printNodeToFile(rootEl, fOrderFile);
1508:
1509:                if (bError) {
1510:                    retnStatus.setStatusLevel(StatusData.LEVEL_ERROR);
1511:                    retnStatus.setStatusCode(StatusData.STATUS_INVALID_REQUEST);
1512:                }
1513:
1514:                return retnStatus;
1515:            }
1516:
1517:            /* (non-Javadoc)
1518:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getNewValueInstance(com.simulacramedia.vfs.metadata.PropertyInstance)
1519:             */
1520:            public ValueInstance getNewValueInstance(PropertyInstance propInst) {
1521:                ValueInstance val = null;
1522:
1523:                Range range = propInst.getDefinition().getRange();
1524:
1525:                if (range instanceof  BooleanRange) {
1526:                    val = new LVVFSBooleanValue();
1527:                } else if (range instanceof  DateTimeRange) {
1528:                    val = new LVVFSDateTimeValue();
1529:                } else if (range instanceof  DateRange) {
1530:                    val = new LVVFSDateValue();
1531:                } else if (range instanceof  DomainRange) {
1532:                    val = new LVVFSDomainValue();
1533:                } else if (range instanceof  FloatRange) {
1534:                    val = new LVVFSFloatValue();
1535:                } else if (range instanceof  IntegerRange) {
1536:                    val = new LVVFSIntegerValue();
1537:                } else if (range instanceof  PropertyRange) {
1538:                    val = new LVVFSPropertyValue();
1539:                } else if (range instanceof  RangeRange) {
1540:                    val = new LVVFSRangeValue();
1541:                } else if (range instanceof  ResourceRange) {
1542:                    val = new LVVFSResourceValue();
1543:                } else if (range instanceof  URIRange) {
1544:                    val = new LVVFSURIValue();
1545:                } else if (range instanceof  ValueRange) {
1546:                    val = new LVVFSValueValue();
1547:                } else {
1548:                    val = new LVVFSStringValue();
1549:                }
1550:
1551:                return val;
1552:            }
1553:
1554:            /* (non-Javadoc)
1555:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#rejectAllChanges()
1556:             */
1557:            public boolean rejectAllChanges() {
1558:                return false;
1559:            }
1560:
1561:            /* (non-Javadoc)
1562:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#fullyPopulateFileAllowedMethods(com.simulacramedia.vfs.VirtualFile)
1563:             */
1564:            protected void fullyPopulateFileAllowedMethods(VirtualFile vfFile) {
1565:            }
1566:
1567:            /* (non-Javadoc)
1568:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#currentUserResourcePath()
1569:             */
1570:            public String currentUserResourcePath(AuthInfo authInfo) {
1571:                return null;
1572:            }
1573:
1574:            /* (non-Javadoc)
1575:             * @see com.simulacramedia.vfs.AbstractVirtualFileSystem#getChangedVirtualFiles()
1576:             */
1577:            public List getChangedVirtualFiles() {
1578:                return new ArrayList();
1579:            }
1580:
1581:            /* (non-Javadoc)
1582:             * @see org.openharmonise.vfs.AbstractVirtualFileSystem#getPropertyVirtualFile(java.lang.String)
1583:             */
1584:            public VirtualFile getPropertyVirtualFile(String sPropPath) {
1585:                return null;
1586:            }
1587:
1588:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.