Mercurial > hg > mpdl-group
diff software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/xml/SchemaHandler.java @ 10:59ff47d1e237
TEI Unterst?tzung, Fehlerbehebungen, externe Objekte
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 11 Mar 2011 13:33:26 +0100 |
parents | 408254cf2f1d |
children | 257f67be5c00 |
line wrap: on
line diff
--- a/software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/xml/SchemaHandler.java Tue Feb 22 16:03:45 2011 +0100 +++ b/software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/xml/SchemaHandler.java Fri Mar 11 13:33:26 2011 +0100 @@ -23,7 +23,7 @@ /** * - * @param fileName + * @param fileName local file name to validate * @param docOperation * @return doc root node of xml file * @throws ApplicationException @@ -69,6 +69,12 @@ String id = getIdByExistId(eXistIdentifier); mdRecord.setIdentifier("ARCHIMEDES:" + id + ".xml"); } + } else if (docBase != null && docBase.equals("tei")) { + mdRecord = getMetadataRecordTEI(documentNode); + if (mdRecord != null) { + String id = getIdByExistId(eXistIdentifier); + mdRecord.setIdentifier("TEI:" + id + ".xml"); + } } if (mdRecord != null) { mdRecord.setEXistIdentifier(eXistIdentifier); @@ -130,16 +136,26 @@ NamespaceContext nsContext = getEchoNsContext(); String echoTest = null; String archimedesTest = null; + String teiTest = null; try { echoTest = xmlUtil.evaluateToString(docNode, "/echo:echo/echo:metadata", nsContext); archimedesTest = xmlUtil.evaluateToString(docNode, "/archimedes/info", null); + teiTest = xmlUtil.evaluateToString(docNode, "/TEI/teiHeader", null); } catch (ApplicationException e) { throw new ApplicationException("Your source file is not an \"echo\" or \"archimedes\" file. Please proof that file."); } if (docBase.equals("echo") && archimedesTest != null) throw new ApplicationException("Your source file is an \"archimedes\" file. " + "Please specify \"archimedes\" in your destination document base."); + if (docBase.equals("echo") && teiTest != null) + throw new ApplicationException("Your source file is a \"TEI\" file. " + "Please specify \"TEI\" in your destination document base."); if (docBase.equals("archimedes") && echoTest != null) throw new ApplicationException("Your source file is an \"echo\" file. " + "Please specify \"echo\" in your destination document base."); + if (docBase.equals("archimedes") && teiTest != null) + throw new ApplicationException("Your source file is a \"archimedes\" file. " + "Please specify \"TEI\" in your destination document base."); + if (docBase.equals("tei") && archimedesTest != null) + throw new ApplicationException("Your source file is an \"archimedes\" file. " + "Please specify \"archimedes\" in your destination document base."); + if (docBase.equals("tei") && echoTest != null) + throw new ApplicationException("Your source file is an \"echo\" file. " + "Please specify \"echo\" in your destination document base."); } private void validateByRelaxNGSchema(File destFile, String docBase) throws ApplicationException { @@ -147,6 +163,9 @@ if (docBase.equals("echo")) { URL echoSchemaUrl = getEchoRelaxNGSchemaUrl(); xmlUtil.validateByRelaxNG(destFile, echoSchemaUrl); + } else if (docBase.equals("tei")) { + URL teiSchemaUrl = getTeiLiteRelaxNGSchemaUrl(); + xmlUtil.validateByRelaxNG(destFile, teiSchemaUrl); } } @@ -161,6 +180,17 @@ return echoSchemaUrl; } + private URL getTeiLiteRelaxNGSchemaUrl() throws ApplicationException { + String schemaUrlStr = "http://" + MpdlConstants.MPDL_EXIST_HOST_NAME + ":" + MpdlConstants.MPDL_EXIST_PORT + MpdlConstants.MPDL_TEILITE_RELAXNG_PATH; + URL schemaUrl = null; + try { + schemaUrl = new URL(schemaUrlStr); + } catch (MalformedURLException e) { + throw new ApplicationException(e); + } + return schemaUrl; + } + private void validate(MetadataRecord mdRecord) throws ApplicationException { String identifier = mdRecord.getIdentifier(); String creator = mdRecord.getCreator(); @@ -252,6 +282,42 @@ return mdRecord; } + private MetadataRecord getMetadataRecordTEI(Node documentNode) throws ApplicationException { + XmlUtil xmlUtil = XmlUtil.getInstance(); + NamespaceContext nsContext = getTeiNsContext(); + String creator = xmlUtil.evaluateToString(documentNode, "/TEI:TEI/TEI:teiHeader/TEI:fileDesc/TEI:titleStmt/TEI:author", nsContext); + if (creator != null) + creator = StringUtilEscapeChars.deresolveXmlEntities(creator); + String title = xmlUtil.evaluateToString(documentNode, "/TEI:TEI/TEI:teiHeader/TEI:fileDesc/TEI:titleStmt/TEI:title", nsContext); + if (title != null) + title = StringUtilEscapeChars.deresolveXmlEntities(title); + String language = xmlUtil.evaluateToString(documentNode, "/TEI:TEI/TEI:teiHeader/TEI:profileDesc/TEI:langUsage/TEI:language/@ident", nsContext); + if (language != null) + language = StringUtilEscapeChars.deresolveXmlEntities(language); + String yearStr = xmlUtil.evaluateToString(documentNode, "/TEI:TEI/TEI:teiHeader/TEI:fileDesc/TEI:publicationStmt/TEI:date", nsContext); + Date date = null; + if (yearStr != null && ! yearStr.equals("")) { + yearStr = StringUtilEscapeChars.deresolveXmlEntities(yearStr); + yearStr = new Util().toYearStr(yearStr); // test if possible etc + if (yearStr != null) + date = XmlUtil.getInstance().toDate(yearStr + "-01-01T00:00:00.000Z"); + } + String rights = xmlUtil.evaluateToString(documentNode, "/TEI:TEI/TEI:teiHeader/TEI:fileDesc/TEI:publicationStmt/TEI:availability", nsContext); + if (rights == null) + rights = "open access"; + rights = StringUtilEscapeChars.deresolveXmlEntities(rights); + String license = "http://echo.mpiwg-berlin.mpg.de/policy/oa_basics/declaration"; + String accessRights = xmlUtil.evaluateToString(documentNode, "/TEI:TEI/TEI:teiHeader/TEI:fileDesc/TEI:publicationStmt/TEI:availability/@status", nsContext); + if (accessRights == null) + accessRights = "free"; + accessRights = StringUtilEscapeChars.deresolveXmlEntities(accessRights); + MetadataRecord mdRecord = new MetadataRecord(null, language, creator, title, null, null, "text/xml", rights, date); + mdRecord.setDocBase("tei"); + mdRecord.setLicense(license); + mdRecord.setAccessRights(accessRights); + return mdRecord; + } + private String getIndexMetaDataPageImg(String imagesDocDirectory) throws ApplicationException { String resultStr = null; String nausikaaURLTexter = "http://nausikaa2.mpiwg-berlin.mpg.de/digitallibrary/servlet/Texter"; @@ -364,5 +430,41 @@ return nsContext; } + public NamespaceContext getTeiNsContext() { + NamespaceContext nsContext = new NamespaceContext() { + public String getNamespaceURI(String prefix) { + String uri; + if (prefix.equals("TEI")) + uri = "http://www.tei-c.org/ns/1.0"; + else if (prefix.equals("xhtml")) + uri = "http://www.w3.org/1999/xhtml"; + else if (prefix.equals("xlink")) + uri = "http://www.w3.org/1999/xlink"; + else if (prefix.equals("mml")) + uri = "http://www.w3.org/1998/Math/MathML"; + else + uri = null; + return uri; + } + + public String getPrefix(String uri) { + if (uri.equals("http://www.tei-c.org/ns/1.0")) + return "TEI"; + else if (uri.equals("http://www.w3.org/1999/xhtml")) + return "xhtml"; + else if (uri.equals("http://www.w3.org/1999/xlink")) + return "xlink"; + else if (uri.equals("http://www.w3.org/1998/Math/MathML")) + return "mml"; + else + return null; + } + + public Iterator getPrefixes(String namespace) { + return null; + } + }; + return nsContext; + } }