2007-02-16

Thrillers

A Few Great Books

Next by Michael Crichton

Michael Crichton's "Next" is about a not-so-distant future when genetic engineering has encroached every aspect of our life. As usual, the author warns us about the uninhibited progress of science. I enjoyed this book much better than the "State of Fear". Like many of the novels by Crichton, the characters seem to be one-dimensional, almost soulless, but the events are very entertaining, and the science interspersed in the book is informative.

"Next" has a unique tinge of humor which I have not seen in other books by Crichton. In a certain part of the book, a company which has claimed ownership of a cell line derived from the cells of a patient's body, employs a bounty hunter to acquire another sample from the body of that patient or his progeny, claiming that the cells in their body also belongs to that company. It seems improbable that any jurisdiction may ever reach to such a ridiculous conclusion, but this is humorous anyway, and I think I can understand the logic behind it. Overall, this seems to be one of the best books by Michael Crichton. I recommend it to every reader interested in technothrillers.

The Lincoln Lawyer by Michael Connelly

Michael Connelly is my favorite author of crime and legal thrillers. I have read every book in the Harry Bosch series, and I have enjoyed all of them. "The Lincoln Lawyer" is a legal thriller, even better than many of his other books. This book features Mickey Haller, Harry's half-brother, who is a defense attorney. Haller used to think that the worst client for a defense attorney is an innocent client. But he encounters another kind of client who is much worse, a really evil man. The Lincoln Lawyer is the best book I have read for some time.

The Surgeon by Tess Gerritsen

Tess Gerritsen is another author who has used the theme of evil perps in her books. Her novels enjoy a robust balance of character development and page-turning plots. After reading The Surgeon and The Apprentice, I can't help but to start reading the third book in the Jane Rizzoli series, The Sinner. The problem is, I see a lot of true evilness in her books, but there is little sign of true righteousness. For one thing, Jane Rizzoli does a lot of attempt to prove herself, to get credit for the works she does. I do like real-looking characters, with a natural blend of strong and weak points. But I think there is some place for true virtue and good in her books. Rizzoli should have more valuable drives for her works than just "proving herself." Anyway, Gerritsen is a great author and has a great, useful blog which I usually read on a regular basis. And she has many other bestseller works which I plan to read in the near fututre. Maybe I'll change my mind after reading them.

چند كتاب خوب

بعدي اثر مايكل كرايتون

كتاب «بعدي» اثر مايكل كرايتون در باره‌ي آينده‌ي نه چندان دوري است كه در آن، مهندسي ژنتيك بر تمام جنبه‌هاي زندگي ما چنگ انداخته است. طبق معمول، مؤلف در اين كتاب در باره‌ي پيشرفت افسارگسيخته‌ي علم هشدار مي‌دهد. اين كتاب به نظر من بهتر از «وضعيت ترس» بود. البته، مانند خيلي از رمان‌هاي ديگر كرايتون، شخصيت‌ها يك‌بعدي و تقريباً بي‌روح به نظر مي‌رسند، ليكن رويدادها بسيار جذاب هستند، و نكات علمي پراكنده در لابلاي كتاب نيز آموزنده است.

كتاب «بعدي» با شوخ‌طبعي خاصي همراه است كه در كتاب‌هاي ديگر كرايتون به ندرت به چشم مي‌خورد. در يك جاي داستان، شركتي كه مالك يك رده‌ي سلولي به دست آمده از سلول‌هاي بدن يك بيمار شناخته شده است، افرادي را اجير مي‌كند كه مجدداً از بدن آن بيمار يا فرزندانش نمونه بگيرند، چون معتقد است سلول‌هاي موجود در بدن آنها نيز به آن شركت تعلق دارند. بعيد است كار دستگاه قضايي در آينده به دادن چنين حكم مضحكي بكشد، ولي به هر حال، اين قسمت داستان مفرح است و به گمانم مي‌توانم منطق نهفته در اين رويداد عجيب را درك كنم. روي هم رفته، به نظر مي‌رسد كه اين كتاب يكي از بهترين كتابهاي مايكل كرايتون است. من آن را به هر خواننده‌ي علاقه‌مند به داستان‌هاي علمي و فناوري توصيه مي‌كنم.

وكيل ليموزين‌سوار اثر مايكل كانلي

مايكل كانلي نويسنده‌ي مورد علاقه‌ي من در ژانر رمان‌هاي جنايي و حقوقي است. من تقريباً تمام كتاب‌هاي سري «هري بوش» را خوانده‌ام و برايم بسيار جذاب بودند. «وكيل ليموزين‌سوار» يكي از داستان‌هاي حقوقي او است كه حتي از كتاب‌هاي ديگرش هم بهتر است. در اين كتاب، با ميكي هالر، برادر ناتني هري بوش، كه يك وكيل مدافع است، ملاقات مي‌كنيم. هالر هميشه فكر مي‌كرد بدترين موكلي كه ممكن است به تورش بخورد، موكلي است كه واقعاً بي‌گناه باشد. ولي در اين كتاب با نوع بسيار بدتري از موكل رو به رو مي‌شود. فردي كه شرارت در نهاد او جاي گرفته است. «وكيل ليموزين‌سوار» بهترين كتابي است كه در اين اواخر خوانده‌ام.

جراح اثر تس گريتسن

تس گريتسن يكي ديگر از نويسندگاني است كه در كتاب‌هايش از بزهكاران شرور استفاده مي‌كند. رمان‌هاي او از تعادل خوبي بين شخصيت‌پردازي و وقايع پركشش برخوردار است. من اخيراً كتاب‌هاي «جراح» و «شاگرد» او را خواندم و بي‌صبرانه منتظر فرصتم تا خواندن سومين كتاب در سري «جين ريزولي» را، كه «گناهكار» نام دارد، آغاز كنم. مسئله اين است كه در كتاب‌هاي او شرارت واقعي زياد به چشم مي‌خورد، ولي كمتر اثري از خوبي مطلق يافت مي‌شود. مثلاً جين ريزولي هميشه در پي آن است كه موفقيت‌هاي كارآگاهي‌اش به نام كس ديگري ثبت نشود. البته من از كاراكترهاي واقعي كه تركيب متوازني از نقاط قوت و ضعف داشته باشند، بدم نمي‌آيد. ولي فكر مي‌كنم جاي خير مطلق در داستان‌هاي او تا حدودي خالي است. ريزولي بايد انگيزه‌هايي بالاتر از «اثبات كردن خود» براي كارهايش داشته باشد. در هر حال، گريتسن نويسنده‌ي بزرگي است و وبلاگ ارزشمندي نيز دارد كه من معمولاً به طور مرتب مطالب آن را مطالعه مي‌كنم. او كتاب‌هاي پرفروش متعدد ديگري نيز دارد كه تصميم دارم در آينده‌ي نزديك بخوانم. شايد آن موقع نظرم در باره‌ي آثار او عوض شود.

2006-04-09

Reflections about Books and Publishing Industry in Iran

My first acquaintance with books dates back to ca. 1973, when I was a 3-year-old child. My elder sister used to read or recount some books for us, and one of those books has remained very vividly in my memory: "The Story of Doctor Doolittle" by Hugh Lofting. At those days in the small town of Boshruyeh, my sister used to borrow books from the General Library. Now that I think about what I recall of those days, it is quite clear for me that book reading was more widespread in our community in those days.

I continued to enjoy books, especially fiction books, into school years. But the crucial point was in 1980 when I was introduced--this time personally--to the General Library of Boshruyeh. Since that memorable day when a cousin of mine told me about the library until today, I have not spent a single day without reading books.

I was especially interested in novels, and they were mostly classic works, like Oliver Twist by Charles Dickens and The Black Arrow by Robert Louis Stevenson. A large number of these books were published by an institute called the Center for Translation and Publication of Books, which changed its name after the 1979 revolution. What is noteworthy about those books is that they were "authorized" translations, in contrast to most foreign books which are translated and published in these days, since these latter books are generally published without observing the international Copyright law.

Even when I was a little schoolboy, I dreamed of creating books. Some times, I used Handicopy papers to create a few copies of a tale I had invented and illustrated myself (though I never was much of a painter), and thought of handing out those copies as books to my classmates!

Now, I have eventually found the opportunity to translate and publish a few books. And there is the all-important issue of Copyright in Iran.

Unfortunately, the international Copyright law is not enforced in Iran. Maybe one of the most profitable parts of the book industry in Iran is the offset-printing and distribution of foreign books. This doesn't even entail a little creative work and it should surely be forbidden by the government.

As a translator, I would like that my books be published after the authorization of the Author and the original Publisher. But the situation in Iran is so that this does not seem to be practical. For one thing, a novel book may not sell more that 2,000 copies (say, $4 a copy), and this hardly exceeds the expenses the publisher has sustained for publishing it. But it may be better to negotiate for a symbolic agreement at the very least. Anyway, I am not a publisher.

It should be noted that while honorable creators and publishers may not be able to pay for royalties to acquire the authorization for publication of a foreign book in Iran, there are some people who have misused the current situation to earn very large amounts of money without doing the slightest creative work, by just publishing the original book without paying the royalties.

I understand that the prices of foreign books are generally so high that an average student in Iran can not usually pay for them. But the government has always allocated some money for buying foreign books for students, and that seems the proper way, because it does not infringe the international laws.

I hope the copyright law is established in Iran very soon, so that the rights of foreign authors and publishers are not wasted in this country.

2006-01-19

The Broker by John Grisham

The Persian translation of "The Broker" by John Grisham was published.

brokercoversmall.jpg

ترجمه‌ي «سوداگر» آخرين اثر جان گريشام منتشر شد.

1. خلاصه

جوئل بكمن، تا قبل از آنكه به خاطر خيانت (و اتهامات ديگر) به زندان فدرال فرستاده شود، مرد بسيار قدرتمندي بود. او كه به «سوداگر» شهرت يافته بود، ساليانه 10 ميليون دلار درآمد داشت و «مي‌توانست هر دري را در واشنگتن بگشايد». البته تا آنكه تلاش كرد معامله‌اي جور كند و دسترسي به قوي‌ترين سيستم ماهواره‌اي جهان را به بالاترين قيمت واگذار كند. وقتي بكمن را گرفتند، زندان را به عنوان تنها گزينه‌اي كه مي‌توانست او را زنده و سالم نگه دارد، پذيرفت، چون طرف‌هاي درگير (اسرائيلي‌ها، سعودي‌ها، روس‌ها، و چيني‌ها) همگي در صدد بودند به هر قيمتي به راز او دست يابند. غافل از آنكه دولت كشور خودش هم برنامه‌هايي براي دست يافتن به آن اطلاعات-يا لااقل دفن كردن آن اطلاعات با خود او-دارد. اينك، شش سال پس از زنداني شدن بكمن، رئيس سيا رئيس‌جمهور درمانده را متقاعد مي‌كند كه بكمن را عفو كند و سوداگر يك مرد آزاد مي‌شود-و يا در واقع يك هدف آزاد.

سوداگر بهترين قابليت‌هاي جان گريشام را در يك جا جمع كرده است-توانايي غرق شدن در فرهنگ يك شهر كوچك (در اين مورد، بولونياي ايتاليا)، و مهارت انكارناپذير در تعقيب و گريز. نيمه‌ي اول كتاب به شرح مبدل شدن بكمن از سوداگري بدنام به يك قرباني درمانده در بازي خودش اختصاص دارد. بكمن را پس از آزاد شدن، تحت‌الحفظ به ايتاليا مي‌برند و هويتي جديد به او مي‌دهند تا با محيط ممزوج شود. در آنجا، خوانندگان در سفري سينماوار به اطراف ايتاليا با او همراه مي‌شوند، كه با فراگيري زبان ايتاليايي و نكاتي در باره‌ي تاريخ ايتاليا نيز تكميل مي‌شود. نيمه‌ي دوم كتاب، به سبك و سياق كلاسيك گريشام، تعقيب و گريزي از نوع موش و گربه است كه در آن بكمن سعي مي‌كند از دست سازمان‌هاي متعدد جاسوسي كه در پي او هستند، جان سالم به در ببرد و زندگي خود را از سر گيرد. (نقد دافنه دورهام، برگرفته از آمازون)

2. مشخصات كتاب

  • عنوان: سوداگر
  • عنوان اصلي: The Broker
  • مؤلف: جان گريشام
  • مترجم: دكتر قاسم كياني مقدم
  • ناشر: اميد مهر
  • نوبت چاپ: اول، 1384
  • شمارگان: 3000 جلد
  • قيمت: 37000 ريال
  • شابك: 9648605386
  • نشاني انتشارات اميد مهر: سبزوار، پاساژ ارم، طبقه‌ي همكف
  • صندوق پستي: 453
  • تلفن و دورنگار: 2234595
  • تلفن همراه: 09151710360

3. نحوه‌ي تهيه

گزيده‌اي از كتاب را مي‌توانيد به رايگان از نشاني زير دريافت كنيد:

http://groups.yahoo.com/group/persian-library/files/brokerexcerpt.pdf

براي اطلاعات بيشتر مي‌توانيد به وبلاگ مترجم در نشاني زير مراجعه كنيد:

http://ghasemkiani.blogspot.com

براي تهيه‌ي كتاب با انتشارات اميد مهر (تلفن همراه 09151710360) تماس بگيريد و يا به مراكز پخش مراجعه فرماييد.

در ضمن، هر گونه نظر و پيشنهاد خود را مي‌توانيد براي مترجم با پست الكترونيك به نشاني ghasemkiani@gmail.com بفرستيد.

2005-07-19

Harry Potter and the Half-Blood Prince

Today, I finished reading "Harry Potter and the Half-Blood Prince" by J.K. Rowling. It turns out that the "Half-Blood Prince" was the same person I had read in a forum some time ago (with particularly accurate inferences), but my most favourite character in this series died -- or, rather, became a victim of his generous tolerance and confidence in people that don't deserve that much of optimism and confidence from him. What a pity!

2005-07-15

London Bridges by James Patterson

There is a certain similarity between the unfortunate bombings in London and the fiction in "London Bridges" by James Patterson. This is an opportunity for me to write a few lines about this book.

What bothers me about James Patterson is that his books are just for entertainment, they don't give you more insight about life or anything else whatsoever. And in this book, the writer's view about terrorism and its roots are not very clear and convincing.

Recently, I read "The Forgotten Man" by Robert Crais, and I think I have finally found a writer who is to some extent like Raymond Chandler, whom I adore.

در ضمن، در حالي كه منتظر انتشار ششمين كتاب هري پاتر هستم، وبلاگ جديدي با عنوان «هري پاتر به زبان فارسي» درست كرده‌ام تا در باره‌ي ترجمه‌ي آن مطالبي بنويسم. علاقه‌مندان مي‌توانند به آنجا هم مراجعه كنند.

2005-06-27

Cyclothymia

Sometimes I get the impression that I have some minor form of cyclothymia (just the impression, I don't believe I do!). And now, it is one of those periods that I have a somewhat depressed mood. Usually when I do not have so much energy to entertain myself with the usual tasks of my life, I think about myself, life, loneliness, and so on.

One of the main subjects that I think about is the ends I am seeking in my life. I know some people who have very clear ends: money, fame, and anything else that pertains to them. The problem with me is that I do not feel satisfied with money, celebrity, or being respected.

Sometimes, I ask myself, "If I do not like to be respected by other people, do I like to be humiliated by them?" Surely, this is not what I am seeking. I mean I do not like to be humiliated, but on the other hand, other people's respect (or fear) towards me does not satisfy me. It's not an important end for me. When I think too much, it becomes clear that what I do really want is my love towards other people and their love towards me. But, doesn't this way of thinking have a flaw? Maybe it does. There are people whom I cannot love easily - people who are jealous, people who are intruding, people who do not have the capacity to love other people. This is the main challenge of my life: how to love other people and how to consider all of them worthy of loving.

2005-04-11

My New Book

This post is in Persian. Please stay tuned for future posts in English.

In the name of God

طعمه اثر مايكل كرايتون، ترجمه‌ي قاسم كياني مقدم

طعمه نوشته‌ي مايكل كرايتون

در بيابان نوادا، يك آزمايش تحقيقاتي به گرفتاري بزرگي منجر شده است. ابري از نانوذره‌ها - ريزروبوت‌ها - از آزمايشگاه گريخته است. اين ابر خودمختار است و قدرت توليد مثل دارد. هوشمند است و به تجربه ياد مي‌گيرد. عملاً يك موجود زنده است.
اين موجود به عنوان شكارچي برنامه‌نويسي شده است. به سرعت تكامل مي‌يابد، و با گذشت هر ساعت، مرگبارتر مي‌شود.
هر تلاشي براي نابودي آن با شكست مواجه شده است.
و ما طعمه‌ي اين شكارچي هستيم.


رمان «طعمه» نوشته‌ي مايكل كرايتون به فارسي ترجمه و منتشر شد.

مشخصات كتاب

نام

طعمه

نويسنده

مايكل كرايتون

مترجم

قاسم كياني مقدم

ناشر

انتشارات اميد مهر

تعداد صفحات

432

شابك

964-8605-19-X

اين كتاب از طريق كتابفروشي‌هاي تهران جهت علاقه‌مندان عرضه مي‌شود. براي كسب اطلاعات بيشتر، با نشاني‌هاي زير تماس بگيريد:

پست الكترونيك

ghasemkiani@gmail.com

تلفن (7 تا 9 عصر)

05712238144

توضيح

براي بحث در باره‌ي اين كتاب، مي‌توانيد در گروه زير عضو شويد:

http://groups.yahoo.com/group/persian-library

در ضمن، خواهشمندم هر گونه نظرات خود را با اينجانب از طريق نشاني پست الكترونيك فوق در ميان گذاريد.

2005-04-08

My Email Address

I have lost my account at Yahoo after about 5 years! Now I use the same ID at Gmail. Of course I liked Gmail from the beginning, but because of some stuff in Yahoo groups, I continued to use Yahoo for some time.

2005-03-07

Iran Books House

This is one of the few really useful Iranian sites. I really enjoy using it. You can search data of all published books in iran in this site.

ICU4J-based Implementation of the Persian Calendar

IBM's International Components for Unicode (Java version) or ICU4J enhances the I18n capabilities of Java in many ways. Since it is based on the Common Locale Data Repository (CLDR), it is especially useful for Persian-language applications (noting that the support for Persian is rudimentary in Java's native locales). But there is another important reason for using ICU4J for implementing a Persian calendar: The newer releases of ICU4J have reworked the calendar framework, so that, contrary to the Calendar class in the java.util package, much of the functionality has been embedded in the base class. For example, no longer should we worry about DST or weekdays. They are already worked out. The only thing one should implement is the peculiarities of the specific kind of calendar at hand -- here the Persian calendar.

The version 2.0 of my prersiancalendar Java program contains an implementation of the Persian calendar based on ICU4J, version 3.2. It formats and parses dates for many locales besides Persian.

A new update will be released in the near future, containing a bug fix for the SimplePersianCalendar class (which is, in fact, a deprecated class now) and some more locales for the ICU4J-based PersianCalendar class.

One important note is indispensable here: I have used an arithmetic algorithm for calculation of the leap years, which was apparently devised by the late Ahmad Birashk. Although this algorithm is valid for many hundreds of years, the formal definition of the Persian calendar is astronomical. To implement the calendar astronomically, we must be able to calculate the accurate time of the vernal equinox (the time when the solar longitude is 0). The current version of the class com.ibm.icu.impl.CalendarAstronomer is not very accurate, since it only considers the Keplerian gravitational effect of Sun and Earth and ignores the disturbances caused by other celestial bodies (of course there may be other things as well, but I am not particularly knowledgeable in astronomy). I used this class to calculate the time of the spring equinox in the next Persian year (1384) and it had a discrepancy with the magnitude order of many minutes with what has been announced by the Geophysics Institute of the Tehran University. Currently I am working on this.

I would like to thank Mr. Paul Hastings from Sustainable GIS Co. for his valuable suggestions and contributions. He has added the new Persian calendar to their calendar test bed. He has also promised to provide me with a Thai localization of the Persian month names, which will be a great enhancement to this program.

2005-02-12

Using Gmail's SMTP and POP3 Services

If you have a Gmail account, you can activate POP3 access to your mailbox. Then you can configure Outlook 2003 to access and retrieve your incoming mails. Information for configuring other mail clients is provided here.

2005-02-10

Using SVG in Servlets and JavaServer Pages

The Scalable Vector Graphics (SVG) is a language used for creating vector (as opposed to raster) graphics, including shapes, images, and text. Since this format is based on the extensible markup language (XML), it can be extremely useful in web page authoring.

But the problem is that most of the current browsers do not have built-in support for SVG. Currently, this support is added through plug-ins, e.g. the Adobe SVG viewer. I don't know what percentage of internet users have installed an SVG plug-in. So it seems that if we are going to use SVG in our web pages in a practical way, we must rasterize the image before sending the page to the client (though this makes it an ordinary image, not a vector graphic!).

This can be easily done in JSP pages using the library of the Apache Batik project. I have done this and I present the code below. (Please note that the code for this post is released under the GNU General Public License and that there is no warranty as to its correctness or usability.)

Conversion of the SVG source into an image in PNG format may make problems in a case of simultaneous access. So, a noCache attribute has been devised for the <h:svg> tag, so that we can turn on/off the conversion. The best way would be to use noCache="true" while the page is under development, and then turn off conversion with noCache="false" when our images have taken their permanent form.

The full source of my simple application (svgtest) is shown below. But please keep in mind that you need the following libraries to get this application running:

  1. Batik jar file(s) (may be a single or multiple jar files depending on your build target). I have used batik 1.5.
  2. JSTL (jstl.jar, standard.jar)
  3. Xerces XML parser (xerces_2_3_0.jar). This is included with the batik distribution linked above.

Needless to say, the jar files go to the TOMCAT/webapps/svgtest/WEB-INF/lib directory.

Figure 1. The graphics on this page have been created using SVG. Particularly, the three hiragana and kanji characters comprising the Japanese phrase for "Good day!" (今日は) (konnichi wa in rōmaji) have been rendered graphically to ensure their proper appearance even on machines lacking suitable unicode fonts.

The source code for this simple application follows.

 

TOMCAT/webapps/svgtest/index.jspx

<?xml version="1.0" encoding="windows-1256" ?>

<!-- Copyright © 2005, Ghasem Kiani. License: GPL. -->

<jsp:root version="2.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:h="urn:jsptagdir:/WEB-INF/tags/html" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:page="urn:jsptagdir:/WEB-INF/tags/page" xmlns:xlink="http://www.w3.org/1999/xlink">

<jsp:directive.page contentType="text/html" />

<c:set scope="page" value="${true}" var="debug" />

<c:set property="characterEncoding" target="${pageContext.request}" value="UTF-8" />

<c:set property="characterEncoding" target="${pageContext.response}" value="UTF-8" />

<page:simple title="SVG Test">

<div style="direction: rtl; background-color: white;">

<c:set scope="page" value="تصوير" var="text1" />

<p>

<h:img noCacheSvg="${debug}" src="/title.png">

<jsp:attribute name="svg">

<svg height="25mm" width="100mm" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

<defs>

<filter filterUnits="objectBoundingBox" height="1.4" id="dropShadow" width="1.4">

<feGaussianBlur in="SourceAlpha" stdDeviation="4" />

<feOffset dx="4" dy="4" />

<feComponentTransfer result="shadow">

<feFuncA intercept="0" slope="0.5" type="linear" />

</feComponentTransfer>

</filter>

<filter id="emboss">

<feGaussianBlur in="SourceAlpha" result="blur" stdDeviation="2" />

<feSpecularLighting in="blur" kernelUnitLength="1" result="spec" specularConstant="1" specularExponent="16" style="lighting-color:white" surfaceScale="-3">

<feDistantLight azimuth="45" elevation="45" />

</feSpecularLighting>

<feComposite in="spec" in2="SourceGraphic" operator="in" result="specOut" />

</filter>

</defs>

<g style="font-size: 20mm; font-family: b nasim; font-weight: bold; text-anchor: end;">

<text style="filter:url(#dropShadow)" x="95%" y="66.667%">

${text1}

</text>

<text style="fill:rgb(172,20,20)" x="95%" y="66.667%">

${text1}

</text>

<text style="filter:url(#emboss)" x="95%" y="66.667%">

${text1}

</text>

</g>

</svg>

</jsp:attribute>

</h:img>

</p>

<h:roundrect fill="lightblue" id="mytest1" noCache="true" r="25" stroke="orange" strokeWidth="3">

<div style="direction: rtl; margin: 1mm;">

<p>

<strong>

كلماتي كه ممكن است در مرورگر شما درست نمايش داده نشوند، به صورت تصوير نشان داده مي‌شوند. مانند

<h:img noCacheSvg="${debug}" src="/konnichiwa.png">

<jsp:attribute name="svg">

<svg height="1em" width="3em" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

<rect fill="lightblue" height="100%" stroke-width="0" width="100%" x="0" y="0" />

<text x="0" y="90%">

&amp;#20170;&amp;#26085;&amp;#12399;

</text>

</svg>

</jsp:attribute>

</h:img>

كه معنايش مي‌شود روز به خير!

</strong>

</p>

</div>

</h:roundrect>

</div>

</page:simple>

</jsp:root>

 

TOMCAT/webapps/svgtest/WEB-INF/tags/html/svg.tagx

<?xml version="1.0" encoding="windows-1256" ?>

<!-- Copyright © 2005, Ghasem Kiani. License: GPL. -->

<jsp:root version="2.0" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:jsp="http://java.sun.com/JSP/Page">

<jsp:directive.tag body-content="scriptless" />

<jsp:directive.attribute name="image" required="true" />

<jsp:directive.attribute name="noCache" type="java.lang.Boolean" />

<c:set scope="page" var="svg">

<jsp:doBody />

</c:set>

<jsp:declaration>

<![CDATA[

class PngMaker extends org.apache.batik.transcoder.image.PNGTranscoder

{

public boolean convert(String svgUri, String png)

{

java.io.OutputStream os;

org.apache.batik.bridge.DocumentLoader dl = new org.apache.batik.bridge.DocumentLoader(userAgent);

try

{

org.w3c.dom.svg.SVGDocument doc = (org.w3c.dom.svg.SVGDocument)dl.loadDocument(svgUri);

os = new java.io.BufferedOutputStream(new java.io.FileOutputStream(png));

transcode(doc, null, new org.apache.batik.transcoder.TranscoderOutput(os));

os.flush();

os.close();

return true;

}

catch(Exception e)

{

System.out.println(e.getMessage());

return false;

}

}

}

]]>

</jsp:declaration>

<jsp:scriptlet>

<![CDATA[

String png = application.getRealPath(String.valueOf(getJspContext().getAttribute("image")));

boolean noCache = new Boolean(String.valueOf(getJspContext().getAttribute("noCache"))).booleanValue();

if(noCache || ! new java.io.File(png).exists())

{

java.io.File dir = new java.io.File(application.getRealPath("/WEB-INF/temp"));

if(!dir.exists()) dir.mkdir();

java.io.File f = java.io.File.createTempFile("src", ".svg", dir);

f.deleteOnExit();

java.io.BufferedWriter bw = new java.io.BufferedWriter(new java.io.OutputStreamWriter(new java.io.FileOutputStream(f), "UTF-8"));

bw.write("<?xml version='1.0' encoding='UTF-8' ?>");

bw.write(String.valueOf(getJspContext().getAttribute("svg")));

bw.close();

new PngMaker().convert(f.toURI().toString(), png);

}

]]>

</jsp:scriptlet>

</jsp:root>

 

TOMCAT/webapps/svgtest/WEB-INF/tags/html/img.tagx

<?xml version="1.0" encoding="windows-1256" ?>

<!-- Copyright © 2005, Ghasem Kiani. License: GPL. -->

<jsp:root version="2.0" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:h="urn:jsptagdir:/WEB-INF/tags/html" xmlns:jsp="http://java.sun.com/JSP/Page">

<jsp:directive.tag body-content="scriptless" dynamic-attributes="dyn" />

<jsp:directive.attribute name="src" />

<jsp:directive.attribute name="svg" />

<jsp:directive.attribute name="noCacheSvg" type="java.lang.Boolean" />

<jsp:directive.attribute name="params" type="java.util.Map" />

<jsp:directive.attribute name="alt" />

<jsp:directive.attribute name="title" />

<jsp:directive.attribute name="style" />

<jsp:directive.attribute name="styleId" />

<jsp:directive.attribute name="styleClass" />

<c:url scope="page" value="${src}" var="url" />

<c:if test="${not empty svg}">

<h:svg image="${src}" noCache="${noCacheSvg}">

${svg}

</h:svg>

</c:if>

<img alt="${alt}" class="${styleClass}" id="${styleId}" src="${url}" style="${style}" title="${title}">

<jsp:doBody />

</img>

</jsp:root>

 

TOMCAT/webapps/svgtest/WEB-INF/tags/html/roundrect.tagx

<?xml version="1.0" encoding="windows-1256" ?>

<!-- Copyright © 2005, Ghasem Kiani. License: GPL. -->

<jsp:root version="2.0" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:h="urn:jsptagdir:/WEB-INF/tags/html" xmlns:jsp="http://java.sun.com/JSP/Page">

<jsp:directive.tag body-content="scriptless" />

<jsp:directive.attribute name="id" required="true" />

<jsp:directive.attribute name="fill" />

<jsp:directive.attribute name="stroke" />

<jsp:directive.attribute name="strokeWidth" />

<jsp:directive.attribute name="r" />

<jsp:directive.attribute name="width" />

<jsp:directive.attribute name="height" />

<jsp:directive.attribute name="body" />

<jsp:directive.attribute name="noCache" />

<c:if test="${empty fill}">

<c:set scope="page" value="none" var="fill" />

</c:if>

<c:if test="${empty stroke}">

<c:set scope="page" value="black" var="stroke" />

</c:if>

<c:if test="${empty strokeWidth}">

<c:set scope="page" value="1" var="strokeWidth" />

</c:if>

<c:if test="${empty r}">

<c:set scope="page" value="5" var="r" />

</c:if>

<c:if test="${empty width}">

<c:set scope="page" value="auto" var="width" />

</c:if>

<c:if test="${empty height}">

<c:set scope="page" value="auto" var="height" />

</c:if>

<c:if test="${empty body}">

<c:set scope="page" var="body">

<jsp:doBody />

</c:set>

</c:if>

<table cellpadding="0" cellspacing="0" style="direction: ltr; width: ${width}; height: ${height};">

<tr>

<h:svg image="/${id}nw.png" noCache="${noCache}">

<svg height="${r}" width="${r}" xmlns="http://www.w3.org/2000/svg">

<circle cx="100%" cy="100%" fill="${fill}" r="${r/2}" stroke="${stroke}" stroke-width="${strokeWidth}" />

</svg>

</h:svg>

<c:url value="/${id}nw.png" var="bg" />

<td style="width: ${r};">

<h:img src="/${id}nw.png" style="margin: 0; padding: 0; width: ${r}; height: ${r};" />

</td>

<h:svg image="/${id}n.png" noCache="${noCache}">

<svg height="${r}" width="${r}" xmlns="http://www.w3.org/2000/svg">

<rect fill="${fill}" height="50%" stroke="${stroke}" stroke-width="${0}" width="100%" x="0" y="50%" />

<line stroke="${stroke}" stroke-width="${strokeWidth}" x1="0" x2="100%" y1="50%" y2="50%" />

</svg>

</h:svg>

<c:url value="/${id}n.png" var="bg" />

<td style="background: url(${bg});">

&amp;nbsp;

</td>

<h:svg image="/${id}ne.png" noCache="${noCache}">

<svg height="${r}" width="${r}" xmlns="http://www.w3.org/2000/svg">

<circle cx="0" cy="100%" fill="${fill}" r="${r/2}" stroke="${stroke}" stroke-width="${strokeWidth}" />

</svg>

</h:svg>

<c:url value="/${id}ne.png" var="bg" />

<td style="width: ${r};">

<h:img src="/${id}ne.png" style="margin: 0; padding: 0; width: ${r}; height: ${r};" />

</td>

</tr>

<tr>

<h:svg image="/${id}w.png" noCache="${noCache}">

<svg height="${r}" width="${r}" xmlns="http://www.w3.org/2000/svg">

<rect fill="${fill}" height="100%" stroke="${stroke}" stroke-width="${0}" width="50%" x="50%" y="0" />

<line stroke="${stroke}" stroke-width="${strokeWidth}" x1="50%" x2="50%" y1="0" y2="100%" />

</svg>

</h:svg>

<c:url value="/${id}w.png" var="bg" />

<td style="background: url(${bg});">

&amp;nbsp;

</td>

<h:svg image="/${id}c.png" noCache="${noCache}">

<svg height="${r}" width="${r}" xmlns="http://www.w3.org/2000/svg">

<rect fill="${fill}" height="100%" stroke="${stroke}" stroke-width="${0}" width="100%" x="0" y="0" />

</svg>

</h:svg>

<c:url value="/${id}c.png" var="bg" />

<td style="background: url(${bg}); vertical-align: top;">

<jsp:text>

${body}

</jsp:text>

</td>

<h:svg image="/${id}e.png" noCache="${noCache}">

<svg height="${r}" width="${r}" xmlns="http://www.w3.org/2000/svg">

<rect fill="${fill}" height="100%" stroke="${stroke}" stroke-width="${0}" width="50%" x="0" y="0" />

<line stroke="${stroke}" stroke-width="${strokeWidth}" x1="50%" x2="50%" y1="0" y2="100%" />

</svg>

</h:svg>

<c:url value="/${id}e.png" var="bg" />

<td style="background: url(${bg});">

&amp;nbsp;

</td>

</tr>

<tr style="height: ${r};">

<h:svg image="/${id}sw.png" noCache="${noCache}">

<svg height="${r}" width="${r}" xmlns="http://www.w3.org/2000/svg">

<circle cx="100%" cy="0" fill="${fill}" r="${r/2}" stroke="${stroke}" stroke-width="${strokeWidth}" />

</svg>

</h:svg>

<c:url value="/${id}sw.png" var="bg" />

<td style="width: ${r};">

<h:img src="/${id}sw.png" style="margin: 0; padding: 0; width: ${r}; height: ${r};" />

</td>

<h:svg image="/${id}s.png" noCache="${noCache}">

<svg height="${r}" width="${r}" xmlns="http://www.w3.org/2000/svg">

<rect fill="${fill}" height="50%" stroke="${stroke}" stroke-width="${0}" width="100%" x="0" y="0" />

<line stroke="${stroke}" stroke-width="${strokeWidth}" x1="0" x2="100%" y1="50%" y2="50%" />

</svg>

</h:svg>

<c:url value="/${id}s.png" var="bg" />

<td style="background: url(${bg});">

&amp;nbsp;

</td>

<h:svg image="/${id}se.png" noCache="${noCache}">

<svg height="${r}" width="${r}" xmlns="http://www.w3.org/2000/svg">

<circle cx="0" cy="0" fill="${fill}" r="${r/2}" stroke="${stroke}" stroke-width="${strokeWidth}" />

</svg>

</h:svg>

<c:url value="/${id}se.png" var="bg" />

<td style="width: ${r};">

<h:img src="/${id}se.png" style="margin: 0; padding: 0; width: ${r}; height: ${r};" />

</td>

</tr>

</table>

</jsp:root>

 

TOMCAT/webapps/svgtest/WEB-INF/tags/page/simple.tagx

<?xml version="1.0" encoding="windows-1256" ?>

<!-- Copyright © 2005, Ghasem Kiani. License: GPL. -->

<jsp:root version="2.0" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:jsp="http://java.sun.com/JSP/Page">

<jsp:directive.attribute name="title" />

<jsp:directive.attribute name="head" />

<html>

<head>

<meta content="text/html; charset=${pageContext.response.characterEncoding}" http-equiv="Content-Type" />

<meta content="no-cache" http-equiv="pragma" />

<c:if test="${not empty title}">

<title>

<c:out value="${title}" />

</title>

</c:if>

<jsp:text>

${head}

</jsp:text>

</head>

<body>

<jsp:doBody />

</body>

</html>

</jsp:root>

 

TOMCAT/webapps/svgtest/WEB-INF/web.xml

<?xml version="1.0" encoding="windows-1256"?>

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd">

<description>

SVG Test Web Application By Ghasem Kiani. This application uses the Apache Batik project to convert SVG graphics into PNG images.

</description>

<display-name>

SVG Test

</display-name>

<welcome-file-list>

<welcome-file>

index.jspx

</welcome-file>

<welcome-file>

index.html

</welcome-file>

</welcome-file-list>

</web-app>

P.S.

The better way to do this is to write a servlet that outputs the image stream to the client. This will not envolve the writing of the image on disk. Even we can map files with .svg extension to that servlet, so that whenever we reference an SVG file on our application in the src attribute of an <img> tag, the servelt will be activated and the rasterized image will be sent instead. On the other hand, the JSP architecture seems to be inconvenient for outputting binary formats.