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


001:        /*
002:         * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/importexport/CmsImportVersion4.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:48 $
004:         * Version: $Revision: 1.93 $
005:         *
006:         * This library is part of OpenCms -
007:         * the Open Source Content Management System
008:         *
009:         * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010:         *
011:         * This library is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Lesser General Public
013:         * License as published by the Free Software Foundation; either
014:         * version 2.1 of the License, or (at your option) any later version.
015:         *
016:         * This library is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019:         * Lesser General Public License for more details.
020:         *
021:         * For further information about Alkacon Software GmbH, please see the
022:         * company website: http://www.alkacon.com
023:         *
024:         * For further information about OpenCms, please see the
025:         * project website: http://www.opencms.org
026:         * 
027:         * You should have received a copy of the GNU Lesser General Public
028:         * License along with this library; if not, write to the Free Software
029:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030:         */
031:
032:        package org.opencms.importexport;
033:
034:        import org.opencms.file.CmsFile;
035:        import org.opencms.file.CmsObject;
036:        import org.opencms.file.CmsResource;
037:        import org.opencms.file.types.CmsResourceTypePlain;
038:        import org.opencms.file.types.I_CmsResourceType;
039:        import org.opencms.i18n.CmsMessageContainer;
040:        import org.opencms.loader.CmsLoaderException;
041:        import org.opencms.main.CmsException;
042:        import org.opencms.main.CmsLog;
043:        import org.opencms.main.OpenCms;
044:        import org.opencms.relations.I_CmsLinkParseable;
045:        import org.opencms.report.I_CmsReport;
046:        import org.opencms.security.CmsRole;
047:        import org.opencms.security.I_CmsPasswordHandler;
048:        import org.opencms.security.I_CmsPrincipal;
049:        import org.opencms.util.CmsDateUtil;
050:        import org.opencms.util.CmsUUID;
051:        import org.opencms.xml.CmsXmlException;
052:        import org.opencms.xml.CmsXmlUtils;
053:
054:        import java.io.File;
055:        import java.io.IOException;
056:        import java.text.ParseException;
057:        import java.util.ArrayList;
058:        import java.util.Collections;
059:        import java.util.HashMap;
060:        import java.util.Iterator;
061:        import java.util.List;
062:        import java.util.Map;
063:        import java.util.zip.ZipFile;
064:
065:        import org.apache.commons.logging.Log;
066:
067:        import org.dom4j.Document;
068:        import org.dom4j.Element;
069:
070:        /**
071:         * Implementation of the OpenCms Import Interface ({@link org.opencms.importexport.I_CmsImport}) for 
072:         * the import version 4.<p>
073:         * 
074:         * This import format is used in OpenCms since 5.1.6.<p>
075:         *
076:         * @author Michael Emmerich 
077:         * @author Thomas Weckert  
078:         * 
079:         * @version $Revision: 1.93 $ 
080:         * 
081:         * @since 6.0.0 
082:         * 
083:         * @see org.opencms.importexport.A_CmsImport
084:         * 
085:         * @deprecated this import class is no longer in use and should only be used to import old export files
086:         */
087:        public class CmsImportVersion4 extends A_CmsImport {
088:
089:            /** The version number of this import implementation.<p> */
090:            private static final int IMPORT_VERSION = 4;
091:
092:            /** The log object for this class. */
093:            private static final Log LOG = CmsLog
094:                    .getLog(CmsImportVersion4.class);
095:
096:            /** Stores all resource of type that implements the {@link I_CmsLinkParseable} interface. */
097:            private List m_parseables;
098:
099:            /**
100:             * Creates a new CmsImportVerion4 object.<p>
101:             */
102:            public CmsImportVersion4() {
103:
104:                m_convertToXmlPage = true;
105:            }
106:
107:            /**
108:             * @see org.opencms.importexport.I_CmsImport#getVersion()
109:             * @return the version number of this import implementation
110:             */
111:            public int getVersion() {
112:
113:                return CmsImportVersion4.IMPORT_VERSION;
114:            }
115:
116:            /**
117:             * @see org.opencms.importexport.I_CmsImport#importResources(org.opencms.file.CmsObject, java.lang.String, org.opencms.report.I_CmsReport, java.io.File, java.util.zip.ZipFile, org.dom4j.Document)
118:             * 
119:             * @deprecated use {@link #importData(CmsObject, I_CmsReport, CmsImportParameters)} instead
120:             */
121:            public void importResources(CmsObject cms, String importPath,
122:                    I_CmsReport report, File importResource, ZipFile importZip,
123:                    Document docXml) throws CmsImportExportException {
124:
125:                CmsImportParameters params = new CmsImportParameters(
126:                        importResource != null ? importResource
127:                                .getAbsolutePath() : importZip.getName(),
128:                        importPath, true);
129:
130:                try {
131:                    importData(cms, report, params);
132:                } catch (CmsXmlException e) {
133:                    throw new CmsImportExportException(e.getMessageContainer(),
134:                            e);
135:                }
136:            }
137:
138:            /**
139:             * @see org.opencms.importexport.I_CmsImport#importData(CmsObject, I_CmsReport, CmsImportParameters)
140:             */
141:            public void importData(CmsObject cms, I_CmsReport report,
142:                    CmsImportParameters params)
143:                    throws CmsImportExportException, CmsXmlException {
144:
145:                // initialize the import
146:                initialize();
147:                m_cms = cms;
148:                m_importPath = params.getDestinationPath();
149:                m_report = report;
150:
151:                m_linkStorage = new HashMap();
152:                m_linkPropertyStorage = new HashMap();
153:                m_parseables = new ArrayList();
154:
155:                CmsImportHelper helper = new CmsImportHelper(params);
156:                try {
157:                    helper.openFile();
158:                    m_importResource = helper.getFolder();
159:                    m_importZip = helper.getZipFile();
160:                    m_docXml = CmsXmlUtils
161:                            .unmarshalHelper(
162:                                    helper
163:                                            .getFileBytes(CmsImportExportManager.EXPORT_MANIFEST),
164:                                    null);
165:                    // first import the user information
166:                    if (OpenCms.getRoleManager().hasRole(m_cms,
167:                            CmsRole.ACCOUNT_MANAGER)) {
168:                        importGroups();
169:                        importUsers();
170:                    }
171:                    // now import the VFS resources
172:                    readResourcesFromManifest();
173:                    convertPointerToSiblings();
174:                    rewriteParseables();
175:                } catch (IOException ioe) {
176:                    CmsMessageContainer msg = Messages.get().container(
177:                            Messages.ERR_IMPORTEXPORT_ERROR_READING_FILE_1,
178:                            CmsImportExportManager.EXPORT_MANIFEST);
179:                    if (LOG.isErrorEnabled()) {
180:                        LOG.error(msg.key(), ioe);
181:                    }
182:                    throw new CmsImportExportException(msg, ioe);
183:                } finally {
184:                    helper.closeFile();
185:                    cleanUp();
186:                }
187:            }
188:
189:            /**
190:             * @see org.opencms.importexport.A_CmsImport#importUser(String, String, String, String, String, String, long, Map, List)
191:             */
192:            protected void importUser(String name, String flags,
193:                    String password, String firstname, String lastname,
194:                    String email, long dateCreated, Map userInfo,
195:                    List userGroups) throws CmsImportExportException {
196:
197:                boolean convert = false;
198:
199:                Map config = OpenCms.getPasswordHandler().getConfiguration();
200:                if ((config != null)
201:                        && config
202:                                .containsKey(I_CmsPasswordHandler.CONVERT_DIGEST_ENCODING)) {
203:                    convert = Boolean
204:                            .valueOf(
205:                                    (String) config
206:                                            .get(I_CmsPasswordHandler.CONVERT_DIGEST_ENCODING))
207:                            .booleanValue();
208:                }
209:
210:                if (convert) {
211:                    password = convertDigestEncoding(password);
212:                }
213:
214:                super .importUser(name, flags, password, firstname, lastname,
215:                        email, dateCreated, userInfo, userGroups);
216:            }
217:
218:            /**
219:             * Rewrites all parseable files, to assure link check.<p>
220:             */
221:            protected void rewriteParseables() {
222:
223:                if (m_parseables.isEmpty()) {
224:                    return;
225:                }
226:
227:                m_report.println(Messages.get().container(
228:                        Messages.RPT_START_PARSE_LINKS_0),
229:                        I_CmsReport.FORMAT_HEADLINE);
230:
231:                int i = 0;
232:                Iterator it = m_parseables.iterator();
233:                while (it.hasNext()) {
234:                    CmsResource res = (CmsResource) it.next();
235:
236:                    m_report.print(org.opencms.report.Messages.get().container(
237:                            org.opencms.report.Messages.RPT_SUCCESSION_2,
238:                            String.valueOf(i + 1),
239:                            String.valueOf(m_parseables.size())),
240:                            I_CmsReport.FORMAT_NOTE);
241:
242:                    m_report.print(Messages.get().container(
243:                            Messages.RPT_PARSE_LINKS_FOR_1,
244:                            m_cms.getSitePath(res)), I_CmsReport.FORMAT_NOTE);
245:                    m_report.print(org.opencms.report.Messages.get().container(
246:                            org.opencms.report.Messages.RPT_DOTS_0));
247:
248:                    try {
249:                        // make sure the date last modified is kept...
250:                        CmsFile file = m_cms.readFile(res);
251:                        file.setDateLastModified(res.getDateLastModified());
252:                        m_cms.writeFile(file);
253:
254:                        m_report.println(
255:                                org.opencms.report.Messages.get().container(
256:                                        org.opencms.report.Messages.RPT_OK_0),
257:                                I_CmsReport.FORMAT_OK);
258:                    } catch (Throwable e) {
259:                        m_report.addWarning(e);
260:                        m_report
261:                                .println(
262:                                        org.opencms.report.Messages
263:                                                .get()
264:                                                .container(
265:                                                        org.opencms.report.Messages.RPT_FAILED_0),
266:                                        I_CmsReport.FORMAT_ERROR);
267:                        if (LOG.isWarnEnabled()) {
268:                            LOG.warn(Messages.get().getBundle().key(
269:                                    Messages.LOG_IMPORTEXPORT_REWRITING_1,
270:                                    res.getRootPath()));
271:                        }
272:                        if (LOG.isDebugEnabled()) {
273:                            LOG.debug(e.getLocalizedMessage(), e);
274:                        }
275:                    }
276:                    i++;
277:                }
278:
279:                m_report.println(Messages.get().container(
280:                        Messages.RPT_END_PARSE_LINKS_0),
281:                        I_CmsReport.FORMAT_HEADLINE);
282:            }
283:
284:            /**
285:             * Convert a given timestamp from a String format to a long value.<p>
286:             * 
287:             * The timestamp is either the string representation of a long value (old export format)
288:             * or a user-readable string format.
289:             * 
290:             * @param timestamp timestamp to convert
291:             * @return long value of the timestamp
292:             */
293:            private long convertTimestamp(String timestamp) {
294:
295:                long value = 0;
296:                // try to parse the timestamp string
297:                // if it successes, its an old style long value
298:                try {
299:                    value = Long.parseLong(timestamp);
300:
301:                } catch (NumberFormatException e) {
302:                    // the timestamp was in in a user-readable string format, create the long value form it
303:                    try {
304:                        value = CmsDateUtil.parseHeaderDate(timestamp);
305:                    } catch (ParseException pe) {
306:                        value = System.currentTimeMillis();
307:                    }
308:                }
309:                return value;
310:            }
311:
312:            /**
313:             * Imports a resource (file or folder) into the cms.<p>
314:             * 
315:             * @param source the path to the source-file
316:             * @param destination the path to the destination-file in the cms
317:             * @param type the resource type name of the file
318:             * @param uuidresource  the resource uuid of the resource
319:             * @param datelastmodified the last modification date of the resource
320:             * @param userlastmodified the user who made the last modifications to the resource
321:             * @param datecreated the creation date of the resource
322:             * @param usercreated the user who created 
323:             * @param datereleased the release date of the resource
324:             * @param dateexpired the expire date of the resource
325:             * @param flags the flags of the resource     
326:             * @param properties a list with properties for this resource
327:             * 
328:             * @return imported resource
329:             */
330:            private CmsResource importResource(String source,
331:                    String destination, I_CmsResourceType type,
332:                    String uuidresource, long datelastmodified,
333:                    String userlastmodified, long datecreated,
334:                    String usercreated, long datereleased, long dateexpired,
335:                    String flags, List properties) {
336:
337:                byte[] content = null;
338:                CmsResource result = null;
339:
340:                try {
341:
342:                    // get the file content
343:                    if (source != null) {
344:                        content = getFileBytes(source);
345:                    }
346:                    int size = 0;
347:                    if (content != null) {
348:                        size = content.length;
349:                    }
350:
351:                    // get UUIDs for the user   
352:                    CmsUUID newUserlastmodified;
353:                    CmsUUID newUsercreated;
354:                    // check if user created and user lastmodified are valid users in this system.
355:                    // if not, use the current user
356:                    try {
357:                        newUserlastmodified = m_cms.readUser(userlastmodified)
358:                                .getId();
359:                    } catch (CmsException e) {
360:                        newUserlastmodified = m_cms.getRequestContext()
361:                                .currentUser().getId();
362:                        // datelastmodified = System.currentTimeMillis();
363:                    }
364:
365:                    try {
366:                        newUsercreated = m_cms.readUser(usercreated).getId();
367:                    } catch (CmsException e) {
368:                        newUsercreated = m_cms.getRequestContext()
369:                                .currentUser().getId();
370:                        // datecreated = System.currentTimeMillis();
371:                    }
372:
373:                    // get UUIDs for the resource and content        
374:                    CmsUUID newUuidresource = null;
375:                    if ((uuidresource != null) && (!type.isFolder())) {
376:                        // create a UUID from the provided string
377:                        newUuidresource = new CmsUUID(uuidresource);
378:                    } else {
379:                        // folders get always a new resource record UUID
380:                        newUuidresource = new CmsUUID();
381:                    }
382:
383:                    // create a new CmsResource                         
384:                    CmsResource resource = new CmsResource(
385:                            new CmsUUID(), // structure ID is always a new UUID
386:                            newUuidresource, destination, type.getTypeId(),
387:                            type.isFolder(), new Integer(flags).intValue(),
388:                            m_cms.getRequestContext().currentProject()
389:                                    .getUuid(), CmsResource.STATE_NEW,
390:                            datecreated, newUsercreated, datelastmodified,
391:                            newUserlastmodified, datereleased, dateexpired, 1,
392:                            size, System.currentTimeMillis(), 0);
393:
394:                    // import this resource in the VFS
395:                    result = m_cms.importResource(destination, resource,
396:                            content, properties);
397:
398:                    if (result != null) {
399:                        m_report.println(
400:                                org.opencms.report.Messages.get().container(
401:                                        org.opencms.report.Messages.RPT_OK_0),
402:                                I_CmsReport.FORMAT_OK);
403:                    }
404:                } catch (Exception exc) {
405:                    // an error while importing the file
406:                    m_report.println(exc);
407:                    try {
408:                        // Sleep some time after an error so that the report output has a chance to keep up
409:                        Thread.sleep(1000);
410:                    } catch (Exception e) {
411:                        // 
412:                    }
413:                }
414:                return result;
415:            }
416:
417:            /**
418:             * Reads all file nodes plus their meta-information (properties, ACL) 
419:             * from the <code>manifest.xml</code> and imports them as Cms resources to the VFS.<p>
420:             * 
421:             * @throws CmsImportExportException if something goes wrong
422:             */
423:            private void readResourcesFromManifest()
424:                    throws CmsImportExportException {
425:
426:                String source = null, destination = null, uuidresource = null, userlastmodified = null, usercreated = null, flags = null, timestamp = null;
427:                long datelastmodified = 0, datecreated = 0, datereleased = 0, dateexpired = 0;
428:
429:                List fileNodes = null, acentryNodes = null;
430:                Element currentElement = null, currentEntry = null;
431:                List properties = null;
432:
433:                // get list of immutable resources
434:                List immutableResources = OpenCms.getImportExportManager()
435:                        .getImmutableResources();
436:                if (immutableResources == null) {
437:                    immutableResources = Collections.EMPTY_LIST;
438:                }
439:                if (LOG.isDebugEnabled()) {
440:                    LOG
441:                            .debug(Messages
442:                                    .get()
443:                                    .getBundle()
444:                                    .key(
445:                                            Messages.LOG_IMPORTEXPORT_IMMUTABLE_RESOURCES_SIZE_1,
446:                                            Integer.toString(immutableResources
447:                                                    .size())));
448:                }
449:                // get list of ignored properties
450:                List ignoredProperties = OpenCms.getImportExportManager()
451:                        .getIgnoredProperties();
452:                if (ignoredProperties == null) {
453:                    ignoredProperties = Collections.EMPTY_LIST;
454:                }
455:
456:                // get the desired page type for imported pages
457:                m_convertToXmlPage = OpenCms.getImportExportManager()
458:                        .convertToXmlPage();
459:
460:                try {
461:                    // get all file-nodes
462:                    fileNodes = m_docXml.selectNodes("//" + A_CmsImport.N_FILE);
463:                    int importSize = fileNodes.size();
464:
465:                    // walk through all files in manifest
466:                    for (int i = 0; i < fileNodes.size(); i++) {
467:                        m_report
468:                                .print(
469:                                        org.opencms.report.Messages
470:                                                .get()
471:                                                .container(
472:                                                        org.opencms.report.Messages.RPT_SUCCESSION_2,
473:                                                        String.valueOf(i + 1),
474:                                                        String
475:                                                                .valueOf(importSize)),
476:                                        I_CmsReport.FORMAT_NOTE);
477:                        currentElement = (Element) fileNodes.get(i);
478:
479:                        // <source>
480:                        source = getChildElementTextValue(currentElement,
481:                                A_CmsImport.N_SOURCE);
482:                        // <destination>
483:
484:                        destination = getChildElementTextValue(currentElement,
485:                                A_CmsImport.N_DESTINATION);
486:
487:                        // <type>
488:                        String typeName = getChildElementTextValue(
489:                                currentElement, A_CmsImport.N_TYPE);
490:                        I_CmsResourceType type;
491:                        try {
492:                            type = OpenCms.getResourceManager()
493:                                    .getResourceType(typeName);
494:                        } catch (CmsLoaderException e) {
495:                            // unknown resource type, import resource as type "plain"
496:                            type = OpenCms.getResourceManager()
497:                                    .getResourceType(
498:                                            CmsResourceTypePlain
499:                                                    .getStaticTypeName());
500:                        }
501:
502:                        if (!type.isFolder()) {
503:                            // <uuidresource>
504:                            uuidresource = getChildElementTextValue(
505:                                    currentElement, A_CmsImport.N_UUIDRESOURCE);
506:                        } else {
507:                            uuidresource = null;
508:                        }
509:
510:                        // <datelastmodified>
511:                        timestamp = getChildElementTextValue(currentElement,
512:                                A_CmsImport.N_DATELASTMODIFIED);
513:                        if (timestamp != null) {
514:                            datelastmodified = convertTimestamp(timestamp);
515:                        } else {
516:                            datelastmodified = System.currentTimeMillis();
517:                        }
518:
519:                        // <userlastmodified>
520:                        userlastmodified = getChildElementTextValue(
521:                                currentElement, A_CmsImport.N_USERLASTMODIFIED);
522:                        userlastmodified = OpenCms.getImportExportManager()
523:                                .translateUser(userlastmodified);
524:
525:                        // <datecreated>
526:                        timestamp = getChildElementTextValue(currentElement,
527:                                A_CmsImport.N_DATECREATED);
528:                        if (timestamp != null) {
529:                            datecreated = convertTimestamp(timestamp);
530:                        } else {
531:                            datecreated = System.currentTimeMillis();
532:                        }
533:
534:                        // <usercreated>
535:                        usercreated = getChildElementTextValue(currentElement,
536:                                A_CmsImport.N_USERCREATED);
537:                        usercreated = OpenCms.getImportExportManager()
538:                                .translateUser(usercreated);
539:
540:                        // <datereleased>
541:                        timestamp = getChildElementTextValue(currentElement,
542:                                A_CmsImport.N_DATERELEASED);
543:                        if (timestamp != null) {
544:                            datereleased = convertTimestamp(timestamp);
545:                        } else {
546:                            datereleased = CmsResource.DATE_RELEASED_DEFAULT;
547:                        }
548:
549:                        // <dateexpired>
550:                        timestamp = getChildElementTextValue(currentElement,
551:                                A_CmsImport.N_DATEEXPIRED);
552:                        if (timestamp != null) {
553:                            dateexpired = convertTimestamp(timestamp);
554:                        } else {
555:                            dateexpired = CmsResource.DATE_EXPIRED_DEFAULT;
556:                        }
557:
558:                        // <flags>              
559:                        flags = getChildElementTextValue(currentElement,
560:                                A_CmsImport.N_FLAGS);
561:
562:                        // apply name translation and import path         
563:                        String translatedName = m_cms.getRequestContext()
564:                                .addSiteRoot(m_importPath + destination);
565:                        if (type.isFolder()) {
566:                            // ensure folders end with a "/"
567:                            if (!CmsResource.isFolder(translatedName)) {
568:                                translatedName += "/";
569:                            }
570:                        }
571:
572:                        // check if this resource is immutable
573:                        boolean resourceNotImmutable = checkImmutable(
574:                                translatedName, immutableResources);
575:                        translatedName = m_cms.getRequestContext()
576:                                .removeSiteRoot(translatedName);
577:                        // if the resource is not immutable and not on the exclude list, import it
578:                        if (resourceNotImmutable) {
579:                            // print out the information to the report
580:                            m_report.print(Messages.get().container(
581:                                    Messages.RPT_IMPORTING_0),
582:                                    I_CmsReport.FORMAT_NOTE);
583:                            m_report
584:                                    .print(org.opencms.report.Messages
585:                                            .get()
586:                                            .container(
587:                                                    org.opencms.report.Messages.RPT_ARGUMENT_1,
588:                                                    translatedName));
589:                            m_report
590:                                    .print(org.opencms.report.Messages
591:                                            .get()
592:                                            .container(
593:                                                    org.opencms.report.Messages.RPT_DOTS_0));
594:                            // get all properties
595:                            properties = readPropertiesFromManifest(
596:                                    currentElement, ignoredProperties);
597:
598:                            // import the resource               
599:                            CmsResource res = importResource(source,
600:                                    translatedName, type, uuidresource,
601:                                    datelastmodified, userlastmodified,
602:                                    datecreated, usercreated, datereleased,
603:                                    dateexpired, flags, properties);
604:
605:                            // if the resource was imported add the access control entrys if available
606:                            if (res != null) {
607:
608:                                List aceList = new ArrayList();
609:
610:                                // write all imported access control entries for this file
611:                                acentryNodes = currentElement.selectNodes("*/"
612:                                        + A_CmsImport.N_ACCESSCONTROL_ENTRY);
613:
614:                                // collect all access control entries
615:                                for (int j = 0; j < acentryNodes.size(); j++) {
616:                                    currentEntry = (Element) acentryNodes
617:                                            .get(j);
618:
619:                                    // get the data of the access control entry
620:                                    String id = getChildElementTextValue(
621:                                            currentEntry,
622:                                            A_CmsImport.N_ACCESSCONTROL_PRINCIPAL);
623:                                    String principalId = new CmsUUID()
624:                                            .toString();
625:                                    String principal = id.substring(id
626:                                            .indexOf('.') + 1, id.length());
627:
628:                                    try {
629:                                        if (id
630:                                                .startsWith(I_CmsPrincipal.PRINCIPAL_GROUP)) {
631:                                            principal = OpenCms
632:                                                    .getImportExportManager()
633:                                                    .translateGroup(principal);
634:                                            principalId = m_cms.readGroup(
635:                                                    principal).getId()
636:                                                    .toString();
637:                                        } else {
638:                                            principal = OpenCms
639:                                                    .getImportExportManager()
640:                                                    .translateUser(principal);
641:                                            principalId = m_cms.readUser(
642:                                                    principal).getId()
643:                                                    .toString();
644:                                        }
645:
646:                                        String acflags = getChildElementTextValue(
647:                                                currentEntry,
648:                                                A_CmsImport.N_FLAGS);
649:
650:                                        String allowed = ((Element) currentEntry
651:                                                .selectNodes(
652:                                                        "./"
653:                                                                + A_CmsImport.N_ACCESSCONTROL_PERMISSIONSET
654:                                                                + "/"
655:                                                                + A_CmsImport.N_ACCESSCONTROL_ALLOWEDPERMISSIONS)
656:                                                .get(0)).getTextTrim();
657:
658:                                        String denied = ((Element) currentEntry
659:                                                .selectNodes(
660:                                                        "./"
661:                                                                + A_CmsImport.N_ACCESSCONTROL_PERMISSIONSET
662:                                                                + "/"
663:                                                                + A_CmsImport.N_ACCESSCONTROL_DENIEDPERMISSIONS)
664:                                                .get(0)).getTextTrim();
665:
666:                                        // add the entry to the list
667:                                        aceList
668:                                                .add(getImportAccessControlEntry(
669:                                                        res, principalId,
670:                                                        allowed, denied,
671:                                                        acflags));
672:                                    } catch (CmsException e) {
673:                                        // user or group of ACE might not exist in target system, ignore ACE
674:                                        if (LOG.isWarnEnabled()) {
675:                                            LOG
676:                                                    .warn(
677:                                                            Messages
678:                                                                    .get()
679:                                                                    .getBundle()
680:                                                                    .key(
681:                                                                            Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_ACE_1,
682:                                                                            translatedName),
683:                                                            e);
684:                                        }
685:                                        m_report.println(e);
686:                                    }
687:                                }
688:
689:                                importAccessControlEntries(res, aceList);
690:                                if (OpenCms.getResourceManager()
691:                                        .getResourceType(res.getTypeId()) instanceof  I_CmsLinkParseable) {
692:                                    // store for later use
693:                                    m_parseables.add(res);
694:                                }
695:                                if (LOG.isInfoEnabled()) {
696:                                    LOG
697:                                            .info(Messages
698:                                                    .get()
699:                                                    .getBundle()
700:                                                    .key(
701:                                                            Messages.LOG_IMPORTING_4,
702:                                                            new Object[] {
703:                                                                    String
704:                                                                            .valueOf(i + 1),
705:                                                                    String
706:                                                                            .valueOf(importSize),
707:                                                                    translatedName,
708:                                                                    destination }));
709:                                }
710:                            } else {
711:                                // resource import failed, since no CmsResource was created
712:                                m_report.print(Messages.get().container(
713:                                        Messages.RPT_SKIPPING_0),
714:                                        I_CmsReport.FORMAT_NOTE);
715:                                m_report
716:                                        .println(org.opencms.report.Messages
717:                                                .get()
718:                                                .container(
719:                                                        org.opencms.report.Messages.RPT_ARGUMENT_1,
720:                                                        translatedName));
721:
722:                                if (LOG.isInfoEnabled()) {
723:                                    LOG.info(Messages.get().getBundle().key(
724:                                            Messages.LOG_SKIPPING_3,
725:                                            String.valueOf(i + 1),
726:                                            String.valueOf(importSize),
727:                                            translatedName));
728:                                }
729:                            }
730:                        } else {
731:                            // skip the file import, just print out the information to the report
732:                            m_report.print(Messages.get().container(
733:                                    Messages.RPT_SKIPPING_0),
734:                                    I_CmsReport.FORMAT_NOTE);
735:                            m_report
736:                                    .println(org.opencms.report.Messages
737:                                            .get()
738:                                            .container(
739:                                                    org.opencms.report.Messages.RPT_ARGUMENT_1,
740:                                                    translatedName));
741:
742:                            if (LOG.isInfoEnabled()) {
743:                                LOG.info(Messages.get().getBundle().key(
744:                                        Messages.LOG_SKIPPING_3,
745:                                        String.valueOf(i + 1),
746:                                        String.valueOf(importSize),
747:                                        translatedName));
748:                            }
749:                        }
750:                    }
751:                } catch (Exception e) {
752:                    m_report.println(e);
753:                    m_report.addError(e);
754:
755:                    CmsMessageContainer message = Messages
756:                            .get()
757:                            .container(
758:                                    Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
759:                    if (LOG.isDebugEnabled()) {
760:                        LOG.debug(message.key(), e);
761:                    }
762:                    throw new CmsImportExportException(message, e);
763:                }
764:            }
765:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.