Project

General

Profile

« Previous | Next » 

Revision 2032

Added by sgarg over 20 years ago

Made changes so that & and other characters dont mess up the url that is passed to metacat.

View differences:

register-dataset.cgi
978 978
    return $paramHasContent;
979 979
}
980 980

  
981
################################################################################
982
#
983
# Subroutine for replacing characters not recognizable by XML and otherwise. 
984
#
985
################################################################################
986
sub normalize{
987
    my $val = shift;
981 988

  
989
    $val =~ s/&/&/g;
990

  
991
    $val =~ s/</&lt;/g;
992
    $val =~ s/>/&gt;/g;
993
    $val =~ s/\"/&quot;/g;
994
    
995
    my $returnVal = "";
996
    
997
    foreach (split(//,$val)){
998
	my $var = unpack "C*", $_; 
999
	
1000
	if($var<128 && $var>31){
1001
	    $returnVal=$returnVal.$_;
1002
	} elsif ($var<32){
1003
	    if($var == 10){
1004
		$returnVal=$returnVal.$_;
1005
	    }
1006
	    if($var == 13){
1007
		$returnVal=$returnVal.$_;
1008
	    }
1009
	    if($var == 9){
1010
		$returnVal=$returnVal.$_;
1011
	    }
1012
	} else { 
1013
	    $returnVal=$returnVal."&#".$var.";";
1014
	}
1015
    }
1016
    
1017
    $returnVal =~ s/&/%26/g;    
1018
    return $returnVal;
1019
}
1020

  
982 1021
################################################################################
983 1022
# 
984 1023
# Create the XML document from the HTML form input
......
996 1035
    my $publ  = "";
997 1036
    my $dso   = "";
998 1037
    my $gmt = gmtime($now);
1038

  
1039

  
999 1040
    my $doc =  "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
1000 1041

  
1001
   $doc .= "<eml:eml\n 
1042
    $doc .= "<eml:eml\n 
1002 1043
                     \t packageId=\"docid\" system=\"knb\"\n 
1003 1044
                     \t xmlns:eml=\"eml://ecoinformatics.org/eml-2.0.0\"\n
1004 1045
                     \t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n 
......
1007 1048
                     \t xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.0.0 eml.xsd\">\n";
1008 1049

  
1009 1050
    $doc .= "<!-- Person who filled in the catalog entry form: ";
1010
    $doc .= "$FORM::providerGivenName $FORM::providerSurName -->\n";
1051
    $doc .= normalize($FORM::providerGivenName)." ".normalize($FORM::providerSurName)." -->\n";
1011 1052
    $doc .= "<!-- Form filled out at $gmt GMT -->\n";
1012 1053
    $doc .= "<dataset>\n";
1013 1054
    
1014 1055
    if (hasContent($FORM::identifier)) {
1015 1056
        $doc .= "<alternateIdentifier system=\"$FORM::site\">";
1016
        $doc .= $FORM::identifier . "</alternateIdentifier>\n";
1057
        $doc .= normalize($FORM::identifier) . "</alternateIdentifier>\n";
1017 1058
    }
1018 1059
    
1019 1060
    if (hasContent($FORM::title)) {
1020
        $doc .= "<title>$FORM::title</title>\n";
1061
        $doc .= "<title>".normalize($FORM::title)."</title>\n";
1021 1062
    }
1022 1063

  
1023 1064
    if (hasContent($FORM::origNamelast0)) {
1024 1065
    $role = "creator";
1025 1066
        $orig .= "<individualName>\n";
1026
        $orig .= "<givenName>$FORM::origNamefirst0</givenName>\n";
1027
        $orig .= "<surName>$FORM::origNamelast0</surName>\n";
1067
        $orig .= "<givenName>".normalize($FORM::origNamefirst0)."</givenName>\n";
1068
        $orig .= "<surName>".normalize($FORM::origNamelast0)."</surName>\n";
1028 1069
        $orig .= "</individualName>\n";
1029 1070
    }
1030 1071

  
1031 1072
    if (hasContent($FORM::origNameOrg)) {
1032
        $orig .= "<organizationName>$FORM::origNameOrg</organizationName>\n";
1073
        $orig .= "<organizationName>".normalize($FORM::origNameOrg)."</organizationName>\n";
1033 1074
    }
1034 1075

  
1035 1076
    if (hasContent($FORM::origDelivery) || hasContent($FORM::origCity) ||
......
1040 1081
        $orig .= "<address>\n";
1041 1082

  
1042 1083
        if (hasContent($FORM::origDelivery)) {
1043
            $orig .= "<deliveryPoint>$FORM::origDelivery</deliveryPoint>\n";
1084
            $orig .= "<deliveryPoint>".normalize($FORM::origDelivery)."</deliveryPoint>\n";
1044 1085
        }
1045 1086
        if (hasContent($FORM::origCity)) {
1046
            $orig .= "<city>$FORM::origCity</city>\n";
1087
            $orig .= "<city>".normalize($FORM::origCity)."</city>\n";
1047 1088
        }
1048 1089

  
1049 1090
    if (hasContent($FORM::origState) && 
1050 1091
            ($FORM::origState !~ "Select state here.")) {
1051
            $orig .= "<administrativeArea>$FORM::origState";
1092
            $orig .= "<administrativeArea>".normalize($FORM::origState);
1052 1093
            $orig .= "</administrativeArea>\n";
1053 1094
        } elsif (hasContent($FORM::origStateOther)) {
1054
            $orig .= "<administrativeArea>$FORM::origStateOther";
1095
            $orig .= "<administrativeArea>".normalize($FORM::origStateOther);
1055 1096
            $orig .= "</administrativeArea>\n";
1056 1097
        }
1057 1098
        if (hasContent($FORM::origZIP)) {
1058
            $orig .= "<postalCode>$FORM::origZIP</postalCode>\n";
1099
            $orig .= "<postalCode>".normalize($FORM::origZIP)."</postalCode>\n";
1059 1100
        }
1060 1101
        if (hasContent($FORM::origCountry)) {
1061
            $orig .= "<country>$FORM::origCountry</country>\n";
1102
            $orig .= "<country>".normalize($FORM::origCountry)."</country>\n";
1062 1103
        }
1063 1104
        $orig .= "</address>\n";
1064 1105
    }
1065 1106

  
1066 1107
    if (hasContent($FORM::origPhone)) {
1067
        $orig .= "<phone>$FORM::origPhone</phone>\n";
1108
        $orig .= "<phone>".normalize($FORM::origPhone)."</phone>\n";
1068 1109
    }
1069 1110
    if (hasContent($FORM::origFAX)) {
1070
        $orig .= "<phone phonetype=\"Fax\">$FORM::origFAX</phone>\n";
1111
        $orig .= "<phone phonetype=\"Fax\">".normalize($FORM::origFAX)."</phone>\n";
1071 1112
    }
1072 1113
    if (hasContent($FORM::origEmail)) {
1073
        $orig .= "<electronicMailAddress>$FORM::origEmail";
1114
        $orig .= "<electronicMailAddress>".normalize($FORM::origEmail);
1074 1115
        $orig .= "</electronicMailAddress>\n";
1075 1116
    }
1076 1117
    $dso = "<$role>\n$orig</$role>\n";
......
1086 1127
        $cont .= "<contact>\n";
1087 1128

  
1088 1129
        $cont .= "<individualName>\n";
1089
        $cont .= "<givenName>$FORM::origNamefirstContact</givenName>\n";
1090
        $cont .= "<surName>$FORM::origNamelastContact</surName>\n";
1130
        $cont .= "<givenName>".normalize($FORM::origNamefirstContact)."</givenName>\n";
1131
        $cont .= "<surName>".normalize($FORM::origNamelastContact)."</surName>\n";
1091 1132
        $cont .= "</individualName>\n";
1092 1133
 
1093 1134
    if (hasContent($FORM::origNameOrgContact)) {
1094
        $cont .= "<organizationName>$FORM::origNameOrgContact</organizationName>\n";
1135
        $cont .= "<organizationName>".normalize($FORM::origNameOrgContact)."</organizationName>\n";
1095 1136
    }
1096 1137

  
1097 1138
        if (hasContent($FORM::origDeliveryContact) || 
......
1103 1144
            hasContent($FORM::origCountryContact)) {
1104 1145
            $cont .= "<address>\n";
1105 1146
            if (hasContent($FORM::origDeliveryContact)) {
1106
                $cont .= "<deliveryPoint>$FORM::origDeliveryContact";
1147
                $cont .= "<deliveryPoint>".normalize($FORM::origDeliveryContact);
1107 1148
                $cont .= "</deliveryPoint>\n";
1108 1149
            }
1109 1150
            if (hasContent($FORM::origCityContact)) {
1110
                $cont .= "<city>$FORM::origCityContact</city>\n";
1151
                $cont .= "<city>".normalize($FORM::origCityContact)."</city>\n";
1111 1152
            }
1112 1153
            if (hasContent($FORM::origStateContact) && 
1113 1154
                ($FORM::origStateContact !~ "Select state here.")) {
1114
                $cont .= "<administrativeArea>$FORM::origStateContact";
1155
                $cont .= "<administrativeArea>".normalize($FORM::origStateContact);
1115 1156
                $cont .= "</administrativeArea>\n";
1116 1157
            } elsif (hasContent($FORM::origStateOtherContact)) {
1117
                $cont .= "<administrativeArea>$FORM::origStateOtherContact";
1158
                $cont .= "<administrativeArea>".normalize($FORM::origStateOtherContact);
1118 1159
                $cont .= "</administrativeArea>\n";
1119 1160
            }
1120 1161
            if (hasContent($FORM::origZIPContact)) {
1121
                $cont .= "<postalCode>$FORM::origZIPContact</postalCode>\n";
1162
                $cont .= "<postalCode>".normalize($FORM::origZIPContact)."</postalCode>\n";
1122 1163
            }
1123 1164
            if (hasContent($FORM::origCountryContact)) {
1124
                $cont .= "<country>$FORM::origCountryContact</country>\n";
1165
                $cont .= "<country>".normalize($FORM::origCountryContact)."</country>\n";
1125 1166
            }
1126 1167
            $cont .= "</address>\n";
1127 1168
        }
1128 1169
        if (hasContent($FORM::origPhoneContact)) {
1129
            $cont .= "<phone>$FORM::origPhoneContact</phone>\n";
1170
            $cont .= "<phone>".normalize($FORM::origPhoneContact)."</phone>\n";
1130 1171
        }
1131 1172
    if (hasContent($FORM::origFAXContact)) {
1132
        $cont .= "<phone phonetype=\"Fax\">$FORM::origFAXContact</phone>\n";
1173
        $cont .= "<phone phonetype=\"Fax\">".normalize($FORM::origFAXContact)."</phone>\n";
1133 1174
    }
1134 1175
        if (hasContent($FORM::origEmailContact)) {
1135
            $cont .= "<electronicMailAddress>$FORM::origEmailContact";
1176
            $cont .= "<electronicMailAddress>".normalize($FORM::origEmailContact);
1136 1177
            $cont .= "</electronicMailAddress>\n";
1137 1178
        }
1138 1179
    $cont .= "</contact>\n";
......
1140 1181

  
1141 1182
    $metaP .= "<metadataProvider>\n";
1142 1183
    $metaP .= "<individualName>\n";
1143
    $metaP .= "<givenName>$FORM::providerGivenName</givenName>\n";
1144
    $metaP .= "<surName>$FORM::providerSurName</surName>\n";
1184
    $metaP .= "<givenName>".normalize($FORM::providerGivenName)."</givenName>\n";
1185
    $metaP .= "<surName>".normalize($FORM::providerSurName)."</surName>\n";
1145 1186
    $metaP .= "</individualName>\n";
1146 1187
    $metaP .= "</metadataProvider>\n";
1147 1188

  
......
1168 1209
            my $add = "";
1169 1210
            $add .= "<individualName>\n";
1170 1211
            $add .= "<givenName>";
1171
            $add .= param("origNamefirst" . $tmp1);
1212
            $add .= normalize(param("origNamefirst" . $tmp1));
1172 1213
            $add .= "</givenName>\n";
1173 1214
            $add .= "<surName>";
1174
            $add .= param("origNamelast" . $tmp1);
1215
            $add .= normalize(param("origNamelast" . $tmp1));
1175 1216
            $add .= "</surName>\n";
1176 1217
            $add .= "</individualName>\n";
1177 1218
            
......
1206 1247
    if ($FORM::cfg eq 'nceas') {
1207 1248
        for (my $i = 0; $i < scalar(@FORM::wg); $i++) {
1208 1249
            $creat .= "<creator>\n";
1209
            $creat .= "<organizationName>$FORM::wg[$i]</organizationName>\n";
1250
            $creat .= "<organizationName>".normalize($FORM::wg[$i])."</organizationName>\n";
1210 1251
            $creat .= "</creator>\n";
1211 1252
        }
1212 1253
    } else {
1213 1254
	$creat .= "<creator>\n";
1214
	$creat .= "<organizationName>$FORM::site</organizationName>\n";
1255
	$creat .= "<organizationName>".normalize($FORM::site)."</organizationName>\n";
1215 1256
	$creat .= "</creator>\n";
1216 1257
    }
1217 1258

  
1218 1259
    $creat .= "<creator>\n";
1219
    $creat .= "<organizationName>$organization</organizationName>\n";
1260
    $creat .= "<organizationName>".normalize($organization)."</organizationName>\n";
1220 1261
    $creat .= "</creator>\n";
1221 1262

  
1222 1263
    $doc .= $creat;
......
1224 1265
    $doc .= $apart;
1225 1266

  
1226 1267
    $doc .= "<abstract>\n";
1227
    $doc .= "<para>$FORM::abstract</para>\n";
1268
    $doc .= "<para>".normalize($FORM::abstract)."</para>\n";
1228 1269
    $doc .= "</abstract>\n";
1229 1270

  
1230 1271
    # Keyword information
......
1245 1286
                         $doc .= "\"";
1246 1287
                    }
1247 1288
                    $doc .= ">";
1248
                    $doc .= param("keyword" . $tmp1);
1289
                    $doc .= normalize(param("keyword" . $tmp1));
1249 1290
                    $doc .= "</keyword>\n";
1250 1291
                    $doc .= "<keywordThesaurus>";
1251
                    $doc .= param("kwTh" . $tmp1);
1292
                    $doc .= normalize(param("kwTh" . $tmp1));
1252 1293
                    $doc .= "</keywordThesaurus>\n";
1253 1294
                    $doc .= "</keywordSet>\n";
1254 1295
                }
......
1258 1299

  
1259 1300
    if (hasContent($FORM::addComments)) {
1260 1301
        $doc .= "<additionalInfo>\n";
1261
        $doc .= "<para>$FORM::addComments</para>\n";
1302
        $doc .= "<para>".normalize($FORM::addComments)."</para>\n";
1262 1303
        $doc .= "</additionalInfo>\n";
1263 1304
    }
1264 1305

  
......
1266 1307
        hasContent($FORM::useConstraintsOther)) {
1267 1308
        $doc .= "<intellectualRights>\n";
1268 1309
        if (hasContent($FORM::useConstraints)) {
1269
            $doc .= "<para>$FORM::useConstraints</para>\n";
1310
            $doc .= "<para>".normalize($FORM::useConstraints)."</para>\n";
1270 1311
        }
1271 1312
        if (hasContent($FORM::useConstraintsOther)) {
1272
            $doc .= "<para>$FORM::useConstraintsOther</para>\n";
1313
            $doc .= "<para>".normalize($FORM::useConstraintsOther)."</para>\n";
1273 1314
        }
1274 1315
        $doc .= "</intellectualRights>\n";
1275 1316
    }
......
1278 1319
    if (hasContent($FORM::url)) {
1279 1320
    $doc .= "<distribution>\n";
1280 1321
        $doc .= "<online>\n";
1281
    $doc .= "<url>$FORM::url</url>\n";
1322
    $doc .= "<url>".normalize($FORM::url)."</url>\n";
1282 1323
    $doc .= "</online>\n";
1283 1324
    $doc .= "</distribution>\n";
1284 1325
    }
1285 1326
    
1286 1327
    $doc .= "<distribution>\n";
1287 1328
    $doc .= "<offline>\n";
1288
    $doc .= "<mediumName>" . "$FORM::dataMedium   $FORM::dataMediumOther";
1329
    $doc .= "<mediumName>" . normalize($FORM::dataMedium)." ".normalize($FORM::dataMediumOther);
1289 1330
    $doc .= "</mediumName>\n";
1290 1331
    $doc .= "</offline>\n";
1291 1332
    $doc .= "</distribution>\n";
......
1302 1343
        [$FORM::beginningMonth - 1];
1303 1344
        $doc .= "<beginDate>\n";
1304 1345
        $doc .= "<calendarDate>";
1305
        $doc .= "$FORM::beginningYear-$FORM::beginningMonth-$FORM::beginningDay";
1346
        $doc .= normalize($FORM::beginningYear)."-".normalize($FORM::beginningMonth)."-".normalize($FORM::beginningDay);
1306 1347
        $doc .= "</calendarDate>\n";
1307 1348
        $doc .= "</beginDate>\n";
1308 1349
    } else {
1309 1350
        $doc .= "<beginDate>\n";
1310 1351
        $doc .= "<calendarDate>";
1311
        $doc .= "$FORM::beginningYear";
1352
        $doc .= normalize($FORM::beginningYear);
1312 1353
        $doc .= "</calendarDate>\n";
1313 1354
        $doc .= "</beginDate>\n";
1314 1355
    }
......
1319 1360
        [$FORM::endingMonth - 1];
1320 1361
        $doc .= "<endDate>\n";
1321 1362
        $doc .= "<calendarDate>";
1322
        $doc .= "$FORM::endingYear-$FORM::endingMonth-$FORM::endingDay";
1363
        $doc .= normalize($FORM::endingYear)."-".normalize($FORM::endingMonth)."-".normalize($FORM::endingDay);
1323 1364
        $doc .= "</calendarDate>\n";
1324 1365
        $doc .= "</endDate>\n";
1325 1366
    } else {
1326 1367
        $doc .= "<endDate>\n";
1327 1368
        $doc .= "<calendarDate>";
1328
        $doc .= "$FORM::endingYear";
1369
        $doc .= normalize($FORM::endingYear);
1329 1370
        $doc .= "</calendarDate>\n";
1330 1371
        $doc .= "</endDate>\n";
1331 1372
    }
......
1337 1378
             "JUL","AUG","SEP","OCT","NOV","DEC")
1338 1379
        [$FORM::beginningMonth - 1];
1339 1380
        $doc .= "<calendarDate>";
1340
        $doc .= "$FORM::beginningYear-$FORM::beginningMonth-$FORM::beginningDay";
1381
	$doc .= normalize($FORM::beginningYear)."-".normalize($FORM::beginningMonth)."-".normalize($FORM::beginningDay);
1341 1382
        $doc .= "</calendarDate>\n";
1342 1383
    } else {
1343 1384
        $doc .= "<calendarDate>";
1344
        $doc .= "$FORM::beginningYear";
1385
	$doc .= normalize($FORM::beginningYear);
1345 1386
        $doc .= "</calendarDate>\n";
1346 1387
    }
1347 1388
    $doc .= "</singleDateTime>\n";
......
1350 1391
    $doc .= "</temporalCoverage>\n";
1351 1392
    
1352 1393
    $doc .= "<geographicCoverage>\n";
1353
    $doc .= "<geographicDescription>$FORM::geogdesc</geographicDescription>\n";
1394
    $doc .= "<geographicDescription>".normalize($FORM::geogdesc)."</geographicDescription>\n";
1354 1395
    $doc .= "<boundingCoordinates>\n";
1355 1396

  
1356 1397
    # if the second latitude is missing, then set the second lat/long pair 
......
1416 1457
                        $doc .= "<taxonomicCoverage>\n";
1417 1458
                        $foundFirstTaxon = 1;
1418 1459
                        if (hasContent($FORM::taxaAuth)) {
1419
                            $doc .= "<generalTaxonomicCoverage>".$FORM::taxaAuth."</generalTaxonomicCoverage>\n";
1460
                            $doc .= "<generalTaxonomicCoverage>".normalize($FORM::taxaAuth)."</generalTaxonomicCoverage>\n";
1420 1461
                        }
1421 1462
                    }
1422 1463
                    $doc .= "<taxonomicClassification>\n";
1423
                    $doc .= "  <taxonRankName>".param($trn)."</taxonRankName>\n";
1424
                    $doc .= "  <taxonRankValue>".param($trv)."</taxonRankValue>\n";
1464
                    $doc .= "  <taxonRankName>".normalize(param($trn))."</taxonRankName>\n";
1465
                    $doc .= "  <taxonRankValue>".normalize(param($trv))."</taxonRankValue>\n";
1425 1466
                    $doc .= "</taxonomicClassification>\n";
1426 1467
                }
1427 1468
            }
......
1439 1480
    if ((hasContent($FORM::methodTitle)) || scalar(@FORM::methodsPara) > 0) {
1440 1481
        my $methods = "<methods><methodStep><description><section>\n";
1441 1482
        if (hasContent($FORM::methodTitle)) {
1442
            $methods .= "<title>$FORM::methodTitle</title>\n";
1483
            $methods .= "<title>".normalize($FORM::methodTitle)."</title>\n";
1443 1484
        }
1444 1485
        for (my $i = 0; $i < scalar(@FORM::methodPara); $i++) {
1445
            $methods .= "<para>$FORM::methodPara[$i]</para>\n";
1486
            $methods .= "<para>".normalize($FORM::methodPara[$i])."</para>\n";
1446 1487
        }
1447 1488
        $methods .= "</section></description></methodStep>\n";
1448 1489
        if (hasContent($FORM::studyExtentDescription)) {
1449 1490
            $methods .= "<sampling><studyExtent><description>\n";
1450
            $methods .= "<para>$FORM::studyExtentDescription</para>\n";
1491
            $methods .= "<para>".normalize($FORM::studyExtentDescription)."</para>\n";
1451 1492
            $methods .= "</description></studyExtent>\n";
1452 1493
            $methods .= "<samplingDescription>\n";
1453
            $methods .= "<para>$FORM::samplingDescription</para>\n";
1494
            $methods .= "<para>".normalize($FORM::samplingDescription)."</para>\n";
1454 1495
            $methods .= "</samplingDescription>\n";
1455 1496
            $methods .= "</sampling>\n";
1456 1497
        }

Also available in: Unified diff