com.googlecode.fascinator.common
Class PythonUtils

java.lang.Object
  extended by com.googlecode.fascinator.common.PythonUtils

public class PythonUtils
extends java.lang.Object

The purpose of this class is to expose common Java classes and methods we use to Python scripts. Messaging is a duplicate of com.googlecode.fascinator.MessagingServices since Common library cannot acces it.

Author:
Greg Pendlebury

Constructor Summary
PythonUtils(JsonSimpleConfig config)
           
 
Method Summary
 void add(java.util.Map<java.lang.String,java.util.List<java.lang.String>> index, java.lang.String field, java.lang.String value)
          Add the provided key/value pair into the index.
 java.lang.String basicDisplayType(java.lang.String mimeType)
          A basic method for selecting common display templates from a given MIME type.
 AccessControlSchema getAccessSchema(java.lang.String plugin)
          Return an empty access control schema from the given plugin
 java.lang.String getDisplayMimeType(java.lang.String[] indexerFormats, DigitalObject object, java.lang.String preview)
          Find the MIME type to use at display time, giving first priority to the preview payload, then to the source payload.
 JsonSimple getJsonObject(java.io.InputStream in)
          Parse a JSON object from an inputstream
 org.ontoware.rdf2go.model.Model getRdfModel(java.io.InputStream rdfIn)
          Parse RDF data from an inputstream
 org.ontoware.rdf2go.model.Model getRdfModel(Payload payload)
          Parse RDF data stored in a payload
 java.io.InputStream getResource(java.lang.String path)
          Get a resource from one of the compiled classes on the classpath
 java.util.List<java.lang.String> getRolesWithAccess(java.lang.String recordId)
          Find the list of roles with access to the given object
 java.util.List<java.lang.String> getRolesWithAccess(java.lang.String recordId, java.lang.String plugin)
          Find the list of roles with access to the given object, but only looking at a single plugin.
 java.util.List<java.lang.String> getUsersWithAccess(java.lang.String recordId)
          Find the list of users with access to the given object
 java.util.List<java.lang.String> getUsersWithAccess(java.lang.String recordId, java.lang.String plugin)
          Find the list of users with access to the given object, but only looking at a single plugin.
 org.dom4j.Document getXmlDocument(java.io.InputStream xmlIn)
          Parse an XML document from an inputstream
 org.dom4j.Document getXmlDocument(Payload payload)
          Parse an XML document stored in a payload
 org.dom4j.Document getXmlDocument(java.lang.String xmlData)
          Parse an XML document from a string
 void registerNamespace(java.lang.String prefix, java.lang.String uri)
          Register a namespace for our XML parser
 void removeAccessSchema(AccessControlSchema schema, java.lang.String plugin)
          Remove an access control schema from a security plugin
 boolean sendMessage(java.lang.String messageQueue, java.lang.String message)
          Send a message to the given message queue
 void setAccessSchema(AccessControlSchema schema, java.lang.String plugin)
          Submit a new access control schema to a security plugin
 void shutdown()
          Try to closing any objects that require closure
 java.lang.String solrDocument(java.util.Map<java.lang.String,java.util.List<java.lang.String>> fields)
          Generate a Solr document from a map of provided key/value pairs.
 java.lang.String solrField(java.lang.String field, java.lang.String value)
          Generate an XML snippet representing a key/value pair in a Solr doc.
 void unregisterNamespace(java.lang.String prefix)
          UN-register a namespace for our XML parser
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PythonUtils

public PythonUtils(JsonSimpleConfig config)
            throws PluginException
Throws:
PluginException
Method Detail

shutdown

public void shutdown()
Try to closing any objects that require closure


sendMessage

public boolean sendMessage(java.lang.String messageQueue,
                           java.lang.String message)
Send a message to the given message queue

Parameters:
messageQueue - to connect to
message - to send
Returns:
boolean flag for success

getResource

public java.io.InputStream getResource(java.lang.String path)
Get a resource from one of the compiled classes on the classpath

Parameters:
path - To the requested resource
Returns:
InputStream to the resource

getXmlDocument

public org.dom4j.Document getXmlDocument(Payload payload)
Parse an XML document stored in a payload

Parameters:
payload - holding the document
Returns:
Document object after parsing

getXmlDocument

public org.dom4j.Document getXmlDocument(java.lang.String xmlData)
Parse an XML document from a string

Parameters:
xmlData - to parse
Returns:
Document object after parsing

getXmlDocument

public org.dom4j.Document getXmlDocument(java.io.InputStream xmlIn)
Parse an XML document from an inputstream

Parameters:
xmlIn, - the inputstream to read and parse
Returns:
Document object after parsing

registerNamespace

public void registerNamespace(java.lang.String prefix,
                              java.lang.String uri)
Register a namespace for our XML parser

Parameters:
prefix - of the namespace
uri - of the namespace

unregisterNamespace

public void unregisterNamespace(java.lang.String prefix)
UN-register a namespace for our XML parser

Parameters:
prefix - of the namespace

getJsonObject

public JsonSimple getJsonObject(java.io.InputStream in)
Parse a JSON object from an inputstream

Parameters:
in, - the inputstream to read and parse
Returns:
JsonConfigHelper object after parsing

getRdfModel

public org.ontoware.rdf2go.model.Model getRdfModel(Payload payload)
Parse RDF data stored in a payload

Parameters:
payload - containing the data
Returns:
Model object after parsing

getRdfModel

public org.ontoware.rdf2go.model.Model getRdfModel(java.io.InputStream rdfIn)
Parse RDF data from an inputstream

Parameters:
rdfIn, - the inputstream to read and parse
Returns:
Model object after parsing

getAccessSchema

public AccessControlSchema getAccessSchema(java.lang.String plugin)
Return an empty access control schema from the given plugin

Parameters:
plugin - to request the schema from
Returns:
AccessControlSchema returned by the plugin

setAccessSchema

public void setAccessSchema(AccessControlSchema schema,
                            java.lang.String plugin)
Submit a new access control schema to a security plugin

Parameters:
schema - to submit
plugin - to submit to

removeAccessSchema

public void removeAccessSchema(AccessControlSchema schema,
                               java.lang.String plugin)
Remove an access control schema from a security plugin

Parameters:
schema - to remove
plugin - to remove to

getRolesWithAccess

public java.util.List<java.lang.String> getRolesWithAccess(java.lang.String recordId)
Find the list of roles with access to the given object

Parameters:
recordId - the object to query
Returns:
List of roles with access to the object

getRolesWithAccess

public java.util.List<java.lang.String> getRolesWithAccess(java.lang.String recordId,
                                                           java.lang.String plugin)
Find the list of roles with access to the given object, but only looking at a single plugin.

Parameters:
recordId - the object to query
plugin - the plugin we are interested in
Returns:
List of roles with access to the object

getUsersWithAccess

public java.util.List<java.lang.String> getUsersWithAccess(java.lang.String recordId)
Find the list of users with access to the given object

Parameters:
recordId - the object to query
Returns:
List of users with access to the object

getUsersWithAccess

public java.util.List<java.lang.String> getUsersWithAccess(java.lang.String recordId,
                                                           java.lang.String plugin)
Find the list of users with access to the given object, but only looking at a single plugin.

Parameters:
recordId - the object to query
plugin - the plugin we are interested in
Returns:
List of users with access to the object

getDisplayMimeType

public java.lang.String getDisplayMimeType(java.lang.String[] indexerFormats,
                                           DigitalObject object,
                                           java.lang.String preview)
Find the MIME type to use at display time, giving first priority to the preview payload, then to the source payload.

Parameters:
indexerFormats - The list of types so far allocated by the rules script.
object - The object being indexed.
preview - The preview payload
Returns:
String The MIME type to be used at display time.

basicDisplayType

public java.lang.String basicDisplayType(java.lang.String mimeType)
A basic method for selecting common display templates from a given MIME type. This simple algorithm is suitable for most rules files.

Parameters:
preview - The MIME type.
Returns:
String The display type.

add

public void add(java.util.Map<java.lang.String,java.util.List<java.lang.String>> index,
                java.lang.String field,
                java.lang.String value)
Add the provided key/value pair into the index.

Parameters:
index - : Data structure to add data into
field - : The field name
value - : The value to store

solrDocument

public java.lang.String solrDocument(java.util.Map<java.lang.String,java.util.List<java.lang.String>> fields)
Generate a Solr document from a map of provided key/value pairs.

Parameters:
fields - : The lists of evaluated fields for the document
Returns:
String : The generated XML snippet

solrField

public java.lang.String solrField(java.lang.String field,
                                  java.lang.String value)
Generate an XML snippet representing a key/value pair in a Solr doc.

Parameters:
field - : The field
value - : The value
Returns:
String : The generated XML snippet


Copyright © 2009-2013. All Rights Reserved.