Stefano Bianchi wrote:

Dear Vladimir,
I'm not a programming expert, but I thought that wrapping some plain HTML in
JspPortlet would allow you to put code also in the HTML files (after all,
the rendering on the portal is of a jsp, not of an html!) included. This
sounds a bit strange to me, but it could be.
Did you use the <include> tag? I used it but I had file system based files
and not from DB.


I don`t use <include> tag,
I insert HTML-Pages in jsp-pages next method:

...

 <%if (doc != null) {%>

 <h2><%=doc.getTitle()%></h2/>

 <%=doc.getContent()%>

 <%}%>

...


Where "doc" is a class-wrapper for sample of various HTML-files of a database.

For resolve problem with <a href="#anchorName"... I, before insert HTML-content,
parse this HTML (HTML->DOMDoc->XMLDoc) for find (use XPath) this tag
and transform then his to correct absolute URL.

-use CyberNeko HTML2DOM parsers lib - 
http://www.apache.org/~andyc/neko/nekohtml-latest.zip
-& DOM4J XML lib - http://sourceforge.net/projects/dom4j/
I made next:


String result = null;

   // Get full URL current Portals Page

   StringBuffer currURL = request.getRequestURL();

   currURL.append(";jsessionid=").append(request.getRequestedSessionId());

   currURL.append("?").append(request.getQueryString());

   // Convert HTML Document to DOM Document (for fast find by XPath)

   org.cyberneko.html.parsers.DOMParser parser = new 
org.cyberneko.html.parsers.DOMParser();

   try {

     parser.parse(new InputSource(new StringReader(htmlSource)));

     org.w3c.dom.Document docDOM = parser.getDocument();

     // Convert DOM 2 XML Document

     org.dom4j.io.DOMReader readerDOM = new org.dom4j.io.DOMReader();

     org.dom4j.Document docXML = readerDOM.read(docDOM);

     // Find by XPath all <a href="#...">

     List listNode_A_HREFs = docXML.selectNodes("//A[starts-with(@href,'#')]");

     for (Iterator it = listNode_A_HREFs.iterator(); it.hasNext();) {

       // Convert LOCAL refs to ABSOLUTE refs

       org.dom4j.Element node_A_HREFs = (org.dom4j.Element)it.next();

       String hrefValue = node_A_HREFs.attributeValue("href");

       hrefValue = currURL+hrefValue;

       node_A_HREFs.addAttribute("href",hrefValue);

     }

     // Out to HTML

     StringWriter sw = new StringWriter();

     org.dom4j.io.OutputFormat format = org.dom4j.io.OutputFormat.createPrettyPrint();

     //These are the default formats from createPrettyPrint, so you needn't set them:

     //  format.setNewlines(true);

     //  format.setTrimText(true);

     format.setNewlines(setNewlines);

     format.setTrimText(setTrimText);

     format.setIndent(setIndent);

     format.setXHTML(setXHTML);

     format.setExpandEmptyElements(setExpandEmptyElements);

     format.setNewLineAfterNTags(setNewLineAfterNTags); //print a line every so often.

     org.dom4j.io.HTMLWriter writer = new org.dom4j.io.HTMLWriter(sw, format);

     writer.write(docXML);

     writer.flush();

     result = sw.toString();



Couldn't you change the file format of include files from html to jsp?
Good luck
Stefano


----- Original Message ----- From: "Vladimir Figurov" <[EMAIL PROTECTED]>
To: "Jetspeed Users List" <[EMAIL PROTECTED]>
Sent: Tuesday, July 13, 2004 7:21 AM
Subject: Re: HTML page with <a href="#anchor1"....





To Stefano:
Yes, it's working on JSP, but my JSP-portlet - is wrapper for varios
HTML-pages outing from data base & in this HTML-pages (clean HTML, not
JSP)  placed jsp-code don't work - HTML-pages out to stream server
response & and not compiling ;-(


Stefano Bianchi wrote:



I solved this by paasing to JspPortlet and using this code

<%@ taglib uri='/WEB-INF/templates/jsp/tld/template.tld'


prefix='jetspeed'


%>
...
<%
String s = request.getRequestURI();
String ss = s.substring(s.lastIndexOf("portal")+6);
%>
...
<a href="<jetspeed:contentUri


href='portal'/><%=ss%>;jsessionid=<%=request.getRequestedSessionId()%>#a001


"




What is this?</a></li>




...
<a name="a001"> </a>
...

Not so clean but it worked it out!
Good luck
Stefano


----- Original Message ----- From: "Vladimir Figurov" <[EMAIL PROTECTED]>
To: "Jetspeed Users List" <[EMAIL PROTECTED]>
Sent: Monday, July 12, 2004 5:28 AM
Subject: HTML page with <a href="#anchor1"....







Hi
I have a trubles with working HTML pages. If HTML page has code:
....
<a href="#anchor1">Goto step ONE</a>
....
<a name="anchor1">Step ONE:</a>
....
at output this page on portal has wrong ref. on "Step ONE" - #anchor1
write at once after Base URI Portal, without the current page (portlet)
and its parameters.
Example:
"http://localhost/jetspeed/#anchor1";
-------------------
Certainly, this is a wrong refs...
Please, help! need optimal choise (this page is taken from data base):
1) I must use org.apache.jetspeed.util.HTMLRewriter class and after out


from base and before render page portlets, TRANSFORMed <a href=... ????


2) or have is another, better resolv...???

Bob Figurov




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to