You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lenya.apache.org by Andreas Hartmann <an...@apache.org> on 2004/07/11 02:08:57 UTC
Deprecate o.a.l.xml.DOMUtil?
Hi Lenya developers,
is it OK with everybody to deprecate the DOMUtil class?
It provides several XML utility methods based on the
deprecated DOMParserFactory class.
Apart from that, some javadocs are missing.
Here's my
+1
to set this class to "deprecated".
-- Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Deprecate o.a.l.xml.DOMUtil?
Posted by "Gregor J. Rothfuss" <gr...@apache.org>.
Andreas Hartmann wrote:
> Hi Lenya developers,
>
> is it OK with everybody to deprecate the DOMUtil class?
> It provides several XML utility methods based on the
> deprecated DOMParserFactory class.
>
> Apart from that, some javadocs are missing.
>
> Here's my
>
> +1
>
> to set this class to "deprecated".
will it be removed once we open the 1.4 branch? what takes its place?
+1
--
Gregor J. Rothfuss
Wyona Inc. - Open Source Content Management - Apache Lenya
http://wyona.com http://cocoon.apache.org/lenya
gregor.rothfuss@wyona.com gregor@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Deprecate o.a.l.xml.DOMUtil?
Posted by Andreas Hartmann <an...@apache.org>.
Michael Wechner wrote:
> Andreas Hartmann wrote:
>
>>
>>
>> I don't want to remove the functionality, I just
>> want to remove the use of deprecated code. So maybe
>> refactoring would be even better than deprecating.
>
>
>
> I think we can deprecate it and refactor it at the same time, but I think
> it's important to tell people within the deprecated methods what the
> alternative is, else people (myself ;-) will start again to use whatever
> as alternative ...
I added javadocs with replacement code suggestions.
Could you please review them?
-- Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Deprecate o.a.l.xml.DOMUtil?
Posted by Andreas Hartmann <an...@apache.org>.
Michael Wechner wrote:
> Andreas Hartmann wrote:
>
>>
>>
>> I don't want to remove the functionality, I just
>> want to remove the use of deprecated code. So maybe
>> refactoring would be even better than deprecating.
>
>
>
> I think we can deprecate it and refactor it at the same time, but I think
> it's important to tell people within the deprecated methods what the
> alternative is, else people (myself ;-) will start again to use whatever
> as alternative ...
I think this one needs a complete rewrite. The XPath
should be resolved and the node list checked if it consists
of elements.
/**
* Check if elements exists This method just checks the root
element! TODO: Implementation is
* not really finished, or is it!
*/
public boolean elementExists(Element element, XPath xpath) throws
Exception {
log.debug(xpath);
if (xpath.parts.length > 0) {
NodeList nl = element.getElementsByTagName(xpath.parts[0]);
if (nl.getLength() == 0) {
return false;
} else if (nl.getLength() == 1) {
return true;
}
}
return false;
}
-- Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Deprecate o.a.l.xml.DOMUtil?
Posted by "Gregor J. Rothfuss" <gr...@apache.org>.
Andreas Hartmann wrote:
> This method (see below) is considered harmful too.
> It will throw ClassCastExceptions when the resolved node list contains
> non-element nodes.
>
> I would agree to change it to
>
> Element[] selectElements(Node node, String xPath)
>
> with proper error handling. Otherwise the client class should use
> the XPathAPI class directly.
+1
--
Gregor J. Rothfuss
Wyona Inc. - Open Source Content Management - Apache Lenya
http://wyona.com http://cocoon.apache.org/lenya
gregor.rothfuss@wyona.com gregor@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Deprecate o.a.l.xml.DOMUtil?
Posted by Andreas Hartmann <an...@apache.org>.
Michael Wechner wrote:
> Andreas Hartmann wrote:
>
>>
>>
>> I don't want to remove the functionality, I just
>> want to remove the use of deprecated code. So maybe
>> refactoring would be even better than deprecating.
>
>
>
> I think we can deprecate it and refactor it at the same time, but I think
> it's important to tell people within the deprecated methods what the
> alternative is, else people (myself ;-) will start again to use whatever
> as alternative ...
This method (see below) is considered harmful too.
It will throw ClassCastExceptions when the resolved node list contains
non-element nodes.
I would agree to change it to
Element[] selectElements(Node node, String xPath)
with proper error handling. Otherwise the client class should use
the XPathAPI class directly.
-- Andreas
/**
* Selects an array of elements using an XPath.
*
* @param document The document.
* @param xpath The XPath.
* @return An array of elements.
* @throws Exception if the XPath does not return a
<code>NodeList</code> consisting of elements.
*
* @deprecated Use
* {@link
org.apache.xpath.XPathAPI#selectNodeList(org.w3c.dom.Node,
java.lang.String)}
* instead.
*/
public Element[] select(Document document, String xpath) throws
Exception {
log.debug(".select(): " + xpath);
Vector nodes = xpf.select(document, "xpointer(" + xpath + ")");
Element[] elements = new Element[nodes.size()];
for (int i = 0; i < nodes.size(); i++) {
elements[i] = (Element) nodes.elementAt(i);
}
return elements;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Deprecate o.a.l.xml.DOMUtil?
Posted by Michael Wechner <mi...@wyona.com>.
Andreas Hartmann wrote:
>
> I think the following method is a little dangerous (I added javadocs).
thanks
> Do you think the javadocs are sufficient, or should we change the
> method to keep the child elements?
IIRC there is/was a usecase where this method makes/made sense, e.g.
<para>hello <i>Andreas</i></para>
replace by
<para>goodbye</para>
I think the javadoc is sufficient. Nobody is used to use this method ;-)
Michi
>
> /**
> * <p>
> * This method removes all child nodes from an element and inserts
> a text node instead.
> * </p>
> * <p>
> * Caution: Child elements are removed as well!
> * </p>
> * @param element The element.
> * @param text The string to insert as a text node.
> */
> public void replaceText(Element element, String text) {
> NodeList nl = element.getChildNodes();
>
> for (int i = nl.getLength() - 1; i >= 0; i--) {
> element.removeChild(nl.item(i));
> }
>
>
> element.appendChild(dpf.newTextNode(element.getOwnerDocument(), text));
> }
>
> -- Andreas
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
>
>
--
Michael Wechner
Wyona Inc. - Open Source Content Management - Apache Lenya
http://www.wyona.com http://cocoon.apache.org/lenya/
michael.wechner@wyona.com michi@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Deprecate o.a.l.xml.DOMUtil?
Posted by Andreas Hartmann <an...@apache.org>.
Michael Wechner wrote:
> Andreas Hartmann wrote:
>
>>
>>
>> I don't want to remove the functionality, I just
>> want to remove the use of deprecated code. So maybe
>> refactoring would be even better than deprecating.
>
>
>
> I think we can deprecate it and refactor it at the same time, but I think
> it's important to tell people within the deprecated methods what the
> alternative is, else people (myself ;-) will start again to use whatever
> as alternative ...
I think the following method is a little dangerous (I added javadocs).
Do you think the javadocs are sufficient, or should we change the
method to keep the child elements?
/**
* <p>
* This method removes all child nodes from an element and inserts
a text node instead.
* </p>
* <p>
* Caution: Child elements are removed as well!
* </p>
* @param element The element.
* @param text The string to insert as a text node.
*/
public void replaceText(Element element, String text) {
NodeList nl = element.getChildNodes();
for (int i = nl.getLength() - 1; i >= 0; i--) {
element.removeChild(nl.item(i));
}
element.appendChild(dpf.newTextNode(element.getOwnerDocument(),
text));
}
-- Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Deprecate o.a.l.xml.DOMUtil?
Posted by Michael Wechner <mi...@wyona.com>.
Andreas Hartmann wrote:
> Michael Wechner wrote:
> . If there
> is no sufficient test scenario, we will have to write a unit test.
+1 for writing a unit test, whereas we can use the ingredients of the
main method of DOMUtil (good start to refactor ;-)
Michi
>
> -- Andreas
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
>
>
--
Michael Wechner
Wyona Inc. - Open Source Content Management - Apache Lenya
http://www.wyona.com http://cocoon.apache.org/lenya/
michael.wechner@wyona.com michi@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Deprecate o.a.l.xml.DOMUtil?
Posted by Andreas Hartmann <an...@apache.org>.
Michael Wechner wrote:
> Andreas Hartmann wrote:
>
>>
>>
>> I don't want to remove the functionality, I just
>> want to remove the use of deprecated code. So maybe
>> refactoring would be even better than deprecating.
>
>
>
> I think we can deprecate it and refactor it at the same time, but I think
> it's important to tell people within the deprecated methods what the
> alternative is, else people (myself ;-) will start again to use whatever
> as alternative ...
OK.
Do you know a scenario to test the DOMUtil class? Before starting
the refactoring, we have to provide regression tests. If there
is no sufficient test scenario, we will have to write a unit test.
-- Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Deprecate o.a.l.xml.DOMUtil?
Posted by Michael Wechner <mi...@wyona.com>.
Andreas Hartmann wrote:
>
>
> I don't want to remove the functionality, I just
> want to remove the use of deprecated code. So maybe
> refactoring would be even better than deprecating.
I think we can deprecate it and refactor it at the same time, but I think
it's important to tell people within the deprecated methods what the
alternative is, else people (myself ;-) will start again to use whatever
as alternative ...
Michi
>
> -- Andreas
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
>
>
--
Michael Wechner
Wyona Inc. - Open Source Content Management - Apache Lenya
http://www.wyona.com http://cocoon.apache.org/lenya/
michael.wechner@wyona.com michi@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Deprecate o.a.l.xml.DOMUtil?
Posted by Andreas Hartmann <an...@apache.org>.
Michael Wechner wrote:
> Andreas Hartmann wrote:
>
>>
>> Here's my
>>
>> +1
>>
>> to set this class to "deprecated".
>
>
>
> +1 but what shall we take as alternative?
We have to look at the methods in detail.
I guess most of them can be replaced with calls
to the DocumentHelper and XPathAPI.
When we don't find a replacement, we can consider
to implement the methods using JAXP / XPathAPI and
maybe move them to the DocumentHelper.
I don't want to remove the functionality, I just
want to remove the use of deprecated code. So maybe
refactoring would be even better than deprecating.
-- Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
Re: Deprecate o.a.l.xml.DOMUtil?
Posted by Michael Wechner <mi...@wyona.com>.
Andreas Hartmann wrote:
>
> Here's my
>
> +1
>
> to set this class to "deprecated".
+1 but what shall we take as alternative?
Thanks
Michi
>
> -- Andreas
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: lenya-dev-help@cocoon.apache.org
>
>
--
Michael Wechner
Wyona Inc. - Open Source Content Management - Apache Lenya
http://www.wyona.com http://cocoon.apache.org/lenya/
michael.wechner@wyona.com michi@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-dev-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-dev-help@cocoon.apache.org