Holger Prause

Ranch Hand
+ Follow
since Oct 09, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Holger Prause

Hello,

I dont know exactly when to use the protected modifier.
I read several posting on several pages and as far as i can see, there are 2 main opinions

1)
protected should only be used when a subtype
needs to access parts of its supertype for
efficiency reasons
By default, a subtype should access its supertype
only through the public interface

2)
when you expect that you will have subclasses in different packages to be able to access things that most classes in your system shouldn't.
I can understand this 2 points.
In point 1 data hiding is the reason for that
In point 2 inherance is the reason for that

Which one is right approach, what do u think about this ?

I always make all members package scope(default)
and if there exists derived classes in other packages i make the affected attribute protected only if i want to avoid manupiulation i make
the affected attribute private.

Now we have a new coding convention and there s written members should always be private and the access should result from a set/getter for it (i alyway write a set/getter for my package/protected scope attributes)
This approach is like point 1)

Now i am programming like point 2)
What is the right/better way to do it?Wht your opinion about it ?

Thank you very much,
Holger
Hi,

i had the same problem a time ago because i save unser input from a htlm Form into an xml File.I display this text lateron with xslt and cocoon.

Saving the links explicitly as CDATA is the right way.
the just get the value with xslt
<xsl:value-of select="//NewsText" disable-output-escaping="yes"/>
the attribute
disable-output-escaping="yes" is very important because i tells the xslt Processor
not to convert <> into &lt&gt
Bye,
Holger

Hi

i am using Jtidy(html tidy) to get a DOM out of some html files and then
i get all Links (all Elements with nodename "a").Now i want to take this
dom and want it to
process with XSLT
when i use the following Code i get the following Exception
<pre>
XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
processor.process(new XSLTInputSource(doc),new
XSLTInputSource(new FileInputStream(xslPath)),
new XSLTResultTarget(new FileOutputStream(outputFile)));
</pre>

XSL Error: Cannot use a DTMLiaison for a input DOM node... pass a
org.apache.xalan.xpath.xdom.XercesLiaison instead!
XSL Error: SAX Exception
org.apache.xalan.xslt.XSLProcessorException:
at org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1799)
at org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1691)
atorg.apache.xalan.xslt.XSLTEngineImpl.getSourceTreeFromInput(XSLTEngineImpl.java:919)
at
org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java:643)
at DOMToHtmlSerializer.serialize(DOMToHtmlSerializer.java:39)
at HtmlLinkValidator.validate(HtmlLinkValidator.java:56)
at Main.<init>(Main.java:44)
at Main.main(Main.java:55)

Ok i thought , if he want it that way i pass a xerces liasion
<pre>
XercesLiaison xl = new XercesLiaison();
XSLTProcessor processor = XSLTProcessorFactory.getProcessor(xl);
processor.process(new XSLTInputSource(doc),new
XSLTInputSource(new FileInputStream(xslPath)),
new XSLTResultTarget(new FileOutputStream(outputFile)));
</pre>
than i get the following exception
XSL Error: SAX Exception
org.apache.xalan.xslt.XSLProcessorException: XercesLiaison can not
handle nodes of type class org.w3c.tidy.DOMDocumentImpl
at org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1753)
at org.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1717)
at
org.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java:746)
at DOMToHtmlSerializer.serialize(DOMToHtmlSerializer.java:39)
at HtmlLinkValidator.validate(HtmlLinkValidator.java:56)
at Main.<init>(Main.java:44)
at Main.main(Main.java:55)

"
org.apache.xalan.xslt.XSLProcessorException: XercesLiaison can not
handle nodes of type class org.w3c.tidy.DOMDocumentImpl "
Why is JTidy using its own DOMDocumentImpl(org.w3c.tidy.DOMDocumentImp)
and not the DOMDocumentImpl from w3c(org.w3c.dom.DOMDocumentImp) ?? (
This would have saved my a lot of time
Now what can i do ?
Solution 1: write the tidy-dom to disk and the reparse it with any
xml-parser , and the process it
Solution 2.
write a wrapper wich changes the tidy-dom to an pure
org.w3c.dom.Document
and then process it
Solution 3 :
Search for another tool doing it

Hmm can anyone of u , especially the developers of this too / libraryl,
tell me what to do?
Hi
During Xslt processing i want Xalan to call a Extension Class auf me.When i do it "local" that means i process the XML-File and Xslt with a Programm with a main mathod.Everything works fine.
But if i copy the code into a Servlet nothing works anymore.
I have all necessary jar in Classpath

Following xml-Code

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:lxslt="http://xml.apache.org/xslt"
xmlns:formatter="XalanExtension"
extension-element-prefixes="formatter"
version="1.0">
<xsl:template match="/">
<xsl:value-of select="formatter:format($text)"/>
</xsl:template>
</xsl:stylesheet>
I think u dont want to c the java code ,its too simple ...
when i run this with servlets i get the following message :
Call to extension function failed: unable to load class 'XalanExtension'
mybe it depends on the directory where the program is started , Servlet runs in a different Enviroment than my program,so it has different pathes to my Extension-Class.That would be an explination.I dont know how to hardcode the path to the Extension-Class so this also dont works.
I tried to jar my Extension-Class and to put it in my Classpath , i had the hope that Xalan looks in the Classpath for this jar, but this also didnt work :-(

P.S(the xml-mail archive from apache is down,so i have to post my question here)
Has anyone of u a solution / suggestion ?
Thx,
Holger
Hi,

I have a XML File where the string
<footag>&#160;</footag> occurs,
I want to parse this Document,add some processing instructions
and then i want i to write it back again to disk.When i do so,
the string <footag>&#160;<footag> is transformed into
<footag> </footag>
Thats odd because i want to process this xml file with a stylesheet and the result of
<xsl:value-of select="//foo"/>
is <footag> <footag> instead of <footag>&nbsp;</footag>
Can i somehow tell the parser to ignore &#160;?
Thanks,
Holger


[This message has been edited by Holger Prause (edited May 25, 2001).]
Hi
I have an existing xml File and i use Xerces to read it in.
<code>
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
org.w3c.dom.Document sourceDoc = builder.parse(new FileInputStream(outputPath));
</code>
But now i want to create a ProcessingInstruction ,i read the api and found that method :
createProcessingInstruction(java.lang.String target, java.lang.String data)
this method returns a ProcessingInstruction which i have to add lateron on the Dom tree.But how can i add this ProcessingInstruction BEFORE the Root-Element.
Has anyone of u already done that ? Must i create a new Document to add the ProcessingInstruction before the root-element ?

Thx a lot,
Holger

The scary thing is that XML will very likely share
the same fate as javascript and DHTML. Being , not living up
to its potenial because of incompatible browsers and parsers.
This is my prediction ! for the next 5 years
I also think so , but when u use xml / xsl with browser , its you own fault !
I think using XML / Xsl in a Browser makes the same sense as writing applets :-(
There are alternative for using xml / xsl in your Browser
-> Xerces / Xalan and the many other good parsers and XSL Prozessors
Its so easy to make Html Output to the browser using Xalan / Java Servlets.

XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
processor.process(new XSLTInputSource(new FileInputStream(xmlPath)),new XSLTInputSource(new FileInputStream(xslPath)),
new XSLTResultTarget(res.getWriter()));
thats all
why writing 80 % w3c Conform Xsl Stylesheets just for that reason that it runs with Msxml Parser, and then writing the same stylesheet for Netscape(Netscapt still has no Xml Support or am i wrong ?) ?
Yeah - i also search for such a solution, i know html is not werllformed , but there must be some custom parser out there building a dom tree from html.

Hello
I developed some classes or accesing xml Documents with JDom.
I like JDOM a lot cause of its little and uncomplicated Api.
I manipulate my xml-document - but then i want it to be used by xalan -
But Xalan only accepts org.w3c.dom.Documents but i have a org.jdom.Document - ok i thought i can use the XMLOutputter of JDOM to do the job.
But i always get a JDom Exception

org.jdom.JDOMException: Exception outputting Document: null
at org.jdom.output.DOMOutputter.output(DOMOutputter.java:168)
at com.discon.servlets.EditServlet.doPost(EditServlet.java:59)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:
04)
at org.apache.tomcat.core.Handler.service(Handler.java:286)

hmm i dont have any special processing instruction or namespaces in my xml document.
hers the source code that causes the error

File file = new File(xmlPath);
SAXBuilder builder = new SAXBuilder();
org.jdom.Document jdoc = builder.build(file);
DOMOutputter out = new DOMOutputter();
org.w3c.dom.Document w3cdoc = out.output(jdoc);
this should work :-(
and heres the xml File

<?xml version="1.0" encoding="ISO-8859-1"?>
<NewsDocument>
<NewsContent>
<NewsContentHeader>
<Caption>1.News erstellt</Caption>
<Date>06.07.2001</Date>
<Author>Holger Prause</Author>
<Id></Id>
</NewsContentHeader>
<NewsText>
Heute wurde eine neue News erstellt
</NewsText>
</NewsContent>
<NewsContent>

</NewsDocument>

I know i am using a Beta Version but maybe i am doing something wrong...

Ok thx a lot,
Holger
>Holger, I�ve heard about werken.xpath, which is said to >implement xpath on top of jdom. �werken.xpath takes as input, a >XPath expression, and a JDOM tree, and returns a NodeSet
>(java.util.List) of selected elements

Hi,
thx for this tip.
I think i am quite familiar with XSLT+XPath so ill take a look at it.In the Xalan Api, this is also possible.(www.apache.org)

Bye,
Holger
Hi

I like JDOM a lot because of its an easy api.
But i have a real Problem when i want to serialize it with JDOM

I want to use the following method(taken from the JDOM Api
public void output(Document doc,
java.io.Writer writer)
throws java.io.IOException
This will print the Document to the given Writer.

The following is my Source Code
SAXBuilder b = new SAXBuilder();
// Create the document
Document doc = b.build(new File(xmlsourcepath));
//get the root -Element
Element rootElement = doc.getRootElement();
serialize(doc);
public void serialize(Document doc) throws Exception {
XMLOutputter outputter = new XMLOutputter();
//outputter.setIndentSize(2);
FileWriter writer = new FileWriter(xmlsourcepath);
outputter.ouput(doc,(java.io.Writer)writer);
}
When i want to compile withe the JBuilder i get the following errormessage
"Main.java": Error #: 300 : method ouput(org.jdom.Document, java.io.Writer) not found in class org.jdom.output.XMLOutputter at line 78, column 17
How can this be ? I als took a looks a the sourcecode of Jdom but i couldnt find any mistake
public void output(Document doc, Writer writer)

i could use the DomOutputter to make a org.w3c.dom.Document and then i could serialize it with Xerces but this is overhead..
has any of you got the same probelm.How did you fixed it ?
Thx,
Holger
Hi

I think i found a reasonalbe solution - ill test how it works on huge Documents
here it comes - ill just show the important methods
<pre>
public Main() {
try {
// Build w/ SAX and Xerces, no validation
SAXBuilder b = new SAXBuilder();
// Create the document
doc = b.build(new File(xmlpath));
Element rootElement = doc.getRootElement();
Vector myChilds = getAllElementsWithName(rootElement,"TextElement");
log("Vector myChilds contains " + myChilds.size()+ " elements");
// Output as XML to screen
//XMLOutputter outputter = new XMLOutputter();
//outputter.output(doc, System.out);
} catch (Exception e)
{
log(e.getMessage());
e.printStackTrace();
}
}
//this method returns a Vector of all Elements with the specified name
private Vector getAllElementsWithName(Element elem,String elemName)
throws Exception{
Vector childVector = new Vector(20,1);
findChilds(childVector,elem,elemName);
return childVector;
}
//this method works recursivly through the DOM - putting all Elements in
//the spezicied Vector
private void findChilds(Vector childContainer,Element elem,String elemName)
throws Exception {
List childs = elem.getChildren();
for(int i = 0;i <childs.size();i++) {
Element tmpelem = (Element)childs.get(i);
log("processing node: "+tmpelem.getName());
if(tmpelem.getName().equals(elemName)) {
childContainer.addElement(tmpelem);
log("Element "+elemName+ "found");
}
else {
findChilds(childContainer,tmpelem, elemName);
}
}
}
</pre>
thats it - i like JDOM
[This message has been edited by Holger Prause (edited March 29, 2001).]
Hi

Sorry i accidentially pressed Return and submitted the topic- *gg*

So my conclusion is you have always to be aware of the XML Spezifikation of the Document you have.You must browse the tree until you reach the node with the child you want to have.
Right ?

Thx,
Holger
[This message has been edited by Holger Prause (edited March 29, 2001).]
Hi,

i just downloaded JDOM and i have to say i find it much easier to learn than the xerces Api.
My Question is : Is there a possebility to search the (whole!)Document for a specified childnode ? . As Result i want a list of all Childs in the document with the given name.
I didnt found such a method - all methods i found
only find child elements nested directly (one level deep).
Hi,

if i understand you - you have an xml File and want to make a Pdf File out of it(with the datas from the xml File)

You can use FOP to do that.you can Find FOP at www.apache.org
With FOP comes some sample files / sample programs.Take a look at the program XalanCommandLine.java coming with FOP.