⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datamanager.java

📁 联合国农粮署牵头开发的geonetwork源代码最新版
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		//--- check if the metadata has been deleted		if (md == null)			return false;		editLib.enumerateTree(md);		//--- check if the metadata has been modified from last time		if (currVersion != null && !editLib.getVersion(id).equals(currVersion))			return false;		//--- get element to add		Element el = editLib.findElement(md, ref);		if (el == null)			throw new IllegalStateException("Element not found at ref = " + ref);		//--- remove editing info added by previous call		editLib.removeEditingInfo(md);		el.setAttribute(new Attribute(name, ""));		String schema = getMetadataSchema(dbms, id);		md = updateFixedInfo(schema, id, md, dbms);		XmlSerializer.update(dbms, id, md);		//--- update search criteria		indexMetadata(dbms, id);		return true;	}	//--------------------------------------------------------------------------	/** For Editing : removes an element from a metadata ([del] link)	  */	public synchronized boolean deleteElement(Dbms dbms, String id, String ref,															String currVersion) throws Exception	{		Element md = XmlSerializer.select(dbms, "Metadata", id);		//--- check if the metadata has been deleted		if (md == null)			return false;		editLib.enumerateTree(md);		//--- check if the metadata has been modified from last time		if (currVersion != null && !editLib.getVersion(id).equals(currVersion))			return false;		//--- get element to remove		Element el = editLib.findElement(md, ref);		if (el == null)			throw new IllegalStateException("Element not found at ref = " + ref);		el.detach();		//--- remove editing info added by previous call		editLib.removeEditingInfo(md);		String schema = getMetadataSchema(dbms, id);		md = updateFixedInfo(schema, id, md, dbms);		XmlSerializer.update(dbms, id, md);		//--- update search criteria		indexMetadata(dbms, id);		return true;	}	//--------------------------------------------------------------------------	/** For Editing : removes an attribute from a metadata ([del] link)	  */	public synchronized boolean deleteAttribute(Dbms dbms, String id, String ref,															  String name, String currVersion) throws Exception	{		Element md = XmlSerializer.select(dbms, "Metadata", id);		//--- check if the metadata has been deleted		if (md == null)			return false;		editLib.enumerateTree(md);		//--- check if the metadata has been modified from last time		if (currVersion != null && !editLib.getVersion(id).equals(currVersion))			return false;		//--- get element to remove		Element el = editLib.findElement(md, ref);		if (el == null)			throw new IllegalStateException("Element not found at ref = " + ref);		//--- remove editing info added by previous call		editLib.removeEditingInfo(md);		el.removeAttribute(name);		String schema = getMetadataSchema(dbms, id);		md = updateFixedInfo(schema, id, md, dbms);		XmlSerializer.update(dbms, id, md);		//--- update search criteria		indexMetadata(dbms, id);		return true;	}	//--------------------------------------------------------------------------	/** For Editing : swap a tag with one of its sibling ([up] and [down] links)	  */	public synchronized boolean swapElement(Dbms dbms, String id, String ref,														 String currVersion, boolean down) throws Exception	{		Element md = XmlSerializer.select(dbms, "Metadata", id);		//--- check if the metadata has been deleted		if (md == null)			return false;		editLib.enumerateTree(md);		//--- check if the metadata has been modified from last time		if (currVersion != null && !editLib.getVersion(id).equals(currVersion))			return false;		//--- get element to swap		Element elSwap = editLib.findElement(md, ref);		if (elSwap == null)			throw new IllegalStateException("Element not found at ref = " + ref);		//--- remove editing info added by previous call		editLib.removeEditingInfo(md);		//--------------------------------------------------------------------		//--- swap elements		int iSwapIndex = -1;		List list = ((Element) elSwap.getParent()).getChildren(elSwap.getName(), elSwap.getNamespace());		for(int i=0; i<list.size(); i++)			if (list.get(i) == elSwap)			{				iSwapIndex = i;				break;			}		if (iSwapIndex == -1)			throw new IllegalStateException("Index not found for element --> " + elSwap);		if (down)	swapElements(elSwap, (Element) list.get(iSwapIndex +1));			else		swapElements(elSwap, (Element) list.get(iSwapIndex -1));		String schema = getMetadataSchema(dbms, id);		md = updateFixedInfo(schema, id, md, dbms);		XmlSerializer.update(dbms, id, md);		return true;	}	//--------------------------------------------------------------------------	/** For Editing : updates all leaves with new values	  */	public synchronized boolean updateMetadata(Dbms dbms, String id, String currVersion,															 Hashtable changes, boolean validate) throws Exception	{		Element md = XmlSerializer.select(dbms, "Metadata", id);		//--- check if the metadata has been deleted		if (md == null)			return false;		editLib.enumerateTree(md);		//--- check if the metadata has been modified from last time		if (currVersion != null && !editLib.getVersion(id).equals(currVersion))			return false;		//--------------------------------------------------------------------		//--- update elements		for(Enumeration e=changes.keys(); e.hasMoreElements();)		{			String ref = ((String) e.nextElement()) .trim();			String val = ((String) changes.get(ref)).trim();			String attr= null;			int at = ref.indexOf("_");			if (at != -1)			{				attr = ref.substring(at +1);				ref  = ref.substring(0, at);			}			Element el = editLib.findElement(md, ref);			if (el == null)				throw new IllegalStateException("Element not found at ref = " + ref);			if (attr != null) {// The following work-around decodes any attribute name that has a COLON in it// The : is replaced by the word COLON in the xslt so that it can be processed// by the XML Serializer when an update is submitted - the only situation// where this is known to occur is in the gml schema (eg. gml:id) - a better// solution may be required				Integer indexColon = attr.indexOf("COLON");        if (indexColon != -1) {					String prefix = attr.substring(0,indexColon);          String localname = attr.substring(indexColon + 5);          String namespace = editLib.getNamespace(prefix+":"+localname,md);					Namespace attrNS = Namespace.getNamespace(prefix,namespace);          if (el.getAttribute(localname,attrNS) != null) {            el.setAttribute(new Attribute(localname,val,attrNS));          }// End of work-around        } else {          if (el.getAttribute(attr) != null)            el.setAttribute(new Attribute(attr, val));        }			}			else			{				List content = el.getContent();				for(int i=0; i<content.size(); i++)				{					if (content.get(i) instanceof Text)					{						el.removeContent((Text) content.get(i));						i--;					}				}				el.addContent(val);			}		}		//--- remove editing info added by previous call		editLib.removeEditingInfo(md);		return updateMetadata(dbms, id, md, validate, currVersion);	}	//--------------------------------------------------------------------------	public synchronized boolean updateMetadata(Dbms dbms, String id, Element md,														 boolean validate, String version) throws Exception	{		//--- check if the metadata has been modified from last time		if (version != null && !editLib.getVersion(id).equals(version))			return false;		//--- make sure that any lingering CHOICE_ELEMENTS are replaced with their		//--- children		editLib.replaceChoiceElements(md);		String schema = getMetadataSchema(dbms, id);		md = updateFixedInfo(schema, id, md, dbms);		if (validate)			validate(schema, md);		XmlSerializer.update(dbms, id, md);		//--- update search criteria		indexMetadata(dbms, id);		return true;	}	//--------------------------------------------------------------------------	//--- Used by the harvesting procedure	public void updateMetadataExt(Dbms dbms, String id, Element md, String changeDate)											throws Exception	{		XmlSerializer.update(dbms, id, md, changeDate);	}	//--------------------------------------------------------------------------	//---	//--- Metadata Delete API	//---	//--------------------------------------------------------------------------	/** Removes a metadata	  */	public synchronized void deleteMetadata(Dbms dbms, String id) throws Exception	{		//--- remove operations		deleteMetadataOper(dbms, id, false);		//--- remove categories		deleteAllMetadataCateg(dbms, id);		//--- remove metadata		XmlSerializer.delete(dbms, "Metadata", id);		//--- update search criteria		searchMan.delete("_id", id+"");	}	//--------------------------------------------------------------------------	/** Remove all operations stored for a metadata	  */	public void deleteMetadataOper(Dbms dbms, String id, boolean skipAllIntranet) throws Exception	{		String query = "DELETE FROM OperationAllowed WHERE metadataId="+id;		if (skipAllIntranet)			query += " AND groupId>1";		dbms.execute(query);	}	//--------------------------------------------------------------------------	/** Remove all categories stored for a metadata	  */	public void deleteAllMetadataCateg(Dbms dbms, String id) throws Exception	{		String query = "DELETE FROM MetadataCateg WHERE metadataId="+id;		dbms.execute(query);	}	//--------------------------------------------------------------------------	//---	//--- Metadata thumbnail API	//---	//--------------------------------------------------------------------------	public Element getThumbnails(Dbms dbms, String id) throws Exception	{		Element md = XmlSerializer.select(dbms, "Metadata", id);		if (md == null)			return null;		md.detach();		String schema = getMetadataSchema(dbms, id);		//--- do an XSL  transformation		String styleSheet = editLib.getSchemaDir(schema) + Geonet.File.EXTRACT_THUMBNAILS;		Element result = Xml.transform(md, styleSheet);		result.addContent(new Element("id").setText(id));		return result;	}	//--------------------------------------------------------------------------	public void setThumbnail(Dbms dbms, String id, boolean small, String file) throws Exception	{		int    pos = file.lastIndexOf(".");		String ext = (pos == -1) ? "???" : file.substring(pos +1);		Element env = new Element("env");		env.addContent(new Element("file").setText(file));		env.addContent(new Element("ext").setText(ext));		manageThumbnail(dbms, id, small, env, Geonet.File.SET_THUMBNAIL);	}	//--------------------------------------------------------------------------	public void unsetThumbnail(Dbms dbms, String id, boolean small) throws Exception	{		Element env = new Element("env");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -