Source Code Cross Referenced for CmsImportVersion5.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/CmsImportVersion5.java,v $
003:         * Date   : $Date: 2008-02-27 12:05:48 $
004:         * Version: $Revision: 1.9 $
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.CmsResourceFilter;
038:        import org.opencms.file.types.CmsResourceTypePlain;
039:        import org.opencms.file.types.I_CmsResourceType;
040:        import org.opencms.i18n.CmsMessageContainer;
041:        import org.opencms.loader.CmsLoaderException;
042:        import org.opencms.main.CmsException;
043:        import org.opencms.main.CmsLog;
044:        import org.opencms.main.OpenCms;
045:        import org.opencms.relations.CmsRelation;
046:        import org.opencms.relations.CmsRelationType;
047:        import org.opencms.relations.I_CmsLinkParseable;
048:        import org.opencms.report.I_CmsReport;
049:        import org.opencms.security.CmsAccessControlEntry;
050:        import org.opencms.security.CmsRole;
051:        import org.opencms.security.I_CmsPasswordHandler;
052:        import org.opencms.security.I_CmsPrincipal;
053:        import org.opencms.util.CmsDateUtil;
054:        import org.opencms.util.CmsUUID;
055:        import org.opencms.xml.CmsXmlException;
056:        import org.opencms.xml.CmsXmlUtils;
057:
058:        import java.io.File;
059:        import java.io.IOException;
060:        import java.text.ParseException;
061:        import java.util.ArrayList;
062:        import java.util.Collections;
063:        import java.util.HashMap;
064:        import java.util.Iterator;
065:        import java.util.List;
066:        import java.util.Map;
067:        import java.util.Map.Entry;
068:        import java.util.zip.ZipFile;
069:
070:        import org.apache.commons.logging.Log;
071:
072:        import org.dom4j.Document;
073:        import org.dom4j.Element;
074:
075:        /**
076:         * Implementation of the OpenCms Import Interface ({@link org.opencms.importexport.I_CmsImport}) for 
077:         * the import version 5.<p>
078:         * 
079:         * This import format is used in OpenCms since 6.3.0.<p>
080:         *
081:         * @author Michael Moossen 
082:         * 
083:         * @version $Revision: 1.9 $ 
084:         * 
085:         * @since 6.3.0 
086:         * 
087:         * @see org.opencms.importexport.A_CmsImport
088:         * 
089:         * @deprecated this import class is no longer in use and should only be used to import old export files
090:         */
091:        public class CmsImportVersion5 extends A_CmsImport {
092:
093:            /** The version number of this import implementation.<p> */
094:            public static final int IMPORT_VERSION = 5;
095:
096:            /** The log object for this class. */
097:            private static final Log LOG = CmsLog
098:                    .getLog(CmsImportVersion5.class);
099:
100:            /** Stores all relations defined in the import file to be created after all resources has been imported. */
101:            protected Map m_importedRelations;
102:
103:            /** Stores all resources of any type that implements the {@link I_CmsLinkParseable} interface. */
104:            protected List m_parseables;
105:
106:            /** The keep permissions flag. */
107:            protected boolean m_keepPermissions;
108:
109:            /**
110:             * Creates a new CmsImportVerion7 object.<p>
111:             */
112:            public CmsImportVersion5() {
113:
114:                m_convertToXmlPage = true;
115:            }
116:
117:            /**
118:             * @see org.opencms.importexport.I_CmsImport#getVersion()
119:             */
120:            public int getVersion() {
121:
122:                return CmsImportVersion5.IMPORT_VERSION;
123:            }
124:
125:            /**
126:             * @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)
127:             * 
128:             * @deprecated use {@link #importData(CmsObject, I_CmsReport, CmsImportParameters)} instead
129:             */
130:            public void importResources(CmsObject cms, String importPath,
131:                    I_CmsReport report, File importResource, ZipFile importZip,
132:                    Document docXml) throws CmsImportExportException {
133:
134:                CmsImportParameters params = new CmsImportParameters(
135:                        importResource != null ? importResource
136:                                .getAbsolutePath() : importZip.getName(),
137:                        importPath, false);
138:
139:                try {
140:                    importData(cms, report, params);
141:                } catch (CmsXmlException e) {
142:                    throw new CmsImportExportException(e.getMessageContainer(),
143:                            e);
144:                }
145:            }
146:
147:            /**
148:             * @see org.opencms.importexport.I_CmsImport#importData(CmsObject, I_CmsReport, CmsImportParameters)
149:             */
150:            public void importData(CmsObject cms, I_CmsReport report,
151:                    CmsImportParameters params)
152:                    throws CmsImportExportException, CmsXmlException {
153:
154:                // initialize the import
155:                initialize();
156:                m_cms = cms;
157:                m_importPath = params.getDestinationPath();
158:                m_report = report;
159:                m_keepPermissions = params.isKeepPermissions();
160:
161:                m_linkStorage = new HashMap();
162:                m_linkPropertyStorage = new HashMap();
163:                m_parseables = new ArrayList();
164:                m_importedRelations = new HashMap();
165:
166:                CmsImportHelper helper = new CmsImportHelper(params);
167:                try {
168:                    helper.openFile();
169:                    m_importResource = helper.getFolder();
170:                    m_importZip = helper.getZipFile();
171:                    m_docXml = CmsXmlUtils
172:                            .unmarshalHelper(
173:                                    helper
174:                                            .getFileBytes(CmsImportExportManager.EXPORT_MANIFEST),
175:                                    null);
176:                    // first import the user information
177:                    if (OpenCms.getRoleManager().hasRole(m_cms,
178:                            CmsRole.ACCOUNT_MANAGER)) {
179:                        importGroups();
180:                        importUsers();
181:                    }
182:                    // now import the VFS resources
183:                    readResourcesFromManifest();
184:                    convertPointerToSiblings();
185:                    rewriteParseables();
186:                    importRelations();
187:                } catch (IOException ioe) {
188:                    CmsMessageContainer msg = Messages.get().container(
189:                            Messages.ERR_IMPORTEXPORT_ERROR_READING_FILE_1,
190:                            CmsImportExportManager.EXPORT_MANIFEST);
191:                    if (LOG.isErrorEnabled()) {
192:                        LOG.error(msg.key(), ioe);
193:                    }
194:                    throw new CmsImportExportException(msg, ioe);
195:                } finally {
196:                    helper.closeFile();
197:                    cleanUp();
198:                }
199:            }
200:
201:            /**
202:             * Convert a given time stamp from a String format to a long value.<p>
203:             * 
204:             * The time stamp is either the string representation of a long value (old export format)
205:             * or a user-readable string format.
206:             * 
207:             * @param timestamp time stamp to convert
208:             * 
209:             * @return long value of the time stamp
210:             */
211:            protected long convertTimestamp(String timestamp) {
212:
213:                long value = 0;
214:                // try to parse the time stamp string
215:                // if it successes, its an old style long value
216:                try {
217:                    value = Long.parseLong(timestamp);
218:
219:                } catch (NumberFormatException e) {
220:                    // the time stamp was in in a user-readable string format, create the long value form it
221:                    try {
222:                        value = CmsDateUtil.parseHeaderDate(timestamp);
223:                    } catch (ParseException pe) {
224:                        value = System.currentTimeMillis();
225:                    }
226:                }
227:                return value;
228:            }
229:
230:            /**
231:             * Imports the relations.<p>
232:             */
233:            protected void importRelations() {
234:
235:                if (m_importedRelations.isEmpty()) {
236:                    return;
237:                }
238:
239:                m_report.println(Messages.get().container(
240:                        Messages.RPT_START_IMPORT_RELATIONS_0),
241:                        I_CmsReport.FORMAT_HEADLINE);
242:
243:                int i = 0;
244:                Iterator it = m_importedRelations.entrySet().iterator();
245:                while (it.hasNext()) {
246:                    Map.Entry entry = (Entry) it.next();
247:                    String resourcePath = (String) entry.getKey();
248:                    List relations = (List) entry.getValue();
249:
250:                    m_report.print(org.opencms.report.Messages.get().container(
251:                            org.opencms.report.Messages.RPT_SUCCESSION_2,
252:                            String.valueOf(i + 1),
253:                            String.valueOf(m_importedRelations.size())),
254:                            I_CmsReport.FORMAT_NOTE);
255:
256:                    m_report.print(Messages.get().container(
257:                            Messages.RPT_IMPORTING_RELATIONS_FOR_2,
258:                            resourcePath, new Integer(relations.size())),
259:                            I_CmsReport.FORMAT_NOTE);
260:                    m_report.print(org.opencms.report.Messages.get().container(
261:                            org.opencms.report.Messages.RPT_DOTS_0));
262:
263:                    boolean withErrors = false;
264:                    Iterator itRelations = relations.iterator();
265:                    while (itRelations.hasNext()) {
266:                        CmsRelation relation = (CmsRelation) itRelations.next();
267:                        try {
268:                            // Add the relation to the resource
269:                            m_cms.importRelation(m_cms.getSitePath(relation
270:                                    .getSource(m_cms, CmsResourceFilter.ALL)),
271:                                    m_cms.getSitePath(relation.getTarget(m_cms,
272:                                            CmsResourceFilter.ALL)), relation
273:                                            .getType().getName());
274:                        } catch (CmsException e) {
275:                            m_report.addWarning(e);
276:                            withErrors = true;
277:                            if (LOG.isWarnEnabled()) {
278:                                LOG.warn(e.getLocalizedMessage());
279:                            }
280:                            if (LOG.isDebugEnabled()) {
281:                                LOG.debug(e.getLocalizedMessage(), e);
282:                            }
283:                        }
284:                    }
285:                    if (!withErrors) {
286:                        m_report.println(
287:                                org.opencms.report.Messages.get().container(
288:                                        org.opencms.report.Messages.RPT_OK_0),
289:                                I_CmsReport.FORMAT_OK);
290:                    } else {
291:                        m_report
292:                                .println(
293:                                        org.opencms.report.Messages
294:                                                .get()
295:                                                .container(
296:                                                        org.opencms.report.Messages.RPT_FAILED_0),
297:                                        I_CmsReport.FORMAT_ERROR);
298:                    }
299:                    i++;
300:                }
301:
302:                m_report.println(Messages.get().container(
303:                        Messages.RPT_END_IMPORT_RELATIONS_0),
304:                        I_CmsReport.FORMAT_HEADLINE);
305:            }
306:
307:            /**
308:             * Reads all the relations of the resource from the <code>manifest.xml</code> file
309:             * and adds them to the according resource.<p>
310:             * 
311:             * @param resource the resource to import the relations for 
312:             * @param parentElement the current element
313:             */
314:            protected void importRelations(CmsResource resource,
315:                    Element parentElement) {
316:
317:                // Get the nodes for the relations        
318:                List relationElements = parentElement.selectNodes("./"
319:                        + A_CmsImport.N_RELATIONS + "/"
320:                        + A_CmsImport.N_RELATION);
321:
322:                List relations = new ArrayList();
323:                // iterate over the nodes
324:                Iterator itRelations = relationElements.iterator();
325:                while (itRelations.hasNext()) {
326:                    Element relationElement = (Element) itRelations.next();
327:                    String structureID = getChildElementTextValue(
328:                            relationElement,
329:                            A_CmsImport.N_RELATION_ATTRIBUTE_ID);
330:                    String targetPath = getChildElementTextValue(
331:                            relationElement,
332:                            A_CmsImport.N_RELATION_ATTRIBUTE_PATH);
333:                    String relationType = getChildElementTextValue(
334:                            relationElement,
335:                            A_CmsImport.N_RELATION_ATTRIBUTE_TYPE);
336:                    CmsUUID targetId = new CmsUUID(structureID);
337:                    CmsRelationType type = CmsRelationType
338:                            .valueOf(relationType);
339:
340:                    CmsRelation relation = new CmsRelation(resource
341:                            .getStructureId(), resource.getRootPath(),
342:                            targetId, targetPath, type);
343:
344:                    relations.add(relation);
345:                }
346:
347:                if (!relations.isEmpty()) {
348:                    m_importedRelations.put(resource.getRootPath(), relations);
349:                }
350:            }
351:
352:            /**
353:             * Imports a resource (file or folder) into the cms.<p>
354:             * 
355:             * @param source the path to the source-file
356:             * @param destination the path to the destination-file in the cms
357:             * @param type the resource type name of the file
358:             * @param uuidstructure the structure uuid of the resource
359:             * @param uuidresource the resource uuid of the resource
360:             * @param datelastmodified the last modification date of the resource
361:             * @param userlastmodified the user who made the last modifications to the resource
362:             * @param datecreated the creation date of the resource
363:             * @param usercreated the user who created 
364:             * @param datereleased the release date of the resource
365:             * @param dateexpired the expire date of the resource
366:             * @param flags the flags of the resource     
367:             * @param properties a list with properties for this resource
368:             * 
369:             * @return imported resource
370:             */
371:            protected CmsResource importResource(String source,
372:                    String destination, I_CmsResourceType type,
373:                    String uuidstructure, String uuidresource,
374:                    long datelastmodified, String userlastmodified,
375:                    long datecreated, String usercreated, long datereleased,
376:                    long dateexpired, String flags, List properties) {
377:
378:                byte[] content = null;
379:                CmsResource result = null;
380:
381:                try {
382:
383:                    // get the file content
384:                    if (source != null) {
385:                        content = getFileBytes(source);
386:                    }
387:                    int size = 0;
388:                    if (content != null) {
389:                        size = content.length;
390:                    }
391:
392:                    // get UUIDs for the user   
393:                    CmsUUID newUserlastmodified;
394:                    CmsUUID newUsercreated;
395:                    // check if user created and user last modified are valid users in this system.
396:                    // if not, use the current user
397:                    try {
398:                        newUserlastmodified = m_cms.readUser(userlastmodified)
399:                                .getId();
400:                    } catch (CmsException e) {
401:                        newUserlastmodified = m_cms.getRequestContext()
402:                                .currentUser().getId();
403:                        // datelastmodified = System.currentTimeMillis();
404:                    }
405:
406:                    try {
407:                        newUsercreated = m_cms.readUser(usercreated).getId();
408:                    } catch (CmsException e) {
409:                        newUsercreated = m_cms.getRequestContext()
410:                                .currentUser().getId();
411:                        // datecreated = System.currentTimeMillis();
412:                    }
413:
414:                    // get UUID for the structure
415:                    CmsUUID newUuidstructure = null;
416:                    if (uuidstructure != null) {
417:                        // create a UUID from the provided string
418:                        newUuidstructure = new CmsUUID(uuidstructure);
419:                    } else {
420:                        // if null generate a new structure id
421:                        newUuidstructure = new CmsUUID();
422:                    }
423:
424:                    // get UUIDs for the resource and content        
425:                    CmsUUID newUuidresource = null;
426:                    if ((uuidresource != null) && (!type.isFolder())) {
427:                        // create a UUID from the provided string
428:                        newUuidresource = new CmsUUID(uuidresource);
429:                    } else {
430:                        // folders get always a new resource record UUID
431:                        newUuidresource = new CmsUUID();
432:                    }
433:
434:                    // create a new CmsResource                         
435:                    CmsResource resource = new CmsResource(newUuidstructure,
436:                            newUuidresource, destination, type.getTypeId(),
437:                            type.isFolder(), new Integer(flags).intValue(),
438:                            m_cms.getRequestContext().currentProject()
439:                                    .getUuid(), CmsResource.STATE_NEW,
440:                            datecreated, newUsercreated, datelastmodified,
441:                            newUserlastmodified, datereleased, dateexpired, 1,
442:                            size, System.currentTimeMillis(), 0);
443:
444:                    // import this resource in the VFS
445:                    result = m_cms.importResource(destination, resource,
446:                            content, properties);
447:
448:                    if (result != null) {
449:                        m_report.println(
450:                                org.opencms.report.Messages.get().container(
451:                                        org.opencms.report.Messages.RPT_OK_0),
452:                                I_CmsReport.FORMAT_OK);
453:                    }
454:                } catch (Exception exc) {
455:                    // an error while importing the file
456:                    m_report.println(exc);
457:                    try {
458:                        // Sleep some time after an error so that the report output has a chance to keep up
459:                        Thread.sleep(1000);
460:                    } catch (Exception e) {
461:                        // 
462:                    }
463:                }
464:                return result;
465:            }
466:
467:            /**
468:             * @see org.opencms.importexport.A_CmsImport#importUser(String, String, String, String, String, String, long, Map, List)
469:             */
470:            protected void importUser(String name, String flags,
471:                    String password, String firstname, String lastname,
472:                    String email, long dateCreated, Map userInfo,
473:                    List userGroups) throws CmsImportExportException {
474:
475:                boolean convert = false;
476:
477:                Map config = OpenCms.getPasswordHandler().getConfiguration();
478:                if ((config != null)
479:                        && config
480:                                .containsKey(I_CmsPasswordHandler.CONVERT_DIGEST_ENCODING)) {
481:                    convert = Boolean
482:                            .valueOf(
483:                                    (String) config
484:                                            .get(I_CmsPasswordHandler.CONVERT_DIGEST_ENCODING))
485:                            .booleanValue();
486:                }
487:
488:                if (convert) {
489:                    password = convertDigestEncoding(password);
490:                }
491:
492:                super .importUser(name, flags, password, firstname, lastname,
493:                        email, dateCreated, userInfo, userGroups);
494:            }
495:
496:            /**
497:             * Reads all file nodes plus their meta-information (properties, ACL) 
498:             * from the <code>manifest.xml</code> and imports them as Cms resources to the VFS.<p>
499:             * 
500:             * @throws CmsImportExportException if something goes wrong
501:             */
502:            protected void readResourcesFromManifest()
503:                    throws CmsImportExportException {
504:
505:                String source = null, destination = null, uuidstructure = null, uuidresource = null, userlastmodified = null, usercreated = null, flags = null, timestamp = null;
506:                long datelastmodified = 0, datecreated = 0, datereleased = 0, dateexpired = 0;
507:
508:                List fileNodes = null, acentryNodes = null;
509:                Element currentElement = null, currentEntry = null;
510:                List properties = null;
511:
512:                // get list of immutable resources
513:                List immutableResources = OpenCms.getImportExportManager()
514:                        .getImmutableResources();
515:                if (immutableResources == null) {
516:                    immutableResources = Collections.EMPTY_LIST;
517:                }
518:                if (LOG.isDebugEnabled()) {
519:                    LOG
520:                            .debug(Messages
521:                                    .get()
522:                                    .getBundle()
523:                                    .key(
524:                                            Messages.LOG_IMPORTEXPORT_IMMUTABLE_RESOURCES_SIZE_1,
525:                                            Integer.toString(immutableResources
526:                                                    .size())));
527:                }
528:                // get list of ignored properties
529:                List ignoredProperties = OpenCms.getImportExportManager()
530:                        .getIgnoredProperties();
531:                if (ignoredProperties == null) {
532:                    ignoredProperties = Collections.EMPTY_LIST;
533:                }
534:
535:                // get the desired page type for imported pages
536:                m_convertToXmlPage = OpenCms.getImportExportManager()
537:                        .convertToXmlPage();
538:
539:                try {
540:                    // get all file-nodes
541:                    fileNodes = m_docXml.selectNodes("//" + A_CmsImport.N_FILE);
542:                    int importSize = fileNodes.size();
543:
544:                    // walk through all files in manifest
545:                    for (int i = 0; i < fileNodes.size(); i++) {
546:                        m_report
547:                                .print(
548:                                        org.opencms.report.Messages
549:                                                .get()
550:                                                .container(
551:                                                        org.opencms.report.Messages.RPT_SUCCESSION_2,
552:                                                        String.valueOf(i + 1),
553:                                                        String
554:                                                                .valueOf(importSize)),
555:                                        I_CmsReport.FORMAT_NOTE);
556:                        currentElement = (Element) fileNodes.get(i);
557:
558:                        // <source>
559:                        source = getChildElementTextValue(currentElement,
560:                                A_CmsImport.N_SOURCE);
561:                        // <destination>
562:                        destination = getChildElementTextValue(currentElement,
563:                                A_CmsImport.N_DESTINATION);
564:
565:                        // <type>
566:                        String typeName = getChildElementTextValue(
567:                                currentElement, A_CmsImport.N_TYPE);
568:                        I_CmsResourceType type;
569:                        try {
570:                            type = OpenCms.getResourceManager()
571:                                    .getResourceType(typeName);
572:                        } catch (CmsLoaderException e) {
573:                            type = OpenCms.getResourceManager()
574:                                    .getResourceType(
575:                                            CmsResourceTypePlain
576:                                                    .getStaticTypeId());
577:                        }
578:
579:                        // <uuidstructure>
580:                        uuidstructure = getChildElementTextValue(
581:                                currentElement, A_CmsImport.N_UUIDSTRUCTURE);
582:
583:                        // <uuidresource>
584:                        if (!type.isFolder()) {
585:                            uuidresource = getChildElementTextValue(
586:                                    currentElement, A_CmsImport.N_UUIDRESOURCE);
587:                        } else {
588:                            uuidresource = null;
589:                        }
590:
591:                        // <datelastmodified>
592:                        timestamp = getChildElementTextValue(currentElement,
593:                                A_CmsImport.N_DATELASTMODIFIED);
594:                        if (timestamp != null) {
595:                            datelastmodified = convertTimestamp(timestamp);
596:                        } else {
597:                            datelastmodified = System.currentTimeMillis();
598:                        }
599:
600:                        // <userlastmodified>
601:                        userlastmodified = getChildElementTextValue(
602:                                currentElement, A_CmsImport.N_USERLASTMODIFIED);
603:                        userlastmodified = OpenCms.getImportExportManager()
604:                                .translateUser(userlastmodified);
605:
606:                        // <datecreated>
607:                        timestamp = getChildElementTextValue(currentElement,
608:                                A_CmsImport.N_DATECREATED);
609:                        if (timestamp != null) {
610:                            datecreated = convertTimestamp(timestamp);
611:                        } else {
612:                            datecreated = System.currentTimeMillis();
613:                        }
614:
615:                        // <usercreated>
616:                        usercreated = getChildElementTextValue(currentElement,
617:                                A_CmsImport.N_USERCREATED);
618:                        usercreated = OpenCms.getImportExportManager()
619:                                .translateUser(usercreated);
620:
621:                        // <datereleased>
622:                        timestamp = getChildElementTextValue(currentElement,
623:                                A_CmsImport.N_DATERELEASED);
624:                        if (timestamp != null) {
625:                            datereleased = convertTimestamp(timestamp);
626:                        } else {
627:                            datereleased = CmsResource.DATE_RELEASED_DEFAULT;
628:                        }
629:
630:                        // <dateexpired>
631:                        timestamp = getChildElementTextValue(currentElement,
632:                                A_CmsImport.N_DATEEXPIRED);
633:                        if (timestamp != null) {
634:                            dateexpired = convertTimestamp(timestamp);
635:                        } else {
636:                            dateexpired = CmsResource.DATE_EXPIRED_DEFAULT;
637:                        }
638:
639:                        // <flags>              
640:                        flags = getChildElementTextValue(currentElement,
641:                                A_CmsImport.N_FLAGS);
642:
643:                        // apply name translation and import path         
644:                        String translatedName = m_cms.getRequestContext()
645:                                .addSiteRoot(m_importPath + destination);
646:                        if (type.isFolder()) {
647:                            // ensure folders end with a "/"
648:                            if (!CmsResource.isFolder(translatedName)) {
649:                                translatedName += "/";
650:                            }
651:                        }
652:
653:                        // check if this resource is immutable
654:                        boolean resourceNotImmutable = checkImmutable(
655:                                translatedName, immutableResources);
656:                        translatedName = m_cms.getRequestContext()
657:                                .removeSiteRoot(translatedName);
658:                        // if the resource is not immutable and not on the exclude list, import it
659:                        if (resourceNotImmutable) {
660:                            // print out the information to the report
661:                            m_report.print(Messages.get().container(
662:                                    Messages.RPT_IMPORTING_0),
663:                                    I_CmsReport.FORMAT_NOTE);
664:                            m_report
665:                                    .print(org.opencms.report.Messages
666:                                            .get()
667:                                            .container(
668:                                                    org.opencms.report.Messages.RPT_ARGUMENT_1,
669:                                                    translatedName));
670:                            m_report
671:                                    .print(org.opencms.report.Messages
672:                                            .get()
673:                                            .container(
674:                                                    org.opencms.report.Messages.RPT_DOTS_0));
675:                            // get all properties
676:                            properties = readPropertiesFromManifest(
677:                                    currentElement, ignoredProperties);
678:
679:                            boolean exists = m_cms.existsResource(
680:                                    translatedName, CmsResourceFilter.ALL);
681:
682:                            // import the resource               
683:                            CmsResource res = importResource(source,
684:                                    translatedName, type, uuidstructure,
685:                                    uuidresource, datelastmodified,
686:                                    userlastmodified, datecreated, usercreated,
687:                                    datereleased, dateexpired, flags,
688:                                    properties);
689:
690:                            if (res != null) {
691:                                // only set permissions if the resource did not exists or if the keep permissions flag is not set
692:                                if (!exists || !m_keepPermissions) {
693:                                    // if the resource was imported add the access control entries if available
694:                                    List aceList = new ArrayList();
695:
696:                                    // write all imported access control entries for this file
697:                                    acentryNodes = currentElement
698:                                            .selectNodes("*/"
699:                                                    + A_CmsImport.N_ACCESSCONTROL_ENTRY);
700:
701:                                    // collect all access control entries
702:                                    for (int j = 0; j < acentryNodes.size(); j++) {
703:                                        currentEntry = (Element) acentryNodes
704:                                                .get(j);
705:
706:                                        // get the data of the access control entry
707:                                        String id = getChildElementTextValue(
708:                                                currentEntry,
709:                                                A_CmsImport.N_ACCESSCONTROL_PRINCIPAL);
710:                                        String principalId = new CmsUUID()
711:                                                .toString();
712:                                        String principal = id.substring(id
713:                                                .indexOf('.') + 1, id.length());
714:
715:                                        try {
716:                                            if (id
717:                                                    .startsWith(I_CmsPrincipal.PRINCIPAL_GROUP)) {
718:                                                principal = OpenCms
719:                                                        .getImportExportManager()
720:                                                        .translateGroup(
721:                                                                principal);
722:                                                principalId = m_cms.readGroup(
723:                                                        principal).getId()
724:                                                        .toString();
725:                                            } else if (id
726:                                                    .startsWith(I_CmsPrincipal.PRINCIPAL_USER)) {
727:                                                principal = OpenCms
728:                                                        .getImportExportManager()
729:                                                        .translateUser(
730:                                                                principal);
731:                                                principalId = m_cms.readUser(
732:                                                        principal).getId()
733:                                                        .toString();
734:                                            } else if (id
735:                                                    .startsWith(CmsRole.PRINCIPAL_ROLE)) {
736:                                                principalId = CmsRole
737:                                                        .valueOfRoleName(
738:                                                                principal)
739:                                                        .getId().toString();
740:                                            } else if (id
741:                                                    .equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME)) {
742:                                                principalId = CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID
743:                                                        .toString();
744:                                            } else if (id
745:                                                    .equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME)) {
746:                                                principalId = CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID
747:                                                        .toString();
748:                                            } else {
749:                                                if (LOG.isWarnEnabled()) {
750:                                                    LOG
751:                                                            .warn(Messages
752:                                                                    .get()
753:                                                                    .getBundle()
754:                                                                    .key(
755:                                                                            Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_ACE_1,
756:                                                                            id));
757:                                                }
758:                                            }
759:
760:                                            String acflags = getChildElementTextValue(
761:                                                    currentEntry,
762:                                                    A_CmsImport.N_FLAGS);
763:
764:                                            String allowed = ((Element) currentEntry
765:                                                    .selectNodes(
766:                                                            "./"
767:                                                                    + A_CmsImport.N_ACCESSCONTROL_PERMISSIONSET
768:                                                                    + "/"
769:                                                                    + A_CmsImport.N_ACCESSCONTROL_ALLOWEDPERMISSIONS)
770:                                                    .get(0)).getTextTrim();
771:
772:                                            String denied = ((Element) currentEntry
773:                                                    .selectNodes(
774:                                                            "./"
775:                                                                    + A_CmsImport.N_ACCESSCONTROL_PERMISSIONSET
776:                                                                    + "/"
777:                                                                    + A_CmsImport.N_ACCESSCONTROL_DENIEDPERMISSIONS)
778:                                                    .get(0)).getTextTrim();
779:
780:                                            // add the entry to the list
781:                                            aceList
782:                                                    .add(getImportAccessControlEntry(
783:                                                            res, principalId,
784:                                                            allowed, denied,
785:                                                            acflags));
786:                                        } catch (CmsException e) {
787:                                            // user or group of ACE might not exist in target system, ignore ACE
788:                                            if (LOG.isWarnEnabled()) {
789:                                                LOG
790:                                                        .warn(
791:                                                                Messages
792:                                                                        .get()
793:                                                                        .getBundle()
794:                                                                        .key(
795:                                                                                Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_ACE_1,
796:                                                                                translatedName),
797:                                                                e);
798:                                            }
799:                                            m_report.println(e);
800:                                            m_report.addError(e);
801:                                        }
802:                                    }
803:                                    importAccessControlEntries(res, aceList);
804:                                }
805:
806:                                // Add the relations for the resource
807:                                importRelations(res, currentElement);
808:
809:                                if (OpenCms.getResourceManager()
810:                                        .getResourceType(res.getTypeId()) instanceof  I_CmsLinkParseable) {
811:                                    // store for later use
812:                                    m_parseables.add(res);
813:                                }
814:
815:                                if (LOG.isInfoEnabled()) {
816:                                    LOG
817:                                            .info(Messages
818:                                                    .get()
819:                                                    .getBundle()
820:                                                    .key(
821:                                                            Messages.LOG_IMPORTING_4,
822:                                                            new Object[] {
823:                                                                    String
824:                                                                            .valueOf(i + 1),
825:                                                                    String
826:                                                                            .valueOf(importSize),
827:                                                                    translatedName,
828:                                                                    destination }));
829:                                }
830:                            } else {
831:                                // resource import failed, since no CmsResource was created
832:                                m_report.print(Messages.get().container(
833:                                        Messages.RPT_SKIPPING_0),
834:                                        I_CmsReport.FORMAT_NOTE);
835:                                m_report
836:                                        .println(org.opencms.report.Messages
837:                                                .get()
838:                                                .container(
839:                                                        org.opencms.report.Messages.RPT_ARGUMENT_1,
840:                                                        translatedName));
841:
842:                                if (LOG.isInfoEnabled()) {
843:                                    LOG.info(Messages.get().getBundle().key(
844:                                            Messages.LOG_SKIPPING_3,
845:                                            String.valueOf(i + 1),
846:                                            String.valueOf(importSize),
847:                                            translatedName));
848:                                }
849:                            }
850:
851:                        } else {
852:                            // skip the file import, just print out the information to the report
853:
854:                            m_report.print(Messages.get().container(
855:                                    Messages.RPT_SKIPPING_0),
856:                                    I_CmsReport.FORMAT_NOTE);
857:                            m_report
858:                                    .println(org.opencms.report.Messages
859:                                            .get()
860:                                            .container(
861:                                                    org.opencms.report.Messages.RPT_ARGUMENT_1,
862:                                                    translatedName));
863:
864:                            if (LOG.isInfoEnabled()) {
865:                                LOG.info(Messages.get().getBundle().key(
866:                                        Messages.LOG_SKIPPING_3,
867:                                        String.valueOf(i + 1),
868:                                        String.valueOf(importSize),
869:                                        translatedName));
870:                            }
871:                        }
872:                    }
873:                } catch (Exception e) {
874:                    m_report.println(e);
875:                    m_report.addError(e);
876:
877:                    CmsMessageContainer message = Messages
878:                            .get()
879:                            .container(
880:                                    Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0);
881:                    if (LOG.isDebugEnabled()) {
882:                        LOG.debug(message.key(), e);
883:                    }
884:
885:                    throw new CmsImportExportException(message, e);
886:                }
887:            }
888:
889:            /**
890:             * Rewrites all parseable files, to assure link check.<p>
891:             */
892:            protected void rewriteParseables() {
893:
894:                if (m_parseables.isEmpty()) {
895:                    return;
896:                }
897:
898:                m_report.println(Messages.get().container(
899:                        Messages.RPT_START_PARSE_LINKS_0),
900:                        I_CmsReport.FORMAT_HEADLINE);
901:
902:                int i = 0;
903:                Iterator it = m_parseables.iterator();
904:                while (it.hasNext()) {
905:                    CmsResource res = (CmsResource) it.next();
906:
907:                    m_report.print(org.opencms.report.Messages.get().container(
908:                            org.opencms.report.Messages.RPT_SUCCESSION_2,
909:                            String.valueOf(i + 1),
910:                            String.valueOf(m_parseables.size())),
911:                            I_CmsReport.FORMAT_NOTE);
912:
913:                    m_report.print(Messages.get().container(
914:                            Messages.RPT_PARSE_LINKS_FOR_1,
915:                            m_cms.getSitePath(res)), I_CmsReport.FORMAT_NOTE);
916:                    m_report.print(org.opencms.report.Messages.get().container(
917:                            org.opencms.report.Messages.RPT_DOTS_0));
918:
919:                    try {
920:                        // make sure the date last modified is kept...
921:                        CmsFile file = m_cms.readFile(res);
922:                        file.setDateLastModified(res.getDateLastModified());
923:                        m_cms.writeFile(file);
924:
925:                        m_report.println(
926:                                org.opencms.report.Messages.get().container(
927:                                        org.opencms.report.Messages.RPT_OK_0),
928:                                I_CmsReport.FORMAT_OK);
929:                    } catch (Throwable e) {
930:                        m_report.addWarning(e);
931:                        m_report
932:                                .println(
933:                                        org.opencms.report.Messages
934:                                                .get()
935:                                                .container(
936:                                                        org.opencms.report.Messages.RPT_FAILED_0),
937:                                        I_CmsReport.FORMAT_ERROR);
938:                        if (LOG.isWarnEnabled()) {
939:                            LOG.warn(Messages.get().getBundle().key(
940:                                    Messages.LOG_IMPORTEXPORT_REWRITING_1,
941:                                    res.getRootPath()));
942:                        }
943:                        if (LOG.isDebugEnabled()) {
944:                            LOG.debug(e.getLocalizedMessage(), e);
945:                        }
946:                    }
947:                    i++;
948:                }
949:
950:                m_report.println(Messages.get().container(
951:                        Messages.RPT_END_PARSE_LINKS_0),
952:                        I_CmsReport.FORMAT_HEADLINE);
953:            }
954:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.