edu.sampleu.bookstore.document.attribs
Class XPathSearchableAttribute

java.lang.Object
  extended by edu.sampleu.bookstore.document.attribs.XPathSearchableAttribute
All Implemented Interfaces:
SearchableAttribute
Direct Known Subclasses:
BookPriceSearchableAttribute, BookPublicationDateSearchableAttribute, BookRatingSearchableAttribute, BookTitleSearchableAttribute, BookTypeSearchableAttribute

public abstract class XPathSearchableAttribute
extends Object
implements SearchableAttribute

Base class for simple attributes which extract values from document content via an xpath expression. Compare to StandardGenericXMLSearchableAttribute. In most cases it's simplest to just define an SGXSA. This class exists expressly to aid testing non-SGXSA attributes, and illustrates performing proper validation.


Field Summary
protected  String dataType
           
protected  String key
           
protected  org.apache.log4j.Logger log
           
protected  String title
           
protected  String xpathExpression
           
 
Constructor Summary
protected XPathSearchableAttribute(String key, String dataType, String xpathExpression)
           
protected XPathSearchableAttribute(String key, String dataType, String xpathExpression, String title)
           
 
Method Summary
protected static DocumentAttribute createAttribute(String name, String value, String dataTypeValue)
          Creates an DocumentAttribute of the specified type
protected  RemotableAttributeField.Builder decorateRemotableAttributeField(RemotableAttributeField.Builder raf)
          Template method for subclasses to customize the remotableattributefield
 List<DocumentAttribute> extractDocumentAttributes(ExtensionDefinition extensionDefinition, DocumentWithContent documentWithContent)
          Extracts and returns document attributes for the given document in order to allow indexing of those values for association with the document and use in document searches.
 String generateSearchContent(ExtensionDefinition extensionDefinition, String documentTypeName, WorkflowAttributeDefinition attributeDefinition)
          Allows for generation of custom XML for this searchable attribute.
 List<RemotableAttributeField> getSearchFields(ExtensionDefinition extensionDefinition, String documentTypeName)
          Returns a list of RemotableAttributeField objects which define which searchable attribute criteria fields should be included in the criteria section of the document search user interface for this searchable attribute.
 List<RemotableAttributeError> validateDocumentAttributeCriteria(ExtensionDefinition extensionDefinition, DocumentSearchCriteria documentSearchCriteria)
          Performs custom validation of document attribute values that come from this searchable attribute whenever a document search is performed against a document type which uses this searchable attribute.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.log4j.Logger log

key

protected final String key

title

protected final String title

xpathExpression

protected final String xpathExpression

dataType

protected final String dataType
Constructor Detail

XPathSearchableAttribute

protected XPathSearchableAttribute(String key,
                                   String dataType,
                                   String xpathExpression)

XPathSearchableAttribute

protected XPathSearchableAttribute(String key,
                                   String dataType,
                                   String xpathExpression,
                                   String title)
Method Detail

generateSearchContent

public String generateSearchContent(ExtensionDefinition extensionDefinition,
                                    String documentTypeName,
                                    WorkflowAttributeDefinition attributeDefinition)
Description copied from interface: SearchableAttribute
Allows for generation of custom XML for this searchable attribute. The trigger for invocation of custom XML generation happens via the workflow API whenever a document action is taken and a request is submitted to update document XML based on searchable attribute definitions (see DocumentContentUpdate). This XML is ultimately included as part of the document's content.

It is intended that this XML can be used by the extractDocumentAttributes method in order to pull values out for indexing, though this method is free to use any source available to it for extracting data for indexing alongside a document.

A null or blank value may be returned from this method to indicate that no XML was generated.

Specified by:
generateSearchContent in interface SearchableAttribute
Parameters:
extensionDefinition - the extension definition which was used to locate and load this searchable attribute implementation
documentTypeName - the name of the document type for which this method is being invoked
attributeDefinition - contains parameters and properties that can be used to inform generation of the XML, these are supplied by the user of the workflow API when the document's searchable XML content is requested to be updated
Returns:
a String containing valid XML that should be included in the searchable attribute XML section of the document's XML content

extractDocumentAttributes

public List<DocumentAttribute> extractDocumentAttributes(ExtensionDefinition extensionDefinition,
                                                         DocumentWithContent documentWithContent)
Description copied from interface: SearchableAttribute
Extracts and returns document attributes for the given document in order to allow indexing of those values for association with the document and use in document searches. The document and it's XML content is passed to this method as that is a common source of data for indexing purposes, though implementations are free to pull data for indexing from any readily accessible source.

There are a finite set of DocumentAttribute implementations which can be returned and interpreted correctly. Client application's should not create custom extensions of the DocumentAttribute abstract class but should preferably use the DocumentAttributeFactory to construct strongly-typed document attribute instances for indexing.

Specified by:
extractDocumentAttributes in interface SearchableAttribute
Parameters:
extensionDefinition - the extension definition which was used to locate and load this searchable attribute implementation
documentWithContent - the workflow document and it's XML content
Returns:
a list of document attribute values that should be indexed for the given document, or a null or empty list if no attributes should be indexed
See Also:
DocumentAttributeFactory

createAttribute

protected static DocumentAttribute createAttribute(String name,
                                                   String value,
                                                   String dataTypeValue)
                                            throws ParseException
Creates an DocumentAttribute of the specified type

Throws:
ParseException

getSearchFields

public List<RemotableAttributeField> getSearchFields(ExtensionDefinition extensionDefinition,
                                                     String documentTypeName)
Description copied from interface: SearchableAttribute
Returns a list of RemotableAttributeField objects which define which searchable attribute criteria fields should be included in the criteria section of the document search user interface for this searchable attribute.

Specified by:
getSearchFields in interface SearchableAttribute
Parameters:
extensionDefinition - the extension definition which was used to locate and load this searchable attribute implementation
documentTypeName - the name of the document type for which this method is being invoked
Returns:
a list of remotable attribute fields which define the search fields that should be included in the document search criteria, or a null or empty list if no criteria should be included for this searchable attribute

decorateRemotableAttributeField

protected RemotableAttributeField.Builder decorateRemotableAttributeField(RemotableAttributeField.Builder raf)
Template method for subclasses to customize the remotableattributefield

Returns:
modified or new RemotableAttributeField.Builder

validateDocumentAttributeCriteria

public List<RemotableAttributeError> validateDocumentAttributeCriteria(ExtensionDefinition extensionDefinition,
                                                                       DocumentSearchCriteria documentSearchCriteria)
Description copied from interface: SearchableAttribute
Performs custom validation of document attribute values that come from this searchable attribute whenever a document search is performed against a document type which uses this searchable attribute. This hook allows for any desired validation of this searchable attributes custom document attribute values to be performed prior to the execution of the document search.

The entire DocumentSearchCriteria is passed to this method, though it's intended that implementing code will pull out the document attribute values on the criteria which are managed by this searchable attribute and perform any desired validation. However, there are certainly no restrictions on this method that would prevent it from performing validations outside of this scope and in relation to other portions of the criteria, though this is certainly not the intent of this validation hook.

Note that this method is invoked when performing a document search from the user interface as well as via the WorkflowDocumentService api.

Specified by:
validateDocumentAttributeCriteria in interface SearchableAttribute
Parameters:
extensionDefinition - the extension definition which was used to locate and load this searchable attribute implementation
documentSearchCriteria - the criteria that was submitted to the document search and against which validation is requested
Returns:
a list of attribute errors containing and validation failure errors messages for the relevant document attributes, if this returns a null or empty list it means that validation was successful


Copyright © 2005-2014 The Kuali Foundation. All Rights Reserved.