Re: Using Jivan in a Barracuda App

David R Robison <[email protected]>
Newsgroups gmane.comp.java.enhydra.barracuda.general
Message-ID <[email protected]>
Thanks for the info...
The problem I'm now having is in modifying the loaded HTML file. Here is my code:

	class RenderSitePageHandler extends DefaultBaseEventListener {
		public void handleViewEvent(ViewEventContext context) throws EventException,
ServletException, IOException {
			HttpServletRequest req = context.getRequest();

			//get the XMLC object
			Document page =
DefaultDOMLoader.getGlobalInstance().getDOM("/WEB-INF/jivan/SitePage.html");
			DocumentFactory docFactory = DocumentFactory.getInstance();
			docFactory.docManFor(page).repair(page);

			//create a template component and render it
			Node node = page.getElementById("SiteForm");
			BTemplate templateComp = new BTemplate(new SiteModel(context));
			templateComp.setView(new DefaultTemplateView(node));
			try {templateComp.render(new DefaultViewContext(context));}
			catch (RenderException re) {logger.warn("Render err:"+re);}

			//now actually render the page 
			new DefaultDOMWriter().write(page, context.getResponse());
		}
	}

If I comment out the section where I create a template componet then the page
renders fine. If not, then, when I write out the DOM, I get an empty <td></td>
between each cell in my table and an empty <tr></tr> between each row. I'm not
adding new rows to the table, just populating a form that uses tables.

Any idea? Am I missing something?

Thanks in advance,
David

Quoting Jacob Kjome <[email protected]>:

> DefaultDOMWriter uses XMLC to format the DOM.  You can create your own
> 
> DOMWriter if you want.  This is actually why I wanted to rename 
> DefaultDOMWriter to XMLCDOMWriter.  Calling is "Default" hides its 
> implementation too much, and the whole point to switch out
> implementations 
> at will anyway, not use a single default one.  The DOMLoader is the more
> 
> generic of the 3 interfaces.  Anyway, knowing that, you can create your
> own 
> DOMWriter implementation that doesn't use XMLC's DOM formatter.  Oh, and
> I 
> forgot, there still is a dependency on XMLC via the 
> XMLCDeferredParsingDOMFactory instance created by default in the 
> DefaultDOMLoader.  Hmm....  Those should really be separated more. 
> Maybe 
> we should add another getGlobalInstance() that takes a DOMFactory as a
> 
> parameter and have the default dom factory loaded up via reflection. 
> That 
> way, DefaultDOMLoader would be much more generic.  Anyway...
> 
> 
> Here are some ways to use the JivanDOMFactory....
> 
> First do...
> DefaultDOMLoader loader = DefaultDOMLoader.getGlobalInstance();
> 
> Then, either use the object repository assember as shown by Thelmo below
> 
> (except change XMLCDeferredParsingDOMFactory to JivanDOMFactory) or use
> the 
> following...
> 
> 
> JivanDOMFactory jfactory = new JivanDOMFactory();
> jfactory.setServletContext(getServletContext());
> loader.setDefaultDOMFactory(jfactory);
> 
> //note that you can also choose to set the default dom factory to
> something 
> else and use Jivan for a specific fully qualified class name (String) or
> 
> file path such as....
> String docPath = "/WEB-INF/mydocs/myfile.html";
> loader.registerDOMFactory(jfactory, docPath);
> 
> 
> Then do....
> 
> Document doc = loader.getDOM(docPath);
> 
> 
> Of course, you can skip the DOMLoader as you did before, but at that
> point, 
> you might as well just load things as described here...
> http://www.jivan.org/parser/samples.html
> 
> You can also look at how JivanDOMFactory is implemented to for an
> example 
> of how to use it directly.
> 
> Hope that clears things up a bit.
> 
> Jake
> 
> At 01:18 PM 11/18/2003 -0500, you wrote:
> >Thanks, when I try this without the xmlc.jar file, it complains that
> the 
> >class
> >
> >org/enhydra/xml/io/DOMFormatter
> >
> >is not found. Is the xmlc.jar files still required?
> >
> >david
> >
> >Thelmo Loisio wrote:
> >>
> >>On Tue, 2003-11-18 at 17:19, David R Robison wrote:
> >>
> >>>
> >>>Do you have an example of what to set in the object-repository to use
> jivan?
> >>>David
> >>>
> >>
> >>
> >> >From the contrib package here it is snippet from
> >>object-repository.xml...
> >>
> >><object name="$df"
> >>class="org.enhydra.barracuda.core.util.dom.XMLCDeferredParsingDOMFactory">
> >>         <!-- set the servlet context so that the dom factory can
> read
> >>web.xml context params -->
> >>     <method name="setServletContext" arg="$sc"/>
> >>   </object>
> >>
> >>   <object
> class="org.enhydra.barracuda.core.util.dom.DefaultDOMLoader">
> >>     <method name="getGlobalInstance" return="$dl"/>
> >>   </object>
> >>
> >>... and from java within an handleViewEvent method...
> >>
> >>Document page =
> >>DefaultDOMLoader.getGlobalInstance().getDOM(WaitHTML.class,
> >>context.getViewCapabilities().getClientLocale());
> >>
> >>
> >>
> >
> >
> >--
> >
> >David R Robison
> >Open Roads Consulting, Inc.
> >708 S. Battlefield Blvd., Chesapeake, VA 23322
> >phone: (757) 546-3401
> >e-mail: 
> ><mailto:[email protected]>[email protected]
> >web: <http://openroadsconsulting.com>http://openroadsconsulting.com
> 
> _______________________________________________
> Barracuda mailing list
> [email protected]
> http://barracudamvc.org/lists/listinfo/barracuda
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.