001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.importexport; 029 030import org.opencms.configuration.CmsConfigurationManager; 031import org.opencms.configuration.CmsParameterConfiguration; 032import org.opencms.db.CmsDbEntryNotFoundException; 033import org.opencms.db.log.CmsLogEntry; 034import org.opencms.file.CmsDataAccessException; 035import org.opencms.file.CmsFile; 036import org.opencms.file.CmsObject; 037import org.opencms.file.CmsProject; 038import org.opencms.file.CmsProperty; 039import org.opencms.file.CmsResource; 040import org.opencms.file.CmsResourceFilter; 041import org.opencms.file.CmsUser; 042import org.opencms.file.CmsVfsResourceNotFoundException; 043import org.opencms.file.types.CmsResourceTypePlain; 044import org.opencms.file.types.CmsResourceTypeXmlContainerPage; 045import org.opencms.file.types.I_CmsResourceType; 046import org.opencms.i18n.CmsMessageContainer; 047import org.opencms.loader.CmsLoaderException; 048import org.opencms.lock.CmsLock; 049import org.opencms.main.CmsException; 050import org.opencms.main.CmsIllegalStateException; 051import org.opencms.main.CmsLog; 052import org.opencms.main.OpenCms; 053import org.opencms.relations.CmsRelation; 054import org.opencms.relations.CmsRelationType; 055import org.opencms.relations.I_CmsLinkParseable; 056import org.opencms.report.I_CmsReport; 057import org.opencms.security.CmsAccessControlEntry; 058import org.opencms.security.CmsOrganizationalUnit; 059import org.opencms.security.CmsRole; 060import org.opencms.security.I_CmsPasswordHandler; 061import org.opencms.security.I_CmsPrincipal; 062import org.opencms.util.CmsCollectionsGenericWrapper; 063import org.opencms.util.CmsDataTypeUtil; 064import org.opencms.util.CmsDateUtil; 065import org.opencms.util.CmsStringUtil; 066import org.opencms.util.CmsUUID; 067import org.opencms.xml.CmsXmlEntityResolver; 068import org.opencms.xml.CmsXmlErrorHandler; 069 070import java.io.File; 071import java.io.IOException; 072import java.io.InputStream; 073import java.text.ParseException; 074import java.util.ArrayList; 075import java.util.Collections; 076import java.util.Comparator; 077import java.util.HashMap; 078import java.util.HashSet; 079import java.util.Iterator; 080import java.util.List; 081import java.util.Map; 082import java.util.Map.Entry; 083import java.util.Set; 084import java.util.zip.ZipFile; 085 086import org.apache.commons.codec.binary.Base64; 087import org.apache.commons.digester3.Digester; 088import org.apache.commons.logging.Log; 089 090import org.dom4j.Document; 091import org.xml.sax.SAXException; 092 093import com.google.common.collect.ComparisonChain; 094 095/** 096 * Adds the XML handler rules for import and export of resources and accounts.<p> 097 * 098 * @since 7.0.4 099 */ 100 101@Deprecated 102public class CmsImportVersion7 implements I_CmsImport { 103 104 /** Tag for the "userinfo / entry name" attribute, contains the additional user info entry name. */ 105 public static final String A_NAME = "name"; 106 107 /** Tag for the "type" attribute, contains the property type. */ 108 public static final String A_TYPE = "type"; 109 110 /** The name of the DTD for this import version. */ 111 public static final String DTD_FILENAME = "opencms-import7.dtd"; 112 113 /** The location of the OpenCms configuration DTD if the default prefix is the system ID. */ 114 public static final String DTD_LOCATION = "org/opencms/importexport/"; 115 116 /** The version number of this import implementation.<p> */ 117 public static final int IMPORT_VERSION7 = 7; 118 119 /** Tag for the "allowed" node, to identify allowed user permissions. */ 120 public static final String N_ACCESSCONTROL_ALLOWEDPERMISSIONS = "allowed"; 121 122 /** Tag for the "denied" node, to identify denied user permissions. */ 123 public static final String N_ACCESSCONTROL_DENIEDPERMISSIONS = "denied"; 124 125 /** Tag for the "accesscontrol" node, to identify access control entries. */ 126 public static final String N_ACCESSCONTROL_ENTRIES = "accesscontrol"; 127 128 /** Tag for the "accessentry" node, to identify a single access control entry. */ 129 public static final String N_ACCESSCONTROL_ENTRY = "accessentry"; 130 131 /** Tag for the "permissionset" node, to identify a permission set. */ 132 public static final String N_ACCESSCONTROL_PERMISSIONSET = "permissionset"; 133 134 /** Tag for the "uuidprincipal" node, to identify a principal UUID. */ 135 public static final String N_ACCESSCONTROL_PRINCIPAL = "uuidprincipal"; 136 137 /** Tag for the "accounts" node. */ 138 public static final String N_ACCOUNTS = "accounts"; 139 140 /** Tag for the "datecreated" node, contains the date created VFS file attribute. */ 141 public static final String N_DATECREATED = "datecreated"; 142 143 /** Tag for the "dateexpired" node, contains the expiration date VFS file attribute. */ 144 public static final String N_DATEEXPIRED = "dateexpired"; 145 146 /** Tag for the "datelastmodified" node, contains the date last modified VFS file attribute. */ 147 public static final String N_DATELASTMODIFIED = "datelastmodified"; 148 149 /** Tag for the "datereleased" node, contains the release date VFS file attribute. */ 150 public static final String N_DATERELEASED = "datereleased"; 151 152 /** Tag for the "description" node, contains a users description test. */ 153 public static final String N_DESCRIPTION = "description"; 154 155 /** Tag for the "destination" node, contains target VFS file name. */ 156 public static final String N_DESTINATION = "destination"; 157 158 /** Tag for the "email" node, contains a users email. */ 159 public static final String N_EMAIL = "email"; 160 161 /** Tag for the "file" node, container node for all VFS resources. */ 162 public static final String N_FILE = "file"; 163 164 /** Tag for the "files" node, container node for all VFS resources. */ 165 public static final String N_FILES = "files"; 166 167 /** Tag for the "firstname" node, contains a users first name. */ 168 public static final String N_FIRSTNAME = "firstname"; 169 170 /** Tag for the "flags" node, contains the flags of a VFS resource. */ 171 public static final String N_FLAGS = "flags"; 172 173 /** Tag for the "group" node, contains a group name. */ 174 public static final String N_GROUP = "group"; 175 176 /** Tag for the "groups" node, contains a users group data. */ 177 public static final String N_GROUPS = "groups"; 178 179 /** Tag for the "id" relation attribute, contains the structure id of the target resource of the relation. */ 180 public static final String N_ID = "id"; 181 182 /** Tag for the "lastname" node, contains a users last name. */ 183 public static final String N_LASTNAME = "lastname"; 184 185 /** Tag for the "managersgroup" node, contains name of the managers group of the project. */ 186 public static final String N_MANAGERSGROUP = "managersgroup"; 187 188 /** Tag for the "name" node, contains the name of a property. */ 189 public static final String N_NAME = "name"; 190 191 /** Tag for the "orgunit" node, starts the organizational unit data. */ 192 public static final String N_ORGUNIT = "orgunit"; 193 194 /** Tag for the "orgunits" node, starts the organizational unit data. */ 195 public static final String N_ORGUNITS = "orgunits"; 196 197 /** Tag for the "parentgroup" node, contains a groups parent group fqn. */ 198 public static final String N_PARENTGROUP = "parentgroup"; 199 200 /** Tag for the "password" node, contains a users encrypted password. */ 201 public static final String N_PASSWORD = "password"; 202 203 /** Tag for the "path" relation attribute, contains the path to the target resource of the relation. */ 204 public static final String N_PATH = "path"; 205 206 /** Tag for the "project" node, starts the project data. */ 207 public static final String N_PROJECT = "project"; 208 209 /** Tag for the "projects" node, starts the project data. */ 210 public static final String N_PROJECTS = "projects"; 211 212 /** Tag for the "properties" node, starts the list of properties of a VFS resource. */ 213 public static final String N_PROPERTIES = "properties"; 214 215 /** Tag for the "property" node, starts a property for a VFS resource. */ 216 public static final String N_PROPERTY = "property"; 217 218 /** Tag in the {@link CmsImportExportManager#EXPORT_MANIFEST} for the "relation" node, starts a relation for a VFS resource. */ 219 public static final String N_RELATION = "relation"; 220 221 /** Tag for the "relations" node, starts the list of relations of a VFS resources. */ 222 public static final String N_RELATIONS = "relations"; 223 224 /** Tag for the "resource" node, contains the a organizational unit resource name. */ 225 public static final String N_RESOURCE = "resource"; 226 227 /** Tag for the "resources" node, contains the list of organizational unit resources. */ 228 public static final String N_RESOURCES = "resources"; 229 230 /** Tag for the "source" node, contains the source path of a VFS resource in the import zip (or folder). */ 231 public static final String N_SOURCE = "source"; 232 233 /** Tag for the "type" node, the resource type name of a VFS resource. */ 234 public static final String N_TYPE = "type"; 235 236 /** Tag for the "user" node, starts the user data. */ 237 public static final String N_USER = "user"; 238 239 /** Tag for the "usercreated" node, contains the name of the user who created the VFS resource. */ 240 public static final String N_USERCREATED = "usercreated"; 241 242 /** Tag for the "usergroup" node, the name of a users group. */ 243 public static final String N_USERGROUP = "usergroup"; 244 245 /** Tag for the "usergroups" node, starts the users group data. */ 246 public static final String N_USERGROUPS = "usergroups"; 247 248 /** Tag for the "userinfo" node, contains the additional user info. */ 249 public static final String N_USERINFO = "userinfo"; 250 251 /** Tag for the "userinfo/entry" node, contains the additional user info entry value. */ 252 public static final String N_USERINFO_ENTRY = "entry"; 253 254 /** Tag for the "userlastmodified" node, contains the name of the user who last modified the VFS resource. */ 255 public static final String N_USERLASTMODIFIED = "userlastmodified"; 256 257 /** Tag for the "userrole" node, contains an users role name. */ 258 public static final String N_USERROLE = "userrole"; 259 260 /** Tag for the "userroles" node, starts the users role data. */ 261 public static final String N_USERROLES = "userroles"; 262 263 /** Tag for the "users" node, starts the list of users. */ 264 public static final String N_USERS = "users"; 265 266 /** Tag for the "usersgroup" node, contains name of the users group of the project. */ 267 public static final String N_USERSGROUP = "usersgroup"; 268 269 /** Tag for the "uuidresource" node, contains a the resource UUID of a VFS resource. */ 270 public static final String N_UUIDRESOURCE = "uuidresource"; 271 272 /** Tag for the "uuidstructure" node, only required for backward compatibility with import version 2. */ 273 public static final String N_UUIDSTRUCTURE = "uuidstructure"; 274 275 /** Tag for the "value" node, contains the value of a property. */ 276 public static final String N_VALUE = "value"; 277 278 /** Value for the "shared" property type attribute value. */ 279 public static final String PROPERTY_ATTRIB_TYPE_SHARED = "shared"; 280 281 /** The log object for this class. */ 282 private static final Log LOG = CmsLog.getLog(CmsImportVersion7.class); 283 284 /** The ACE flags value. */ 285 private int m_aceFlags; 286 287 /** The ACE allowed permissions value. */ 288 private int m_acePermissionsAllowed; 289 290 /** The ACE denied permissions value. */ 291 private int m_acePermissionsDenied; 292 293 /** The ACE principal id value. */ 294 private CmsUUID m_acePrincipalId; 295 296 /** The list of ACEs for the current imported resource. */ 297 private List<CmsAccessControlEntry> m_aces; 298 299 /** The cms object. */ 300 private CmsObject m_cms; 301 302 /** The set of resource ids of files which actually are contained in the zip file. */ 303 private Set<CmsUUID> m_contentFiles = new HashSet<CmsUUID>(); 304 305 /** The date created value. */ 306 private long m_dateCreated; 307 308 /** The date expired value. */ 309 private long m_dateExpired = CmsResource.DATE_EXPIRED_DEFAULT; 310 311 /** The date last modified value. */ 312 private long m_dateLastModified; 313 314 /** The date released value. */ 315 private long m_dateReleased = CmsResource.DATE_RELEASED_DEFAULT; 316 317 /** The destination value. */ 318 private String m_destination; 319 320 /** The current file counter. */ 321 private int m_fileCounter; 322 323 /** The flags value. */ 324 private int m_flags; 325 326 /** The description of the current group to import. */ 327 private String m_groupDescription; 328 329 /** The flags of the current group to import. */ 330 private int m_groupFlags; 331 332 /** The name of the current group to import. */ 333 private String m_groupName; 334 335 /** The parent of the current group to import. */ 336 private String m_groupParent; 337 338 /** Map of all parent groups that could not be set immediately, because of the import order. */ 339 private Map<String, List<String>> m_groupParents; 340 341 /** The import helper. */ 342 private CmsImportHelper m_helper; 343 344 /** List of ignored properties. */ 345 private List<String> m_ignoredProperties; 346 347 /** List of immutable resources. */ 348 private List<String> m_immutables; 349 350 /** The flag to import ACEs. */ 351 private boolean m_importACEs; 352 353 /** The membership structure. */ 354 private Map<String, Map<String, Map<String, String>>> m_membership; 355 356 /** The current imported organizational unit. */ 357 private CmsOrganizationalUnit m_orgUnit; 358 359 /** The organizational unit description. */ 360 private String m_orgUnitDescription; 361 362 /** The organizational unit flags. */ 363 private int m_orgUnitFlags; 364 365 /** The organizational unit fqn. */ 366 private String m_orgUnitName; 367 368 /** The map of organizational unit resources, this is a global field that will be use at the end of the import. */ 369 private Map<String, List<String>> m_orgUnitResources; 370 371 /** The import parameters to use. */ 372 private CmsImportParameters m_parameters; 373 374 /** The list of resource to be parsed, this is a global list, which will be handled at the end of the import. */ 375 private List<CmsResource> m_parseables; 376 377 /** The project description. */ 378 private String m_projectDescription; 379 380 /** The project managers group name. */ 381 private String m_projectManagers; 382 383 /** The project fqn. */ 384 private String m_projectName; 385 386 /** The current read project resources. */ 387 private List<String> m_projectResources; 388 389 /** The project users group name. */ 390 private String m_projectUsers; 391 392 /** The map of properties for current imported resource. */ 393 private Map<String, CmsProperty> m_properties; 394 395 /** The property name value. */ 396 private String m_propertyName; 397 398 /** The property value value. */ 399 private String m_propertyValue; 400 401 /** The relation id value. */ 402 private CmsUUID m_relationId; 403 404 /** The relation path value. */ 405 private String m_relationPath; 406 407 /** The map of relations to be created, this is a global map, which will be handled at the end of the import. */ 408 private Map<String, List<CmsRelation>> m_relations; 409 410 /** The relation type value. */ 411 private CmsRelationType m_relationType; 412 413 /** The report. */ 414 private I_CmsReport m_report; 415 416 /** The current imported resource. */ 417 private CmsResource m_resource; 418 419 /** The resource id value. */ 420 private CmsUUID m_resourceId; 421 422 /** The source value. */ 423 private String m_source; 424 425 /** The structure id value. */ 426 private CmsUUID m_structureId; 427 428 /** Possible exception during xml parsing. */ 429 private Throwable m_throwable; 430 431 /** The total number of files to import. */ 432 private int m_totalFiles; 433 434 /** The type value. */ 435 private I_CmsResourceType m_type; 436 437 /** The current imported user. */ 438 private CmsUser m_user; 439 440 /** The user created value. */ 441 private CmsUUID m_userCreated; 442 443 /** The current user date created. */ 444 private long m_userDateCreated; 445 446 /** The current user email. */ 447 private String m_userEmail; 448 449 /** The current user first name. */ 450 private String m_userFirstname; 451 452 /** The current user flags. */ 453 private int m_userFlags; 454 455 /** The additional information for the current imported user. */ 456 private Map<String, Object> m_userInfos; 457 458 /** The user last modified value. */ 459 private CmsUUID m_userLastModified; 460 461 /** The current user last name. */ 462 private String m_userLastname; 463 464 /** The current user name. */ 465 private String m_userName; 466 467 /** The current user password. */ 468 private String m_userPassword; 469 470 /** The export version. */ 471 private int m_version; 472 473 /** 474 * Public constructor.<p> 475 */ 476 public CmsImportVersion7() { 477 478 // empty 479 } 480 481 /** 482 * Adds an ACE from the current xml data.<p> 483 * 484 * @see #addResourceAceRules(Digester, String) 485 */ 486 public void addAccessControlEntry() { 487 488 try { 489 if ((m_resource == null) || !m_importACEs) { 490 // skip ace import if not intended or the import of the resource failed 491 return; 492 } 493 if (m_throwable != null) { 494 // user or group of ACE might not exist in target system, ignore ACE 495 if (LOG.isWarnEnabled()) { 496 LOG.warn( 497 Messages.get().getBundle().key( 498 Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_ACE_1, 499 getCms().getRequestContext().removeSiteRoot(m_resource.getRootPath())), 500 m_throwable); 501 } 502 getReport().println(m_throwable); 503 getReport().addError(m_throwable); 504 return; 505 } 506 if (m_aces == null) { 507 // this list will be used and clean up in the importResource and importAccessControlEntries methods 508 m_aces = new ArrayList<CmsAccessControlEntry>(); 509 } 510 m_aces.add( 511 new CmsAccessControlEntry( 512 m_resource.getResourceId(), 513 m_acePrincipalId, 514 m_acePermissionsAllowed, 515 m_acePermissionsDenied, 516 m_aceFlags)); 517 } finally { 518 m_throwable = null; 519 m_acePrincipalId = null; 520 m_acePermissionsAllowed = 0; 521 m_acePermissionsDenied = 0; 522 m_aceFlags = 0; 523 } 524 } 525 526 /** 527 * Registers a file whose contents are contained in the zip file.<p> 528 * 529 * @param source the path in the zip file 530 * 531 * @param resourceId 532 */ 533 public void addContentFile(String source, String resourceId) { 534 535 if ((source != null) && (resourceId != null)) { 536 try { 537 m_helper.getFileBytes(source); 538 m_contentFiles.add(new CmsUUID(resourceId)); 539 } catch (CmsImportExportException e) { 540 LOG.info("File not found in import: " + source); 541 } 542 } 543 } 544 545 /** 546 * Adds a new resource to be associated to the current organizational unit.<p> 547 * 548 * @param resourceName the resource name to add 549 */ 550 public void addOrgUnitResource(String resourceName) { 551 552 if ((m_throwable != null) || (m_orgUnitName == null)) { 553 return; 554 } 555 if (m_orgUnitResources == null) { 556 m_orgUnitResources = new HashMap<String, List<String>>(); 557 } 558 List<String> resources = m_orgUnitResources.get(m_orgUnitName); 559 if (resources == null) { 560 resources = new ArrayList<String>(); 561 m_orgUnitResources.put(m_orgUnitName, resources); 562 } 563 resources.add(resourceName); 564 } 565 566 /** 567 * Adds a new resource to be associated to the current project.<p> 568 * 569 * @param resourceName the resource name to add 570 */ 571 public void addProjectResource(String resourceName) { 572 573 if ((m_throwable != null) || (m_projectName == null)) { 574 return; 575 } 576 if (m_projectResources == null) { 577 m_projectResources = new ArrayList<String>(); 578 } 579 m_projectResources.add(resourceName); 580 } 581 582 /** 583 * Adds a property from the current xml data, in case the type is implicit given.<p> 584 * 585 * @see #addResourcePropertyRules(Digester, String) 586 */ 587 public void addProperty() { 588 589 addProperty("individual"); 590 } 591 592 /** 593 * Adds a property from the current xml data, in case the type is explicit given.<p> 594 * 595 * @param propertyType the type of the property to be added 596 * 597 * @see #addResourcePropertyRules(Digester, String) 598 */ 599 public void addProperty(String propertyType) { 600 601 if (m_properties == null) { 602 // this list will be used and clean up in the importResource method 603 m_properties = new HashMap<String, CmsProperty>(); 604 } 605 try { 606 if ((m_propertyName == null) || getIgnoredProperties().contains(m_propertyName)) { 607 // continue if the current property (name) should be ignored or is null 608 return; 609 } 610 CmsProperty property = m_properties.get(m_propertyName); 611 if (property == null) { 612 property = new CmsProperty(); 613 property.setName(m_propertyName); 614 property.setAutoCreatePropertyDefinition(true); 615 m_properties.put(m_propertyName, property); 616 } 617 618 if (m_propertyValue == null) { 619 m_propertyValue = ""; 620 } 621 622 if ((propertyType != null) && propertyType.equals(PROPERTY_ATTRIB_TYPE_SHARED)) { 623 // it is a shared/resource property value 624 property.setResourceValue(m_propertyValue); 625 } else { 626 // it is an individual/structure value 627 property.setStructureValue(m_propertyValue); 628 } 629 } finally { 630 m_propertyName = null; 631 m_propertyValue = null; 632 } 633 } 634 635 /** 636 * Adds a relation to be imported from the current xml data.<p> 637 * 638 * @see #addResourceRelationRules(Digester, String) 639 */ 640 public void addRelation() { 641 642 if (m_relations == null) { 643 m_relations = new HashMap<String, List<CmsRelation>>(); 644 } 645 try { 646 if (m_resource == null) { 647 // skip relation import if the import of the resource failed 648 return; 649 } 650 if (m_throwable != null) { 651 // relation data is corrupt, ignore relation 652 if (LOG.isWarnEnabled()) { 653 LOG.warn( 654 Messages.get().getBundle().key( 655 Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_RELATION_1, 656 getCms().getRequestContext().removeSiteRoot(m_resource.getRootPath())), 657 m_throwable); 658 } 659 getReport().println(m_throwable); 660 getReport().addError(m_throwable); 661 m_throwable = null; 662 return; 663 } 664 List<CmsRelation> currentRelations = m_relations.get(m_resource.getRootPath()); 665 if (currentRelations == null) { 666 currentRelations = new ArrayList<CmsRelation>(); 667 m_relations.put(m_resource.getRootPath(), currentRelations); 668 } 669 currentRelations.add( 670 new CmsRelation( 671 m_resource.getStructureId(), 672 m_resource.getRootPath(), 673 m_relationId, 674 m_relationPath, 675 m_relationType)); 676 } finally { 677 m_relationId = null; 678 m_relationPath = null; 679 m_relationType = null; 680 } 681 } 682 683 /** 684 * Adds the XML digester rules for a single import file.<p> 685 * 686 * @param digester the digester to add the rules to 687 */ 688 public void addXmlDigesterRules(Digester digester) { 689 690 // first accounts 691 String xpath = CmsImportExportManager.N_EXPORT + "/" + N_ACCOUNTS + "/" + N_ORGUNITS + "/" + N_ORGUNIT + "/"; 692 addAccountsOrgunitRules(digester, xpath); 693 addAccountsGroupRules(digester, xpath); 694 addAccountsUserRules(digester, xpath); 695 digester.addCallMethod( 696 CmsImportExportManager.N_EXPORT + "/" + N_ACCOUNTS + "/" + N_ORGUNITS + "/" + N_ORGUNIT, 697 "setMembership"); 698 699 // then resources 700 xpath = CmsImportExportManager.N_EXPORT + "/" + N_FILES + "/" + N_FILE + "/"; 701 addResourceAttributesRules(digester, xpath); 702 addResourcePropertyRules(digester, xpath); 703 addResourceRelationRules(digester, xpath); 704 addResourceAceRules(digester, xpath); 705 digester.addCallMethod(CmsImportExportManager.N_EXPORT + "/" + N_FILES + "/" + N_FILE, "increaseCounter"); 706 digester.addCallMethod(CmsImportExportManager.N_EXPORT + "/" + N_FILES, "importRelations"); 707 digester.addCallMethod(CmsImportExportManager.N_EXPORT + "/" + N_FILES, "rewriteParseables"); 708 709 // and now the organizational unit resources 710 digester.addCallMethod(CmsImportExportManager.N_EXPORT + "/" + N_FILES, "associateOrgUnitResources"); 711 712 // then projects 713 xpath = CmsImportExportManager.N_EXPORT + "/" + N_PROJECTS + "/" + N_PROJECT + "/"; 714 addProjectRules(digester, xpath); 715 } 716 717 /** 718 * Adds the XML digester rules for pre-processing a single import file.<p> 719 * 720 * @param digester the digester to add the rules to 721 */ 722 public void addXmlPreprocessingDigesterRules(Digester digester) { 723 724 digester.addCallMethod(CmsImportExportManager.N_EXPORT + "/" + N_FILES + "/" + N_FILE, "increaseTotalFiles"); 725 digester.addCallMethod( 726 CmsImportExportManager.N_EXPORT 727 + "/" 728 + CmsImportExportManager.N_INFO 729 + "/" 730 + CmsImportExportManager.N_VERSION, 731 "setVersion", 732 0); 733 } 734 735 /** 736 * Associates the stored resources to the created organizational units.<p> 737 * 738 * This is a global process that occurs only once at the end of the import, 739 * after all resources have been imported, to make sure that the resources 740 * of the organizational units are available.<p> 741 * 742 * @see #addAccountsOrgunitRules(Digester, String) 743 * @see #addXmlDigesterRules(Digester) 744 */ 745 public void associateOrgUnitResources() { 746 747 if ((m_orgUnitResources == null) || m_orgUnitResources.isEmpty()) { 748 // no organizational resources to associate 749 return; 750 } 751 752 String site = getCms().getRequestContext().getSiteRoot(); 753 try { 754 getCms().getRequestContext().setSiteRoot(""); 755 List<String> orgUnits = new ArrayList<String>(m_orgUnitResources.keySet()); 756 Collections.sort(orgUnits); 757 Iterator<String> it = orgUnits.iterator(); 758 while (it.hasNext()) { 759 String orgUnitName = it.next(); 760 List<String> resources = m_orgUnitResources.get(orgUnitName); 761 762 if (orgUnitName.equals("")) { 763 continue; 764 } 765 766 Iterator<String> itResources = resources.iterator(); 767 while (itResources.hasNext()) { 768 String resourceName = itResources.next(); 769 try { 770 // Add the resource to the organizational unit 771 OpenCms.getOrgUnitManager().addResourceToOrgUnit(getCms(), orgUnitName, resourceName); 772 } catch (CmsException e) { 773 getReport().addWarning(e); 774 if (LOG.isWarnEnabled()) { 775 LOG.warn(e.getLocalizedMessage()); 776 } 777 if (LOG.isDebugEnabled()) { 778 LOG.debug(e.getLocalizedMessage(), e); 779 } 780 } 781 } 782 783 // remove the meanwhile used first resource of the parent organizational unit 784 try { 785 String resName = (OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit( 786 getCms(), 787 CmsOrganizationalUnit.getParentFqn(orgUnitName)).get(0)).getRootPath(); 788 if (!resources.contains(resName)) { 789 OpenCms.getOrgUnitManager().removeResourceFromOrgUnit(getCms(), orgUnitName, resName); 790 } 791 } catch (CmsException e) { 792 getReport().addWarning(e); 793 if (LOG.isWarnEnabled()) { 794 LOG.warn(e.getLocalizedMessage()); 795 } 796 if (LOG.isDebugEnabled()) { 797 LOG.debug(e.getLocalizedMessage(), e); 798 } 799 } 800 801 } 802 } finally { 803 getCms().getRequestContext().setSiteRoot(site); 804 } 805 806 m_orgUnitResources = null; 807 } 808 809 /** 810 * Returns the ace Flags.<p> 811 * 812 * @return the ace Flags 813 * 814 * @see #N_FLAGS 815 * @see #addResourceAceRules(Digester, String) 816 */ 817 public int getAceFlags() { 818 819 return m_aceFlags; 820 } 821 822 /** 823 * Returns the ace Permissions Allowed.<p> 824 * 825 * @return the ace Permissions Allowed 826 * 827 * @see #N_ACCESSCONTROL_ALLOWEDPERMISSIONS 828 * @see #addResourceAceRules(Digester, String) 829 */ 830 public int getAcePermissionsAllowed() { 831 832 return m_acePermissionsAllowed; 833 } 834 835 /** 836 * Returns the acePermissionsDenied.<p> 837 * 838 * @return the acePermissionsDenied 839 * 840 * @see #N_ACCESSCONTROL_DENIEDPERMISSIONS 841 * @see #addResourceAceRules(Digester, String) 842 */ 843 public int getAcePermissionsDenied() { 844 845 return m_acePermissionsDenied; 846 } 847 848 /** 849 * Returns the acePrincipalId.<p> 850 * 851 * @return the acePrincipalId 852 * 853 * @see #N_ACCESSCONTROL_PRINCIPAL 854 * @see #addResourceAceRules(Digester, String) 855 */ 856 public CmsUUID getAcePrincipalId() { 857 858 return m_acePrincipalId; 859 } 860 861 /** 862 * Returns the cms object.<p> 863 * 864 * @return the cms object 865 */ 866 public CmsObject getCms() { 867 868 return m_cms; 869 } 870 871 /** 872 * Returns the dateCreated.<p> 873 * 874 * @return the dateCreated 875 * 876 * @see #N_DATECREATED 877 * @see #addResourceAttributesRules(Digester, String) 878 */ 879 public long getDateCreated() { 880 881 return m_dateCreated; 882 } 883 884 /** 885 * Returns the dateExpired.<p> 886 * 887 * @return the dateExpired 888 * 889 * @see #N_DATEEXPIRED 890 * @see #addResourceAttributesRules(Digester, String) 891 */ 892 public long getDateExpired() { 893 894 return m_dateExpired; 895 } 896 897 /** 898 * Returns the dateLastModified.<p> 899 * 900 * @return the dateLastModified 901 * 902 * @see #N_DATELASTMODIFIED 903 * @see #addResourceAttributesRules(Digester, String) 904 */ 905 public long getDateLastModified() { 906 907 return m_dateLastModified; 908 } 909 910 /** 911 * Returns the dateReleased.<p> 912 * 913 * @return the dateReleased 914 * 915 * @see #N_DATERELEASED 916 * @see #addResourceAttributesRules(Digester, String) 917 */ 918 public long getDateReleased() { 919 920 return m_dateReleased; 921 } 922 923 /** 924 * Returns the destination.<p> 925 * 926 * @return the destination 927 * 928 * @see #N_DESTINATION 929 * @see #addResourceAttributesRules(Digester, String) 930 */ 931 public String getDestination() { 932 933 return m_destination; 934 } 935 936 /** 937 * Returns the flags.<p> 938 * 939 * @return the flags 940 * 941 * @see #N_FLAGS 942 * @see #addResourceAttributesRules(Digester, String) 943 */ 944 public int getFlags() { 945 946 return m_flags; 947 } 948 949 /** 950 * Returns the group Description.<p> 951 * 952 * @return the group Description 953 */ 954 public String getGroupDescription() { 955 956 return m_groupDescription; 957 } 958 959 /** 960 * Returns the group Flags.<p> 961 * 962 * @return the group Flags 963 */ 964 public int getGroupFlags() { 965 966 return m_groupFlags; 967 } 968 969 /** 970 * Returns the group Name.<p> 971 * 972 * @return the group Name 973 */ 974 public String getGroupName() { 975 976 return m_groupName; 977 } 978 979 /** 980 * Returns the group Parent.<p> 981 * 982 * @return the group Parent 983 */ 984 public String getGroupParent() { 985 986 return m_groupParent; 987 } 988 989 /** 990 * Returns the organizational unit description.<p> 991 * 992 * @return the organizational unit description 993 */ 994 public String getOrgUnitDescription() { 995 996 return m_orgUnitDescription; 997 } 998 999 /** 1000 * Returns the organizational unit flags.<p> 1001 * 1002 * @return the organizational unit flags 1003 */ 1004 public int getOrgUnitFlags() { 1005 1006 return m_orgUnitFlags; 1007 } 1008 1009 /** 1010 * Returns the organizational unit name.<p> 1011 * 1012 * @return the organizational unit name 1013 */ 1014 public String getOrgUnitName() { 1015 1016 return m_orgUnitName; 1017 } 1018 1019 /** 1020 * Returns the project Description.<p> 1021 * 1022 * @return the project Description 1023 */ 1024 public String getProjectDescription() { 1025 1026 return m_projectDescription; 1027 } 1028 1029 /** 1030 * Returns the project Managers group name.<p> 1031 * 1032 * @return the project Managers group name 1033 */ 1034 public String getProjectManagers() { 1035 1036 return m_projectManagers; 1037 } 1038 1039 /** 1040 * Returns the project Name.<p> 1041 * 1042 * @return the project Name 1043 */ 1044 public String getProjectName() { 1045 1046 return m_projectName; 1047 } 1048 1049 /** 1050 * Returns the project Users group name.<p> 1051 * 1052 * @return the project Users group name 1053 */ 1054 public String getProjectUsers() { 1055 1056 return m_projectUsers; 1057 } 1058 1059 /** 1060 * Returns the propertyName.<p> 1061 * 1062 * @return the propertyName 1063 * 1064 * @see #N_NAME 1065 * @see #addResourcePropertyRules(Digester, String) 1066 */ 1067 public String getPropertyName() { 1068 1069 return m_propertyName; 1070 } 1071 1072 /** 1073 * Returns the propertyValue.<p> 1074 * 1075 * @return the propertyValue 1076 * 1077 * @see #N_VALUE 1078 * @see #addResourcePropertyRules(Digester, String) 1079 */ 1080 public String getPropertyValue() { 1081 1082 return m_propertyValue; 1083 } 1084 1085 /** 1086 * Returns the relationId.<p> 1087 * 1088 * @return the relationId 1089 * 1090 * @see #N_ID 1091 * @see #addResourceRelationRules(Digester, String) 1092 */ 1093 public CmsUUID getRelationId() { 1094 1095 return m_relationId; 1096 } 1097 1098 /** 1099 * Returns the relationPath.<p> 1100 * 1101 * @return the relationPath 1102 * 1103 * @see #N_PATH 1104 * @see #addResourceRelationRules(Digester, String) 1105 */ 1106 public String getRelationPath() { 1107 1108 return m_relationPath; 1109 } 1110 1111 /** 1112 * Returns the relationType.<p> 1113 * 1114 * @return the relationType 1115 * 1116 * @see #N_TYPE 1117 * @see #addResourceRelationRules(Digester, String) 1118 */ 1119 public CmsRelationType getRelationType() { 1120 1121 return m_relationType; 1122 } 1123 1124 /** 1125 * Returns the report.<p> 1126 * 1127 * @return the report 1128 */ 1129 public I_CmsReport getReport() { 1130 1131 return m_report; 1132 } 1133 1134 /** 1135 * Returns the resourceId.<p> 1136 * 1137 * @return the resourceId 1138 * 1139 * @see #N_UUIDRESOURCE 1140 * @see #addResourceAttributesRules(Digester, String) 1141 */ 1142 public CmsUUID getResourceId() { 1143 1144 return m_resourceId; 1145 } 1146 1147 /** 1148 * Returns the source.<p> 1149 * 1150 * @return the source 1151 * 1152 * @see #N_SOURCE 1153 * @see #addResourceAttributesRules(Digester, String) 1154 */ 1155 public String getSource() { 1156 1157 return m_source; 1158 } 1159 1160 /** 1161 * Returns the structureId.<p> 1162 * 1163 * @return the structureId 1164 * 1165 * @see #N_UUIDSTRUCTURE 1166 * @see #addResourceAttributesRules(Digester, String) 1167 */ 1168 public CmsUUID getStructureId() { 1169 1170 return m_structureId; 1171 } 1172 1173 /** 1174 * Returns the throwable.<p> 1175 * 1176 * @return the throwable 1177 */ 1178 public Throwable getThrowable() { 1179 1180 return m_throwable; 1181 } 1182 1183 /** 1184 * Returns the type.<p> 1185 * 1186 * @return the type 1187 * 1188 * @see #N_TYPE 1189 * @see #addResourceAttributesRules(Digester, String) 1190 */ 1191 public I_CmsResourceType getType() { 1192 1193 return m_type; 1194 } 1195 1196 /** 1197 * Returns the userCreated.<p> 1198 * 1199 * @return the userCreated 1200 * 1201 * @see #N_USERCREATED 1202 * @see #addResourceAttributesRules(Digester, String) 1203 */ 1204 public CmsUUID getUserCreated() { 1205 1206 return m_userCreated; 1207 } 1208 1209 /** 1210 * Returns the user Date Created.<p> 1211 * 1212 * @return the user Date Created 1213 */ 1214 public long getUserDateCreated() { 1215 1216 return m_userDateCreated; 1217 } 1218 1219 /** 1220 * Returns the user Email address.<p> 1221 * 1222 * @return the user Email address 1223 */ 1224 public String getUserEmail() { 1225 1226 return m_userEmail; 1227 } 1228 1229 /** 1230 * Returns the user First name.<p> 1231 * 1232 * @return the user First name 1233 */ 1234 public String getUserFirstname() { 1235 1236 return m_userFirstname; 1237 } 1238 1239 /** 1240 * Returns the user Flags.<p> 1241 * 1242 * @return the user Flags 1243 */ 1244 public int getUserFlags() { 1245 1246 return m_userFlags; 1247 } 1248 1249 /** 1250 * Returns the userLastModified.<p> 1251 * 1252 * @return the userLastModified 1253 * 1254 * @see #N_USERLASTMODIFIED 1255 * @see #addResourceAttributesRules(Digester, String) 1256 */ 1257 public CmsUUID getUserLastModified() { 1258 1259 return m_userLastModified; 1260 } 1261 1262 /** 1263 * Returns the user Last name.<p> 1264 * 1265 * @return the user Last name 1266 */ 1267 public String getUserLastname() { 1268 1269 return m_userLastname; 1270 } 1271 1272 /** 1273 * Returns the user Name.<p> 1274 * 1275 * @return the user Name 1276 */ 1277 public String getUserName() { 1278 1279 return m_userName; 1280 } 1281 1282 /** 1283 * Returns the user Password.<p> 1284 * 1285 * @return the user Password 1286 */ 1287 public String getUserPassword() { 1288 1289 return m_userPassword; 1290 } 1291 1292 /** 1293 * @see org.opencms.importexport.I_CmsImport#getVersion() 1294 */ 1295 public int getVersion() { 1296 1297 return IMPORT_VERSION7; 1298 } 1299 1300 /** 1301 * Imports an ACE from the current xml data.<p> 1302 * 1303 * @see #addResourceAceRules(Digester, String) 1304 */ 1305 public void importAccessControlEntries() { 1306 1307 // only set permissions if the resource did not exists or if the keep permissions flag is not set 1308 if ((m_resource == null) || !m_importACEs) { 1309 return; 1310 } 1311 if ((m_aces == null) || (m_aces.size() == 0)) { 1312 // no ACE in the list 1313 return; 1314 } 1315 // if the resource was imported add the access control entries if available 1316 try { 1317 getCms().importAccessControlEntries(m_resource, m_aces); 1318 } catch (CmsException exc) { 1319 getReport().println( 1320 Messages.get().container(Messages.RPT_IMPORT_ACL_DATA_FAILED_0), 1321 I_CmsReport.FORMAT_WARNING); 1322 } finally { 1323 m_aces = null; 1324 } 1325 } 1326 1327 /** 1328 * @see org.opencms.importexport.I_CmsImport#importData(CmsObject, I_CmsReport, CmsImportParameters) 1329 */ 1330 public void importData(CmsObject cms, I_CmsReport report, CmsImportParameters parameters) { 1331 1332 m_cms = cms; 1333 m_report = report; 1334 m_parameters = parameters; 1335 1336 // instantiate Digester and enable XML validation 1337 Digester digester = new Digester(); 1338 digester.setUseContextClassLoader(true); 1339 digester.setValidating(m_parameters.isXmlValidation()); 1340 digester.setEntityResolver(new CmsXmlEntityResolver(null)); 1341 digester.setRuleNamespaceURI(null); 1342 digester.setErrorHandler(new CmsXmlErrorHandler(CmsImportExportManager.EXPORT_MANIFEST)); 1343 1344 // add this object to the Digester 1345 digester.push(this); 1346 1347 addXmlDigesterRules(digester); 1348 1349 InputStream stream = null; 1350 m_helper = new CmsImportHelper(m_parameters); 1351 try { 1352 m_helper.openFile(); 1353 m_helper.cacheDtdSystemId(DTD_LOCATION, DTD_FILENAME, CmsConfigurationManager.DEFAULT_DTD_PREFIX); 1354 findContentFiles(); 1355 // start the parsing process 1356 stream = m_helper.getFileStream(CmsImportExportManager.EXPORT_MANIFEST); 1357 digester.parse(stream); 1358 } catch (Exception ioe) { 1359 if (LOG.isErrorEnabled()) { 1360 LOG.error( 1361 Messages.get().getBundle().key( 1362 Messages.ERR_IMPORTEXPORT_ERROR_READING_FILE_1, 1363 CmsImportExportManager.EXPORT_MANIFEST), 1364 ioe); 1365 } 1366 getReport().println(ioe); 1367 } finally { 1368 try { 1369 if (stream != null) { 1370 stream.close(); 1371 } 1372 } catch (Exception e) { 1373 // noop 1374 } 1375 m_helper.closeFile(); 1376 } 1377 } 1378 1379 /** 1380 * Import the current group from xml data.<p> 1381 */ 1382 public void importGroup() { 1383 1384 if (m_orgUnit == null) { 1385 return; 1386 } 1387 if (m_groupDescription == null) { 1388 m_groupDescription = ""; 1389 } 1390 if (m_groupParents == null) { 1391 m_groupParents = new HashMap<String, List<String>>(); 1392 } 1393 1394 String groupName = m_orgUnit.getName() + m_groupName; 1395 try { 1396 if (m_throwable != null) { 1397 getReport().println(m_throwable); 1398 1399 CmsMessageContainer message = Messages.get().container( 1400 Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_GROUP_1, 1401 groupName); 1402 if (LOG.isDebugEnabled()) { 1403 LOG.debug(message.key(), m_throwable); 1404 } 1405 m_throwable = null; 1406 return; 1407 } 1408 1409 getReport().print(Messages.get().container(Messages.RPT_IMPORT_GROUP_0), I_CmsReport.FORMAT_NOTE); 1410 getReport().print( 1411 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_ARGUMENT_1, groupName)); 1412 getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 1413 1414 try { 1415 getCms().readGroup(groupName); 1416 // the group already exists and will not be created 1417 getReport().println(Messages.get().container(Messages.RPT_NOT_CREATED_0), I_CmsReport.FORMAT_OK); 1418 } catch (CmsDbEntryNotFoundException e) { 1419 // ok, let's create it 1420 // first check the parent group 1421 CmsUUID parentGroupId = null; 1422 if (CmsStringUtil.isNotEmpty(m_groupParent)) { 1423 try { 1424 // parent group exists 1425 parentGroupId = getCms().readGroup(m_groupParent).getId(); 1426 } catch (CmsDbEntryNotFoundException exc) { 1427 // parent group does not exist, remember to set the parent group later 1428 List<String> childs = m_groupParents.get(m_groupParent); 1429 if (childs == null) { 1430 childs = new ArrayList<String>(); 1431 m_groupParents.put(m_groupParent, childs); 1432 } 1433 childs.add(groupName); 1434 } 1435 } 1436 1437 getCms().createGroup( 1438 groupName, 1439 m_groupDescription, 1440 m_groupFlags, 1441 parentGroupId == null ? null : m_groupParent); 1442 getReport().println( 1443 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 1444 I_CmsReport.FORMAT_OK); 1445 1446 // set parents that could not be set before 1447 List<String> childs = m_groupParents.remove(groupName); 1448 if (childs != null) { 1449 Iterator<String> it = childs.iterator(); 1450 while (it.hasNext()) { 1451 String childGroup = it.next(); 1452 getCms().setParentGroup(childGroup, groupName); 1453 } 1454 } 1455 } 1456 } catch (Exception e) { 1457 getReport().println(e); 1458 1459 CmsMessageContainer message = Messages.get().container( 1460 Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_GROUP_1, 1461 groupName); 1462 if (LOG.isDebugEnabled()) { 1463 LOG.debug(message.key(), e); 1464 } 1465 } finally { 1466 m_groupDescription = null; 1467 m_groupFlags = 0; 1468 m_groupName = null; 1469 m_groupParent = null; 1470 m_throwable = null; 1471 } 1472 } 1473 1474 /** 1475 * Imports the current organizational unit.<p> 1476 */ 1477 public void importOrgUnit() { 1478 1479 try { 1480 if (m_throwable != null) { 1481 getReport().println(m_throwable); 1482 getReport().addError(m_throwable); 1483 1484 CmsMessageContainer message = Messages.get().container( 1485 Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_ORGUNITS_0); 1486 if (LOG.isDebugEnabled()) { 1487 LOG.debug(message.key(), m_throwable); 1488 } 1489 m_throwable = null; 1490 m_orgUnit = null; 1491 1492 return; 1493 } 1494 1495 getReport().print(Messages.get().container(Messages.RPT_IMPORT_ORGUNIT_0), I_CmsReport.FORMAT_NOTE); 1496 getReport().print( 1497 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_ARGUMENT_1, m_orgUnitName)); 1498 getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 1499 1500 try { 1501 m_orgUnit = OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), m_orgUnitName); 1502 // the organizational unit already exists and will not be created 1503 getReport().println(Messages.get().container(Messages.RPT_NOT_CREATED_0), I_CmsReport.FORMAT_OK); 1504 m_orgUnitResources.remove(m_orgUnitName); 1505 return; 1506 } catch (CmsDataAccessException e) { 1507 // ok, continue creating the ou 1508 } 1509 1510 // get the resources that already exist for the organizational unit 1511 // if there are resources that does not exist jet, there will be a second try after importing resources 1512 List<CmsResource> resources = new ArrayList<CmsResource>(); 1513 String site = getCms().getRequestContext().getSiteRoot(); 1514 try { 1515 getCms().getRequestContext().setSiteRoot(""); 1516 1517 boolean remove = true; 1518 List<String> ouResources = CmsCollectionsGenericWrapper.list(m_orgUnitResources.get(m_orgUnitName)); 1519 if (ouResources != null) { 1520 Iterator<String> itResNames = ouResources.iterator(); 1521 while (itResNames.hasNext()) { 1522 String resName = itResNames.next(); 1523 try { 1524 resources.add(getCms().readResource(resName, CmsResourceFilter.ALL)); 1525 itResNames.remove(); 1526 } catch (CmsVfsResourceNotFoundException e) { 1527 // resource does not exist yet, skip it for now 1528 remove = false; 1529 } 1530 } 1531 } 1532 1533 if (remove) { 1534 m_orgUnitResources.remove(m_orgUnitName); 1535 } 1536 } finally { 1537 getCms().getRequestContext().setSiteRoot(site); 1538 } 1539 1540 // if no resource available 1541 if (resources.isEmpty()) { 1542 // meanwhile use the first one of the parent organizational unit 1543 resources.add( 1544 OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit( 1545 getCms(), 1546 CmsOrganizationalUnit.getParentFqn(m_orgUnitName)).get(0)); 1547 } 1548 1549 // create the organizational unit with a dummy resource, which will be corrected later 1550 m_orgUnit = OpenCms.getOrgUnitManager().createOrganizationalUnit( 1551 getCms(), 1552 m_orgUnitName, 1553 m_orgUnitDescription, 1554 m_orgUnitFlags, 1555 resources.get(0).getRootPath()); 1556 for (int i = 1; i < resources.size(); i++) { 1557 OpenCms.getOrgUnitManager().addResourceToOrgUnit( 1558 getCms(), 1559 m_orgUnitName, 1560 resources.get(i).getRootPath()); 1561 } 1562 1563 getReport().println( 1564 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 1565 I_CmsReport.FORMAT_OK); 1566 } catch (CmsException e) { 1567 getReport().println(e); 1568 getReport().addError(e); 1569 1570 CmsMessageContainer message = Messages.get().container( 1571 Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_ORGUNITS_0); 1572 if (LOG.isDebugEnabled()) { 1573 LOG.debug(message.key(), e); 1574 } 1575 m_throwable = null; 1576 m_orgUnit = null; 1577 } finally { 1578 m_orgUnitName = null; 1579 m_orgUnitDescription = null; 1580 m_orgUnitFlags = 0; 1581 } 1582 1583 } 1584 1585 /** 1586 * Imports the current project.<p> 1587 */ 1588 public void importProject() { 1589 1590 try { 1591 if (m_throwable != null) { 1592 getReport().println(m_throwable); 1593 getReport().addError(m_throwable); 1594 1595 CmsMessageContainer message = Messages.get().container( 1596 Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_PROJECTS_0); 1597 if (LOG.isDebugEnabled()) { 1598 LOG.debug(message.key(), m_throwable); 1599 } 1600 m_throwable = null; 1601 1602 return; 1603 } 1604 1605 getReport().print(Messages.get().container(Messages.RPT_IMPORT_PROJECT_0), I_CmsReport.FORMAT_NOTE); 1606 getReport().print( 1607 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_ARGUMENT_1, m_projectName)); 1608 getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 1609 1610 try { 1611 getCms().readProject(m_projectName); 1612 // the project already exists and will not be created 1613 getReport().println(Messages.get().container(Messages.RPT_NOT_CREATED_0), I_CmsReport.FORMAT_OK); 1614 return; 1615 } catch (CmsDataAccessException e) { 1616 // ok, continue creating the project 1617 } 1618 1619 // create the project 1620 CmsProject project = getCms().createProject( 1621 m_projectName, 1622 m_projectDescription, 1623 m_projectUsers, 1624 m_projectManagers, 1625 CmsProject.PROJECT_TYPE_NORMAL); 1626 // set the resources 1627 if (m_projectResources != null) { 1628 String site = getCms().getRequestContext().getSiteRoot(); 1629 CmsProject currentProject = getCms().getRequestContext().getCurrentProject(); 1630 try { 1631 getCms().getRequestContext().setSiteRoot(""); 1632 getCms().getRequestContext().setCurrentProject(project); 1633 1634 Iterator<String> itResNames = m_projectResources.iterator(); 1635 while (itResNames.hasNext()) { 1636 String resName = itResNames.next(); 1637 try { 1638 getCms().copyResourceToProject(resName); 1639 } catch (CmsVfsResourceNotFoundException e) { 1640 // resource does not exist, skip 1641 } 1642 } 1643 } finally { 1644 getCms().getRequestContext().setSiteRoot(site); 1645 getCms().getRequestContext().setCurrentProject(currentProject); 1646 } 1647 } 1648 getReport().println( 1649 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 1650 I_CmsReport.FORMAT_OK); 1651 } catch (CmsException e) { 1652 getReport().println(e); 1653 getReport().addError(e); 1654 1655 CmsMessageContainer message = Messages.get().container( 1656 Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_PROJECTS_0); 1657 if (LOG.isDebugEnabled()) { 1658 LOG.debug(message.key(), e); 1659 } 1660 m_throwable = null; 1661 } finally { 1662 m_projectName = null; 1663 m_projectDescription = null; 1664 m_projectManagers = null; 1665 m_projectUsers = null; 1666 m_projectResources = null; 1667 } 1668 1669 } 1670 1671 /** 1672 * Imports all relations from the current xml data.<p> 1673 * 1674 * This is a global process that occurs only once at the end of the import, 1675 * after all resources have been imported, to make sure that both resources 1676 * of the relations are available.<p> 1677 * 1678 * @see #addResourceRelationRules(Digester, String) 1679 * @see #addXmlDigesterRules(Digester) 1680 */ 1681 public void importRelations() { 1682 1683 if ((m_relations == null) || m_relations.isEmpty()) { 1684 // no relations to add 1685 return; 1686 } 1687 1688 getReport().println( 1689 Messages.get().container(Messages.RPT_START_IMPORT_RELATIONS_0), 1690 I_CmsReport.FORMAT_HEADLINE); 1691 1692 int i = 0; 1693 Iterator<Entry<String, List<CmsRelation>>> it = m_relations.entrySet().iterator(); 1694 while (it.hasNext()) { 1695 Entry<String, List<CmsRelation>> entry = it.next(); 1696 String resourcePath = entry.getKey(); 1697 List<CmsRelation> relations = entry.getValue(); 1698 1699 if (checkImmutable(resourcePath)) { 1700 continue; 1701 } 1702 getReport().print(org.opencms.report.Messages.get().container( 1703 org.opencms.report.Messages.RPT_SUCCESSION_2, 1704 String.valueOf(i + 1), 1705 String.valueOf(m_relations.size())), I_CmsReport.FORMAT_NOTE); 1706 1707 getReport().print( 1708 Messages.get().container( 1709 Messages.RPT_IMPORTING_RELATIONS_FOR_2, 1710 resourcePath, 1711 Integer.valueOf(relations.size())), 1712 I_CmsReport.FORMAT_NOTE); 1713 getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 1714 1715 boolean withErrors = false; 1716 Iterator<CmsRelation> itRelations = relations.iterator(); 1717 while (itRelations.hasNext()) { 1718 CmsRelation relation = itRelations.next(); 1719 try { 1720 // Add the relation to the resource 1721 getCms().importRelation( 1722 getCms().getSitePath(relation.getSource(getCms(), CmsResourceFilter.ALL)), 1723 getCms().getSitePath(relation.getTarget(getCms(), CmsResourceFilter.ALL)), 1724 relation.getType().getName()); 1725 } catch (CmsException e) { 1726 getReport().addWarning(e); 1727 withErrors = true; 1728 if (LOG.isWarnEnabled()) { 1729 LOG.warn(e.getLocalizedMessage()); 1730 } 1731 if (LOG.isDebugEnabled()) { 1732 LOG.debug(e.getLocalizedMessage(), e); 1733 } 1734 } 1735 } 1736 if (!withErrors) { 1737 getReport().println( 1738 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 1739 I_CmsReport.FORMAT_OK); 1740 } else { 1741 getReport().println( 1742 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_FAILED_0), 1743 I_CmsReport.FORMAT_ERROR); 1744 } 1745 i++; 1746 } 1747 1748 getReport().println(Messages.get().container(Messages.RPT_END_IMPORT_RELATIONS_0), I_CmsReport.FORMAT_HEADLINE); 1749 1750 m_relations = null; 1751 } 1752 1753 /** 1754 * Imports a resource from the current xml data.<p> 1755 * 1756 * @see #addResourceAttributesRules(Digester, String) 1757 * @see #addResourcePropertyRules(Digester, String) 1758 */ 1759 public void importResource() { 1760 1761 boolean resourceIdWasNull = false; 1762 1763 try { 1764 if (m_throwable != null) { 1765 getReport().println(m_throwable); 1766 getReport().addError(m_throwable); 1767 1768 CmsMessageContainer message = Messages.get().container( 1769 Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0); 1770 if (LOG.isDebugEnabled()) { 1771 LOG.debug(message.key(), m_throwable); 1772 } 1773 m_throwable = null; 1774 m_importACEs = false; 1775 m_resource = null; 1776 1777 return; 1778 } 1779 1780 // apply name translation and import path 1781 String translatedName = getCms().getRequestContext().addSiteRoot( 1782 m_parameters.getDestinationPath() + m_destination); 1783 1784 boolean resourceImmutable = checkImmutable(translatedName); 1785 translatedName = getCms().getRequestContext().removeSiteRoot(translatedName); 1786 // if the resource is not immutable and not on the exclude list, import it 1787 if (!resourceImmutable) { 1788 // print out the information to the report 1789 getReport().print(Messages.get().container(Messages.RPT_IMPORTING_0), I_CmsReport.FORMAT_NOTE); 1790 getReport().print( 1791 org.opencms.report.Messages.get().container( 1792 org.opencms.report.Messages.RPT_ARGUMENT_1, 1793 translatedName)); 1794 getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 1795 1796 boolean exists = getCms().existsResource(translatedName, CmsResourceFilter.ALL); 1797 1798 byte[] content = null; 1799 // get the file content 1800 if (m_source != null) { 1801 content = m_helper.getFileBytes(m_source); 1802 } 1803 int size = 0; 1804 if (content != null) { 1805 size = content.length; 1806 } 1807 1808 // get UUID for the structure 1809 if (m_structureId == null) { 1810 // if null generate a new structure id 1811 m_structureId = new CmsUUID(); 1812 } 1813 1814 // get UUIDs for the resource 1815 if ((m_resourceId == null) || (m_type.isFolder())) { 1816 // folders get always a new resource UUID 1817 m_resourceId = new CmsUUID(); 1818 resourceIdWasNull = true; 1819 } 1820 1821 // create a new CmsResource 1822 CmsResource resource = new CmsResource( 1823 m_structureId, 1824 m_resourceId, 1825 translatedName, 1826 m_type.getTypeId(), 1827 m_type.isFolder(), 1828 m_flags, 1829 getCms().getRequestContext().getCurrentProject().getUuid(), 1830 CmsResource.STATE_NEW, 1831 m_dateCreated, 1832 m_userCreated, 1833 m_dateLastModified, 1834 m_userLastModified, 1835 m_dateReleased, 1836 m_dateExpired, 1837 1, 1838 size, 1839 System.currentTimeMillis(), 1840 0); 1841 1842 if (m_properties == null) { 1843 m_properties = new HashMap<String, CmsProperty>(); 1844 } 1845 1846 if (m_type.isFolder() || resourceIdWasNull || hasContentInVfsOrImport(resource)) { 1847 // import this resource in the VFS 1848 m_resource = getCms().importResource( 1849 translatedName, 1850 resource, 1851 content, 1852 new ArrayList<CmsProperty>(m_properties.values())); 1853 } 1854 1855 // only set permissions if the resource did not exists or if the keep permissions flag is not set 1856 m_importACEs = (m_resource != null) && (!exists || !m_parameters.isKeepPermissions()); 1857 1858 if (m_resource != null) { 1859 getReport().println( 1860 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 1861 I_CmsReport.FORMAT_OK); 1862 1863 if (OpenCms.getResourceManager().getResourceType( 1864 m_resource.getTypeId()) instanceof I_CmsLinkParseable) { 1865 // store for later use 1866 m_parseables.add(m_resource); 1867 } 1868 if (LOG.isInfoEnabled()) { 1869 LOG.info( 1870 Messages.get().getBundle().key( 1871 Messages.LOG_IMPORTING_4, 1872 new Object[] { 1873 String.valueOf(m_fileCounter), 1874 String.valueOf(m_totalFiles), 1875 translatedName, 1876 m_destination})); 1877 } 1878 } else { 1879 // resource import failed, since no CmsResource was created 1880 getReport().print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE); 1881 getReport().println( 1882 org.opencms.report.Messages.get().container( 1883 org.opencms.report.Messages.RPT_ARGUMENT_1, 1884 translatedName)); 1885 1886 if (LOG.isInfoEnabled()) { 1887 LOG.info( 1888 Messages.get().getBundle().key( 1889 Messages.LOG_SKIPPING_3, 1890 String.valueOf(m_fileCounter), 1891 String.valueOf(m_totalFiles), 1892 translatedName)); 1893 } 1894 } 1895 } else { 1896 m_resource = null; 1897 // skip the file import, just print out the information to the report 1898 getReport().print(Messages.get().container(Messages.RPT_SKIPPING_0), I_CmsReport.FORMAT_NOTE); 1899 getReport().println( 1900 org.opencms.report.Messages.get().container( 1901 org.opencms.report.Messages.RPT_ARGUMENT_1, 1902 translatedName)); 1903 1904 if (LOG.isInfoEnabled()) { 1905 LOG.info( 1906 Messages.get().getBundle().key( 1907 Messages.LOG_SKIPPING_3, 1908 String.valueOf(m_fileCounter), 1909 String.valueOf(m_totalFiles), 1910 translatedName)); 1911 } 1912 // do not import ACEs 1913 m_importACEs = false; 1914 } 1915 } catch (Exception e) { 1916 m_resource = null; 1917 m_importACEs = false; 1918 1919 getReport().println(e); 1920 getReport().addError(e); 1921 1922 CmsMessageContainer message = Messages.get().container( 1923 Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_RESOURCES_0); 1924 if (LOG.isDebugEnabled()) { 1925 LOG.debug(message.key(), e); 1926 } 1927 1928 return; 1929 } finally { 1930 m_structureId = null; 1931 m_resourceId = null; 1932 m_destination = null; 1933 m_source = null; 1934 m_type = null; 1935 m_flags = 0; 1936 m_dateCreated = 0; 1937 m_dateLastModified = 0; 1938 m_dateReleased = CmsResource.DATE_RELEASED_DEFAULT; 1939 m_dateExpired = CmsResource.DATE_EXPIRED_DEFAULT; 1940 m_properties = null; 1941 m_throwable = null; 1942 m_aces = null; 1943 m_properties = null; 1944 } 1945 } 1946 1947 /** 1948 * @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) 1949 * 1950 * @deprecated use {@link #importData(CmsObject, I_CmsReport, CmsImportParameters)} instead 1951 */ 1952 @Deprecated 1953 public void importResources( 1954 CmsObject cms, 1955 String importPath, 1956 I_CmsReport report, 1957 File importResource, 1958 ZipFile importZip, 1959 Document docXml) { 1960 1961 CmsImportParameters params = new CmsImportParameters(importResource.getAbsolutePath(), importPath, true); 1962 1963 importData(cms, report, params); 1964 } 1965 1966 /** 1967 * Imports a new user from the current xml data.<p> 1968 */ 1969 public void importUser() { 1970 1971 // create a new user id 1972 String userName = m_orgUnit.getName() + m_userName; 1973 try { 1974 if (m_throwable != null) { 1975 m_user = null; 1976 getReport().println(m_throwable); 1977 1978 CmsMessageContainer message = Messages.get().container( 1979 Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_USER_1, 1980 userName); 1981 if (LOG.isDebugEnabled()) { 1982 LOG.debug(message.key(), m_throwable); 1983 } 1984 m_throwable = null; 1985 return; 1986 } 1987 1988 getReport().print(Messages.get().container(Messages.RPT_IMPORT_USER_0), I_CmsReport.FORMAT_NOTE); 1989 getReport().print( 1990 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_ARGUMENT_1, userName)); 1991 getReport().print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 1992 1993 try { 1994 getCms().readUser(userName); 1995 // user exists already 1996 getReport().println(Messages.get().container(Messages.RPT_NOT_CREATED_0), I_CmsReport.FORMAT_OK); 1997 m_user = null; 1998 return; 1999 } catch (CmsDbEntryNotFoundException e) { 2000 // user does not exist 2001 } 2002 2003 CmsParameterConfiguration config = OpenCms.getPasswordHandler().getConfiguration(); 2004 if ((config != null) && config.containsKey(I_CmsPasswordHandler.CONVERT_DIGEST_ENCODING)) { 2005 if (config.getBoolean(I_CmsPasswordHandler.CONVERT_DIGEST_ENCODING, false)) { 2006 m_userPassword = convertDigestEncoding(m_userPassword); 2007 } 2008 } 2009 2010 m_user = getCms().importUser( 2011 new CmsUUID().toString(), 2012 userName, 2013 m_userPassword, 2014 m_userFirstname, 2015 m_userLastname, 2016 m_userEmail, 2017 m_userFlags, 2018 m_userDateCreated, 2019 m_userInfos); 2020 2021 getReport().println( 2022 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 2023 I_CmsReport.FORMAT_OK); 2024 } catch (Throwable e) { 2025 m_user = null; 2026 getReport().println(e); 2027 2028 CmsMessageContainer message = Messages.get().container( 2029 Messages.ERR_IMPORTEXPORT_ERROR_IMPORTING_USER_1, 2030 userName); 2031 if (LOG.isDebugEnabled()) { 2032 LOG.debug(message.key(), e); 2033 } 2034 } finally { 2035 m_userName = null; 2036 m_userPassword = null; 2037 m_userFirstname = null; 2038 m_userLastname = null; 2039 m_userEmail = null; 2040 m_userFlags = 0; 2041 m_userDateCreated = 0; 2042 m_userInfos = null; 2043 } 2044 } 2045 2046 /** 2047 * Sets the current user as member of the given group.<p> 2048 * 2049 * It can happen that the organizational unit has not been imported jet, 2050 * in this case, the data is kept for later.<p> 2051 * 2052 * @param groupName the name of the group to set 2053 * 2054 * @see #setMembership() 2055 */ 2056 public void importUserGroup(String groupName) { 2057 2058 if ((m_throwable != null) || (m_user == null)) { 2059 return; 2060 } 2061 groupName = OpenCms.getImportExportManager().translateGroup(groupName); 2062 try { 2063 String ouName = CmsOrganizationalUnit.getParentFqn(groupName); 2064 try { 2065 // check if the organizational unit exists 2066 OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), ouName); 2067 // set the user group 2068 getCms().addUserToGroup(m_user.getName(), groupName); 2069 return; 2070 } catch (CmsDbEntryNotFoundException e) { 2071 // organizational unit does not exist 2072 } 2073 // remember the user and group for later 2074 Map<String, Map<String, String>> membership = m_membership.get(ouName); 2075 if (membership == null) { 2076 membership = new HashMap<String, Map<String, String>>(); 2077 m_membership.put(ouName, membership); 2078 } 2079 Map<String, String> groups = membership.get(I_CmsPrincipal.PRINCIPAL_GROUP); 2080 if (groups == null) { 2081 groups = new HashMap<String, String>(); 2082 membership.put(I_CmsPrincipal.PRINCIPAL_GROUP, groups); 2083 } 2084 groups.put(m_user.getName(), groupName); 2085 } catch (Throwable e) { 2086 getReport().println( 2087 Messages.get().container(Messages.RPT_USER_COULDNT_BE_ADDED_TO_GROUP_2, m_user.getName(), groupName), 2088 I_CmsReport.FORMAT_WARNING); 2089 if (LOG.isDebugEnabled()) { 2090 LOG.debug(e.getLocalizedMessage(), e); 2091 } 2092 } 2093 } 2094 2095 /** 2096 * Creates a new additional information entry for the current user.<p> 2097 * 2098 * @param infoName the name of the additional information entry 2099 * @param infoType the type of the additional information entry 2100 * @param infoValue the value of the additional information entry 2101 */ 2102 public void importUserInfo(String infoName, String infoType, String infoValue) { 2103 2104 if (m_userInfos == null) { 2105 m_userInfos = new HashMap<String, Object>(); 2106 } 2107 try { 2108 m_userInfos.put(infoName, CmsDataTypeUtil.dataImport(infoValue, infoType)); 2109 } catch (Throwable e) { 2110 if (LOG.isErrorEnabled()) { 2111 LOG.error(e.getLocalizedMessage(), e); 2112 } 2113 } 2114 } 2115 2116 /** 2117 * Sets the current user as member of the given role.<p> 2118 * 2119 * It can happen that the organizational unit has not been imported jet, 2120 * in this case, the data is kept for later.<p> 2121 * 2122 * @param roleName the name of the role to set 2123 * 2124 * @see #setMembership() 2125 */ 2126 public void importUserRole(String roleName) { 2127 2128 if ((m_throwable != null) || (m_user == null)) { 2129 return; 2130 } 2131 try { 2132 CmsRole role = CmsRole.valueOfRoleName(roleName); 2133 try { 2134 // check if the organizational unit exists 2135 OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), role.getOuFqn()); 2136 // set the user role 2137 OpenCms.getRoleManager().addUserToRole(getCms(), role, m_user.getName()); 2138 return; 2139 } catch (CmsDbEntryNotFoundException e) { 2140 // organizational unit does not exist 2141 } 2142 // remember the user and role for later 2143 Map<String, Map<String, String>> membership = m_membership.get(role.getOuFqn()); 2144 if (membership == null) { 2145 membership = new HashMap<String, Map<String, String>>(); 2146 m_membership.put(role.getOuFqn(), membership); 2147 } 2148 Map<String, String> roles = membership.get(I_CmsPrincipal.PRINCIPAL_USER); 2149 if (roles == null) { 2150 roles = new HashMap<String, String>(); 2151 membership.put(I_CmsPrincipal.PRINCIPAL_USER, roles); 2152 } 2153 roles.put(m_user.getName(), role.getFqn()); 2154 } catch (Throwable e) { 2155 getReport().println( 2156 Messages.get().container(Messages.RPT_USER_COULDNT_BE_ADDED_TO_ROLE_2, m_user.getName(), roleName), 2157 I_CmsReport.FORMAT_WARNING); 2158 if (LOG.isDebugEnabled()) { 2159 LOG.debug(e.getLocalizedMessage(), e); 2160 } 2161 } 2162 } 2163 2164 /** 2165 * Increases the file counter.<p> 2166 */ 2167 public void increaseCounter() { 2168 2169 m_fileCounter++; 2170 } 2171 2172 /** 2173 * Increases the total number of files.<p> 2174 */ 2175 public void increaseTotalFiles() { 2176 2177 m_totalFiles++; 2178 } 2179 2180 /** 2181 * @see org.opencms.importexport.I_CmsImport#matches(org.opencms.importexport.CmsImportParameters) 2182 */ 2183 public boolean matches(CmsImportParameters parameters) throws CmsImportExportException { 2184 2185 m_fileCounter = 1; 2186 m_totalFiles = 0; 2187 m_parseables = new ArrayList<CmsResource>(); 2188 2189 m_parameters = parameters; 2190 2191 // instantiate Digester and enable XML validation 2192 Digester digester = new Digester(); 2193 digester.setUseContextClassLoader(true); 2194 digester.setValidating(m_parameters.isXmlValidation()); 2195 digester.setEntityResolver(new CmsXmlEntityResolver(null)); 2196 digester.setRuleNamespaceURI(null); 2197 digester.setErrorHandler(new CmsXmlErrorHandler(CmsImportExportManager.EXPORT_MANIFEST)); 2198 2199 // add this object to the Digester 2200 digester.push(this); 2201 2202 addXmlPreprocessingDigesterRules(digester); 2203 2204 InputStream stream = null; 2205 m_helper = new CmsImportHelper(m_parameters); 2206 m_helper.cacheDtdSystemId(DTD_LOCATION, DTD_FILENAME, CmsConfigurationManager.DEFAULT_DTD_PREFIX); 2207 try { 2208 m_helper.openFile(); 2209 // start the parsing process 2210 // this will set the version attribute 2211 stream = m_helper.getFileStream(CmsImportExportManager.EXPORT_MANIFEST); 2212 digester.parse(stream); 2213 } catch (Exception ioe) { 2214 CmsMessageContainer msg = Messages.get().container( 2215 Messages.ERR_IMPORTEXPORT_ERROR_READING_FILE_1, 2216 CmsImportExportManager.EXPORT_MANIFEST); 2217 if (LOG.isErrorEnabled()) { 2218 LOG.error(msg.key(), ioe); 2219 } 2220 throw new CmsImportExportException(msg, ioe); 2221 } finally { 2222 try { 2223 if (stream != null) { 2224 stream.close(); 2225 } 2226 } catch (Exception e) { 2227 // noop 2228 } 2229 m_helper.closeFile(); 2230 } 2231 return (m_version == getVersion()); 2232 } 2233 2234 /** 2235 * Rewrites all parseable files, to assure link check.<p> 2236 * 2237 * This is a global process, that is executed only once at the 2238 * end of the import to be sure that all link targets are 2239 * available.<p> 2240 * 2241 * @see #addXmlDigesterRules(Digester) 2242 */ 2243 public void rewriteParseables() { 2244 2245 if (m_parseables.isEmpty()) { 2246 return; 2247 } 2248 2249 I_CmsReport report = getReport(); 2250 CmsObject cms = getCms(); 2251 cms.getRequestContext().setAttribute(CmsLogEntry.ATTR_LOG_ENTRY, Boolean.FALSE); 2252 report.println(Messages.get().container(Messages.RPT_START_PARSE_LINKS_0), I_CmsReport.FORMAT_HEADLINE); 2253 parseLinks(cms, report); 2254 report.println(Messages.get().container(Messages.RPT_END_PARSE_LINKS_0), I_CmsReport.FORMAT_HEADLINE); 2255 m_parseables = null; 2256 } 2257 2258 /** 2259 * Sets the aceFlags.<p> 2260 * 2261 * @param aceFlags the aceFlags to set 2262 * 2263 * @see #N_FLAGS 2264 * @see #addResourceAceRules(Digester, String) 2265 */ 2266 public void setAceFlags(String aceFlags) { 2267 2268 try { 2269 m_aceFlags = Integer.parseInt(aceFlags); 2270 } catch (Throwable e) { 2271 m_throwable = e; 2272 } 2273 } 2274 2275 /** 2276 * Sets the acePermissionsAllowed.<p> 2277 * 2278 * @param acePermissionsAllowed the acePermissionsAllowed to set 2279 * 2280 * @see #N_ACCESSCONTROL_ALLOWEDPERMISSIONS 2281 * @see #addResourceAceRules(Digester, String) 2282 */ 2283 public void setAcePermissionsAllowed(String acePermissionsAllowed) { 2284 2285 try { 2286 m_acePermissionsAllowed = Integer.parseInt(acePermissionsAllowed); 2287 } catch (Throwable e) { 2288 m_throwable = e; 2289 } 2290 } 2291 2292 /** 2293 * Sets the acePermissionsDenied.<p> 2294 * 2295 * @param acePermissionsDenied the acePermissionsDenied to set 2296 * 2297 * @see #N_ACCESSCONTROL_DENIEDPERMISSIONS 2298 * @see #addResourceAceRules(Digester, String) 2299 */ 2300 public void setAcePermissionsDenied(String acePermissionsDenied) { 2301 2302 try { 2303 m_acePermissionsDenied = Integer.parseInt(acePermissionsDenied); 2304 } catch (Throwable e) { 2305 m_throwable = e; 2306 } 2307 } 2308 2309 /** 2310 * Sets the acePrincipalId.<p> 2311 * 2312 * @param acePrincipalId the acePrincipalId to set 2313 * 2314 * @see #N_ACCESSCONTROL_PRINCIPAL 2315 * @see #addResourceAceRules(Digester, String) 2316 */ 2317 public void setAcePrincipalId(String acePrincipalId) { 2318 2319 try { 2320 CmsUUID principalId = null; 2321 String principal = acePrincipalId.substring(acePrincipalId.indexOf('.') + 1, acePrincipalId.length()); 2322 if (acePrincipalId.startsWith(I_CmsPrincipal.PRINCIPAL_GROUP)) { 2323 principal = OpenCms.getImportExportManager().translateGroup(principal); 2324 principalId = getCms().readGroup(principal).getId(); 2325 } else if (acePrincipalId.startsWith(I_CmsPrincipal.PRINCIPAL_USER)) { 2326 principal = OpenCms.getImportExportManager().translateUser(principal); 2327 principalId = getCms().readUser(principal).getId(); 2328 } else if (acePrincipalId.startsWith(CmsRole.PRINCIPAL_ROLE)) { 2329 principalId = CmsRole.valueOfRoleName(principal).getId(); 2330 } else if (acePrincipalId.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME)) { 2331 principalId = CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID; 2332 } else if (acePrincipalId.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME)) { 2333 principalId = CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID; 2334 } else { 2335 if (LOG.isWarnEnabled()) { 2336 LOG.warn( 2337 Messages.get().getBundle().key( 2338 Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_ACE_1, 2339 acePrincipalId)); 2340 } 2341 throw new CmsIllegalStateException( 2342 Messages.get().container(Messages.LOG_IMPORTEXPORT_ERROR_IMPORTING_ACE_1, acePrincipalId)); 2343 } 2344 m_acePrincipalId = principalId; 2345 } catch (Throwable e) { 2346 setThrowable(e); 2347 } 2348 } 2349 2350 /** 2351 * Sets the dateCreated.<p> 2352 * 2353 * @param dateCreated the dateCreated to set 2354 * 2355 * @see #N_DATECREATED 2356 * @see #addResourceAttributesRules(Digester, String) 2357 */ 2358 public void setDateCreated(String dateCreated) { 2359 2360 try { 2361 if (dateCreated != null) { 2362 m_dateCreated = convertTimestamp(dateCreated); 2363 } else { 2364 m_dateCreated = System.currentTimeMillis(); 2365 } 2366 } catch (Throwable e) { 2367 setThrowable(e); 2368 } 2369 } 2370 2371 /** 2372 * Sets the dateExpired.<p> 2373 * 2374 * @param dateExpired the dateExpired to set 2375 * 2376 * @see #N_DATEEXPIRED 2377 * @see #addResourceAttributesRules(Digester, String) 2378 */ 2379 public void setDateExpired(String dateExpired) { 2380 2381 try { 2382 if (dateExpired != null) { 2383 m_dateExpired = convertTimestamp(dateExpired); 2384 } else { 2385 m_dateExpired = CmsResource.DATE_EXPIRED_DEFAULT; 2386 } 2387 } catch (Throwable e) { 2388 setThrowable(e); 2389 } 2390 } 2391 2392 /** 2393 * Sets the dateLastModified.<p> 2394 * 2395 * @param dateLastModified the dateLastModified to set 2396 * 2397 * @see #N_DATELASTMODIFIED 2398 * @see #addResourceAttributesRules(Digester, String) 2399 */ 2400 public void setDateLastModified(String dateLastModified) { 2401 2402 try { 2403 if (dateLastModified != null) { 2404 m_dateLastModified = convertTimestamp(dateLastModified); 2405 } else { 2406 m_dateLastModified = System.currentTimeMillis(); 2407 } 2408 } catch (Throwable e) { 2409 setThrowable(e); 2410 } 2411 } 2412 2413 /** 2414 * Sets the dateReleased.<p> 2415 * 2416 * @param dateReleased the dateReleased to set 2417 * 2418 * @see #N_DATERELEASED 2419 * @see #addResourceAttributesRules(Digester, String) 2420 */ 2421 public void setDateReleased(String dateReleased) { 2422 2423 try { 2424 if (dateReleased != null) { 2425 m_dateReleased = convertTimestamp(dateReleased); 2426 } else { 2427 m_dateReleased = CmsResource.DATE_RELEASED_DEFAULT; 2428 } 2429 } catch (Throwable e) { 2430 setThrowable(e); 2431 } 2432 } 2433 2434 /** 2435 * Sets the destination.<p> 2436 * 2437 * @param destination the destination to set 2438 * 2439 * @see #N_DESTINATION 2440 * @see #addResourceAttributesRules(Digester, String) 2441 */ 2442 public void setDestination(String destination) { 2443 2444 m_destination = destination; 2445 } 2446 2447 /** 2448 * Sets the flags.<p> 2449 * 2450 * @param flags the flags to set 2451 * 2452 * @see #N_FLAGS 2453 * @see #addResourceAttributesRules(Digester, String) 2454 */ 2455 public void setFlags(String flags) { 2456 2457 try { 2458 m_flags = Integer.parseInt(flags); 2459 } catch (Throwable e) { 2460 setThrowable(e); 2461 } 2462 } 2463 2464 /** 2465 * Sets the group Description.<p> 2466 * 2467 * @param groupDescription the description to set 2468 */ 2469 public void setGroupDescription(String groupDescription) { 2470 2471 m_groupDescription = groupDescription; 2472 } 2473 2474 /** 2475 * Sets the group Flags.<p> 2476 * 2477 * @param groupFlags the flags to set 2478 */ 2479 public void setGroupFlags(String groupFlags) { 2480 2481 try { 2482 m_groupFlags = Integer.parseInt(groupFlags); 2483 } catch (Throwable e) { 2484 setThrowable(e); 2485 } 2486 } 2487 2488 /** 2489 * Sets the group Name.<p> 2490 * 2491 * @param groupName the name to set 2492 */ 2493 public void setGroupName(String groupName) { 2494 2495 m_groupName = OpenCms.getImportExportManager().translateGroup(groupName); 2496 } 2497 2498 /** 2499 * Sets the group Parent.<p> 2500 * 2501 * @param groupParent the group Parent to set 2502 */ 2503 public void setGroupParent(String groupParent) { 2504 2505 m_groupParent = OpenCms.getImportExportManager().translateGroup(groupParent); 2506 } 2507 2508 /** 2509 * Sets the membership information that could not been set immediately, 2510 * because of import order issues.<p> 2511 */ 2512 public void setMembership() { 2513 2514 if ((m_orgUnit == null) || (m_membership == null)) { 2515 return; 2516 } 2517 2518 // get the membership data to set 2519 Map<String, Map<String, String>> membership = m_membership.get(m_orgUnit.getName()); 2520 if (membership == null) { 2521 return; 2522 } 2523 2524 // set group membership 2525 Map<String, String> groups = membership.get(I_CmsPrincipal.PRINCIPAL_GROUP); 2526 if (groups != null) { 2527 Iterator<Entry<String, String>> it = groups.entrySet().iterator(); 2528 while (it.hasNext()) { 2529 Entry<String, String> entry = it.next(); 2530 String userName = entry.getKey(); 2531 String groupName = entry.getValue(); 2532 2533 // set the users group 2534 try { 2535 getCms().addUserToGroup(userName, groupName); 2536 } catch (Throwable e) { 2537 getReport().println( 2538 Messages.get().container(Messages.RPT_USER_COULDNT_BE_ADDED_TO_GROUP_2, userName, groupName), 2539 I_CmsReport.FORMAT_WARNING); 2540 if (LOG.isDebugEnabled()) { 2541 LOG.debug(e.getLocalizedMessage(), e); 2542 } 2543 } 2544 } 2545 } 2546 2547 // set role membership 2548 Map<String, String> roles = membership.get(I_CmsPrincipal.PRINCIPAL_USER); 2549 if (roles != null) { 2550 Iterator<Entry<String, String>> it = roles.entrySet().iterator(); 2551 while (it.hasNext()) { 2552 Entry<String, String> entry = it.next(); 2553 String userName = entry.getKey(); 2554 String roleName = entry.getValue(); 2555 2556 // set the users roles 2557 CmsRole role = CmsRole.valueOfRoleName(roleName); 2558 try { 2559 // set the user role 2560 OpenCms.getRoleManager().addUserToRole(getCms(), role, userName); 2561 return; 2562 } catch (Throwable e) { 2563 getReport().println( 2564 Messages.get().container(Messages.RPT_USER_COULDNT_BE_ADDED_TO_ROLE_2, userName, roleName), 2565 I_CmsReport.FORMAT_WARNING); 2566 if (LOG.isDebugEnabled()) { 2567 LOG.debug(e.getLocalizedMessage(), e); 2568 } 2569 } 2570 } 2571 } 2572 } 2573 2574 /** 2575 * Sets the organizational unit description.<p> 2576 * 2577 * @param orgUnitDescription the description to set 2578 */ 2579 public void setOrgUnitDescription(String orgUnitDescription) { 2580 2581 m_orgUnitDescription = orgUnitDescription; 2582 } 2583 2584 /** 2585 * Sets the organizational unit flags.<p> 2586 * 2587 * @param orgUnitFlags the flags to set 2588 */ 2589 public void setOrgUnitFlags(String orgUnitFlags) { 2590 2591 try { 2592 m_orgUnitFlags = Integer.parseInt(orgUnitFlags); 2593 } catch (Throwable e) { 2594 setThrowable(e); 2595 } 2596 } 2597 2598 /** 2599 * Sets the organizational unit name.<p> 2600 * 2601 * @param orgUnitName the name to set 2602 */ 2603 public void setOrgUnitName(String orgUnitName) { 2604 2605 m_orgUnitName = orgUnitName; 2606 } 2607 2608 /** 2609 * Sets the project Description.<p> 2610 * 2611 * @param projectDescription the description to set 2612 */ 2613 public void setProjectDescription(String projectDescription) { 2614 2615 m_projectDescription = projectDescription; 2616 } 2617 2618 /** 2619 * Sets the project Managers group name.<p> 2620 * 2621 * @param projectManagers the managers group to set 2622 */ 2623 public void setProjectManagers(String projectManagers) { 2624 2625 m_projectManagers = projectManagers; 2626 } 2627 2628 /** 2629 * Sets the project Name.<p> 2630 * 2631 * @param projectName the name to set 2632 */ 2633 public void setProjectName(String projectName) { 2634 2635 m_projectName = projectName; 2636 } 2637 2638 /** 2639 * Sets the project Users group name.<p> 2640 * 2641 * @param projectUsers the Users group to set 2642 */ 2643 public void setProjectUsers(String projectUsers) { 2644 2645 m_projectUsers = projectUsers; 2646 } 2647 2648 /** 2649 * Sets the propertyName.<p> 2650 * 2651 * @param propertyName the propertyName to set 2652 * 2653 * @see #N_NAME 2654 * @see #addResourcePropertyRules(Digester, String) 2655 */ 2656 public void setPropertyName(String propertyName) { 2657 2658 m_propertyName = propertyName; 2659 } 2660 2661 /** 2662 * Sets the propertyValue.<p> 2663 * 2664 * @param propertyValue the propertyValue to set 2665 * 2666 * @see #N_VALUE 2667 * @see #addResourcePropertyRules(Digester, String) 2668 */ 2669 public void setPropertyValue(String propertyValue) { 2670 2671 m_propertyValue = propertyValue; 2672 } 2673 2674 /** 2675 * Sets the relationId.<p> 2676 * 2677 * @param relationId the relationId to set 2678 * 2679 * @see #N_ID 2680 * @see #addResourceRelationRules(Digester, String) 2681 */ 2682 public void setRelationId(String relationId) { 2683 2684 try { 2685 m_relationId = new CmsUUID(relationId); 2686 } catch (Throwable e) { 2687 setThrowable(e); 2688 } 2689 } 2690 2691 /** 2692 * Sets the relationPath.<p> 2693 * 2694 * @param relationPath the relationPath to set 2695 * 2696 * @see #N_PATH 2697 * @see #addResourceRelationRules(Digester, String) 2698 */ 2699 public void setRelationPath(String relationPath) { 2700 2701 m_relationPath = relationPath; 2702 } 2703 2704 /** 2705 * Sets the relationType.<p> 2706 * 2707 * @param relationType the relationType to set 2708 * 2709 * @see #N_TYPE 2710 * @see #addResourceRelationRules(Digester, String) 2711 */ 2712 public void setRelationType(String relationType) { 2713 2714 try { 2715 m_relationType = CmsRelationType.valueOf(relationType); 2716 } catch (Throwable e) { 2717 setThrowable(e); 2718 } 2719 } 2720 2721 /** 2722 * Sets the resourceId.<p> 2723 * 2724 * @param resourceId the resourceId to set 2725 * 2726 * @see #N_UUIDRESOURCE 2727 * @see #addResourceAttributesRules(Digester, String) 2728 */ 2729 public void setResourceId(String resourceId) { 2730 2731 try { 2732 if (!m_type.isFolder()) { 2733 m_resourceId = new CmsUUID(resourceId); 2734 } else { 2735 m_resourceId = new CmsUUID(); 2736 } 2737 } catch (Throwable e) { 2738 setThrowable(e); 2739 } 2740 } 2741 2742 /** 2743 * Sets the source.<p> 2744 * 2745 * @param source the source to set 2746 * 2747 * @see #N_SOURCE 2748 * @see #addResourceAttributesRules(Digester, String) 2749 */ 2750 public void setSource(String source) { 2751 2752 m_source = source; 2753 } 2754 2755 /** 2756 * Sets the structureId.<p> 2757 * 2758 * @param structureId the structureId to set 2759 * 2760 * @see #N_UUIDSTRUCTURE 2761 * @see #addResourceAttributesRules(Digester, String) 2762 */ 2763 public void setStructureId(String structureId) { 2764 2765 try { 2766 m_structureId = new CmsUUID(structureId); 2767 } catch (Throwable e) { 2768 setThrowable(e); 2769 } 2770 } 2771 2772 /** 2773 * Sets the throwable.<p> 2774 * 2775 * @param throwable the throwable to set 2776 */ 2777 public void setThrowable(Throwable throwable) { 2778 2779 m_throwable = throwable; 2780 } 2781 2782 /** 2783 * Sets the type.<p> 2784 * 2785 * @param typeName the type to set 2786 * 2787 * @see #N_TYPE 2788 * @see #addResourceAttributesRules(Digester, String) 2789 */ 2790 public void setType(String typeName) { 2791 2792 try { 2793 try { 2794 m_type = OpenCms.getResourceManager().getResourceType(typeName); 2795 } catch (CmsLoaderException e) { 2796 // TODO: what happens if the resource type is a specialized folder and is not configured?? 2797 int plainId; 2798 try { 2799 plainId = OpenCms.getResourceManager().getResourceType( 2800 CmsResourceTypePlain.getStaticTypeName()).getTypeId(); 2801 } catch (CmsLoaderException e1) { 2802 // this should really never happen 2803 plainId = CmsResourceTypePlain.getStaticTypeId(); 2804 } 2805 m_type = OpenCms.getResourceManager().getResourceType(plainId); 2806 } 2807 if (m_type.isFolder()) { 2808 // ensure folders end with a "/" 2809 if (!CmsResource.isFolder(m_destination)) { 2810 m_destination += "/"; 2811 } 2812 } 2813 } catch (Throwable e) { 2814 setThrowable(e); 2815 } 2816 } 2817 2818 /** 2819 * Sets the user Created.<p> 2820 * 2821 * @param userCreated the user Created to set 2822 */ 2823 public void setUserCreated(CmsUUID userCreated) { 2824 2825 m_userCreated = userCreated; 2826 } 2827 2828 /** 2829 * Sets the userCreated.<p> 2830 * 2831 * @param userCreated the userCreated to set 2832 * 2833 * @see #N_USERCREATED 2834 * @see #addResourceAttributesRules(Digester, String) 2835 */ 2836 public void setUserCreated(String userCreated) { 2837 2838 try { 2839 String userCreatedName = OpenCms.getImportExportManager().translateUser(userCreated); 2840 try { 2841 m_userCreated = getCms().readUser(userCreatedName).getId(); 2842 } catch (CmsDbEntryNotFoundException e) { 2843 m_userCreated = getCms().getRequestContext().getCurrentUser().getId(); 2844 } 2845 } catch (Throwable e) { 2846 setThrowable(e); 2847 } 2848 } 2849 2850 /** 2851 * Sets the user Date Created.<p> 2852 * 2853 * @param userDateCreated the date to set 2854 */ 2855 public void setUserDateCreated(String userDateCreated) { 2856 2857 try { 2858 m_userDateCreated = convertTimestamp(userDateCreated); 2859 } catch (Throwable e) { 2860 setThrowable(e); 2861 } 2862 } 2863 2864 /** 2865 * Sets the user email address.<p> 2866 * 2867 * @param userEmail the email address to set 2868 */ 2869 public void setUserEmail(String userEmail) { 2870 2871 m_userEmail = userEmail; 2872 } 2873 2874 /** 2875 * Sets the user First name.<p> 2876 * 2877 * @param userFirstname the first name to set 2878 */ 2879 public void setUserFirstname(String userFirstname) { 2880 2881 m_userFirstname = userFirstname; 2882 } 2883 2884 /** 2885 * Sets the user Flags.<p> 2886 * 2887 * @param userFlags the flags to set 2888 */ 2889 public void setUserFlags(String userFlags) { 2890 2891 try { 2892 m_userFlags = Integer.parseInt(userFlags); 2893 } catch (Throwable e) { 2894 setThrowable(e); 2895 } 2896 } 2897 2898 /** 2899 * Sets the user Last Modified.<p> 2900 * 2901 * @param userLastModified the user Last Modified to set 2902 */ 2903 public void setUserLastModified(CmsUUID userLastModified) { 2904 2905 m_userLastModified = userLastModified; 2906 } 2907 2908 /** 2909 * Sets the userLastModified.<p> 2910 * 2911 * @param userLastModified the userLastModified to set 2912 * 2913 * @see #N_USERLASTMODIFIED 2914 * @see #addResourceAttributesRules(Digester, String) 2915 */ 2916 public void setUserLastModified(String userLastModified) { 2917 2918 try { 2919 String userLastModifiedName = OpenCms.getImportExportManager().translateUser(userLastModified); 2920 try { 2921 m_userLastModified = getCms().readUser(userLastModifiedName).getId(); 2922 } catch (CmsDbEntryNotFoundException e) { 2923 m_userLastModified = getCms().getRequestContext().getCurrentUser().getId(); 2924 } 2925 } catch (Throwable e) { 2926 setThrowable(e); 2927 } 2928 } 2929 2930 /** 2931 * Sets the user Last name.<p> 2932 * 2933 * @param userLastname the last name to set 2934 */ 2935 public void setUserLastname(String userLastname) { 2936 2937 m_userLastname = userLastname; 2938 } 2939 2940 /** 2941 * Sets the user Name.<p> 2942 * 2943 * @param userName the name to set 2944 */ 2945 public void setUserName(String userName) { 2946 2947 m_userName = OpenCms.getImportExportManager().translateUser(userName); 2948 } 2949 2950 /** 2951 * Sets the user Password.<p> 2952 * 2953 * @param userPassword the password to set 2954 */ 2955 public void setUserPassword(String userPassword) { 2956 2957 m_userPassword = new String(Base64.decodeBase64(userPassword.trim().getBytes())); 2958 } 2959 2960 /** 2961 * Sets the export version from the manifest file.<p> 2962 * 2963 * @param version the export version to set 2964 */ 2965 public void setVersion(String version) { 2966 2967 m_version = Integer.parseInt(version); 2968 } 2969 2970 /** 2971 * Adds the XML digester rules for groups.<p> 2972 * 2973 * @param digester the digester to add the rules to 2974 * @param xpath the base xpath for the rules 2975 */ 2976 protected void addAccountsGroupRules(Digester digester, String xpath) { 2977 2978 String xp_group = xpath + N_GROUPS + "/" + N_GROUP; 2979 digester.addCallMethod(xp_group, "importGroup"); 2980 xp_group += "/"; 2981 digester.addCallMethod(xp_group + N_NAME, "setGroupName", 0); 2982 digester.addCallMethod(xp_group + N_DESCRIPTION, "setGroupDescription", 0); 2983 digester.addCallMethod(xp_group + N_FLAGS, "setGroupFlags", 0); 2984 digester.addCallMethod(xp_group + N_PARENTGROUP, "setGroupParent", 0); 2985 } 2986 2987 /** 2988 * Adds the XML digester rules for organizational units.<p> 2989 * 2990 * @param digester the digester to add the rules to 2991 * @param xpath the base xpath for the rules 2992 */ 2993 protected void addAccountsOrgunitRules(Digester digester, String xpath) { 2994 2995 digester.addCallMethod(xpath + N_NAME, "setOrgUnitName", 0); 2996 digester.addCallMethod(xpath + N_DESCRIPTION, "setOrgUnitDescription", 0); 2997 digester.addCallMethod(xpath + N_FLAGS, "setOrgUnitFlags", 0); 2998 digester.addCallMethod(xpath + N_RESOURCES + "/" + N_RESOURCE, "addOrgUnitResource", 0); 2999 digester.addCallMethod(xpath + N_RESOURCES, "importOrgUnit"); 3000 } 3001 3002 /** 3003 * Adds the XML digester rules for users.<p> 3004 * 3005 * @param digester the digester to add the rules to 3006 * @param xpath the base xpath for the rules 3007 */ 3008 protected void addAccountsUserRules(Digester digester, String xpath) { 3009 3010 String xp_user = xpath + N_USERS + "/" + N_USER + "/"; 3011 digester.addCallMethod(xp_user + N_NAME, "setUserName", 0); 3012 digester.addCallMethod(xp_user + N_PASSWORD, "setUserPassword", 0); 3013 digester.addCallMethod(xp_user + N_FIRSTNAME, "setUserFirstname", 0); 3014 digester.addCallMethod(xp_user + N_LASTNAME, "setUserLastname", 0); 3015 digester.addCallMethod(xp_user + N_EMAIL, "setUserEmail", 0); 3016 digester.addCallMethod(xp_user + N_FLAGS, "setUserFlags", 0); 3017 digester.addCallMethod(xp_user + N_DATECREATED, "setUserDateCreated", 0); 3018 digester.addCallMethod(xp_user + N_USERINFO, "importUser"); 3019 3020 String xp_info = xp_user + N_USERINFO + "/" + N_USERINFO_ENTRY; 3021 digester.addCallMethod(xp_info, "importUserInfo", 3); 3022 digester.addCallParam(xp_info, 0, A_NAME); 3023 digester.addCallParam(xp_info, 1, A_TYPE); 3024 digester.addCallParam(xp_info, 2); 3025 3026 digester.addCallMethod(xp_user + N_USERROLES + "/" + N_USERROLE, "importUserRole", 0); 3027 digester.addCallMethod(xp_user + N_USERGROUPS + "/" + N_USERGROUP, "importUserGroup", 0); 3028 } 3029 3030 /** 3031 * Adds the XML digester rules for projects.<p> 3032 * 3033 * @param digester the digester to add the rules to 3034 * @param xpath the base xpath for the rules 3035 */ 3036 protected void addProjectRules(Digester digester, String xpath) { 3037 3038 digester.addCallMethod(xpath + N_NAME, "setProjectName", 0); 3039 digester.addCallMethod(xpath + N_DESCRIPTION, "setProjectDescription", 0); 3040 digester.addCallMethod(xpath + N_MANAGERSGROUP, "setProjectManagers", 0); 3041 digester.addCallMethod(xpath + N_USERSGROUP, "setProjectUsers", 0); 3042 digester.addCallMethod(xpath + N_RESOURCES + "/" + N_RESOURCE, "addProjectResource", 0); 3043 digester.addCallMethod(xpath + N_RESOURCES, "importProject"); 3044 } 3045 3046 /** 3047 * Adds the XML digester rules for resource access control entries.<p> 3048 * 3049 * @param digester the digester to add the rules to 3050 * @param xpath the base xpath for the rules 3051 */ 3052 protected void addResourceAceRules(Digester digester, String xpath) { 3053 3054 String xp_ace = xpath + N_ACCESSCONTROL_ENTRIES + "/" + N_ACCESSCONTROL_ENTRY; 3055 digester.addCallMethod(xpath + N_ACCESSCONTROL_ENTRIES, "importAccessControlEntries"); 3056 digester.addCallMethod(xp_ace, "addAccessControlEntry"); 3057 digester.addCallMethod(xp_ace + "/" + N_ACCESSCONTROL_PRINCIPAL, "setAcePrincipalId", 0); 3058 digester.addCallMethod(xp_ace + "/" + N_FLAGS, "setAceFlags", 0); 3059 String xp_perms = xp_ace + "/" + N_ACCESSCONTROL_PERMISSIONSET + "/"; 3060 digester.addCallMethod(xp_perms + N_ACCESSCONTROL_ALLOWEDPERMISSIONS, "setAcePermissionsAllowed", 0); 3061 digester.addCallMethod(xp_perms + N_ACCESSCONTROL_DENIEDPERMISSIONS, "setAcePermissionsDenied", 0); 3062 } 3063 3064 /** 3065 * Adds the XML digester rules for resource attributes.<p> 3066 * 3067 * @param digester the digester to add the rules to 3068 * @param xpath the base xpath for the rules 3069 */ 3070 protected void addResourceAttributesRules(Digester digester, String xpath) { 3071 3072 digester.addCallMethod(xpath + N_SOURCE, "setSource", 0); 3073 digester.addCallMethod(xpath + N_DESTINATION, "setDestination", 0); 3074 digester.addCallMethod(xpath + N_TYPE, "setType", 0); 3075 digester.addCallMethod(xpath + N_UUIDSTRUCTURE, "setStructureId", 0); 3076 digester.addCallMethod(xpath + N_UUIDRESOURCE, "setResourceId", 0); 3077 digester.addCallMethod(xpath + N_DATELASTMODIFIED, "setDateLastModified", 0); 3078 digester.addCallMethod(xpath + N_USERLASTMODIFIED, "setUserLastModified", 0); 3079 digester.addCallMethod(xpath + N_DATECREATED, "setDateCreated", 0); 3080 digester.addCallMethod(xpath + N_USERCREATED, "setUserCreated", 0); 3081 digester.addCallMethod(xpath + N_DATERELEASED, "setDateReleased", 0); 3082 digester.addCallMethod(xpath + N_DATEEXPIRED, "setDateExpired", 0); 3083 digester.addCallMethod(xpath + N_FLAGS, "setFlags", 0); 3084 } 3085 3086 /** 3087 * Adds the XML digester rules for resource properties.<p> 3088 * 3089 * @param digester the digester to add the rules to 3090 * @param xpath the base xpath for the rules 3091 */ 3092 protected void addResourcePropertyRules(Digester digester, String xpath) { 3093 3094 String xp_props = xpath + N_PROPERTIES + "/" + N_PROPERTY; 3095 // first rule in case the type is implicit 3096 digester.addCallMethod(xp_props, "addProperty"); 3097 // second rule in case the type is given 3098 digester.addCallMethod(xp_props, "addProperty", 1); 3099 digester.addCallParam(xp_props, 0, A_TYPE); 3100 3101 digester.addCallMethod(xp_props + "/" + N_NAME, "setPropertyName", 0); 3102 digester.addCallMethod(xp_props + "/" + N_VALUE, "setPropertyValue", 0); 3103 digester.addCallMethod(xpath + N_PROPERTIES, "importResource"); 3104 } 3105 3106 /** 3107 * Adds the XML digester rules for resource relations.<p> 3108 * 3109 * @param digester the digester to add the rules to 3110 * @param xpath the base xpath for the rules 3111 */ 3112 protected void addResourceRelationRules(Digester digester, String xpath) { 3113 3114 String xp_rels = xpath + N_RELATIONS + "/" + N_RELATION; 3115 digester.addCallMethod(xp_rels, "addRelation"); 3116 digester.addCallMethod(xp_rels + "/" + N_ID, "setRelationId", 0); 3117 digester.addCallMethod(xp_rels + "/" + N_PATH, "setRelationPath", 0); 3118 digester.addCallMethod(xp_rels + "/" + N_TYPE, "setRelationType", 0); 3119 } 3120 3121 /** 3122 * Checks if the resources is in the list of immutable resources.<p> 3123 * 3124 * @param resourceName the name of the resource 3125 * 3126 * @return <code>true</code> or <code>false</code> 3127 */ 3128 protected boolean checkImmutable(String resourceName) { 3129 3130 boolean resourceImmutable = false; 3131 if (getImmutableResources().contains(resourceName)) { 3132 if (LOG.isDebugEnabled()) { 3133 LOG.debug( 3134 Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_RESOURCENAME_IMMUTABLE_1, resourceName)); 3135 } 3136 // this resource must not be modified by an import if it already exists 3137 String storedSiteRoot = getCms().getRequestContext().getSiteRoot(); 3138 try { 3139 getCms().getRequestContext().setSiteRoot("/"); 3140 getCms().readResource(resourceName); 3141 resourceImmutable = true; 3142 if (LOG.isDebugEnabled()) { 3143 LOG.debug( 3144 Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_IMMUTABLE_FLAG_SET_1, resourceName)); 3145 } 3146 } catch (CmsException e) { 3147 // resourceNotImmutable will be true 3148 if (LOG.isDebugEnabled()) { 3149 LOG.debug( 3150 Messages.get().getBundle().key( 3151 Messages.LOG_IMPORTEXPORT_ERROR_ON_TEST_IMMUTABLE_1, 3152 resourceName), 3153 e); 3154 } 3155 } finally { 3156 getCms().getRequestContext().setSiteRoot(storedSiteRoot); 3157 } 3158 } 3159 return resourceImmutable; 3160 } 3161 3162 /** 3163 * Converts a given digest to base64 encoding.<p> 3164 * 3165 * @param value the digest value in the legacy encoding 3166 * 3167 * @return the digest in the new encoding 3168 */ 3169 protected String convertDigestEncoding(String value) { 3170 3171 byte[] data = new byte[value.length() / 2]; 3172 3173 for (int i = 0; i < data.length; i++) { 3174 data[i] = (byte)(Integer.parseInt(value.substring(i * 2, (i * 2) + 2), 16) - 128); 3175 } 3176 return new String(Base64.encodeBase64(data)); 3177 } 3178 3179 /** 3180 * Convert a given time stamp from a String format to a long value.<p> 3181 * 3182 * The time stamp is either the string representation of a long value (old export format) 3183 * or a user-readable string format.<p> 3184 * 3185 * @param timestamp time stamp to convert 3186 * 3187 * @return long value of the time stamp 3188 */ 3189 protected long convertTimestamp(String timestamp) { 3190 3191 long value = 0; 3192 // try to parse the time stamp string 3193 // if it successes, its an old style long value 3194 try { 3195 value = Long.parseLong(timestamp); 3196 } catch (NumberFormatException e) { 3197 // the time stamp was in in a user-readable string format, create the long value form it 3198 try { 3199 value = CmsDateUtil.parseHeaderDate(timestamp); 3200 } catch (ParseException pe) { 3201 value = System.currentTimeMillis(); 3202 } 3203 } 3204 return value; 3205 } 3206 3207 /** 3208 * This method goes through the manifest, records all files from the manifest for which the content also 3209 * exists in the zip file, and stores their resource ids in m_contentFiles.<p> 3210 * 3211 * @throws CmsImportExportException 3212 * @throws IOException 3213 * @throws SAXException 3214 */ 3215 protected void findContentFiles() throws CmsImportExportException, IOException, SAXException { 3216 3217 Digester digester = new Digester(); 3218 digester.setUseContextClassLoader(true); 3219 digester.setValidating(false); 3220 digester.setEntityResolver(new CmsXmlEntityResolver(null)); 3221 digester.setRuleNamespaceURI(null); 3222 digester.setErrorHandler(new CmsXmlErrorHandler(CmsImportExportManager.EXPORT_MANIFEST)); 3223 3224 digester.addCallMethod("export/files/file", "addContentFile", 2); 3225 digester.addCallParam("export/files/file/source", 0); 3226 digester.addCallParam("export/files/file/uuidresource", 1); 3227 m_contentFiles.clear(); 3228 digester.push(this); 3229 InputStream stream = null; 3230 try { 3231 stream = m_helper.getFileStream(CmsImportExportManager.EXPORT_MANIFEST); 3232 digester.parse(stream); 3233 } finally { 3234 if (stream != null) { 3235 stream.close(); 3236 } 3237 } 3238 } 3239 3240 /** 3241 * Gets the import helper instance.<p> 3242 * 3243 * @return the import helper 3244 */ 3245 protected CmsImportHelper getHelper() { 3246 3247 return m_helper; 3248 } 3249 3250 /** 3251 * Returns the list of properties to ignore during import.<p> 3252 * 3253 * @return the list of properties to ignore during import 3254 */ 3255 protected List<String> getIgnoredProperties() { 3256 3257 if (m_ignoredProperties == null) { 3258 // get list of ignored properties 3259 m_ignoredProperties = OpenCms.getImportExportManager().getIgnoredProperties(); 3260 if (m_ignoredProperties == null) { 3261 m_ignoredProperties = Collections.emptyList(); 3262 } 3263 } 3264 return m_ignoredProperties; 3265 } 3266 3267 /** 3268 * Returns the list of immutable resources.<p> 3269 * 3270 * @return the list of immutable resources 3271 */ 3272 protected List<String> getImmutableResources() { 3273 3274 if (m_immutables == null) { 3275 // get list of immutable resources 3276 m_immutables = OpenCms.getImportExportManager().getImmutableResources(); 3277 if (m_immutables == null) { 3278 m_immutables = Collections.emptyList(); 3279 } 3280 if (LOG.isDebugEnabled()) { 3281 LOG.debug( 3282 Messages.get().getBundle().key( 3283 Messages.LOG_IMPORTEXPORT_IMMUTABLE_RESOURCES_SIZE_1, 3284 Integer.toString(m_immutables.size()))); 3285 } 3286 } 3287 return m_immutables; 3288 } 3289 3290 /** 3291 * Sorts the parsealble resources before we actually parse the links.<p> 3292 * 3293 * This is needed because we may, for example, have resources A and B such that A has a link to B, and B requires 3294 * the relation corresponding to that link to be present for some functionality (e.g. the page_title macro in gallery name 3295 * mappings), so we need to parse the links for A first to create the relation before B is processed. 3296 * 3297 * @parameter parseables the list of parseable resources which should be sorted in place 3298 * 3299 */ 3300 protected void sortParseableResources(List<CmsResource> parseables) { 3301 3302 Collections.sort(parseables, new Comparator<CmsResource>() { 3303 3304 public int compare(CmsResource a, CmsResource b) { 3305 3306 return ComparisonChain.start().compare(getRank(a), getRank(b)).compare( 3307 a.getRootPath(), 3308 b.getRootPath()).result(); 3309 } 3310 3311 int getRank(CmsResource res) { 3312 3313 if (CmsResourceTypeXmlContainerPage.isContainerPage(res)) { 3314 return 0; 3315 } else { 3316 return 1; 3317 } 3318 } 3319 }); 3320 3321 } 3322 3323 /** 3324 * Checks whether the content for the resource being imported exists either in the VFS or in the import file.<p> 3325 * 3326 * @param resource the resource which should be checked 3327 * 3328 * @return true if the content exists in the VFS or import file 3329 */ 3330 private boolean hasContentInVfsOrImport(CmsResource resource) { 3331 3332 if (m_contentFiles.contains(resource.getResourceId())) { 3333 return true; 3334 } 3335 try { 3336 List<CmsResource> resources = getCms().readSiblings(resource, CmsResourceFilter.ALL); 3337 if (!resources.isEmpty()) { 3338 return true; 3339 } 3340 } catch (CmsException e) { 3341 LOG.warn(e.getLocalizedMessage(), e); 3342 } 3343 return false; 3344 3345 } 3346 3347 /** 3348 * Parses the links.<p> 3349 * 3350 * @param cms the CMS context to use 3351 * @param report the report 3352 */ 3353 private void parseLinks(CmsObject cms, I_CmsReport report) { 3354 3355 int i = 0; 3356 3357 sortParseableResources(m_parseables); 3358 for (CmsResource parsableRes : m_parseables) { 3359 String resName = cms.getSitePath(parsableRes); 3360 3361 report.print( 3362 org.opencms.report.Messages.get().container( 3363 org.opencms.report.Messages.RPT_SUCCESSION_2, 3364 String.valueOf(i + 1), 3365 String.valueOf(m_parseables.size())), 3366 I_CmsReport.FORMAT_NOTE); 3367 3368 LOG.info("Rewriting parsable resource: " + resName); 3369 report.print(Messages.get().container(Messages.RPT_PARSE_LINKS_FOR_1, resName), I_CmsReport.FORMAT_NOTE); 3370 report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 3371 3372 try { 3373 CmsFile file = cms.readFile(resName); 3374 // make sure the date last modified is kept... 3375 file.setDateLastModified(file.getDateLastModified()); 3376 // make sure the file is locked 3377 CmsLock lock = cms.getLock(file); 3378 if (lock.isUnlocked()) { 3379 cms.lockResource(resName); 3380 } else if (!lock.isDirectlyOwnedInProjectBy(cms)) { 3381 cms.changeLock(resName); 3382 } 3383 // rewrite the file 3384 cms.writeFile(file); 3385 3386 report.println( 3387 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 3388 I_CmsReport.FORMAT_OK); 3389 } catch (Throwable e) { 3390 report.addWarning(e); 3391 report.println( 3392 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_FAILED_0), 3393 I_CmsReport.FORMAT_ERROR); 3394 if (LOG.isWarnEnabled()) { 3395 LOG.warn(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_REWRITING_1, resName)); 3396 LOG.warn(e.getMessage(), e); 3397 } 3398 if (LOG.isDebugEnabled()) { 3399 LOG.debug(e.getLocalizedMessage(), e); 3400 } 3401 } 3402 i++; 3403 } 3404 cms.getRequestContext().removeAttribute(CmsLogEntry.ATTR_LOG_ENTRY); 3405 } 3406}