001/* 002 * File : $Source$ 003 * Date : $Date$ 004 * Version: $Revision$ 005 * 006 * This library is part of OpenCms - 007 * the Open Source Content Management System 008 * 009 * Copyright (C) 2002 - 2009 Alkacon Software (http://www.alkacon.com) 010 * 011 * This library is free software; you can redistribute it and/or 012 * modify it under the terms of the GNU Lesser General Public 013 * License as published by the Free Software Foundation; either 014 * version 2.1 of the License, or (at your option) any later version. 015 * 016 * This library is distributed in the hope that it will be useful, 017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 * Lesser General Public License for more details. 020 * 021 * For further information about Alkacon Software, please see the 022 * company website: http://www.alkacon.com 023 * 024 * For further information about OpenCms, please see the 025 * project website: http://www.opencms.org 026 * 027 * You should have received a copy of the GNU Lesser General Public 028 * License along with this library; if not, write to the Free Software 029 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 030 */ 031 032package org.opencms.staticexport; 033 034import org.opencms.site.CmsSite; 035import org.opencms.util.CmsStringUtil; 036 037import java.util.Comparator; 038 039/** 040 * A bean for a export name. Combines the export name with the site information<p> 041 */ 042public class CmsExportname { 043 044 /** 045 * A export name comparator.<p> 046 */ 047 public static class CmsExportNameComparator implements Comparator<CmsExportname> { 048 049 /** A slash comparator. */ 050 private CmsStringUtil.CmsSlashComparator m_comp = new CmsStringUtil.CmsSlashComparator(); 051 052 /** 053 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) 054 */ 055 public int compare(CmsExportname o1, CmsExportname o2) { 056 057 if (((o1.getSite() == null) && (o2.getSite() == null)) 058 || ((o1.getSite() == null) && (o2.getSite() != null)) 059 || ((o1.getSite() != null) && (o2.getSite() == null)) 060 || o1.getSite().getSiteRoot().equals(o2.getSite().getSiteRoot())) { 061 return m_comp.compare(o1.getExportname(), o2.getExportname()); 062 } else { 063 int siteComp = o1.getSite().getSiteRoot().compareTo(o2.getSite().getSiteRoot()); 064 if (siteComp == 0) { 065 return m_comp.compare(o1.getExportname(), o2.getExportname()); 066 } 067 return siteComp; 068 } 069 } 070 } 071 072 /** The value of the exportname property. */ 073 private String m_exportname; 074 075 /** 076 * The according site.<p> 077 */ 078 private CmsSite m_site; 079 080 /** 081 * Constructor with parameters.<p> 082 * 083 * @param exportname the export name 084 * @param site the site object 085 */ 086 public CmsExportname(String exportname, CmsSite site) { 087 088 m_exportname = exportname; 089 m_site = site; 090 } 091 092 /** 093 * @see java.lang.Object#equals(java.lang.Object) 094 */ 095 @Override 096 public boolean equals(Object obj) { 097 098 if (this == obj) { 099 return true; 100 } 101 if (obj == null) { 102 return false; 103 } 104 if (getClass() != obj.getClass()) { 105 return false; 106 } 107 CmsExportname other = (CmsExportname)obj; 108 if (m_exportname == null) { 109 if (other.m_exportname != null) { 110 return false; 111 } 112 } else if (!m_exportname.equals(other.m_exportname)) { 113 return false; 114 } 115 if (m_site == null) { 116 if (other.m_site != null) { 117 return false; 118 } 119 } else if (!m_site.equals(other.m_site)) { 120 return false; 121 } 122 return true; 123 } 124 125 /** 126 * Returns the value of the 'exportname' property.<p> 127 * 128 * @return the value of the 'exportname' property 129 */ 130 public String getExportname() { 131 132 return m_exportname; 133 } 134 135 /** 136 * Returns the site.<p> 137 * 138 * @return the site 139 */ 140 public CmsSite getSite() { 141 142 return m_site; 143 } 144 145 /** 146 * @see java.lang.Object#hashCode() 147 */ 148 @Override 149 public int hashCode() { 150 151 final int prime = 31; 152 int result = 1; 153 result = (prime * result) + ((m_exportname == null) ? 0 : m_exportname.hashCode()); 154 result = (prime * result) + ((m_site == null) ? 0 : m_site.hashCode()); 155 return result; 156 } 157 158 /** 159 * Sets the export name.<p> 160 * 161 * @param exportname the value to set the export name to 162 */ 163 public void setExportname(String exportname) { 164 165 m_exportname = exportname; 166 } 167 168 /** 169 * Sets the site.<p> 170 * 171 * @param site the site to set 172 */ 173 public void setSite(CmsSite site) { 174 175 m_site = site; 176 } 177 178 /** 179 * @see java.lang.Object#toString() 180 */ 181 @Override 182 public String toString() { 183 184 return "CmsExportName [m_exportname=" + m_exportname + ", m_site=" + m_site + "]"; 185 } 186}