Professional Documents
Culture Documents
http://www.dspace.org/
TableofContents
1Introduction...........................................................................................................................3 2TheDSpaceEnvironment......................................................................................................4 2.1TheDSpacebuildprocess..............................................................................................4 2.1.1Overviewofinstallprocesses.................................................................................4 2.1.2Detailedtreatmentofinstallationprocess...............................................................5 2.2DeployingDSpace..........................................................................................................6 2.2.1Manuallyunpackingwarfiles.................................................................................6 2.2.2DeployingastheROOTapplication.......................................................................6 2.3Tomcatconfiguration......................................................................................................6 2.3.1server.xmlconfiguration.........................................................................................7 2.3.2web.xmlconfiguration.............................................................................................7 3EssentialDSpacecomponentuse..........................................................................................9 3.1Configurationmanagement.............................................................................................9 3.2Context...........................................................................................................................9 3.3Databaseaccess..........................................................................................................10 3.3.1Insertingrecords..................................................................................................10 3.3.2Updatingrecords..................................................................................................11 3.3.3Deletingrecords...................................................................................................11 3.4Servlets.........................................................................................................................12 3.4.1web.xmlconfiguration...........................................................................................12 3.4.2Creatingservlets..................................................................................................13 3.4.3CallingJSPs.........................................................................................................13 3.5JSPs.............................................................................................................................14 3.5.1Obtainingobjectsfromtheresponseobject.........................................................14 3.5.2InsertingjavacodeintotheJSP...........................................................................14 3.5.3JavaTagLibraries................................................................................................15 3.6JSPTags......................................................................................................................16 3.6.1dspacetags.tldconfiguration...............................................................................16 3.6.2Creatingcustomtags...........................................................................................17 3.7ContentManagementobjects.......................................................................................18 3.7.1Assemblingahierarchy........................................................................................18 3.7.2Locatingcontent...................................................................................................20 3.8Logging.........................................................................................................................21 3.9MetadataandMetadataSchemas................................................................................21 3.9.1Metadatainandoutofitems................................................................................21 3.9.2Workingwithmetadatavalues..............................................................................22 3.10Pluginmanagement....................................................................................................23 3.10.1Plugintypes........................................................................................................24 3.10.2ConfiguringPlugins............................................................................................25 3.10.3Reusableplugins................................................................................................27 3.10.4UsingthePluginManager...................................................................................27 3.10.5PluginDevelopment...........................................................................................28
1Introduction
Thisdocumentcoversthedetailsofwhatyouneedtoknowinordertowritecodeforthe DSpacesystem,eitheraspartofthecore,orproducinganinstallablecomponent.Fordetails oftheDSpacesystemarchitectureseealsothesystemdocumentation,aspackagedwiththe sourcecode. ItshouldbenotedthatthisdocumentationisnotacompleteguidetotheDSpacecodebase, asthisiscontinuallyinchange,andconstitutesmanyseparateparts.Insteaditattemptsto makeclearthemostcorecomponentsandfeatures.ItisalsointransitionbetweenDSpace 1.3.2and1.4,sincesomeoftheAPIisundergoingchangeduringthatupdate.
1.1Notationandfontsforthisdocument
NormalSansSerifFontThemainbodyofthetextofthisdocument ItalicSansSerifFontNotesthatshouldbepaidattentionto.
Fixed-Width FontExamplesofcommandsoritemsthatyoumightseeonthecomputer
screen.Forexample,directoryandfilenamesaswellasinstallationcommands.
Italic Fixed-Width FontTheuserthatyoushouldbeloggedinaswhenperformingtasks.
Youshouldalwaysbeloggedinastheusermostrecentlyspecifiedonthelefthand sideofthepageinthecurrentsection.
%
Indicatesthatthefollowingtextistobeenteredatthecommandlineinterface
2TheDSpaceEnvironment
2.1TheDSpacebuildprocess
TheDSpacebuildprocesscanbeenteredintoin3mainways:
% ant
ThiswilldoafullinstallationfromscratchoftheDSpacesystem,includingconfiguration, databasesettingsandsoforth.Theprocessisdescribedindetailbelow.
% ant update
A) B) C) D) E) F) G) H) I)
ant update:
A) B) C) D)
Soant
B:
makealltherelevantlivedirectories
dspace-source/bin/* --cp--> dspace/bin dspace-source/lib/* --cp--> dspace/lib
C:
D:
dspace-source/etc/dspace-web.xml --cp--> dspace-source/build @@dspace.dir@@ --replace--> ${dspace.dir}indspace-web.xml dspace-source/jsp/* --cp--> build/jsp dspace-source/jsp/local/* --cp--> build/jsp dspace-source/config/language-packs/Messages*.properties --cp--> build/classes (dspace-source/build/dspace-web.xml, dspace-source/build/jsp, dspace-source/lib, dspace-source/build/classes) --war--> dspace-source/build/dspace.war dspace-source/etc/oai-web.xml --cp--> dspace-source/build/oai-web.xml @@dspace.dir@@ --replace--> ${dspace.dir} inoai-web.xml (dspace-source/build/oai-web.xml, dspace-source/lib, dspace-source/build/classes) --war--> dspace-source/build/dspace-oai.war
E:
dspace-source/config/* --cp--> dspace/config dspace-source/etc/log4j.build.properties --cp--> dspace/config/log4j.properties
F:
G:
java org.dspace.administer.RegistryLoader -bitstream dspace/config/registries/bitstream-formats.xml java org.dspace.administer.RegistryLoader -dc dspace/config/registries/dublin-coretypes.xml
H:
I:
java org.dspace.browse.InitializeBrowse java org.dspace.search.DSIndexer
2.2DeployingDSpace
DeployingDSpaceisstraightforward.Allthatisrequiredistocopythedspace.warand dspace-oai.warfilesfromdspace-source/buildtotheservletcontainer'swebappsdirectory. TherestofthissectionassumesthattheservletcontainerisTomcat,andshouldbeadjusted asnecessaryforothercontainers. Oncethewarfilesareinthewebappsdirectory,restartingTomcatwillcausethemtobe unpacked.Toavoidtheriskofcaching,ifthewarshavebeenunpackedpreviouslyitissafeto deletetheexistingdirectories,astheywillbereplacedatrestart.Itissometimesalso necessarytodeletethecontentsoftheTomcatworkdirectory.
YouwillstillneedtorestartTomcatinorderfortheapplicationtobedeployed,
2.3Tomcatconfiguration
TomcatconfigurationforDSpaceisrelativelystraightforward.Themostimportantpartsare ensuringthatyouareabletodelivertheusercontentoverHTTPSwhereappropriate.
IfyouwishtoonlysecurethoseareasofDSpacewhichactivelyrequireauthentication,you candothisinstead:
<security-constraint> <web-resource-collection> <web-resource-name>Pages requiring HTTPS</web-resource-name> <url-pattern>/dspace-admin/*</url-pattern> <url-pattern>/mydspace</url-pattern> <url-pattern>/tools/*</url-pattern> <url-pattern>/profile</url-pattern> <url-pattern>/submit</url-pattern> <url-pattern>/subscribe</url-pattern> <url-pattern>/workspace</url-pattern> <url-pattern>/view-workspaceitem</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint>
ThisconfigurationisnotpartoftheDSpacecodebase,andthereforemustbemaintained locallybyreferencetothosepageswhichhavefiltermappingssetintheDSpaceweb.xmlfile.
3EssentialDSpacecomponentuse
ThissectiondescribessomeofthemostcommonandusefulobjectsandrelatedAPIs(and theirusage)fortheDSpacecodebase.
3.1Configurationmanagement
Managementofconfigurationoptionsindspace.cfgisdonethroughtheConfigurationManager class.TheconfigurationfileisloadedasaSystempropertyatserverstartup,andtherefore anychangestodspace.cfgrequireaservletcontainerrestarttotakeeffect.Whenusing DSpaceclassesfromthecommandlineorviaantitisnecessarytospecifythe dspace.configurationsystempropertysothattheconfigurationmaybeloadedbythat process. BasicuseoftheConfigurationManageristosimplycall:
String prop = ConfigurationManager.getProperty(property.name);
ThiswillreturnthepropertyasaStringvalue.YoumayalsoasktheConfigurationManagerto returndifferentdatatypes,usingothermethodcalls:
// integer value of the property int prop = ConfigurationManager.getIntProperty(property.name); // boolean value of the property boolean prop = ConfigurationManager.getBooleanProperty(property.name);
SeetheAPIdocumentationforafulllistofmethodsavailableonthisclass. Example:
// determine whether the item tag should display the licence information // webui.licence_bundle.show is a true or false value in dspace.cfg if (ConfigurationManager.getBooleanProperty("webui.licence_bundle.show")) { showLicence(); }
3.2Context
ThecontextobjectisthemostpervasiveofallobjectsintheDSpacecodebase.Itholds informationabouttheuser'sstate,aswellastheuser'sassignedtransactionsafedatabase connection.AlmosteverymethodcallintheDSpaceAPIrequiresacontext,sothatthe
Ifyouareworkinginsideaservlet,areadymadecontextwillbepassedtoyourdoDSGetand doDSPostmethods,sothereisnoneedtocreateone.
3.3Databaseaccess
DatabaseaccessismediatedbytheDatabaseManagerclass.Therearevariousoptionswith regardtohowtorequestdatabaseoperations.Youcan,forexample,constructtheSQLand passthewholequerystringtotheDatabaseManagerforexecution,butthisisnotthe recommendedmethod,asitwillcauseproblemsfordatabaseabstractionlater(e.g. supportingotherdatabases).MostoftheobjectsinDSpacehavetheirownfindmethods,so youshouldnotgenerallyneedtoperformSELECTqueriesonthedatabasedirectly,andshould avoiddoingsoespeciallyintheservlet/controllerlayer. Herewewilllookprimarilyatinserting,updatinganddeletingdatabaserecordsviathe DatabaseManager. Notethatalldatabaseinteractionsarecachedduringrequests,andwillallbeactionedagainst thedatabaseinatransactionsafeoperationwhentheuser'scontextiscompleted. Thecontextcanbeforcedtowriteallitsdatabasechangesandsoforthduringoperationthus:
context.commit();
Thecontextcanalsobeforcedtocompleteduringtheoperation,whichdoesthesameas commit(),butalsoclosesthecontextobjectsothatitcannotbeusedagain:
context.complete();
10
DatabaseManager.insert(Context, TableRow);
// left blank or the default value will be used. // mytable_seq sequence tr.setColumn("fieldA", Some value); tr.setColumn("fieldB", Some other value);
// field is the primary key, and will be automatically set based on the
Nowwecaninsertthisintothedatabasewith:
DatabaseManager.insert(context, tr);
3.3.2Updatingrecords Updatingarecordcanbedonebyusing:
DatabaseManager.update(Context, TableRow)
11
Acommonexamplewouldbe:
// obtain a row from the database via a SELECT query String query = SELECT * FROM mytable WHERE fieldA = 'A new value'; TableRow tr = DatabaseManager.querySingle(context, query); DatabaseManager.delete(context, mytable, tr.getIntColumn(id));
3.4Servlets
ServletsprovidethecontrollerlayerinJavaServletFramework(JSF)applications.Theyare invokedautomaticallybasedontheservletmappingsintheapplication'sweb.xmlfile.All DSpaceservletsshouldextendtheDSpaceServletclass,whichperformssomeadditional environmentworkbeforedeliveringcontroltothespecificservlet.
12
Notethatyoumayapplythesamefiltertomanyurlpatternsbyrepeatingthefiltermapping elementwithdifferenturlpatterns.
3.4.2Creatingservlets Thebasicstructureoftheservletisshownhere:
public class MyServlet extends DSpaceServlet { public void init() { }
protected void doDSGet( Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException { } protected void doDSPost( Context context, HttpServletRequest request, HttpServletResponse response) throws ServletException { } }
13
Onceyouhavethistemplatesetoutforyourservlet,youarefreetowritethecontrollercode asyouseefit.
3.5JSPs
JSPsprovidetheuserinterfacepagesforJSFapplications.Theyarecalledbythecontroller (servlet)torendertheoutputofanoperation;seetheprevioussectionforinformationonhow JSPsarecalledbytheservlet.
NowtheJSPcanusethesewhenpreparingthepagefortheuser.
14
15
<dspace:item item="<%= item %>" collections="<%= collections %>" style="<%= displayStyle %>" />
Youcanalsousethistagwithembeddedparameters,thus:
<fmt:message key="jsp.key.with.params"> <fmt:param>Param 1</fmt:param> <fmt:param>Param 2</fmt:param> </fmt:message>
Thiswilloutputthemessagewiththerelevantparametersinthekeyreplacedbythevaluesin theparameters.Theymaycome,forexample,fromitemmetadatafields.
3.6JSPTags
JSPtagsallowchunksoftheuserinterfacetobeencapsulatedinacompiledjavaclass,and invokedfromtheJSP(seethesectiononJSPsformoreinformationonhowtodothis).To createandimplementanewtagitneedstobeaddedtothedspace-tags.tldfileinWEB-INF, andextendtheTagSupportclass.
3.6.1dspacetags.tldconfiguration ToaddanewtagtotheDSpacesystem,youmustaddareferencetoitintheWEBINF/dspace-tags.tldfile.Atag'sentrylooksmuchlikethis:
<tag> <name>mytag</name> <tagclass>org.dspace.app.webui.jsptag.MyTag</tagclass> <info> This is my custom tag </info> <attribute> <name>param</name>
16
17
// get the output writer JspWriter out = pageContext.getOut(); // output a message out.println(here is my message);
3.7ContentManagementobjects
Thepackageorg.dspace.contentcontainsallofthecontentmanagementobjectsinuseby DSpace.Herewewilldiscussonlytheprimaryobjectsinwhatiseffectivelytheobject hierarchy:Community,Collection,Item,Bundle,Bitstream TheseclassesrepresentthegeneralstructureofthetheDSpacearchive.Communitiescan containothercommunitiesandcollections,collectionscancontainitems,itemscancontain bundleswhichinturncontainBitstreams.
3.7.1Assemblingahierarchy HereweprovidecodesegmentswhichassembleafullobjecthierarchyinDSpace.
// create a community with no parent Community community = Community.create(null, context); // add a description to the community community.setMetadata("short_description", "This is a short description"); // write the community to the database community.update(); // now we create a sub community Community subcommuntiy = Community.create(community, context); // this can also be written: // Community subcommunity = community.createSubcommunity(); subcomminty.setMetadata(short_description, This is another short description); subcommunity.update();
Oncewehavecreatedacommunityandasubcommunity,wecanaddcollectionstothem, thus:
// create a child collection directly Collection collection = community.createCollection();
18
// This can also be done alternatively: // Collection collection = Collection.create(context); // community.addCollection(collection); // add some metadata collection.setMetadata("short_description", "Yet another short description"); collection.update();
Mostcommonlyyouwillgettheitemfromtheworkspace,oryouwillbecreatingaworkspace item:
// create the item (the final argument of the first line indicates that // no template is used) WorkspaceItem wsi = WorkspaceItem.create(context, collection, false); Item item = wsi.getItem();
Toaddmetadatatoanitem,youcandothefollowing:
// add a metadata element value String schema =dc; String element=contributor; String qualifier=author; String lang = en; String value =Some Name; // dublin core schema // dc contributor element // dc author element // english language // the value of the metadata element
item.addMetadata(schema, element, qualifier, lang, value); // we could also set the value to be an array // String value = new String[2]; // value[0] = First author; // value[1] = Second author; // item.addMetadata(schema, element, qualifier, lang, value);
19
Toaddafiletotheitem,itisnecessarytocreateaBundleinwhichtoputtheBitstream.If thereisonlyonefiletobeadded,thenthereisashortcutfordoingthis:
// create a single bitstream from a given InputStream File file = new File(/some/file/path); InputStream is = new FileInputStream(file); item.createSingleBitstream(is);
Toperformthisoperationmoreformally,wemustcreatethebundlefortheitem,andcreate bitstreamsforitasfollows:
// create a bundle with the name BUNDLE (usually you would use ORIGINAL) Bundle bundle = item.createBundle(BUNDLE); // you can also write this: // Bundle bundle = Bundle.create(context); // bundle.setName(BUNDLE); // item.addBundle(bundle); // now create the InputStream, and create a bitstream from it: File file = new File(/some/file/path); InputStream is = new FileInputStream(file); Bitstream bitstream = bundle.createBitstream(context, is); // you can also write this // Bitstream bitstream = Bitstream.create(context, is); // bundle.addBitstream(bitstream);
Someofthemorecomplexobjectssupportfindoperationsonotherconditions.Forexample:
20
// locate an item by it's submitter ItemIterator ii = Item.findBySubmitter(context, eperson); // locate which collections the user is authorised to do the given action with Collection[] collections = Collection.findAuthorized(context, community, action); // locate all of the top level communities Community[] communities = Community.findAllTop(context);
3.8Logging
DSpaceusesthelog4jsystemtomanageit'sloggingoutput.Toenablealoggerfora particularclass,declareastaticmembervariablecontainingthelogger:
private static Logger log = Logger.getLogger(MyClass.class);
Nowlogrecordscanbewrittenbysimplycalling,forexample:
log.info(LogManager.getHeader(context, my message));
Youmayalsousedebug,warn,errorandfatalmethodcalls.
3.9MetadataandMetadataSchemas
ThemetadatasysteminDSpaceisinaperiodoftransition.Itismovingfrombeinggeared towardQualifiedDublinCorestylemetadatatobeingmoregenericinitstreatmentofall schemaswhichcanbeexpressedasanelement.qualifierpair.Thereforethereare metadatahandlingobjectswhicharegeneric,andmetadatavaluehandlingobjectswhichare labelledasbeingDCspecific,althoughwhichwillbeofusetomostmetadataschemas.
21
item.addMetadata(schema, element, qualifier, lang, value); // we could also set the value to be an array // String value = new String[2]; // value[0] = First author; // value[1] = Second author; // item.addDC(element, qualifier, lang, value); // String schema =dc; // dublin core schema
Thevaluesofeachoftheargumentscanbeobtainedfromanumberofconstantslocations. TheschemashouldbeobtainedfromtheMetadataSchemaclass:
MetadataSchema.DC_SCHEMA
Theelement,qualifierandlangcanbefilledwiththewildcardtakenfromtheItemclass:
Item.ANY
metadatavalue.YoucanaskDCValuefortheschema,element,qualifier,languageandvalue attributesthus:
22
String schema = DCValue.schema String element = DCValue.element String qualifier = DCValue.qualifier String lang = DCValue.language String value = DCValue.value
UsingDCLanguage:
// get just one value DCValue[] langVals = item.getMetadata(dc, title, alternative, Item.ANY); DCValue dc = langVals[0]; // create a language object, and use it to print to stdout the display // name of the language String lang = dc.lang; DCLanguage language = new DCLanguage(lang); System.out.print(language.getDisplayName());
UsingDCPersonName:
// get just one value DCValue[] authVals = item.getMetadata(dc, contributor, author, Item.ANY); DCValue dcAuth = authVals[0]; // create a DCPersonName object and use it to print the name to stdout String auth = dcAuth.value; DCPersonName name = new DCPersonName(auth); System.out.print(First: + name.getFirstNames() + Last: + name.getLastName());
23
// create a DCPersonName and use it to prepare a metadata value String fn = Richard; String ln = Jones; DCPersonName name = new DCPersonName(fn, ln); String value = name.toString();
3.10Pluginmanagement
Note:muchofthetextherecomesfromLarryStone'sintroductiontothePluginManageron http://wiki.dspace.org/PluginManager.Allcreditforthissectionthereforegoestohim,and failurestorepresentitcorrectlyhereareattributedtotheauthor. ThePluginManagerallowsforcomponentsorpluginstobecreatedandmanagedatruntime. Apluginimplementsoneormoredefinedinterfaces,sothatitcanbeloadedundervarious conditionsbytheimplementingcode.Theimplementingcodethenonlyneedstoknowthe interfaceAPItobeabletodealdirectlywiththepluginimplementation. Asaninitialexample,considerasimplesiteauthenticationmechanism,wherethecodedoes notknowexactlyhowthelocalDSpaceinstancewouldwanttoimplementauthentication.The configuration(whichwillbeexplainedinfullshortly)lookslikethis:
plugin.single.org.dspace.app.webui.SiteAuthenticator = org.myuniversity.MyAuthenticator
Thiscanthenbeinstantiatedandusedasfollows:
SiteAuthenticator siteAuth = (SiteAuthenticator) PluginManager.getSinglePlugin(SiteAuthenticator.class); siteAuth.startAuthentication(context, request, response);
3.10.1Plugintypes Therearethreedifferenttypesofpluginthatcanbedefined.
SingletonPlugins:
Thereisonlyoneimplementationclassfortheplugin,whichisindicatedintheconfiguration. Thistypeofpluginchoosesanimplementationofaservicefortheentiresystemat 24
configurationtime.Yourapplicationjustfetchesthepluginforthatinterfaceandgetsthe configuredinchoice.Theexampleabovewasofthiskind.
SequencePlugins
NamedPlugins
Useanamedpluginwhentheapplicationhastochooseonepluginimplementationoutof manyavailableones.Eachimplementationisboundtooneormorenames(symbolic identifiers)intheconfiguration. Thenameisjustastringtobeassociatedwiththecombinationofimplementationclassand interface.Itmaycontainanycharactersexceptforcomma(,)andequals(=).Itmaycontain embeddedspaces.Commaisaspecialcharacterusedtoseparatenamesintheconfiguration entry. Namesmustbeuniquewithinaninterface:Nopluginclassesimplementingthesameinterface mayhavethesamename. Thinkofpluginnamesasacontrolledvocabulary:foragivenplugininterface,thereisasetof namesforwhichpluginscanbefound.ThedesignerofaNamedPlugininterfaceis responsiblefordecidingwhatthenamemeansandhowtoderiveit;forexample,namesof metadatacrosswalkpluginsmaydescribethetargetmetadataformat.
3.10.2ConfiguringPlugins Pluginconfigurationsaresuppliedinthedspace.cfgfile.
SingletonPlugins:
TotellthePluginManageraboutasingletonplugin,usethefollowingconfigurationline:
plugin.single.<interface> = <classname>
Forexample,thisconfigurestheclassorg.dspace.app.webui.SimpleAuthenticatorasthe pluginforinterfaceorg.dspace.app.webui.SiteAuthenticator:
25
plugin.single.org.dspace.app.webui.SiteAuthenticator = org.dspace.app.webui.SimpleAuthenticator
SequencePlugins
Todefinethesequenceofplugins,usethefollowingconfigurationline:
plugin.sequence.<interface> = <classname> [, <classname> ...]
NamedPlugins
ThisnextpluginisboundtothenamesAdobe
26
Ifthepluginisgoingtodefineitsownname,thenitmustbedeclaredaselfnamedplugin.This canbedoneusingthefollowingconfigurationline:
plugin.selfnamed.<interface> = <classname>[, <classname>...]
Inthefollowingexample,configurationoptonsaredefinedforusingthe XsltDisseminationCrosswalkandthisplugindefinesforitselfthetwonamesMODSand
DublinCore
Forexample,thismarksthePDFpluginfromaboveasnonreusable:
plugin.reusable.org.dspace.app.mediafilter.PDFFilter = false
Thisconfigurationcanbeomittedentirelyifyouarehappyfortheplugintobereused.
3.10.4UsingthePluginManager
SingletonPlugin
27
SequencePlugin
Withthepreviousexampleofhowtoconfigurethestackableauthentication(seesection 3.10.2),thePluginManagercanbeimplemented(inthemostbasicform)asfollows:
AuthenticationMethod stack[] = PluginManager.getPluginSequence(AuthenticationMethod.class); // return on first success for (int i = 0; i < stack.length; ++i) { auth = stack[i].authenticate( context, username, password, realm, request); if (auth == AuthenticationMethod.SUCCESS) { break; } } // next do the relevant authorisation handling, depending on the value // of the variable auth...
Foracompletetreatmentofhowtousethisparticularplugin,seethecodein
org.dspace.eperson.AuthenticationManager
NamedPlugin
FromtheaboveconfigurationexampledefiningnamedpluginsfortheMediaFilter(see section3.10.2),wecanimplementthisasfollows:
MediaFilter myFilter = (MediaFilter) PluginManager.getNamedPlugin( MediaFilter.class, myBitstream.getFormat().getShortDescription());
28
implementit.Inthissectionwewilllookbrieflyatthecodetodefinesomeofthepluginsfor thecommonoperationsthatwehaveusedpreviously.
AuthenticationMethod
ThisisabasicoutlineoftheAuthenticationMethodinterface.SeetheAPIdocumentationfor morecompletedetails:
public interface AuthenticationMethod { public static final int SUCCESS = 1; public static final int BAD_CREDENTIALS = 2; public static final int CERT_REQUIRED = 3; public static final int NO_SUCH_USER = 4; public static final int BAD_ARGS = 5; public boolean canSelfRegister( Context context, HttpServletRequest request, String username) throws SQLException; public void initEPerson( Context context, HttpServletRequest request, EPerson eperson) throws SQLException; public boolean allowSetPassword( Context context, HttpServletRequest request, String username) throws SQLException; public boolean isImplicit(); public int[] getSpecialGroups(Context context, HttpServletRequest request); public int authenticate( Context context, String username, String password, String realm, HttpServletRequest request) throws SQLException; public String loginPageURL( Context context, HttpServletRequest request, HttpServletResponse response); public String loginPageTitle(Context context); }
ThePasswordAuthenticationprocess,thensimplyimplementsthisinterface:
public class PasswordAuthentication implements AuthenticationMethod { // implementation }
29
ThisisthenusedintheAuthenticationManagerthus:
private static AuthenticationMethod methodStack[] = (AuthenticationMethod[]) PluginManager.getPluginSequence(AuthenticationMethod.class);
MediaFilter
TheMediaFilterisnotaninterface,butanabstractclass.Therefore,insteadofimplementing asinthepreviousexample,newmediafiltersmustextendinstead:
public abstract class MediaFilter { /* methods for implementation by extending class */ public abstract String getFilteredName(String sourceName); public abstract String getBundleName(); public abstract String getFormatString(); public abstract String getDescription(); public abstract InputStream getDestinationStream(InputStream source) throws Exception; /* implemented method */ public boolean processBitstream(Context c, Item item, Bitstream source) throws Exception { // implementation } }
TheconcretesubclassforfilteringJPEGs,then,wouldbe:
public class JPEGFilter extends MediaFilter { // implementation of all but processBitstream() }
ThisistheimplementedintheMediaFilterManagerthus(withsimplification):
MediaFilter myFilter = (MediaFilter) PluginManager.getNamedPlugin( MediaFilter.class, myBitstream.getFormat().getShortDescription()); if (myFilter != null) { if (myFilter.processBitstream(c, myItem, myBitstream)) { myItem.update();
30
} }
31