114 |
114 |
public static final String EML200 = "eml200";
|
115 |
115 |
public static final String EML210 = "eml210";
|
116 |
116 |
public static final String EXTERNALSCHEMALOCATIONPROPERTY = "http://apache.org/xml/properties/schema/external-schemaLocation";
|
|
117 |
public static final String EXTERNALNONAMESPACESCHEMALOCATIONPROPERTY = "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation";
|
117 |
118 |
public static final String REVISIONTABLE = "xml_revisions";
|
118 |
119 |
public static final String DOCUMENTTABLE = "xml_documents";
|
119 |
120 |
/*
|
... | ... | |
2658 |
2659 |
|
2659 |
2660 |
public static String write(DBConnection conn, String xmlString, String pub,
|
2660 |
2661 |
Reader dtd, String action, String docid, String user,
|
2661 |
|
String[] groups, String ruleBase, boolean needValidation, boolean writeAccessRules, byte[] xmlBytes, String formatId)
|
|
2662 |
String[] groups, String ruleBase, boolean needValidation, boolean writeAccessRules, byte[] xmlBytes, String schemaLocation)
|
2662 |
2663 |
throws Exception
|
2663 |
2664 |
{
|
2664 |
2665 |
//this method will be called in handleUpdateOrInsert method
|
... | ... | |
2666 |
2667 |
// get server location for this doc
|
2667 |
2668 |
int serverLocation = getServerLocationNumber(docid);
|
2668 |
2669 |
return write(conn, xmlString, pub, dtd, action, docid, user, groups,
|
2669 |
|
serverLocation, false, ruleBase, needValidation, writeAccessRules, xmlBytes, formatId);
|
|
2670 |
serverLocation, false, ruleBase, needValidation, writeAccessRules, xmlBytes, schemaLocation);
|
2670 |
2671 |
}
|
2671 |
2672 |
|
2672 |
2673 |
/**
|
... | ... | |
2703 |
2704 |
public static String write(DBConnection conn, String xmlString, String pub,
|
2704 |
2705 |
Reader dtd, String action, String accnum, String user,
|
2705 |
2706 |
String[] groups, int serverCode, boolean override, String ruleBase,
|
2706 |
|
boolean needValidation, boolean writeAccessRules, byte[] xmlBytes, String formatId) throws Exception
|
|
2707 |
boolean needValidation, boolean writeAccessRules, byte[] xmlBytes, String schemaLocation) throws Exception
|
2707 |
2708 |
{
|
2708 |
2709 |
// NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT
|
2709 |
2710 |
|
... | ... | |
2790 |
2791 |
logMetacat.debug("DocumentImpl.write - initializing parser");
|
2791 |
2792 |
parser = initializeParser(conn, action, docid, xmlReader, updaterev,
|
2792 |
2793 |
user, groups, pub, serverCode, dtd, ruleBase,
|
2793 |
|
needValidation, false, null, null, encoding, writeAccessRules, guidsToSync, formatId);
|
|
2794 |
needValidation, false, null, null, encoding, writeAccessRules, guidsToSync, schemaLocation);
|
2794 |
2795 |
// false means it is not a revision doc
|
2795 |
2796 |
//null, null are createdate and updatedate
|
2796 |
2797 |
//null will use current time as create date time
|
... | ... | |
2894 |
2895 |
Vector<String>guidsToSync = new Vector<String>();
|
2895 |
2896 |
|
2896 |
2897 |
parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups,
|
2897 |
|
pub, serverCode, dtd, ruleBase, needValidation, false, null, null, encoding, writeAccessRules, guidsToSync, formatId);
|
|
2898 |
pub, serverCode, dtd, ruleBase, needValidation, false, null, null, encoding, writeAccessRules, guidsToSync, schemaLocation);
|
2898 |
2899 |
// null and null are createtime and updatetime
|
2899 |
2900 |
// null will create current time
|
2900 |
2901 |
//false means it is not a revision doc
|
2901 |
2902 |
|
2902 |
2903 |
conn.setAutoCommit(false);
|
2903 |
|
logMetacat.debug("DocumentImpl.write - XML to be parsed: " + xmlString);
|
|
2904 |
//logMetacat.debug("DocumentImpl.write - XML to be parsed: " + xmlString);
|
2904 |
2905 |
parser.parse(new InputSource(xmlReader));
|
2905 |
2906 |
|
2906 |
2907 |
conn.commit();
|
... | ... | |
3038 |
3039 |
String pub, Reader dtd, String action, String accnum, String user,
|
3039 |
3040 |
String[] groups, String homeServer, String notifyServer,
|
3040 |
3041 |
String ruleBase, boolean needValidation, String tableName,
|
3041 |
|
boolean timedReplication, Date createDate, Date updateDate, String formatId) throws Exception
|
|
3042 |
boolean timedReplication, Date createDate, Date updateDate, String schemaLocation) throws Exception
|
3042 |
3043 |
{
|
3043 |
3044 |
// Get the xml as a string so we can write to file later
|
3044 |
3045 |
StringReader xmlReader = new StringReader(xmlString);
|
... | ... | |
3106 |
3107 |
|
3107 |
3108 |
parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups,
|
3108 |
3109 |
pub, serverCode, dtd, ruleBase, needValidation,
|
3109 |
|
isRevision, createDate, updateDate, encoding, writeAccessRules, guidsToSync, formatId);
|
|
3110 |
isRevision, createDate, updateDate, encoding, writeAccessRules, guidsToSync, schemaLocation);
|
3110 |
3111 |
|
3111 |
3112 |
conn.setAutoCommit(false);
|
3112 |
3113 |
parser.parse(new InputSource(xmlReader));
|
... | ... | |
3725 |
3726 |
String action, String docid, Reader xml, String rev, String user,
|
3726 |
3727 |
String[] groups, String pub, int serverCode, Reader dtd,
|
3727 |
3728 |
String ruleBase, boolean needValidation, boolean isRevision,
|
3728 |
|
Date createDate, Date updateDate, String encoding, boolean writeAccessRules, Vector<String> guidsToSync, String formatId) throws Exception
|
|
3729 |
Date createDate, Date updateDate, String encoding, boolean writeAccessRules, Vector<String> guidsToSync, String schemaLocation) throws Exception
|
3729 |
3730 |
{
|
3730 |
3731 |
XMLReader parser = null;
|
3731 |
3732 |
try {
|
... | ... | |
3736 |
3737 |
// Get an instance of the parser
|
3737 |
3738 |
String parserName = PropertyService.getProperty("xml.saxparser");
|
3738 |
3739 |
parser = XMLReaderFactory.createXMLReader(parserName);
|
3739 |
|
XMLSchemaService.getInstance().populateRegisteredSchemaList();
|
|
3740 |
//XMLSchemaService.getInstance().populateRegisteredSchemaList();
|
3740 |
3741 |
if (ruleBase != null && ruleBase.equals(EML200)) {
|
3741 |
3742 |
logMetacat.info("DocumentImpl.initalizeParser - Using eml 2.0.0 parser");
|
3742 |
3743 |
chandler = new Eml200SAXHandler(dbconn, action, docid, rev,
|
... | ... | |
3747 |
3748 |
parser.setErrorHandler((ErrorHandler) chandler);
|
3748 |
3749 |
parser.setProperty(DECLARATIONHANDLERPROPERTY, chandler);
|
3749 |
3750 |
parser.setProperty(LEXICALPROPERTY, chandler);
|
3750 |
|
// turn on schema validation feature
|
3751 |
|
parser.setFeature(VALIDATIONFEATURE, true);
|
3752 |
3751 |
parser.setFeature(NAMESPACEFEATURE, true);
|
3753 |
|
//parser.setFeature(NAMESPACEPREFIXESFEATURE, true);
|
3754 |
|
parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
|
3755 |
|
// From DB to find the register external schema location
|
3756 |
|
String externalSchemaLocation = null;
|
3757 |
|
// SchemaLocationResolver resolver = new SchemaLocationResolver();
|
3758 |
|
logMetacat.debug("DocumentImpl.initalizeParser - the final formatId of the object "+docid+" is "+formatId);
|
3759 |
|
externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocation(formatId);
|
3760 |
|
if(externalSchemaLocation == null) {
|
3761 |
|
logMetacat.info("DocumentImpl.initalizeParser - there is no register schemas for the formatid "+ formatId+". So we will use the old way."+
|
3762 |
|
" Put all registred schema/location paris for the validation.");
|
3763 |
|
externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocationStringWithoutFormatId();
|
3764 |
|
|
3765 |
|
}
|
3766 |
|
logMetacat.info("DocumentImpl.initalizeParser - 2.0.0 external schema location: " + externalSchemaLocation);
|
3767 |
|
// Set external schemalocation.
|
3768 |
|
if (externalSchemaLocation != null
|
3769 |
|
&& !(externalSchemaLocation.trim()).equals("")) {
|
3770 |
|
parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
|
3771 |
|
externalSchemaLocation);
|
3772 |
|
} else {
|
3773 |
|
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.");
|
|
3752 |
if(needValidation) {
|
|
3753 |
logMetacat.info("DocumentImpl.initalizeParser - 2.0.0 parser sets up validation feature since the parameter of the needValidataion is "+needValidation);
|
|
3754 |
// turn on schema validation feature
|
|
3755 |
parser.setFeature(VALIDATIONFEATURE, true);
|
|
3756 |
//parser.setFeature(NAMESPACEPREFIXESFEATURE, true);
|
|
3757 |
parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
|
|
3758 |
logMetacat.info("DocumentImpl.initalizeParser - 2.0.0 external schema location: " + schemaLocation);
|
|
3759 |
// Set external schemalocation.
|
|
3760 |
if (schemaLocation != null
|
|
3761 |
&& !(schemaLocation.trim()).equals("")) {
|
|
3762 |
parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
|
|
3763 |
schemaLocation);
|
|
3764 |
} else {
|
|
3765 |
throw new Exception ("The schema for the namespace on docid "+docid+" can't be found in any place. So we can't validate the xml instance.");
|
|
3766 |
}
|
3774 |
3767 |
}
|
3775 |
|
logMetacat.debug("DocumentImpl.initalizeParser - 2.0.0 parser configured");
|
|
3768 |
|
|
3769 |
logMetacat.info("DocumentImpl.initalizeParser - 2.0.0 parser configured");
|
3776 |
3770 |
} else if (ruleBase != null && ruleBase.equals(EML210)) {
|
3777 |
3771 |
logMetacat.info("DocumentImpl.initalizeParser - Using eml 2.1.0 parser");
|
3778 |
3772 |
chandler = new Eml210SAXHandler(dbconn, action, docid, rev,
|
... | ... | |
3784 |
3778 |
parser.setProperty(DECLARATIONHANDLERPROPERTY, chandler);
|
3785 |
3779 |
parser.setProperty(LEXICALPROPERTY, chandler);
|
3786 |
3780 |
// turn on schema validation feature
|
3787 |
|
parser.setFeature(VALIDATIONFEATURE, true);
|
3788 |
3781 |
parser.setFeature(NAMESPACEFEATURE, true);
|
3789 |
|
//parser.setFeature(NAMESPACEPREFIXESFEATURE, true);
|
3790 |
|
parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
|
3791 |
|
// From DB to find the register external schema location
|
3792 |
|
String externalSchemaLocation = null;
|
3793 |
|
logMetacat.debug("DocumentImpl.initalizeParser - the final formatId of the object "+docid+" is "+formatId);
|
3794 |
|
externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocation(formatId);
|
3795 |
|
if(externalSchemaLocation == null) {
|
3796 |
|
logMetacat.info("DocumentImpl.initalizeParser - there is no register schemas for the formatid "+ formatId+". So we will use the old way."+
|
3797 |
|
" Put all registred schema/location paris for the validation.");
|
3798 |
|
externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocationStringWithoutFormatId();
|
3799 |
|
|
3800 |
|
}
|
3801 |
|
logMetacat.info("DocumentImpl.initalizeParser - 2.1.0 external schema location: " + externalSchemaLocation);
|
3802 |
|
// Set external schemalocation.
|
3803 |
|
if (externalSchemaLocation != null
|
3804 |
|
&& !(externalSchemaLocation.trim()).equals("")) {
|
3805 |
|
parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
|
3806 |
|
externalSchemaLocation);
|
3807 |
|
} else {
|
3808 |
|
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.");
|
|
3782 |
if(needValidation) {
|
|
3783 |
logMetacat.info("DocumentImpl.initalizeParser - 2.1.0 parser sets up validation features since the parameter of the needValidataion is "+needValidation);
|
|
3784 |
parser.setFeature(VALIDATIONFEATURE, true);
|
|
3785 |
//parser.setFeature(NAMESPACEPREFIXESFEATURE, true);
|
|
3786 |
parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
|
|
3787 |
logMetacat.info("DocumentImpl.initalizeParser - 2.1.0 external schema location: " + schemaLocation);
|
|
3788 |
// Set external schemalocation.
|
|
3789 |
if (schemaLocation != null
|
|
3790 |
&& !(schemaLocation.trim()).equals("")) {
|
|
3791 |
parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
|
|
3792 |
schemaLocation);
|
|
3793 |
} else {
|
|
3794 |
throw new Exception ("The schema for the docid "+docid+" can't be found in any place. So we can't validate the xml instance.");
|
|
3795 |
}
|
3809 |
3796 |
}
|
3810 |
3797 |
logMetacat.debug("DocumentImpl.initalizeParser - Using eml 2.1.0 parser configured");
|
3811 |
3798 |
} else {
|
... | ... | |
3824 |
3811 |
&& needValidation) {
|
3825 |
3812 |
|
3826 |
3813 |
XMLSchemaService xmlss = XMLSchemaService.getInstance();
|
3827 |
|
xmlss.doRefresh();
|
|
3814 |
//xmlss.doRefresh();
|
3828 |
3815 |
logMetacat.info("DocumentImpl.initalizeParser - Using General schema parser");
|
3829 |
3816 |
// turn on schema validation feature
|
3830 |
3817 |
parser.setFeature(VALIDATIONFEATURE, true);
|
... | ... | |
3838 |
3825 |
if (xmlss.useFullSchemaValidation() && !allSchemasRegistered) {
|
3839 |
3826 |
parser.setFeature(FULLSCHEMAVALIDATIONFEATURE, true);
|
3840 |
3827 |
}
|
3841 |
|
// From DB to find the register external schema location
|
3842 |
|
String externalSchemaLocation = null;
|
3843 |
|
logMetacat.debug("DocumentImpl.initalizeParser - the final formatId of the object "+docid+" is "+formatId);
|
3844 |
|
externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocation(formatId);
|
3845 |
|
if(externalSchemaLocation == null) {
|
3846 |
|
logMetacat.info("DocumentImpl.initalizeParser - there is no register schemas for the formatid "+ formatId+". So we will use the old way."+
|
3847 |
|
" Put all registred schema/location paris for the validation.");
|
3848 |
|
externalSchemaLocation = XMLSchemaService.getInstance().getNameSpaceAndLocationStringWithoutFormatId();
|
3849 |
|
|
3850 |
|
}
|
3851 |
|
logMetacat.info("DocumentImpl.initalizeParser - Generic external schema location: " + externalSchemaLocation);
|
|
3828 |
logMetacat.info("DocumentImpl.initalizeParser - Generic external schema location: " + schemaLocation);
|
3852 |
3829 |
// Set external schemalocation.
|
3853 |
|
if (externalSchemaLocation != null
|
3854 |
|
&& !(externalSchemaLocation.trim()).equals("")) {
|
|
3830 |
if (schemaLocation != null
|
|
3831 |
&& !(schemaLocation.trim()).equals("")) {
|
3855 |
3832 |
parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
|
3856 |
|
externalSchemaLocation);
|
|
3833 |
schemaLocation);
|
3857 |
3834 |
} else {
|
3858 |
|
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.");
|
|
3835 |
throw new Exception ("The schema for the document "+docid+" can't be found in any place. So we can't validate the xml instance.");
|
3859 |
3836 |
}
|
3860 |
|
|
|
3837 |
} else if (ruleBase != null && ruleBase.equals(NONAMESPACESCHEMA)
|
|
3838 |
&& needValidation) {
|
|
3839 |
//xmlss.doRefresh();
|
|
3840 |
logMetacat.info("DocumentImpl.initalizeParser - Using General schema parser");
|
|
3841 |
// turn on schema validation feature
|
|
3842 |
parser.setFeature(VALIDATIONFEATURE, true);
|
|
3843 |
parser.setFeature(NAMESPACEFEATURE, true);
|
|
3844 |
//parser.setFeature(NAMESPACEPREFIXESFEATURE, true);
|
|
3845 |
parser.setFeature(SCHEMAVALIDATIONFEATURE, true);
|
|
3846 |
logMetacat.info("DocumentImpl.initalizeParser - Generic external no-namespace schema location: " + schemaLocation);
|
|
3847 |
// Set external schemalocation.
|
|
3848 |
if (schemaLocation != null
|
|
3849 |
&& !(schemaLocation.trim()).equals("")) {
|
|
3850 |
parser.setProperty(EXTERNALNONAMESPACESCHEMALOCATIONPROPERTY,
|
|
3851 |
schemaLocation);
|
|
3852 |
} else {
|
|
3853 |
throw new Exception ("The schema for the document "+docid+" can't be found in any place. So we can't validate the xml instance.");
|
|
3854 |
}
|
3861 |
3855 |
} else if (ruleBase != null && ruleBase.equals(DTD)
|
3862 |
3856 |
&& needValidation) {
|
3863 |
3857 |
logMetacat.info("DocumentImpl.initalizeParser - Using dtd parser");
|
Add the feature to support the noNamespaceSchemalLocation and refactory the code.