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 2011/02/11 17:29:03 UTC
svn commit: r1069861 - in /incubator/wookie/trunk:
parser/java/src/org/apache/wookie/w3c/
parser/java/src/org/apache/wookie/w3c/impl/
parser/java/src/org/apache/wookie/w3c/updates/
src/org/apache/wookie/util/gadgets/
Author: scottbw
Date: Fri Feb 11 16:29:02 2011
New Revision: 1069861
URL: http://svn.apache.org/viewvc?rev=1069861&view=rev
Log:
Added the functionality for Widget entities to be marshalled back into XML. This is part of the functionality needed for the "Flatpack" feature (see WOOKIE-182)
Modified:
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/IElement.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AbstractLocalizedEntity.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AccessEntity.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AuthorEntity.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/ContentEntity.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/DescriptionEntity.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/FeatureEntity.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/IconEntity.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/LicenseEntity.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/NameEntity.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/ParamEntity.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/PreferenceEntity.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/WidgetManifestModel.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescription.java
incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescriptionDocument.java
incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetAdapter.java
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/IElement.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/IElement.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/IElement.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/IElement.java Fri Feb 11 16:29:02 2011
@@ -28,4 +28,9 @@ public interface IElement {
*/
void fromXML(Element element) throws BadManifestException;
+ /**
+ * Marshall the entity into an XML Element
+ * @return the W3C Widgets Element representing the content of the entity
+ */
+ Element toXml();
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AbstractLocalizedEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AbstractLocalizedEntity.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AbstractLocalizedEntity.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AbstractLocalizedEntity.java Fri Feb 11 16:29:02 2011
@@ -140,5 +140,15 @@ public abstract class AbstractLocalizedE
}
}
+ /**
+ * Set the dir and lang attributes of an element representing the entity - used when marshalling an entity to XML
+ * @param element the element to add attributes to
+ * @return the element with dir and lang attributes added if appropriate
+ */
+ protected Element setLocalisationAttributes(Element element){
+ if (getDir() != null) element.setAttribute(IW3CXMLConfiguration.DIR_ATRRIBUTE,getDir());
+ if (getLang() != null) element.setAttribute(IW3CXMLConfiguration.LANG_ATTRIBUTE,getLang(), Namespace.XML_NAMESPACE);
+ return element;
+ }
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AccessEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AccessEntity.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AccessEntity.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AccessEntity.java Fri Feb 11 16:29:02 2011
@@ -117,4 +117,11 @@ public class AccessEntity implements IAc
}
}
}
+
+ public Element toXml() {
+ Element element = new Element(IW3CXMLConfiguration.ACCESS_ELEMENT,IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ element.setAttribute(IW3CXMLConfiguration.SUBDOMAINS_ATTRIBUTE, String.valueOf(hasSubDomains()));
+ element.setAttribute(IW3CXMLConfiguration.ORIGIN_ATTRIBUTE, getOrigin());
+ return element;
+ }
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AuthorEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AuthorEntity.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AuthorEntity.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/AuthorEntity.java Fri Feb 11 16:29:02 2011
@@ -76,4 +76,13 @@ public class AuthorEntity extends Abstra
if (fEmail.equals("")) fEmail = null;
}
+ public Element toXml() {
+ Element element = new Element(IW3CXMLConfiguration.NAME_ELEMENT, IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ element.setText(getAuthorName());
+ if (getHref()!=null && getHref().length()>0) element.setAttribute(IW3CXMLConfiguration.HREF_ATTRIBUTE, getHref());
+ if (getEmail()!=null && getEmail().length()>0) element.setAttribute(IW3CXMLConfiguration.EMAIL_ATTRIBUTE, getEmail());
+ element = setLocalisationAttributes(element);
+ return element;
+ }
+
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/ContentEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/ContentEntity.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/ContentEntity.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/ContentEntity.java Fri Feb 11 16:29:02 2011
@@ -126,4 +126,14 @@ public class ContentEntity extends Abstr
return supported;
}
+ public Element toXml() {
+ Element contentElem = new Element(IW3CXMLConfiguration.CONTENT_ELEMENT,IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ contentElem.setAttribute(IW3CXMLConfiguration.SOURCE_ATTRIBUTE,getSrc());
+ if (getType() != null) contentElem.setAttribute(IW3CXMLConfiguration.TYPE_ATTRIBUTE,getType());
+ if (getCharSet() != null) contentElem.setAttribute(IW3CXMLConfiguration.CHARSET_ATTRIBUTE,getCharSet());
+
+ contentElem = setLocalisationAttributes(contentElem);
+ return contentElem;
+ }
+
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/DescriptionEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/DescriptionEntity.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/DescriptionEntity.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/DescriptionEntity.java Fri Feb 11 16:29:02 2011
@@ -48,5 +48,12 @@ public class DescriptionEntity extends A
fDescription = getLocalizedTextContent(element);
}
+ public Element toXml() {
+ Element element = new Element(IW3CXMLConfiguration.DESCRIPTION_ELEMENT, IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ element.setText(getDescription());
+ element = setLocalisationAttributes(element);
+ return element;
+ }
+
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/FeatureEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/FeatureEntity.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/FeatureEntity.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/FeatureEntity.java Fri Feb 11 16:29:02 2011
@@ -136,4 +136,14 @@ public class FeatureEntity implements IF
}
+ public Element toXml() {
+ Element element = new Element(IW3CXMLConfiguration.FEATURE_ELEMENT, IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ element.setAttribute(IW3CXMLConfiguration.NAME_ATTRIBUTE, getName());
+ element.setAttribute(IW3CXMLConfiguration.REQUIRED_ATTRIBUTE, String.valueOf(isRequired()));
+ for (IParamEntity param: getParams()){
+ element.addContent(param.toXml());
+ }
+ return element;
+ }
+
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/IconEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/IconEntity.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/IconEntity.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/IconEntity.java Fri Feb 11 16:29:02 2011
@@ -107,5 +107,13 @@ public class IconEntity extends Abstract
}
}
+ public Element toXml() {
+ Element element = new Element(IW3CXMLConfiguration.ICON_ELEMENT, IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ element.setAttribute(IW3CXMLConfiguration.SOURCE_ATTRIBUTE, getSrc());
+ if (getHeight() != null && getHeight() > 0) element.setAttribute(IW3CXMLConfiguration.HEIGHT_ATTRIBUTE,String.valueOf(getHeight()));
+ if (getWidth() != null && getWidth() > 0) element.setAttribute(IW3CXMLConfiguration.WIDTH_ATTRIBUTE,String.valueOf(getWidth()));
+ return element;
+ }
+
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/LicenseEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/LicenseEntity.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/LicenseEntity.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/LicenseEntity.java Fri Feb 11 16:29:02 2011
@@ -62,4 +62,12 @@ public class LicenseEntity extends Abstr
if (fHref.equals("")) fHref = null;
}
+ public Element toXml() {
+ Element element = new Element(IW3CXMLConfiguration.LICENSE_ELEMENT, IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ element.setText(getLicenseText());
+ if (getHref()!=null && getHref().length()>0) element.setAttribute(IW3CXMLConfiguration.HREF_ATTRIBUTE, getHref());
+ element = setLocalisationAttributes(element);
+ return element;
+ }
+
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/NameEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/NameEntity.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/NameEntity.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/NameEntity.java Fri Feb 11 16:29:02 2011
@@ -23,7 +23,7 @@ import org.jdom.Element;
* the <name> element
*/
public class NameEntity extends AbstractLocalizedEntity implements INameEntity {
-
+
private String fName;
private String fShort;
@@ -64,5 +64,13 @@ public class NameEntity extends Abstract
// Get the short attribute (if exists)
fShort = UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.SHORT_ATTRIBUTE));
}
+
+ public Element toXml() {
+ Element nameElem = new Element(IW3CXMLConfiguration.NAME_ELEMENT, IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ nameElem.setText(getName());
+ if (getShort() != null && getShort().length() > 0) nameElem.setAttribute(IW3CXMLConfiguration.SHORT_ATTRIBUTE, getShort());
+ nameElem = setLocalisationAttributes(nameElem);
+ return nameElem;
+ }
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/ParamEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/ParamEntity.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/ParamEntity.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/ParamEntity.java Fri Feb 11 16:29:02 2011
@@ -60,6 +60,13 @@ public class ParamEntity implements IPar
if (fName.equals("")) fName = null;
fValue = UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.VALUE_ATTRIBUTE));
if (fValue.equals("")) fValue = null;
- }
+ }
+
+ public Element toXml() {
+ Element element = new Element(IW3CXMLConfiguration.PARAM_ELEMENT, IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ element.setAttribute(IW3CXMLConfiguration.NAME_ATTRIBUTE, getName());
+ element.setAttribute(IW3CXMLConfiguration.VALUE_ATTRIBUTE, getValue());
+ return element;
+ }
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/PreferenceEntity.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/PreferenceEntity.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/PreferenceEntity.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/PreferenceEntity.java Fri Feb 11 16:29:02 2011
@@ -49,4 +49,13 @@ public class PreferenceEntity extends Pa
fReadOnly = false;
}
}
+
+ @Override
+ public Element toXml() {
+ Element element = new Element(IW3CXMLConfiguration.PREFERENCE_ELEMENT, IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ element.setAttribute(IW3CXMLConfiguration.READONLY_ATTRIBUTE, String.valueOf(isReadOnly()));
+ element.setAttribute(IW3CXMLConfiguration.NAME_ATTRIBUTE, getName());
+ element.setAttribute(IW3CXMLConfiguration.VALUE_ATTRIBUTE, getValue());
+ return element;
+ }
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/WidgetManifestModel.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/WidgetManifestModel.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/WidgetManifestModel.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/impl/WidgetManifestModel.java Fri Feb 11 16:29:02 2011
@@ -408,4 +408,67 @@ public class WidgetManifestModel impleme
if (StringUtils.equals(entity.getLang(), ent.getLang())) first = false;
return first;
}
+
+ public Element toXml() {
+ Element widgetElem = new Element(IW3CXMLConfiguration.WIDGET_ELEMENT,IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ widgetElem.setAttribute(IW3CXMLConfiguration.ID_ATTRIBUTE, getIdentifier());
+ if (getVersion() != null && getVersion().length() > 0) widgetElem.setAttribute(IW3CXMLConfiguration.VERSION_ATTRIBUTE, getVersion());
+ if (getHeight() != null && getHeight() > 0) widgetElem.setAttribute(IW3CXMLConfiguration.HEIGHT_ATTRIBUTE,String.valueOf(getHeight()));
+ if (getWidth() != null && getWidth() > 0) widgetElem.setAttribute(IW3CXMLConfiguration.WIDTH_ATTRIBUTE,String.valueOf(getWidth()));
+ if (getViewModes() != null) widgetElem.setAttribute(IW3CXMLConfiguration.MODE_ATTRIBUTE, getViewModes());
+
+
+ // Name
+ for (INameEntity name: getNames()){
+ Element nameElem = name.toXml();
+ widgetElem.addContent(nameElem);
+ }
+ // Description
+ for (IDescriptionEntity description: getDescriptions()){
+ widgetElem.addContent(description.toXml());
+ }
+ // Author
+ if (getAuthor() != null) widgetElem.addContent(getAuthor().toXml());
+
+ // Update
+ if (getUpdate()!= null){
+ widgetElem.addContent(new UpdateDescription(getUpdate()).toXML());
+ }
+
+
+ // Licenses
+ for (ILicenseEntity license: getLicensesList()){
+ widgetElem.addContent(license.toXml());
+ }
+
+ // Icons
+ for (IIconEntity icon:getIconsList()){
+ Element iconElem = icon.toXml();
+ widgetElem.addContent(iconElem);
+ }
+
+ // Access
+ for (IAccessEntity access: getAccessList()){
+ Element accessElem = access.toXml();
+ widgetElem.addContent(accessElem);
+ }
+
+ // Content
+ for (IContentEntity content: getContentList()){
+ Element contentElem = content.toXml();
+ widgetElem.addContent(contentElem);
+ }
+
+ // Features
+ for (IFeatureEntity feature: getFeatures()){
+ widgetElem.addContent(feature.toXml());
+ }
+
+ // Preferences
+ for (IPreferenceEntity preference: getPrefences()){
+ widgetElem.addContent(preference.toXml());
+ }
+
+ return widgetElem;
+ }
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescription.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescription.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescription.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescription.java Fri Feb 11 16:29:02 2011
@@ -12,6 +12,7 @@
* limitations under the License.
*/
package org.apache.wookie.w3c.updates;
+import org.apache.wookie.w3c.IW3CXMLConfiguration;
import org.apache.wookie.w3c.exceptions.BadManifestException;
import org.apache.wookie.w3c.util.IRIValidator;
import org.jdom.Element;
@@ -26,6 +27,10 @@ public class UpdateDescription{
public UpdateDescription(){
}
+ public UpdateDescription(String href){
+ _href = href;
+ }
+
public String getHref() {
return _href;
}
@@ -36,5 +41,11 @@ public class UpdateDescription{
_href = href;
}
}
+
+ public Element toXML(){
+ Element element = new Element(IW3CXMLConfiguration.UPDATE_ELEMENT, IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ element.setAttribute(IW3CXMLConfiguration.HREF_ATTRIBUTE, getHref());
+ return element;
+ }
}
Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescriptionDocument.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescriptionDocument.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescriptionDocument.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/updates/UpdateDescriptionDocument.java Fri Feb 11 16:29:02 2011
@@ -138,5 +138,12 @@ public class UpdateDescriptionDocument{
super.fromXML(element);
this.text = getLocalizedTextContent(element);
}
+
+ public Element toXml() {
+ Element element = new Element("details",IW3CXMLConfiguration.MANIFEST_NAMESPACE);
+ element.setText(text);
+ element = setLocalisationAttributes(element);
+ return element;
+ }
}
}
Modified: incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetAdapter.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetAdapter.java?rev=1069861&r1=1069860&r2=1069861&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetAdapter.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/gadgets/GadgetAdapter.java Fri Feb 11 16:29:02 2011
@@ -203,6 +203,11 @@ public class GadgetAdapter implements W3
public String getUpdate() {
return null;
}
+
+ public Element toXml() {
+ // TODO Auto-generated method stub
+ return null;
+ }