Project

General

Profile

« Previous | Next » 

Revision 9583

Added by Jing Tao over 8 years ago

If a format id in the system metadata is registered in the xml_catalog table, we will use the schema location for the format id to validate the xml instance;
otherwise, we will use our previous way.

View differences:

src/edu/ucsb/nceas/metacat/DBSAXHandler.java
446 446
        				throw new SAXException("Odd number of elements found when parsing schema location: " + 	
447 447
        						attributeValue + ". There should be an even number of uri/files in location.");
448 448
        			}
449
        			//since we don't have format id information here, we set it null
450
        			String formatId = null;
449 451
        			XMLSchema xmlSchema = 
450
        				new XMLSchema(parsedUri.get(j), parsedUri.get(j + 1));
452
        				new XMLSchema(parsedUri.get(j), parsedUri.get(j + 1), formatId);
451 453
        			schemaList.add(xmlSchema);
452 454
        		}
453 455
            }
src/edu/ucsb/nceas/metacat/DocumentImpl.java
2657 2657

  
2658 2658
    public static String write(DBConnection conn, String xmlString, String pub,
2659 2659
            Reader dtd, String action, String docid, String user,
2660
            String[] groups, String ruleBase, boolean needValidation, boolean writeAccessRules, byte[] xmlBytes)
2660
            String[] groups, String ruleBase, boolean needValidation, boolean writeAccessRules, byte[] xmlBytes, String formatId)
2661 2661
            throws Exception
2662 2662
    {
2663 2663
        //this method will be called in handleUpdateOrInsert method
......
2665 2665
        // get server location for this doc
2666 2666
        int serverLocation = getServerLocationNumber(docid);
2667 2667
        return write(conn, xmlString, pub, dtd, action, docid, user, groups,
2668
                serverLocation, false, ruleBase, needValidation, writeAccessRules, xmlBytes);
2668
                serverLocation, false, ruleBase, needValidation, writeAccessRules, xmlBytes, formatId);
2669 2669
    }
2670 2670

  
2671 2671
    /**
......
2702 2702
    public static String write(DBConnection conn, String xmlString, String pub,
2703 2703
            Reader dtd, String action, String accnum, String user,
2704 2704
            String[] groups, int serverCode, boolean override, String ruleBase,
2705
            boolean needValidation, boolean writeAccessRules, byte[] xmlBytes) throws Exception
2705
            boolean needValidation, boolean writeAccessRules, byte[] xmlBytes, String formatId) throws Exception
2706 2706
    {
2707 2707
        // NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT
2708 2708
    	
......
2789 2789
                    logMetacat.debug("DocumentImpl.write - initializing parser");
2790 2790
                    parser = initializeParser(conn, action, docid, xmlReader, updaterev,
2791 2791
                            user, groups, pub, serverCode, dtd, ruleBase,
2792
                            needValidation, false, null, null, encoding, writeAccessRules, guidsToSync);
2792
                            needValidation, false, null, null, encoding, writeAccessRules, guidsToSync, formatId);
2793 2793
                    	// false means it is not a revision doc
2794 2794
                                   //null, null are createdate and updatedate
2795 2795
                                   //null will use current time as create date time
......
2893 2893
	        Vector<String>guidsToSync = new Vector<String>();
2894 2894

  
2895 2895
            parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups,
2896
                    pub, serverCode, dtd, ruleBase, needValidation, false, null, null, encoding, writeAccessRules, guidsToSync);
2896
                    pub, serverCode, dtd, ruleBase, needValidation, false, null, null, encoding, writeAccessRules, guidsToSync, formatId);
2897 2897
                    // null and null are createtime and updatetime
2898 2898
                    // null will create current time
2899 2899
                    //false means it is not a revision doc
......
3037 3037
            String pub, Reader dtd, String action, String accnum, String user,
3038 3038
            String[] groups, String homeServer, String notifyServer,
3039 3039
            String ruleBase, boolean needValidation, String tableName, 
3040
            boolean timedReplication, Date createDate, Date updateDate) throws Exception
3040
            boolean timedReplication, Date createDate, Date updateDate, String formatId) throws Exception
3041 3041
    {
3042 3042
    	// Get the xml as a string so we can write to file later
3043 3043
    	StringReader xmlReader = new StringReader(xmlString);
......
3105 3105

  
3106 3106
            parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups,
3107 3107
                    pub, serverCode, dtd, ruleBase, needValidation, 
3108
                    isRevision, createDate, updateDate, encoding, writeAccessRules, guidsToSync);
3108
                    isRevision, createDate, updateDate, encoding, writeAccessRules, guidsToSync, formatId);
3109 3109
         
3110 3110
            conn.setAutoCommit(false);
3111 3111
            parser.parse(new InputSource(xmlReader));
......
3721 3721
            String action, String docid, Reader xml, String rev, String user,
3722 3722
            String[] groups, String pub, int serverCode, Reader dtd,
3723 3723
            String ruleBase, boolean needValidation, boolean isRevision,
3724
            Date createDate, Date updateDate, String encoding, boolean writeAccessRules, Vector<String> guidsToSync) throws Exception
3724
            Date createDate, Date updateDate, String encoding, boolean writeAccessRules, Vector<String> guidsToSync, String formatId) throws Exception
3725 3725
    {
3726 3726
        XMLReader parser = null;
3727 3727
        try {
......
3751 3751
                // From DB to find the register external schema location
3752 3752
                String externalSchemaLocation = null;
3753 3753
//                SchemaLocationResolver resolver = new SchemaLocationResolver();
3754
                externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocationString();
3755
                logMetacat.debug("DocumentImpl.initalizeParser - 2.0.0 external schema location: " + externalSchemaLocation);
3754
                logMetacat.debug("DocumentImpl.initalizeParser - the final formatId of the object "+docid+" is "+formatId);
3755
                externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocation(formatId);
3756
                if(externalSchemaLocation == null) {
3757
                    logMetacat.info("DocumentImpl.initalizeParser - there is no register schemas for the formatid "+ formatId+". So we will use the old way."+
3758
                    " Put all registred schema/location paris for the validation.");
3759
                    externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocationStringWithoutFormatId();
3760
                    
3761
                } 
3762
                logMetacat.info("DocumentImpl.initalizeParser - 2.0.0 external schema location: " + externalSchemaLocation);
3756 3763
                // Set external schemalocation.
3757 3764
                if (externalSchemaLocation != null
3758 3765
                        && !(externalSchemaLocation.trim()).equals("")) {
3759 3766
                    parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
3760 3767
                            externalSchemaLocation);
3768
                } else {
3769
                    throw new Exception ("The schema for the format id "+formatId+" can't be found in any place. So we can't validate the xml instance.");
3761 3770
                }
3762 3771
                logMetacat.debug("DocumentImpl.initalizeParser - 2.0.0 parser configured");
3763 3772
            } else if (ruleBase != null && ruleBase.equals(EML210)) {
......
3777 3786
                parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
3778 3787
                // From DB to find the register external schema location
3779 3788
                String externalSchemaLocation = null;
3780
                externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocationString();
3781
                logMetacat.debug("DocumentImpl.initalizeParser - 2.1.0 external schema location: " + externalSchemaLocation);
3789
                logMetacat.debug("DocumentImpl.initalizeParser - the final formatId of the object "+docid+" is "+formatId);
3790
                externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocation(formatId);
3791
                if(externalSchemaLocation == null) {
3792
                    logMetacat.info("DocumentImpl.initalizeParser - there is no register schemas for the formatid "+ formatId+". So we will use the old way."+
3793
                    " Put all registred schema/location paris for the validation.");
3794
                    externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocationStringWithoutFormatId();
3795
                    
3796
                } 
3797
                logMetacat.info("DocumentImpl.initalizeParser - 2.1.0 external schema location: " + externalSchemaLocation);
3782 3798
                // Set external schemalocation.
3783 3799
                if (externalSchemaLocation != null
3784 3800
                        && !(externalSchemaLocation.trim()).equals("")) {
3785 3801
                    parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
3786 3802
                            externalSchemaLocation);
3803
                } else {
3804
                    throw new Exception ("The schema for the format id "+formatId+" can't be found in any place. So we can't validate the xml instance.");
3787 3805
                }
3788 3806
                logMetacat.debug("DocumentImpl.initalizeParser - Using eml 2.1.0 parser configured");
3789 3807
            } else {
......
3818 3836
                    }
3819 3837
                    // From DB to find the register external schema location
3820 3838
                    String externalSchemaLocation = null;
3821
                    externalSchemaLocation = xmlss.getNameSpaceAndLocationString();
3822
                    logMetacat.debug("DocumentImpl.initalizeParser - Generic external schema location: " + externalSchemaLocation);              
3839
                    logMetacat.debug("DocumentImpl.initalizeParser - the final formatId of the object "+docid+" is "+formatId);
3840
                    externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocation(formatId);
3841
                    if(externalSchemaLocation == null) {
3842
                        logMetacat.info("DocumentImpl.initalizeParser - there is no register schemas for the formatid "+ formatId+". So we will use the old way."+
3843
                        " Put all registred schema/location paris for the validation.");
3844
                        externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocationStringWithoutFormatId();
3845
                        
3846
                    } 
3847
                    logMetacat.info("DocumentImpl.initalizeParser - Generic external schema location: " + externalSchemaLocation);              
3823 3848
                    // Set external schemalocation.
3824 3849
                    if (externalSchemaLocation != null
3825 3850
                            && !(externalSchemaLocation.trim()).equals("")) {
3826 3851
                        parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
3827 3852
                                externalSchemaLocation);
3853
                    } else {
3854
                        throw new Exception ("The schema for the format id "+formatId+" can't be found in any place. So we can't validate the xml instance.");
3828 3855
                    }
3829 3856

  
3830 3857
                } else if (ruleBase != null && ruleBase.equals(DTD)
src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java
59 59
	}//Constructor
60 60

  
61 61
	public String write(DBConnection conn, String xml, String pub, Reader dtd,
62
			String action, String docid, String user, String[] groups, byte[]xmlBytes) throws Exception {
62
			String action, String docid, String user, String[] groups, byte[]xmlBytes, String formatId) throws Exception {
63 63
		return DocumentImpl.write(conn, xml, pub, dtd, action, docid, user, groups,
64
				ruleBase, needValidation, writeAccessRules, xmlBytes);
64
				ruleBase, needValidation, writeAccessRules, xmlBytes, formatId);
65 65
	}
66 66

  
67 67
	public String writeReplication(DBConnection conn, String xml, byte[]xmlBytes, String pub, Reader dtd,
68 68
			String action, String accnum, String user, String[] groups,
69
			String homeServer, String notifyServer, Date createDate, Date updateDate)
69
			String homeServer, String notifyServer, Date createDate, Date updateDate, String formatId)
70 70
			throws Exception {
71 71
		//we don't need to check validation in replication
72 72
		// so rule base is null and need validation is false (first false)
......
74 74
		// and timed replication is false (last false)
75 75
		return DocumentImpl.writeReplication(conn, xml, xmlBytes, pub, dtd, action, accnum, user,
76 76
				groups, homeServer, notifyServer, ruleBase, false,
77
				DocumentImpl.DOCUMENTTABLE, false, createDate, updateDate);
77
				DocumentImpl.DOCUMENTTABLE, false, createDate, updateDate, formatId);
78 78
		// last false means is not timed replication
79 79

  
80 80
	}
......
99 99
	public String writeReplication(DBConnection conn, String xml, byte[]xmlBytes, String pub, Reader dtd,
100 100
			String action, String accnum, String user, String[] groups,
101 101
			String homeServer, String notifyServer, String tableName,
102
			boolean timedReplication, Date createDate, Date updateDate)
102
			boolean timedReplication, Date createDate, Date updateDate, String formatId)
103 103
			throws Exception {
104 104
		//we don't need to check validation in replication
105 105
		// so rule base is null and need validation is false
106 106
		return DocumentImpl.writeReplication(conn, xml, xmlBytes, pub, dtd, action, accnum, user,
107 107
				groups, homeServer, notifyServer, ruleBase, false, tableName,
108
				timedReplication, createDate, updateDate);
108
				timedReplication, createDate, updateDate, formatId);
109 109
	}
110 110

  
111 111
}
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
687 687
		// if we get here, metacat is configured.  If we have not completed the 
688 688
		// second half of the initialization, do so now.  This allows us to initially
689 689
		// configure metacat without a restart.
690
		logMetacat.info("MetacatServlet.handleGetOrPost - the _fullyInitailzied value is "+_fullyInitialized);
690 691
		if (!_fullyInitialized) {
691 692
			initSecondHalf(request.getSession().getServletContext());
692 693
		}
......
917 918
                }
918 919
				PrintWriter out = response.getWriter();
919 920
				if ((userName != null) && !userName.equals("public")) {
921
				    //formatid will be set null here since this is metacat api
922
				    String formatId = null;
920 923
					handler.handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), response, out, params, userName,
921
							groupNames, true, true, null);
924
							groupNames, true, true, null, formatId);
922 925
				} else {
923 926
					response.setContentType("text/xml");
924 927
					out.println("<?xml version=\"1.0\"?>");
src/edu/ucsb/nceas/metacat/MetacatHandler.java
1628 1628
     */
1629 1629
    public String handleInsertOrUpdateAction(String ipAddress, String userAgent,
1630 1630
            HttpServletResponse response, PrintWriter out, Hashtable<String, String[]> params,
1631
            String user, String[] groups, boolean generateSystemMetadata, boolean writeAccessRules, byte[] xmlBytes) {
1631
            String user, String[] groups, boolean generateSystemMetadata, boolean writeAccessRules, byte[] xmlBytes, String formatId) {
1632 1632
        Logger logMetacat = Logger.getLogger(MetacatHandler.class);
1633 1633
        DBConnection dbConn = null;
1634 1634
        int serialNumber = -1;
......
1805 1805
              
1806 1806
              } else {*/
1807 1807
              newdocid = documentWrapper.write(dbConn, doctext[0], pub, dtd,
1808
                          doAction, accNumber, user, groups, xmlBytes);
1808
                          doAction, accNumber, user, groups, xmlBytes, formatId);
1809 1809
            
1810 1810
              EventLog.getInstance().log(ipAddress, userAgent, user, accNumber, action[0]);
1811 1811
              
......
3197 3197
                params.put("doctext", doctextArr);
3198 3198
                boolean writeAccessRules = true;
3199 3199
                //call the insert routine
3200
                String formatId = null;
3200 3201
                handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), response, out, 
3201
                          params, username, groupnames, true, writeAccessRules, null);
3202
                          params, username, groupnames, true, writeAccessRules, null, formatId);
3202 3203
              }
3203 3204
              catch(Exception e)
3204 3205
              {
src/edu/ucsb/nceas/metacat/SchemaLocationResolver.java
339 339
    } 
340 340
  }
341 341
  
342
  public static void main(String[] argus)
342
  /*public static void main(String[] argus)
343 343
  {
344 344
     try
345 345
     {
......
368 368
       logMetacat.error("erorr in Schemalocation.main: " + 
369 369
                                e.getMessage());
370 370
     }
371
  }
371
  }*/
372 372
  
373 373
  /**
374 374
   * Gets the downloadNewSchema's value.
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
447 447
      	//String objectAsXML = "";
448 448
        try {
449 449
	        //objectAsXML = IOUtils.toString(object, "UTF-8");
450
	        localId = insertOrUpdateDocument(object,"UTF-8", pid, session, "insert");
450
            String formatId = null;
451
            if(sysmeta.getFormatId() != null)  {
452
                formatId = sysmeta.getFormatId().getValue();
453
            }
454
	        localId = insertOrUpdateDocument(object,"UTF-8", pid, session, "insert", formatId);
451 455
	        //localId = im.getLocalId(pid.getValue());
452 456

  
453 457
        } catch (IOException e) {
......
1269 1273
          " is science metadata: " + e.getMessage());*/
1270 1274
    
1271 1275
    } catch (NotFound e) {
1272
      logMetacat.debug("There was a problem determining if the object identified by" + 
1276
      logMetacat.warn("There was a problem determining if the object identified by" + 
1273 1277
          sysmeta.getIdentifier().getValue() + 
1274 1278
          " is science metadata: " + e.getMessage());
1275 1279
    
......
1303 1307
   * 
1304 1308
   */
1305 1309
  public String insertOrUpdateDocument(InputStream xml, String encoding,  Identifier pid, 
1306
    Session session, String insertOrUpdate) 
1310
    Session session, String insertOrUpdate, String formatId) 
1307 1311
    throws ServiceFailure, IOException {
1308 1312
    
1309 1313
  	logMetacat.debug("Starting to insert xml document...");
......
1376 1380
    // do the insert or update action
1377 1381
    handler = new MetacatHandler(new Timer());
1378 1382
    String result = handler.handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), null, 
1379
                        null, params, username, groupnames, false, false, xmlBytes);
1383
                        null, params, username, groupnames, false, false, xmlBytes, formatId);
1380 1384
    
1381 1385
    if(result.indexOf("<error>") != -1) {
1382 1386
    	String detailCode = "";
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
474 474
                //String objectAsXML = "";
475 475
                try {
476 476
                    //objectAsXML = IOUtils.toString(object, "UTF-8");
477
                	
478
                    localId = insertOrUpdateDocument(object, "UTF-8", pid, session, "update");
477
                	String formatId = null;
478
                	if(sysmeta.getFormatId() != null) {
479
                	    formatId = sysmeta.getFormatId().getValue();
480
                	}
481
                    localId = insertOrUpdateDocument(object, "UTF-8", pid, session, "update", formatId);
479 482
                    
480 483
                    // register the newPid and the generated localId
481 484
                    if (newPid != null) {
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java
456 456
      {
457 457
        parserBase = DocumentImpl.EML210;
458 458
      }
459
      
460
      String formatId = null;
461
      //get the format id from the system metadata 
462
      if(sysMeta != null && sysMeta.getFormatId() != null) {
463
          logMetacat.debug("ReplicationService.handleForceReplicateRequest - the format id will be got from the system metadata for the object "+accNumber);
464
          formatId = sysMeta.getFormatId().getValue();
465
      }
459 466
      // Write the document into local host
460 467
      DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false, false);
461 468
      String newDocid = wrapper.writeReplication(dbConn,
......
469 476
                              docHomeServer,
470 477
                              remoteserver, tableName, true,// true is for time replication 
471 478
                              createdDate,
472
                              updatedDate);
479
                              updatedDate, formatId);
473 480
      
474 481
      if(sysMeta != null) {
475 482
			// submit for indexing. When the doc writing process fails, the index process will fail as well. But this failure
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
731 731
				parserBase = DocumentImpl.EML210;
732 732
			}
733 733
			logReplication.warn("ReplicationService.handleForceReplicateRequest - The parserBase is: " + parserBase);
734

  
734
			
735
			String formatId = null;
736
		    //get the format id from the system metadata 
737
		    if(sysMeta != null && sysMeta.getFormatId() != null) {
738
		          logMetacat.debug("ReplicationService.handleForceReplicateRequest - the format id will be got from the system metadata for the object "+docid);
739
		          formatId = sysMeta.getFormatId().getValue();
740
		    }
741
		      
735 742
			// Get DBConnection from pool
736 743
			dbConn = DBConnectionPool
737 744
					.getDBConnection("MetacatReplication.handleForceReplicateRequest");
......
742 749
			try {
743 750
				wrapper.writeReplication(dbConn, xmldoc, xmlBytes, null, null,
744 751
						dbaction, docid, null, null, homeServer, server, createdDate,
745
						updatedDate);
752
						updatedDate, formatId);
746 753
			} finally {
747 754
				if(sysMeta != null) {
748 755
					// submit for indexing. When the doc writing process fails, the index process will fail as well. But this failure
src/edu/ucsb/nceas/metacat/service/XMLSchema.java
39 39
	private String fileName = null;
40 40
	private String localFileUri = null;
41 41
	private String localFileDir = null;
42
	private String formatId = null;
42 43
	
43
	private Logger logMetacat = Logger.getLogger(XMLSchema.class);
44 44

  
45
    private Logger logMetacat = Logger.getLogger(XMLSchema.class);
46

  
45 47
	/**
46 48
	 * Constructor - the schema file name will be extracted from the external
47 49
	 * file uri. The local file uri and local file dir will be constructed using
......
52 54
	 * @param externalFileUri
53 55
	 *            the external uri where the schema is located
54 56
	 */
55
	public XMLSchema(String fileNamespace, String externalFileUri) {
57
	public XMLSchema(String fileNamespace, String externalFileUri, String formatId) {
56 58
		setFileNamespace(fileNamespace);
57 59
		setExternalFileUri(externalFileUri);
60
		setFormatId(formatId);
58 61
	}
59 62
	
60 63
	/**
......
64 67
	 * @param namespace
65 68
	 *            the file's name space
66 69
	 */
67
	public XMLSchema(String fileNamespace) {
70
	/*public XMLSchema(String fileNamespace) {
68 71
		setFileNamespace(fileNamespace);
69
	}
72
	}*/
70 73
	
71 74
	/**
72 75
	 * Set the file name. The local file uri and local file dir will also get
......
202 205
	public String getLocalFileDir() {
203 206
		return localFileDir;
204 207
	}
208
	
209
	
210
	/**
211
	 * Get the format id
212
	 * @return the format id
213
	 */
214
	public String getFormatId() {
215
        return formatId;
216
    }
217

  
218
	/**
219
	 * Set the format id. 
220
	 * @param formatId. 
221
	 */
222
    public void setFormatId(String formatId) {
223
            this.formatId = formatId;
224
    }
205 225
}
src/edu/ucsb/nceas/metacat/service/XMLSchemaService.java
37 37
import java.sql.PreparedStatement;
38 38
import java.sql.ResultSet;
39 39
import java.sql.SQLException;
40
import java.util.Hashtable;
40 41
import java.util.Vector;
41 42
import java.util.regex.Matcher;
42 43
import java.util.regex.Pattern;
......
77 78
    private static Vector<String> nameSpaceList = new Vector<String>();
78 79
    
79 80
    // a convenience string that holds all name spaces and locations in a space
80
    // delimited format
81
    private static String nameSpaceAndLocationString = ""; 
81
    // delimited format. Those items don't have a format id. This is the old way we handle the schema location
82
    private static String nameSpaceAndLocationStringWithoutFormatId = ""; 
82 83
	
84
    //this hash table is design for schema variants. Two schemas have the same name space,
85
    //but they have different content (location). So we different format id to
86
    //distinguish them. The key of the hash table is the format id, the values is all the namespace schema location
87
    //delimited string for this format id.
88
    private static Hashtable<String, String> formatId_NamespaceLocationHash = new Hashtable<String, String>();
83 89
	/**
84 90
	 * private constructor since this is a singleton
85 91
	 */
......
142 148
	/**
143 149
	 * Gets the name space and location string. This is a convenience method.
144 150
	 * The string will have space delimited namespaces and locations that are
145
	 * held in the registered schema list.
151
	 * held in the registered schema list. This is the old way Metacat worked.
152
	 * Usually, we will call the method getNameSapceAndLocation(String formatId) first.
153
	 * If the method return null, we will call this method.
146 154
	 * 
147 155
	 * @return a string that holds space delimited registered namespaces and
148 156
	 *         locations.
149 157
	 */
150
	public String getNameSpaceAndLocationString() {
151
		return nameSpaceAndLocationString;
158
	public String getNameSpaceAndLocationStringWithoutFormatId() {
159
		return nameSpaceAndLocationStringWithoutFormatId;
152 160
	}
153 161
	
162
	
154 163
	/**
164
	 * Get the all schema-location pairs registered for the formatId.
165
	 * The null will be returned, if we can find it.
166
	 * @param formatId
167
	 * @return
168
	 */
169
	public String getNameSpaceAndLocation(String formatId) {
170
	    if(formatId == null) {
171
	        return null;
172
	    } else {
173
	        return formatId_NamespaceLocationHash.get(formatId);
174
	    }
175
	}
176
	
177
	/**
155 178
	 * Gets a list of name spaces. This is a convenience method. The list will 
156 179
	 * have all namespaces that are held in the registered schema list.
157 180
	 * 
......
196 219
		registeredSchemaList = new Vector<XMLSchema>();
197 220

  
198 221
		// get the system id from the xml_catalog table for all schemas.
199
		String sql = "SELECT public_id, system_id FROM xml_catalog where "
222
		String sql = "SELECT public_id, system_id, format_id FROM xml_catalog where "
200 223
				+ "entry_type ='" + DocumentImpl.SCHEMA + "'";
201 224
		try {
202 225
			// check out DBConnection
......
213 236
			while (resultSet.next()) {
214 237
				String fileNamespace = resultSet.getString(1);
215 238
				String fileLocation = resultSet.getString(2);
216
				logMetacat.debug("XMLService.populateRegisteredSchemaList - Registering schema: " + fileNamespace + " " + fileLocation);
217
				XMLSchema xmlSchema = new XMLSchema(fileNamespace);
239
				String formatId = resultSet.getString(3);
240
				logMetacat.debug("XMLService.populateRegisteredSchemaList - Registering schema: " + fileNamespace + " " + fileLocation+ " and format id "+formatId);
241
				XMLSchema xmlSchema = new XMLSchema(fileNamespace, fileLocation, formatId);
218 242
				if(fileLocation.startsWith("http://") || fileLocation.startsWith("https://"))
219 243
				{
220 244
				    //System.out.println("processing an http schemal location");
......
310 334
	 * in the registered schema list.
311 335
	 */
312 336
	private static void createRegisteredNameSpaceAndLocationString() {
313
		boolean firstRow = true;
314
		nameSpaceAndLocationString = "";
337
		boolean firstRowWithoutFormatid = true;
338
		boolean firstRowWithFormatid = true;
339
		nameSpaceAndLocationStringWithoutFormatId = "";
315 340
		
316 341
		for (XMLSchema xmlSchema : registeredSchemaList) {
317
			if (!firstRow) {
318
				nameSpaceAndLocationString += " ";
319
			}
320
			nameSpaceAndLocationString += xmlSchema.getFileNamespace() + " "
321
					+ xmlSchema.getLocalFileUri();
322
			firstRow = false;
342
		    String formatId = xmlSchema.getFormatId();
343
		    if( formatId == null ||formatId.trim().equals("")) {
344
		        //this is to handle the old way - no schema variants 
345
		        if (!firstRowWithoutFormatid) {
346
	                nameSpaceAndLocationStringWithoutFormatId += " ";
347
	            }
348
	            nameSpaceAndLocationStringWithoutFormatId += xmlSchema.getFileNamespace() + " "
349
	                    + xmlSchema.getLocalFileUri();
350
	            firstRowWithoutFormatid = false;
351
		    } else {
352
		        //it has a format id on the xml_catalog table. It is a variant.
353
		        if(!formatId_NamespaceLocationHash.containsKey(xmlSchema.getFormatId())) {
354
		            //the hash table hasn't stored the value. So put it on the hash.
355
		            formatId_NamespaceLocationHash.put(formatId, xmlSchema.getFileNamespace() + " "
356
	                        + xmlSchema.getLocalFileUri());
357
		        } else {
358
		          //the hash table already has it. We will attache the new pair to the exist value
359
		            String value = formatId_NamespaceLocationHash.get(formatId);
360
		            value += " "+ xmlSchema.getFileNamespace() + " "
361
	                        + xmlSchema.getLocalFileUri();
362
		            formatId_NamespaceLocationHash.put(formatId, value);
363
		        }
364
		    }
365
			
323 366
		}
324 367
	}
325 368

  
......
419 462
										+ targetLine
420 463
										+ ". There should be an even number of uri/files in location.");
421 464
					}
465
					String formatId = null;
422 466
					XMLSchema xmlSchema = new XMLSchema(parsedUri.get(j), parsedUri
423
							.get(j + 1));
467
							.get(j + 1), formatId);
424 468
					schemaList.add(xmlSchema);
425 469
				}
426 470
				i = matcher.end();
src/edu/ucsb/nceas/metacat/util/EMLVersionsTransformer.java
159 159
             DBConnection dbconn = null;
160 160
             StringReader dtd = null;
161 161
             int serialNumber = -1;
162
             String formatId = null;
162 163
             try
163 164
             {
164 165
            	 dbconn = DBConnectionPool
165 166
                 .getDBConnection("EMLVersionsTransformer.handleSingleEML200Document");
166 167
                  serialNumber = dbconn.getCheckOutSerialNumber();
167 168
                  documentWrapper.write(dbconn, eml210Content, pub, dtd,
168
                          doAction, newId, owner, groups, null);
169
                          doAction, newId, owner, groups, null, formatId);
169 170
                  logMetacat.warn("Doc "+docidWithRev+" was transformed to eml210 with new id "+newId);
170 171
                  transformLog("Doc "+docidWithRev+" was transformed to eml210 with new id "+newId);
171 172
             }

Also available in: Unified diff