Skip to content

Commit

Permalink
add element will now add language combo box if required
Browse files Browse the repository at this point in the history
Conflicts:
	web/src/main/java/org/fao/geonet/kernel/EditLib.java
	web/src/main/java/org/fao/geonet/services/metadata/DeleteElement.java
  • Loading branch information
Jesse Eichar committed Oct 29, 2012
1 parent ae05810 commit 28fcc4f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 30 deletions.
15 changes: 15 additions & 0 deletions web/src/main/java/org/fao/geonet/kernel/EditLib.java
Expand Up @@ -1435,6 +1435,21 @@ else if (!attr.required)
}
}

// -- The following methods are used by services that use metadata-edit-embedded so the
// -- classes know which element to transform
/**
* Tag the element so the metaata-edit-embedded.xsl know which element is the element for display
*/
public static void tagForDisplay(Element elem) {
elem.setAttribute("addedObj","true", Edit.NAMESPACE);
}
/**
* Remove the tag element so the tag does not stay in the actual metadata.
*/
public static void removeDisplayTag(Element elem) {
elem.removeAttribute("addedObj", Edit.NAMESPACE);
}

/**
* Get the XPath expression for identified Element.
*
Expand Down
33 changes: 25 additions & 8 deletions web/src/main/java/org/fao/geonet/services/metadata/AddElement.java
Expand Up @@ -29,10 +29,10 @@
import jeeves.server.UserSession;
import jeeves.server.context.ServiceContext;
import jeeves.utils.Util;
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.kernel.EditLib;
import org.jdom.Element;

//=============================================================================
Expand All @@ -42,7 +42,7 @@

public class AddElement implements Service
{
public void init(String appPath, ServiceConfig params) throws Exception {}
public void init(String appPath, ServiceConfig params) throws Exception {}

//--------------------------------------------------------------------------
//---
Expand All @@ -53,9 +53,6 @@ public void init(String appPath, ServiceConfig params) throws Exception {}
public Element exec(Element params, ServiceContext context) throws Exception
{

GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
DataManager dataMan = gc.getDataManager();

Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB);
UserSession session = context.getUserSession();

Expand All @@ -64,10 +61,30 @@ public Element exec(Element params, ServiceContext context) throws Exception
String name = Util.getParam(params, Params.NAME);
String child = params.getChildText(Params.CHILD);

// -- build the element to be added and return it
// -- build the element to be added
// -- Here we do mark the element that is added
// -- then we traverse up the tree to the root
// -- clone from the root and return the clone
// -- this is done so that the style sheets have
// -- access to important information like the
// -- document language and other locales
// -- this is important for multilingual editing
// --
// -- Note that the metadata-embedded.xsl stylesheet
// -- only applies the templating to the added element, not to
// -- the entire metadata so performance should not be a big issue
Element elResp = new AjaxEditUtils(context).addElementEmbedded(dbms, session, id, ref, name, child);
return elResp;
EditLib.tagForDisplay(elResp);
Element md = (Element) findRoot(elResp).clone();
EditLib.removeDisplayTag(elResp);

return md;
}

private Element findRoot( Element element ) {
if(element.isRootElement() || element.getParentElement() == null) return element;
return findRoot(element.getParentElement());
}
}

//=============================================================================
Expand Down
15 changes: 3 additions & 12 deletions web/src/main/java/org/fao/geonet/services/metadata/AddXLink.java
Expand Up @@ -20,11 +20,6 @@

package org.fao.geonet.services.metadata;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import jeeves.constants.Jeeves;
import jeeves.interfaces.Service;
import jeeves.resources.dbms.Dbms;
import jeeves.server.ServiceConfig;
Expand All @@ -33,14 +28,11 @@
import jeeves.utils.Util;
import jeeves.xlink.XLink;

import org.apache.commons.lang.NotImplementedException;
import org.fao.geonet.GeonetContext;
import org.fao.geonet.constants.Edit;
import org.fao.geonet.constants.Geonet;
import org.fao.geonet.constants.Params;
import org.fao.geonet.kernel.DataManager;
import org.fao.geonet.kernel.EditLib;
import org.fao.geonet.kernel.reusable.ReusableObjManager;
import org.jdom.Attribute;
import org.jdom.Element;

//=============================================================================
Expand Down Expand Up @@ -90,10 +82,9 @@ public Element exec(Element params, ServiceContext context)
// -- build the element to be added and return it
AjaxEditUtils ajaxEditUtils = new AjaxEditUtils(context);
Element element = ajaxEditUtils.addXLink(dbms, session, id, ref, name, xLink);
Attribute attribute = new Attribute("xlinkedObj","true", Edit.NAMESPACE);
element.setAttribute(attribute);
EditLib.tagForDisplay(element);
Element md = (Element) findRoot(element).clone();
element.removeAttribute(attribute);
EditLib.removeDisplayTag(element);
return md;
}

Expand Down
Expand Up @@ -29,10 +29,10 @@
import jeeves.server.UserSession;
import jeeves.server.context.ServiceContext;
import jeeves.utils.Util;
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.kernel.EditLib;
import org.jdom.Element;

//=============================================================================
Expand All @@ -58,20 +58,22 @@ public void init(String appPath, ServiceConfig params) throws Exception {}

public Element exec(Element params, ServiceContext context) throws Exception
{

GeonetContext gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
DataManager dataMan = gc.getDataManager();

UserSession session = context.getUserSession();
Dbms dbms = (Dbms) context.getResourceManager().open(Geonet.Res.MAIN_DB);

String id = Util.getParam(params, Params.ID);
String ref = Util.getParam(params, Params.REF);
String parentRef = Util.getParam(params, Params.PARENT);

Element child = new AjaxEditUtils(context).deleteElementEmbedded(dbms, session, id, ref, parentRef);
Element child = null;
child = new AjaxEditUtils(context).deleteElementEmbedded(dbms, session, id, ref, parentRef);

// -- The metadata-edit-embedded.xsl searches for a taged element to
// -- transform so tag the element for display
Element cloned = (Element) child.clone();
EditLib.tagForDisplay(cloned);

return child;
return cloned;
}
}

Expand Down
2 changes: 1 addition & 1 deletion web/src/main/webapp/WEB-INF/config-geocat.xml
Expand Up @@ -218,7 +218,7 @@
<service name="metadata.xlink.add">
<class name=".services.metadata.AddXLink"/>

<output sheet="metadata-add-xlink.xsl">
<output sheet="metadata-edit-embedded.xsl">
<call name="currTab" class =".guiservices.util.GetCurrentMDTab"/>
<call name="position" class =".guiservices.util.GetPositionMD"/>
<call name="groups" class =".guiservices.groups.GetMine"/>
Expand Down
2 changes: 1 addition & 1 deletion web/src/main/webapp/xsl/metadata-edit-embedded.xsl
Expand Up @@ -13,7 +13,7 @@
<xsl:include href="metadata.xsl"/>

<xsl:template match="/">
<xsl:for-each select="/root/*[name(.)!='gui' and name(.)!='request']">
<xsl:for-each select="/root/*[name(.)!='gui' and name(.)!='request']//*[@geonet:addedObj = 'true']">
<xsl:apply-templates mode="elementEP" select=".">
<xsl:with-param name="edit" select="true()"/>
<xsl:with-param name="schema">
Expand Down

0 comments on commit 28fcc4f

Please sign in to comment.