|
|
|
sppigot
|
Revision: 5450
http://geonetwork.svn.sourceforge.net/geonetwork/?rev=5450&view=rev Author: sppigot Date: 2009-11-05 13:39:52 +0000 (Thu, 05 Nov 2009) Log Message: ----------- Backport extended metadata import and paste functions from trunk Modified Paths: -------------- sandbox/BlueNetMEST/src/org/fao/gast/lib/MefLib.java sandbox/BlueNetMEST/src/org/fao/geonet/constants/Params.java sandbox/BlueNetMEST/src/org/fao/geonet/kernel/harvest/harvester/geonet/Aligner.java sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/Importer.java sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/MEFLib.java sandbox/BlueNetMEST/src/org/fao/geonet/services/mef/Import.java sandbox/BlueNetMEST/src/org/fao/geonet/services/metadata/ImportFromDir.java sandbox/BlueNetMEST/src/org/fao/geonet/services/metadata/Insert.java sandbox/BlueNetMEST/web/geonetwork/loc/en/xml/strings.xml sandbox/BlueNetMEST/web/geonetwork/xsl/metadata-batchimport.xsl sandbox/BlueNetMEST/web/geonetwork/xsl/metadata-insert-form.xsl Added Paths: ----------- sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/FileVisitor.java sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/MEFFileVisitor.java sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/XMLFileVisitor.java sandbox/BlueNetMEST/web/geonetwork/xsl/metadata-insert-form-utils.xsl Removed Paths: ------------- sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/Visitor.java Modified: sandbox/BlueNetMEST/src/org/fao/gast/lib/MefLib.java =================================================================== --- sandbox/BlueNetMEST/src/org/fao/gast/lib/MefLib.java 2009-11-05 11:06:51 UTC (rev 5449) +++ sandbox/BlueNetMEST/src/org/fao/gast/lib/MefLib.java 2009-11-05 13:39:52 UTC (rev 5450) @@ -30,6 +30,8 @@ import java.util.List; import java.util.UUID; import jeeves.resources.dbms.Dbms; + +import org.fao.geonet.kernel.mef.MEFFileVisitor; import org.fao.geonet.kernel.mef.MEFLib; import org.fao.geonet.kernel.mef.MEFVisitor; import org.fao.geonet.util.ISODate; @@ -53,7 +55,7 @@ Lib.log.info("Adding MEF file : "+ mefFile.getAbsolutePath()); - MEFLib.visit(mefFile, new MEFVisitor() + MEFLib.visit(mefFile, new MEFFileVisitor(), new MEFVisitor() { public void handleMetadata(Element mdata) throws Exception { @@ -104,15 +106,6 @@ String schema = general.getChildText("schema"); String isTemplate = general.getChildText("isTemplate").equals("true") ? "y" : "n"; -/* - boolean dcore = schema.equals("dublin-core"); - boolean fgdc = schema.equals("fgdc-std"); - boolean iso115 = schema.equals("iso19115"); - boolean iso139 = schema.equals("iso19139"); - - if (!dcore && !fgdc && !iso115 && !iso139) - throw new Exception("Unknown schema format : "+schema); -*/ if (uuid == null) { uuid = UUID.randomUUID().toString(); @@ -241,6 +234,7 @@ { if (descr.equals("view")) return 0; if (descr.equals("download")) return 1; + if (descr.equals("editing")) return 2; if (descr.equals("notify")) return 3; if (descr.equals("dynamic")) return 5; if (descr.equals("featured")) return 6; Modified: sandbox/BlueNetMEST/src/org/fao/geonet/constants/Params.java =================================================================== --- sandbox/BlueNetMEST/src/org/fao/geonet/constants/Params.java 2009-11-05 11:06:51 UTC (rev 5449) +++ sandbox/BlueNetMEST/src/org/fao/geonet/constants/Params.java 2009-11-05 13:39:52 UTC (rev 5450) @@ -45,13 +45,16 @@ public static final String EDITING = "editing"; public static final String EMAIL = "email"; public static final String FNAME = "fname"; + public static final String FILE_TYPE = "file_type"; public static final String FINISHED = "finished"; public static final String FORGET = "forget"; + public static final String GENERATE_UUID= "generateUUID"; public static final String GROUP = "group"; public static final String GROUPS = "groups"; public static final String ID = "id"; public static final String NAME = "name"; public static final String NEW_PASSWORD = "newPassword"; + public static final String NOTHING = "nothing"; public static final String OPERATION = "operation"; public static final String ORIGINALCHOICE = "originalchoice"; public static final String ORG = "org"; @@ -83,6 +86,7 @@ public static final String USERNAME = "username"; public static final String USER = "user"; public static final String UUID = "uuid"; + public static final String UUID_ACTION = "uuidAction"; public static final String VERSION = "version"; public static final String VALIDATE = "validate"; public static final String ADDRESS = "address"; Modified: sandbox/BlueNetMEST/src/org/fao/geonet/kernel/harvest/harvester/geonet/Aligner.java =================================================================== --- sandbox/BlueNetMEST/src/org/fao/geonet/kernel/harvest/harvester/geonet/Aligner.java 2009-11-05 11:06:51 UTC (rev 5449) +++ sandbox/BlueNetMEST/src/org/fao/geonet/kernel/harvest/harvester/geonet/Aligner.java 2009-11-05 13:39:52 UTC (rev 5450) @@ -44,8 +44,10 @@ import org.fao.geonet.kernel.harvest.harvester.GroupMapper; import org.fao.geonet.kernel.harvest.harvester.RecordInfo; import org.fao.geonet.kernel.harvest.harvester.UUIDMapper; +import org.fao.geonet.kernel.mef.MEFFileVisitor; import org.fao.geonet.kernel.mef.MEFLib; import org.fao.geonet.kernel.mef.MEFVisitor; +import org.fao.geonet.kernel.setting.SettingManager; import org.fao.geonet.lib.Lib; import org.fao.geonet.util.ISODate; import org.jdom.Element; @@ -152,8 +154,17 @@ { String id = dataMan.getMetadataId(dbms, ri.uuid); - if (id == null) addMetadata(ri); - else updateMetadata(ri, id); + // look up value of localrating/enabled + GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); + SettingManager settingManager = gc.getSettingManager(); + boolean localRating = settingManager.getValueAsBool("system/localrating/enabled", false); + + if (id == null) { + addMetadata(ri, localRating); + } + else { + updateMetadata(ri, id, localRating); + } } } @@ -168,7 +179,7 @@ //--- //-------------------------------------------------------------------------- - private void addMetadata(final RecordInfo ri) throws Exception + private void addMetadata(final RecordInfo ri, final boolean localRating) throws Exception { final String id[] = { null }; final Element md[] = { null }; @@ -179,7 +190,7 @@ try { - MEFLib.visit(mefFile, new MEFVisitor() + MEFLib.visit(mefFile, new MEFFileVisitor(), new MEFVisitor() { public void handleMetadata(Element mdata) throws Exception { @@ -190,7 +201,7 @@ public void handleInfo(Element info) throws Exception { - id[0] = addMetadata(ri, md[0], info); + id[0] = addMetadata(ri, md[0], info, localRating); } //-------------------------------------------------------------------- @@ -226,7 +237,7 @@ //-------------------------------------------------------------------------- - private String addMetadata(RecordInfo ri, Element md, Element info) throws Exception + private String addMetadata(RecordInfo ri, Element md, Element info, boolean localRating) throws Exception { Element general = info.getChild("general"); @@ -234,7 +245,6 @@ String changeDate = general.getChildText("changeDate"); String isTemplate = general.getChildText("isTemplate"); String siteId = general.getChildText("siteId"); - String rating = general.getChildText("rating"); String popularity = general.getChildText("popularity"); if ("true".equals(isTemplate)) isTemplate = "y"; @@ -249,10 +259,13 @@ dataMan.setTemplate(dbms, iId, isTemplate, null); dataMan.setHarvested(dbms, iId, params.uuid); - - if (rating != null) - dbms.execute("UPDATE Metadata SET rating=? WHERE id=?", new Integer(rating), iId); - + + if(!localRating) { + String rating = general.getChildText("rating"); + if (rating != null) + dbms.execute("UPDATE Metadata SET rating=? WHERE id=?", new Integer(rating), iId); + } + if (popularity != null) dbms.execute("UPDATE Metadata SET popularity=? WHERE id=?", new Integer(popularity), iId); @@ -419,7 +432,7 @@ //--- //-------------------------------------------------------------------------- - private void updateMetadata(final RecordInfo ri, final String id) throws Exception + private void updateMetadata(final RecordInfo ri, final String id, final boolean localRating) throws Exception { final Element md[] = { null }; final Element publicFiles[] = { null }; @@ -432,7 +445,7 @@ try { - MEFLib.visit(mefFile, new MEFVisitor() + MEFLib.visit(mefFile, new MEFFileVisitor(), new MEFVisitor() { public void handleMetadata(Element mdata) throws Exception { @@ -443,7 +456,7 @@ public void handleInfo(Element info) throws Exception { - updateMetadata(ri, id, md[0], info); + updateMetadata(ri, id, md[0], info, localRating); publicFiles[0] = info.getChild("public"); } @@ -473,7 +486,7 @@ //-------------------------------------------------------------------------- - private void updateMetadata(RecordInfo ri, String id, Element md, Element info) throws Exception + private void updateMetadata(RecordInfo ri, String id, Element md, Element info, boolean localRating) throws Exception { String date = localUuids.getChangeDate(ri.uuid); @@ -491,12 +504,14 @@ Element general = info.getChild("general"); - String rating = general.getChildText("rating"); String popularity = general.getChildText("popularity"); - if (rating != null) - dbms.execute("UPDATE Metadata SET rating=? WHERE id=?", new Integer(rating), new Integer(id)); - + if(!localRating) { + String rating = general.getChildText("rating"); + if (rating != null) + dbms.execute("UPDATE Metadata SET rating=? WHERE id=?", new Integer(rating), new Integer(id)); + } + if (popularity != null) dbms.execute("UPDATE Metadata SET popularity=? WHERE id=?", new Integer(popularity), new Integer(id)); Added: sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/FileVisitor.java =================================================================== --- sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/FileVisitor.java (rev 0) +++ sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/FileVisitor.java 2009-11-05 13:39:52 UTC (rev 5450) @@ -0,0 +1,99 @@ +//============================================================================= +//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the +//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) +//=== and United Nations Environment Programme (UNEP) +//=== +//=== This program is free software; you can redistribute it and/or modify +//=== it under the terms of the GNU General Public License as published by +//=== the Free Software Foundation; either version 2 of the License, or (at +//=== your option) any later version. +//=== +//=== This program is distributed in the hope that it will be useful, but +//=== WITHOUT ANY WARRANTY; without even the implied warranty of +//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +//=== General Public License for more details. +//=== +//=== You should have received a copy of the GNU General Public License +//=== along with this program; if not, write to the Free Software +//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA +//=== +//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, +//=== Rome - Italy. email: [hidden email] +//============================================================================== + +package org.fao.geonet.kernel.mef; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import org.jdom.Element; + + +//============================================================================= + +public interface FileVisitor +{ + // -------------------------------------------------------------------------- + // --- + // --- API methods + // --- + // -------------------------------------------------------------------------- + + public void visit(File mefFile, MEFVisitor v) throws Exception; + + // -------------------------------------------------------------------------- + + public Element handleXml(File mefFile, MEFVisitor v) throws Exception ; + + // -------------------------------------------------------------------------- + + public void handleBin(File mefFile, MEFVisitor v, Element info) throws Exception ; + + // -------------------------------------------------------------------------- + +} + +// ============================================================================= + +class InputStreamBridge extends InputStream +{ + // -------------------------------------------------------------------------- + // --- + // --- Constructor + // --- + // -------------------------------------------------------------------------- + + public InputStreamBridge(InputStream is) + { + this.is = is; + } + + // -------------------------------------------------------------------------- + // --- + // --- Bridging methods + // --- + // -------------------------------------------------------------------------- + + public int read() throws IOException { return is.read(); } + + public int available() throws IOException { return is.available(); } + + // --- this *must* be empty to work with zip files + public void close() throws IOException {} + + public synchronized void mark(int readlimit) { is.mark(readlimit); } + + public synchronized void reset() throws IOException { is.reset(); } + + public boolean markSupported() { return is.markSupported(); } + + // -------------------------------------------------------------------------- + // --- + // --- Variables + // --- + // -------------------------------------------------------------------------- + + private InputStream is; +} +// ============================================================================= + Modified: sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/Importer.java =================================================================== --- sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/Importer.java 2009-11-05 11:06:51 UTC (rev 5449) +++ sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/Importer.java 2009-11-05 13:39:52 UTC (rev 5450) @@ -35,13 +35,16 @@ import jeeves.server.context.ServiceContext; import jeeves.utils.BinaryFile; import jeeves.utils.Log; +import jeeves.utils.Util; import jeeves.utils.Xml; import org.fao.geonet.GeonetContext; import org.fao.geonet.constants.Geonet; +import org.fao.geonet.constants.Params; import org.fao.geonet.kernel.DataManager; import org.fao.geonet.lib.Lib; import org.fao.geonet.util.ISODate; +import org.fao.oaipmh.exceptions.BadArgumentException; import org.jdom.Element; //============================================================================= @@ -54,8 +57,10 @@ //--- //-------------------------------------------------------------------------- - public static int doImport(final ServiceContext context, File mefFile, - final boolean includeOwnership) throws Exception + private static final String SingleFileType = "single"; + private static final String MefFileType = "mef"; + + public static int doImport(final Element params, final ServiceContext context, File mefFile, final String stylePath, final boolean includeOwnership) throws Exception { final GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); final DataManager dm = gc.getDataManager(); @@ -65,9 +70,20 @@ final String id[] = { "" }; final Element md[] = { null }; + String fileType = Util.getParam(params,Params.FILE_TYPE, MefFileType); + + FileVisitor visitor = null; + + if (fileType.equals(SingleFileType)) + visitor = new XMLFileVisitor(); + else if (fileType.equals(MefFileType)) + visitor = new MEFFileVisitor(); + else + throw new BadArgumentException("Missing file type parameter!!"); + //--- import metadata from MEF file - MEFLib.visit(mefFile, new MEFVisitor() + MEFLib.visit(mefFile, visitor, new MEFVisitor() { public void handleMetadata(Element metadata) throws Exception { @@ -79,51 +95,109 @@ public void handleInfo(Element info) throws Exception { - Element general = info.getChild("general"); - Element prvFile = info.getChild("private"); + String uuid = null; + String createDate = null; + String changeDate = null; + String source = null; + String sourceName = null; + String schema = null; + String isTemplate = null; + String rating = null; + String popularity = null; + String owner = null; + String groupOwner = null; + Element categs = null; + Element privileges = null; + Element prvFile = null; - String uuid = general.getChildText("uuid"); - String createDate = general.getChildText("createDate"); - String changeDate = general.getChildText("changeDate"); - String source = general.getChildText("siteId"); - String sourceName = general.getChildText("siteName"); - String schema = general.getChildText("schema"); - String isTemplate = general.getChildText("isTemplate").equals("true") ? "y" : "n"; - String rating = general.getChildText("rating"); - String popularity = general.getChildText("popularity"); - String owner = general.getChildText("owner"); - String groupOwner = general.getChildText("groupOwner"); + // Element group = null; - /* - boolean dcore = schema.equals("dublin-core"); - boolean fgdc = schema.equals("fgdc-std"); - boolean iso115 = schema.equals("iso19115"); - boolean iso139 = schema.equals("iso19139"); + // Handle non MEF files insertion + if (info.getChildren().size() == 0) { + + source = Util.getParam(params, Params.SITE_ID, gc.getSiteId()); + isTemplate = Util.getParam(params, Params.TEMPLATE, "n"); - if (!dcore && !fgdc && !iso115 && !iso139) - throw new Exception("Unknown schema format : "+schema); - */ + categs = new Element("categories"); + categs.addContent((new Element("category")).setAttribute( + "name", Util.getParam(params, Params.CATEGORY))); + + groupOwner = Util.getParam(params, Params.GROUP); + privileges = new Element("group"); + privileges.addContent(new Element("operation").setAttribute("name", "view")); + privileges.addContent(new Element("operation").setAttribute("name", "download")); + privileges.addContent(new Element("operation").setAttribute("name", "editing")); + privileges.addContent(new Element("operation").setAttribute("name", "notify")); + privileges.addContent(new Element("operation").setAttribute("name", "dynamic")); + privileges.addContent(new Element("operation").setAttribute("name", "featured")); + + String style = Util.getParam(params, Params.STYLESHEET); + + // Apply a stylesheet transformation if requested + if (!style.equals("_none_")) + md[0] = Xml.transform(md[0],stylePath+"/"+style); + + schema = dm.autodetectSchema(md[0]); + + // Get the Metadata uuid + if (isTemplate.equals("n")) + uuid = dm.extractUUID(schema, md[0]); + + } else { - if (uuid == null) - { + categs = info.getChild("categories"); + privileges = info.getChild("privileges"); + + Element general = info.getChild("general"); + prvFile = info.getChild("private"); + + uuid = general.getChildText("uuid"); + createDate = general.getChildText("createDate"); + changeDate = general.getChildText("changeDate"); + source = general.getChildText("siteId"); + sourceName = general.getChildText("siteName"); + schema = general.getChildText("schema"); + isTemplate = general.getChildText("isTemplate").equals("true") ? "y" : "n"; + rating = general.getChildText("rating"); + popularity = general.getChildText("popularity"); + owner = general.getChildText("owner"); + groupOwner = general.getChildText("groupOwner"); + + schema = dm.autodetectSchema(md[0]); + } + + if (schema == null) + throw new Exception("Unknown schema format : " + schema); + + String uuidAction = Util.getParam(params, Params.UUID_ACTION, + Params.NOTHING); + if (uuid == null || uuid.equals("") || uuidAction.equals(Params.GENERATE_UUID)) { uuid = UUID.randomUUID().toString(); source = null; //--- set uuid inside metadata md[0] = dm.setUUID(schema, uuid, md[0]); - } - else - { - if (sourceName == null) - sourceName = "???"; + } else { + if (sourceName == null || source.trim().length() == 0) + throw new Exception("Missing siteId parameter from info.xml file"); Lib.sources.update(dbms, source, sourceName, true); } + + try { + if (dm.existsMetadataUuid(dbms, uuid) && !uuidAction.equals(Params.NOTHING)) { + dm.deleteMetadata(dbms, dm.getMetadataId(dbms, uuid)) ; + context.debug("Deleting existing metadata with UUID : " + uuid ); + } + } + catch (Exception e) { + throw new Exception(" Existing metadata with same UUID could not be deleted."); + } // set metadata owner String ownerId = null; - if (includeOwnership && owner != null) + if (owner != null) ownerId = getLocalUserId(context,dbms,owner); if (ownerId == null) @@ -134,7 +208,7 @@ // set group owner String groupOwnerId = null; - if (includeOwnership && groupOwner != null) + if (groupOwner != null) groupOwnerId = getLocalGroupId(context,dbms,groupOwner); Log.debug(Geonet.MEF, "Adding metadata with uuid="+ uuid); @@ -171,8 +245,13 @@ new File(pubDir).mkdirs(); new File(priDir).mkdirs(); - addCategories(dm, dbms, id[0], info.getChild("categories")); - addPrivileges(dm, dbms, id[0], info.getChild("privileges")); + addCategories(dm, dbms, id[0], categs); + + if (groupOwnerId == null) + addPrivileges(dm, dbms, id[0], privileges); + else + addOperations(dm, dbms, privileges, id[0], groupOwnerId); + dm.indexMetadata(dbms, id[0]); } Added: sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/MEFFileVisitor.java =================================================================== --- sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/MEFFileVisitor.java (rev 0) +++ sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/MEFFileVisitor.java 2009-11-05 13:39:52 UTC (rev 5450) @@ -0,0 +1,186 @@ +//============================================================================= +//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the +//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) +//=== and United Nations Environment Programme (UNEP) +//=== +//=== This program is free software; you can redistribute it and/or modify +//=== it under the terms of the GNU General Public License as published by +//=== the Free Software Foundation; either version 2 of the License, or (at +//=== your option) any later version. +//=== +//=== This program is distributed in the hope that it will be useful, but +//=== WITHOUT ANY WARRANTY; without even the implied warranty of +//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +//=== General Public License for more details. +//=== +//=== You should have received a copy of the GNU General Public License +//=== along with this program; if not, write to the Free Software +//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA +//=== +//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, +//=== Rome - Italy. email: [hidden email] +//============================================================================== + +package org.fao.geonet.kernel.mef; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.List; +import java.util.Vector; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import jeeves.exceptions.BadFormatEx; +import jeeves.utils.Xml; +import org.jdom.Element; + +import static org.fao.geonet.kernel.mef.MEFConstants.*; + +//============================================================================= + +public class MEFFileVisitor implements FileVisitor +{ + //-------------------------------------------------------------------------- + //--- + //--- API methods + //--- + //-------------------------------------------------------------------------- + + public void visit(File mefFile, MEFVisitor v) throws Exception + { + Element info = handleXml(mefFile, v); + handleBin(mefFile, v, info); + } + + //-------------------------------------------------------------------------- + + public Element handleXml(File mefFile, MEFVisitor v) throws Exception + { + ZipInputStream zis = new ZipInputStream(new FileInputStream(mefFile)); + InputStreamBridge isb = new InputStreamBridge(zis); + + ZipEntry entry; + + Element md = null; + Element info = null; + + try + { + while ((entry=zis.getNextEntry()) != null) + { + String name = entry.getName(); + + if (name.equals(FILE_METADATA)) + md = Xml.loadStream(isb); + + else if (name.equals(FILE_INFO)) + info = Xml.loadStream(isb); + + zis.closeEntry(); + } + } + finally + { + safeClose(zis); + } + + if (md == null) + throw new BadFormatEx("Missing metadata file : "+ FILE_METADATA); + + if (info == null) + throw new BadFormatEx("Missing info file : "+ FILE_INFO); + + v.handleMetadata(md); + v.handleInfo(info); + + return info; + } + + //-------------------------------------------------------------------------- + + public void handleBin(File mefFile, MEFVisitor v, Element info) throws Exception + { + ZipInputStream zis = new ZipInputStream(new FileInputStream(mefFile)); + InputStreamBridge isb = new InputStreamBridge(zis); + + List pubFiles; + if (info.getChild("public") != null) { + pubFiles = info.getChild("public").getChildren(); + } else { + pubFiles = new Vector(); + } + List prvFiles; + if (info.getChild("private") != null) { + prvFiles = info.getChild("private").getChildren(); + } else { + prvFiles = new Vector(); + } + + ZipEntry entry; + + try + { + while ((entry=zis.getNextEntry()) != null) + { + String fullName = entry.getName(); + String simpleName; + simpleName = null; + if (fullName.indexOf("/") != -1) { + simpleName = fullName.substring(fullName.lastIndexOf("/")+1); + } else if (fullName.indexOf("\\") != -1) { + simpleName = fullName.substring(fullName.lastIndexOf("\\")+1); + } + + if (simpleName == null || simpleName.length() < 1) continue; + + + if (fullName.startsWith(DIR_PUBLIC)) + v.handlePublicFile(simpleName, getChangeDate(pubFiles, simpleName), isb); + + else if (fullName.startsWith(DIR_PRIVATE)) + v.handlePrivateFile(simpleName, getChangeDate(prvFiles, simpleName), isb); + + zis.closeEntry(); + } + } + finally + { + safeClose(zis); + } + } + + //-------------------------------------------------------------------------- + + private static String getChangeDate(List files, String fileName) throws Exception + { + for (Object f : files) + { + Element file = (Element) f; + String name = file.getAttributeValue("name"); + String date = file.getAttributeValue("changeDate"); + + if (name.equals(fileName)) + return date; + } + + throw new Exception("File not found in info.xml : "+ fileName); + } + + //-------------------------------------------------------------------------- + + private static void safeClose(ZipInputStream zis) + { + try + { + zis.close(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + +} + +//============================================================================= + Modified: sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/MEFLib.java =================================================================== --- sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/MEFLib.java 2009-11-05 11:06:51 UTC (rev 5449) +++ sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/MEFLib.java 2009-11-05 13:39:52 UTC (rev 5450) @@ -30,6 +30,8 @@ import jeeves.exceptions.MissingParameterEx; import jeeves.server.context.ServiceContext; +import org.jdom.Element; + //============================================================================= public class MEFLib @@ -40,24 +42,23 @@ //--- //-------------------------------------------------------------------------- - public static int doImport(ServiceContext context, File mefFile, boolean includeOwnership) throws Exception + public static int doImport(Element params, ServiceContext context, File mefFile, String stylePath, boolean includeOwnership) throws Exception { - return Importer.doImport(context, mefFile, includeOwnership); + return Importer.doImport(params, context, mefFile, stylePath, includeOwnership); } //-------------------------------------------------------------------------- - public static String doExport(ServiceContext context, String uuid, String format, - boolean skipUUID) throws Exception + public static String doExport(ServiceContext context, String uuid, String format, boolean skipUUID) throws Exception { return Exporter.doExport(context, uuid, Format.parse(format), skipUUID); } //-------------------------------------------------------------------------- - public static void visit(File mefFile, MEFVisitor v) throws Exception + public static void visit(File mefFile, FileVisitor fvisitor, MEFVisitor v) throws Exception { - Visitor.visit(mefFile, v); + fvisitor.visit(mefFile, v); } //-------------------------------------------------------------------------- Deleted: sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/Visitor.java =================================================================== --- sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/Visitor.java 2009-11-05 11:06:51 UTC (rev 5449) +++ sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/Visitor.java 2009-11-05 13:39:52 UTC (rev 5450) @@ -1,232 +0,0 @@ -//============================================================================= -//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the -//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) -//=== and United Nations Environment Programme (UNEP) -//=== -//=== This program is free software; you can redistribute it and/or modify -//=== it under the terms of the GNU General Public License as published by -//=== the Free Software Foundation; either version 2 of the License, or (at -//=== your option) any later version. -//=== -//=== This program is distributed in the hope that it will be useful, but -//=== WITHOUT ANY WARRANTY; without even the implied warranty of -//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -//=== General Public License for more details. -//=== -//=== You should have received a copy of the GNU General Public License -//=== along with this program; if not, write to the Free Software -//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA -//=== -//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, -//=== Rome - Italy. email: [hidden email] -//============================================================================== - -package org.fao.geonet.kernel.mef; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import java.util.Vector; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import jeeves.exceptions.BadFormatEx; -import jeeves.utils.Log; -import jeeves.utils.Xml; -import org.jdom.Element; -import org.fao.geonet.constants.Geonet; - -import static org.fao.geonet.kernel.mef.MEFConstants.*; - -//============================================================================= - -public class Visitor -{ - //-------------------------------------------------------------------------- - //--- - //--- API methods - //--- - //-------------------------------------------------------------------------- - - public static void visit(File mefFile, MEFVisitor v) throws Exception - { - Element info = handleXml(mefFile, v); - handleBin(mefFile, v, info); - } - - //-------------------------------------------------------------------------- - - private static Element handleXml(File mefFile, MEFVisitor v) throws Exception - { - ZipInputStream zis = new ZipInputStream(new FileInputStream(mefFile)); - InputStreamBridge isb = new InputStreamBridge(zis); - - ZipEntry entry; - - Element md = null; - Element info = null; - - try - { - while ((entry=zis.getNextEntry()) != null) - { - String name = entry.getName(); - - if (name.equals(FILE_METADATA)) - md = Xml.loadStream(isb); - - else if (name.equals(FILE_INFO)) - info = Xml.loadStream(isb); - - zis.closeEntry(); - } - } - finally - { - safeClose(zis); - } - - if (md == null) - throw new BadFormatEx("Missing metadata file : "+ FILE_METADATA); - - if (info == null) - throw new BadFormatEx("Missing info file : "+ FILE_INFO); - - v.handleMetadata(md); - v.handleInfo(info); - - return info; - } - - //-------------------------------------------------------------------------- - - private static void handleBin(File mefFile, MEFVisitor v, Element info) throws Exception - { - ZipInputStream zis = new ZipInputStream(new FileInputStream(mefFile)); - InputStreamBridge isb = new InputStreamBridge(zis); - - List pubFiles; - if (info.getChild("public") != null) { - pubFiles = info.getChild("public").getChildren(); - } else { - pubFiles = new Vector(); - } - List prvFiles; - if (info.getChild("private") != null) { - prvFiles = info.getChild("private").getChildren(); - } else { - prvFiles = new Vector(); - } - - ZipEntry entry; - - try - { - while ((entry=zis.getNextEntry()) != null) - { - String fullName = entry.getName(); - String simpleName; - simpleName = null; - if (fullName.indexOf("/") != -1) { - simpleName = fullName.substring(fullName.lastIndexOf("/")+1); - } else if (fullName.indexOf("\\") != -1) { - simpleName = fullName.substring(fullName.lastIndexOf("\\")+1); - } - - Log.debug(Geonet.MEF, "Processing " + fullName + ":" + simpleName); - if (simpleName == null || simpleName.length() < 1) continue; - - - if (fullName.startsWith(DIR_PUBLIC)) - v.handlePublicFile(simpleName, getChangeDate(pubFiles, simpleName), isb); - - else if (fullName.startsWith(DIR_PRIVATE)) - v.handlePrivateFile(simpleName, getChangeDate(prvFiles, simpleName), isb); - - zis.closeEntry(); - } - } - finally - { - safeClose(zis); - } - } - - //-------------------------------------------------------------------------- - - private static String getChangeDate(List files, String fileName) throws Exception - { - for (Object f : files) - { - Element file = (Element) f; - String name = file.getAttributeValue("name"); - String date = file.getAttributeValue("changeDate"); - - if (name.equals(fileName)) - return date; - } - - throw new Exception("File not found in info.xml : "+ fileName); - } - - //-------------------------------------------------------------------------- - - private static void safeClose(ZipInputStream zis) - { - try - { - zis.close(); - } - catch (IOException e) - { - e.printStackTrace(); - } - } -} - -//============================================================================= - -class InputStreamBridge extends InputStream -{ - //-------------------------------------------------------------------------- - //--- - //--- Constructor - //--- - //-------------------------------------------------------------------------- - - public InputStreamBridge(InputStream is) - { - this.is = is; - } - - //-------------------------------------------------------------------------- - //--- - //--- Bridging methods - //--- - //-------------------------------------------------------------------------- - - public int read() throws IOException { return is.read(); } - - public int available() throws IOException { return is.available(); } - - //--- this *must* be empty to work with zip files - public void close() throws IOException {} - - public synchronized void mark(int readlimit) { is.mark(readlimit); } - - public synchronized void reset() throws IOException { is.reset(); } - - public boolean markSupported() { return is.markSupported(); } - - //-------------------------------------------------------------------------- - //--- - //--- Variables - //--- - //-------------------------------------------------------------------------- - - private InputStream is; -} - -//============================================================================= - Added: sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/XMLFileVisitor.java =================================================================== --- sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/XMLFileVisitor.java (rev 0) +++ sandbox/BlueNetMEST/src/org/fao/geonet/kernel/mef/XMLFileVisitor.java 2009-11-05 13:39:52 UTC (rev 5450) @@ -0,0 +1,65 @@ +//============================================================================= +//=== Copyright (C) 2001-2007 Food and Agriculture Organization of the +//=== United Nations (FAO-UN), United Nations World Food Programme (WFP) +//=== and United Nations Environment Programme (UNEP) +//=== +//=== This program is free software; you can redistribute it and/or modify +//=== it under the terms of the GNU General Public License as published by +//=== the Free Software Foundation; either version 2 of the License, or (at +//=== your option) any later version. +//=== +//=== This program is distributed in the hope that it will be useful, but +//=== WITHOUT ANY WARRANTY; without even the implied warranty of +//=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +//=== General Public License for more details. +//=== +//=== You should have received a copy of the GNU General Public License +//=== along with this program; if not, write to the Free Software +//=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA +//=== +//=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, +//=== Rome - Italy. email: [hidden email] +//============================================================================== +package org.fao.geonet.kernel.mef; + +import java.io.File; + +import jeeves.exceptions.BadFormatEx; +import jeeves.utils.Xml; + +import org.jdom.Element; + +public class XMLFileVisitor implements FileVisitor { + + // -------------------------------------------------------------------------- + // --- + // --- API methods + // --- + // -------------------------------------------------------------------------- + + public void visit(File mefFile, MEFVisitor v) throws Exception { + Element info = handleXml(mefFile, v); + } + + // -------------------------------------------------------------------------- + + public Element handleXml(File mefFile, MEFVisitor v) + throws Exception { + + Element md = null; + Element info = null; + + md = Xml.loadFile(mefFile); + info = new Element("info"); + + if (md == null) + throw new BadFormatEx("Missing xml metadata file ."); + + v.handleMetadata(md); + v.handleInfo(info); + + return info; + } + + public void handleBin(File mefFile, MEFVisitor v, Element info) throws Exception {} +} Modified: sandbox/BlueNetMEST/src/org/fao/geonet/services/mef/Import.java =================================================================== --- sandbox/BlueNetMEST/src/org/fao/geonet/services/mef/Import.java 2009-11-05 11:06:51 UTC (rev 5449) +++ sandbox/BlueNetMEST/src/org/fao/geonet/services/mef/Import.java 2009-11-05 13:39:52 UTC (rev 5450) @@ -39,8 +39,12 @@ public class Import implements Service { - public void init(String appPath, ServiceConfig params) throws Exception {} + private String stylePath; + public void init(String appPath, ServiceConfig params) throws Exception { + this.stylePath = appPath + Geonet.Path.IMPORT_STYLESHEETS; + } + //-------------------------------------------------------------------------- //--- //--- Service @@ -51,7 +55,7 @@ { String mefFile = Util.getParam(params, "file", null); if (mefFile == null) mefFile = Util.getParam(params, "mefFile"); - String sIncOwner = Util.getParam(params, "includeOwnership","false"); + String sIncOwner = Util.getParam(params, "includeOwnership", "false"); String uploadDir = context.getUploadDir(); boolean includeOwnership = sIncOwner.equals("true"); @@ -60,7 +64,7 @@ throw new OperationNotAllowedEx(); File file = new File(uploadDir, mefFile); - int id = MEFLib.doImport(context, file, includeOwnership); + int id = MEFLib.doImport(params, context, file, stylePath, includeOwnership); file.delete(); Modified: sandbox/BlueNetMEST/src/org/fao/geonet/services/metadata/ImportFromDir.java =================================================================== --- sandbox/BlueNetMEST/src/org/fao/geonet/services/metadata/ImportFromDir.java 2009-11-05 11:06:51 UTC (rev 5449) +++ sandbox/BlueNetMEST/src/org/fao/geonet/services/metadata/ImportFromDir.java 2009-11-05 13:39:52 UTC (rev 5450) @@ -30,6 +30,7 @@ import java.util.List; import java.util.UUID; import jeeves.exceptions.XSDValidationErrorEx; +import jeeves.exceptions.OperationNotAllowedEx; import jeeves.interfaces.Service; import jeeves.resources.dbms.Dbms; import jeeves.server.ServiceConfig; @@ -42,6 +43,7 @@ import org.fao.geonet.constants.Params; import org.fao.geonet.exceptions.SchematronValidationErrorEx; import org.fao.geonet.kernel.DataManager; +import org.fao.geonet.kernel.mef.MEFLib; import org.jdom.Element; // FIXME: this class could be moved to DataManager @@ -66,6 +68,9 @@ //-------------------------------------------------------------------------- + /** + * Filter xml or mef files. + */ private FilenameFilter mdFilter = new FilenameFilter() { public boolean accept(File dir, String name) @@ -76,7 +81,10 @@ if (name.startsWith(".")) return false; - return name.endsWith(".xml"); + if (name.toLowerCase().endsWith(".xml") || name.toLowerCase().endsWith(".mef")) + return true; + else + return false; } }; @@ -103,6 +111,15 @@ //--- //-------------------------------------------------------------------------- + /** + * util.import service allow to import metadata in batch mode using 2 + * different mode: + * <ul> + * <li>Search for all xml file in given directory and load them</li> + * <li>Search for a file named import-config.xml in given directory + * and the import as described in that file.</li> + * </ul> + */ public Element exec(Element params, ServiceContext context) throws Exception { String dir = Util.getParam(params, Params.DIR); @@ -136,49 +153,22 @@ private int standardImport(Element params, ServiceContext context) throws Exception { - GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); - DataManager dm = gc.getDataManager(); - String dir = Util.getParam(params, Params.DIR); - String schema = Util.getParam(params, Params.SCHEMA); - String group = Util.getParam(params, Params.GROUP); - String category = Util.getParam(params, Params.CATEGORY); - String style = Util.getParam(params, Params.STYLESHEET); - - boolean validate = Util.getParam(params, Params.VALIDATE, "off").equals("on"); - + File files[] = new File(dir).listFiles(mdFilter); if (files == null) throw new Exception("Directory not found: " + dir); - ArrayList<Element> alMetadata = new ArrayList<Element>(); + // find out whether we need to include ownership details in the import + String sIncOwner = Util.getParam(params, "includeOwnership", "false"); + boolean includeOwnership = sIncOwner.equals("true"); + if (includeOwnership && !context.getUserSession().getProfile().equals(Geonet.Profile.ADMINISTRATOR)) + throw new OperationNotAllowedEx(); - //--- first collect metadata - for(int i=0; i<files.length; i++) - { - context.debug("Importing : "+files[i]); + MEFLib.doImport(params, context, files[i], stylePath, includeOwnership); - Element xml = Xml.loadFile(files[i]); - - if (!style.equals("_none_")) { - context.debug("Transforming with : "+stylePath +"/"+ style); - xml = Xml.transform(xml, stylePath +"/"+ style); - } - - if (validate) - validateIt(schema, xml, context, files[i].getName()); - - alMetadata.add(xml); - } - - //--- then insert them. At this stage they are well formed and we should not - //--- get exceptions that invalidate the index - - for (Element xml : alMetadata) - insert(schema, xml, group, context, category); - return files.length; } @@ -258,6 +248,37 @@ //-------------------------------------------------------------------------- //--- + //--- Private methods + //--- + //-------------------------------------------------------------------------- + + private void insert(String schema, Element xml, String group, ServiceContext context, + String category) throws Exception + { + GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); + DataManager dm = gc.getDataManager(); + + //----------------------------------------------------------------------- + //--- if the uuid does not exist we generate it + + String uuid = dm.extractUUID(schema, xml); + + if (uuid.length() == 0) + uuid = UUID.randomUUID().toString(); + + if (category.equals("_none_")) category = null; + //----------------------------------------------------------------------- + //--- insert metadata into the system + + Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB); + + String id = dm.insertMetadata(dbms, schema, category, group, xml, context.getSerialFactory(), gc.getSiteId(), uuid, context.getUserSession().getUserIdAsInt()); + + } + + + //-------------------------------------------------------------------------- + //--- //--- validateIt (should be in DataManager?) //--- //-------------------------------------------------------------------------- @@ -313,35 +334,6 @@ } - //-------------------------------------------------------------------------- - //--- - //--- Private methods - //--- - //-------------------------------------------------------------------------- - - private void insert(String schema, Element xml, String group, ServiceContext context, - String category) throws Exception - { - GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME); - DataManager dm = gc.getDataManager(); - - //----------------------------------------------------------------------- - //--- if the uuid does not exist we generate it - - String uuid = dm.extractUUID(schema, xml); - - if (uuid.length() == 0) - uuid = UUID.randomUUID().toString(); - - if (category.equals("_none_")) category = null; - //----------------------------------------------------------------------- - //--- insert metadata into the system - - Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB); - - String id = dm.insertMetadata(dbms, schema, category, group, xml, context.getSerialFactory(), gc.getSiteId(), uuid, context.getUserSession().getUserIdAsInt()); - - } } //============================================================================= @@ -511,7 +503,7 @@ throw new IllegalArgumentException("Default schema not found : "+ defaultTo); defaultSchema = defaultTo; - } + } } //============================================================================= Modified: sandbox/BlueNetMEST/src/org/fao/geonet/services/metadata/Insert.java =================================================================== --- sandbox/BlueNetMEST/src/org/fao/geonet/services/metadata/Insert.java 2009-11-05 11:06:51 UTC (rev 5449) +++ sandbox/BlueNetMEST/src/org/fao/geonet/services/metadata/Insert.java 2009-11-05 13:39:52 UTC (rev 5450) @@ -24,7 +24,9 @@ package org.fao.geonet.services.metadata; import java.util.UUID; + import jeeves.constants.Jeeves; +import jeeves.exceptions.BadParameterEx; import jeeves.exceptions.MissingParameterEx; import jeeves.interfaces.Service; import jeeves.resources.dbms.Dbms; @@ -32,6 +34,7 @@ import jeeves.server.context.ServiceContext; import jeeves.utils.Util; import jeeves.utils.Xml; + import org.fao.geonet.GeonetContext; import org.fao.geonet.constants.Geonet; import org.fao.geonet.constants.Params; @@ -73,7 +76,6 @@ String data = Util.getParam(params, Params.DATA); String group = Util.getParam(params, Params.GROUP); - String schema = Util.getParam(params, Params.SCHEMA); String isTemplate = Util.getParam(params, Params.TEMPLATE, "n"); String title = Util.getParam(params, Params.TITLE, ""); String category = Util.getParam(params, Params.CATEGORY); @@ -93,9 +95,12 @@ if (!style.equals("_none_")) xml = Xml.transform(xml, stylePath +"/"+ style); - if (validate) - ImportFromDir.validateIt(schema, xml, context); + String schema = dataMan.autodetectSchema(xml); + if (schema == null) + throw new BadParameterEx("Can't detect schema for metadata automatically.", schema); + if (validate) ImportFromDir.validateIt(schema, xml, context); + //----------------------------------------------------------------------- //--- if the uuid does not exist and is not a template we generate it @@ -107,11 +112,10 @@ } else uuid = UUID.randomUUID().toString(); - if (category.equals("_none_")) category = null; - //----------------------------------------------------------------------- //--- insert metadata into the system + if (category.equals("_none_")) category = null; Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB); String id = dataMan.insertMetadata(dbms, schema, category, group, xml, Modified: sandbox/BlueNetMEST/web/geonetwork/loc/en/xml/strings.xml =================================================================== --- sandbox/BlueNetMEST/web/geonetwork/loc/en/xml/strings.xml 2009-11-05 11:06:51 UTC (rev 5449) +++ sandbox/BlueNetMEST/web/geonetwork/loc/en/xml/strings.xml 2009-11-05 13:39:52 UTC (rev 5450) @@ -131,7 +131,7 @@ <backToDescription>Back to the data description</backToDescription> <backToPreviousPage>Back to previous page</backToPreviousPage> <backToEditor>Back to editing metadata</backToEditor> - <batchImport>Import all XML formatted metadata from a local directory</batchImport> + <batchImport>Import all metadata in XML or MEF format from a local directory</batchImport> <batchImportTitle>Batch Import</batchImportTitle> <begdate>Beginning Date</begdate> @@ -256,13 +256,19 @@ <feedbackReasonForDownload>Feedback / reason for download</feedbackReasonForDownload> <feedbackRequest>Please provide your details before downloading</feedbackRequest> <file>File</file> + <fileType>File type:</fileType> <fileUploadSuccessful>File Upload Successful</fileUploadSuccessful> + <insertFileMode js="true">File Upload</insertFileMode> + <insertMode>Insert mode:</insertMode> + <insertPasteMode>Copy/Paste</insertPasteMode> <firstName>First Name</firstName> <fr>Français</fr> <!-- Do not translate! --> + <fragment>Fragment</fragment> <freeKeyword>Free Keywords</freeKeyword> <from>From</from> <general>General</general> <generalInfo>General information</generalInfo> + <generateUUID>Generate UUID for inserted metadata</generateUUID> <georss>Open a GeoRSS feed</georss> <group>Group</group> <groupManagement>Group management</groupManagement> @@ -392,6 +398,7 @@ <metadataBadResponse1> - ERROR: Cannot understand the response received from the remote server</metadataBadResponse1> <metadataBadResponse2>Unable to show this record!</metadataBadResponse2> <mdUpdateError>Update error</mdUpdateError> + <mefFile>MEF file</mefFile> <message>The username or the password is wrong.<br/>Press the 'back' button and try again.</message> <messageMdUpdateError>Sorry, an error occurred while updating metadata.</messageMdUpdateError> <messageChanged>The metadata has been changed by another user. Please retry.</messageChanged> @@ -413,6 +420,7 @@ <newGroup>Add a new group</newGroup> <newCategory>Add a new category</newCategory> <newMdDes>Adds a new metadata into geonetwork copying it from a template</newMdDes> + <newMdInsert>New metadata inserted:</newMdInsert> <newMetadata>New metadata</newMetadata> <newOwner>New Owner</newOwner> <newPassword>New Password</newPassword> @@ -427,12 +435,14 @@ <northbc>North Bounding Coordinate</northbc> <noSelectedMd>No metadata selected! Please at least select one before select an action.</noSelectedMd> <notfound>Not found</notfound> + <nothing>No action on import</nothing> <online>Interactive map</online> <onlink>Online Linkage</onlink> <opensearch>GeoNetwork opensearch service allow search to be made into the metadata catalog.</opensearch> <operation>Operation</operation> <organisation>Organisation / department</organisation> <overwrite>Overwrite?</overwrite> + <overwriteUUID>Overwrite metadata with same UUID</overwriteUUID> <ownedBy>Owned by me</ownedBy> <owner>Owner</owner> <ownerrights>Delete/Privileges/Categories Unlocked: You have ownership rights</ownerrights> @@ -508,6 +518,7 @@ <setshowcategories>Set/Show Categories</setshowcategories> <setshowprivileges>Set/Show Privileges</setshowprivileges> <showFileDownloadSummary>Show File Download Summary</showFileDownloadSummary> + <singleFile>Single File (XML, SLD, WMC...)</singleFile> <sortBy>Sort by</sortBy> <sortByType id="relevance">Relevance</sortByType> <sortByType id="rating">Rating</sortByType> @@ -598,6 +609,7 @@ <userPw>Change password</userPw> <userPwDes>Allow current user to change password</userPwDes> <uuid>Universal Unique Identifier (UUID)</uuid> + <uuidAction>Import actions:</uuidAction> <validate>Validate</validate> <validityBegins>Validity begins</validityBegins> <validityEnds>and ends</validityEnds> @@ -610,7 +622,7 @@ <winInfo1>This window will show GeoNetwork resources. This window may be hidden at times depending on how your browser manages windows. In this case, you will have to manually bring the window to the foreground when necessary.</winInfo1> <winInfo2>Throughout the Help (?) icon give you access to explanations. When you activate this icon, it's output will be displayed in this Resource Window.</winInfo2> <wwwlink>Web link</wwwlink> - <xmlInsert>Import XML formatted metadata</xmlInsert> + <xmlInsert>Import metadata record in XML or MEF</xmlInsert> <xmlInsertTitle>XML Metadata Insert</xmlInsertTitle> <xmlTab>XML view</xmlTab> Modified: sandbox/BlueNetMEST/web/geonetwork/xsl/metadata-batchimport.xsl =================================================================== --- sandbox/BlueNetMEST/web/geonetwork/xsl/metadata-batchimport.xsl 2009-11-05 11:06:51 UTC (rev 5449) +++ sandbox/BlueNetMEST/web/geonetwork/xsl/metadata-batchimport.xsl 2009-11-05 13:39:52 UTC (rev 5450) @@ -2,31 +2,8 @@ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:include href="edit.xsl"/> + <xsl:include href="metadata-insert-form-utils.xsl"/> - <xsl:template mode="script" match="/"> - <script type="text/javascript" language="JavaScript"> - - var schema = new Array ( - <xsl:for-each select="/root/gui/schemas/name"> - <xsl:sort select="."/> - "<xsl:value-of select="."/>"<xsl:if test="position()!=last()">,</xsl:if> - </xsl:for-each>); - - // Update schema according to stylesheet selected (ie. styleSheet MUST end with schemaName.xsl) - function updateSchema() { - var xsl = $('styleSheet').options[$('styleSheet').selectedIndex].value; - for (i = 0; i < schema.length; i ++) { - if (xsl.toLowerCase().lastIndexOf(schema[i]+'.xsl') != -1) { - $('schema').selectedIndex = i; - return; - } - } - $('schema').selectedIndex = 0; - } - - </script> - </xsl:template> - <!-- page content --> @@ -37,8 +14,9 @@ <xsl:call-template name="form"/> </xsl:with-param> <xsl:with-param name="buttons"> - <!-- <button class="content" onclick="goBack()"><xsl:value-of select="/root/gui/strings/back"/></button> - --> + <!-- <button class="content" onclick="goBack()"><xsl:value-of select="/root/gui/strings/back"/></button> + + --> <button class="content" onclick="goSubmit('xmlbatch')"><xsl:value-of select="/root/gui/strings/upload"/></button> </xsl:with-param> </xsl:call-template> @@ -47,84 +25,33 @@ <xsl:template name="form"> <form name="xmlbatch" accept-charset="UTF-8" action="{/root/gui/locService}/util.import" method="post"> <input type="submit" style="display: none;" /> + <table> <tr> <th class="padded"><xsl:value-of select="/root/gui/strings/directory"/></th> - <td class="padded"><input class="content" type="text" name="dir"/></td> + <td class="padded"><input class="content" type="text" size="50" name="dir"/></td> </tr> <!-- transformation stylesheet --> - - <tr> - <th class="padded"><xsl:value-of select="/root/gui/strings/styleSheet"/></th> - <td class="padded"> - <select class="content" name="styleSheet" id="styleSheet" size="1" onchange="updateSchema();"> - <option value="_none_"> - <xsl:value-of select="/root/gui/strings/none"/> - </option> - <xsl:for-each select="/root/gui/importStyleSheets/record"> - <xsl:sort select="name"></xsl:sort> - <option value="{id}"> - <xsl:value-of select="name"/> - </option> - </xsl:for-each> - </select> - </td> - </tr> - <tr> - <th class="padded"><xsl:value-of select="/root/gui/strings/schema"/></th> - <td class="padded"> - <select class="content" name="schema" id="schema" size="1"> - <xsl:for-each select="/root/gui/schemas/name"> - <xsl:sort select="."></xsl:sort> - <option value="{.}"> - <xsl:value-of select="."/> - </option> - </xsl:for-each> - </select> + <tr id="gn.fileType"> + <th class="padded" valign="top"><xsl:value-of select="/root/gui/strings/fileType"/></th> + <td> + <table> + <tr> + <td class="padded"> + <label for="singleFile"><xsl:value-of select="/root/gui/strings/singleFile"/></label> + <input type="radio" id="singleFile" name="file_type" value="single" checked="true"/> + </td> + <td class="padded"> + <label for="mefFile"><xsl:value-of select="/root/gui/strings/mefFile"/></label> + <input type="radio" id="mefFile" name="file_type" value="mef"/> + </td> + </tr> + </table> </td> </tr> - <tr> - <th class="padded"><xsl:value-of select="/root/gui/strings/validate"/></th> - <td><input class="content" type="checkbox" name="validate"/></td> - </tr> - <!-- groups --> - - <xsl:variable name="lang" select="/root/gui/language"/> - - <tr> - <th class="padded"><xsl:value-of select="/root/gui/strings/group"/></th> - <td class="padded"> - <select class="content" name="group" size="1"> - <xsl:for-each select="/root/gui/groups/record"> - <option value="{id}"> - <xsl:value-of select="label/child::*[name() = $lang]"/> - </option> - </xsl:for-each> - </select> - </td> - </tr> - - <!-- categories --> - - <tr> - <th class="padded"><xsl:value-of select="/root/gui/strings/category"/></th> - <td class="padded"> - <select class="content" name="category" size="1"> - <option value="_none_"> - <xsl:value-of select="/root/gui/strings/none"/> - </option> - <xsl:for-each select="/root/gui/categories/record"> - <xsl:sort select="label/child::*[name() = $lang]" order="ascending"/> - <option value="{id}"> - <xsl:value-of select="label/child::*[name() = $lang]"/> - </option> - </xsl:for-each> - </select> - </td> - </tr> - + <xsl:call-template name="metadata-insert-common-form"/> </table> </form> </xsl:template> Added: sandbox/BlueNetMEST/web/geonetwork/xsl/metadata-insert-form-utils.xsl =================================================================== --- sandbox/BlueNetMEST/web/geonetwork/xsl/metadata-insert-form-utils.xsl (rev 0) +++ sandbox/BlueNetMEST/web/geonetwork/xsl/metadata-insert-form-utils.xsl 2009-11-05 13:39:52 UTC (rev 5450) @@ -0,0 +1,132 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + + <xsl:template name="metadata-insert-common-form"> + + <xsl:variable name="lang" select="/root/gui/language"/> + + <!-- uuid constraints --> + <tr id="gn.uuidAction"> + <th class="padded" valign="top"> + <xsl:value-of select="/root/gui/strings/uuidAction"/> + </th> + <td> + <table> + <tr> + <td class="padded"> + <input type="radio" id="nothing" name="uuidAction" value="nothing" checked="true"/> + <label for="nothing"> + <xsl:value-of select="/root/gui/strings/nothing"/> + </label> + <xsl:text> </xsl:text> + </td> + </tr> + <tr> + <td class="padded"> + <input type="radio" id="overwrite" name="uuidAction" value="overwrite"/> + <label for="overwrite"> + <xsl:value-of select="/root/gui/strings/overwriteUUID"/> + </label> + <xsl:text> </xsl:text> + </td> + </tr> + <tr> + <td class="padded"> + <input type="radio" id="generateUUID" name="uuidAction" value="generateUUID"/> + <label for="generateUUID"> + <xsl:value-of select="/root/gui/strings/generateUUID"/> + </label> + <xsl:text> </xsl:text> + </td> + </tr> + </table> + </td> + </tr> + + + + <!-- stylesheet --> + <tr id="gn.stylesheet"> + <th class="padded"> + <xsl:value-of select="/root/gui/strings/styleSheet"/> + </th> + <td class="padded"> + <select class="content" id="styleSheet" name="styleSheet" size="1"> + <option value="_none_"> + <xsl:value-of select="/root/gui/strings/none"/> + </option> + <xsl:for-each select="/root/gui/importStyleSheets/record"> + <xsl:sort select="name"/> + <option value="{id}"> + <xsl:value-of select="name"/> + </option> + </xsl:for-each> + </select> + </td> + </tr> + + + <!-- validate --> + <tr id="gn.validate"> + <th class="padded"> + <label for="validate"> + <xsl:value-of select="/root/gui/strings/validate"/> + </label> + </th> + <td> + <input class="content" type="checkbox" name="validate" id="validate"/> + </td> + </tr> + + + + <!-- groups --> + <tr id="gn.groups"> + <th class="padded"> + <xsl:value-of select="/root/gui/strings/group"/> + </th> + <td class="padded"> + <select class="content" name="group" size="1"> + <xsl:for-each select="/root/gui/groups/record"> + <xsl:sort select="label/child::*[name() = $lang]"/> + <option value="{id}"> + <xsl:value-of select="label/child::*[name() = $lang]"/> + </option> + </xsl:for-each> + </select> + </td> + </tr> + + + + <!-- categories + Some users are not using categories, so hide the list and + set default value to _none_ if no categories available. + --> + <xsl:choose> + <xsl:when test="/root/gui/categories/record"> + <tr id="gn.categories"> + <th class="padded"> + <xsl:value-of select="/root/gui/strings/category"/> + </th> + <td class="padded"> + <select class="content" name="category" size="1"> + <option value="_none_"> + <xsl:value-of select="/root/gui/strings/none"/> + </option> + <xsl:for-each select="/root/gui/categories/record"> + <xsl:sort select="label/child::*[name() = $lang]"/> + <option value="{id}"> + <xsl:value-of select="label/child::*[name() = $lang]"/> + </option> + </xsl:for-each> + </select> + </td> + </tr> + </xsl:when> + <xsl:otherwise> + <input type="hidden" name="category" value="_none_"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> +</xsl:stylesheet> Modified: sandbox/BlueNetMEST/web/geonetwork/xsl/metadata-insert-form.xsl =================================================================== --- sandbox/BlueNetMEST/web/geonetwork/xsl/metadata-insert-form.xsl 2009-11-05 11:06:51 UTC (rev 5449) +++ sandbox/BlueNetMEST/web/geonetwork/xsl/metadata-insert-form.xsl 2009-11-05 13:39:52 UTC (rev 5450) @@ -2,41 +2,149 @@ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:include href="edit.xsl"/> - + <xsl:include href="metadata-insert-form-utils.xsl"/> + <!-- ================================================================================ --> <!-- additional scripts --> <!-- ================================================================================ --> <xsl:template mode="script" match="/"> <script type="text/javascript" language="JavaScript"> - function init() - { - typeChanged(); + function init() { + var modeValue = getModeValue(); + + typeChanged(); + insertMode(modeValue); + + if (modeValue == 1) + updateForm(); } - function typeChanged() - { + function typeChanged() { var type = $F('metadata.type'); if (type == 's') Element.show('metadata.title'); - else Element.hide('metadata.title'); + else Element.hide('metadata.title'); } - var schema = new Array ( - <xsl:for-each select="/root/gui/schemas/name"> - <xsl:sort select="."/> - "<xsl:value-of select="."/>"<xsl:if test="position()!=last()">,</xsl:if> - </xsl:for-each>); + + function getModeValue() { + for (var i=0; i < document.xmlinsert.insert_mode.length; i++){ + if (document.xmlinsert.insert_mode[i].checked){ + var modeValue = document.xmlinsert.insert_mode[i].value; + } + } + return modeValue; + } - // Update schema according to stylesheet selected (ie. styleSheet MUST end with schemaName.xsl) - function updateSchema() { - var xsl = $('styleSheet').options[$('styleSheet').selectedIndex].value; - for (i = 0; i < schema.length; i ++) { - if (xsl.toLowerCase().lastIndexOf(schema[i]+'.xsl') != -1) { - $('schema').selectedIndex = i; - return; + function getFileValue() { + for (var i=0; i < document.xmlinsert.file_type.length; i++){ + if (document.xmlinsert.file_type[i].checked){ + var fileValue = document.xmlinsert.file_type[i].value; } - } - $('schema').selectedIndex = 0; + } + return fileValue; } + + function updateForm() { + var fileType = getFileValue(); + + if (fileType == 'single') displayAllForm(true); + else if (fileType == 'mef') displayAllForm(false); + } + + function insertMode(value) { + if (value == 0) { + Element.hide('gn.fileUp'); + Element.show('gn.xmlUp'); + $('gn.fileType').style.display='none'; + $('gn.uuidAction').style.display='none'; + document.xmlinsert.enctype="application/x-www-form-urlencoded"; + document.xmlinsert.encoding="application/x-www-form-urlencoded"; + document.xmlinsert.action=Env.locService+"/metadata.insert.paste"; + document.xmlinsert.target='_self'; + } else { + Element.hide('gn.xmlUp'); + Element.show('gn.fileUp'); + $('gn.fileType').style.display=''; + $('gn.uuidAction').style.display=''; + document.xmlinsert.enctype="multipart/form-data"; + document.xmlinsert.encoding="multipart/form-data"; + document.xmlinsert.action=Env.locService+"/mef.import"; + document.xmlinsert.target='upFrame'; + } + } + + function displayAllForm(show) { + var display; + + if (show == true) + display=''; + else + display='none'; + + displayElement('gn.type',display); + displayElement('gn.stylesheet',display); + displayElement('gn.validate',display); + displayElement('gn.groups',display); + displayElement('gn.categories',display); + } + + function displayElement(id, value) { + if ($(id)) + $(id).style.display=value; + } + + function doFileUpload(){ + var response = $('upFrame').contentWindow.document; + var elt; + if (response.XMLDocument){ + elt = response.XMLDocument.selectSingleNode('ok'); + } else { + elt = response.getElementsByTagName('ok')[0]; + } + var error = $('upFrame').contentWindow.document.getElementById('error'); + + if (elt != null || error != null) { + $('btInsert').style.display='none'; + $('gn.insertTable').style.display = 'none'; + if (elt != null) { + var id; + if (response.XMLDocument) + id= elt.text; + else + id = elt.firstChild.nodeValue; + createResponseForm(id); + } else if (error != null){ + $('back').style.display='none'; + displayError(error); + } + $('gn.result').style.display = 'block'; + } + } + + function createResponseForm(value) { + var contentElt = $('gn.resultContent'); + var id = document.createTextNode(value); + var element = document.createElement("a"); + var space = document.createTextNode(" "); + + element.setAttribute("href", Env.locService+"/metadata.show?id="+value+"&currTab=simple"); + element.appendChild(id); + + contentElt.appendChild(element); + contentElt.appendChild(space); + } + + function displayError(errorDiv) { + var content = $('gn.resultContent'); + $('gn.resultTitle').innerHTML = "" ; + if (!$('error')) { + content.appendChild(errorDiv); + $('goBack').onclick = function () { + load('metadata.xmlinsert.form'); + }; + } + } + </script> </xsl:template> @@ -48,23 +156,68 @@ <xsl:call-template name="formLayout"> <xsl:with-param name="title" select="/root/gui/strings/xmlInsert"/> <xsl:with-param name="content"> - <form name="xmlinsert" accept-charset="UTF-8" method="post" action="{/root/gui/locService}/metadata.insert.paste"> + <form name="xmlinsert" accept-charset="UTF-8" method="post" action="{/root/gui/locService}/metadata.insert" enctype="multipart/form-data"> <input type="submit" style="display: none;" /> - <table> + <table id="gn.insertTable"> <tr> - <th class="padded" valign="top"><xsl:value-of select="/root/gui/strings/metadata"/></th> - <td class="padded"><textarea class="content" name="data" cols="80" rows="20"/></td> - </tr> - + <th class="padded" valign="top"><xsl:value-of select="/root/gui/strings/insertMode"/></th> + <td> + <table> + <tr> + <td class="padded"> + <input type="radio" id="insertFileMode" name="insert_mode" value="1" + onclick="insertMode(this.value)" checked="true"/> + <label for="insertFileMode"><xsl:value-of select="/root/gui/strings/insertFileMode"/></label> + </td> + <td class="padded"> + <input type="radio" id="insertPasteMode" name="insert_mode" value="0" + onclick="$('singleFile').checked=true;displayAllForm(true);insertMode(this.value)"/> + <label for="insertPasteMode"><xsl:value-of select="/root/gui/strings/insertPasteMode"/></label> + <xsl:text> </xsl:text> + </td> + </tr> + </table> + </td> + </tr> + <tr id="gn.fileType"> + <th class="padded" valign="top"><xsl:value-of select="/root/gui/strings/fileType"/></th> + <td> + <table> + <tr> + <td class="padded"> + <input type="radio" id="singleFile" name="file_type" value="single" onclick="displayAllForm(this.checked)" checked="true"/> + <label for="singleFile"><xsl:value-of select="/root/gui/strings/singleFile"/></label> + <xsl:text> </xsl:text> + </td> + <td class="padded"> + <input type="radio" id="mefFile" name="file_type" value="mef" onclick="displayAllForm(false)"/> + <label for="mefFile"><xsl:value-of select="/root/gui/strings/mefFile"/></label> + <xsl:text> </xsl:text> + </td> + </tr> + </table> + </td> + </tr> + <tr> + <th class="padded" valign="top"><xsl:value-of select="/root/gui/strings/metadata"/></th> + <td class="padded"> + <span id="gn.xmlUp" style="display:none"> + <textarea class="content" name="data" cols="80" rows="20"/> + </span> + <span id="gn.fileUp" style="display:none"> + <input type="file" accept="*.xml, *.zip, *.mef" class="content" size="60" name="mefFile" value=""/> + </span> + </td> + </tr> + <!-- type --> - - <tr> + <tr id="gn.type"> <th class="padded" valign="top"><xsl:value-of select="/root/gui/strings/type"/></th> <td> <select class="content" name="template" size="1" id="metadata.type" onchange="typeChanged()"> <option value="n"><xsl:value-of select="/root/gui/strings/metadata"/></option> <option value="y"><xsl:value-of select="/root/gui/strings/template"/></option> - <!-- <option value="s"><xsl:value-of select="/root/gui/strings/subtemplate"/></option> --> + <option value="s"><xsl:value-of select="/root/gui/strings/fragment"/></option> </select> <div id="metadata.title"> <xsl:text> </xsl:text> @@ -75,90 +228,23 @@ </td> </tr> - <!-- stylesheet --> + <xsl:call-template name="metadata-insert-common-form"/> - <tr> - <th class="padded"><xsl:value-of select="/root/gui/strings/styleSheet"/></th> - <td class="padded"> - <select class="content" id="styleSheet" name="styleSheet" size="1" onchange="updateSchema();"> - <option value="_none_"> - <xsl:value-of select="/root/gui/strings/none"/> - </option> - <xsl:for-each select="/root/gui/importStyleSheets/record"> - <xsl:sort select="name"></xsl:sort> - <option value="{id}"> - <xsl:value-of select="name"/> - </option> - </xsl:for-each> - </select> - </td> - </tr> - - <!-- destination schema --> - - <tr> - <th class="padded"><xsl:value-of select="/root/gui/strings/desSchema"/></th> - <td class="padded"> - <select class="content" id="schema" name="schema" size="1"> - <xsl:for-each select="/root/gui/schemas/name"> - <xsl:sort select="."></xsl:sort> - <option value="{.}"> - <xsl:value-of select="."/> - </option> - </xsl:for-each> - </select> - </td> - </tr> - - <!-- validate --> - - <tr> - <th class="padded"><xsl:value-of select="/root/gui/strings/validate"/></th> - <td><input class="content" type="checkbox" name="validate"/></td> - </tr> - - <!-- groups --> - - <xsl:variable name="lang" select="/root/gui/language"/> - - <tr> - <th class="padded"><xsl:value-of select="/root/gui/strings/group"/></th> - <td class="padded"> - <select class="content" name="group" size="1"> - <xsl:for-each select="/root/gui/groups/record"> - <option value="{id}"> - <xsl:value-of select="label/child::*[name() = $lang]"/> - </option> - </xsl:for-each> - </select> - </td> - </tr> - - <!-- categories --> - - <tr> - <th class="padded"><xsl:value-of select="/root/gui/strings/category"/></th> - <td class="padded"> - <select class="content" name="category" size="1"> - <option value="_none_"> - <xsl:value-of select="/root/gui/strings/none"/> - </option> - <xsl:for-each select="/root/gui/categories/record"> - <xsl:sort select="label/child::*[name() = $lang]" order="ascending"/> - <option value="{id}"> - <xsl:value-of select="label/child::*[name() = $lang]"/> - </option> - </xsl:for-each> - </select> - </td> - </tr> + </table> + <iframe id="upFrame" name="upFrame" width="200p" height="100p" onload="javascript:doFileUpload();" style="display:none;"/> + <table id="gn.result" style="display:none;"> + <tr> + <th id="gn.resultTitle" class="padded-content"> + <h2><xsl:value-of select="/root/gui/strings/newMdInsert" /></h2> + </th> + <td id="gn.resultContent" class="padded-content" /> + </tr> + </table> </form> </xsl:with-param> <xsl:with-param name="buttons"> - <!-- <button class="content" onclick="goBack()"><xsl:value-of select="/root/gui/strings/back"/></button> - --> - <button class="content" onclick="goSubmit('xmlinsert')"><xsl:value-of select="/root/gui/strings/insert"/></button> + <button class="content" onclick="goSubmit('xmlinsert')" id="btInsert"><xsl:value-of select="/root/gui/strings/insert"/></button> </xsl:with-param> </xsl:call-template> </xsl:template> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ GeoNetwork-commit mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geonetwork-commit |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |