001 //$HeadURL: https://sushibar/svn/deegree/base/trunk/src/org/deegree/framework/xml/Arc2ISO.java $
002 /*----------------------------------------------------------------------------
003 This file is part of deegree, http://deegree.org/
004 Copyright (C) 2001-2009 by:
005 Department of Geography, University of Bonn
006 and
007 lat/lon GmbH
008
009 This library is free software; you can redistribute it and/or modify it under
010 the terms of the GNU Lesser General Public License as published by the Free
011 Software Foundation; either version 2.1 of the License, or (at your option)
012 any later version.
013 This library is distributed in the hope that it will be useful, but WITHOUT
014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016 details.
017 You should have received a copy of the GNU Lesser General Public License
018 along with this library; if not, write to the Free Software Foundation, Inc.,
019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020
021 Contact information:
022
023 lat/lon GmbH
024 Aennchenstr. 19, 53177 Bonn
025 Germany
026 http://lat-lon.de/
027
028 Department of Geography, University of Bonn
029 Prof. Dr. Klaus Greve
030 Postfach 1147, 53001 Bonn
031 Germany
032 http://www.geographie.uni-bonn.de/deegree/
033
034 e-mail: info@deegree.org
035 ----------------------------------------------------------------------------*/
036
037 package org.deegree.ogcwebservices.csw.iso_profile;
038
039 import java.sql.Connection;
040 import java.sql.PreparedStatement;
041 import java.sql.ResultSet;
042 import java.sql.SQLException;
043 import java.util.UUID;
044
045 import org.deegree.framework.log.ILogger;
046 import org.deegree.framework.log.LoggerFactory;
047 import org.deegree.ogcwebservices.csw.CSW202PropertiesAccess;
048
049 /**
050 * <code>Coupling</code>
051 *
052 * @author <a href="mailto:buesching@lat-lon.de">Lyn Buesching</a>
053 * @author last edited by: $Author:$
054 *
055 * @version $Revision:$, $Date:$
056 *
057 */
058 public class Coupling {
059
060 private static final ILogger LOG = LoggerFactory.getLogger( Coupling.class );
061
062 /**
063 * @param identifier
064 * identifier of a data metadataset
065 * @return returns true, if an dataset or series with the given identifier of the MD_DataIdentification element
066 * exists
067 */
068 public static boolean existsRecord( String identifier ) {
069 try {
070 Connection conn = CSW202PropertiesAccess.getConnection();
071 if ( conn != null ) {
072 String sql = "SELECT count(identifier) FROM CQP_Main WHERE identifier = ?";
073 LOG.logDebug( "Request CSW if dataset or series with MD_DataIdentification/identifier/*/code = "
074 + identifier + " exists [" + sql + "]" );
075 PreparedStatement st = conn.prepareStatement( sql );
076 st.setString( 1, identifier );
077 ResultSet rs = st.executeQuery();
078 if ( rs.next() && rs.getInt( 1 ) > 0 ) {
079 return true;
080 }
081 }
082 } catch ( SQLException e ) {
083 LOG.logError( "could not request dataidentification id for fileidentifier " + identifier, e );
084 }
085
086 return false;
087 }
088
089 /**
090 * @return the url of the service
091 */
092 public static String getCSWUrl() {
093 return CSW202PropertiesAccess.getString( "csw.url" );
094 }
095
096 /**
097 * Replaces all ':' with '_' and added the prefix "uuid_" if the given uuid begins with a number or invalid char.
098 *
099 * @param uuid
100 * the uuid
101 * @return the uuid if it is a valid id, otherwise a modified version of the uuid
102 */
103 public static String getValidId( String uuid ) {
104 uuid = uuid.replace( ':', '_' );
105 String first = uuid.substring( 0, 1 );
106 if ( !first.matches( "[a-zA-Z_]" ) ) {
107 return "uuid_" + uuid;
108 }
109 return uuid;
110 }
111
112 /**
113 * @return a random created id, based on a uuid
114 */
115 public static String createValidId() {
116 return getValidId( UUID.randomUUID().toString() );
117 }
118
119 }