You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2009/12/08 22:51:07 UTC
svn commit: r888585 - in /incubator/wookie/trunk/src/org/apache/wookie:
manifestmodel/impl/AuthorEntity.java
manifestmodel/impl/DescriptionEntity.java
manifestmodel/impl/LicenseEntity.java manifestmodel/impl/NameEntity.java
util/XmlUtils.java
Author: scottbw
Date: Tue Dec 8 21:51:07 2009
New Revision: 888585
URL: http://svn.apache.org/viewvc?rev=888585&view=rev
Log:
fix for WOOKIE-81 - added an XmlUtils class with getTextContent() which recursively adds text nodes from child elements to the return String.
Added:
incubator/wookie/trunk/src/org/apache/wookie/util/XmlUtils.java
Modified:
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/AuthorEntity.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/DescriptionEntity.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/LicenseEntity.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/NameEntity.java
Modified: incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/AuthorEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/AuthorEntity.java?rev=888585&r1=888584&r2=888585&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/AuthorEntity.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/AuthorEntity.java Tue Dec 8 21:51:07 2009
@@ -20,6 +20,7 @@
import org.apache.wookie.manifestmodel.IAuthorEntity;
import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
import org.apache.wookie.util.UnicodeUtils;
+import org.apache.wookie.util.XmlUtils;
import org.jdom.Element;
/**
* @author Paul Sharples
@@ -73,7 +74,7 @@
}
public void fromXML(Element element) {
- fAuthorName = UnicodeUtils.normalizeWhitespace(element.getText());
+ fAuthorName = UnicodeUtils.normalizeWhitespace(XmlUtils.getTextContent(element));
fHref = UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.HREF_ATTRIBUTE));
if (fHref.equals("")) fHref = null;
if (fHref != null){
Modified: incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/DescriptionEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/DescriptionEntity.java?rev=888585&r1=888584&r2=888585&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/DescriptionEntity.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/DescriptionEntity.java Tue Dec 8 21:51:07 2009
@@ -17,6 +17,7 @@
import org.apache.wookie.manifestmodel.IDescriptionEntity;
import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
import org.apache.wookie.util.UnicodeUtils;
+import org.apache.wookie.util.XmlUtils;
import org.jdom.Element;
/**
* @author Paul Sharples
@@ -51,7 +52,7 @@
public void fromXML(Element element) {
super.fromXML(element);
- fDescription = UnicodeUtils.normalizeWhitespace(element.getText());
+ fDescription = UnicodeUtils.normalizeWhitespace(XmlUtils.getTextContent(element));
}
Modified: incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/LicenseEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/LicenseEntity.java?rev=888585&r1=888584&r2=888585&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/LicenseEntity.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/LicenseEntity.java Tue Dec 8 21:51:07 2009
@@ -17,6 +17,7 @@
import org.apache.wookie.manifestmodel.ILicenseEntity;
import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
import org.apache.wookie.util.UnicodeUtils;
+import org.apache.wookie.util.XmlUtils;
import org.jdom.Element;
/**
* @author Paul Sharples
@@ -74,7 +75,7 @@
public void fromXML(Element element) {
super.fromXML(element);
- fLicenseText = UnicodeUtils.normalizeWhitespace(element.getText());
+ fLicenseText = UnicodeUtils.normalizeWhitespace(XmlUtils.getTextContent(element));
fHref = UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.HREF_ATTRIBUTE));
if (fHref.equals("")) fHref = null;
// Text direction (e.g. for Arabic)
Modified: incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/NameEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/NameEntity.java?rev=888585&r1=888584&r2=888585&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/NameEntity.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/NameEntity.java Tue Dec 8 21:51:07 2009
@@ -17,6 +17,7 @@
import org.apache.wookie.manifestmodel.INameEntity;
import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
import org.apache.wookie.util.UnicodeUtils;
+import org.apache.wookie.util.XmlUtils;
import org.jdom.Element;
/**
@@ -65,7 +66,7 @@
public void fromXML(Element element) {
super.fromXML(element);
// Get the text value of name
- fName = UnicodeUtils.normalizeWhitespace(element.getText());
+ fName = UnicodeUtils.normalizeWhitespace(XmlUtils.getTextContent(element));
// Get the short attribute (if exists)
fShort = UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.SHORT_ATTRIBUTE));
}
Added: incubator/wookie/trunk/src/org/apache/wookie/util/XmlUtils.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/XmlUtils.java?rev=888585&view=auto
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/XmlUtils.java (added)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/XmlUtils.java Tue Dec 8 21:51:07 2009
@@ -0,0 +1,45 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wookie.util;
+
+import org.jdom.Element;
+import org.jdom.Text;
+
+/**
+ * General XML utilities
+ * @author scott
+ *
+ */
+public class XmlUtils {
+
+ /**
+ * Returns the text content of an element, recursively adding
+ * any text nodes found in its child nodes
+ * @param element
+ * @return a string
+ */
+ public static String getTextContent(Element element){
+ String content = "";
+ for (Object node:element.getContent()){
+ if (node instanceof Element){
+ content += getTextContent((Element)node);
+ }
+ if (node instanceof Text){
+ content += ((Text)node).getText();
+ }
+ }
+ return content;
+ }
+
+}