Revision 1407
Added by Jing Tao almost 22 years ago
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
67 | 67 |
*/ |
68 | 68 |
public class DocumentImpl { |
69 | 69 |
|
70 |
/* Constents */
|
|
70 |
/* Constants */
|
|
71 | 71 |
public static final String SCHEMA = "schema"; |
72 | 72 |
public static final String DTD = "dtd"; |
73 |
public static final String EML2 = "eml2"; |
|
73 | 74 |
public static final String EXTERNALSCHEMALOCATIONPROPERTY = |
74 | 75 |
"http://apache.org/xml/properties/schema/external-schemaLocation"; |
75 |
public static final String EXTERNALSCHEMALOCATION = |
|
76 |
/*public static final String EXTERNALSCHEMALOCATION =
|
|
76 | 77 |
"eml://ecoinformatics.org/eml-2.0.0 http://dev.nceas.ucsb.edu/tao/schema/eml.xsd"+ |
77 |
" http://www.xml-cml.org/schema/stmml http://dev.nceas.ucsb.edu/tao/schema/stmml.xsd"; |
|
78 |
" http://www.xml-cml.org/schema/stmml http://dev.nceas.ucsb.edu/tao/schema/stmml.xsd";*/
|
|
78 | 79 |
public static final String DECLARATIONHANDLERPROPERTY = |
79 | 80 |
"http://xml.org/sax/properties/declaration-handler"; |
80 | 81 |
public static final String LEXICALPROPERTY = |
... | ... | |
1847 | 1848 |
XMLReader parser = null; |
1848 | 1849 |
try |
1849 | 1850 |
{ |
1850 |
|
|
1851 |
//create a DBSAXHandler object which has the revision specification |
|
1852 |
ContentHandler chandler = new DBSAXHandler(dbconn, action, |
|
1853 |
docid, rev, user, groups, pub, serverCode); |
|
1851 |
// handler |
|
1852 |
ContentHandler chandler; |
|
1854 | 1853 |
EntityResolver eresolver; |
1855 | 1854 |
DTDHandler dtdhandler; |
1856 |
|
|
1857 | 1855 |
// Get an instance of the parser |
1858 | 1856 |
String parserName = MetaCatUtil.getOption("saxparser"); |
1859 | 1857 |
parser = XMLReaderFactory.createXMLReader(parserName); |
1860 |
parser.setContentHandler((ContentHandler)chandler); |
|
1861 |
parser.setErrorHandler((ErrorHandler)chandler); |
|
1862 |
parser.setProperty(DECLARATIONHANDLERPROPERTY, chandler); |
|
1863 |
parser.setProperty(LEXICALPROPERTY, chandler); |
|
1864 |
|
|
1865 |
if (ruleBase != null && ruleBase.equals(SCHEMA) && needValidation) |
|
1858 |
if (ruleBase != null && ruleBase.equals(EML2)) |
|
1866 | 1859 |
{ |
1860 |
MetaCatUtil.debugMessage("eml 2 parser", 20); |
|
1861 |
chandler = new EmlSAXHandler(dbconn, action, |
|
1862 |
docid, rev, user, groups, pub, serverCode); |
|
1863 |
parser.setContentHandler((ContentHandler)chandler); |
|
1864 |
parser.setErrorHandler((ErrorHandler)chandler); |
|
1865 |
parser.setProperty(DECLARATIONHANDLERPROPERTY, chandler); |
|
1866 |
parser.setProperty(LEXICALPROPERTY, chandler); |
|
1867 | 1867 |
// turn on schema validation feature |
1868 | 1868 |
parser.setFeature(VALIDATIONFEATURE, true); |
1869 | 1869 |
parser.setFeature(NAMESPACEFEATURE, true); |
... | ... | |
1877 | 1877 |
if (externalSchemaLocation != null && |
1878 | 1878 |
!(externalSchemaLocation.trim()).equals("")) |
1879 | 1879 |
{ |
1880 |
parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY, |
|
1880 |
parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY,
|
|
1881 | 1881 |
externalSchemaLocation); |
1882 | 1882 |
} |
1883 |
|
|
1884 | 1883 |
} |
1885 |
else if (ruleBase != null && ruleBase.equals(DTD) && needValidation) |
|
1886 |
{ |
|
1887 |
// turn on dtd validaton feature |
|
1888 |
parser.setFeature(VALIDATIONFEATURE, true); |
|
1889 |
eresolver= new DBEntityResolver(dbconn, (DBSAXHandler)chandler, dtd); |
|
1890 |
dtdhandler = new DBDTDHandler(dbconn); |
|
1891 |
parser.setEntityResolver((EntityResolver)eresolver); |
|
1892 |
parser.setDTDHandler((DTDHandler)dtdhandler); |
|
1893 |
} |
|
1894 | 1884 |
else |
1895 | 1885 |
{ |
1896 |
// non validation |
|
1897 |
parser.setFeature(VALIDATIONFEATURE, false); |
|
1898 |
eresolver= new DBEntityResolver(dbconn, (DBSAXHandler)chandler, dtd); |
|
1899 |
dtdhandler = new DBDTDHandler(dbconn); |
|
1900 |
parser.setEntityResolver((EntityResolver)eresolver); |
|
1901 |
parser.setDTDHandler((DTDHandler)dtdhandler); |
|
1902 |
} |
|
1903 |
|
|
1886 |
//create a DBSAXHandler object which has the revision specification |
|
1887 |
chandler = new DBSAXHandler(dbconn, action, |
|
1888 |
docid, rev, user, groups, pub, serverCode); |
|
1889 |
parser.setContentHandler((ContentHandler)chandler); |
|
1890 |
parser.setErrorHandler((ErrorHandler)chandler); |
|
1891 |
parser.setProperty(DECLARATIONHANDLERPROPERTY, chandler); |
|
1892 |
parser.setProperty(LEXICALPROPERTY, chandler); |
|
1893 |
|
|
1894 |
if (ruleBase != null && ruleBase.equals(SCHEMA) && needValidation) |
|
1895 |
{ |
|
1896 |
MetaCatUtil.debugMessage("General schema parser", 20); |
|
1897 |
// turn on schema validation feature |
|
1898 |
parser.setFeature(VALIDATIONFEATURE, true); |
|
1899 |
parser.setFeature(NAMESPACEFEATURE, true); |
|
1900 |
parser.setFeature(NAMESPACEPREFIXESFEATURE, true); |
|
1901 |
parser.setFeature(SCHEMAVALIDATIONFEATURE, true); |
|
1902 |
// From DB to find the register external schema location |
|
1903 |
String externalSchemaLocation = null; |
|
1904 |
SchemaLocationResolver resolver = new SchemaLocationResolver(); |
|
1905 |
externalSchemaLocation = resolver.getNameSpaceAndLocationString(); |
|
1906 |
// Set external schemalocation. |
|
1907 |
if (externalSchemaLocation != null && |
|
1908 |
!(externalSchemaLocation.trim()).equals("")) |
|
1909 |
{ |
|
1910 |
parser.setProperty(EXTERNALSCHEMALOCATIONPROPERTY, |
|
1911 |
externalSchemaLocation); |
|
1912 |
} |
|
1913 |
|
|
1914 |
} |
|
1915 |
else if (ruleBase != null && ruleBase.equals(DTD) && needValidation) |
|
1916 |
{ |
|
1917 |
MetaCatUtil.debugMessage("dtd parser", 20); |
|
1918 |
// turn on dtd validaton feature |
|
1919 |
parser.setFeature(VALIDATIONFEATURE, true); |
|
1920 |
eresolver= new DBEntityResolver(dbconn, (DBSAXHandler)chandler, dtd); |
|
1921 |
dtdhandler = new DBDTDHandler(dbconn); |
|
1922 |
parser.setEntityResolver((EntityResolver)eresolver); |
|
1923 |
parser.setDTDHandler((DTDHandler)dtdhandler); |
|
1924 |
} |
|
1925 |
else |
|
1926 |
{ |
|
1927 |
MetaCatUtil.debugMessage("other parser", 20); |
|
1928 |
// non validation |
|
1929 |
parser.setFeature(VALIDATIONFEATURE, false); |
|
1930 |
eresolver= new DBEntityResolver(dbconn, (DBSAXHandler)chandler, dtd); |
|
1931 |
dtdhandler = new DBDTDHandler(dbconn); |
|
1932 |
parser.setEntityResolver((EntityResolver)eresolver); |
|
1933 |
parser.setDTDHandler((DTDHandler)dtdhandler); |
|
1934 |
} |
|
1935 |
}//else |
|
1904 | 1936 |
} |
1905 | 1937 |
catch (Exception e) |
1906 | 1938 |
{ |
Also available in: Unified diff
Set up an eml parser.