org.fao.geonet.services.metadata
Class AjaxEditUtils

java.lang.Object
  extended by org.fao.geonet.services.metadata.AjaxEditUtils

public class AjaxEditUtils
extends Object

// -------------------------------------------------------------------------- // --- // --- Embedded Metadata Update API for AJAX Editor support // --- // --------------------------------------------------------------------------


Field Summary
protected  AccessManager accessMan
           
protected  ServiceContext context
           
protected  DataManager dataManager
           
protected  GeonetContext gc
           
protected  UserSession session
           
protected  XmlSerializer xmlSerializer
           
 
Constructor Summary
AjaxEditUtils(ServiceContext context)
           
 
Method Summary
 boolean addAttribute(Dbms dbms, String id, String ref, String name, String currVersion)
          For Editing : adds an attribute from a metadata ([add] link).
 org.jdom.Element addElementEmbedded(Dbms dbms, UserSession session, String id, String ref, String name, String childName)
          For Ajax Editing : adds an element or an attribute to a metadata element ([add] link).
protected static String addNamespaceToFragment(String fragment)
          Adds missing namespace (ie.
protected  org.jdom.Element applyChangesEmbedded(Dbms dbms, String id, Map<String,String> changes, String currVersion)
          Apply a list of changes to the metadata record in current editing session.
 boolean deleteAttribute(Dbms dbms, String id, String ref, String name, String currVersion)
          For Editing : removes an attribute from a metadata ([del] link).
 org.jdom.Element deleteAttributeEmbedded(Dbms dbms, UserSession session, String id, String ref)
          Removes attribute in embedded mode.
 org.jdom.Element deleteElementEmbedded(Dbms dbms, UserSession session, String id, String ref, String parentRef)
          For Ajax Editing : removes an element from a metadata ([del] link).
 org.jdom.Element getMetadataEmbedded(ServiceContext srvContext, String id, boolean forEditing, boolean withValidationErrors)
          For Ajax Editing : gets Metadata from database and places it in session.
protected static org.jdom.Element getMetadataFromSession(UserSession session, String id)
          TODO javadoc.
protected static org.jdom.Element getOrAdd(org.jdom.Element parent, String name, org.jdom.Namespace ns)
          If no PT_FreeText element exists, creates a geonet:element with an empty ref.
 void preprocessUpdate(org.jdom.Element params, ServiceContext context)
          Performs common editor preprocessing tasks.
 void removeMetadataEmbedded(UserSession session, String id)
          For Ajax Editing : removes metadata from session.
 void swapElementEmbedded(Dbms dbms, UserSession session, String id, String ref, boolean down)
          For Ajax Editing : swap element with sibling ([up] and [down] links).
protected  void swapElements(org.jdom.Element el1, org.jdom.Element el2)
          Used for editing : swaps 2 elements.
 void updateContent(org.jdom.Element params)
           
 void updateContent(org.jdom.Element params, boolean validate)
          Updates metadata content.
 void updateContent(org.jdom.Element params, boolean validate, boolean embedded)
          TODO javadoc.
protected static boolean updatedLocalizedTextElement(org.jdom.Element md, String ref, String val, EditLib editLib)
          Adds a localised character string to an element.
 org.jdom.Element validateMetadataEmbedded(UserSession session, Dbms dbms, String id, String lang)
          For Ajax Editing : retrieves metadata from session and validates it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected ServiceContext context

dataManager

protected DataManager dataManager

xmlSerializer

protected XmlSerializer xmlSerializer

gc

protected GeonetContext gc

accessMan

protected AccessManager accessMan

session

protected UserSession session
Constructor Detail

AjaxEditUtils

public AjaxEditUtils(ServiceContext context)
Method Detail

applyChangesEmbedded

protected org.jdom.Element applyChangesEmbedded(Dbms dbms,
                                                String id,
                                                Map<String,String> changes,
                                                String currVersion)
                                         throws Exception
Apply a list of changes to the metadata record in current editing session.

The changes are a list of KVP. A key contains at least the element identifier from the meta-document. A key starting with an "X" should contain an XML fragment for the value.

The following KVP combinations are allowed: ElementName MUST contain "" instead of ":" for prefixed elements.

When using X key ElementValue could contains many XML fragments (eg. <gmd:keywords .../><gmd:keywords .../>) separated by XML_FRAGMENT_SEPARATOR. All those fragments are inserted to the last element of this type in its parent if ElementName is set. If not, the element with ElementId is replaced. If _replace suffix is used, then all elements having the same type than elementId are removed before insertion.

Parameters:
dbms -
id - Metadata internal identifier.
changes - List of changes to apply.
currVersion - Editing version which is checked against current editing version.
Returns:
The update metadata record
Throws:
Exception

getMetadataFromSession

protected static org.jdom.Element getMetadataFromSession(UserSession session,
                                                         String id)
TODO javadoc.

Parameters:
session -
id -
Returns:

removeMetadataEmbedded

public void removeMetadataEmbedded(UserSession session,
                                   String id)
For Ajax Editing : removes metadata from session.

Parameters:
session -
id -

getMetadataEmbedded

public org.jdom.Element getMetadataEmbedded(ServiceContext srvContext,
                                            String id,
                                            boolean forEditing,
                                            boolean withValidationErrors)
                                     throws Exception
For Ajax Editing : gets Metadata from database and places it in session.

Parameters:
srvContext -
id -
forEditing -
withValidationErrors -
Returns:
Throws:
Exception

addElementEmbedded

public org.jdom.Element addElementEmbedded(Dbms dbms,
                                           UserSession session,
                                           String id,
                                           String ref,
                                           String name,
                                           String childName)
                                    throws Exception
For Ajax Editing : adds an element or an attribute to a metadata element ([add] link).

Parameters:
dbms -
session -
id -
ref -
name -
childName -
Returns:
Throws:
Exception

deleteElementEmbedded

public org.jdom.Element deleteElementEmbedded(Dbms dbms,
                                              UserSession session,
                                              String id,
                                              String ref,
                                              String parentRef)
                                       throws Exception
For Ajax Editing : removes an element from a metadata ([del] link).

Parameters:
dbms -
session -
id -
ref -
parentRef -
Returns:
Throws:
Exception

deleteAttributeEmbedded

public org.jdom.Element deleteAttributeEmbedded(Dbms dbms,
                                                UserSession session,
                                                String id,
                                                String ref)
                                         throws Exception
Removes attribute in embedded mode.

Parameters:
dbms -
session -
id -
ref - Attribute identifier (eg. _169_uom).
Returns:
Throws:
Exception

swapElementEmbedded

public void swapElementEmbedded(Dbms dbms,
                                UserSession session,
                                String id,
                                String ref,
                                boolean down)
                         throws Exception
For Ajax Editing : swap element with sibling ([up] and [down] links).

Parameters:
dbms -
session -
id -
ref -
down -
Throws:
Exception

validateMetadataEmbedded

public org.jdom.Element validateMetadataEmbedded(UserSession session,
                                                 Dbms dbms,
                                                 String id,
                                                 String lang)
                                          throws Exception
For Ajax Editing : retrieves metadata from session and validates it.

Parameters:
session -
dbms -
id -
lang -
Returns:
Throws:
Exception

addAttribute

public boolean addAttribute(Dbms dbms,
                            String id,
                            String ref,
                            String name,
                            String currVersion)
                     throws Exception
For Editing : adds an attribute from a metadata ([add] link). FIXME: Modify and use within Ajax controls

Parameters:
dbms -
id -
ref -
name -
currVersion -
Returns:
Throws:
Exception

deleteAttribute

public boolean deleteAttribute(Dbms dbms,
                               String id,
                               String ref,
                               String name,
                               String currVersion)
                        throws Exception
For Editing : removes an attribute from a metadata ([del] link). FIXME: Modify and use within Ajax controls

Parameters:
dbms -
id -
ref -
name -
currVersion -
Returns:
Throws:
Exception

preprocessUpdate

public void preprocessUpdate(org.jdom.Element params,
                             ServiceContext context)
                      throws Exception
Performs common editor preprocessing tasks.

Parameters:
params -
context -
Throws:
Exception

updateContent

public void updateContent(org.jdom.Element params,
                          boolean validate)
                   throws Exception
Updates metadata content.

Parameters:
params -
validate -
Throws:
Exception

updateContent

public void updateContent(org.jdom.Element params,
                          boolean validate,
                          boolean embedded)
                   throws Exception
TODO javadoc.

Parameters:
params -
validate -
embedded -
Throws:
Exception

updatedLocalizedTextElement

protected static boolean updatedLocalizedTextElement(org.jdom.Element md,
                                                     String ref,
                                                     String val,
                                                     EditLib editLib)
Adds a localised character string to an element.

Parameters:
md - metadata record
ref - current ref of element. All _lang_AB_123 element will be processed.
val -
Returns:

addNamespaceToFragment

protected static String addNamespaceToFragment(String fragment)
Adds missing namespace (ie. GML) to XML inputs. It should be done by the client side but add a check in here.

Parameters:
fragment - The fragment to be checked and processed.
Returns:
The updated fragment.

getOrAdd

protected static org.jdom.Element getOrAdd(org.jdom.Element parent,
                                           String name,
                                           org.jdom.Namespace ns)
If no PT_FreeText element exists, creates a geonet:element with an empty ref.

Parameters:
parent -
name -
ns -
Returns:

updateContent

public void updateContent(org.jdom.Element params)
                   throws Exception
Parameters:
params -
Throws:
Exception

swapElements

protected void swapElements(org.jdom.Element el1,
                            org.jdom.Element el2)
                     throws Exception
Used for editing : swaps 2 elements.

Parameters:
el1 -
el2 -
Throws:
Exception


Copyright © 2003-2013. All Rights Reserved.