From: zapata Date: Sun, 11 Jan 2004 20:35:50 +0000 (+0000) Subject: - XML parser framework rewrite X-Git-Tag: LATEST_MERGED_1_1~191 X-Git-Url: http://erislabs.net/gitweb/?p=mir.git;a=commitdiff_plain;h=04bf29aa1f1abf43e96d0272b2a286f0c1f9fea8 - XML parser framework rewrite - HTML parser added - TAL template engine maintenance --- diff --git a/bundles/admin_en.properties b/bundles/admin_en.properties index 52a44282..1e0ef2b6 100755 --- a/bundles/admin_en.properties +++ b/bundles/admin_en.properties @@ -1,6 +1,6 @@ ########## admin ########## # language: english -# $Id: admin_en.properties,v 1.48.2.20 2003/12/21 13:32:01 zapata Exp $ +# $Id: admin_en.properties,v 1.48.2.21 2004/01/11 20:35:50 zapata Exp $ languagename=English @@ -45,6 +45,8 @@ no_matches_found=No matching entries! list.next=next list.previous=previous +system.status = Status: +system.loggedin = Logged in: # media - used by image, audio, video and other media media.urls = Urls diff --git a/bundles/admin_es.properties b/bundles/admin_es.properties index 6f7e8273..54b446ed 100755 --- a/bundles/admin_es.properties +++ b/bundles/admin_es.properties @@ -1,6 +1,6 @@ ########## admin ########## # language: spanish -# $Id: admin_es.properties,v 1.29.2.2 2003/12/07 23:30:34 init Exp $ +# $Id: admin_es.properties,v 1.29.2.3 2004/01/11 20:35:50 zapata Exp $ languagename = Castellano @@ -45,8 +45,14 @@ no_matches_found = \u00a1No se encontraron coincidencias! list.next = siguiente list.previous = anterior +# missing (master value = "Status:") +system.status = +# missing (master value = "Logged in:") +system.loggedin = # media - used by image, audio, video and other media +# missing (master value = "Urls") +media.urls = media.created = creado media.changed = \u00faltima modificaci\u00f3n media.published = publicado @@ -67,6 +73,10 @@ media.is_published = Est\u00e1 publicado media.icon = Icono media.nr_of_media = N\u00famero de recursos medi\u00e1ticos (m\u00e1ximo 20) media.nr_of_media.submit = definir n\u00famero +# missing (master value = "Comments ") +media.comments = +# missing (master value = "Articles") +media.articles = medialist.search_text_in = Buscar texto en @@ -94,6 +104,8 @@ other_medialist.htmltitle = Lista de recursos medi\u00e1ticos # breaking breaking.htmltitle = \u00daltimas noticias breaking.textinfo = (m\u00e1x. 5 l\u00edneas / 250 caracteres) +# missing (master value = "id") +breaking.id = breaking.text = texto breaking.date = fecha @@ -115,6 +127,12 @@ comment.article = Art\u00edculo comment.html = HTML comment.status = Estado comment.language = Idioma +# missing (master value = "All comments") +comment.allcomments = +# missing (master value = "Internal Comment") +comment.comment = +# missing (master value = "(internal)") +comment.comment.info = comment.operation.hide = ocultar comment.operation.unhide = desocultar @@ -124,8 +142,7 @@ comment.operation.unhide = desocultar commentlist.htmltitle = Lista de comentarios commentlist.published = publicado commentlist.hidden = oculto -# missing (master value = "All comments for this article") -commentlist.allcomments = Todos los comentarios de este artículo +commentlist.allcomments = Todos los comentarios de este art\u00edculo commentlist.search = buscar commentlist.activate = activar modificaciones commentlist.order = orden @@ -136,6 +153,10 @@ commentlist.order.articletitle = t\u00edtulo del art\u00edculo commentsearch.field = Buscar commentsearch.field.title = T\u00edtulo commentsearch.field.creator = Autor +# missing (master value = "Url") +commentsearch.field.main_url = +# missing (master value = "Email") +commentsearch.field.email = commentsearch.field.description = Descripci\u00f3n commentsearch.value = Valor @@ -179,6 +200,16 @@ content.content = Contenido content.html = HTML? content.comment = Comentario interno content.internal = (prop\u00f3sito interno) +# missing (master value = "Keywords") +content.keywords = +# missing (master value = "Locked by {0}") +content.lockedby = +# missing (master value = "Lock") +content.lock = +# missing (master value = "Unlock") +content.unlock = +# missing (master value = "Force lock") +content.forcelock = content.attachments = Adjuntos content.images = Im\u00e1genes @@ -217,12 +248,15 @@ content.operation.hide = ocultar content.operation.unhide = desocultar content.operation.newswire = newswire -# missing (master value = "search") contentsearch.value = buscar contentsearch.field = campo contentsearch.field.title = T\u00edtulo contentsearch.field.creator = Autor contentsearch.field.contents = Contenido +# missing (master value = "Email") +contentsearch.field.creator_email = +# missing (master value = "Web address") +contentsearch.field.creator_main_url = contentsearch.publishedstate = estado de publicaci\u00f3n contentsearch.publishedstate.hidden = oculto @@ -246,26 +280,13 @@ contentlist.select = Seleccionar # language language.htmltitle = Idioma +# missing (master value = "Id") +language.id = language.name = Idioma language.code = C\u00f3digo de idioma languagelist.htmltitle = Idiomas - -# imcs -linkimcs.htmltitle = Enlaces a CMIs -linkimcs.name = Nombre -linkimcs.continent = Continente -linkimcs.new_parent = Nuevo padre -linkimcs.url = URL -linkimcs.sort_by = Criterio de ordenaci\u00f3n -linkimcs.language = Idioma -linkimcs.parent = Padre - -linkimcslist.htmltitle = Lista de enlaces a CMIs -linkimcslist.search_in = Buscar texto en - - # login login.htmltitle = Entrada login.info = Esta zona es accesible exclusivamente a grupos autorizados. Si quieres colaborar como editor, por favor contacta con nosotros en {0}. @@ -278,6 +299,8 @@ login.submit = Aceptar # mediafolder mediafolder.htmltitle = Carpeta de recursos medi\u00e1ticos +# missing (master value = "id") +mediafolder.id = mediafolder.date = fecha mediafolder.name = nombre mediafolder.location = lugar de origen @@ -289,6 +312,8 @@ mediafolderlist.htmltitle = Lista de carpetas de recursos medi\u00e1ticos # message message.htmltitle = Mensajes +# missing (master value = "id") +message.id = message.date = fecha message.title = t\u00edtulo message.creator = autor @@ -300,12 +325,13 @@ messagelist.htmltitle = Lista de mensajes # admin start page start.htmltitle = Administraci\u00f3n -start.breaking.new = a\u00f1adir \u00faltima noticia start.content.new = nuevo art\u00edculo start.show = mostrar -start.open_by_id = ID env\u00edo +# missing (master value = "open comment #") +start.comment.open_by_id = +# missing (master value = "open article #") +start.content.open_by_id = -start.administer.comments = comentarios start.content.hidden = art\u00edculos ocultos start.content.not_published = art\u00edculos (aun) sin publicar start.content.with_media = con recursos medi\u00e1ticos @@ -315,24 +341,32 @@ start.content.all = Todos los art\u00edculos start.content.search = buscar start.allarticlesoftype = {0} +# missing (master value = "{0}") +start.allcommentswithstatus = start.producers.title = GENERAR MANUALMENTE start.producers.produceAllNew = generar todos los nuevos +# missing (master value = "generate all new") +start.producers.recipe.allnew = + start.producers.advanced = p\u00e1gina avanzada (usar con cuidado!) -start.openpostings.title = ENV\u00cdOS ABIERTOS +start.administer.title = ADMINISTRAR +start.administer.comments = comentarios + start.comments.title = COMENTARIOS + start.breaking.title = \u00faltimas noticias -start.content.title = ART\u00cdCULOS -start.administer.title = ADMINISTRAR -start.list.title = LISTA +# missing (master value = "ARTICLES") +start.articles.title = start.fileedit.includes.title = editar ficheros start.addandedit.title = A\u00d1ADIR / EDITAR start.extra.title = EXTRA start.search.title = BUSCAR -start.topics.title = TEMAS start.other_media.title = otros recursos medi\u00e1ticos start.images.title = im\u00e1genes +# missing (master value = "open image #") +start.images.open_by_id = start.video.title = video start.audio.title = audio start.media.title = MEDIA @@ -346,7 +380,11 @@ start.superusermenu = funciones de super-usuario (usar con cuidado!) # topic + topic.htmltitle = tema + +# missing (master value = "id") +topic.id = topic.title = nombre topic.description = descripci\u00f3n topic.filename = nombre del fichero @@ -359,9 +397,28 @@ topiclist.htmltitle = Lista de temas # users user.htmltitle = Usuario user.login = Usuario +# missing (master value = "Your own password") +user.ownpassword = +# missing (master value = "Old password") +user.oldpassword = user.password = Contrase\u00f1a user.password2 = Contrase\u00f1a (confirmaci\u00f3n) user.admin = Administrador +# missing (master value = "Disabled ?") +user.is_disabled = +# missing (master value = "Creation date") +user.creationdate = +# missing (master value = "Last login") +user.lastlogindate = +# missing (master value = "Email address") +user.email = +# missing (master value = "Comment") +user.comment = +# missing (master value = "Profile") +user.profile = + + + userlist.htmltitle = Lista de usuarios @@ -374,7 +431,6 @@ articletype.name = Nombre articletypelist.htmltitle = Lista de tipos de art\u00edculo # mediatypes -### needs translation mediatypelist.htmltitle = Manage Mediatypes mediatype.id = id mediatype.name = Name @@ -383,8 +439,6 @@ mediatype.mimetype = MIME-Type mediatype.classname = Classname mediatype.tablename = Tabelname - - #commentstatus commentstatus.htmltitle = Estado de comentario commentstatus.id = ID @@ -413,10 +467,14 @@ producer.verb.enqueue = Poner a la cola producer.job.name = Trabajo producer.job.status = Estado producer.job.date = \u00daltima modificacion -producer.job.cancel = cancelar -producer.job.abort = abortar producer.job.empty = La cola est\u00e1 vac\u00eda +# missing (master value = "Running time") +producer.job.runningtime = +# missing (master value = "Cancel selected jobs") +producer.jobqueue.canceljobs = +# missing (master value = "Cancel all pending jobs") +producer.jobqueue.cancelalljobs = producer.jobqueue.title = Trabajos actuales producer.jobqueue.refresh = refrescar producer.producerlist.title = A\u00f1adir un nuevo trabajo @@ -448,8 +506,8 @@ abuse.openpostingpassword = Pedir contrase\u00f1a para los env\u00edos abiertos abuse.logpostings = Hacer un log de las IPs de los env\u00edos abiertos abuse.logsize = Tama\u00f1o del buffer del log abuse.cookies = Utilizar cookies para los usuarios bloqueados -abuse.articleaction = Acción a realizar con un artículo bloqueado -abuse.commentaction = Acción a realizar con un comentario bloqueado +abuse.articleaction = Acci\u00f3n a realizar con un art\u00edculo bloqueado +abuse.commentaction = Acci\u00f3n a realizar con un comentario bloqueado abuse.showlog = Mostrar el log de IPs abuse.showfilters = Gestionar filtros @@ -458,17 +516,52 @@ abuse.log.time = Hora abuse.log.address = N\u00famero de IP abuse.log.object = Objeto abuse.log.browser = Navegador +# missing (master value = "Filter type") +abuse.log.filtertype = +# missing (master value = "Expression") +abuse.log.filterexpression = abuse.filters = Filtros +# missing (master value = "down") +abuse.filters.movedown = +# missing (master value = "up") +abuse.filters.moveup = + abuse.filter.type = Tipos +abuse.filter.expression = Expresi\u00f3n +# missing (master value = "Article ") +abuse.filter.articleaction = +# missing (master value = "Comment ") +abuse.filter.commentaction = +# missing (master value = "Comments (internal usage)") +abuse.filter.comments = +# missing (master value = "Last hit") +abuse.filter.lasthit = +# missing (master value = "Edit filter") +abuse.filter.htmltitle = + abuse.filtertype.ip = N\u00famero de IP abuse.filtertype.regexp = Expresi\u00f3n regular -abuse.filter.expression = Expresi\u00f3n +# missing (master value = "User Agent") +abuse.filtertype.useragent = +# missing (master value = "Error:") +abuse.filtererror.title = +# missing (master value = "Invalid filter type") +abuse.filtererror.invalidtype = +# missing (master value = "Invalid expression for this type") +abuse.filtererror.invalidexpression = + +# missing (master value = "Anti-abuse filter rules") +abuse.filters.htmltitle = +# missing (master value = "Anti-abuse open posting log") +abuse.log.htmltitle = # head head.start = inicio head.logout = salir +# missing (master value = "password") +head.changepassword = head.help = ayuda head.search = buscar head.logged_in = identificado @@ -492,8 +585,6 @@ articletypes.startspecial = Especial de portada # Comment status values commentstatus.normal = normal -commentstatus.good = bueno -commentstatus.bad = malo @@ -512,8 +603,13 @@ media.error.unsupportedformat = El formato del recurso medi\u00e1tico que has su user.error.missingpasswords = La nueva contrase\u00f1a debe ser introducida dos veces user.error.passwordmismatch = Las contrase\u00f1as no son iguales user.error.missingpassword = Es necesario introducir alguna contrase\u00f1a +# missing (master value = "Incorrect password") +user.error.incorrectpassword = + + ########## infomessages ########## infomessage.htmltitle = Informaci\u00f3n -infomessage.produceAllNewAddedToQueue = Tu petici\u00f3n se ha a\u00f1adido a la cola. +# missing (master value = "Your request has been added to the queue.") +infomessage.recipeAddedToQueue = diff --git a/bundles/admin_eu.properties b/bundles/admin_eu.properties index 42c46dda..40a12538 100755 --- a/bundles/admin_eu.properties +++ b/bundles/admin_eu.properties @@ -1,6 +1,6 @@ ########## admin ########## # language: euskera / basque -# $Id: admin_eu.properties,v 1.12.2.2 2003/12/07 23:30:34 init Exp $ +# $Id: admin_eu.properties,v 1.12.2.3 2004/01/11 20:35:50 zapata Exp $ languagename = Euskera @@ -54,8 +54,14 @@ no_matches_found = Ez da horrelako sarrerarik aurkitu! list.next = hurrengoa list.previous = aurrekoa +# missing (master value = "Status:") +system.status = +# missing (master value = "Logged in:") +system.loggedin = # media - used by image, audio, video and other media +# missing (master value = "Urls") +media.urls = media.created = sortua media.changed = aldatua media.published = argitaratua @@ -76,6 +82,10 @@ media.is_published = Argitaratzeko prest media.icon = Ikonoa media.nr_of_media = Baliabide mediatikoen kopurua media.nr_of_media.submit = Aldatu kopurua +# missing (master value = "Comments ") +media.comments = +# missing (master value = "Articles") +media.articles = medialist.search_text_in = Testua non bilatu @@ -104,6 +114,8 @@ other_medialist.htmltitle = # breaking breaking.htmltitle = Azken albisteak breaking.textinfo = (gehienez 5 lerrro / 250 letra) +# missing (master value = "id") +breaking.id = breaking.text = testua breaking.date = data @@ -125,6 +137,12 @@ comment.article = Artikuluarena comment.html = HTML da? comment.status = Egoera comment.language = Hizkuntza +# missing (master value = "All comments") +comment.allcomments = +# missing (master value = "Internal Comment") +comment.comment = +# missing (master value = "(internal)") +comment.comment.info = # missing (master value = "hide") comment.operation.hide = @@ -144,9 +162,9 @@ commentlist.search = bilatu! commentlist.activate = # missing (master value = "order") commentlist.order = -# missing (master value = "date (desc.)") +# missing (master value = "newest first") commentlist.order.datedesc = -# missing (master value = "date (asc.)") +# missing (master value = "oldest first") commentlist.order.dateasc = # missing (master value = "article title") commentlist.order.articletitle = @@ -157,6 +175,10 @@ commentsearch.field = commentsearch.field.title = # missing (master value = "Author") commentsearch.field.creator = +# missing (master value = "Url") +commentsearch.field.main_url = +# missing (master value = "Email") +commentsearch.field.email = # missing (master value = "Description") commentsearch.field.description = # missing (master value = "Value") @@ -211,6 +233,16 @@ content.content = Edukia content.html = HTML da? content.comment = Barne komentarioa content.internal = (barne xederako) +# missing (master value = "Keywords") +content.keywords = +# missing (master value = "Locked by {0}") +content.lockedby = +# missing (master value = "Lock") +content.lock = +# missing (master value = "Unlock") +content.unlock = +# missing (master value = "Force lock") +content.forcelock = content.attachments = Atxekiak content.images = Irudiak @@ -273,6 +305,10 @@ contentsearch.field.title = contentsearch.field.creator = # missing (master value = "Contents") contentsearch.field.contents = +# missing (master value = "Email") +contentsearch.field.creator_email = +# missing (master value = "Web address") +contentsearch.field.creator_main_url = # missing (master value = "publication state") contentsearch.publishedstate = @@ -307,26 +343,13 @@ contentlist.select = # language language.htmltitle = Hizkuntza +# missing (master value = "Id") +language.id = language.name = hizkuntza language.code = Hizkuntza kodea languagelist.htmltitle = Hizkuntzen zerrenda - -# imcs -linkimcs.htmltitle = MIGen loturak -linkimcs.name = Izena -linkimcs.continent = Kontinentea -linkimcs.new_parent = Aita berria -linkimcs.url = URL -linkimcs.sort_by = Hurrenkera irizpidea -linkimcs.language = Hizkuntza -linkimcs.parent = Aita - -linkimcslist.htmltitle = MIGen loturen zerrenda -linkimcslist.search_in = Testua non bilatu - - # login login.htmltitle = Sarrera login.info = Eremu hau baimendutako taldeentzat bakarrik da. Editore lanetan lagundu nahi baduzu, jar zaitez gurekin kontaktuan imceuskalherria-editorial@lists.indymedia.org helbidean mesedez. @@ -339,6 +362,8 @@ login.submit = Ados # mediafolder mediafolder.htmltitle = Baliabide mediatikoen karpeta +# missing (master value = "id") +mediafolder.id = mediafolder.date = data mediafolder.name = izena mediafolder.location = jatorrizko lekua @@ -350,6 +375,8 @@ mediafolderlist.htmltitle = Baliabide mediatikoen karpeten zerrenda # message message.htmltitle = Mezuak +# missing (master value = "id") +message.id = message.date = data message.title = izenburua message.creator = Egilea @@ -361,14 +388,13 @@ messagelist.htmltitle = Mezuen zerrenda # admin start page start.htmltitle = Administrazioa -start.breaking.new = azken albiste berriak start.content.new = artikulu berriak start.show = Erakutsi -# missing (master value = "open id") -start.open_by_id = +# missing (master value = "open comment #") +start.comment.open_by_id = +# missing (master value = "open article #") +start.content.open_by_id = -# missing (master value = "comments") -start.administer.comments = start.content.hidden = aritukulu ezkutukoak start.content.not_published = argitaratzeke dauden artikuluak start.content.with_media = baliabide mediatikoekin @@ -378,19 +404,26 @@ start.content.all = Artikulu guztiak start.content.search = bilatu start.allarticlesoftype = {0} motatako artikulu guztiak +# missing (master value = "{0}") +start.allcommentswithstatus = start.producers.title = Euskuz ekoiztu start.producers.produceAllNew = Dena berria ekoiztu +# missing (master value = "generate all new") +start.producers.recipe.allnew = + start.producers.advanced = Aukera arreratuak (kontuz honekin!) -start.openpostings.title = BIDALKETA IREKIAK -start.comments.title = KOMENTARIOAK -start.breaking.title = AZKEN ALBISTRAK -start.content.title = ARTIKULUAK # missing (master value = "ADMINISTER") start.administer.title = -# missing (master value = "LIST") -start.list.title = +# missing (master value = "comments") +start.administer.comments = + +start.comments.title = KOMENTARIOAK + +start.breaking.title = AZKEN ALBISTRAK +# missing (master value = "ARTICLES") +start.articles.title = # missing (master value = "edit include files") start.fileedit.includes.title = # missing (master value = "ADD / EDIT") @@ -399,9 +432,10 @@ start.addandedit.title = start.extra.title = # missing (master value = "SEARCH") start.search.title = -start.topics.title = GAIAK start.other_media.title = BESTE MEDIOEN FITXATEGIAK start.images.title = IRUDIAK +# missing (master value = "open image #") +start.images.open_by_id = start.video.title = BIDEO FITXATEGIAK start.audio.title = AUDIO FITXATEGIAK # missing (master value = "MEDIA") @@ -416,7 +450,11 @@ start.superusermenu = Aukera aurreratuak (kontuz honekin!) # topic + topic.htmltitle = Gaia + +# missing (master value = "id") +topic.id = topic.title = Izena topic.description = deskripzioa topic.filename = Fitxategiaren izena @@ -429,10 +467,29 @@ topiclist.htmltitle = Gaien zerrenda # users user.htmltitle = Erabiltzailea user.login = erabiltzailea +# missing (master value = "Your own password") +user.ownpassword = +# missing (master value = "Old password") +user.oldpassword = user.password = pasahitza # missing (master value = "Password (confirmation)") -user.password2 = +user.password2 = user.admin = administratzailea +# missing (master value = "Disabled ?") +user.is_disabled = +# missing (master value = "Creation date") +user.creationdate = +# missing (master value = "Last login") +user.lastlogindate = +# missing (master value = "Email address") +user.email = +# missing (master value = "Comment") +user.comment = +# missing (master value = "Profile") +user.profile = + + + userlist.htmltitle = Erabiltzaileen zerrenda @@ -445,7 +502,6 @@ articletype.name = Izena articletypelist.htmltitle = Artikuluen mota zerrenda # mediatypes -### needs translation mediatypelist.htmltitle = Manage Mediatypes mediatype.id = id mediatype.name = Name @@ -454,8 +510,6 @@ mediatype.mimetype = MIME-Type mediatype.classname = Classname mediatype.tablename = Tabelname - - #commentstatus commentstatus.htmltitle = Komentarioen egoera commentstatus.id = ID @@ -469,12 +523,12 @@ commentstatuslist.htmltitle = Komentarioen egoeraren zerrenda fileedit.htmltitle = Fitxategia aldatu fileedit.filename = Fitxategiaren izena # missing (master value = "Subdirectory") -fileedit.subdirectory = +fileedit.subdirectory = fileeditlist.htmltitle = Fitxategien aldaketak fileeditlist.filename = Fitxategiaren izena # missing (master value = "Subdirectory") -fileeditlist.dirname = +fileeditlist.dirname = #producers @@ -486,11 +540,15 @@ producer.verb.enqueue = Eskatu producer.job.name = Lana producer.job.status = Egoera producer.job.date = azken aldaketa -producer.job.cancel = ezeztatu -producer.job.abort = utzi # missing (master value = "Queue is empty") -producer.job.empty = - +producer.job.empty = +# missing (master value = "Running time") +producer.job.runningtime = + +# missing (master value = "Cancel selected jobs") +producer.jobqueue.canceljobs = +# missing (master value = "Cancel all pending jobs") +producer.jobqueue.cancelalljobs = producer.jobqueue.title = Oraingo lanak producer.jobqueue.refresh = birkargatu producer.producerlist.title = Lan berri bat gehitu @@ -501,7 +559,7 @@ producerqueue.htmltitle = Eskuz ekoiztu #superusermenu superusermenu.htmltitle = Aukera aurreratuak # missing (master value = "MANAGE") -superusermenu.manage = +superusermenu.manage = superusermenu.topics = Gaien kudeaketa superusermenu.articletypes = Artiukuluen moten kudeaketa superusermenu.mediatypes = Mediatypes @@ -550,22 +608,57 @@ abuse.log.address = abuse.log.object = # missing (master value = "Browser") abuse.log.browser = +# missing (master value = "Filter type") +abuse.log.filtertype = +# missing (master value = "Expression") +abuse.log.filterexpression = # missing (master value = "Filters") abuse.filters = +# missing (master value = "down") +abuse.filters.movedown = +# missing (master value = "up") +abuse.filters.moveup = + # missing (master value = "Type") abuse.filter.type = +# missing (master value = "Expression") +abuse.filter.expression = +# missing (master value = "Article ") +abuse.filter.articleaction = +# missing (master value = "Comment ") +abuse.filter.commentaction = +# missing (master value = "Comments (internal usage)") +abuse.filter.comments = +# missing (master value = "Last hit") +abuse.filter.lasthit = +# missing (master value = "Edit filter") +abuse.filter.htmltitle = + # missing (master value = "IP Number") abuse.filtertype.ip = # missing (master value = "Regular expression") abuse.filtertype.regexp = -# missing (master value = "Expression") -abuse.filter.expression = +# missing (master value = "User Agent") +abuse.filtertype.useragent = +# missing (master value = "Error:") +abuse.filtererror.title = +# missing (master value = "Invalid filter type") +abuse.filtererror.invalidtype = +# missing (master value = "Invalid expression for this type") +abuse.filtererror.invalidexpression = + +# missing (master value = "Anti-abuse filter rules") +abuse.filters.htmltitle = +# missing (master value = "Anti-abuse open posting log") +abuse.log.htmltitle = # head head.start = hasiera head.logout = irten +# missing (master value = "password") +head.changepassword = head.help = laguntza head.search = bilatu head.logged_in = erregistraturik zaude @@ -590,10 +683,6 @@ articletypes.startspecial = berezia # Comment status values # missing (master value = "normal") commentstatus.normal = -# missing (master value = "good") -commentstatus.good = -# missing (master value = "bad") -commentstatus.bad = @@ -616,10 +705,13 @@ user.error.missingpasswords = user.error.passwordmismatch = # missing (master value = "A password must be entered") user.error.missingpassword = +# missing (master value = "Incorrect password") +user.error.incorrectpassword = + + ########## infomessages ########## infomessage.htmltitle = Oharra -infomessage.produceAllNewAddedToQueue = Lana zerrendan sartuta - -########## HTML-charset ########## +# missing (master value = "Your request has been added to the queue.") +infomessage.recipeAddedToQueue = diff --git a/etc/open/comment.template b/etc/open/comment.template index 8051c662..cd693b86 100755 --- a/etc/open/comment.template +++ b/etc/open/comment.template @@ -1,7 +1,7 @@ ${lang("comment.htmltitle")} - + @@ -9,121 +9,121 @@ - - - - - + + + + - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + +
- ${lang("comment.header")} -
-

- - ${lang("comment.note")} - +

+ ${lang("comment.header")} +
+

+ + ${lang("comment.note")} +
${data.passwd}
-
-

+ +

-
- ${lang("comment.formtitle")} -
${lang("comment.password")}:
+ ${lang("comment.formtitle")} +
${lang("comment.password")}:
- ${lang("comment.title")}: - - (${lang("required")}) -
- ${lang("comment.name")}: - - (${lang("required")}) -
- ${lang("comment.email")}: - - (${lang("optional")}) -
- ${lang("comment.url")}: - - (${lang("optional")}) -
- ${lang("comment.phone")}: - - (${lang("optional")}) -
- ${lang("comment.address")}: - - (${lang("optional")}) -
- ${lang("comment.language")}: - - - (${lang("optional")}) -
- ${lang("comment.text")}: - -   -

-
  - -
-  
+
+ ${lang("comment.title")}: + + (${lang("required")}) +
+ ${lang("comment.name")}: + + (${lang("required")}) +
+ ${lang("comment.email")}: + + (${lang("optional")}) +
+ ${lang("comment.url")}: + + (${lang("optional")}) +
+ ${lang("comment.phone")}: + + (${lang("optional")}) +
+ ${lang("comment.address")}: + + (${lang("optional")}) +
+ ${lang("comment.language")}: + + + (${lang("optional")}) +
+ ${lang("comment.text")}: + +   +

+
  + +
+  
-
-
-  
- -
-
+
+  
+ +
+
diff --git a/etc/open/comment_done.template b/etc/open/comment_done.template index bf9d1ed4..0b7ebf68 100755 --- a/etc/open/comment_done.template +++ b/etc/open/comment_done.template @@ -2,35 +2,35 @@ - ${lang("commentdone.htmltitle")} + ${lang("commentdone.htmltitle")} - - - - + + + - - - - + + + + +
- ${lang("commentdone.thanks")} -
+
+ ${lang("commentdone.thanks")} +
-
+
${lang("commentdone.wait")} -
+
${lang("commentdone.criteria")} -
- ${lang("commentdone.stay_calm")}
-
+
+ ${lang("commentdone.stay_calm")}
+
-
- >> ${lang("commentdone.back")} -
+ >> ${lang("commentdone.back")} +
diff --git a/etc/open/comment_dupe.template b/etc/open/comment_dupe.template index 2e9ce66e..3f44874a 100755 --- a/etc/open/comment_dupe.template +++ b/etc/open/comment_dupe.template @@ -2,35 +2,35 @@ - ${lang("commentdupe.htmltitle")} + ${lang("commentdupe.htmltitle")} - - - - + + + - - - - +
+
${lang("commentdupe.no_panic")}

+
+ + + + + +
- - ${lang("commentdupe.title")} - -
- -
+
+ + ${lang("commentdupe.title")} + +
+ +
${lang("commentdupe.explanation")} -
-
${lang("commentdupe.no_panic")}

-
-
-
- >> ${lang("commentdupe.back")} -
+ >> ${lang("commentdupe.back")} +
diff --git a/etc/open/disclaimer.inc.de b/etc/open/disclaimer.inc.de index e2124efc..d28d2ea3 100755 --- a/etc/open/disclaimer.inc.de +++ b/etc/open/disclaimer.inc.de @@ -68,8 +68,8 @@ Beitr Außerdem gibt es Beiträge, die sofort in ein Müllarchiv kommen: diff --git a/etc/open/donearticle.template b/etc/open/donearticle.template index 1eeb5c6a..baca72c6 100755 --- a/etc/open/donearticle.template +++ b/etc/open/donearticle.template @@ -2,53 +2,53 @@ - ${lang("postingdone.htmltitle")} - + ${lang("postingdone.htmltitle")} + - - - - - - - - - - - - - - - + + + + + +
 
-   start >> - - ${lang("postingdone.title")} -  
 
  -
+ + + + + + + + + + + + + + + - - - - - - + + + + + + - - - - - -
 
+   start >> + + ${lang("postingdone.title")} +  
 
  +
${lang("postingdone.info")}
-
- ${lang("commentdone.stay_calm")}
-
-
 
  - +
+ ${lang("commentdone.stay_calm")}
+
+
 
  + ${lang("postingdone.back")} >> - -  
 

+ +
 
 

diff --git a/etc/open/donecomment.template b/etc/open/donecomment.template index dac560bf..1d38bf29 100755 --- a/etc/open/donecomment.template +++ b/etc/open/donecomment.template @@ -2,35 +2,35 @@ - ${lang("commentdone.htmltitle")} + ${lang("commentdone.htmltitle")} - - - - + + + - - - - + + + + +
- ${lang("commentdone.thanks")} -
+
+ ${lang("commentdone.thanks")} +
-
+
${lang("commentdone.wait")} -
+
${lang("commentdone.criteria")} -
- ${lang("commentdone.stay_calm")}
-
+
+ ${lang("commentdone.stay_calm")}
+
-
- >> ${lang("commentdone.back")} -
+ >> ${lang("commentdone.back")} +
diff --git a/etc/open/dupearticle.template b/etc/open/dupearticle.template index 8ba30e7c..cac7fcbd 100755 --- a/etc/open/dupearticle.template +++ b/etc/open/dupearticle.template @@ -2,51 +2,51 @@ - ${lang("postingdupe.htmltitle")} - + ${lang("postingdupe.htmltitle")} + - - - - - - - - - - - - - - - + + + + + + + + + + + +
 
-   start >> - - ${lang("postingdupe.title")} -  
 
  -
+ + + + + + + + + + + + + + + - - - - - - - - - - - -
 
+   start >> + + ${lang("postingdupe.title")} +  
 
  +
${lang("postingdupe.explanation")}
-
- ${lang("postingdupe.no_panic")}
-
-
 
  - ${lang("postingdupe.back")} >> -  
 

+
+ ${lang("postingdupe.no_panic")}
+
+
 
  + ${lang("postingdupe.back")} >> +  
 

diff --git a/etc/open/dupecomment.template b/etc/open/dupecomment.template index 2e9ce66e..3f44874a 100755 --- a/etc/open/dupecomment.template +++ b/etc/open/dupecomment.template @@ -2,35 +2,35 @@ - ${lang("commentdupe.htmltitle")} + ${lang("commentdupe.htmltitle")} - - - - + + + - - - - +
+
${lang("commentdupe.no_panic")}

+
+ + + + + +
- - ${lang("commentdupe.title")} - -
- -
+
+ + ${lang("commentdupe.title")} + +
+ +
${lang("commentdupe.explanation")} -
-
${lang("commentdupe.no_panic")}

-
-
-
- >> ${lang("commentdupe.back")} -
+ >> ${lang("commentdupe.back")} +
diff --git a/etc/open/editcomment.template b/etc/open/editcomment.template index fe559a5d..817edcd4 100755 --- a/etc/open/editcomment.template +++ b/etc/open/editcomment.template @@ -259,48 +259,48 @@ ${lang("posting.step03")}
- - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + +
- ${lang("posting.media.title")} 1: - -
-
${lang("posting.media.media")} 1 - -
- ${lang("posting.media.title")} 2: - -
-
${lang("posting.media.media")} 2 - -
- ${lang("posting.media.title")} 3: - -
-
${lang("posting.media.media")} 3 - -
+ ${lang("posting.media.title")} 1: + +
+
${lang("posting.media.media")} 1 + +
+ ${lang("posting.media.title")} 2: + +
+
${lang("posting.media.media")} 2 + +
+ ${lang("posting.media.title")} 3: + +
+
${lang("posting.media.media")} 3 + +
diff --git a/etc/open/email_article.template b/etc/open/email_article.template index e6c178ff..29557836 100755 --- a/etc/open/email_article.template +++ b/etc/open/email_article.template @@ -9,14 +9,14 @@ ${lang("general.htmltitle")} Email Forward ------------------------------------------------------------ ${data.article.title} - + ${data.article.creator}, ${data.article.creationdate.formatted["dd.MM.yyyy HH:mm"]} ${data.article.description} - + ${data.article.content_data} - - + + ${lang("article.email.prefix")}: ${data.article.creator_email} @@ -38,62 +38,62 @@ Content-type: text/html;charset="utf-8"; - +

${data.article.description_parsed}

+ + +

+ + ${media["title"]} - ${media["media_descr"]} ${media["human_readable_size"]} + +

+
+ +

+ + + ${media["title"]} - ${media["media_descr"]} ${media["human_readable_size"]} +

+
+ +

+ + + ${media["title"]} - ${media["media_descr"]} ${media["human_readable_size"]} +

+
+ + +

+ ${image[ +
${image["title"]} +

+
+
+

${data.article.content_data_parsed}

+
+ +

+ + + - ${lang("article.email.prefix")}: ${article.creator_email}
+
+ + ${lang("article.homepage.prefix")}: ${data.article.creator_main_url}
+
+
+

+
+
+
+
+ !COMMENT! + +

${data.article.title}(original location here)

- -

${data.article.creator}, ${data.article.creationdate.formatted["dd.MM.yyyy HH:mm"]}

+ +

${data.article.creator}, ${data.article.creationdate.formatted["dd.MM.yyyy HH:mm"]}


-

${data.article.description_parsed}

- - -

- - ${media["title"]} - ${media["media_descr"]} ${media["human_readable_size"]} - -

-
- -

- - - ${media["title"]} - ${media["media_descr"]} ${media["human_readable_size"]} -

-
- -

- - - ${media["title"]} - ${media["media_descr"]} ${media["human_readable_size"]} -

-
- - -

- ${image[ -
${image["title"]} -

-
-
-

${data.article.content_data_parsed}

-
- -

- - - - ${lang("article.email.prefix")}: ${article.creator_email}
-
- - ${lang("article.homepage.prefix")}: ${data.article.creator_main_url}
-
-
-

-
-
-
-
- !COMMENT! -
diff --git a/etc/open/error.template b/etc/open/error.template index 2a0395d0..6965788a 100755 --- a/etc/open/error.template +++ b/etc/open/error.template @@ -6,31 +6,31 @@ - - - - - - - - - - - + + + + + + + + + + - +

+ +

-

${lang("error.title")}

-
-
-

${lang("error.text", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])} -

-

-

${data.date} -- ${data.errorstring} -

-

-

+

+

${lang("error.title")}

+
+
+

${lang("error.text", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])} +

+

+

${data.date} -- ${data.errorstring} +

+

+

${lang("error.text2", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])} -

-

diff --git a/etc/open/posting.template b/etc/open/posting.template index d22dab16..6d35bee8 100755 --- a/etc/open/posting.template +++ b/etc/open/posting.template @@ -1,79 +1,79 @@ - ${lang("posting.htmltitle")} - - - - - - - - - + ${lang("posting.htmltitle")} + + + + + + + + + - - - - - - - - + + + + + + + - + + - - - + + + - - - - + + + + - - - + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + - - - + + + - - + - + - - + + +
- >> ${lang("posting.jump_to_form")} -
-
- ${lang("posting.title")}
-
+
+ >> ${lang("posting.jump_to_form")} +
+
+ ${lang("posting.title")}
+
- +
${data.passwd}


-
${lang("posting.nr_of_media")}
- ${lang("posting.nr_of_media.info")}
  -
${lang("posting.nr_of_media")}
+ ${lang("posting.nr_of_media.info")}
  +
-
${lang("posting.form.title")}
-
+
${lang("posting.form.title")}
+
${lang("posting.password")}
${lang("posting.password")}
- ${lang("posting.title")}:
- ${lang("posting.title.info")} -
-
(${lang("required")})
-
+ ${lang("posting.title")}:
+ ${lang("posting.title.info")} +
+
(${lang("required")})
+
${lang("posting.topic")}:
- ${lang("posting.topic.info")} + ${lang("posting.topic.info")}
- ${lang("posting.author")}: - -
${lang("required")}
-
- ${lang("posting.abstract")}:
- ${lang("posting.abstract.info")} -
- -
${lang("posting.abstract.constraint")}
-
- - ${lang("posting.contact.info")} - -
- ${lang("posting.email")}: - -
- (${lang("optional")}) -
- ${lang("posting.url")}: - -
- (${lang("optional")}) -
- ${lang("posting.address")}: - -
- (${lang("optional")}) -
- ${lang("posting.phone")}: - -
- (${lang("optional")}) -
 
- ${lang("posting.language")}: - - -   (${lang("optional")}) -
- ${lang("posting.text")}:
- ${lang("posting.text.info")} -
-   -

-
- ${lang("posting.media")}: - - ${lang("posting.media.info")}
- ${lang("posting.media.howto")} -
+ ${lang("posting.author")}: + +
${lang("required")}
+
+ ${lang("posting.abstract")}:
+ ${lang("posting.abstract.info")} +
+ +
${lang("posting.abstract.constraint")}
+
+ + ${lang("posting.contact.info")} + +
+ ${lang("posting.email")}: + +
+ (${lang("optional")}) +
+ ${lang("posting.url")}: + +
+ (${lang("optional")}) +
+ ${lang("posting.address")}: + +
+ (${lang("optional")}) +
+ ${lang("posting.phone")}: + +
+ (${lang("optional")}) +
 
+ ${lang("posting.language")}: + + +   (${lang("optional")}) +
+ ${lang("posting.text")}:
+ ${lang("posting.text.info")} +
+   +

+
+ ${lang("posting.media")}: + + ${lang("posting.media.info")}
+ ${lang("posting.media.howto")} +
- ${lang("posting.media.title")} ${m}: - -
-
${lang("posting.media.media")} ${m} - -
(${lang("optional")}) -
+ ${lang("posting.media.title")} ${m}: + +
+
${lang("posting.media.media")} ${m} + +
(${lang("optional")}) +
 
 
+
${lang("posting.submit.info")} -
- ${lang("posting.criteria")}
+
+ ${lang("posting.criteria")}
-
- + + - - -
+ +
diff --git a/etc/open/posting_disabled.template b/etc/open/posting_disabled.template index fc196426..21a44680 100755 --- a/etc/open/posting_disabled.template +++ b/etc/open/posting_disabled.template @@ -2,30 +2,30 @@ - ${lang("postingdisabled.htmltitle")} + ${lang("postingdisabled.htmltitle")} - - - - - + + + + + + - - + +
- ${lang("postingdisabled.title")}
- -
+
+ ${lang("postingdisabled.title")}
+ +
${lang("postingdisabled.info")}
- -
- >> ${lang("postingdisabled.back")} -
+ >> ${lang("postingdisabled.back")} +
diff --git a/etc/open/posting_done.template b/etc/open/posting_done.template index 1aa3d083..baee9ee9 100755 --- a/etc/open/posting_done.template +++ b/etc/open/posting_done.template @@ -2,18 +2,18 @@ - ${lang("postingdone.htmltitle")} + ${lang("postingdone.htmltitle")} - - - - - + + + + + + - - + +
- ${lang("postingdone.title")}
+
+ ${lang("postingdone.title")}

@@ -21,15 +21,15 @@ ${lang("postingdone.info")}

${lang("postingdone.stay_calm")}


-
-
- >> ${lang("postingdone.back")} -
+ >> ${lang("postingdone.back")} +
diff --git a/etc/open/posting_dupe.template b/etc/open/posting_dupe.template index acaf870b..e5329e35 100755 --- a/etc/open/posting_dupe.template +++ b/etc/open/posting_dupe.template @@ -2,35 +2,35 @@ - ${lang("postingdupe.htmltitle")} + ${lang("postingdupe.htmltitle")} - - - - + + + - - - - +
+
${lang("postingdupe.no_panic")}

+
+ + + + + +
- - ${lang("postingdupe.title")} - -
- -
+
+ + ${lang("postingdupe.title")} + +
+ +
${lang("postingdupe.explanation")} -
-
${lang("postingdupe.no_panic")}

-
-
-
- >> ${lang("postingdupe.back")} -
+ >> ${lang("postingdupe.back")} +
diff --git a/etc/open/prepare_mail.template b/etc/open/prepare_mail.template index bb90dffd..a5446baa 100755 --- a/etc/open/prepare_mail.template +++ b/etc/open/prepare_mail.template @@ -2,18 +2,18 @@ - ${lang("email.prepare.htmltitle")} + ${lang("email.prepare.htmltitle")} - - - - - + + + + + - - + +
- ${lang("email.prepare.title")}
+
+ ${lang("email.prepare.title")}
${lang("email.prepare.description")}
@@ -24,20 +24,20 @@ ${lang("email.prepare.from.name")} ${data.mail_comment}
${lang("email.prepare.chooselanguage")}
-
- >> ${lang("postingdone.back")} -
+ >> ${lang("postingdone.back")} +
diff --git a/etc/open/search_results.template b/etc/open/search_results.template index 62ef6dae..1a416e80 100755 --- a/etc/open/search_results.template +++ b/etc/open/search_results.template @@ -12,77 +12,77 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/etc/open/sent_mail.template b/etc/open/sent_mail.template index 4e8cae6b..ad991967 100755 --- a/etc/open/sent_mail.template +++ b/etc/open/sent_mail.template @@ -2,27 +2,27 @@ - ${lang("email.sent.htmltitle")} + ${lang("email.sent.htmltitle")}
-    ${lang("search.title")} -
-   -
- ${lang("search.mainsearchfield")} - - -
- ${lang("search.refine")} - - -
- ${lang("search.all_or_any")} - - - ${lang("search.all")} - ${lang("search.any")} - - ${lang("search.all")} - ${lang("search.any")} - -
- ${lang("search.by_author")} - - -
${lang("search.by_topic")} - -
+    ${lang("search.title")} +
+   +
+ ${lang("search.mainsearchfield")} + + +
+ ${lang("search.refine")} + + +
+ ${lang("search.all_or_any")} + + + ${lang("search.all")} + ${lang("search.any")} + + ${lang("search.all")} + ${lang("search.any")} + +
+ ${lang("search.by_author")} + + +
${lang("search.by_topic")} + +
- - - - - + + + + + - - + +
- ${lang("email.sent.title")}
+
+ ${lang("email.sent.title")}
${lang("email.sent.text")} -
+ >> ${lang("postingdone.back")} -
diff --git a/etc/open/sessionerror.template b/etc/open/sessionerror.template index 2a0395d0..6965788a 100755 --- a/etc/open/sessionerror.template +++ b/etc/open/sessionerror.template @@ -6,31 +6,31 @@ - - - - - - - - - - - + + + + + + + + + + - +

+ +

-

${lang("error.title")}

-
-
-

${lang("error.text", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])} -

-

-

${data.date} -- ${data.errorstring} -

-

-

+

+

${lang("error.title")}

+
+
+

${lang("error.text", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])} +

+

+

${data.date} -- ${data.errorstring} +

+

+

${lang("error.text2", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])} -

-

diff --git a/etc/open/unsupportedmediatype.template b/etc/open/unsupportedmediatype.template index 2a0395d0..6965788a 100755 --- a/etc/open/unsupportedmediatype.template +++ b/etc/open/unsupportedmediatype.template @@ -6,31 +6,31 @@ - - - - - - - - - - - + + + + + + + + + + - +

+ +

-

${lang("error.title")}

-
-
-

${lang("error.text", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])} -

-

-

${data.date} -- ${data.errorstring} -

-

-

+

+

${lang("error.title")}

+
+
+

${lang("error.text", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])} +

+

+

${data.date} -- ${data.errorstring} +

+

+

${lang("error.text2", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])} -

-

diff --git a/etc/open/usererror.template b/etc/open/usererror.template index fc61c25c..4409c367 100755 --- a/etc/open/usererror.template +++ b/etc/open/usererror.template @@ -5,32 +5,32 @@ - - - - - - - - + + + + + + + - - - - +

+ + +

+ +
-

${lang("usererror.title")}

-
-
-

${lang("usererror.text")} -

-

-

${data.errorstring} +

+

${lang("usererror.title")}

+
+
+

${lang("usererror.text")} +

+

+

${data.errorstring}

-

-

-

${lang("usererror.what_to_do")} - -

-

+

${lang("usererror.what_to_do")} + +

+

diff --git a/source/Mir.java b/source/Mir.java index 24c111eb..a2e8b152 100755 --- a/source/Mir.java +++ b/source/Mir.java @@ -57,7 +57,6 @@ import mir.util.ExceptionFunctions; import mir.util.StringRoutines; import mircoders.entity.EntityUsers; import mircoders.global.MirGlobal; -import mircoders.module.ModuleMessage; import mircoders.module.ModuleUsers; import mircoders.servlet.ServletHelper; import mircoders.storage.DatabaseUsers; @@ -71,12 +70,11 @@ import org.apache.struts.util.MessageResources; * Mir.java - main servlet, that dispatches to servletmodules * * @author $Author: zapata $ - * @version $Id: Mir.java,v 1.49.2.9 2003/12/21 13:32:02 zapata Exp $ + * @version $Id: Mir.java,v 1.49.2.10 2004/01/11 20:35:51 zapata Exp $ * */ public class Mir extends AbstractServlet { private static ModuleUsers usersModule = null; - private static ModuleMessage messageModule = null; private final static Map servletModuleInstanceHash = new HashMap(); private static Locale fallbackLocale = null; @@ -190,7 +188,6 @@ public class Mir extends AbstractServlet { HttpSession session = aRequest.getSession(true); setNoCaching(aResponse); - Locale locale = new Locale(getDefaultLanguage(aRequest), ""); aResponse.setContentType("text/html; charset=" + configuration. getString("Mir.DefaultHTMLCharset", "UTF-8")); diff --git a/source/mir/generator/TALGenerator.java b/source/mir/generator/TALGenerator.java index e8789da4..bf457e20 100755 --- a/source/mir/generator/TALGenerator.java +++ b/source/mir/generator/TALGenerator.java @@ -35,6 +35,7 @@ import java.util.Map; import mir.generator.tal.MirExpressionParser; import mir.generator.tal.TALTemplate; import mir.generator.tal.TALTemplateEngine; +import mir.generator.tal.interfaces.TALLogger; import mir.log.LoggerWrapper; public class TALGenerator implements Generator { @@ -47,15 +48,38 @@ public class TALGenerator implements Generator { library = aLibrary; } - public void generate(Object anOutputWriter, Map aValues, LoggerWrapper aLogger) throws GeneratorExc, GeneratorFailure { + public void generate(Object anOutputWriter, Map aValues, final LoggerWrapper aLogger) throws GeneratorExc, GeneratorFailure { TALTemplate template; try { template = library.engine.loadTemplate(templateIdentifier); + if (template == null) { throw new GeneratorExc("TALGeneratorLibrary: Can't find template " + templateIdentifier); } - template.processTemplate(aValues, (PrintWriter) anOutputWriter); + + template.processTemplate(aValues, (PrintWriter) anOutputWriter, + new TALLogger() { + public void debug(String anObject, String aMessage) { + aLogger.debug(anObject + ": " + aMessage); + } + + public void info(String anObject, String aMessage) { + aLogger.info(anObject + ": " + aMessage); + } + + public void warning(String anObject, String aMessage) { + aLogger.warn(anObject + ": " + aMessage); + } + + public void error(String anObject, String aMessage) { + aLogger.error(anObject + ": " + aMessage); + } + + public void fatal(String anObject, String aMessage) { + aLogger.fatal(anObject + ": " + aMessage); + } + }); } catch (Throwable t) { throw new GeneratorFailure(t); diff --git a/source/mir/generator/tal/CachingFileLoader.java b/source/mir/generator/tal/CachingFileLoader.java index 5218a4ab..df0c2b6a 100755 --- a/source/mir/generator/tal/CachingFileLoader.java +++ b/source/mir/generator/tal/CachingFileLoader.java @@ -27,6 +27,7 @@ * exception to your version of the file, but you are not obligated to do so. * If you do not wish to do so, delete this exception statement from your version. */ + package mir.generator.tal; import java.io.BufferedInputStream; diff --git a/source/mir/generator/tal/TALTemplate.java b/source/mir/generator/tal/TALTemplate.java index 0dca83b7..3d3a3301 100755 --- a/source/mir/generator/tal/TALTemplate.java +++ b/source/mir/generator/tal/TALTemplate.java @@ -1,314 +1,336 @@ -/* - * Copyright (C) 2001, 2002 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. - * If you do not wish to do so, delete this exception statement from your version. - */ -package mir.generator.tal; - -import java.io.PrintWriter; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import mir.generator.tal.interfaces.TALExpressionParser; -import mir.util.HTMLRoutines; - -/** - * {@link http://dev.zope.org/Wikis/DevSite/Projects/ZPT/TAL%20Specification%201.4} - * - *

Title:

- *

Description:

- *

Copyright: Copyright (c) 2003

- *

Company:

- * @author not attributable - * @version 1.0 - */ - -public class TALTemplate { - private TemplateNode rootNode; - private TALExpressionParser parser; - - public TALTemplate(TALExpressionParser aParser, TemplateNode aRootNode) { - rootNode = aRootNode; - parser = aParser; - } - - public void processTemplate(Object aContext, PrintWriter aDestination) { - StringBuffer output = new StringBuffer(); - - rootNode.process(parser, aContext, output); - aDestination.print(output); - } - - public interface TemplateNode { - public void process(TALExpressionParser aParser, Object aContext, StringBuffer aDestination); - } - - public static class CompositeTemplateNode - implements TemplateNode { - private List parts; - - public CompositeTemplateNode() { - parts = new Vector(); - } - - public void process(TALExpressionParser aParser, Object aContext, StringBuffer aDestination) { - Iterator i = parts.iterator(); - - while (i.hasNext()) { - ((TemplateNode) i.next()).process(aParser, aContext, aDestination); - } - } - - public void appendSubNode(TemplateNode aNode) { - if (aNode instanceof CompositeTemplateNode) { - Iterator i = ((CompositeTemplateNode) aNode).parts.iterator(); - while (i.hasNext()) { - appendSubNode((TemplateNode) i.next()); - } - } - else if (aNode instanceof PlainTextTemplateNode && parts.size()>0 && - (parts.get(parts.size()-1) instanceof PlainTextTemplateNode)) { - - ((PlainTextTemplateNode) parts.get(parts.size()-1)).appendText(((PlainTextTemplateNode) aNode).getText()); - } - else { - parts.add(aNode); - } - } - } - - public static class PlainTextTemplateNode - implements TemplateNode { - private String text; - - public PlainTextTemplateNode() { - this(""); - } - - public PlainTextTemplateNode(String aText) { - text = aText; - } - - public void appendText(String aText) { - text = text + aText; - } - - protected String getText() { - return text; - } - - public void process(TALExpressionParser aParser, Object aContext, StringBuffer aDestination) { - aDestination.append(text); - } - } - - public static class SmartTemplateNode implements TemplateNode { - private String tag; - private Map fixedAttributes; - private Map attributeModifiers; - - private List definitions; - private Object condition; - - private Object repeatVariable; - private Object repeatExpression; - private Object contentExpression; - private Object omitTagExpression; - private Object errorExpression; - - private TemplateNode body; - - public SmartTemplateNode(String aTag) { - tag = aTag; - - fixedAttributes = new HashMap(); - attributeModifiers = new HashMap(); - - definitions = new Vector(); - condition = null; - - repeatVariable = null; - repeatExpression = null; - contentExpression = null; - omitTagExpression = null; - - body = null; - } - - public void setBody(TemplateNode aBody) { - body = aBody; - } - - public void addFixedAttribute(String aKey, String aValue) { - fixedAttributes.put(aKey, aValue); - } - - public void addModifiedAttribute(String aKey, Object aValue) { - attributeModifiers.put(aKey, aValue); - } - - public void addDefinition(Object aKey, Object aValue) { - definitions.add(new Definition(aKey, aValue)); - } - - public void setCondition(Object aCondition) { - condition = aCondition; - } - - public void setRepeat(Object aRepeatVariable, Object aRepeatExpression) { - repeatVariable = aRepeatVariable; - repeatExpression = aRepeatExpression; - } - - public void setContent(Object aContentExpression) { - contentExpression = aContentExpression; - } - - public void setOmitTag(Object anOmitTagExpression) { - omitTagExpression = anOmitTagExpression; - } - - public void setError(Object anErrorExpression) { - errorExpression = anErrorExpression; - } - - public static class Definition { - private Object variable; - private Object expression; - - public Definition(Object aVariable, Object anExpression) { - variable = aVariable; - expression = anExpression; - } - - public Object getVariable() { - return variable; - } - - public Object getExpression() { - return expression; - } - } - - public void process(TALExpressionParser aParser, Object aContext, StringBuffer aDestination) { - Iterator i; - - i = definitions.iterator(); - while (i.hasNext()) { - Definition d = (Definition) i.next(); - aParser.processAssignment(aContext, d.getVariable(), d.getExpression()); - } - - if (condition == null || aParser.evaluateBooleanExpression(aContext, condition)) { - if (repeatExpression != null) { - i = aParser.evaluateListExpression(aContext, repeatExpression); - - while (i.hasNext()) { - aParser.processDirectAssignment(aContext, repeatVariable, i.next()); - innerProcess(aParser, aContext, aDestination); - } - } - else { - innerProcess(aParser, aContext, aDestination); - } - } - }; - - private void innerProcess(TALExpressionParser aParser, Object aContext, StringBuffer aDestination) { - boolean omitTag = false; - if (omitTagExpression != null) - omitTag = aParser.evaluateBooleanExpression(aContext, omitTagExpression); - - if (!omitTag) { - Map generatedAttributes = new HashMap(fixedAttributes); - - Iterator i = attributeModifiers.keySet().iterator(); - while (i.hasNext()) { - Map.Entry entry = (Map.Entry) i.next(); - - generatedAttributes.put(entry.getKey(), aParser.evaluateStringExpression(aContext, entry.getValue())); - } - - aDestination.append("<"); - aDestination.append(tag); - - i = generatedAttributes.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry entry = (Map.Entry) i.next(); - aDestination.append(" "); - aDestination.append(entry.getKey()); - aDestination.append("="); - aDestination.append("\""); - aDestination.append(HTMLRoutines.encodeHTML( (String) entry.getValue())); - aDestination.append("\""); - } - aDestination.append(">"); - } - - StringBuffer destination = aDestination; - if (errorExpression != null) { - destination = new StringBuffer(); - } - try { - if (contentExpression != null) { - destination.append(aParser.evaluateStringExpression(aContext, contentExpression)); - } - else { - if (body != null) - body.process(aParser, aContext, destination); - } - } - catch (RuntimeException t) { - if (errorExpression != null) { - try { - destination.delete(0, destination.length()); - - aParser.processPseudoAssignment(aContext, "exception", t); - destination.append(aParser.evaluateStringExpression(aContext, errorExpression)); - } - catch (Throwable s) { - } - } - else - throw t; - } - finally { - if (errorExpression != null) { - aDestination.append(destination); - } - } - if (!omitTag) { - aDestination.append(""); - } - } - } +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. + */ +package mir.generator.tal; + +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import mir.generator.tal.interfaces.TALExpressionParser; +import mir.generator.tal.interfaces.TALLogger; +import mir.util.HTMLRoutines; + +/** + * + * + * + * @see TAL Spec + */ + +public class TALTemplate { + private TemplateNode rootNode; + private TALExpressionParser parser; + + public TALTemplate(TALExpressionParser aParser, TemplateNode aRootNode) { + rootNode = aRootNode; + parser = aParser; + } + + public void processTemplate(Object aContext, PrintWriter aDestination, TALLogger aLogger) throws TemplateProcessingException { + StringBuffer output = new StringBuffer(); + + aLogger.debug("TALTemplate", "processing rootnode"); + rootNode.process(parser, aContext, output, aLogger); + aLogger.debug("TALTemplate", "done processing rootnode"); + aDestination.print(output); + } + + public interface TemplateNode { + public void process(TALExpressionParser aParser, Object aContext, StringBuffer aDestination, TALLogger aLogger) throws TemplateProcessingException; + } + + public static class CompositeTemplateNode + implements TemplateNode { + private List parts; + + public CompositeTemplateNode() { + parts = new Vector(); + } + + public void process(TALExpressionParser aParser, Object aContext, StringBuffer aDestination, TALLogger aLogger) throws TemplateProcessingException { + Iterator i = parts.iterator(); + + while (i.hasNext()) { + ((TemplateNode) i.next()).process(aParser, aContext, aDestination, aLogger); + } + } + + public void appendSubNode(TemplateNode aNode) { + if (aNode instanceof CompositeTemplateNode) { + Iterator i = ((CompositeTemplateNode) aNode).parts.iterator(); + while (i.hasNext()) { + appendSubNode((TemplateNode) i.next()); + } + } + else if (aNode instanceof PlainTextTemplateNode && parts.size()>0 && + (parts.get(parts.size()-1) instanceof PlainTextTemplateNode)) { + + ((PlainTextTemplateNode) parts.get(parts.size()-1)).appendText(((PlainTextTemplateNode) aNode).getText()); + } + else { + parts.add(aNode); + } + } + } + + public static class PlainTextTemplateNode + implements TemplateNode { + private String text; + + public PlainTextTemplateNode() { + this(""); + } + + public PlainTextTemplateNode(String aText) { + text = aText; + } + + public void appendText(String aText) { + text = text + aText; + } + + protected String getText() { + return text; + } + + public void process(TALExpressionParser aParser, Object aContext, StringBuffer aDestination, TALLogger aLogger) throws TemplateProcessingException { + aDestination.append(text); + } + } + + public static class SmartTemplateNode implements TemplateNode { + private String tag; + private Map fixedAttributes; + private Map attributeModifiers; + + private List definitions; + private Object condition; + + private Object repeatVariable; + private Object repeatExpression; + private Object contentExpression; + private Object omitTagExpression; + private Object errorExpression; + + private TemplateNode body; + + public SmartTemplateNode(String aTag) { + tag = aTag; + + fixedAttributes = new HashMap(); + attributeModifiers = new HashMap(); + + definitions = new Vector(); + condition = null; + + repeatVariable = null; + repeatExpression = null; + contentExpression = null; + omitTagExpression = null; + + body = null; + } + + public void setBody(TemplateNode aBody) { + body = aBody; + } + + public void addFixedAttribute(String aKey, String aValue) { + fixedAttributes.put(aKey, aValue); + } + + public void addModifiedAttribute(String aKey, Object aValue) { + attributeModifiers.put(aKey, aValue); + } + + public void addDefinition(Object aKey, Object aValue) { + definitions.add(new Definition(aKey, aValue)); + } + + public void setCondition(Object aCondition) { + condition = aCondition; + } + + public void setRepeat(Object aRepeatVariable, Object aRepeatExpression) { + repeatVariable = aRepeatVariable; + repeatExpression = aRepeatExpression; + } + + public void setContent(Object aContentExpression) { + contentExpression = aContentExpression; + } + + public void setOmitTag(Object anOmitTagExpression) { + omitTagExpression = anOmitTagExpression; + } + + public void setError(Object anErrorExpression) { + errorExpression = anErrorExpression; + } + + public static class Definition { + private Object variable; + private Object expression; + + public Definition(Object aVariable, Object anExpression) { + variable = aVariable; + expression = anExpression; + } + + public Object getVariable() { + return variable; + } + + public Object getExpression() { + return expression; + } + } + + public void process(TALExpressionParser aParser, Object aContext, StringBuffer aDestination, TALLogger aLogger) throws TemplateProcessingException { + Iterator i; + + i = definitions.iterator(); + while (i.hasNext()) { + Definition d = (Definition) i.next(); + aParser.processAssignment(aContext, d.getVariable(), d.getExpression()); + } + + if (condition == null || aParser.evaluateBooleanExpression(aContext, condition)) { + if (repeatExpression != null) { + i = aParser.evaluateListExpression(aContext, repeatExpression); + + while (i.hasNext()) { + aParser.processDirectAssignment(aContext, repeatVariable, i.next()); + innerProcess(aParser, aContext, aDestination, aLogger); + } + } + else { + innerProcess(aParser, aContext, aDestination, aLogger); + } + } + }; + + private void innerProcess(TALExpressionParser aParser, Object aContext, StringBuffer aDestination, TALLogger aLogger) + throws TemplateProcessingException + { + boolean omitTag = false; + if (omitTagExpression != null) + omitTag = aParser.evaluateBooleanExpression(aContext, omitTagExpression); + + if (!omitTag) { + Map generatedAttributes = new HashMap(fixedAttributes); + + Iterator i = attributeModifiers.keySet().iterator(); + while (i.hasNext()) { + Map.Entry entry = (Map.Entry) i.next(); + + generatedAttributes.put(entry.getKey(), aParser.evaluateStringExpression(aContext, entry.getValue())); + } + + aDestination.append("<"); + aDestination.append(tag); + + i = generatedAttributes.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry entry = (Map.Entry) i.next(); + aDestination.append(" "); + aDestination.append(entry.getKey()); + aDestination.append("="); + aDestination.append("\""); + aDestination.append(HTMLRoutines.encodeHTML( (String) entry.getValue())); + aDestination.append("\""); + } + aDestination.append(">"); + } + + StringBuffer destination = aDestination; + if (errorExpression != null) { + destination = new StringBuffer(); + } + try { + if (contentExpression != null) { + destination.append(aParser.evaluateStringExpression(aContext, contentExpression)); + } + else { + if (body != null) + body.process(aParser, aContext, destination, aLogger); + } + } + catch (Throwable t) { + if (!(t instanceof TemplateProcessingException)) + aLogger.error("TALTemplate.SmartTemplateNode.processs", "exception occurred: " + t.toString()); + if (errorExpression != null) { + try { + destination.delete(0, destination.length()); + + aParser.processPseudoAssignment(aContext, "exception", t); + destination.append(aParser.evaluateStringExpression(aContext, errorExpression)); + } + catch (Throwable s) { + } + } + else { + throw new TemplateProcessingException(t); + } + } + finally { + if (errorExpression != null) { + aDestination.append(destination); + } + } + if (!omitTag) { + aDestination.append(""); + } + } + } + + public static class TemplateProcessingException extends Exception { + private Throwable cause; + + public TemplateProcessingException(Throwable aCause) { + this (aCause.getMessage(), aCause); + } + + public TemplateProcessingException(String aMessage, Throwable aCause) { + super(aMessage); + + cause = aCause; + } + + public TemplateProcessingException(String aMessage) { + this(aMessage, null); + } + } } \ No newline at end of file diff --git a/source/mir/generator/tal/TALTemplateEngine.java b/source/mir/generator/tal/TALTemplateEngine.java index 47596183..13125bf0 100755 --- a/source/mir/generator/tal/TALTemplateEngine.java +++ b/source/mir/generator/tal/TALTemplateEngine.java @@ -55,7 +55,7 @@ public class TALTemplateEngine { private class TemplateFactory implements CachingFileLoader.CachedFileObjectFactory { public Object constructObject(InputStream aStream) { try { - return TALTemplateParser.parseInputStream(aStream, expressionParser); + return TALTemplateParser.parse(aStream, expressionParser); } catch (Throwable t) { throw new TALFailure(t); diff --git a/source/mir/generator/tal/TALTemplateParser.java b/source/mir/generator/tal/TALTemplateParser.java index f63876d7..deacff9b 100755 --- a/source/mir/generator/tal/TALTemplateParser.java +++ b/source/mir/generator/tal/TALTemplateParser.java @@ -30,6 +30,9 @@ package mir.generator.tal; import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -37,42 +40,37 @@ import java.util.Map; import mir.generator.tal.interfaces.TALExpressionParser; import mir.util.HTMLRoutines; import mir.util.StringRoutines; -import mir.util.XMLReader; -import mir.util.XMLReader.AbstractSectionHandler; +import mir.util.xml.XMLParserExc; +import mir.util.xml.XMLParserEngine; +import mir.util.xml.XMLParserFailure; +import mir.util.xml.SectionHandler; +import mir.util.xml.XMLName; public class TALTemplateParser { - private int bal; private static final String TAL_PREFIX = "tal"; - public static TALTemplate parseString(String aData, TALExpressionParser aParser) throws TALExc, TALFailure { - try { - TALHandler handler = new TALHandler(aParser); - XMLReader reader = new XMLReader(false); - - reader.parseString(true, aData, handler); - - return new TALTemplate(aParser, handler.getNode()); - } - catch (Throwable t) { - throw new TALFailure(t); - } + public static TALTemplate parse(String aData, TALExpressionParser aParser) throws TALExc, TALFailure { + return parse(new StringReader(aData), aParser); } - public static TALTemplate parseInputStream(InputStream anInputStream, TALExpressionParser aParser) throws TALExc, TALFailure { - try { - TALHandler handler = new TALHandler(aParser); - XMLReader reader = new XMLReader(false); + public static TALTemplate parse(InputStream anInputStream, TALExpressionParser aParser) throws TALExc, TALFailure { + return parse(new InputStreamReader(anInputStream), aParser); + } - reader.parseInputStream(true, anInputStream, handler); + public static TALTemplate parse(Reader aReader, TALExpressionParser aParser) throws TALExc, TALFailure { + TALHandler handler = new TALHandler(aParser); - return new TALTemplate(aParser, handler.getNode()); + try { + XMLParserEngine.getInstance().parse("html", aReader, handler); } - catch (Throwable t) { - throw new TALFailure(t); + catch (XMLParserExc e) { + throw new TALFailure(e); } + + return new TALTemplate(aParser, handler.getNode()); } - private static String normalizeXMLName(XMLReader.XMLName aName) { + private static String normalizeXMLName(mir.util.xml.XMLName aName) { String result = aName.getLocalName(); if (aName.getPrefix().length() > 0) result = aName.getPrefix() + ":" + result; @@ -80,20 +78,16 @@ public class TALTemplateParser { return result; } - - private static final String CONDITION_ATTRIBUTE = "condition"; private static final String REPEAT_ATTRIBUTE = "repeat"; private static final String CONTENT_ATTRIBUTE = "content"; private static final String ERROR_ATTRIBUTE = "on-error"; private static final String REPLACE_ATTRIBUTE = "replace"; private static final String DEFINITION_ATTRIBUTE = "define"; - private static final String ONERROR_ATTRIBUTE = "onerror"; private static final String OMITTAG_ATTRIBUTE = "omit-tag"; private static final String ATTRIBUTE_ATTRIBUTE = "attributes"; - - protected static class TALHandler extends XMLReader.AbstractSectionHandler { + protected static class TALHandler implements SectionHandler { private TALTemplate.CompositeTemplateNode compositeNode; private StringBuffer data; private TALExpressionParser parser; @@ -114,18 +108,20 @@ public class TALTemplateParser { } } - public XMLReader.SectionHandler startElement(XMLReader.XMLName aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public void extra(String anExtraData) throws XMLParserExc, XMLParserFailure { + appendCode(anExtraData); + } + + public SectionHandler startElement(mir.util.xml.XMLName aTag, Map anAttributes) throws XMLParserExc { smartTag = false; currentTag = normalizeXMLName(aTag); - smartTag = (aTag.getPrefix().equals(TAL_PREFIX)); Iterator i = anAttributes.keySet().iterator(); - while (!smartTag && i.hasNext()) { - String name = (String) i.next(); - smartTag = smartTag || (name.startsWith(TAL_PREFIX+":")); + XMLName name = (XMLName) i.next(); + smartTag = smartTag || (name.getPrefix().equals(TAL_PREFIX)); } if (!smartTag) { @@ -135,7 +131,7 @@ public class TALTemplateParser { while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); - appendCode(" "+ entry.getKey()); + appendCode(" "+ normalizeXMLName((XMLName) entry.getKey())); appendCode("=\""); appendText((String) entry.getValue()); appendCode("\""); @@ -150,68 +146,65 @@ public class TALTemplateParser { i = anAttributes.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); - String fullAttributeName = (String) entry.getKey(); - List attributeParts = StringRoutines.separateString(fullAttributeName, ":"); - String prefix = ""; - String name = ""; - if (attributeParts.size()==2) { - name = (String) attributeParts.get(1); - prefix = (String) attributeParts.get(0); - } - else { - name = (String) attributeParts.get(0); - } + XMLName name = (XMLName) entry.getKey(); - if (!prefix.equals(TAL_PREFIX)) { - smartNode.addFixedAttribute(fullAttributeName, (String) entry.getValue()); + if (!name.getPrefix().equals(TAL_PREFIX)) { + smartNode.addFixedAttribute(normalizeXMLName(name), (String) entry.getValue()); } else { - if (name.equalsIgnoreCase(DEFINITION_ATTRIBUTE)) { + if (name.getLocalName().equalsIgnoreCase(DEFINITION_ATTRIBUTE)) { List definitions = StringRoutines.splitStringWithEscape((String) entry.getValue(), ';', '\\'); - Iterator j = definitions.iterator(); { - List parts = StringRoutines.separateString((String) i.next(), " "); + Iterator j = definitions.iterator(); + while (j.hasNext()) + { + List parts = StringRoutines.separateString((String) j.next(), " "); if (parts.size()==2) { smartNode.addDefinition(parser.preparseReferenceExpression((String) parts.get(0)), parser.preparseExpression((String) parts.get(1))); } } } - else if (name.equalsIgnoreCase(CONDITION_ATTRIBUTE)) { + else if (name.getLocalName().equalsIgnoreCase(CONDITION_ATTRIBUTE)) { smartNode.setCondition(parser.preparseBooleanExpression((String) entry.getValue())); } - else if (name.equalsIgnoreCase(CONTENT_ATTRIBUTE)) { + else if (name.getLocalName().equalsIgnoreCase(CONTENT_ATTRIBUTE)) { smartNode.setContent(parser.preparseStringExpression((String) entry.getValue())); } - else if (name.equalsIgnoreCase(ERROR_ATTRIBUTE)) { + else if (name.getLocalName().equalsIgnoreCase(ERROR_ATTRIBUTE)) { smartNode.setError(parser.preparseStringExpression((String) entry.getValue())); } - else if (name.equalsIgnoreCase(OMITTAG_ATTRIBUTE)) { + else if (name.getLocalName().equalsIgnoreCase(OMITTAG_ATTRIBUTE)) { if (((String) entry.getValue()).trim().length()==0) smartNode.setOmitTag(parser.preparseTRUE()); else smartNode.setOmitTag(parser.preparseBooleanExpression((String) entry.getValue())); } - else if (name.equalsIgnoreCase(REPLACE_ATTRIBUTE)) { + else if (name.getLocalName().equalsIgnoreCase(REPLACE_ATTRIBUTE)) { smartNode.setOmitTag(parser.preparseTRUE()); smartNode.setContent(parser.preparseStringExpression((String) entry.getValue())); } - else if (name.equalsIgnoreCase(REPEAT_ATTRIBUTE)) { + else if (name.getLocalName().equalsIgnoreCase(REPEAT_ATTRIBUTE)) { List parts = StringRoutines.separateString((String) entry.getValue(), " "); if (parts.size()==2) { smartNode.setRepeat(parser.preparseReferenceExpression((String) parts.get(0)), parser.preparseExpression((String) parts.get(1))); } } - else if (name.equalsIgnoreCase(ATTRIBUTE_ATTRIBUTE)) { + else if (name.getLocalName().equalsIgnoreCase(ATTRIBUTE_ATTRIBUTE)) { List attributes = StringRoutines.splitStringWithEscape((String) entry.getValue(), ';', '\\'); - Iterator j = attributes.iterator(); { - List parts = StringRoutines.separateString((String) i.next(), " "); + Iterator j = attributes.iterator(); + while (j.hasNext()) { + String value = (String) j.next(); + List parts = StringRoutines.separateString(value, " "); if (parts.size()==2) { smartNode.addModifiedAttribute((String) parts.get(0), parser.preparseExpression((String) parts.get(1))); } + else { + throw new XMLParserExc(ATTRIBUTE_ATTRIBUTE + " tag should have exactly 2 parts ("+value+")"); + } } } } @@ -223,7 +216,7 @@ public class TALTemplateParser { return new TALHandler(parser); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { if (!smartTag) { appendSubNode(((TALHandler) aHandler).getNode()); appendCode(""); @@ -247,7 +240,7 @@ public class TALTemplateParser { data.append(HTMLRoutines.encodeHTML(aText)); } - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { flushData(); } @@ -255,8 +248,11 @@ public class TALTemplateParser { return compositeNode; } - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { appendText(aCharacters); } + + public void startSection() throws XMLParserExc, XMLParserFailure { + } } } diff --git a/source/mir/generator/tal/TALTest.java b/source/mir/generator/tal/TALTest.java index d40df51c..cbc89fe9 100755 --- a/source/mir/generator/tal/TALTest.java +++ b/source/mir/generator/tal/TALTest.java @@ -27,33 +27,85 @@ * exception to your version of the file, but you are not obligated to do so. * If you do not wish to do so, delete this exception statement from your version. */ + package mir.generator.tal; -import java.io.PrintWriter; +import java.io.*; import java.util.HashMap; -import java.util.Map; +import java.util.*; +import mir.generator.tal.interfaces.*; +import mir.util.xml.html.*; public class TALTest { public static void main(String args[]) { try { - int b=4; - int c=6; - int a = b = c; - TALTemplateParser parser = new TALTemplateParser(); MirExpressionParser expressionParser = new MirExpressionParser(); Map test = new HashMap(); test.put("name", "zapata"); - TALTemplate template = parser.parseString("

test

", expressionParser); + HTMLParser parser2 = new HTMLParser(); +/* + parser2.parse(new StringReader(" "), + new HTMLParser.ParserReceiver() { + + public void dtd(String aDTD) { + System.out.println(aDTD); + } + + public void openTag(String aTag, Map anAttributes) { + + System.out.print("<"+aTag); + Iterator i = anAttributes.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry entry = (Map.Entry) i.next(); + + System.out.print(" " + entry.getKey() + "=\"" + entry.getValue()+"\""); + } + System.out.print(">"); + } + + public void closeTag(String aTag) { + System.out.print(""); + } + + public void comment(String aData) { + } + + public void cdata(String aData) { + System.out.print(aData); + } + } + ); +*/ +String doc = +" " + +" "+ +" "+ +" <meta name=\"description\" tal:attributes=\"content lang('posting.meta.description')\">"+ +" <meta name=\"author\" content=\"${lang(\"posting.meta.author\")}\">"+ +" <meta name=\"keywords\" content=\"${lang(\"posting.meta.keywords\")}\">"+ +" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=${config['Mir.DefaultHTMLCharset']}\">"+ +" <meta name=\"robots\" content=\"index\">"+ +" <meta name=\"robots\" content=\"follow\">"+ +" <link rel=stylesheet type=\"text/css\" href=\"${config['Producer.ProductionHost']}/style/formate.css\">"+ +" </head>"+ +" <body bgcolor=\"white\" text=\"black\" link=\"#006600\" vlink=\"#006600\" alink=\"Red\" tal:on-error='exception.message'>"+ +" </body>"+ +"</html>"; + System.out.println(doc); + TALTemplate template = parser.parse(doc, expressionParser); + + +// <td tal:on-error='exception.message'><tal:test tal:content='name.bla'></tal:test><h1 tal:content=\"name\">test</h1></TD>", expressionParser); PrintWriter o = new PrintWriter(System.out); - template.processTemplate(test, o); + template.processTemplate(test, o, new TALLogger.TALSystemOutLogger()); o.close(); + } catch (Throwable t) { System.out.println("Exception: " + t.toString()); t.printStackTrace(System.out); } - } } \ No newline at end of file diff --git a/source/mir/generator/tal/interfaces/TALExpressionParser.java b/source/mir/generator/tal/interfaces/TALExpressionParser.java index 66b8262d..c8f6d45b 100755 --- a/source/mir/generator/tal/interfaces/TALExpressionParser.java +++ b/source/mir/generator/tal/interfaces/TALExpressionParser.java @@ -27,6 +27,7 @@ * exception to your version of the file, but you are not obligated to do so. * If you do not wish to do so, delete this exception statement from your version. */ + package mir.generator.tal.interfaces; import java.util.Iterator; diff --git a/source/mir/generator/tal/interfaces/TALLogger.java b/source/mir/generator/tal/interfaces/TALLogger.java new file mode 100755 index 00000000..0b7a8ddb --- /dev/null +++ b/source/mir/generator/tal/interfaces/TALLogger.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. + */ + +package mir.generator.tal.interfaces; + +public interface TALLogger { + public void debug(String anObject, String aMessage); + public void info(String anObject, String aMessage); + public void warning(String anObject, String aMessage); + public void error(String anObject, String aMessage); + public void fatal(String anObject, String aMessage); + + /** + * Simple logging class that logs everything to System.out + */ + public class TALSystemOutLogger implements TALLogger { + public TALSystemOutLogger() { + } + + public void debug(String anObject, String aMessage) { + System.out.println("DEBUG: " + anObject + " " + aMessage); + + } + + public void info(String anObject, String aMessage) { + System.out.println("INFO: " + anObject + " " + aMessage); + } + + public void warning(String anObject, String aMessage) { + System.out.println("WARNING: " + anObject + " " + aMessage); + } + + public void error(String anObject, String aMessage) { + System.out.println("ERROR: " + anObject + " " + aMessage); + } + + public void fatal(String anObject, String aMessage) { + System.out.println("FATAL: " + anObject + " " + aMessage); + } + } + + /** + * Simple logging class that discards all logging information. + */ + public class TALVoidLogger implements TALLogger { + public void debug(String anObject, String aMessage) { + } + + public void info(String anObject, String aMessage) { + } + + public void warning(String anObject, String aMessage) { + } + + public void error(String anObject, String aMessage) { + } + + public void fatal(String anObject, String aMessage) { + } + } +} \ No newline at end of file diff --git a/source/mir/producer/ScriptCallingProducerNode.java b/source/mir/producer/ScriptCallingProducerNode.java index df2ad07d..75c51918 100755 --- a/source/mir/producer/ScriptCallingProducerNode.java +++ b/source/mir/producer/ScriptCallingProducerNode.java @@ -1,59 +1,106 @@ -/* - * Copyright (C) 2001, 2002 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. - * If you do not wish to do so, delete this exception statement from your version. - */ -package mir.producer; - -import java.util.Map; - -import mir.log.LoggerWrapper; -import mir.util.ParameterExpander; - -public class ScriptCallingProducerNode implements ProducerNode { - String scriptExpression; - - public ScriptCallingProducerNode(String aScriptExpression) { - scriptExpression = aScriptExpression; - } - - public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure { - String script; - Process process; - int returnValue; - - try { - script = ParameterExpander.expandExpression( aValueMap, scriptExpression ); - process = Runtime.getRuntime().exec(script); - returnValue = process.waitFor(); - aLogger.info(script + " terminated successfully, return value = " + returnValue + "."); - } - catch (Throwable e) { - aLogger.error(scriptExpression + " failed to execute: " + e.getMessage()); - } - } -} +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. + */ +package mir.producer; + +import java.util.Map; + +import mir.log.LoggerWrapper; +import mir.util.ParameterExpander; + +public class ScriptCallingProducerNode implements ProducerNode { + private String scriptExpression; + private String maxDurationExpression; + + public ScriptCallingProducerNode(String aScriptExpression, String aMaxDurationExpression) { + scriptExpression = aScriptExpression; + maxDurationExpression = aMaxDurationExpression; + } + + public void produce(Map aValueMap, String aVerb, LoggerWrapper aLogger) throws ProducerFailure { + String script; + long maxDuration; + Process process; + int returnValue; + + try { + script = ParameterExpander.expandExpression(aValueMap, scriptExpression); + maxDuration = ParameterExpander.evaluateIntegerExpressionWithDefault(aValueMap, maxDurationExpression, 0); + + ProcessRunner runner = new ProcessRunner(Runtime.getRuntime().exec(script)); + runner.start(); + synchronized (runner) { + runner.wait(maxDuration); + } + runner.interrupt(); + + if (runner.getFinished()) { + aLogger.info(script + " terminated successfully, return value = " + runner.getReturnValue() + "."); + } + else { + aLogger.info(script + " interrupted prematurely after " + maxDuration + "ms."); + } + } + catch (Throwable e) { + aLogger.error(scriptExpression + " failed to execute: " + e.getMessage()); + } + } + + private static class ProcessRunner extends Thread { + private Process process; + private boolean finished = false; + private int returnValue = 0; + + public ProcessRunner(Process aProcess) { + process = aProcess; + } + + public boolean getFinished() { + return finished; + } + + public int getReturnValue() { + return returnValue; + } + + public void run() { + try { + returnValue = process.waitFor(); + finished = true; + synchronized (this) { + this.notify(); + } + } + catch (InterruptedException e) { + process.destroy(); + } + } + } + +} diff --git a/source/mir/producer/reader/DefaultProducerNodeBuilders.java b/source/mir/producer/reader/DefaultProducerNodeBuilders.java index cac15306..b3024f19 100755 --- a/source/mir/producer/reader/DefaultProducerNodeBuilders.java +++ b/source/mir/producer/reader/DefaultProducerNodeBuilders.java @@ -63,8 +63,8 @@ import mir.producer.RSSProducerNode; import mir.producer.ResourceBundleProducerNode; import mir.producer.ScriptCallingProducerNode; import mir.util.StringRoutines; -import mir.util.XMLReader; -import mir.util.XMLReaderTool; +import mir.util.xml.*; +import mir.util.xml.XMLReaderTool; public class DefaultProducerNodeBuilders { @@ -102,12 +102,10 @@ public class DefaultProducerNodeBuilders { } public static abstract class AbstractProducerNodeBuilder implements ProducerNodeBuilder { - private Map attributes; private Map subNodes; private Set availableSubnodes; public AbstractProducerNodeBuilder(String anAvailableSubNodes[]) { - attributes = new HashMap(); subNodes = new HashMap(); availableSubnodes = new HashSet(Arrays.asList(anAvailableSubNodes)); } @@ -155,8 +153,8 @@ public class DefaultProducerNodeBuilders { super(ASSIGNMENT_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, ASSIGNMENT_REQUIRED_ATTRIBUTES, ASSIGNMENT_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, ASSIGNMENT_REQUIRED_ATTRIBUTES, ASSIGNMENT_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get(ASSIGNMENT_KEY_ATTRIBUTE); value = (String) anAttributes.get(ASSIGNMENT_VALUE_ATTRIBUTE); @@ -178,8 +176,8 @@ public class DefaultProducerNodeBuilders { super(ASSIGNMENT_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, ASSIGNMENT_REQUIRED_ATTRIBUTES, ASSIGNMENT_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, ASSIGNMENT_REQUIRED_ATTRIBUTES, ASSIGNMENT_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get(ASSIGNMENT_KEY_ATTRIBUTE); value = (String) anAttributes.get(ASSIGNMENT_VALUE_ATTRIBUTE); @@ -225,7 +223,7 @@ public class DefaultProducerNodeBuilders { model = aModel; } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { definition = (String) anAttributes.get(ENUMERATION_DEFINITION_ATTRIBUTE); list = (String) anAttributes.get(ENUMERATION_LIST_ATTRIBUTE); @@ -234,17 +232,17 @@ public class DefaultProducerNodeBuilders { if (list!=null) - XMLReaderTool.checkAttributes(anAttributes, ENUMERATION_LIST_REQUIRED_ATTRIBUTES, ENUMERATION_LIST_OPTIONAL_ATTRIBUTES); + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, ENUMERATION_LIST_REQUIRED_ATTRIBUTES, ENUMERATION_LIST_OPTIONAL_ATTRIBUTES); if (definition!=null) - XMLReaderTool.checkAttributes(anAttributes, ENUMERATION_QUERY_REQUIRED_ATTRIBUTES, ENUMERATION_QUERY_OPTIONAL_ATTRIBUTES); + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, ENUMERATION_QUERY_REQUIRED_ATTRIBUTES, ENUMERATION_QUERY_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get(ENUMERATION_KEY_ATTRIBUTE); - selection = (String) XMLReaderTool.getStringAttributeWithDefault(anAttributes, ENUMERATION_SELECTION_ATTRIBUTE, ""); - order = (String) XMLReaderTool.getStringAttributeWithDefault(anAttributes, ENUMERATION_ORDER_ATTRIBUTE, ""); + selection = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, ENUMERATION_SELECTION_ATTRIBUTE, ""); + order = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, ENUMERATION_ORDER_ATTRIBUTE, ""); limit = (String) anAttributes.get(ENUMERATION_LIMIT_ATTRIBUTE); skip = (String) anAttributes.get(ENUMERATION_SKIP_ATTRIBUTE); - extraTables = StringRoutines.splitString(XMLReaderTool.getStringAttributeWithDefault(anAttributes, ENUMERATION_EXTRATABLES_ATTRIBUTE,"").trim(), ","); + extraTables = StringRoutines.splitString(mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, ENUMERATION_EXTRATABLES_ATTRIBUTE,"").trim(), ","); if (definition!=null) { List parts = StringRoutines.splitString(definition.trim(), " "); if (parts.size() > 0) @@ -294,11 +292,11 @@ public class DefaultProducerNodeBuilders { fieldValues = new HashMap(); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { key = (String) anAttributes.get(UPDATE_KEY_ATTRIBUTE); if (key == null) - throw new XMLReader.XMLReaderExc("missing required attribute '" + UPDATE_KEY_ATTRIBUTE + "'" ); + throw new XMLParserExc("missing required attribute '" + UPDATE_KEY_ATTRIBUTE + "'" ); definition = (String) anAttributes.get(UPDATE_DEFINITION_ATTRIBUTE); fieldValues.putAll(anAttributes); @@ -343,14 +341,14 @@ public class DefaultProducerNodeBuilders { fieldValues = new HashMap(); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { key = (String) anAttributes.get(CREATEENTITY_KEY_ATTRIBUTE); definition = (String) anAttributes.get(CREATEENTITY_DEFINITION_ATTRIBUTE); if (key == null) - throw new XMLReader.XMLReaderExc("missing required attribute '" + CREATEENTITY_KEY_ATTRIBUTE + "'" ); + throw new XMLParserExc("missing required attribute '" + CREATEENTITY_KEY_ATTRIBUTE + "'" ); if (definition == null) - throw new XMLReader.XMLReaderExc("missing required attribute '" + CREATEENTITY_DEFINITION_ATTRIBUTE + "'" ); + throw new XMLParserExc("missing required attribute '" + CREATEENTITY_DEFINITION_ATTRIBUTE + "'" ); fieldValues.putAll(anAttributes); fieldValues.remove(CREATEENTITY_KEY_ATTRIBUTE); @@ -391,11 +389,11 @@ public class DefaultProducerNodeBuilders { super(LOOP_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, LOOP_REQUIRED_ATTRIBUTES, LOOP_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, LOOP_REQUIRED_ATTRIBUTES, LOOP_OPTIONAL_ATTRIBUTES); condition = (String) anAttributes.get(LOOP_CONDITION_ATTRIBUTE); - limit = (String) XMLReaderTool.getStringAttributeWithDefault(anAttributes, LOOP_LIMIT_ATTRIBUTE, ""); + limit = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, LOOP_LIMIT_ATTRIBUTE, ""); }; public ProducerNode constructNode() { @@ -411,7 +409,6 @@ public class DefaultProducerNodeBuilders { private final static String LIST_SELECTION_ATTRIBUTE = SELECTION_ATTRIBUTE; private final static String LIST_EXTRATABLES_ATTRIBUTE = "extratables"; private final static String LIST_ORDER_ATTRIBUTE = ORDER_ATTRIBUTE; - private final static String LIST_DEFAULT_SUBNODE = "default"; private final static String LIST_LIMIT_ATTRIBUTE = LIMIT_ATTRIBUTE; private final static String LIST_SKIP_ATTRIBUTE = SKIP_ATTRIBUTE; private final static String[] LIST_REQUIRED_ATTRIBUTES = { LIST_KEY_ATTRIBUTE, LIST_DEFINITION_ATTRIBUTE }; @@ -434,16 +431,16 @@ public class DefaultProducerNodeBuilders { model = aModel; } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, LIST_REQUIRED_ATTRIBUTES, LIST_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, LIST_REQUIRED_ATTRIBUTES, LIST_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get(LIST_KEY_ATTRIBUTE); definition = (String) anAttributes.get(LIST_DEFINITION_ATTRIBUTE); - selection = (String) XMLReaderTool.getStringAttributeWithDefault(anAttributes, LIST_SELECTION_ATTRIBUTE, ""); - order = (String) XMLReaderTool.getStringAttributeWithDefault(anAttributes, LIST_ORDER_ATTRIBUTE, ""); + selection = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, LIST_SELECTION_ATTRIBUTE, ""); + order = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, LIST_ORDER_ATTRIBUTE, ""); limit = (String) anAttributes.get(LIST_LIMIT_ATTRIBUTE); skip = (String) anAttributes.get(LIST_SKIP_ATTRIBUTE); - extraTables = StringRoutines.splitString(XMLReaderTool.getStringAttributeWithDefault(anAttributes, LIST_EXTRATABLES_ATTRIBUTE,"").trim(), ","); + extraTables = StringRoutines.splitString(mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, LIST_EXTRATABLES_ATTRIBUTE,"").trim(), ","); List parts = StringRoutines.splitString(definition.trim()," "); if (parts.size()>0) definition=(String)parts.get(0); if (parts.size()>1) mainTablePrefix=(String)parts.get(1); @@ -487,11 +484,11 @@ public class DefaultProducerNodeBuilders { model = aModel; } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, DELETEENTITY_REQUIRED_ATTRIBUTES, DELETEENTITY_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, DELETEENTITY_REQUIRED_ATTRIBUTES, DELETEENTITY_OPTIONAL_ATTRIBUTES); definition = (String) anAttributes.get(DELETEENTITY_DEFINITION_ATTRIBUTE); - selection = (String) XMLReaderTool.getStringAttributeWithDefault(anAttributes, DELETEENTITY_SELECTION_ATTRIBUTE, ""); + selection = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, DELETEENTITY_SELECTION_ATTRIBUTE, ""); }; public ProducerNode constructNode() { @@ -527,10 +524,10 @@ public class DefaultProducerNodeBuilders { super(LOG_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { String typeString; - XMLReaderTool.checkAttributes(anAttributes, LOG_REQUIRED_ATTRIBUTES, LOG_OPTIONAL_ATTRIBUTES); + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, LOG_REQUIRED_ATTRIBUTES, LOG_OPTIONAL_ATTRIBUTES); message = (String) anAttributes.get(LOG_MESSAGE_ATTRIBUTE); if (anAttributes.containsKey(LOG_TYPE_ATTRIBUTE)) { @@ -578,10 +575,10 @@ public class DefaultProducerNodeBuilders { super(FREEQUERY_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { String typeString; - XMLReaderTool.checkAttributes(anAttributes, FREEQUERY_REQUIRED_ATTRIBUTES, FREEQUERY_OPTIONAL_ATTRIBUTES); + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, FREEQUERY_REQUIRED_ATTRIBUTES, FREEQUERY_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get(FREEQUERY_KEY_ATTRIBUTE); query = (String) anAttributes.get(FREEQUERY_QUERY_ATTRIBUTE); @@ -616,7 +613,6 @@ public class DefaultProducerNodeBuilders { private final static String RESOURCEBUNDLE_KEY_ATTRIBUTE = KEY_ATTRIBUTE; private final static String RESOURCEBUNDLE_BUNDLE_ATTRIBUTE = "bundle"; private final static String RESOURCEBUNDLE_LANGUAGE_ATTRIBUTE = "language"; - private final static String RESOURCEBUNDLE_DEFAULT_SUBNODE = "default"; private final static String[] RESOURCEBUNDLE_REQUIRED_ATTRIBUTES = { RESOURCEBUNDLE_KEY_ATTRIBUTE, RESOURCEBUNDLE_BUNDLE_ATTRIBUTE }; private final static String[] RESOURCEBUNDLE_OPTIONAL_ATTRIBUTES = { RESOURCEBUNDLE_LANGUAGE_ATTRIBUTE}; private final static String[] RESOURCEBUNDLE_SUBNODES = {}; @@ -629,8 +625,8 @@ public class DefaultProducerNodeBuilders { super(RESOURCEBUNDLE_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, RESOURCEBUNDLE_REQUIRED_ATTRIBUTES, RESOURCEBUNDLE_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, RESOURCEBUNDLE_REQUIRED_ATTRIBUTES, RESOURCEBUNDLE_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get(RESOURCEBUNDLE_KEY_ATTRIBUTE); bundle = (String) anAttributes.get(RESOURCEBUNDLE_BUNDLE_ATTRIBUTE); @@ -658,8 +654,8 @@ public class DefaultProducerNodeBuilders { super(FILEDATESETTING_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, FILEDATESETTING_REQUIRED_ATTRIBUTES, FILEDATESETTING_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, FILEDATESETTING_REQUIRED_ATTRIBUTES, FILEDATESETTING_OPTIONAL_ATTRIBUTES); fileNameKey = (String) anAttributes.get(FILEDATESETTING_FILE_ATTRIBUTE); dateKey = (String) anAttributes.get(FILEDATESETTING_DATE_ATTRIBUTE); @@ -684,8 +680,8 @@ public class DefaultProducerNodeBuilders { super(FILEDELETING_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, FILEDELETING_REQUIRED_ATTRIBUTES, FILEDELETING_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, FILEDELETING_REQUIRED_ATTRIBUTES, FILEDELETING_OPTIONAL_ATTRIBUTES); fileNameKey = (String) anAttributes.get(FILEDELETING_FILE_ATTRIBUTE); }; @@ -699,24 +695,28 @@ public class DefaultProducerNodeBuilders { public static class ScriptCallingProducerNodeBuilder extends AbstractProducerNodeBuilder { private final static String SCRIPT_COMMAND_ATTRIBUTE = "command"; + private final static String SCRIPT_TIME_ATTRIBUTE = "time"; private final static String[] SCRIPT_REQUIRED_ATTRIBUTES = { SCRIPT_COMMAND_ATTRIBUTE }; private final static String[] SCRIPT_OPTIONAL_ATTRIBUTES = {}; private final static String[] SCRIPT_SUBNODES = {}; private String command; + private String time; public ScriptCallingProducerNodeBuilder() { super(SCRIPT_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, SCRIPT_REQUIRED_ATTRIBUTES, SCRIPT_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, SCRIPT_REQUIRED_ATTRIBUTES, SCRIPT_OPTIONAL_ATTRIBUTES); command = (String) anAttributes.get(SCRIPT_COMMAND_ATTRIBUTE); + time = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, SCRIPT_TIME_ATTRIBUTE, "0"); }; public ProducerNode constructNode() { - return new ScriptCallingProducerNode(command); + return new + ScriptCallingProducerNode(command, time); }; } @@ -741,8 +741,8 @@ public class DefaultProducerNodeBuilders { destinationBasePath = aDestinationBasePath; } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, DIRCOPY_REQUIRED_ATTRIBUTES, DIRCOPY_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, DIRCOPY_REQUIRED_ATTRIBUTES, DIRCOPY_OPTIONAL_ATTRIBUTES); source = (String) anAttributes.get(DIRCOPY_SOURCE_ATTRIBUTE); destination = (String) anAttributes.get(DIRCOPY_DESTINATION_ATTRIBUTE); @@ -790,12 +790,12 @@ public class DefaultProducerNodeBuilders { generatorLibrary = aGeneratorLibrary; } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, GENERATION_REQUIRED_ATTRIBUTES, GENERATION_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, GENERATION_REQUIRED_ATTRIBUTES, GENERATION_OPTIONAL_ATTRIBUTES); generator = (String) anAttributes.get(GENERATION_GENERATOR_ATTRIBUTE); destination = (String) anAttributes.get(GENERATION_DESTINATION_ATTRIBUTE); - parameters = XMLReaderTool.getStringAttributeWithDefault(anAttributes, GENERATION_PARAMETERS_ATTRIBUTE, "" ); + parameters = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, GENERATION_PARAMETERS_ATTRIBUTE, "" ); }; public ProducerNode constructNode() { @@ -859,20 +859,20 @@ public class DefaultProducerNodeBuilders { model = aModel; } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, BATCHER_REQUIRED_ATTRIBUTES, BATCHER_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, BATCHER_REQUIRED_ATTRIBUTES, BATCHER_OPTIONAL_ATTRIBUTES); - batchDataKey = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_DATAKEY_ATTRIBUTE, "data" ); - batchInfoKey = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_INFOKEY_ATTRIBUTE, "info" ); - definition = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_DEFINITION_ATTRIBUTE, "" ); - selection = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_SELECTION_ATTRIBUTE, "" ); - order = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_ORDER_ATTRIBUTE, "" ); + batchDataKey = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_DATAKEY_ATTRIBUTE, "data" ); + batchInfoKey = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_INFOKEY_ATTRIBUTE, "info" ); + definition = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_DEFINITION_ATTRIBUTE, "" ); + selection = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_SELECTION_ATTRIBUTE, "" ); + order = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_ORDER_ATTRIBUTE, "" ); - batchSize = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_BATCHSIZE_ATTRIBUTE, "20" ); - minBatchSize = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_MINBATCHSIZE_ATTRIBUTE, "0" ); - skip = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_SKIP_ATTRIBUTE, "0" ); - process = XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_PROCESS_ATTRIBUTE, "-1" ); - extraTables = StringRoutines.splitString(XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_EXTRATABLES_ATTRIBUTE,"").trim(), ","); + batchSize = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_BATCHSIZE_ATTRIBUTE, "20" ); + minBatchSize = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_MINBATCHSIZE_ATTRIBUTE, "0" ); + skip = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_SKIP_ATTRIBUTE, "0" ); + process = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_PROCESS_ATTRIBUTE, "-1" ); + extraTables = StringRoutines.splitString(mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, BATCHER_EXTRATABLES_ATTRIBUTE,"").trim(), ","); List parts = StringRoutines.splitString(definition.trim()," "); if (parts.size()>0) definition=(String)parts.get(0); if (parts.size()>1) mainTablePrefix=(String)parts.get(1); @@ -927,8 +927,8 @@ public class DefaultProducerNodeBuilders { super(IF_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, IF_REQUIRED_ATTRIBUTES, IF_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, IF_REQUIRED_ATTRIBUTES, IF_OPTIONAL_ATTRIBUTES); condition = (String) anAttributes.get( IF_CONDITION_ATTRIBUTE ); }; @@ -962,12 +962,12 @@ public class DefaultProducerNodeBuilders { super(RSS_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, RSS_REQUIRED_ATTRIBUTES, RSS_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, RSS_REQUIRED_ATTRIBUTES, RSS_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get( RSS_KEY_ATTRIBUTE ); url = (String) anAttributes.get( RSS_URL_ATTRIBUTE ); - version = XMLReaderTool.getStringAttributeWithDefault(anAttributes, RSS_VERSION_ATTRIBUTE, "1.0"); + version = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, RSS_VERSION_ATTRIBUTE, "1.0"); }; public ProducerNode constructNode() { @@ -996,13 +996,13 @@ public class DefaultProducerNodeBuilders { super(RDF_AGGREGATOR_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, RDF_AGGREGATOR_REQUIRED_ATTRIBUTES, RDF_AGGREGATOR_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, RDF_AGGREGATOR_REQUIRED_ATTRIBUTES, RDF_AGGREGATOR_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get( RDF_AGGREGATOR_KEY_ATTRIBUTE ); source = (String) anAttributes.get( RDF_AGGREGATOR_SOURCE_ATTRIBUTE ); - order = XMLReaderTool.getStringAttributeWithDefault(anAttributes, RDF_AGGREGATOR_SOURCE_ATTRIBUTE, ""); - filter = XMLReaderTool.getStringAttributeWithDefault(anAttributes, RDF_AGGREGATOR_FILTER_ATTRIBUTE, ""); + order = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, RDF_AGGREGATOR_SOURCE_ATTRIBUTE, ""); + filter = mir.util.xml.XMLReaderTool.getStringAttributeWithDefault(anAttributes, RDF_AGGREGATOR_FILTER_ATTRIBUTE, ""); }; public ProducerNode constructNode() { @@ -1066,8 +1066,8 @@ public class DefaultProducerNodeBuilders { return definition.getNodeParameters(); }; - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributeSet(anAttributes.keySet(), definition.getRequiredAttributes(), definition.getOptionalAttributes()); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributeSet(anAttributes.keySet(), definition.getRequiredAttributes(), definition.getOptionalAttributes()); Iterator i = anAttributes.entrySet().iterator(); while (i.hasNext()) { diff --git a/source/mir/producer/reader/ProducerConfigReader.java b/source/mir/producer/reader/ProducerConfigReader.java index 448f0c36..b3ffdae7 100755 --- a/source/mir/producer/reader/ProducerConfigReader.java +++ b/source/mir/producer/reader/ProducerConfigReader.java @@ -29,7 +29,6 @@ */ package mir.producer.reader; -import java.io.File; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -37,14 +36,16 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.Vector; +import java.io.File; import mir.producer.CompositeProducerNode; import mir.producer.ProducerFactory; import mir.producer.ProducerNode; import mir.producer.SimpleProducerVerb; import mir.util.ExceptionFunctions; -import mir.util.XMLReader; -import mir.util.XMLReaderTool; +import mir.util.xml.XMLParserEngine; +import mir.util.xml.XMLParserExc; +import mir.util.xml.XMLParserFailure; public class ProducerConfigReader { private ProducerNodeBuilderLibrary builderLibrary; @@ -54,56 +55,47 @@ public class ProducerConfigReader { super(); }; - public void parseFile(String aFileName, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories) throws ProducerConfigFailure { - parseFile(aFileName, aBuilderLibrary, aProducerFactories, new Vector()); - } - - public void parseFile(String aFileName, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories, List aUsedFiles) throws ProducerConfigFailure { + public void parse(File aFile, ProducerNodeBuilderLibrary aBuilderLibrary, List aProducerFactories) throws ProducerConfigFailure { try { - XMLReader reader = new XMLReader(); - aUsedFiles.add(new File(aFileName)); - builderLibrary = aBuilderLibrary; scriptedNodeBuilderLibrary = new ProducerNodeBuilderLibrary(); - reader.parseFile(aFileName, new RootSectionHandler(aProducerFactories)); + XMLParserEngine.getInstance().parse("", aFile, new RootSectionHandler(aProducerFactories)); } catch (Throwable e) { Throwable root = ExceptionFunctions.traceCauseException(e); - if ((root instanceof XMLReader.XMLReaderExc) && ((XMLReader.XMLReaderExc) root).getHasLocation()) { - XMLReader.XMLReaderExc f = (XMLReader.XMLReaderExc) root; - throw new ProducerConfigFailure("'" + f.getMessage()+"' in " + f.getFilename()+"(line " + f.getLineNr()+", column " + f.getColumnNr() + ")", e); + if ((root instanceof XMLParserExc) && ((XMLParserExc) root).getHasLocation()) { + XMLParserExc f = (XMLParserExc) root; + throw new ProducerConfigFailure(f.getMessage()+" on line " + f.getLineNr()+", column " + f.getColumnNr(), e); } throw new ProducerConfigFailure(root); } } - - public class RootSectionHandler extends XMLReader.AbstractSectionHandler { + public class RootSectionHandler extends mir.util.xml.AbstractSectionHandler { private List producers; public RootSectionHandler(List aProducers) { producers = aProducers; } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { if (aTag.equals("producers")) { return new ProducersSectionHandler(producers); } else - throw new XMLReader.XMLReaderExc("Tag 'producers' expected, tag '"+aTag+"' found"); + throw new XMLParserExc("Tag 'producers' expected, tag '"+aTag+"' found"); } - public void endElement(XMLReader.SectionHandler aHandler) { + public void endElement(mir.util.xml.SectionHandler aHandler) { } public void finishSection() { } } - private final static String PRODUCER_NAME_ATTRIBUTE = "name"; private final static String[] PRODUCER_REQUIRED_ATTRIBUTES = { PRODUCER_NAME_ATTRIBUTE }; private final static String[] PRODUCER_OPTIONAL_ATTRIBUTES = { }; @@ -112,7 +104,7 @@ public class ProducerConfigReader { private final static String[] NODE_DEFINITION_REQUIRED_ATTRIBUTES = { NODE_DEFINITION_NAME_ATTRIBUTE }; private final static String[] NODE_DEFINITION_OPTIONAL_ATTRIBUTES = { }; - public class ProducersSectionHandler extends XMLReader.AbstractSectionHandler { + public class ProducersSectionHandler extends mir.util.xml.AbstractSectionHandler { private List producers; private Set producerNames; private String name; @@ -122,17 +114,17 @@ public class ProducerConfigReader { producerNames = new HashSet(); } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { if (aTag.equals("producer")) { - XMLReaderTool.checkAttributes(anAttributes, + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, PRODUCER_REQUIRED_ATTRIBUTES, PRODUCER_OPTIONAL_ATTRIBUTES); name = (String) anAttributes.get(PRODUCER_NAME_ATTRIBUTE); - XMLReaderTool.checkValidIdentifier(name); + mir.util.xml.XMLReaderTool.checkValidIdentifier(name); if (producerNames.contains(name)) - throw new XMLReader.XMLReaderExc("Duplicate producer name: '" + + throw new XMLParserExc("Duplicate producer name: '" + name + "'"); name = (String) anAttributes.get(PRODUCER_NAME_ATTRIBUTE); @@ -140,21 +132,21 @@ public class ProducerConfigReader { return new ProducerSectionHandler(name); } else if (aTag.equals("nodedefinition")) { - XMLReaderTool.checkAttributes(anAttributes, + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, NODE_DEFINITION_REQUIRED_ATTRIBUTES, NODE_DEFINITION_OPTIONAL_ATTRIBUTES); name = (String) anAttributes.get(NODE_DEFINITION_NAME_ATTRIBUTE); - XMLReaderTool.checkValidIdentifier(name); + mir.util.xml.XMLReaderTool.checkValidIdentifier(name); name = (String) anAttributes.get(NODE_DEFINITION_NAME_ATTRIBUTE); return new NodeDefinitionSectionHandler(name); } - throw new XMLReader.XMLReaderExc("Unexpected tag: " + aTag); + throw new XMLParserExc("Unexpected tag: " + aTag); } - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { if (aHandler instanceof ProducerSectionHandler) { producers.add(((ProducerSectionHandler) aHandler).getProducerFactory()); producerNames.add(((ProducerSectionHandler) aHandler).getProducerFactory().getName()); @@ -164,14 +156,14 @@ public class ProducerConfigReader { new DefaultProducerNodeBuilders.ScriptedProducerNodeBuilder.factory( ((NodeDefinitionSectionHandler) aHandler).getDefinition())); } - else throw new XMLReader.XMLReaderExc("ProducersSectionHandler.endElement Internal error: Unexpected handler: " + aHandler.getClass().getName()); + else throw new XMLParserExc("ProducersSectionHandler.endElement Internal error: Unexpected handler: " + aHandler.getClass().getName()); } public void finishSection() { } } - public class ProducerSectionHandler extends XMLReader.AbstractSectionHandler { + public class ProducerSectionHandler extends mir.util.xml.AbstractSectionHandler { private ProducerFactory producerFactory; private String factoryName; @@ -184,12 +176,12 @@ public class ProducerConfigReader { factoryName = aName; } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { if (aTag.equals("verbs")) { if (verbs!=null) - throw new XMLReader.XMLReaderExc("Verbs already processed"); + throw new XMLParserExc("Verbs already processed"); if (body!=null) - throw new XMLReader.XMLReaderExc("Verbs should come before body"); + throw new XMLParserExc("Verbs should come before body"); else return new ProducerVerbsSectionHandler(); } @@ -197,12 +189,12 @@ public class ProducerConfigReader { if (body==null) return new ProducerNodeSectionHandler(); else - throw new XMLReader.XMLReaderExc("Body already processed"); + throw new XMLParserExc("Body already processed"); } - throw new XMLReader.XMLReaderExc("Unexpected tag: '"+aTag+"'"); + throw new XMLParserExc("Unexpected tag: '"+aTag+"'"); } - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { if (aHandler instanceof ProducerNodeSectionHandler) { body = ((ProducerNodeSectionHandler) aHandler).getProducerNode(); } @@ -212,15 +204,15 @@ public class ProducerConfigReader { verbNodes = ((ProducerVerbsSectionHandler) aHandler).getVerbNodes(); defaultVerb = ((ProducerVerbsSectionHandler) aHandler).getDefaultVerb(); } - else throw new XMLReader.XMLReaderExc("ProducerSectionHandler.endElement Internal error: Unexpected handler: " + aHandler.getClass().getName()); + else throw new XMLParserExc("ProducerSectionHandler.endElement Internal error: Unexpected handler: " + aHandler.getClass().getName()); } - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { if (verbs==null) - throw new XMLReader.XMLReaderExc("No verbs defined"); + throw new XMLParserExc("No verbs defined"); if (body==null) - throw new XMLReader.XMLReaderExc("No body defined"); + throw new XMLParserExc("No body defined"); producerFactory = new ScriptedProducerFactory(factoryName, verbs, verbNodes, body, defaultVerb); } @@ -236,7 +228,7 @@ public class ProducerConfigReader { private final static String[] PRODUCER_VERB_REQUIRED_ATTRIBUTES = { PRODUCER_VERB_NAME_ATTRIBUTE }; private final static String[] PRODUCER_VERB_OPTIONAL_ATTRIBUTES = { PRODUCER_VERB_DEFAULT_ATTRIBUTE, PRODUCER_VERB_DESCRIPTION_ATTRIBUTE }; - public class ProducerVerbsSectionHandler extends XMLReader.AbstractSectionHandler { + public class ProducerVerbsSectionHandler extends mir.util.xml.AbstractSectionHandler { private Map verbNodes; private List verbs; private String defaultVerb; @@ -249,22 +241,22 @@ public class ProducerConfigReader { defaultVerb = null; } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { if (aTag.equals("verb")) { - XMLReaderTool.checkAttributes(anAttributes, + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, PRODUCER_VERB_REQUIRED_ATTRIBUTES, PRODUCER_VERB_OPTIONAL_ATTRIBUTES); currentVerb = (String) anAttributes.get(PRODUCER_VERB_NAME_ATTRIBUTE); - XMLReaderTool.checkValidIdentifier(currentVerb); + mir.util.xml.XMLReaderTool.checkValidIdentifier(currentVerb); if (verbNodes.containsKey(currentVerb)) - throw new XMLReader.XMLReaderExc("Duplicate definition of verb '" + + throw new XMLParserExc("Duplicate definition of verb '" + currentVerb + "'"); if (anAttributes.containsKey(PRODUCER_VERB_DEFAULT_ATTRIBUTE)) { if (defaultVerb != null) - throw new XMLReader.XMLReaderExc("Default verb already declared"); + throw new XMLParserExc("Default verb already declared"); defaultVerb = currentVerb; } @@ -278,10 +270,10 @@ public class ProducerConfigReader { return new ProducerNodeSectionHandler(); } else - throw new XMLReader.XMLReaderExc("Only 'verb' tags allowed here, '" + aTag + "' encountered."); + throw new XMLParserExc("Only 'verb' tags allowed here, '" + aTag + "' encountered."); } - public void endElement(XMLReader.SectionHandler aHandler) { + public void endElement(mir.util.xml.SectionHandler aHandler) { verbNodes.put(currentVerb, ((ProducerNodeSectionHandler) aHandler).getProducerNode()); verbs.add(new SimpleProducerVerb(currentVerb, currentVerbDescription)); } @@ -302,19 +294,19 @@ public class ProducerConfigReader { } } - public class EmptySectionHandler extends XMLReader.AbstractSectionHandler { - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { - throw new XMLReader.XMLReaderExc("No tags are allowed here"); + public class EmptySectionHandler extends mir.util.xml.AbstractSectionHandler { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { + throw new XMLParserExc("No tags are allowed here"); } - public void endElement(XMLReader.SectionHandler aHandler) { + public void endElement(mir.util.xml.SectionHandler aHandler) { } public void finishSection() { } } - public class MultiProducerNodeSectionHandler extends XMLReader.AbstractSectionHandler { + public class MultiProducerNodeSectionHandler extends mir.util.xml.AbstractSectionHandler { private Map nodeParameters; private Set validNodeParameters; private String currentNodeParameter; @@ -331,25 +323,25 @@ public class ProducerConfigReader { this("", new HashSet(), aValidNodeParameters); } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { if (!validNodeParameters.contains(aTag)) - throw new XMLReader.XMLReaderExc("Invalid node parameter: '" + aTag + "'"); + throw new XMLParserExc("Invalid node parameter: '" + aTag + "'"); else if (nodeParameters.containsKey(aTag)) - throw new XMLReader.XMLReaderExc("Node parameter: '" + aTag + "' already specified"); + throw new XMLParserExc("Node parameter: '" + aTag + "' already specified"); else if (anAttributes.size()>0) - throw new XMLReader.XMLReaderExc("No parameters are allowed here"); + throw new XMLParserExc("No parameters are allowed here"); currentNodeParameter = aTag; return new ProducerNodeSectionHandler(scriptedNodeName, allowedNodeParameterReferences); } - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { if (aHandler instanceof ProducerNodeSectionHandler) { nodeParameters.put(currentNodeParameter, ((ProducerNodeSectionHandler) aHandler).getProducerNode()); } else { - throw new XMLReader.XMLReaderExc("Internal error: unknown section handler '" + aHandler.getClass().getName() + "'" ); + throw new XMLParserExc("Internal error: unknown section handler '" + aHandler.getClass().getName() + "'" ); } } @@ -361,7 +353,7 @@ public class ProducerConfigReader { } } - public class ProducerNodeSectionHandler extends XMLReader.AbstractSectionHandler { + public class ProducerNodeSectionHandler extends mir.util.xml.AbstractSectionHandler { private CompositeProducerNode producerNode; private ProducerNodeBuilder currentBuilder; private String scriptedNodeName; @@ -377,11 +369,11 @@ public class ProducerConfigReader { this("", new HashSet()); } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { try { if (allowedNodeParameterReferences.contains( (aTag))) { if (!anAttributes.isEmpty()) { - throw new XMLReader.XMLReaderExc("No attributes allowed"); + throw new XMLParserExc("No attributes allowed"); } currentBuilder = new DefaultProducerNodeBuilders. @@ -412,14 +404,14 @@ public class ProducerConfigReader { } } else - throw new XMLReader.XMLReaderExc("Unknown producer node tag: '" + aTag + "'"); + throw new XMLParserExc("Unknown producer node tag: '" + aTag + "'"); } catch (Throwable t) { - throw new XMLReader.XMLReaderFailure(t); + throw new XMLParserFailure(t); } } - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { try { if (aHandler instanceof ProducerNodeSectionHandler) { currentBuilder.setSubNode( @@ -444,7 +436,7 @@ public class ProducerConfigReader { // deliberately empty: nothing expected, so nothing to process } else { - throw new XMLReader.XMLReaderExc( + throw new XMLParserExc( "Internal error: unknown section handler '" + aHandler.getClass().getName() + "'"); } @@ -453,7 +445,7 @@ public class ProducerConfigReader { currentBuilder = null; } catch (Throwable t) { - throw new XMLReader.XMLReaderFailure(t); + throw new XMLParserFailure(t); } } @@ -470,7 +462,7 @@ public class ProducerConfigReader { } } - public class NodeDefinitionSectionHandler extends XMLReader.AbstractSectionHandler { + public class NodeDefinitionSectionHandler extends mir.util.xml.AbstractSectionHandler { private ScriptedProducerNodeDefinition nodeDefinition; private ProducerNode body; private Map stringParameters; @@ -486,30 +478,30 @@ public class ProducerConfigReader { name = aName; } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { if (aTag.equals("parameters")) { if (!anAttributes.isEmpty()) { - throw new XMLReader.XMLReaderExc( "No attributes allowed for tag 'parameters'" ); + throw new XMLParserExc( "No attributes allowed for tag 'parameters'" ); } if (nodeParameters!=null) { - throw new XMLReader.XMLReaderExc( "Parameters have already been declared" ); + throw new XMLParserExc( "Parameters have already been declared" ); } if (body!=null) { - throw new XMLReader.XMLReaderExc( "Parameters should come before definition in nodedefinition '" + name +"'" ); + throw new XMLParserExc( "Parameters should come before definition in nodedefinition '" + name +"'" ); } return new NodeDefinitionParametersSectionHandler(); } else if (aTag.equals("definition")) { if (nodeParameters==null) - throw new XMLReader.XMLReaderExc( "Parameters should come before definition in nodedefinition '" + name +"'" ); + throw new XMLParserExc( "Parameters should come before definition in nodedefinition '" + name +"'" ); return new ProducerNodeSectionHandler(name, nodeParameters.keySet()); } - else throw new XMLReader.XMLReaderExc("Only 'definition' or 'parameters' tags allowed here, '" + aTag + "' encountered."); + else throw new XMLParserExc("Only 'definition' or 'parameters' tags allowed here, '" + aTag + "' encountered."); } - public void endElement(XMLReader.SectionHandler aHandler) { + public void endElement(mir.util.xml.SectionHandler aHandler) { if (aHandler instanceof NodeDefinitionParametersSectionHandler) { stringParameters = ((NodeDefinitionParametersSectionHandler) aHandler).getStringParameters(); integerParameters = ((NodeDefinitionParametersSectionHandler) aHandler).getIntegerParameters(); @@ -520,10 +512,10 @@ public class ProducerConfigReader { } } - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { Iterator i; if (body == null) - throw new XMLReader.XMLReaderExc( "Definition missing" ); + throw new XMLParserExc( "Definition missing" ); nodeDefinition = new ScriptedProducerNodeDefinition(name); @@ -558,7 +550,7 @@ public class ProducerConfigReader { private final static String[] NODE_DEFINITION_PARAMETER_OPTIONAL_ATTRIBUTES = { NODE_DEFINITION_PARAMETER_DEFAULTVALUE_ATTRIBUTE }; private final static String[] NODE_DEFINITION_NODE_PARAMETER_OPTIONAL_ATTRIBUTES = { }; - public class NodeDefinitionParametersSectionHandler extends XMLReader.AbstractSectionHandler { + public class NodeDefinitionParametersSectionHandler extends mir.util.xml.AbstractSectionHandler { private Map nodeParameters; private Map stringParameters; private Map integerParameters; @@ -569,29 +561,29 @@ public class ProducerConfigReader { integerParameters = new HashMap(); } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { String parameterName; String defaultValue; if (aTag.equals("node")) { - XMLReaderTool.checkAttributes(anAttributes, + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, NODE_DEFINITION_PARAMETER_REQUIRED_ATTRIBUTES, NODE_DEFINITION_NODE_PARAMETER_OPTIONAL_ATTRIBUTES); parameterName = (String) anAttributes.get( NODE_DEFINITION_PARAMETER_NAME_ATTRIBUTE); if (nodeParameters.containsKey(parameterName)) - throw new XMLReader.XMLReaderExc("Duplicate parameter name: '" + + throw new XMLParserExc("Duplicate parameter name: '" + parameterName + "'"); - XMLReaderTool.checkValidIdentifier(parameterName); + mir.util.xml.XMLReaderTool.checkValidIdentifier(parameterName); nodeParameters.put(parameterName, parameterName); return new EmptySectionHandler(); } else if (aTag.equals("string") || aTag.equals("integer")) { - XMLReaderTool.checkAttributes(anAttributes, + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, NODE_DEFINITION_PARAMETER_REQUIRED_ATTRIBUTES, NODE_DEFINITION_PARAMETER_OPTIONAL_ATTRIBUTES); parameterName = (String) anAttributes.get( @@ -599,10 +591,10 @@ public class ProducerConfigReader { if (stringParameters.containsKey(parameterName) || integerParameters.containsKey(parameterName)) - throw new XMLReader.XMLReaderExc("Duplicate parameter name: '" + + throw new XMLParserExc("Duplicate parameter name: '" + parameterName + "'"); - XMLReaderTool.checkValidIdentifier(parameterName); + mir.util.xml.XMLReaderTool.checkValidIdentifier(parameterName); defaultValue = (String) anAttributes.get( NODE_DEFINITION_PARAMETER_DEFAULTVALUE_ATTRIBUTE); @@ -615,11 +607,11 @@ public class ProducerConfigReader { return new EmptySectionHandler(); } else - throw new XMLReader.XMLReaderExc( + throw new XMLParserExc( "Only 'string', 'integer' and 'node' tags allowed here, '" + aTag + "' encountered."); } - public void endElement(XMLReader.SectionHandler aHandler) { + public void endElement(mir.util.xml.SectionHandler aHandler) { } public void finishSection() { diff --git a/source/mir/producer/reader/ProducerNodeBuilder.java b/source/mir/producer/reader/ProducerNodeBuilder.java index 3a5c10ba..6b47ddef 100755 --- a/source/mir/producer/reader/ProducerNodeBuilder.java +++ b/source/mir/producer/reader/ProducerNodeBuilder.java @@ -18,13 +18,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. * If you do not wish to do so, delete this exception statement from your version. */ package mir.producer.reader; @@ -33,10 +33,10 @@ import java.util.Map; import java.util.Set; import mir.producer.ProducerNode; -import mir.util.XMLReader; +import mir.util.xml.XMLParserExc; public interface ProducerNodeBuilder { - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc; + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc; public void setSubNode(String aName, ProducerNode aNode) throws ProducerConfigExc; public Set getAvailableSubNodes() throws ProducerConfigExc; public ProducerNode constructNode() throws ProducerConfigExc; @@ -48,7 +48,7 @@ public interface ProducerNodeBuilder { public class DefaultProducerNodeBuilderFactory implements ProducerNodeBuilderFactory { private Class producerNodeBuilderClass; - public DefaultProducerNodeBuilderFactory(Class aProducerNodeBuilderClass) throws ProducerConfigExc, XMLReader.XMLReaderExc { + public DefaultProducerNodeBuilderFactory(Class aProducerNodeBuilderClass) throws ProducerConfigExc, XMLParserExc { if (!ProducerNodeBuilder.class.isAssignableFrom(aProducerNodeBuilderClass)) throw new ProducerConfigExc("supplied class is not a ProducerNodeBuilder class but a " + aProducerNodeBuilderClass.getClass().getName()); diff --git a/source/mir/rss/RSS091Reader.java b/source/mir/rss/RSS091Reader.java index 7e85c691..18bc0af8 100755 --- a/source/mir/rss/RSS091Reader.java +++ b/source/mir/rss/RSS091Reader.java @@ -36,8 +36,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Vector; +import mir.util.xml.*; -import mir.util.XMLReader; +import mir.util.xml.XMLParserEngine; /** * @@ -84,9 +85,8 @@ public class RSS091Reader { public RSSData parseInputStream(InputStream aStream) throws RSSExc, RSSFailure { try { - XMLReader xmlReader = new XMLReader(false); RSSData result = new RSSData(); - xmlReader.parseInputStream(aStream, new RootSectionHandler(result)); + XMLParserEngine.getInstance().parse("html", aStream, new RootSectionHandler(result)); return result; } @@ -109,34 +109,34 @@ public class RSS091Reader { } } - private class RootSectionHandler extends XMLReader.AbstractSectionHandler { + private class RootSectionHandler extends mir.util.xml.AbstractSectionHandler { private RSSData data; public RootSectionHandler(RSSData aData) { data = aData; } - public XMLReader.SectionHandler startElement(XMLReader.XMLName aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(mir.util.xml.XMLName aTag, Map anAttributes) throws XMLParserExc { if (aTag.getLocalName().equals("rss")) { return new RSS091SectionHandler(data); } else - throw new XMLReader.XMLReaderFailure(new RSSExc("'rss' tag expected")); + throw new XMLParserFailure(new RSSExc("'rss' tag expected")); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { if (aCharacters.trim().length()>0) - throw new XMLReader.XMLReaderExc("No character data allowed here"); + throw new XMLParserExc("No character data allowed here"); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; } - private class RSS091SectionHandler extends XMLReader.AbstractSectionHandler { + private class RSS091SectionHandler extends mir.util.xml.AbstractSectionHandler { private RSSData data; @@ -144,23 +144,23 @@ public class RSS091Reader { data = aData; } - public XMLReader.SectionHandler startElement(XMLReader.XMLName aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(mir.util.xml.XMLName aTag, Map anAttributes) throws XMLParserExc { if (aTag.getLocalName().equals("channel")) return new RSS091ChannelSectionHandler(data); else - throw new XMLReader.XMLReaderExc("channel tag expected, " + aTag.getLocalName() + " found"); + throw new XMLParserExc("channel tag expected, " + aTag.getLocalName() + " found"); }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { if (aCharacters.trim().length()>0) - throw new XMLReader.XMLReaderExc("No character data allowed here"); + throw new XMLParserExc("No character data allowed here"); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; } - private class RSS091ChannelSectionHandler extends XMLReader.AbstractSectionHandler { + private class RSS091ChannelSectionHandler extends mir.util.xml.AbstractSectionHandler { private String currentTag; private RSSData data; @@ -175,7 +175,7 @@ public class RSS091Reader { attributes = new HashMap(); } - public XMLReader.SectionHandler startElement(XMLReader.XMLName aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(mir.util.xml.XMLName aTag, Map anAttributes) throws XMLParserExc { String tag = aTag.getLocalName(); if (tag.equals("item")) @@ -188,7 +188,7 @@ public class RSS091Reader { return new DiscardingSectionHandler(); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { if (aHandler instanceof PCDATASectionHandler) { attributes.put(currentTag, (((PCDATASectionHandler) aHandler).getData())); } @@ -197,12 +197,12 @@ public class RSS091Reader { } }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { if (aCharacters.trim().length()>0) - throw new XMLReader.XMLReaderExc("No character data allowed here"); + throw new XMLParserExc("No character data allowed here"); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { Iterator i = items.iterator(); while (i.hasNext()) { @@ -211,7 +211,7 @@ public class RSS091Reader { }; } - private class RSS091ItemSectionHandler extends XMLReader.AbstractSectionHandler { + private class RSS091ItemSectionHandler extends mir.util.xml.AbstractSectionHandler { private String currentTag; private RDFResource item; @@ -221,7 +221,7 @@ public class RSS091Reader { attributes = new HashMap(); } - public XMLReader.SectionHandler startElement(XMLReader.XMLName aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(mir.util.xml.XMLName aTag, Map anAttributes) throws XMLParserExc { String tag = aTag.getLocalName(); System.out.println(tag); @@ -233,18 +233,18 @@ public class RSS091Reader { return new DiscardingSectionHandler(); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { if (aHandler instanceof PCDATASectionHandler) { attributes.put(currentTag, (((PCDATASectionHandler) aHandler).getData())); } }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { if (aCharacters.trim().length()>0) - throw new XMLReader.XMLReaderExc("No character data allowed here"); + throw new XMLParserExc("No character data allowed here"); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { item = new RDFResource("rss:item", (String) attributes.get("rss:link")); Iterator i = attributes.entrySet().iterator(); @@ -261,25 +261,25 @@ public class RSS091Reader { } - private class PCDATASectionHandler extends XMLReader.AbstractSectionHandler { + private class PCDATASectionHandler extends mir.util.xml.AbstractSectionHandler { private StringBuffer data; public PCDATASectionHandler() { data = new StringBuffer(); } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { - throw new XMLReader.XMLReaderFailure(new RSSExc("No subtags allowed here")); + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { + throw new XMLParserFailure(new RSSExc("No subtags allowed here")); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { data.append(aCharacters); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; public String getData() { @@ -288,14 +288,14 @@ public class RSS091Reader { } - private class RDFSequenceSectionHandler extends XMLReader.AbstractSectionHandler { + private class RDFSequenceSectionHandler extends mir.util.xml.AbstractSectionHandler { private List items; public RDFSequenceSectionHandler() { items = new Vector(); } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { if (aTag.equals("rdf:li")) { String item = (String) anAttributes.get("rdf:resource"); @@ -306,13 +306,13 @@ public class RSS091Reader { return new DiscardingSectionHandler(); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; public List getItems() { @@ -320,18 +320,18 @@ public class RSS091Reader { } } - private class DiscardingSectionHandler extends XMLReader.AbstractSectionHandler { - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + private class DiscardingSectionHandler extends mir.util.xml.AbstractSectionHandler { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { return this; }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; } } diff --git a/source/mir/rss/RSSReader.java b/source/mir/rss/RSSReader.java index a3a1894f..4b6f120a 100755 --- a/source/mir/rss/RSSReader.java +++ b/source/mir/rss/RSSReader.java @@ -37,7 +37,9 @@ import java.util.Map; import java.util.Vector; import mir.util.DateTimeFunctions; -import mir.util.XMLReader; +import mir.util.xml.XMLParserEngine; +import mir.util.xml.XMLParserExc; +import mir.util.xml.XMLParserFailure; /** * @@ -62,13 +64,13 @@ public class RSSReader { // ML: to be localized: public static final String V2V_NAMESPACE_URI = "http://v2v.cc/rss/"; - private static final XMLReader.XMLName RDF_ABOUT_PARAMETER = new XMLReader.XMLName(RDF_NAMESPACE_URI, "about"); - private static final XMLReader.XMLName RDF_SEQUENCE_TAG = new XMLReader.XMLName(RDF_NAMESPACE_URI, "Seq"); - private static final XMLReader.XMLName RDF_BAG_PARAMETER = new XMLReader.XMLName(RDF_NAMESPACE_URI, "Bag"); + private static final mir.util.xml.XMLName RDF_ABOUT_PARAMETER = new mir.util.xml.XMLName(RDF_NAMESPACE_URI, "about"); + private static final mir.util.xml.XMLName RDF_SEQUENCE_TAG = new mir.util.xml.XMLName(RDF_NAMESPACE_URI, "Seq"); + private static final mir.util.xml.XMLName RDF_BAG_PARAMETER = new mir.util.xml.XMLName(RDF_NAMESPACE_URI, "Bag"); - private static final XMLReader.XMLName RSS_CHANNEL_TAG = new XMLReader.XMLName(RSS_1_0_NAMESPACE_URI, "channel"); - private static final XMLReader.XMLName RSS_ITEM_TAG = new XMLReader.XMLName(RSS_1_0_NAMESPACE_URI, "item"); - private static final XMLReader.XMLName RSS_ITEMS_TAG = new XMLReader.XMLName(RSS_1_0_NAMESPACE_URI, "items"); + private static final mir.util.xml.XMLName RSS_CHANNEL_TAG = new mir.util.xml.XMLName(RSS_1_0_NAMESPACE_URI, "channel"); + private static final mir.util.xml.XMLName RSS_ITEM_TAG = new mir.util.xml.XMLName(RSS_1_0_NAMESPACE_URI, "item"); + private static final mir.util.xml.XMLName RSS_ITEMS_TAG = new mir.util.xml.XMLName(RSS_1_0_NAMESPACE_URI, "items"); private List modules; private Map namespaceURItoModule; @@ -115,9 +117,8 @@ public class RSSReader { public RSSData parseInputStream(InputStream aStream) throws RSSExc, RSSFailure { try { - XMLReader xmlReader = new XMLReader(true); RSSData result = new RSSData(); - xmlReader.parseInputStream(aStream, new RootSectionHandler(result)); + XMLParserEngine.getInstance().parse("xml.namespaceaware", aStream, new RootSectionHandler(result)); return result; } @@ -140,34 +141,34 @@ public class RSSReader { } } - private class RootSectionHandler extends XMLReader.AbstractSectionHandler { + private class RootSectionHandler extends mir.util.xml.AbstractSectionHandler { private RSSData data; public RootSectionHandler(RSSData aData) { data = aData; } - public XMLReader.SectionHandler startElement(XMLReader.XMLName aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(mir.util.xml.XMLName aTag, Map anAttributes) throws XMLParserExc { if (aTag.getLocalName().equals("RDF")) { return new RDFSectionHandler(data); } else - throw new XMLReader.XMLReaderFailure(new RSSExc("'RDF' tag expected")); + throw new XMLParserFailure(new RSSExc("'RDF' tag expected")); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { if (aCharacters.trim().length()>0) - throw new XMLReader.XMLReaderExc("No character data allowed here"); + throw new XMLParserExc("No character data allowed here"); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; } - private class RDFSectionHandler extends XMLReader.AbstractSectionHandler { + private class RDFSectionHandler extends mir.util.xml.AbstractSectionHandler { private RSSData data; @@ -175,29 +176,29 @@ public class RSSReader { data = aData; } - public XMLReader.SectionHandler startElement(XMLReader.XMLName aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(mir.util.xml.XMLName aTag, Map anAttributes) throws XMLParserExc { String identifier = (String) anAttributes.get(RDF_ABOUT_PARAMETER); String rdfClass = makeQualifiedName(aTag); return new RDFResourceSectionHandler(rdfClass, identifier); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { if (aHandler instanceof RDFResourceSectionHandler) { data.addResource(((RDFResourceSectionHandler) aHandler).getResource()); } }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { if (aCharacters.trim().length()>0) - throw new XMLReader.XMLReaderExc("No character data allowed here"); + throw new XMLParserExc("No character data allowed here"); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; } - private XMLReader.SectionHandler makePropertyValueSectionHandler(XMLReader.XMLName aTag, Map anAttributes) { + private mir.util.xml.SectionHandler makePropertyValueSectionHandler(mir.util.xml.XMLName aTag, Map anAttributes) { RSSModule module = (RSSModule) namespaceURItoModule.get(aTag.getNamespaceURI()); if (module!=null) { @@ -224,7 +225,7 @@ public class RSSReader { return new FlexiblePropertyValueSectionHandler(); } - private void usePropertyValueSectionHandler(RDFResource aResource, PropertyValueSectionHandler aHandler, XMLReader.XMLName aTag) { + private void usePropertyValueSectionHandler(RDFResource aResource, PropertyValueSectionHandler aHandler, mir.util.xml.XMLName aTag) { RSSModule module = (RSSModule) namespaceURItoModule.get(aTag.getNamespaceURI()); if (module!=null) { @@ -247,7 +248,7 @@ public class RSSReader { aResource.set(makeQualifiedName(aTag), aHandler.getValue()); } - private String makeQualifiedName(XMLReader.XMLName aName) { + private String makeQualifiedName(mir.util.xml.XMLName aName) { String result=aName.getLocalName(); RSSModule module = (RSSModule) namespaceURItoModule.get(aName.getNamespaceURI()); if (module!=null) { @@ -260,34 +261,34 @@ public class RSSReader { return result; } - private class RDFResourceSectionHandler extends XMLReader.AbstractSectionHandler { + private class RDFResourceSectionHandler extends mir.util.xml.AbstractSectionHandler { private String image; - private XMLReader.XMLName currentTag; + private mir.util.xml.XMLName currentTag; private RDFResource resource; public RDFResourceSectionHandler(String anRDFClass, String anIdentifier) { resource = new RDFResource(anRDFClass, anIdentifier); } - public XMLReader.SectionHandler startElement(XMLReader.XMLName aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(mir.util.xml.XMLName aTag, Map anAttributes) throws XMLParserExc { currentTag = aTag; return makePropertyValueSectionHandler(aTag, anAttributes); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { if (aHandler instanceof PropertyValueSectionHandler) { usePropertyValueSectionHandler(resource, (PropertyValueSectionHandler) aHandler, currentTag); // resource.set(makeQualifiedName(currentTag), ( (PropertyValueSectionHandler) aHandler).getValue()); } }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { if (aCharacters.trim().length()>0) - throw new XMLReader.XMLReaderExc("No character data allowed here"); + throw new XMLParserExc("No character data allowed here"); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; public RDFResource getResource() { @@ -299,7 +300,7 @@ public class RSSReader { } } - private abstract class PropertyValueSectionHandler extends XMLReader.AbstractSectionHandler { + private abstract class PropertyValueSectionHandler extends mir.util.xml.AbstractSectionHandler { public abstract Object getValue(); } @@ -312,24 +313,24 @@ public class RSSReader { structuredData=null; } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { if (aTag.equals(RDF_SEQUENCE_TAG)) return new RDFSequenceSectionHandler(); else return new DiscardingSectionHandler(); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { if (aHandler instanceof RDFSequenceSectionHandler) { structuredData= ((RDFSequenceSectionHandler) aHandler).getItems(); } }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { stringData.append(aCharacters); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; public String getData() { @@ -351,25 +352,25 @@ public class RSSReader { items = new Vector(); } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { if (aTag.equals(RDF_SEQUENCE_TAG)) return new RDFSequenceSectionHandler(); else return new DiscardingSectionHandler(); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { if (aHandler instanceof RDFSequenceSectionHandler) { items.addAll(((RDFSequenceSectionHandler) aHandler).getItems()); } }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { if (aCharacters.trim().length()>0) - throw new XMLReader.XMLReaderExc("No character data allowed here"); + throw new XMLParserExc("No character data allowed here"); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; public List getItems() { @@ -388,18 +389,18 @@ public class RSSReader { data = new StringBuffer(); } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { - throw new XMLReader.XMLReaderFailure(new RSSExc("No subtags allowed here")); + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { + throw new XMLParserFailure(new RSSExc("No subtags allowed here")); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { data.append(aCharacters); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; public String getData() { @@ -418,24 +419,20 @@ public class RSSReader { data = new StringBuffer(); } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { - throw new XMLReader.XMLReaderFailure(new RSSExc("No subtags allowed here")); + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { + throw new XMLParserFailure(new RSSExc("No subtags allowed here")); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { data.append(aCharacters); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; - private final static String SPACE = "[\t\n\r ]*"; - private final static String NUMBER = "[0-9]*"; - private final static String SIGN = "[-+]"; - public Object getValue() { try { String expression = data.toString().trim(); @@ -450,14 +447,14 @@ public class RSSReader { } - private class RDFSequenceSectionHandler extends XMLReader.AbstractSectionHandler { + private class RDFSequenceSectionHandler extends mir.util.xml.AbstractSectionHandler { private List items; public RDFSequenceSectionHandler() { items = new Vector(); } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { if (aTag.equals("rdf:li")) { String item = (String) anAttributes.get("rdf:resource"); @@ -468,13 +465,13 @@ public class RSSReader { return new DiscardingSectionHandler(); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; public List getItems() { @@ -494,23 +491,23 @@ public class RSSReader { return data; } - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { tag=aTag; data.append("<"+tag+">"); return new RDFLiteralSectionHandler(); }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { data.append(((RDFLiteralSectionHandler) aHandler).getData()); data.append("</"+tag+">"); }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { data.append(aCharacters); }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; public Object getValue() { @@ -518,18 +515,18 @@ public class RSSReader { } } - private class DiscardingSectionHandler extends XMLReader.AbstractSectionHandler { - public XMLReader.SectionHandler startElement(String aTag, Map anAttributes) throws XMLReader.XMLReaderExc { + private class DiscardingSectionHandler extends mir.util.xml.AbstractSectionHandler { + public mir.util.xml.SectionHandler startElement(String aTag, Map anAttributes) throws XMLParserExc { return this; }; - public void endElement(XMLReader.SectionHandler aHandler) throws XMLReader.XMLReaderExc { + public void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc { }; - public void characters(String aCharacters) throws XMLReader.XMLReaderExc { + public void characters(String aCharacters) throws XMLParserExc { }; - public void finishSection() throws XMLReader.XMLReaderExc { + public void finishSection() throws XMLParserExc { }; } } diff --git a/source/mir/rss/RSSTest.java b/source/mir/rss/RSSTest.java index cbd4d449..8cece378 100755 --- a/source/mir/rss/RSSTest.java +++ b/source/mir/rss/RSSTest.java @@ -30,6 +30,7 @@ package mir.rss; +import java.util.Iterator; public class RSSTest { @@ -37,33 +38,11 @@ public class RSSTest { public static void main(String[] args) { RSSReader reader = new RSSReader(); -//.. RSS091Reader reader2 = new RSS091Reader(); try { -// RE test = new RE(".*\\bLB\\b.*", RE.REG_ICASE); -// System.out.println(" LB II : " + test.isMatch("LB II")); -// System.out.println(" revised LB: " + test.isMatch("revised LB")); -// System.out.println(" revised LB II : " + test.isMatch("revised LB II")); -// System.out.println(" buLB: " + test.isMatch("buLB")); - - RSSData arg = reader.parseUrl("http://argentina.indymedia.org/features.rdf"); -// RSSData it = reader.parseUrl("http://g8.mir.dnsalias.net/italynewswire.rss"); -// Object result = StructuredContentParser.parse(" { a = 'b' 'as a' = [ 'asd' asd 'asdas asd as''asd' ] }") ; -// System.out.println("" + wvl.get("rss:item")); -// RSSData fr = reader2.parseUrl("http://paris.indymedia.org/backendg8.php3"); -// RSSData be = reader.parseUrl("http://belgium.indymedia.org/features.rdf"); - -// RSSAggregator agg = new RSSAggregator(10, "dc:date", true, null, null); - -// agg.appendItems(wvl.getResourcesForRdfClass("rss:item")); -// agg.appendItems(be.getResourcesForRdfClass("rss:item")); - -// System.out.println(fr); - -// Iterator i = fr.getResourcesForRdfClass("rss:item").iterator(); -// while (i.hasNext()) -// System.out.println(ParameterExpander.evaluateExpression((RDFResource) i.next(), "['dc:date']")); - -// System.out.println(agg.getItems()); + RSSData res = reader.parseUrl(args[0]); + Iterator i = res.getResourcesForRdfClass("rss:item").iterator(); + while (i.hasNext()) + System.out.println(i.next()); } catch (Throwable t) { System.out.println("Exception: " + t.toString()); diff --git a/source/mir/util/XMLReader.java b/source/mir/util/XMLReader.java deleted file mode 100755 index 703e0b39..00000000 --- a/source/mir/util/XMLReader.java +++ /dev/null @@ -1,433 +0,0 @@ -/* - * Copyright (C) 2001, 2002 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. - * If you do not wish to do so, delete this exception statement from your version. - */ -package mir.util; - -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.StringReader; -import java.util.HashMap; -import java.util.Map; -import java.util.Stack; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.ccil.cowan.tagsoup.Parser; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.Locator; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.helpers.DefaultHandler; -import multex.Exc; -import multex.Failure; - -public class XMLReader { - private Locator locator; - private String filename; - private boolean namespaceAware; - - public XMLReader() { - this(false); - } - - public XMLReader(boolean aNameSpaceAware) { - namespaceAware = aNameSpaceAware; - filename=""; - } - - public void parseString(String aString, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc { - try { - parseInputSource(new InputSource(new StringReader(aString)), aRootHandler); - } - catch (Throwable t) { - throw new XMLReaderFailure(t); - } - } - - public void parseString(boolean aTagSoup, String aString, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc { - try { - parseInputSource(aTagSoup, new InputSource(new StringReader(aString)), aRootHandler); - } - catch (Throwable t) { - throw new XMLReaderFailure(t); - } - } - - public void parseFile(String aFileName, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc { - filename= aFileName; - try { - parseInputStream(new BufferedInputStream(new FileInputStream(aFileName),8192), aRootHandler); - } - catch (Throwable t) { - throw new XMLReaderFailure(t); - } - } - - public void parseInputStream(InputStream anInputStream, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc { - parseInputSource(new InputSource(anInputStream), aRootHandler); - } - - public void parseInputStream(boolean aTagSoup, InputStream anInputStream, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc { - parseInputSource(aTagSoup, new InputSource(anInputStream), aRootHandler); - } - - public void parseInputSource(InputSource anInputSource, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc { - try { - parseInputSource(false, anInputSource, aRootHandler); - } - catch (Throwable e) { - Throwable t = ExceptionFunctions.traceCauseException(e); - - if (t instanceof XMLReaderExc) { - throw (XMLReaderExc) t; - } - - if (t instanceof XMLReaderFailure) { - throw (XMLReaderFailure) t; - } - - throw new XMLReaderFailure(t); - } - } - - public void parseInputSource(boolean aTagSoup, InputSource anInputSource, SectionHandler aRootHandler) throws XMLReaderFailure, XMLReaderExc { - try { - XMLReaderHandler handler = new XMLReaderHandler(aRootHandler); - - if (aTagSoup) { - org.ccil.cowan.tagsoup.Parser parser = new Parser(); - parser.setContentHandler(handler); - parser.setDTDHandler(handler); - parser.parse(anInputSource); - } - else { - SAXParserFactory parserFactory = SAXParserFactory.newInstance(); - - parserFactory.setNamespaceAware(true); - parserFactory.setValidating(true); - SAXParser parser = parserFactory.newSAXParser(); - - parser.parse(anInputSource, handler); - } - } - catch (Throwable e) { - Throwable t = ExceptionFunctions.traceCauseException(e); - - if (t instanceof XMLReaderExc) { - throw (XMLReaderExc) t; - } - - if (t instanceof XMLReaderFailure) { - throw (XMLReaderFailure) t; - } - - if (t instanceof XMLReaderExc) { - if (locator!=null && filename!=null) - ((XMLReaderExc) t).setLocation(filename, locator.getLineNumber(), locator.getColumnNumber()); - throw (XMLReaderExc) t; - } - - if (t instanceof SAXParseException) { - XMLReaderExc r = new XMLReaderExc(t.getMessage()); - - if (locator!=null && filename!=null) - r.setLocation(filename, locator.getLineNumber(), locator.getColumnNumber()); - - throw r; - } - - if (t instanceof XMLReaderFailure) { - throw (XMLReaderFailure) t; - } - - if (t instanceof ParserConfigurationException) { - throw new XMLReaderFailure("Internal exception: "+t.toString(), t); - } - - throw new XMLReaderFailure(t); - } - } - private class XMLReaderHandler extends DefaultHandler { - private SectionsManager manager; - - public XMLReaderHandler(SectionHandler aRootHandler) { - super(); - - manager = new SectionsManager(); - manager.pushHandler(aRootHandler); - } - - public void setDocumentLocator(Locator aLocator) { - locator=aLocator; - } - - public void startElement(String aUri, String aLocalName, String aQualifiedName, Attributes anAttributes) throws SAXException { - Map attributesMap; - int i; - - try { - attributesMap = new HashMap(); - - if (namespaceAware) - for (i=0; i<anAttributes.getLength(); i++) - attributesMap.put(new XMLName(anAttributes.getURI(i), XMLReaderTool.getNameSpaceFromQualifiedName(anAttributes.getQName(i)), anAttributes.getLocalName(i)), anAttributes.getValue(i)); - else - for (i=0; i<anAttributes.getLength(); i++) - attributesMap.put(anAttributes.getLocalName(i), anAttributes.getValue(i)); - - SectionHandler handler = manager.currentHandler().startElement(new XMLName(aUri, XMLReaderTool.getNameSpaceFromQualifiedName(aQualifiedName), aLocalName), attributesMap); - - manager.pushHandler( handler ); - } - catch (XMLReaderExc e) { - throw new SAXParseException(e.getMessage(), null, e); - } - catch (Exception e) { - throw new SAXException(e); - } - } - - public void endElement(String aUri, String aLocalName, String aQualifiedName) throws SAXException { - try - { - SectionHandler handler = manager.popHandler(); - - handler.finishSection(); - - if (!manager.isEmpty()) { - manager.currentHandler().endElement(handler); - } - } - catch (XMLReaderExc e) { - throw new SAXParseException(e.getMessage(), null, e); - } - catch (Exception e) { - throw new SAXException(e); - } - } - - public void endDocument() throws SAXException { - try - { - SectionHandler handler = manager.popHandler(); - - handler.finishSection(); - } - catch (XMLReaderExc e) { - throw new SAXParseException(e.getMessage(), null, e); - } - catch (Exception e) { - throw new SAXException(e); - } - } - - public void characters(char[] aBuffer, int aStart, int anEnd) throws SAXException { - try { - String text = new String(aBuffer, aStart, anEnd); - - manager.currentHandler().characters(text); - } - catch (XMLReaderExc e) { - throw new SAXParseException(e.getMessage(), null, e); - } - catch (Exception e) { - throw new SAXException(e); - } - } - } - - private class SectionsManager { - Stack handlerStack; - - public SectionsManager() { - handlerStack = new Stack(); - } - - public void pushHandler(SectionHandler aSectionHandler) { - handlerStack.push(aSectionHandler); - } - - public SectionHandler popHandler() { - return (SectionHandler) handlerStack.pop(); - } - - public SectionHandler currentHandler() { - return (SectionHandler) handlerStack.peek(); - } - - public boolean isEmpty() { - return handlerStack.isEmpty(); - } - } - - public static interface SectionHandler { - public abstract SectionHandler startElement(XMLName aTag, Map anAttributes) throws XMLReaderExc; - - public abstract void endElement(SectionHandler aHandler) throws XMLReaderExc; - - public void characters(String aCharacters) throws XMLReaderExc; - - public void finishSection() throws XMLReaderExc; - } - - public static abstract class AbstractSectionHandler implements SectionHandler { - public SectionHandler startElement(XMLName aTag, Map anAttributes) throws XMLReaderExc { - return startElement(aTag.getLocalName(), anAttributes); - }; - - public SectionHandler startElement(String aLocalName, Map anAttributes) throws XMLReaderExc { - return null; - }; - - public void endElement(SectionHandler aHandler) throws XMLReaderExc { - }; - - public void finishSection() throws XMLReaderExc { - } - - public void characters(String aCharacters) throws XMLReaderExc { - if ( aCharacters.trim().length() > 0) { - throw new XMLReaderExc("Text not allowed"); - } - } - } - - public static class XMLReaderExc extends Exc { - private boolean hasLocation; - private String filename; - private int lineNr; - private int columnNr; - - public XMLReaderExc(String aMessage) { - super(aMessage); - hasLocation = false; - } - - protected void setLocation(String aFilename, int aLineNr, int aColumnNr) { - filename = aFilename; - lineNr = aLineNr; - columnNr = aColumnNr; - hasLocation = true; - } - - public boolean getHasLocation() { - return hasLocation; - } - - public int getLineNr() { - return lineNr; - } - - public int getColumnNr() { - return columnNr; - } - - public String getFilename() { - return filename; - } - } - - public static class XMLReaderFailure extends Failure { - public XMLReaderFailure(String aMessage, Throwable aCause) { - super(aMessage, aCause); - } - - public XMLReaderFailure(Throwable aCause) { - super(aCause.getMessage(), aCause); - } - } - - public static class XMLName { - private String namespaceURI; - private String localName; - private String prefix; - - public XMLName(String aLocalName) { - this(null, null, aLocalName); - } - - public XMLName(String aNamespaceURI, String aPrefix, String aLocalName) { - localName=""; - prefix=""; - namespaceURI=""; - - if (aLocalName!=null) - localName = aLocalName; - if (aPrefix!=null) - prefix = aPrefix; - if (aNamespaceURI!=null) - namespaceURI = aNamespaceURI; - } - - public XMLName(String aNamespaceURI, String aLocalName) { - this (aNamespaceURI, null, aLocalName); - } - - public String getNamespaceURI() { - return namespaceURI; - } - - public String getLocalName() { - return localName; - } - - public String getPrefix() { - return prefix; - } - - public int hashCode() { - if (namespaceURI == null) - return localName.hashCode() + 3*prefix.hashCode(); - else - return localName.hashCode() + 3*namespaceURI.hashCode(); - } - - public String toString() { - return ((namespaceURI.length()>0)? "["+namespaceURI+"]":"")+((prefix.length()>0)?prefix+":":"")+localName; - } - - public boolean equals(Object anObject) { - if (anObject instanceof XMLName) { - if (namespaceURI==null) - return (((XMLName) anObject).namespaceURI == null) && - prefix.equals(((XMLName) anObject).prefix) && - localName.equals(((XMLName) anObject).localName); - else - return namespaceURI.equals(((XMLName) anObject).namespaceURI) && - localName.equals(((XMLName) anObject).localName); - } - else - return false; - } - } - -} \ No newline at end of file diff --git a/source/mir/util/XMLReaderTool.java b/source/mir/util/XMLReaderTool.java deleted file mode 100755 index 2bae6d24..00000000 --- a/source/mir/util/XMLReaderTool.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2001, 2002 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. - * If you do not wish to do so, delete this exception statement from your version. - */ -package mir.util; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class XMLReaderTool { - - public static void checkValidIdentifier(String anIdentifier) throws XMLReader.XMLReaderExc { - } - - public static String getStringAttributeWithDefault(Map anAttributes, String aKey, String aDefault) { - if (anAttributes.containsKey(aKey)) - return (String) anAttributes.get(aKey); - else - return aDefault; - } - - public static void checkIntegerAttribute(Map anAttributes, String aKey) throws XMLReader.XMLReaderExc { - try { - Integer.parseInt((String) anAttributes.get(aKey)); - } - catch (Throwable t) { - throw new XMLReader.XMLReaderExc("attribute '"+aKey+"' is not an integer" ); - } - } - - public static int getIntegerAttributeWithDefault(Map anAttributes, String aKey, int aDefault) throws XMLReader.XMLReaderExc { - String value; - - if (anAttributes.containsKey(aKey)) { - checkIntegerAttribute(anAttributes, aKey); - return Integer.parseInt((String) anAttributes.get(aKey)); - } - else - return aDefault; - } - - public static void checkAttributes(Map anAttributes, String[] aRequiredAttributes, String[] anOptionalAttributes) throws XMLReader.XMLReaderExc { - checkAttributeSet(anAttributes.keySet(), - new HashSet(Arrays.asList(aRequiredAttributes)), - new HashSet(Arrays.asList(anOptionalAttributes))); - } - - public static void checkAttributeSet(Set aSet, Set aRequiredElements, Set anOptionalElements) throws XMLReader.XMLReaderExc{ - Iterator i; - - i = aSet.iterator(); - while (i.hasNext()) { - Object item = i.next(); - - if (!(aRequiredElements.contains(item) || anOptionalElements.contains(item))) - throw new XMLReader.XMLReaderExc("unknown attribute '" + item + "'" ); - } - - i = aRequiredElements.iterator(); - while (i.hasNext()) { - Object item = i.next(); - - if (!(aSet.contains(item))) - throw new XMLReader.XMLReaderExc("missing required attribute '" + item + "'" ); - } - - } - - /** - * Returns the namespace part of a qualified XML Tag name <br> - * Example:<br> - * <code>getNameSpaceFromQualifiedName("dc:creator");</code> <br> - * will return <code>"dc"</code> - * - * @param aQualifiedName - * @return - */ - - public static String getNameSpaceFromQualifiedName(String aQualifiedName) { - List parts = StringRoutines.splitString(aQualifiedName, ":"); - - if (parts.size()<=1) - return null; - else - return (String) parts.get(0); - } - - /** - * Returns the localname part of a qualified XML Tag name <br> - * Example:<br> - * <code>getLocalNameFromQualifiedName("dc:creator");</code> <br> - * will return <code>"creator"</code> - * - * @param aQualifiedName - * @return - */ - - public static String getLocalNameFromQualifiedName(String aQualifiedName) { - List parts = StringRoutines.splitString(aQualifiedName, ":"); - - if (parts.size()<1) - return null; - if (parts.size()==1) - return (String) parts.get(0); - else - return (String) parts.get(1); - } - -} diff --git a/source/mir/util/xml/AbstractSectionHandler.java b/source/mir/util/xml/AbstractSectionHandler.java new file mode 100755 index 00000000..cd2dda53 --- /dev/null +++ b/source/mir/util/xml/AbstractSectionHandler.java @@ -0,0 +1,39 @@ +package mir.util.xml; + +/** + * + * <p>Title: </p> + * <p>Description: </p> + * <p>Copyright: Copyright (c) 2003</p> + * <p>Company: </p> + * @author not attributable + * @version 1.0 + */ + +public abstract class AbstractSectionHandler implements SectionHandler { + public void extra(String anExtraData) throws XMLParserExc, XMLParserFailure { + } + + public SectionHandler startElement(XMLName aTag, java.util.Map anAttributes) throws XMLParserExc{ + return startElement(aTag.getLocalName(), XMLReaderTool.convertXMLAttributeMap(anAttributes)); + }; + + public SectionHandler startElement(String aLocalName, java.util.Map anAttributes) throws XMLParserExc{ + return new AbstractSectionHandler() {}; + }; + + public void endElement(SectionHandler aHandler) throws XMLParserExc{ + }; + + public void startSection() throws XMLParserExc{ + } + + public void finishSection() throws XMLParserExc{ + } + + public void characters(String aCharacters) throws XMLParserExc{ + if ( aCharacters.trim().length() > 0) { + throw new XMLParserExc("Text not allowed"); + } + } +} diff --git a/source/mir/util/xml/SectionHandler.java b/source/mir/util/xml/SectionHandler.java new file mode 100755 index 00000000..6e278d5a --- /dev/null +++ b/source/mir/util/xml/SectionHandler.java @@ -0,0 +1,51 @@ +package mir.util.xml; + +public interface SectionHandler { + /** + * + * @param anExtraData + * @throws XMLParserExc + * @throws XMLParserFailure + */ + public void extra(String anExtraData) throws XMLParserExc, XMLParserFailure; + + /** + * + * @param aTag + * @param anAttributes + * @return + * @throws XMLParserExc + * @throws XMLParserFailure + */ + public abstract mir.util.xml.SectionHandler startElement(XMLName aTag, java.util.Map anAttributes) throws XMLParserExc, XMLParserFailure; + + /** + * + * @param aHandler + * @throws XMLParserExc + * @throws XMLParserFailure + */ + public abstract void endElement(mir.util.xml.SectionHandler aHandler) throws XMLParserExc, XMLParserFailure; + + /** + * + * @param aCharacters + * @throws XMLParserExc + * @throws XMLParserFailure + */ + public void characters(String aCharacters) throws XMLParserExc, XMLParserFailure; + + /** + * + * @throws XMLParserExc + * @throws XMLParserFailure + */ + public void startSection() throws XMLParserExc, XMLParserFailure; + + /** + * + * @throws XMLParserExc + * @throws XMLParserFailure + */ + public void finishSection() throws XMLParserExc, XMLParserFailure; +} diff --git a/source/mir/util/xml/XMLName.java b/source/mir/util/xml/XMLName.java new file mode 100755 index 00000000..a9f60582 --- /dev/null +++ b/source/mir/util/xml/XMLName.java @@ -0,0 +1,88 @@ +package mir.util.xml; + +/** + * Class to encapsulate an XML-style name (either for tagnames, + * or attribute names). + * + * <p> + * Usage requirements: + * <ul> + * <li> Namespace aware parsers must supply a local name + * and a namespace URI + * <li> Non-namespace aware parsers should supply a local name, + * and, if present and applicable, also a prefix + * </ul> + */ + +public class XMLName { + private String namespaceURI; + private String localName; + private String prefix; + + public XMLName(String aLocalName) { + this(null, null, aLocalName); + } + + public XMLName(String aNamespaceURI, String aPrefix, String aLocalName) { + localName=""; + prefix=""; + namespaceURI=""; + + if (aLocalName!=null) + localName = aLocalName; + if (aPrefix!=null) + prefix = aPrefix; + if (aNamespaceURI!=null) + namespaceURI = aNamespaceURI; + } + + public XMLName(String aNamespaceURI, String aLocalName) { + this (aNamespaceURI, null, aLocalName); + } + + /** + * Returns the namespace URI if available + */ + public String getNamespaceURI() { + return namespaceURI; + } + + /** + * Returns the name of the tag, stripped from prefix + */ + public String getLocalName() { + return localName; + } + + /** + * Returns the prefix of the tag, if present + */ + public String getPrefix() { + return prefix; + } + + public int hashCode() { + if (namespaceURI == null) + return localName.hashCode() + 3*prefix.hashCode(); + else + return localName.hashCode() + 3*namespaceURI.hashCode(); + } + + public String toString() { + return ((namespaceURI.length()>0)? "["+namespaceURI+"]":"")+((prefix.length()>0)?prefix+":":"")+localName; + } + + public boolean equals(Object anObject) { + if (anObject instanceof mir.util.xml.XMLName) { + if (namespaceURI==null) + return (((mir.util.xml.XMLName) anObject).namespaceURI == null) && + prefix.equals(((mir.util.xml.XMLName) anObject).prefix) && + localName.equals(((mir.util.xml.XMLName) anObject).localName); + else + return namespaceURI.equals(((mir.util.xml.XMLName) anObject).namespaceURI) && + localName.equals(((mir.util.xml.XMLName) anObject).localName); + } + else + return false; + } +} diff --git a/source/mir/util/xml/XMLParserEngine.java b/source/mir/util/xml/XMLParserEngine.java new file mode 100755 index 00000000..ff616ddc --- /dev/null +++ b/source/mir/util/xml/XMLParserEngine.java @@ -0,0 +1,268 @@ +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. + */ + +package mir.util.xml; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.StringReader; +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import java.util.Stack; + +import mir.util.ExceptionFunctions; +import mir.util.xml.html.XMLHTMLParserProvider; + +public class XMLParserEngine { + private Map providers; + private XMLParserProvider defaultProvider; + + private static XMLParserEngine instance = new XMLParserEngine(); + + public static XMLParserEngine getInstance() { + return instance; + } + + private XMLParserEngine() { + providers = new HashMap(); + defaultProvider = new XMLSAXParserProvider(false); + providers.put("xml", defaultProvider); + providers.put("xml.namespaceaware", new XMLSAXParserProvider(true)); + providers.put("html", new XMLHTMLParserProvider()); + } + + /** + * + * @param aString + * @param aRootHandler + * @throws XMLParserFailure + * @throws XMLParserExc + */ + public void parseString(String aProvider, String aString, SectionHandler aRootHandler) throws XMLParserFailure, XMLParserExc{ + try { + parse(aProvider, new StringReader(aString), aRootHandler); + } + catch (Throwable t) { + throw new XMLParserFailure(t); + } + } + + /** + * + * @param aFile + * @param aRootHandler + */ + public void parse(String aProvider, File aFile, SectionHandler aRootHandler) throws XMLParserFailure, XMLParserExc { +// filename = aFileName; + + try { + parse(aProvider, new BufferedInputStream(new FileInputStream(aFile), 8192), aRootHandler); + } + catch (XMLParserExc e) { + throw e; + } + catch (Throwable t) { + throw new XMLParserFailure(t); + } + } + + /** + * + * @param anInputStream + * @param aRootHandler + * @throws mir.util.xml.XMLParserFailure + * @throws mir.util.xml.XMLParserExc + */ + public void parse(String aProvider, InputStream anInputStream, SectionHandler aRootHandler) throws XMLParserFailure, XMLParserExc{ + parse(aProvider, new java.io.InputStreamReader(anInputStream), aRootHandler); + } + + /** + * + * @param aRootHandler + * @throws mir.util.xml.XMLParserFailure + * @throws mir.util.xml.XMLParserExc + */ + public void parse(String aProvider, java.io.Reader aReader, SectionHandler aRootHandler) throws XMLParserFailure, XMLParserExc{ + XMLParserProvider provider = (XMLParserProvider) providers.get(aProvider); + + if (provider==null) + provider = defaultProvider; + + XMLParserRunner runner = new XMLParserRunner(aRootHandler); + + try { + provider.parse(aReader, runner); + } + catch (Throwable e) { + Throwable t = ExceptionFunctions.traceCauseException(e); + + if (t instanceof XMLParserExc && runner.getLocator()!=null) { + ((XMLParserExc) t).setLocation(runner.getLocator().getLineNr(), runner.getLocator().getColumnNr()); + } + + if (t instanceof XMLParserExc) { + throw (XMLParserExc) t; + } + + if (t instanceof XMLParserFailure) { + throw (XMLParserFailure) t; + } + + throw new XMLParserFailure(t); + } + } + + public interface XMLLocator { + public int getLineNr(); + public int getColumnNr(); + } + + public interface XMLParserReceiver { + /** + * Provides an object with which it's possible to track the parser's + * position. + */ + public void setLocator(XMLLocator aLocator); + + /** + * Extra document data, outside of tags and CDATA, will be passed verbatim + * to this method. This may include comments, DTDs, XML specifications, + * etc. + */ + public void extra(String aPreAmble) throws XMLParserExc, XMLParserFailure; + + public void startElement(XMLName anElement, Map anAttributes) throws XMLParserExc, XMLParserFailure; + public void endElement(XMLName anElement) throws XMLParserExc, XMLParserFailure; + public void startDocument() throws XMLParserExc, XMLParserFailure; + public void endDocument() throws XMLParserExc, XMLParserFailure; + public void text(String aText) throws XMLParserExc, XMLParserFailure; + } + + public interface XMLParserProvider { + public void parse(java.io.Reader aReader, XMLParserReceiver aReceiver) throws XMLParserExc, XMLParserFailure; + } + + private class XMLParserRunner implements XMLParserReceiver { + private SectionsManager manager; + private XMLLocator locator; + private SectionHandler rootHandler; + + public XMLParserRunner(SectionHandler aRootHandler) { + super(); + + locator = null; + manager = new SectionsManager(); + rootHandler = aRootHandler; + } + + public void setLocator(XMLLocator aLocator) { + locator=aLocator; + } + + public void extra(String anExtraData) throws XMLParserExc, XMLParserFailure { + SectionHandler handler = manager.currentHandler(); + + handler.extra(anExtraData); + } + + public void startElement(XMLName anElement, Map anAttributes) throws XMLParserExc, XMLParserFailure { + SectionHandler handler = manager.currentHandler().startElement(anElement, anAttributes); + + handler.startSection(); + + manager.pushHandler(handler); + } + + public void endElement(XMLName anElement) throws XMLParserExc, XMLParserFailure { + SectionHandler handler = manager.popHandler(); + + handler.finishSection(); + + manager.currentHandler().endElement(handler); + } + + public void startDocument() throws XMLParserExc, XMLParserFailure { + rootHandler.startSection(); + manager.pushHandler(rootHandler); + } + + public void endDocument() throws XMLParserExc, XMLParserFailure { + SectionHandler handler = manager.popHandler(); + + handler.finishSection(); + } + + public void text(String aText) throws XMLParserExc, XMLParserFailure { + manager.currentHandler().characters(aText); + } + + public XMLLocator getLocator() { + return locator; + } + } + + /** + * + * <p>Title: </p> + * <p>Description: </p> + * <p>Copyright: Copyright (c) 2003</p> + * <p>Company: </p> + * @author not attributable + * @version 1.0 + */ + private class SectionsManager { + Stack handlerStack; + + public SectionsManager() { + handlerStack = new Stack(); + } + + public void pushHandler(SectionHandler aSectionHandler) { + handlerStack.push(aSectionHandler); + } + + public SectionHandler popHandler() { + return (SectionHandler) handlerStack.pop(); + } + + public SectionHandler currentHandler() { + return (SectionHandler) handlerStack.peek(); + } + + public boolean isEmpty() { + return handlerStack.isEmpty(); + } + } + +} \ No newline at end of file diff --git a/source/mir/util/xml/XMLParserExc.java b/source/mir/util/xml/XMLParserExc.java new file mode 100755 index 00000000..9754224e --- /dev/null +++ b/source/mir/util/xml/XMLParserExc.java @@ -0,0 +1,34 @@ +package mir.util.xml; + +/** + * Exception during parsing with optional location information. + */ + +public class XMLParserExc extends multex.Exc { + private boolean hasLocation; + private int lineNr; + private int columnNr; + + public XMLParserExc(String aMessage) { + super(aMessage); + hasLocation = false; + } + + protected void setLocation(int aLineNr, int aColumnNr) { + lineNr = aLineNr; + columnNr = aColumnNr; + hasLocation = true; + } + + public boolean getHasLocation() { + return hasLocation; + } + + public int getLineNr() { + return lineNr; + } + + public int getColumnNr() { + return columnNr; + } +} diff --git a/source/mir/util/xml/XMLParserFailure.java b/source/mir/util/xml/XMLParserFailure.java new file mode 100755 index 00000000..b96d4511 --- /dev/null +++ b/source/mir/util/xml/XMLParserFailure.java @@ -0,0 +1,20 @@ +package mir.util.xml; + +/** + * + * <p>Title: </p> + * <p>Description: </p> + * <p>Copyright: Copyright (c) 2003</p> + * <p>Company: </p> + * @author not attributable + * @version 1.0 + */ +public class XMLParserFailure extends multex.Failure { + public XMLParserFailure(String aMessage, Throwable aCause) { + super(aMessage, aCause); + } + + public XMLParserFailure(Throwable aCause) { + super(aCause.getMessage(), aCause); + } +} diff --git a/source/mir/util/xml/XMLReaderTool.java b/source/mir/util/xml/XMLReaderTool.java new file mode 100755 index 00000000..2e192ad0 --- /dev/null +++ b/source/mir/util/xml/XMLReaderTool.java @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. + */ +package mir.util.xml; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class XMLReaderTool { + public static void checkValidIdentifier(String anIdentifier) throws XMLParserExc { + } + + public static String getStringAttributeWithDefault(java.util.Map anAttributes, String aKey, String aDefault) { + if (anAttributes.containsKey(aKey)) + return (String) anAttributes.get(aKey); + else + return aDefault; + } + + public static void checkIntegerAttribute(java.util.Map anAttributes, String aKey) throws XMLParserExc { + try { + Integer.parseInt((String) anAttributes.get(aKey)); + } + catch (Throwable t) { + throw new XMLParserExc("attribute '"+aKey+"' is not an integer" ); + } + } + + public static int getIntegerAttributeWithDefault(java.util.Map anAttributes, String aKey, int aDefault) throws XMLParserExc { + if (anAttributes.containsKey(aKey)) { + checkIntegerAttribute(anAttributes, aKey); + + return Integer.parseInt((String) anAttributes.get(aKey)); + } + else + return aDefault; + } + + public static void checkAttributes(java.util.Map anAttributes, String[] aRequiredAttributes, String[] anOptionalAttributes) throws XMLParserExc { + checkAttributeSet(anAttributes.keySet(), + new java.util.HashSet(java.util.Arrays.asList(aRequiredAttributes)), + new java.util.HashSet(java.util.Arrays.asList(anOptionalAttributes))); + } + + public static void checkAttributeSet(java.util.Set aSet, java.util.Set aRequiredElements, java.util.Set anOptionalElements) throws XMLParserExc{ + java.util.Iterator i; + + i = aSet.iterator(); + while (i.hasNext()) { + Object item = i.next(); + + if (!(aRequiredElements.contains(item) || anOptionalElements.contains(item))) + throw new XMLParserExc("unknown attribute '" + item + "'" ); + } + + i = aRequiredElements.iterator(); + while (i.hasNext()) { + Object item = i.next(); + + if (!(aSet.contains(item))) + throw new XMLParserExc("missing required attribute '" + item + "'" ); + } + + } + + /** + * Returns the namespace part of a qualified XML Tag name <br> + * Example:<br> + * <code>getPrefixFromQualifiedName("dc:creator");</code> <br> + * will return <code>"dc"</code> + */ + + public static String getPrefixFromQualifiedName(String aQualifiedName) { + java.util.List parts = mir.util.StringRoutines.splitString(aQualifiedName, ":"); + + if (parts.size()<=1) + return ""; + else + return (String) parts.get(0); + } + + /** + * Returns the localname part of a qualified XML Tag name <br> + * Example:<br> + * <code>getLocalNameFromQualifiedName("dc:creator");</code> <br> + * will return <code>"creator"</code> + */ + public static String getLocalNameFromQualifiedName(String aQualifiedName) { + java.util.List parts = mir.util.StringRoutines.separateString(aQualifiedName, ":"); + + if (parts.size()<1) + return null; + + if (parts.size()==1) + return (String) parts.get(0); + else + return (String) parts.get(1); + } + + /** + * Creates an {@link XMLName} out of qualified name by splitting on the + * <code>:</code>. + */ + public static XMLName getXMLNameForQualifiedName(String aQualifiedName) { + return new XMLName( + null, + getPrefixFromQualifiedName(aQualifiedName), + getLocalNameFromQualifiedName(aQualifiedName)); + } + + /** + * Turns a Map with {@link XMLName} keys into a map with {@link String} keys, + * by taking the <code>XMLName</code>'s local name + */ + public static Map convertXMLAttributeMap(Map anXMLAttributeMap) { + Map result = new HashMap(); + + Iterator i = anXMLAttributeMap.entrySet().iterator(); + + while (i.hasNext()) { + Map.Entry entry = (Map.Entry) i.next(); + + result.put( + ((XMLName) entry.getKey()).getLocalName(), + entry.getValue()); + } + + return result; + } + + +} diff --git a/source/mir/util/xml/XMLSAXParserProvider.java b/source/mir/util/xml/XMLSAXParserProvider.java new file mode 100755 index 00000000..567e0fce --- /dev/null +++ b/source/mir/util/xml/XMLSAXParserProvider.java @@ -0,0 +1,155 @@ +package mir.util.xml; + +import java.util.*; + +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.Locator; +import mir.util.ExceptionFunctions; + +/** + * + * <p>Title: </p> + * <p>Description: </p> + * <p>Copyright: Copyright (c) 2003</p> + * <p>Company: </p> + * @author not attributable + * @version 1.0 + */ +class XMLSAXParserProvider implements XMLParserEngine.XMLParserProvider { + private boolean nameSpaceAware; + + public XMLSAXParserProvider(boolean aNameSpaceAware) { + nameSpaceAware = aNameSpaceAware; + } + + public void parse(java.io.Reader aReader, XMLParserEngine.XMLParserReceiver aReceiver) throws XMLParserExc, XMLParserFailure { + try { + javax.xml.parsers.SAXParserFactory parserFactory = javax.xml.parsers.SAXParserFactory.newInstance(); + + parserFactory.setNamespaceAware(true); + parserFactory.setValidating(true); + javax.xml.parsers.SAXParser parser = parserFactory.newSAXParser(); + + parser.parse(new InputSource(aReader), new SAXHandler(aReceiver)); + } + catch (org.xml.sax.SAXException e) { + Throwable t = ExceptionFunctions.traceCauseException(e); + + if (t instanceof XMLParserExc) { + throw (XMLParserExc) t; + } + + if (t instanceof XMLParserFailure) { + throw (XMLParserFailure) t; + } + + throw new XMLParserFailure(t); + } + catch (Throwable t) { + throw new XMLParserFailure(t); + } + } + + private class SAXHandler extends org.xml.sax.helpers.DefaultHandler { + private XMLParserEngine.XMLParserReceiver receiver; + + public SAXHandler(XMLParserEngine.XMLParserReceiver aReceiver) throws XMLParserExc, XMLParserFailure { + super(); + + receiver = aReceiver; + receiver.startDocument(); + } + + public void setDocumentLocator(final Locator aLocator) { + receiver.setLocator( + new XMLParserEngine.XMLLocator() { + public int getLineNr() { + return aLocator.getLineNumber(); + } + + public int getColumnNr() { + return aLocator.getColumnNumber(); + } + } + ); + } + + public void startElement(String aUri, String aLocalName, String aQualifiedName, org.xml.sax.Attributes anAttributes) throws org.xml.sax.SAXException { + try { + Map attributes = new java.util.HashMap(); + + XMLName tag; + if (nameSpaceAware) { + tag = new XMLName(aUri, XMLReaderTool.getPrefixFromQualifiedName(aQualifiedName), aLocalName); + for (int i=0; i<anAttributes.getLength(); i++) + attributes.put( + new XMLName(anAttributes.getURI(i), + XMLReaderTool.getPrefixFromQualifiedName(anAttributes.getQName(i)), + anAttributes.getLocalName(i)), + anAttributes.getValue(i)); + } + else { + tag = new XMLName(aUri, XMLReaderTool.getPrefixFromQualifiedName(aQualifiedName), + XMLReaderTool.getLocalNameFromQualifiedName(aQualifiedName)); + for (int i=0; i<anAttributes.getLength(); i++) + attributes.put( + new XMLName(anAttributes.getURI(i), + XMLReaderTool.getPrefixFromQualifiedName(anAttributes.getQName(i)), + XMLReaderTool.getLocalNameFromQualifiedName(anAttributes.getQName(i))), + anAttributes.getValue(i)); + } + + receiver.startElement(tag, attributes); + } + catch (XMLParserExc e) { + throw new org.xml.sax.SAXParseException(e.getMessage(), null, e); + } + catch (Exception e) { + throw new SAXException(e); + } + } + + public void endElement(String aUri, String aLocalName, String aQualifiedName) throws org.xml.sax.SAXException { + try + { + XMLName element = new XMLName(aUri, XMLReaderTool.getPrefixFromQualifiedName(aQualifiedName), aLocalName); + + receiver.endElement(element); + } + catch (XMLParserExc e) { + throw new org.xml.sax.SAXParseException(e.getMessage(), null, e); + } + catch (Exception e) { + throw new org.xml.sax.SAXException(e); + } + } + + public void endDocument() throws org.xml.sax.SAXException { + try + { + receiver.endDocument(); + } + catch (XMLParserExc e) { + throw new org.xml.sax.SAXParseException(e.getMessage(), null, e); + } + catch (Exception e) { + throw new org.xml.sax.SAXException(e); + } + } + + public void characters(char[] aBuffer, int aStart, int anEnd) throws org.xml.sax.SAXException { + try { + String text = new String(aBuffer, aStart, anEnd); + + receiver.text(text); + } + catch (XMLParserExc e) { + throw new org.xml.sax.SAXParseException(e.getMessage(), null, e); + } + catch (Exception e) { + throw new org.xml.sax.SAXException(e); + } + } + } +} diff --git a/source/mir/util/xml/html/HTMLParser.java b/source/mir/util/xml/html/HTMLParser.java new file mode 100755 index 00000000..d810ab13 --- /dev/null +++ b/source/mir/util/xml/html/HTMLParser.java @@ -0,0 +1,155 @@ +package mir.util.xml.html; + +import java.io.*; +import java.util.*; + +/** + * + * TODO + * [x] selfclosing <br/> tags + * [ ] de-html-escaping of cdata, parameter values etc + * [ ] Smarter corrections + * [ ] + * [ ] case sensitivity optional + */ + +public class HTMLParser { + private HTMLSchemaInformation schemaInformation; + + public HTMLParser() { + schemaInformation = new HTMLSchemaInformation(); + } + + public void parse(Reader aReader, ParserReceiver aReceiver) throws HTMLParserExc, HTMLParserFailure, IOException { + HTMLScanner scanner; + CoreParser parser; + parser = new CoreParser(aReceiver); + scanner = new HTMLScanner(parser, aReader); + scanner.run(); + } + + private class CoreParser implements HTMLScanner.ScannerReceiver { + private ParserReceiver receiver; + private Stack tagStack; + + public CoreParser(ParserReceiver aReceiver) { + receiver = aReceiver; + tagStack = new Stack(); + } + + public void handleDTD(String aDTD) throws HTMLParserExc { + receiver.dtd(aDTD); + } + + public void handleOpenTag(String aTag, Map anAttributes) throws HTMLParserExc { + String lowercaseTag = aTag.toLowerCase(); + + HTMLSchemaInformation.HTMLTagInformation tagInformation = + schemaInformation.lookupTag(lowercaseTag); + + if (tagInformation!=null) { + if (tagInformation.getIsBlock()) { + closeAllInlineTags(); + } + + closeAllAutoclosingTags(tagInformation); + + Map attributes = new HashMap(); + + Iterator i = anAttributes.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry entry = (Map.Entry) i.next(); + + attributes.put(((String) entry.getKey()).toLowerCase(), entry.getValue()); + } + + receiver.openTag(lowercaseTag, attributes); + if (tagInformation.getHasBody()) { + tagStack.push(lowercaseTag); + } + else { + receiver.closeTag(lowercaseTag); + } + } + else { + tagStack.push(aTag); + } + } + + public void handleClosingTag(String aTag) throws HTMLParserExc { + String lowercaseTag = aTag.toLowerCase(); + String tag = aTag; + + HTMLSchemaInformation.HTMLTagInformation tagInformation = + schemaInformation.lookupTag(lowercaseTag); + + if (tagInformation!=null) { + tag = lowercaseTag; + if (tagInformation.getIsBlock()) { + closeAllInlineTags(); + } + } + + int index = tagStack.search(tag); + + if (index>-1 && index<4) { + for (int i=0; i<index; i++) { + closeUpmostTag(); + } + } + } + + public void handleCData(String aData) throws HTMLParserExc { + receiver.cdata(aData); + } + + public void handleComment(String aTag) throws HTMLParserExc { + receiver.comment(aTag); + } + + public void handleEndOfStream() throws HTMLParserExc { + while (!tagStack.empty()) + closeUpmostTag(); + } + + private void closeAllAutoclosingTags(HTMLSchemaInformation.HTMLTagInformation aTagInformation) throws HTMLParserExc { + while (!tagStack.empty()) { + String tag = (String) tagStack.peek(); + + if (aTagInformation.autoClose(tag)) { + closeUpmostTag(); + } + else { + break; + } + } + } + + private void closeAllInlineTags() throws HTMLParserExc { + while (!tagStack.empty()) { + HTMLSchemaInformation.HTMLTagInformation tagInformation = + schemaInformation.lookupTag((String) tagStack.peek()); + + if (tagInformation!=null && !tagInformation.getIsBlock()) { + closeUpmostTag(); + } + else { + break; + } + } + } + + private void closeUpmostTag() throws HTMLParserExc { + receiver.closeTag((String) tagStack.peek()); + tagStack.pop(); + } + } + + public interface ParserReceiver { + public void dtd(String aDTD) throws HTMLParserExc; + public void openTag(String aTag, Map anAttributes) throws HTMLParserExc; + public void closeTag(String aTag) throws HTMLParserExc; + public void comment(String aData) throws HTMLParserExc; + public void cdata(String aData) throws HTMLParserExc; + } +} \ No newline at end of file diff --git a/source/mir/util/xml/html/HTMLParserExc.java b/source/mir/util/xml/html/HTMLParserExc.java new file mode 100755 index 00000000..c1d48d18 --- /dev/null +++ b/source/mir/util/xml/html/HTMLParserExc.java @@ -0,0 +1,34 @@ +package mir.util.xml.html; + +/** + * Exception during parsing with optional location information. + */ + +public class HTMLParserExc extends multex.Exc { + private boolean hasLocation; + private int lineNr; + private int columnNr; + + public HTMLParserExc(String aMessage) { + super(aMessage); + hasLocation = false; + } + + protected void setLocation(int aLineNr, int aColumnNr) { + lineNr = aLineNr; + columnNr = aColumnNr; + hasLocation = true; + } + + public boolean getHasLocation() { + return hasLocation; + } + + public int getLineNr() { + return lineNr; + } + + public int getColumnNr() { + return columnNr; + } +} diff --git a/source/mir/util/xml/html/HTMLParserFailure.java b/source/mir/util/xml/html/HTMLParserFailure.java new file mode 100755 index 00000000..bbb40ecd --- /dev/null +++ b/source/mir/util/xml/html/HTMLParserFailure.java @@ -0,0 +1,20 @@ +package mir.util.xml.html; + +/** + * + * <p>Title: </p> + * <p>Description: </p> + * <p>Copyright: Copyright (c) 2003</p> + * <p>Company: </p> + * @author not attributable + * @version 1.0 + */ +public class HTMLParserFailure extends multex.Failure { + public HTMLParserFailure(String aMessage, Throwable aCause) { + super(aMessage, aCause); + } + + public HTMLParserFailure(Throwable aCause) { + super(aCause.getMessage(), aCause); + } +} diff --git a/source/mir/util/xml/html/HTMLScanner.java b/source/mir/util/xml/html/HTMLScanner.java new file mode 100755 index 00000000..1a2bf1f0 --- /dev/null +++ b/source/mir/util/xml/html/HTMLScanner.java @@ -0,0 +1,287 @@ +package mir.util.xml.html; + +import java.io.IOException; +import java.io.Reader; +import java.util.HashMap; +import java.util.Map; + +public class HTMLScanner { + private ReaderWrapper reader; + private ScannerReceiver receiver; + + public HTMLScanner(ScannerReceiver aReceiver, Reader aReader) { + reader = new ReaderWrapper(aReader); + receiver = aReceiver; + } + + public interface ScannerReceiver { + public void handleDTD(String aDTD) throws HTMLParserExc; + public void handleOpenTag(String aTag, Map anAttributes) throws HTMLParserExc; + public void handleClosingTag(String aTag) throws HTMLParserExc; + public void handleCData(String aData) throws HTMLParserExc; + public void handleComment(String aTag) throws HTMLParserExc; + public void handleEndOfStream() throws HTMLParserExc; + } + + public void run() throws IOException, HTMLParserExc { + + while (!reader.isAtEnd()) { + char c = reader.peek(); + + if (c != '<') + readCData(); + else { + reader.get(); + c = reader.peek(); + + switch (c) { + case '!': + reader.get(); + readSpecial(); + break; + case '/': + reader.get(); + readEndTag(); + break; + default: + readTag(); + } + } + } + + receiver.handleEndOfStream(); + } + + private boolean isValidTagNameCharacter(char aCharacter) { + int type = Character.getType(aCharacter); + + return + (type == Character.UPPERCASE_LETTER) || + (type == Character.LOWERCASE_LETTER) || + (type == Character.DECIMAL_DIGIT_NUMBER) || + (aCharacter == '-') || + (aCharacter == '_') || + (aCharacter == ':'); + } + + private void skipWhiteSpace() throws IOException { + while (!reader.isAtEnd() && Character.isWhitespace(reader.peek())) { + reader.get(); + } + } + + private void readEndTag() throws IOException, HTMLParserExc { + StringBuffer result = new StringBuffer(); + + skipWhiteSpace(); + + while (!reader.isAtEnd() && isValidTagNameCharacter(reader.peek())) { + result.append(reader.get()); + } + + skipWhiteSpace(); + + if (!reader.isAtEnd() && reader.peek()=='>') + reader.get(); + + receiver.handleClosingTag(result.toString()); + } + + private String getName() throws IOException { + StringBuffer result = new StringBuffer(); + + skipWhiteSpace(); + + while (!reader.isAtEnd() && isValidTagNameCharacter(reader.peek())) { + result.append(reader.get()); + } + + if (result.length()==0) + return null; + else + return result.toString(); + } + + private String getAttributeValue() throws IOException { + StringBuffer result = new StringBuffer(); + + skipWhiteSpace(); + + if (!reader.isAtEnd()) { + if (reader.peek() == '\'' || reader.peek() == '\"') { + char boundary = reader.get(); + + while (!reader.isAtEnd() && reader.peek()!=boundary) { + result.append(reader.get()); + } + + if (!reader.isAtEnd() && reader.peek()==boundary) + reader.get(); + } + else { + while (!reader.isAtEnd() && isValidTagNameCharacter(reader.peek())) { + result.append(reader.get()); + } + } + } + + return result.toString(); + } + + private void readTag() throws IOException, HTMLParserExc { + String tagName = getName(); + + Map attributes = new HashMap(); + + String attributeName = getName(); + String attributeValue = null; + + while (attributeName!=null) { + skipWhiteSpace(); + + if (!reader.isAtEnd() && reader.peek()=='=') { + reader.get(); + attributeValue = getAttributeValue(); + } + + attributes.put(attributeName, attributeValue); + + attributeName = getName(); + } + + boolean isClosed=false; + + skipWhiteSpace(); + if (!reader.isAtEnd() && reader.peek()=='/') { + isClosed = true; + reader.get(); + } + + skipWhiteSpace(); + if (!reader.isAtEnd() && reader.peek()=='>') { + reader.get(); + } + + receiver.handleOpenTag(tagName, attributes); + if (isClosed) + receiver.handleClosingTag(tagName); + } + + private void readSpecial() throws IOException, HTMLParserExc { + StringBuffer result = new StringBuffer(); + + if (!reader.isAtEnd() && reader.peek()=='-') { + reader.get(); + if (!reader.isAtEnd() && reader.peek()=='-') { + reader.get(); + + while (!reader.isAtEnd()) { + if (reader.peek()=='-') { + reader.get(); + if (!reader.isAtEnd() && reader.peek()=='-') { + reader.get(); + break; + } + result.append('-'); + } + if (!reader.isAtEnd()) + result.append(reader.get()); + } + + skipWhiteSpace(); + + if (!reader.isAtEnd() && reader.peek()=='>') + reader.get(); + + receiver.handleComment(result.toString()); + + return; + } + else { + result.append('-'); + } + } + + while (!reader.isAtEnd() && reader.peek()!='>') { + result.append(reader.get()); + } + + if (!reader.isAtEnd() && reader.peek()=='>') + reader.get(); + + receiver.handleDTD("<!"+result.toString()+">"); + } + + private void readCData() throws IOException, HTMLParserExc { + StringBuffer result = new StringBuffer(); + + while (!reader.isAtEnd() && reader.peek()!='<') { + result.append(reader.get()); + } + + receiver.handleCData(result.toString()); + } + + /** + * Class to provide for a 1 character look-ahead on a reader + */ + public static class ReaderWrapper { + private Reader reader; + private char buffer; + private boolean haveBuffer; + + public ReaderWrapper(Reader aReader) { + reader = aReader; + haveBuffer = false; + } + + /** + * Returns <code>true</code> if the stream contains no more characters. + */ + public boolean isAtEnd() throws IOException { + fillBuffer(); + + return !haveBuffer; + } + + /** + * Gets the next character from the reader but will not remove it from the + * stream. + * {@link #isAtEnd()} must return <code>false</code> before call this + * routine. + */ + public char peek() throws IOException { + fillBuffer(); + + return buffer; + } + + /** + * Gets the next character from the reader and removes it from the stream. + * {@link #isAtEnd()} must return <code>false</code> before call this + * routine. + */ + public char get() throws IOException { + fillBuffer(); + haveBuffer = false; + + return buffer; + } + + /** + * If the reader is not at it's end, then upon return, the buffer will + * be filled. If the buffer was already filled, then this method won't + * do anything. + */ + public void fillBuffer() throws IOException { + if (!haveBuffer) { + int c = reader.read(); + + if (c!=-1) { + buffer = (char) c; + haveBuffer=true; + } + } + } + } +} \ No newline at end of file diff --git a/source/mir/util/xml/html/HTMLSchemaInformation.java b/source/mir/util/xml/html/HTMLSchemaInformation.java new file mode 100755 index 00000000..68d21273 --- /dev/null +++ b/source/mir/util/xml/html/HTMLSchemaInformation.java @@ -0,0 +1,169 @@ +package mir.util.xml.html; + +import java.util.*; + +public class HTMLSchemaInformation { + private Map tags; + + public HTMLSchemaInformation() { + tags = new HashMap(); + + addInlineTag("a"); + addInlineTag("abbr"); + addInlineTag("acronym"); + addInlineTag("address"); + addInlineTag("applet"); + addInlineTag("area"); + addInlineTag("b"); + addInlineTag("base"); + addInlineTag("basefont"); + addInlineTag("bdo"); + addInlineTag("big"); + addInlineTag("blockquote"); + addBlockTag("body", new String[] {"head"}); + addBodylessTag("br"); + addBodylessTag("button"); + addInlineTag("caption"); + addInlineTag("center"); + addInlineTag("cite"); + addInlineTag("code"); + addInlineTag("col"); + addInlineTag("colgroup"); + addInlineTag("dd"); + addInlineTag("del"); + addInlineTag("dfn"); + addInlineTag("dir"); + addBlockTag("div"); + addInlineTag("dl"); + addInlineTag("dt"); + addInlineTag("em"); + addInlineTag("fieldset"); + addInlineTag("font"); + addBlockTag("form"); + addBodylessTag("frame"); + addInlineTag("frameset"); + addInlineTag("h1"); + addInlineTag("h2"); + addInlineTag("h3"); + addInlineTag("h4"); + addInlineTag("h5"); + addInlineTag("h6"); + addBlockTag("head"); + addBodylessTag("hr"); + addBlockTag("html"); + addInlineTag("i"); + addBlockTag("iframe"); + addBodylessTag("img"); + addBodylessTag("input"); + addInlineTag("ins"); + addInlineTag("isindex"); + addInlineTag("kbd"); + addInlineTag("label"); + addInlineTag("legend"); + addInlineTag("li"); + addInlineTag("link"); + addInlineTag("map"); + addInlineTag("menu"); + addBodylessTag("meta"); + addBlockTag("noframes"); + addInlineTag("noscript"); + addBodylessTag("object"); + addInlineTag("ol"); + addInlineTag("optgroup"); + addInlineTag("option"); + addBlockTag("p", new String[] {"p"}); + addInlineTag("param"); + addInlineTag("pre"); + addInlineTag("q"); + addInlineTag("s"); + addInlineTag("samp"); + addInlineTag("script"); + addInlineTag("select"); + addInlineTag("small"); + addInlineTag("span"); + addInlineTag("strike"); + addInlineTag("strong"); + addInlineTag("style"); + addInlineTag("sub"); + addInlineTag("sup"); + addBlockTag("table"); + addBlockTag("tbody"); + addBlockTag("td", new String[] {"td", "th"}); + addInlineTag("textarea"); + addInlineTag("tfoot"); + addBlockTag("th", new String[] {"td", "th"}); + addInlineTag("thead"); + addInlineTag("title"); + addBlockTag("tr", new String[] {"td", "th", "tr"}); + addInlineTag("tt"); + addInlineTag("u"); + addInlineTag("ul"); + addInlineTag("var"); + } + + public HTMLTagInformation lookupTag(String aTag) { + return (HTMLTagInformation) tags.get(aTag); + } + + public void addInlineTag(String aTagName) { + addTag(aTagName, false, true, null); + } + + public void addBodylessTag(String aTagName) { + addTag(aTagName, false, false, null); + } + + public void addBlockTag(String aTagName) { + addTag(aTagName, true, true, null); + } + + public void addBlockTag(String aTagName, String[] anAutoCloseList) { + addTag(aTagName, true, true, anAutoCloseList); + } + + public void addTag(String aTagName, boolean anIsBlock, boolean aHasBody, String[] anAutoCloseList) { + HTMLTagInformation tagInformation = new HTMLTagInformation(aTagName, anIsBlock, aHasBody); + + if (anAutoCloseList!=null) { + for (int i = 0; i < anAutoCloseList.length; i++) { + tagInformation.addAutoClosedTag(anAutoCloseList[i]); + } + } + + tags.put(aTagName, tagInformation); + } + + public class HTMLTagInformation { + private boolean isBlock; + private boolean hasBody; + private String tagName; + private List autoCloseList; + + public HTMLTagInformation(String aTagName, boolean anIsBlock, boolean aHasBody) { + hasBody = aHasBody; + isBlock = anIsBlock; + tagName = aTagName; + autoCloseList = new ArrayList(); + } + + void addAutoClosedTag(String aTag) { + autoCloseList.add(aTag); + } + + public boolean autoClose(String aTag) { + return autoCloseList.contains(aTag); + } + + public boolean getIsBlock() { + return isBlock; + } + + public boolean getHasBody() { + return hasBody; + } + + public String getTagName() { + return tagName; + } + } +} \ No newline at end of file diff --git a/source/mir/util/xml/html/XMLHTMLParserProvider.java b/source/mir/util/xml/html/XMLHTMLParserProvider.java new file mode 100755 index 00000000..35708eb5 --- /dev/null +++ b/source/mir/util/xml/html/XMLHTMLParserProvider.java @@ -0,0 +1,91 @@ +package mir.util.xml.html; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import mir.util.xml.XMLParserEngine; +import mir.util.xml.XMLParserExc; +import mir.util.xml.XMLParserFailure; +import mir.util.xml.XMLReaderTool; + +/** + */ + +public class XMLHTMLParserProvider implements XMLParserEngine.XMLParserProvider { + public XMLHTMLParserProvider() { + } + + public void parse(java.io.Reader aReader, final XMLParserEngine.XMLParserReceiver aReceiver) throws XMLParserExc, XMLParserFailure { + HTMLParser parser = new HTMLParser(); + + try { + aReceiver.startDocument(); + + parser.parse(aReader, new HTMLParser.ParserReceiver() { + public void dtd(String aDTD) throws HTMLParserExc { + try { + aReceiver.extra(aDTD); + } + catch (XMLParserExc t) { + throw new HTMLParserFailure(t); + } + } + + public void openTag(String aTag, Map anAttributes) { + Map attributes = new HashMap(); + Iterator i = anAttributes.entrySet().iterator(); + + while (i.hasNext()) { + Map.Entry entry = (Map.Entry) i.next(); + attributes.put( + XMLReaderTool.getXMLNameForQualifiedName((String) entry.getKey()), entry.getValue()); + } + + try { + aReceiver.startElement(XMLReaderTool.getXMLNameForQualifiedName(aTag), attributes); + } + catch (XMLParserExc e) { + throw new HTMLParserFailure(e); + } + } + + public void closeTag(String aTag) { + try { + aReceiver.endElement(XMLReaderTool.getXMLNameForQualifiedName(aTag)); + } + catch (XMLParserExc e) { + throw new HTMLParserFailure(e); + } + } + + public void comment(String aData) { + try { + aReceiver.extra(aData); + } + catch (XMLParserExc e) { + throw new HTMLParserFailure(e); + } + } + + public void cdata(String aData) { + try { + aReceiver.text(aData); + } + catch (XMLParserExc e) { + throw new HTMLParserFailure(e); + } + } + }); + + aReceiver.endDocument(); + } + catch (IOException e) { + throw new XMLParserFailure(e); + } + catch (HTMLParserExc e) { + throw new XMLParserFailure(e); + } + } +} diff --git a/source/mircoders/global/MirGlobal.java b/source/mircoders/global/MirGlobal.java index b2f42326..b4599fd3 100755 --- a/source/mircoders/global/MirGlobal.java +++ b/source/mircoders/global/MirGlobal.java @@ -1,289 +1,296 @@ -/* - * Copyright (C) 2001, 2002 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. - * If you do not wish to do so, delete this exception statement from your version. - */ - -package mircoders.global; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import mir.config.MirPropertiesConfiguration; -import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; -import mir.entity.adapter.EntityAdapter; -import mir.log.LoggerWrapper; -import mir.misc.ConfigException; -import mircoders.accesscontrol.AccessControl; -import mircoders.entity.EntityComment; -import mircoders.entity.EntityContent; -import mircoders.entity.EntityUsers; -import mircoders.localizer.MirAdminInterfaceLocalizer; -import mircoders.localizer.MirCachingLocalizerDecorator; -import mircoders.localizer.MirLocalizer; - -public class MirGlobal { - static private MirPropertiesConfiguration configuration; - static private MirLocalizer localizer; - static private ProducerEngine producerEngine; - static private Abuse abuse; - static private MRUCache mruCache; - static private AccessControl accessControl; - static private Map articleOperations; - static private Map commentOperations; - static private Map loggedInUsers = new HashMap(); - static private Map loggedInUserIds = new HashMap(); - static private LoggerWrapper logger = new LoggerWrapper("Global"); - static private LoggerWrapper adminUsageLogger = new LoggerWrapper("AdminUsage"); - - public synchronized static MirLocalizer localizer() { - String localizerClassName; - Class localizerClass; - - if (localizer == null ) { - localizerClassName = config().getString("Mir.Localizer", "mirlocal.localizer.basic.MirBasicLocalizer"); - - try { - localizerClass = Class.forName(localizerClassName); - } - catch (Throwable t) { - throw new ConfigException("localizer class '" + localizerClassName + "' not found: " + t.toString()); - } - - if (!(MirLocalizer.class.isAssignableFrom(localizerClass))) - throw new ConfigException("localizer class '" + localizerClassName + "' is not assignable from MirLocalizer"); - - try { - localizer = new MirCachingLocalizerDecorator((MirLocalizer) localizerClass.newInstance()); - } - catch (Throwable t) { - throw new ConfigException("localizer class '" + localizerClassName + "' cannot be instantiated: " + t.toString()); - } - } - - return localizer; - } - - public static Abuse abuse() { - if (abuse==null) { - synchronized(MirGlobal.class) { - if (abuse==null) - abuse = new Abuse(); - } - } - - return abuse; - } - - public static MirPropertiesConfiguration config() { - try { - return MirPropertiesConfiguration.instance(); - } - catch (PropertiesConfigExc e) { - throw new RuntimeException(e.getMessage()); - } - } - - public static ProducerEngine producerEngine() { - if (producerEngine == null) { - producerEngine = new ProducerEngine(); - } - - return producerEngine; - } - - public static MRUCache mruCache() { - synchronized(MirGlobal.class) { - if (mruCache == null) { - mruCache = new MRUCache(); - } - return mruCache; - } - } - - public static synchronized AccessControl accessControl() { - if (accessControl == null) { - accessControl=new AccessControl(); - } - - return accessControl; - } - - public static void performArticleOperation(EntityUsers aUser, EntityContent anArticle, String anOperation) { - MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = getArticleOperationForName(anOperation); - - try { - EntityAdapter user = null; - if (aUser!=null) - user = localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser); - - if (operation!=null) - operation.perform( - user, - localizer().dataModel().adapterModel().makeEntityAdapter("content", anArticle)); - } - catch (Throwable t) { - t.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); - - throw new RuntimeException(t.toString()); - } - } - - public static void performCommentOperation(EntityUsers aUser, EntityComment aComment, String anOperation) { - MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = getCommentOperationForName(anOperation); - - try { - EntityAdapter user = null; - if (aUser!=null) - user = localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser); - - if (operation!=null) - operation.perform( - user, - localizer().dataModel().adapterModel().makeEntityAdapter("comment", aComment)); - } - catch (Throwable t) { - throw new RuntimeException(t.toString()); - } - } - - private synchronized static MirAdminInterfaceLocalizer.MirSimpleEntityOperation getArticleOperationForName(String aName) { - try { - if (articleOperations == null) { - articleOperations = new HashMap(); - Iterator i = localizer().adminInterface().simpleArticleOperations().iterator(); - while (i.hasNext()) { - MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next(); - articleOperations.put(operation.getName(), operation); - } - } - - return (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) articleOperations.get(aName); - } - catch (Throwable t) { - throw new RuntimeException(t.toString()); - } - } - - private synchronized static MirAdminInterfaceLocalizer.MirSimpleEntityOperation getCommentOperationForName(String aName) { - try { - if (commentOperations == null) { - commentOperations = new HashMap(); - Iterator i = localizer().adminInterface().simpleCommentOperations().iterator(); - while (i.hasNext()) { - MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next(); - commentOperations.put(operation.getName(), operation); - } - } - - return (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) commentOperations.get(aName); - } - catch (Throwable t) { - throw new RuntimeException(t.toString()); - } - } - - public static boolean isUserLoggedIn(String anId) { - synchronized (loggedInUserIds) { - return loggedInUserIds.containsKey(anId); - } - } - - public static List getLoggedInUsers() { - List result = new Vector(); - - synchronized (loggedInUsers) { - Iterator i = loggedInUsers.entrySet().iterator(); - - while (i.hasNext()) { - Map.Entry entry = (Map.Entry) i.next(); - - Map item = new HashMap(); - item.put("name", entry.getKey()); - item.put("count", entry.getValue()); - result.add(item); - } - } - - return result; - } - - public static void registerLogin(String aName, String anId) { - modifyLoggedInCount(aName, anId, 1); - } - - public static void registerLogout(String aName, String anId) { - modifyLoggedInCount(aName, anId, -1); - } - - private static void modifyLoggedInCount(String aName, String anId, int aModifier) { - synchronized (loggedInUsers) { - Integer count = (Integer) loggedInUsers.get(aName); - if (count==null) - count = new Integer(0); - - if (count.intValue()+aModifier<=0) { - loggedInUsers.remove(aName); - } - else { - loggedInUsers.put(aName, new Integer(count.intValue() + aModifier)); - } - } - - synchronized (loggedInUserIds) { - Integer count = (Integer) loggedInUserIds.get(anId); - if (count==null) - count = new Integer(0); - - if (count.intValue()+aModifier<=0) { - loggedInUserIds.remove(anId); - } - else { - loggedInUserIds.put(anId, new Integer(count.intValue() + aModifier)); - } - } - } - - public static void logAdminUsage(EntityUsers aUser, String anObject, String aDescription) { - try { - if (config().getString("Mir.Admin.LogAdminActivity", "0").equals("1")) { - String user = "unknown (" + aUser.toString() + ")"; - if (aUser != null) - user = aUser.getValue("login"); - adminUsageLogger.info(user + " | " + anObject + " | " + aDescription); - } - } - catch (Throwable t) { - logger.error("Error while logging admin usage ("+aUser.toString()+", "+aDescription+"): " +t.toString()); - } - } -} - - +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. + */ + +package mircoders.global; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import mir.config.MirPropertiesConfiguration; +import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; +import mir.entity.adapter.EntityAdapter; +import mir.log.LoggerWrapper; +import mir.misc.ConfigException; +import mircoders.accesscontrol.AccessControl; +import mircoders.entity.EntityComment; +import mircoders.entity.EntityContent; +import mircoders.entity.EntityUsers; +import mircoders.localizer.MirAdminInterfaceLocalizer; +import mircoders.localizer.MirCachingLocalizerDecorator; +import mircoders.localizer.MirLocalizer; + +public class MirGlobal { + static private MirPropertiesConfiguration configuration; + static private MirLocalizer localizer; + static private ProducerEngine producerEngine; + static private Abuse abuse; + static private MRUCache mruCache; + static private AccessControl accessControl; + static private Map articleOperations; + static private Map commentOperations; + static private Map loggedInUsers = new HashMap(); + static private Map loggedInUserIds = new HashMap(); + static private LoggerWrapper logger = new LoggerWrapper("Global"); + static private LoggerWrapper adminUsageLogger = new LoggerWrapper("AdminUsage"); + + public synchronized static MirLocalizer localizer() { + String localizerClassName; + Class localizerClass; + + if (localizer == null ) { + localizerClassName = config().getString("Mir.Localizer", "mirlocal.localizer.basic.MirBasicLocalizer"); + + try { + localizerClass = Class.forName(localizerClassName); + } + catch (Throwable t) { + throw new ConfigException("localizer class '" + localizerClassName + "' not found: " + t.toString()); + } + + if (!(MirLocalizer.class.isAssignableFrom(localizerClass))) + throw new ConfigException("localizer class '" + localizerClassName + "' is not assignable from MirLocalizer"); + + try { + localizer = new MirCachingLocalizerDecorator((MirLocalizer) localizerClass.newInstance()); + } + catch (Throwable t) { + throw new ConfigException("localizer class '" + localizerClassName + "' cannot be instantiated: " + t.toString()); + } + } + + return localizer; + } + + public static String getStatus() { + StringBuffer result = new StringBuffer(); + + System.gc(); + result.append(Runtime.getRuntime().freeMemory()).append("/"); + result.append(Runtime.getRuntime().freeMemory()).append(" free memory | "); + result.append(Thread.currentThread().activeCount()).append(" active threads"); + + return result.toString(); + } + + public synchronized static Abuse abuse() { + if (abuse==null) + abuse = new Abuse(); + + return abuse; + } + + public static MirPropertiesConfiguration config() { + try { + return MirPropertiesConfiguration.instance(); + } + catch (PropertiesConfigExc e) { + throw new RuntimeException(e.getMessage()); + } + } + + public static ProducerEngine producerEngine() { + if (producerEngine == null) { + producerEngine = new ProducerEngine(); + } + + return producerEngine; + } + + public static MRUCache mruCache() { + synchronized(MirGlobal.class) { + if (mruCache == null) { + mruCache = new MRUCache(); + } + return mruCache; + } + } + + public static synchronized AccessControl accessControl() { + if (accessControl == null) { + accessControl=new AccessControl(); + } + + return accessControl; + } + + public static void performArticleOperation(EntityUsers aUser, EntityContent anArticle, String anOperation) { + MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = getArticleOperationForName(anOperation); + + try { + EntityAdapter user = null; + if (aUser!=null) + user = localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser); + + if (operation!=null) + operation.perform( + user, + localizer().dataModel().adapterModel().makeEntityAdapter("content", anArticle)); + } + catch (Throwable t) { + t.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); + + throw new RuntimeException(t.toString()); + } + } + + public static void performCommentOperation(EntityUsers aUser, EntityComment aComment, String anOperation) { + MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = getCommentOperationForName(anOperation); + + try { + EntityAdapter user = null; + if (aUser!=null) + user = localizer().dataModel().adapterModel().makeEntityAdapter("user", aUser); + + if (operation!=null) + operation.perform( + user, + localizer().dataModel().adapterModel().makeEntityAdapter("comment", aComment)); + } + catch (Throwable t) { + throw new RuntimeException(t.toString()); + } + } + + private synchronized static MirAdminInterfaceLocalizer.MirSimpleEntityOperation getArticleOperationForName(String aName) { + try { + if (articleOperations == null) { + articleOperations = new HashMap(); + Iterator i = localizer().adminInterface().simpleArticleOperations().iterator(); + while (i.hasNext()) { + MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next(); + articleOperations.put(operation.getName(), operation); + } + } + + return (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) articleOperations.get(aName); + } + catch (Throwable t) { + throw new RuntimeException(t.toString()); + } + } + + private synchronized static MirAdminInterfaceLocalizer.MirSimpleEntityOperation getCommentOperationForName(String aName) { + try { + if (commentOperations == null) { + commentOperations = new HashMap(); + Iterator i = localizer().adminInterface().simpleCommentOperations().iterator(); + while (i.hasNext()) { + MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation = (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next(); + commentOperations.put(operation.getName(), operation); + } + } + + return (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) commentOperations.get(aName); + } + catch (Throwable t) { + throw new RuntimeException(t.toString()); + } + } + + public static boolean isUserLoggedIn(String anId) { + synchronized (loggedInUserIds) { + return loggedInUserIds.containsKey(anId); + } + } + + public static List getLoggedInUsers() { + List result = new Vector(); + + synchronized (loggedInUsers) { + Iterator i = loggedInUsers.entrySet().iterator(); + + while (i.hasNext()) { + Map.Entry entry = (Map.Entry) i.next(); + + Map item = new HashMap(); + item.put("name", entry.getKey()); + item.put("count", entry.getValue()); + result.add(item); + } + } + + return result; + } + + public static void registerLogin(String aName, String anId) { + modifyLoggedInCount(aName, anId, 1); + } + + public static void registerLogout(String aName, String anId) { + modifyLoggedInCount(aName, anId, -1); + } + + private static void modifyLoggedInCount(String aName, String anId, int aModifier) { + synchronized (loggedInUsers) { + Integer count = (Integer) loggedInUsers.get(aName); + if (count==null) + count = new Integer(0); + + if (count.intValue()+aModifier<=0) { + loggedInUsers.remove(aName); + } + else { + loggedInUsers.put(aName, new Integer(count.intValue() + aModifier)); + } + } + + synchronized (loggedInUserIds) { + Integer count = (Integer) loggedInUserIds.get(anId); + if (count==null) + count = new Integer(0); + + if (count.intValue()+aModifier<=0) { + loggedInUserIds.remove(anId); + } + else { + loggedInUserIds.put(anId, new Integer(count.intValue() + aModifier)); + } + } + } + + public static void logAdminUsage(EntityUsers aUser, String anObject, String aDescription) { + try { + if (config().getString("Mir.Admin.LogAdminActivity", "0").equals("1")) { + String user = "unknown (" + aUser.toString() + ")"; + if (aUser != null) + user = aUser.getValue("login"); + adminUsageLogger.info(user + " | " + anObject + " | " + aDescription); + } + } + catch (Throwable t) { + logger.error("Error while logging admin usage ("+aUser.toString()+", "+aDescription+"): " +t.toString()); + } + } +} + + diff --git a/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java b/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java index 819b5b3d..24b9982f 100755 --- a/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicProducerLocalizer.java @@ -148,6 +148,16 @@ public class MirBasicProducerLocalizer implements MirProducerLocalizer { return producerFactories; }; + public ProducerFactory getFactoryForName(String aName) { + try { + factories(); + } + catch (Throwable t) { + } + + return (ProducerFactory) nameToFactory.get(aName); + } + protected void setupProducerNodeBuilderLibrary(ProducerNodeBuilderLibrary aLibrary) throws MirLocalizerFailure { try { DefaultProducerNodeBuilders.registerBuilders( @@ -164,25 +174,12 @@ public class MirBasicProducerLocalizer implements MirProducerLocalizer { ProducerConfigReader reader; ProducerNodeBuilderLibrary library = new ProducerNodeBuilderLibrary(); setupProducerNodeBuilderLibrary(library); - List usedFiles = new Vector(); - Iterator i; aFileMonitor.clear(); reader = new ProducerConfigReader(); - reader.parseFile(MirGlobal.config().getString("Home") + File.separatorChar + MirGlobal.config().getString("Mir.Localizer.ProducerConfigFile"), library, aFactories, usedFiles); - i = usedFiles.iterator(); - while (i.hasNext()) - aFileMonitor.addFile((File) i.next()); - } - - public ProducerFactory getFactoryForName(String aName) { - try { - factories(); - } - catch (Throwable t) { - } - - return (ProducerFactory) nameToFactory.get(aName); + File inputFile = new File(MirGlobal.config().getString("Home"), MirGlobal.config().getString("Mir.Localizer.ProducerConfigFile")); + aFileMonitor.addFile(inputFile); + reader.parse(inputFile, library, aFactories); } } diff --git a/source/mircoders/module/ModuleUsers.java b/source/mircoders/module/ModuleUsers.java index 8d317182..c99bd9e2 100755 --- a/source/mircoders/module/ModuleUsers.java +++ b/source/mircoders/module/ModuleUsers.java @@ -70,7 +70,7 @@ public class ModuleUsers extends AbstractModule * @param password The password * @return The authenticated user, or <code>null</code> if the user * doesn't exist, or the supplied password is invalid. - * @throws ModuleException + * @throws ModuleExc */ public EntityUsers getUserForLogin(String user, String password) throws ModuleExc, ModuleFailure { diff --git a/source/mircoders/producer/UnIndexingProducerNode.java b/source/mircoders/producer/UnIndexingProducerNode.java index 5a5a2426..77a25d51 100755 --- a/source/mircoders/producer/UnIndexingProducerNode.java +++ b/source/mircoders/producer/UnIndexingProducerNode.java @@ -18,13 +18,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. * If you do not wish to do so, delete this exception statement from your version. */ package mircoders.producer; @@ -40,12 +40,10 @@ import mir.util.ParameterExpander; import mircoders.entity.EntityContent; import mircoders.search.IndexUtil; - public class UnIndexingProducerNode implements ProducerNode { private String contentKey; private String indexPath; - public UnIndexingProducerNode(String aContentKey, String pathToIndex) { contentKey = aContentKey; indexPath=pathToIndex; @@ -75,8 +73,7 @@ public class UnIndexingProducerNode implements ProducerNode { } aLogger.info("UnIndexing " + (String) entity.getValue("id") + " out of " + index); - IndexUtil.unindexEntity((EntityContent) entity,index); - + IndexUtil.unindexEntity((EntityContent) entity, index); } catch (Throwable t) { aLogger.error("Error while unindexing content: " + t.getMessage()); diff --git a/source/mircoders/producer/reader/SupplementalProducerNodeBuilders.java b/source/mircoders/producer/reader/SupplementalProducerNodeBuilders.java index 4c688f38..11466302 100755 --- a/source/mircoders/producer/reader/SupplementalProducerNodeBuilders.java +++ b/source/mircoders/producer/reader/SupplementalProducerNodeBuilders.java @@ -18,13 +18,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. * If you do not wish to do so, delete this exception statement from your version. */ package mircoders.producer.reader; @@ -36,8 +36,9 @@ import mir.producer.ProducerNode; import mir.producer.reader.DefaultProducerNodeBuilders; import mir.producer.reader.ProducerConfigExc; import mir.producer.reader.ProducerNodeBuilderLibrary; -import mir.util.XMLReader; -import mir.util.XMLReaderTool; +import mir.util.xml.XMLParserEngine; +import mir.util.xml.XMLReaderTool; +import mir.util.xml.XMLParserExc; import mircoders.producer.ContentMarkingProducerNode; import mircoders.producer.ContentModifyingProducerNode; import mircoders.producer.IndexingProducerNode; @@ -73,8 +74,8 @@ public class SupplementalProducerNodeBuilders { super(MARKER_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, MARKER_REQUIRED_ATTRIBUTES, MARKER_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, MARKER_REQUIRED_ATTRIBUTES, MARKER_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get(MARKER_KEY_ATTRIBUTE); }; @@ -98,8 +99,8 @@ public class SupplementalProducerNodeBuilders { super(INDEXER_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, INDEXER_REQUIRED_ATTRIBUTES, INDEXER_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, INDEXER_REQUIRED_ATTRIBUTES, INDEXER_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get(INDEXER_KEY_ATTRIBUTE); pathToIndex = (String) anAttributes.get(INDEXER_INDEX_ATTRIBUTE); @@ -125,8 +126,8 @@ public class SupplementalProducerNodeBuilders { super(UNINDEXER_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, UNINDEXER_REQUIRED_ATTRIBUTES, UNINDEXER_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, UNINDEXER_REQUIRED_ATTRIBUTES, UNINDEXER_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get(UNINDEXER_KEY_ATTRIBUTE); pathToIndex = (String) anAttributes.get(UNINDEXER_INDEX_ATTRIBUTE); @@ -154,8 +155,8 @@ public class SupplementalProducerNodeBuilders { super(CONTENT_MODIFIER_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, CONTENT_MODIFIER_REQUIRED_ATTRIBUTES, CONTENT_MODIFIER_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, CONTENT_MODIFIER_REQUIRED_ATTRIBUTES, CONTENT_MODIFIER_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get(CONTENT_MODIFIER_KEY_ATTRIBUTE); field = (String) anAttributes.get(CONTENT_MODIFIER_FIELD_ATTRIBUTE); @@ -180,8 +181,8 @@ public class SupplementalProducerNodeBuilders { super(MEDIA_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, MEDIA_REQUIRED_ATTRIBUTES, MEDIA_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, MEDIA_REQUIRED_ATTRIBUTES, MEDIA_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get(MEDIA_KEY_ATTRIBUTE); }; @@ -213,8 +214,8 @@ public class SupplementalProducerNodeBuilders { super(MARKER_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, MARKER_REQUIRED_ATTRIBUTES, MARKER_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, MARKER_REQUIRED_ATTRIBUTES, MARKER_OPTIONAL_ATTRIBUTES); key = (String) anAttributes.get(MARKER_KEY_ATTRIBUTE); numLinesBetweenImages = (String) anAttributes.get(PDF_NUM_LINES_ATTRIBUTE); @@ -249,8 +250,8 @@ public class SupplementalProducerNodeBuilders { super(MARKER_SUBNODES); } - public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLReader.XMLReaderExc { - XMLReaderTool.checkAttributes(anAttributes, MARKER_REQUIRED_ATTRIBUTES, MARKER_OPTIONAL_ATTRIBUTES); + public void setAttributes(Map anAttributes) throws ProducerConfigExc, XMLParserExc { + mir.util.xml.XMLReaderTool.checkAttributes(anAttributes, MARKER_REQUIRED_ATTRIBUTES, MARKER_OPTIONAL_ATTRIBUTES); generator = (String) anAttributes.get(PDF_GENERATOR_ATTRIBUTE); destination = (String) anAttributes.get(PDF_DESTINATION_ATTRIBUTE); diff --git a/source/mircoders/servlet/ServletHelper.java b/source/mircoders/servlet/ServletHelper.java index 0d6d7df2..ea2db026 100755 --- a/source/mircoders/servlet/ServletHelper.java +++ b/source/mircoders/servlet/ServletHelper.java @@ -1,154 +1,156 @@ -/* - * Copyright (C) 2001, 2002 The Mir-coders group - * - * This file is part of Mir. - * - * Mir is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Mir is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Mir; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. - * If you do not wish to do so, delete this exception statement from your version. - */ -package mircoders.servlet; - -import java.io.PrintWriter; -import java.util.Locale; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import mir.config.MirPropertiesConfiguration; -import mir.entity.adapter.EntityAdapter; -import mir.generator.Generator; -import mir.generator.GeneratorHelper; -import mir.log.LoggerWrapper; -import mir.servlet.ServletModuleExc; -import mir.servlet.ServletModuleFailure; -import mircoders.entity.EntityUsers; -import mircoders.global.MirGlobal; - - -public class ServletHelper { - private static LoggerWrapper logger = new LoggerWrapper("ServletModule.Helper"); - - public static Map makeGenerationData(HttpServletRequest aRequest, HttpServletResponse aResponse, Locale[] aLocales) throws ServletModuleExc { - return makeGenerationData(aRequest, aResponse, aLocales, "bundles.adminlocal", "bundles.admin"); - } - - public static Map makeGenerationData(HttpServletRequest aRequest, HttpServletResponse aResponse, Locale[] aLocales, String aBundle) throws ServletModuleExc { - return makeGenerationData(aRequest, aResponse, aLocales, aBundle, aBundle); - } - - public static Map makeGenerationData(HttpServletRequest aRequest, HttpServletResponse aResponse, Locale[] aLocales, String aBundle, String aDefaultBundle) throws ServletModuleExc { - try { - MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance(); - Map result=GeneratorHelper.makeBasicGenerationData(aLocales,aBundle,aDefaultBundle); - if (configuration.getString("Mir.Admin.ShowLoggedinUsers").equals("1")) { - result.put("loggedinusers", MirGlobal.getLoggedInUsers()); - } - else - result.put("loggedinusers", null); - - // ML: hackish - ((Map) result.get("config")).put("actionRoot", - aResponse.encodeURL(MirGlobal.config().getString("RootUri") + "/servlet/Mir")); - - result.put("returnurl", null); - result.put("login_user", getUserAdapter(aRequest)); - - return result; - } - catch (Throwable t) { - throw new ServletModuleFailure(t); - } - } - - public static void generateResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) throws ServletModuleExc { - logger.debug("generator used: " + aGenerator); - - Generator generator; - - try { - generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator(aGenerator); - - generator.generate(aWriter, aGenerationData, logger); - } - catch (Throwable t) { - throw new ServletModuleFailure(t); - } - } - - public static void generateOpenPostingResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) throws ServletModuleExc { - Generator generator; - - try { - generator = MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().makeGenerator(aGenerator); - - generator.generate(aWriter, aGenerationData, logger); - } - catch (Throwable t) { - throw new ServletModuleFailure(t); - } - } - - public static void redirect(HttpServletResponse aResponse, String aQuery) throws ServletModuleExc, ServletModuleFailure { - try { - aResponse.sendRedirect(aResponse.encodeRedirectURL(MirPropertiesConfiguration.instance().getString("RootUri") + "/servlet/Mir?"+aQuery)); - } - catch (Throwable t) { - throw new ServletModuleFailure("ServletModule.redirect: " +t.getMessage(), t); - } - } - - public static void redirect(HttpServletResponse aResponse, String aModule, String aMethod) throws ServletModuleExc, ServletModuleFailure { - redirect(aResponse, "module="+aModule+"&do="+aMethod); - } - - public static void setUser(HttpServletRequest aRequest, EntityUsers aUser) { - if (aUser!=null) - aRequest.getSession().setAttribute("login.uid", aUser); - else - aRequest.getSession().removeAttribute("login.uid"); - } - - public static EntityUsers getUser(HttpServletRequest aRequest) { - return (EntityUsers) aRequest.getSession().getAttribute("login.uid"); - } - - public static EntityAdapter getUserAdapter(HttpServletRequest aRequest) { - try { - return MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter( "user", (EntityUsers) aRequest.getSession().getAttribute("login.uid")); - } - catch (Throwable t) { - throw new ServletModuleFailure (t); - } - } - - public static String getUserName(HttpServletRequest aRequest) { - EntityUsers user = getUser(aRequest); - - if (user!=null) - return user.getValue("login"); - else - return "nobody"; - } -} +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. + */ +package mircoders.servlet; + +import java.io.PrintWriter; +import java.util.Locale; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import mir.config.MirPropertiesConfiguration; +import mir.entity.adapter.EntityAdapter; +import mir.generator.Generator; +import mir.generator.GeneratorHelper; +import mir.log.LoggerWrapper; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleFailure; +import mircoders.entity.EntityUsers; +import mircoders.global.MirGlobal; + + +public class ServletHelper { + private static LoggerWrapper logger = new LoggerWrapper("ServletModule.Helper"); + + public static Map makeGenerationData(HttpServletRequest aRequest, HttpServletResponse aResponse, Locale[] aLocales) throws ServletModuleExc { + return makeGenerationData(aRequest, aResponse, aLocales, "bundles.adminlocal", "bundles.admin"); + } + + public static Map makeGenerationData(HttpServletRequest aRequest, HttpServletResponse aResponse, Locale[] aLocales, String aBundle) throws ServletModuleExc { + return makeGenerationData(aRequest, aResponse, aLocales, aBundle, aBundle); + } + + public static Map makeGenerationData(HttpServletRequest aRequest, HttpServletResponse aResponse, Locale[] aLocales, String aBundle, String aDefaultBundle) throws ServletModuleExc { + try { + MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance(); + Map result=GeneratorHelper.makeBasicGenerationData(aLocales,aBundle,aDefaultBundle); + if (configuration.getString("Mir.Admin.ShowLoggedinUsers").equals("1")) { + result.put("loggedinusers", MirGlobal.getLoggedInUsers()); + } + else { + result.put("loggedinusers", null); + } + result.put("systemstatus", MirGlobal.getStatus()); + + // ML: hackish + ((Map) result.get("config")).put("actionRoot", + aResponse.encodeURL(MirGlobal.config().getString("RootUri") + "/servlet/Mir")); + + result.put("returnurl", null); + result.put("login_user", getUserAdapter(aRequest)); + + return result; + } + catch (Throwable t) { + throw new ServletModuleFailure(t); + } + } + + public static void generateResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) throws ServletModuleExc { + logger.debug("generator used: " + aGenerator); + + Generator generator; + + try { + generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator(aGenerator); + + generator.generate(aWriter, aGenerationData, logger); + } + catch (Throwable t) { + throw new ServletModuleFailure(t); + } + } + + public static void generateOpenPostingResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) throws ServletModuleExc { + Generator generator; + + try { + generator = MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().makeGenerator(aGenerator); + + generator.generate(aWriter, aGenerationData, logger); + } + catch (Throwable t) { + throw new ServletModuleFailure(t); + } + } + + public static void redirect(HttpServletResponse aResponse, String aQuery) throws ServletModuleExc, ServletModuleFailure { + try { + aResponse.sendRedirect(aResponse.encodeRedirectURL(MirPropertiesConfiguration.instance().getString("RootUri") + "/servlet/Mir?"+aQuery)); + } + catch (Throwable t) { + throw new ServletModuleFailure("ServletModule.redirect: " +t.getMessage(), t); + } + } + + public static void redirect(HttpServletResponse aResponse, String aModule, String aMethod) throws ServletModuleExc, ServletModuleFailure { + redirect(aResponse, "module="+aModule+"&do="+aMethod); + } + + public static void setUser(HttpServletRequest aRequest, EntityUsers aUser) { + if (aUser!=null) + aRequest.getSession().setAttribute("login.uid", aUser); + else + aRequest.getSession().removeAttribute("login.uid"); + } + + public static EntityUsers getUser(HttpServletRequest aRequest) { + return (EntityUsers) aRequest.getSession().getAttribute("login.uid"); + } + + public static EntityAdapter getUserAdapter(HttpServletRequest aRequest) { + try { + return MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter( "user", (EntityUsers) aRequest.getSession().getAttribute("login.uid")); + } + catch (Throwable t) { + throw new ServletModuleFailure (t); + } + } + + public static String getUserName(HttpServletRequest aRequest) { + EntityUsers user = getUser(aRequest); + + if (user!=null) + return user.getValue("login"); + else + return "nobody"; + } +} diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index 3f890736..02936057 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -11,7 +11,7 @@ * Mir is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU General Public License for more details.f * * You should have received a copy of the GNU General Public License * along with Mir; if not, write to the Free Software @@ -121,7 +121,7 @@ import org.apache.struts.util.MessageResources; * open-postings to the newswire * * @author mir-coders group - * @version $Id: ServletModuleOpenIndy.java,v 1.89.2.9 2003/12/03 18:10:46 rk Exp $ + * @version $Id: ServletModuleOpenIndy.java,v 1.89.2.10 2004/01/11 20:35:53 zapata Exp $ * */ @@ -310,8 +310,7 @@ public class ServletModuleOpenIndy extends ServletModule */ public void addposting(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure - { + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { try { if (MirGlobal.abuse().getOpenPostingDisabled()) { openPostingDisabled(req, res); @@ -357,7 +356,6 @@ public class ServletModuleOpenIndy extends ServletModule extraInfo.put("languagePopUpData", DatabaseLanguage.getInstance().getPopupData()); extraInfo.put("themenPopupData", DatabaseTopics.getInstance().getPopupData()); - extraInfo.put("topics", topicsModule.getTopicsList()); deliver(req, res, mergeData, extraInfo, postingFormTemplate); } catch (Throwable t) { @@ -844,7 +842,7 @@ public class ServletModuleOpenIndy extends ServletModule queryString = queryString + " +" + videoFragment; } - if (queryString == null) { + if (queryString == null || queryString.length()==0) { queryString = ""; } else { @@ -1020,83 +1018,80 @@ public class ServletModuleOpenIndy extends ServletModule */ public void getpdf(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { - long starttime=System.currentTimeMillis(); + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { + long starttime = System.currentTimeMillis(); String ID_REQUEST_PARAM = "id"; int maxArticlesInNewsleter = 15; // it is nice not to be dos'ed try { String idParam = req.getParameter(ID_REQUEST_PARAM); if (idParam != null) { + RE re = new RE("[0-9]+"); - RE re = new RE("[0-9]+"); - + REMatch[] idMatches = re.getAllMatches(idParam); - REMatch[] idMatches=re.getAllMatches(idParam); + String cacheSelector = ""; - String cacheSelector=""; - - for (int i = 0; i < idMatches.length; i++){ - cacheSelector= cacheSelector + "," + idMatches[i].toString(); - } + for (int i = 0; i < idMatches.length; i++) { + cacheSelector = cacheSelector + "," + idMatches[i].toString(); + } - String cacheType="pdf"; + String cacheType = "pdf"; - CacheKey theCacheKey = new CacheKey(cacheType,cacheSelector); + CacheKey theCacheKey = new CacheKey(cacheType, cacheSelector); - byte[] thePDF; + byte[] thePDF; - if (MirGlobal.mruCache().hasObject(theCacheKey)){ - logger.info("fetching pdf from cache"); - thePDF = (byte[]) MirGlobal.mruCache().getObject(theCacheKey); - } - else { - logger.info("generating pdf and caching it"); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - PDFGenerator pdfMaker = new PDFGenerator(out); - - if (idMatches.length > 1){ - pdfMaker.addLine(); - for (int i = 0; i < idMatches.length && i < maxArticlesInNewsleter; i++){ - REMatch aMatch = idMatches[i]; - String id=aMatch.toString(); - EntityContent contentEnt = (EntityContent)contentModule.getById(id); - pdfMaker.addIndexItem(contentEnt); - } - } + if (MirGlobal.mruCache().hasObject(theCacheKey)) { + logger.info("fetching pdf from cache"); + thePDF = (byte[]) MirGlobal.mruCache().getObject(theCacheKey); + } + else { + logger.info("generating pdf and caching it"); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + PDFGenerator pdfMaker = new PDFGenerator(out); + + if (idMatches.length > 1) { + pdfMaker.addLine(); + for (int i = 0; i < idMatches.length && i < maxArticlesInNewsleter; i++) { + REMatch aMatch = idMatches[i]; + String id = aMatch.toString(); + EntityContent contentEnt = (EntityContent) contentModule.getById(id); + pdfMaker.addIndexItem(contentEnt); + } + } - for (int i = 0; i < idMatches.length; i++){ - REMatch aMatch = idMatches[i]; - String id=aMatch.toString(); - EntityContent contentEnt = (EntityContent)contentModule.getById(id); + for (int i = 0; i < idMatches.length; i++) { + REMatch aMatch = idMatches[i]; + String id = aMatch.toString(); + EntityContent contentEnt = (EntityContent) contentModule.getById(id); - pdfMaker.add(contentEnt); - } + pdfMaker.add(contentEnt); + } - pdfMaker.stop(); - thePDF = out.toByteArray(); + pdfMaker.stop(); + thePDF = out.toByteArray(); - //and save all our hard work! - MirGlobal.mruCache().storeObject(theCacheKey,thePDF); - } + //and save all our hard work! + MirGlobal.mruCache().storeObject(theCacheKey, thePDF); + } - res.setContentType("application/pdf"); - res.setContentLength(thePDF.length); - res.getOutputStream().write(thePDF); - res.getOutputStream().flush(); - String elapsedtime=(new Long(System.currentTimeMillis()-starttime)).toString(); - logger.info("pdf retireval took "+elapsedtime + " milliseconds" ); + res.setContentType("application/pdf"); + res.setContentLength(thePDF.length); + res.getOutputStream().write(thePDF); + res.getOutputStream().flush(); + String elapsedtime = (new Long(System.currentTimeMillis() - starttime)).toString(); + logger.info("pdf retireval took " + elapsedtime + " milliseconds"); } else { - throw new ServletModuleExc("Missing id."); + throw new ServletModuleExc("Missing id."); } } catch (Throwable t) { logger.error(t.toString()); throw new ServletModuleFailure(t); } - } diff --git a/source/mircoders/servlet/ServletModuleUsers.java b/source/mircoders/servlet/ServletModuleUsers.java index 5c2d9f8c..3338360a 100755 --- a/source/mircoders/servlet/ServletModuleUsers.java +++ b/source/mircoders/servlet/ServletModuleUsers.java @@ -56,12 +56,7 @@ import mircoders.storage.DatabaseUsers; /** * - * <p>Title: </p> - * <p>Description: </p> - * <p>Copyright: Copyright (c) 2003</p> - * <p>Company: </p> - * @author not attributable - * @version 1.0 + * */ public class ServletModuleUsers extends ServletModule { @@ -255,7 +250,6 @@ public class ServletModuleUsers extends ServletModule int anOffset) throws ServletModuleExc { // ML: to be deleted, support for 3 extra vars to be added - HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); URLBuilder urlBuilder = new URLBuilder(); EntityAdapterModel model; diff --git a/templates/admin/head.template b/templates/admin/head.template index 5def6d82..54a269f2 100755 --- a/templates/admin/head.template +++ b/templates/admin/head.template @@ -20,9 +20,21 @@ </table> <hr> <if loggedinusers> - logged in: - <list loggedinusers as u> - ${u.name} (${u.count}) - </list> + <table cellpadding="3" cellspacing="0" width="100%"> + <tr > + <td class="bg-neutral small" align="left"> + <b>${lang("system.loggedin")} + <list loggedinusers as u> + ${u.name} (${u.count}) + </list> + </b> + </td> + <td class="bg-neutral small" align="right"> + <b>${lang("system.status")} + ${systemstatus} + </b> + </td> + </tr> + </table> <hr> </if>