org.w3c.rdfpic.core
Class RdfPicCore

java.lang.Object
  |
  +--org.w3c.rdfpic.core.RdfPicCore

public class RdfPicCore
extends java.lang.Object

RdfPicCore provides a unifying shell around the various IO issues, schemas, and the like, while attempting not to implement any UI specific features. Ideally, it should only take a replacement of Main and an equivalent of SimpleUI to make a utility that could work off the command line, for instance. The core maintains a list of files, and allows the UI to select any given file. Loading automatically occurs when a file is selected. All rdf data is sent to an RdfDataProvider, which is also responsible for providing rdf data when saving. A number of other functions provide the capability to import/extract the raw comment from the image file, or save/load the current rdf data to a text file.

The core also maintains a list of Schemas. Each schema contains information about its name and URI, and a list of predicates and information about those. this means that the rdf data generated is very simple - no complex tree structures, loops, bags or like are produced. Information about the schema's is revealed through certain functions. Schema's, like files, can be dynamically loaded at runtime.


Field Summary
(package private)  RdfDataProvider dataSource
          an object responsible for keeping track of the rdf data.
(package private)  java.lang.String errMsg
          contains an explanation of the current error, or null if there isn't any.
(package private)  org.w3c.rdf.model.Model extras
          stores an rdf-model of the statements that weren't understood.
(package private)  ImgMetaHandler handler
          The handler is responsible for embedding text data into an image.
(package private)  java.util.LinkedList imgListeners
          Lists of objects to notify when an event occurs.
(package private)  int index
          the index of the active file (in picV).
(package private)  java.lang.String langcode
          The code of the languge used in the rdf Description.
(package private)  ImageLoader loadThread
          an object that deals with placing the loading activity into another thread.
(package private)  URLVector picV
          the list of files.
(package private)  SchemaFileDrv schemadrv
          an object responsible for parsing and serialzing a schema.
(package private)  boolean[] schemaEnabled
          stores whether a schema is active or not.
(package private)  java.util.LinkedList schemaListeners
          Lists of objects to notify when an event occurs.
(package private)  RdfSchema[] schemas
          all loaded schemas.
 
Constructor Summary
RdfPicCore(SchemaFileDrv schemadrv, java.net.URL[] schemaURLs, java.net.URL[] picURLs)
          Initializes the core with the given schemas, pictures, and schema driver.
 
Method Summary
 void addImgListener(ImgListener il)
           
 void addSchema(java.net.URL schemaURL)
          Adds a schema to the schema list's end.
 void addSchemaListener(SchemaListener sl)
           
private static void addTo(org.w3c.rdf.model.Model model, java.lang.String sub, java.lang.String pred, java.lang.String val)
           
 void addURL(java.net.URL pic)
          Adds a URL of a picture to the end of the file list.
(package private)  org.w3c.rdf.model.Model attachLangInfo(org.w3c.rdf.model.Model model)
           
 boolean builtinSchema(int sI)
          Sometimes, you want special functionality in a schema.
 boolean canWrite()
          Returns whether the file is writable or not - falsely returns true when in doubt (esp.
 java.lang.String defaultVal(int sI, int pI)
           
private  void die(java.lang.Throwable exp, java.lang.String msg)
           
 void disableSchema(int i)
          Disables a schema.
 void enableSchema(int i)
          Enables a schema, meaning the rdf-info contained in it will be output in a save operation.
 void exportRDF(java.io.File file)
          Exports the RDF to a text file.
 void extractRaw(java.io.File file)
          Extracts the raw contents of the image's comment into the given file.
 java.lang.String fileName(int i)
          Returns the filename of the ith file in the file list, or "" if the index is out of range.
(package private)  void finishJump()
           
(package private)  org.w3c.rdf.model.Model getData(java.lang.String subject)
          Returns a Model of the data according to RdfDataProducer.
 java.awt.Image getImg()
          Returns the image of the current file.
 int getImgFileSize()
          Retrieves the size of the current file.
 int getImgHeight()
          Retrieves the height of the current image.
 int getImgWidth()
          Retrieves the width of the current image.
 java.lang.String getLang()
          gets the language (of the rdf) of the active file.
 int getPos()
          Returns the currently active file's index.
 java.net.URL getURL()
          Returns the URL of the currently active file.
 void importRDF(java.io.File file)
          Imports RDF from a text file.
 void insertRaw(java.io.File file)
          Inserts the unaltered contents of the given file into the image's comment.
 boolean isEnabled(int schemaIndex)
          Returns whether or not the schema with the given index is enabled.
 void jumpRel(int i)
          Go to the file i further than the current file.
 void jumpTo(int i)
          Selects and makes active a file with the given index.
 void loadData()
          Loads the rdf embedded in the image.
private  void loadData(java.io.Reader reader)
           
 int numFiles()
           
 int numPredicates(int i)
           
 int numSchemas()
           
 java.lang.String predExpl(int sI, int pI)
          An Explanation of the purpose of the predicate.
 java.lang.String predicateName(int sI, int pI)
           
 void removeURL(int i)
          Removes the URL of the picture at the given index from the file list.
 void saveData()
          Saves the rdf currently available to the image.
 java.lang.String schemaName(int i)
           
 void setLang(java.lang.String lang)
          sets the language (of the rdf) of the active file.
 void setRdfDataProvider(RdfDataProvider rdp)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

errMsg

java.lang.String errMsg
contains an explanation of the current error, or null if there isn't any.

schemas

RdfSchema[] schemas
all loaded schemas.

schemadrv

SchemaFileDrv schemadrv
an object responsible for parsing and serialzing a schema.

schemaEnabled

boolean[] schemaEnabled
stores whether a schema is active or not. Inactive schemas are not saved into the output.

dataSource

RdfDataProvider dataSource
an object responsible for keeping track of the rdf data.

schemaListeners

java.util.LinkedList schemaListeners
Lists of objects to notify when an event occurs.

imgListeners

java.util.LinkedList imgListeners
Lists of objects to notify when an event occurs.

picV

URLVector picV
the list of files.

handler

ImgMetaHandler handler
The handler is responsible for embedding text data into an image.

loadThread

ImageLoader loadThread
an object that deals with placing the loading activity into another thread.

index

int index
the index of the active file (in picV).

extras

org.w3c.rdf.model.Model extras
stores an rdf-model of the statements that weren't understood. They are inserted into the output unchanged.

langcode

java.lang.String langcode
The code of the languge used in the rdf Description.
Constructor Detail

RdfPicCore

public RdfPicCore(SchemaFileDrv schemadrv,
                  java.net.URL[] schemaURLs,
                  java.net.URL[] picURLs)
           throws SetupIncompleteException,
                  java.io.IOException
Initializes the core with the given schemas, pictures, and schema driver.
Method Detail

die

private void die(java.lang.Throwable exp,
                 java.lang.String msg)

setRdfDataProvider

public void setRdfDataProvider(RdfDataProvider rdp)

addSchemaListener

public void addSchemaListener(SchemaListener sl)

addImgListener

public void addImgListener(ImgListener il)

isEnabled

public boolean isEnabled(int schemaIndex)
Returns whether or not the schema with the given index is enabled.

numSchemas

public int numSchemas()

schemaName

public java.lang.String schemaName(int i)

numPredicates

public int numPredicates(int i)

predicateName

public java.lang.String predicateName(int sI,
                                      int pI)

defaultVal

public java.lang.String defaultVal(int sI,
                                   int pI)

builtinSchema

public boolean builtinSchema(int sI)
Sometimes, you want special functionality in a schema. A schema can be marked "builtin" which has no impact on the rdf, but allows special decisions to be made on its basis.

predExpl

public java.lang.String predExpl(int sI,
                                 int pI)
An Explanation of the purpose of the predicate.

getPos

public int getPos()
Returns the currently active file's index.

numFiles

public int numFiles()

getLang

public java.lang.String getLang()
gets the language (of the rdf) of the active file.

setLang

public void setLang(java.lang.String lang)
sets the language (of the rdf) of the active file.

fileName

public java.lang.String fileName(int i)
Returns the filename of the ith file in the file list, or "" if the index is out of range.

jumpRel

public void jumpRel(int i)
Go to the file i further than the current file. For example, jumpTo(-1) would go to the previous file.

getURL

public java.net.URL getURL()
Returns the URL of the currently active file.

addSchema

public void addSchema(java.net.URL schemaURL)
               throws java.io.IOException
Adds a schema to the schema list's end. Schema's cannot be removed again, but disabled, if necessary.

enableSchema

public void enableSchema(int i)
Enables a schema, meaning the rdf-info contained in it will be output in a save operation.

disableSchema

public void disableSchema(int i)
Disables a schema. That schema's contents will not be included in any output.

exportRDF

public void exportRDF(java.io.File file)
               throws java.io.IOException
Exports the RDF to a text file.

importRDF

public void importRDF(java.io.File file)
               throws RdfPicError,
                      java.io.IOException
Imports RDF from a text file.

canWrite

public boolean canWrite()
Returns whether the file is writable or not - falsely returns true when in doubt (esp. over HTTP).

extractRaw

public void extractRaw(java.io.File file)
                throws RdfPicError,
                       java.io.IOException
Extracts the raw contents of the image's comment into the given file.

insertRaw

public void insertRaw(java.io.File file)
               throws RdfPicError,
                      java.io.IOException
Inserts the unaltered contents of the given file into the image's comment.

addURL

public void addURL(java.net.URL pic)
Adds a URL of a picture to the end of the file list.

removeURL

public void removeURL(int i)
Removes the URL of the picture at the given index from the file list. Has no effect if the index is out of range, or the index of the active file.

jumpTo

public void jumpTo(int i)
Selects and makes active a file with the given index.

getImg

public java.awt.Image getImg()
                      throws RdfPicError
Returns the image of the current file.
Returns:
the image (java.awt.Image), or null if none loaded.
Throws:
RdfPicError - when called while an image is being loaded.

getImgFileSize

public int getImgFileSize()
                   throws PHException,
                          RdfPicError
Retrieves the size of the current file.
Returns:
the size in bytes
Throws:
RdfPicError - when called while an image is being loaded.
PHException - when the current image couldn't be successfully read (for instance when none is loaded).

getImgWidth

public int getImgWidth()
                throws PHException,
                       RdfPicError
Retrieves the width of the current image.
Returns:
the width in pixels, -1 if unknown
Throws:
RdfPicError - when called while an image is being loaded.
PHException - when the current image couldn't be successfully read (for instance when none is loaded).

getImgHeight

public int getImgHeight()
                 throws PHException,
                        RdfPicError
Retrieves the height of the current image.
Returns:
the height in pixels, -1 if unknown
Throws:
RdfPicError - when called while an image is being loaded.
PHException - when the current image couldn't be successfully read (for instance when none is loaded).

finishJump

void finishJump()

saveData

public void saveData()
              throws RdfPicError,
                     java.io.IOException
Saves the rdf currently available to the image.

loadData

public void loadData()
              throws RdfPicError,
                     java.io.IOException
Loads the rdf embedded in the image.

loadData

private void loadData(java.io.Reader reader)
               throws RdfPicError

getData

org.w3c.rdf.model.Model getData(java.lang.String subject)
                          throws org.w3c.rdf.model.ModelException
Returns a Model of the data according to RdfDataProducer.

addTo

private static void addTo(org.w3c.rdf.model.Model model,
                          java.lang.String sub,
                          java.lang.String pred,
                          java.lang.String val)
                   throws org.w3c.rdf.model.ModelException

attachLangInfo

org.w3c.rdf.model.Model attachLangInfo(org.w3c.rdf.model.Model model)
                                 throws org.w3c.rdf.model.ModelException