Author: scottbw
Date: Fri Nov 13 01:09:02 2009
New Revision: 835686
URL: http://svn.apache.org/viewvc?rev=835686&view=rev
Log:
Refactoring of the processing model for Widgets uploaded into Wookie. It
addresses issues WOOKIE-56, WOOKIE-57, and closes some loopholes in the
solution for WOOKIE-45. Overall a much larger number of W3C test cases can now
pass.
Added:
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/ILocalizedEntity.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/LocalizedEntity.java
Removed:
incubator/wookie/trunk/src/org/apache/wookie/util/WidgetManifestUtils.java
Modified:
incubator/wookie/trunk/src-tests/org/apache/wookie/tests/W3CTest.java
incubator/wookie/trunk/src/org/apache/wookie/WidgetAdminServlet.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IContentEntity.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IDescriptionEntity.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/ILicenseEntity.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/INameEntity.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IW3CXMLConfiguration.java
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/ContentEntity.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
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/WidgetManifestModel.java
incubator/wookie/trunk/src/org/apache/wookie/server/Start.java
incubator/wookie/trunk/src/org/apache/wookie/util/WidgetPackageUtils.java
Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/W3CTest.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/W3CTest.java?rev=835686&r1=835685&r2=835686&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/W3CTest.java
(original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/W3CTest.java Fri
Nov 13 01:09:02 2009
@@ -24,7 +24,7 @@
import org.apache.wookie.exceptions.BadManifestException;
import org.apache.wookie.manifestmodel.IManifestModel;
import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
-import org.apache.wookie.util.WidgetManifestUtils;
+import org.apache.wookie.manifestmodel.impl.WidgetManifestModel;
import org.jdom.JDOMException;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -69,7 +69,7 @@
public void testWrongXML(){
try {
@SuppressWarnings("unused")
- IManifestModel model =
WidgetManifestUtils.dealWithManifest(WRONG_XML,null);
+ IManifestModel model = new
WidgetManifestModel(WRONG_XML,null);
// This should throw a BadManifestException
//assertNull(model);
}
@@ -88,7 +88,7 @@
public void testParseManifestBadNS(){
try {
@SuppressWarnings("unused")
- IManifestModel model =
WidgetManifestUtils.dealWithManifest(BAD_NAMESPACE_MANIFEST,null);
+ IManifestModel model = new
WidgetManifestModel(BAD_NAMESPACE_MANIFEST,null);
// This should throw a BadManifestException
}
catch (BadManifestException ex) {
@@ -105,12 +105,12 @@
@Test
public void testParseManifest(){
try {
- IManifestModel model =
WidgetManifestUtils.dealWithManifest(BASIC_MANIFEST,null);
+ IManifestModel model = new WidgetManifestModel
(BASIC_MANIFEST,null);
assertNotNull(model);
assertEquals("http://www.getwookie.org/widgets/WP3/natter",
model.getIdentifier());
assertEquals("Natter", model.getLocalName("en"));
- assertEquals(255, model.getWidth());
- assertEquals(383, model.getHeight());
+ assertEquals(255, model.getWidth().intValue());
+ assertEquals(383, model.getHeight().intValue());
assertEquals("Icon.png", model.getFirstIconPath());
assertEquals("Scott Wilson", model.getAuthor());
assertEquals("1.0", model.getVersion());
@@ -131,7 +131,7 @@
@Test
public void testFeaturesExample(){
try {
- IManifestModel model =
WidgetManifestUtils.dealWithManifest(FEATURES_MANIFEST, null);
+ IManifestModel model = new
WidgetManifestModel(FEATURES_MANIFEST,null);
assertNotNull(model);
assertEquals("http://www.getwookie.org/example",
model.getIdentifier());
assertEquals("Example Test Widget",
model.getLocalName("en"));
@@ -181,7 +181,7 @@
@Test
public void testPrefsManifest(){
try {
- IManifestModel model =
WidgetManifestUtils.dealWithManifest(MANIFEST_WITH_PREFERENCES,null);
+ IManifestModel model = new
WidgetManifestModel(MANIFEST_WITH_PREFERENCES,null);
assertNotNull(model);
// should be 3 prefs
assertEquals(3, model.getPrefences().size());
@@ -222,5 +222,6 @@
return sb.toString();
}
+
}
Modified: incubator/wookie/trunk/src/org/apache/wookie/WidgetAdminServlet.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/WidgetAdminServlet.java?rev=835686&r1=835685&r2=835686&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/WidgetAdminServlet.java
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/WidgetAdminServlet.java Fri
Nov 13 01:09:02 2009
@@ -41,8 +41,8 @@
import org.apache.wookie.manager.impl.WidgetAdminManager;
import org.apache.wookie.manifestmodel.IManifestModel;
import org.apache.wookie.manifestmodel.impl.ContentEntity;
+import org.apache.wookie.manifestmodel.impl.WidgetManifestModel;
import org.apache.wookie.server.LocaleHandler;
-import org.apache.wookie.util.WidgetManifestUtils;
import org.apache.wookie.util.StartPageJSParser;
import org.apache.wookie.util.WidgetPackageUtils;
import org.apache.wookie.util.gadgets.GadgetUtils;
@@ -464,10 +464,10 @@
ZipFile zip = new ZipFile(zipFile);
if (WidgetPackageUtils.hasManifest(zip)){
// build the model
- IManifestModel widgetModel =
WidgetManifestUtils.dealWithManifest(WidgetPackageUtils.extractManifest(zip),
localizedMessages);
+ IManifestModel widgetModel = new
WidgetManifestModel(WidgetPackageUtils.extractManifest(zip), zip);
// get the start file; if there is no
valid start file an exception will be thrown
- String src =
WidgetPackageUtils.locateStartFile(widgetModel, zip, localizedMessages);
+ String src =
WidgetPackageUtils.locateStartFile(widgetModel, zip);
// get the widget identifier
String manifestIdentifier =
widgetModel.getIdentifier();
// create the folder structure to unzip
the zip into
@@ -525,12 +525,16 @@
session.setAttribute("error_value",
localizedMessages.getString("WidgetAdminServlet.25") + "\n" + ex.getMessage());
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
catch (BadManifestException ex) {
- _logger.error(ex);
- session.setAttribute("error_value", ex.getMessage());
//$NON-NLS-1$
+ _logger.error(ex);
+ String message = ex.getMessage();
+ if (ex.getMessage() == null ||
ex.getMessage().equals("")) message =
localizedMessages.getString("WidgetAdminServlet.27"); //$NON-NLS-1$
+ session.setAttribute("error_value", message);
//$NON-NLS-1$
}
catch (BadWidgetZipFileException ex) {
- _logger.error(ex);
- session.setAttribute("error_value", ex.getMessage());
//$NON-NLS-1$
+ _logger.error(ex);
+ String message = ex.getMessage();
+ if (ex.getMessage() == null ||
ex.getMessage().equals("")) message =
localizedMessages.getString("WidgetAdminServlet.29"); //$NON-NLS-1$
+ session.setAttribute("error_value", message);
//$NON-NLS-1$
}
Modified:
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IContentEntity.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IContentEntity.java?rev=835686&r1=835685&r2=835686&view=diff
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IContentEntity.java
(original)
+++
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IContentEntity.java
Fri Nov 13 01:09:02 2009
@@ -13,6 +13,11 @@
*/
package org.apache.wookie.manifestmodel;
+
+import org.apache.commons.compress.archivers.zip.ZipFile;
+import org.apache.wookie.exceptions.BadManifestException;
+import org.jdom.Element;
+
/**
* @author Paul Sharples
* @version $Id: IContentEntity.java,v 1.3 2009-09-02 18:37:31 scottwilson Exp
$
@@ -30,5 +35,7 @@
public String getType();
public void setType(String type);
+
+ public void fromXML(Element element, ZipFile zip) throws
BadManifestException;
}
Modified:
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IDescriptionEntity.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IDescriptionEntity.java?rev=835686&r1=835685&r2=835686&view=diff
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IDescriptionEntity.java
(original)
+++
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IDescriptionEntity.java
Fri Nov 13 01:09:02 2009
@@ -17,14 +17,10 @@
* @author Paul Sharples
* @version $Id: IDescriptionEntity.java,v 1.3 2009-09-02 18:37:30 scottwilson
Exp $
*/
-public interface IDescriptionEntity extends IManifestModelBase {
+public interface IDescriptionEntity extends ILocalizedEntity {
public String getDescription();
public void setDescription(String description);
- public String getLanguage();
-
- public void setLanguage(String language);
-
}
Modified:
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/ILicenseEntity.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/ILicenseEntity.java?rev=835686&r1=835685&r2=835686&view=diff
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/ILicenseEntity.java
(original)
+++
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/ILicenseEntity.java
Fri Nov 13 01:09:02 2009
@@ -17,7 +17,7 @@
* @author Paul Sharples
* @version $Id: ILicenseEntity.java,v 1.3 2009-09-02 18:37:30 scottwilson Exp
$
*/
-public interface ILicenseEntity extends IManifestModelBase {
+public interface ILicenseEntity extends ILocalizedEntity {
public String getLicenseText();
@@ -27,8 +27,4 @@
public void setHref(String href);
- public String getLanguage();
-
- public void setLanguage(String language);
-
}
Added:
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/ILocalizedEntity.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/ILocalizedEntity.java?rev=835686&view=auto
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/ILocalizedEntity.java
(added)
+++
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/ILocalizedEntity.java
Fri Nov 13 01:09:02 2009
@@ -0,0 +1,22 @@
+/*
+ * 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.manifestmodel;
+
+public interface ILocalizedEntity extends IManifestModelBase {
+
+ public String getLanguage();
+
+ public void setLanguage(String language);
+
+}
Modified:
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/INameEntity.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/INameEntity.java?rev=835686&r1=835685&r2=835686&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/INameEntity.java
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/INameEntity.java
Fri Nov 13 01:09:02 2009
@@ -17,7 +17,7 @@
* @author Paul Sharples
* @version $Id: INameEntity.java,v 1.3 2009-09-02 18:37:31 scottwilson Exp $
*/
-public interface INameEntity extends IManifestModelBase {
+public interface INameEntity extends ILocalizedEntity {
public String getName();
@@ -27,8 +27,6 @@
public void setShort(String short1);
- public String getLanguage();
- public void setLanguage(String language);
}
Modified:
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IW3CXMLConfiguration.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IW3CXMLConfiguration.java?rev=835686&r1=835685&r2=835686&view=diff
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IW3CXMLConfiguration.java
(original)
+++
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/IW3CXMLConfiguration.java
Fri Nov 13 01:09:02 2009
@@ -75,7 +75,6 @@
// Other values used
public static final String DEFAULT_WIDGET_VERSION = "1.0";
public static final String UNKNOWN = "unknown";
- public static final String DEFAULT_SRC_PAGE = "index.htm";
public static final String DEFAULT_ICON_PATH =
"/wookie/shared/images/cog.gif";
public static final int DEFAULT_HEIGHT_SMALL = 32;
public static final int DEFAULT_WIDTH_SMALL = 32;
@@ -83,7 +82,8 @@
public static final int DEFAULT_WIDTH_LARGE = 150;
public static final String MANIFEST_FILE = "config.xml";
public static final String MANIFEST_NAMESPACE =
"http://www.w3.org/ns/widgets";
-
+ public static final String[] SUPPORTED_CONTENT_TYPES = {"text/html",
"image/svg+xml","application/xhtml+xml"};
+ public static final String[] START_FILES =
{"index.htm","index.html","index.svg","index.xhtml","index.xht"};
// Deprecated: used in early drafts of spec:
Modified:
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/ContentEntity.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/ContentEntity.java?rev=835686&r1=835685&r2=835686&view=diff
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/ContentEntity.java
(original)
+++
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/ContentEntity.java
Fri Nov 13 01:09:02 2009
@@ -14,6 +14,9 @@
package org.apache.wookie.manifestmodel.impl;
+import org.apache.commons.compress.archivers.zip.ZipFile;
+import org.apache.commons.lang.StringUtils;
+import org.apache.wookie.exceptions.BadManifestException;
import org.apache.wookie.manifestmodel.IContentEntity;
import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
import org.apache.wookie.util.UnicodeUtils;
@@ -69,20 +72,35 @@
return IW3CXMLConfiguration.CONTENT_ELEMENT;
}
- public void fromXML(Element element) {
- fSrc =
UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.SOURCE_ATTRIBUTE));
- // just in case it's there, but they leave it empty
- if(fSrc.equals("")){
- fSrc = IW3CXMLConfiguration.DEFAULT_SRC_PAGE;
+ public void fromXML(Element element) throws BadManifestException{
+
+ }
+
+ private static boolean isSupportedContentType(String atype){
+ boolean supported = false;
+ for (String type: IW3CXMLConfiguration.SUPPORTED_CONTENT_TYPES){
+ if (StringUtils.equals(atype, type)) supported = true;
}
+ return supported;
+ }
+
+ public void fromXML(Element element, ZipFile zip) throws
BadManifestException {
+ fSrc =
UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.SOURCE_ATTRIBUTE));
+ // Check custom start file exists; remove the src value if it
doesn't
+ if(!fSrc.equals("")) if (zip.getEntry(fSrc) == null) fSrc = "";
+
fCharSet =
UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.CHARSET_ATTRIBUTE));
- if(fSrc.equals("")){
+ if(fCharSet.equals("")){
fCharSet = IW3CXMLConfiguration.DEFAULT_CHARSET;
}
fType =
UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.TYPE_ATTRIBUTE));
- if(fSrc.equals("")){
+ if(fType.equals("")){
fType = IW3CXMLConfiguration.DEFAULT_MEDIA_TYPE;
- }
- }
+ } else {
+ // If a type attribute is specified, and is either
invalid or unsupported, we must treat it as an invalid widget
+ if (!isSupportedContentType(fSrc)) throw new
BadManifestException();
+ }
+
+ }
}
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=835686&r1=835685&r2=835686&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
Fri Nov 13 01:09:02 2009
@@ -18,25 +18,23 @@
import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
import org.apache.wookie.util.UnicodeUtils;
import org.jdom.Element;
-import org.jdom.Namespace;
/**
* @author Paul Sharples
* @version $Id: DescriptionEntity.java,v 1.3 2009-09-02 18:37:31 scottwilson
Exp $
*/
-public class DescriptionEntity implements IDescriptionEntity {
+public class DescriptionEntity extends LocalizedEntity implements
IDescriptionEntity {
private String fDescription;
- private String fLanguage;
public DescriptionEntity(){
fDescription = "";
- fLanguage = "";
+ setLanguage("");
}
public DescriptionEntity(String description, String language) {
super();
fDescription = description;
- fLanguage = language;
+ setLanguage(language);
}
public String getDescription() {
@@ -47,21 +45,13 @@
fDescription = description;
}
- public String getLanguage() {
- return fLanguage;
- }
-
- public void setLanguage(String language) {
- fLanguage = language;
- }
-
public String getXMLTagName() {
return IW3CXMLConfiguration.DESCRIPTION_ELEMENT;
}
public void fromXML(Element element) {
+ super.fromXML(element);
fDescription =
UnicodeUtils.normalizeWhitespace(element.getText());
- fLanguage =
UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.LANG_ATTRIBUTE,
Namespace.XML_NAMESPACE));
}
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=835686&r1=835685&r2=835686&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
Fri Nov 13 01:09:02 2009
@@ -18,28 +18,26 @@
import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
import org.apache.wookie.util.UnicodeUtils;
import org.jdom.Element;
-import org.jdom.Namespace;
/**
* @author Paul Sharples
* @version $Id: LicenseEntity.java,v 1.3 2009-09-02 18:37:31 scottwilson Exp $
*/
-public class LicenseEntity implements ILicenseEntity {
+public class LicenseEntity extends LocalizedEntity implements ILicenseEntity {
private String fLicenseText;
private String fHref;
- private String fLanguage;
public LicenseEntity(){
fLicenseText = "";
fHref = "";
- fLanguage = "";
+ setLanguage("");
}
public LicenseEntity(String licenseText, String href, String language) {
super();
fLicenseText = licenseText;
fHref = href;
- fLanguage = language;
+ setLanguage(language);
}
public String getLicenseText() {
@@ -58,25 +56,14 @@
fHref = href;
}
- public String getLanguage() {
- return fLanguage;
- }
-
- public void setLanguage(String language) {
- fLanguage = language;
- }
-
public String getXMLTagName() {
return IW3CXMLConfiguration.LICENSE_ELEMENT;
}
public void fromXML(Element element) {
+ super.fromXML(element);
fLicenseText =
UnicodeUtils.normalizeWhitespace(element.getText());
- fHref =
UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.HREF_ATTRIBUTE));
- fLanguage =
UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.LANG_ATTRIBUTE,
Namespace.XML_NAMESPACE));
- if(fLanguage.equals("")){
- fLanguage = IW3CXMLConfiguration.DEFAULT_LANG;
- }
+ fHref =
UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.HREF_ATTRIBUTE));
}
Added:
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/LocalizedEntity.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/LocalizedEntity.java?rev=835686&view=auto
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/LocalizedEntity.java
(added)
+++
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/LocalizedEntity.java
Fri Nov 13 01:09:02 2009
@@ -0,0 +1,29 @@
+package org.apache.wookie.manifestmodel.impl;
+
+import org.apache.wookie.manifestmodel.ILocalizedEntity;
+import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
+import org.apache.wookie.util.UnicodeUtils;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+
+public abstract class LocalizedEntity implements ILocalizedEntity {
+
+ private String language;
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.wookie.manifestmodel.IManifestModelBase#fromXML(org.jdom.Element)
+ */
+ public void fromXML(Element element) {
+ setLanguage(
UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.LANG_ATTRIBUTE,
Namespace.XML_NAMESPACE)));
+ }
+
+}
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=835686&r1=835685&r2=835686&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
Fri Nov 13 01:09:02 2009
@@ -18,28 +18,28 @@
import org.apache.wookie.manifestmodel.IW3CXMLConfiguration;
import org.apache.wookie.util.UnicodeUtils;
import org.jdom.Element;
-import org.jdom.Namespace;
+
/**
* @author Paul Sharples
* @version $Id: NameEntity.java,v 1.3 2009-09-02 18:37:31 scottwilson Exp $
*/
-public class NameEntity implements INameEntity {
+public class NameEntity extends LocalizedEntity implements INameEntity {
private String fName;
private String fShort;
- private String fLanguage;
+
public NameEntity(){
fName = "";
fShort = "";
- fLanguage = "";
+ setLanguage("");
}
public NameEntity(String name, String short1, String language) {
super();
fName = name;
fShort = short1;
- fLanguage = language;
+ setLanguage(language);
}
public String getName() {
@@ -58,23 +58,14 @@
fShort = short1;
}
- public String getLanguage() {
- return fLanguage;
- }
-
- public void setLanguage(String language) {
- fLanguage = language;
- }
-
public String getXMLTagName() {
return IW3CXMLConfiguration.NAME_ELEMENT;
}
- public void fromXML(Element element) {
+ public void fromXML(Element element) {
+ super.fromXML(element);
// Get the text value of name
fName = UnicodeUtils.normalizeWhitespace(element.getText());
- // Get the xml:lang attribute (if exists)
- fLanguage =
UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.LANG_ATTRIBUTE,
Namespace.XML_NAMESPACE));
// Get the short attribute (if exists)
fShort =
UnicodeUtils.normalizeSpaces(element.getAttributeValue(IW3CXMLConfiguration.SHORT_ATTRIBUTE));
}
Modified:
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/WidgetManifestModel.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/WidgetManifestModel.java?rev=835686&r1=835685&r2=835686&view=diff
==============================================================================
---
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/WidgetManifestModel.java
(original)
+++
incubator/wookie/trunk/src/org/apache/wookie/manifestmodel/impl/WidgetManifestModel.java
Fri Nov 13 01:09:02 2009
@@ -14,9 +14,12 @@
package org.apache.wookie.manifestmodel.impl;
+import java.io.IOException;
+import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.wookie.exceptions.BadManifestException;
@@ -27,6 +30,7 @@
import org.apache.wookie.manifestmodel.IFeatureEntity;
import org.apache.wookie.manifestmodel.IIconEntity;
import org.apache.wookie.manifestmodel.ILicenseEntity;
+import org.apache.wookie.manifestmodel.ILocalizedEntity;
import org.apache.wookie.manifestmodel.IManifestModel;
import org.apache.wookie.manifestmodel.INameEntity;
import org.apache.wookie.manifestmodel.IPreferenceEntity;
@@ -35,7 +39,9 @@
import org.apache.wookie.util.RandomGUID;
import org.apache.wookie.util.UnicodeUtils;
import org.jdom.Element;
+import org.jdom.JDOMException;
import org.jdom.Namespace;
+import org.jdom.input.SAXBuilder;
/**
* @author Paul Sharples
* @version $Id: WidgetManifestModel.java,v 1.3 2009-09-02 18:37:31
scottwilson Exp $
@@ -59,6 +65,8 @@
private IContentEntity fContent;
private List<IFeatureEntity> fFeaturesList;
private List<IPreferenceEntity> fPreferencesList;
+
+ private ZipFile zip;
public WidgetManifestModel() {
super();
@@ -71,6 +79,28 @@
fPreferencesList = new ArrayList<IPreferenceEntity>();
}
+ /**
+ * Constructs a new WidgetManifestModel using an XML manifest supplied
as a String.
+ * @param xmlText the XML manifest file
+ * @throws JDOMException
+ * @throws IOException
+ * @throws BadManifestException
+ */
+ public WidgetManifestModel (String xmlText, ZipFile zip) throws
JDOMException, IOException, BadManifestException {
+ super();
+ this.zip = zip;
+ fNamesList = new ArrayList<INameEntity>();
+ fDescriptionsList = new ArrayList<IDescriptionEntity>();
+ fLicensesList = new ArrayList<ILicenseEntity>();
+ fIconsList = new ArrayList<IIconEntity>();
+ fAccessList = new ArrayList<IAccessEntity>();
+ fFeaturesList = new ArrayList<IFeatureEntity>();
+ fPreferencesList = new ArrayList<IPreferenceEntity>();
+ SAXBuilder builder = new SAXBuilder();
+ Element root = builder.build(new
StringReader(xmlText)).getRootElement();
+ fromXML(root);
+ }
+
public String getViewModes() {
return fViewModes;
}
@@ -269,18 +299,16 @@
aName.fromXML(child);
// add it to our list only if its not a
repetition of an
// existing name for the locale
- boolean exists = false;
- for (INameEntity name: fNamesList.toArray(new
INameEntity[fNamesList.size()]))
- if
(StringUtils.equals(name.getLanguage(), aName.getLanguage())) exists = true;
- if (!exists) fNamesList.add(aName);
+ if (isFirstLocalizedEntity(fNamesList,aName))
fNamesList.add(aName);
}
// DESCRIPTION IS OPTIONAL multiple on xml:lang
if(tag.equals(IW3CXMLConfiguration.DESCRIPTION_ELEMENT)) {
IDescriptionEntity aDescription = new
DescriptionEntity();
aDescription.fromXML(child);
- // add it to our list
- fDescriptionsList.add(aDescription);
+ // add it to our list only if its not a
repetition of an
+ // existing description for the locale
+ if
(isFirstLocalizedEntity(fDescriptionsList,aDescription))
fDescriptionsList.add(aDescription);
}
// AUTHOR IS OPTIONAL - can only be one, ignore
subsequent repetitions
@@ -293,7 +321,9 @@
if(tag.equals(IW3CXMLConfiguration.LICENSE_ELEMENT)) {
ILicenseEntity aLicense = new LicenseEntity();
aLicense.fromXML(child);
- fLicensesList.add(aLicense);
+ // add it to our list only if its not a
repetition of an
+ // existing entry for the locale
+ if
(isFirstLocalizedEntity(fLicensesList,aLicense)) fLicensesList.add(aLicense);
}
// ICON IS OPTIONAL - can be many
@@ -312,11 +342,11 @@
}
// CONTENT IS OPTIONAL - can only be 0 or 1
- // Only the first CONTENT element should be considered,
further instances MUST be ignored
+ // Only the first valid CONTENT element should be
considered, further instances MUST be ignored
if(tag.equals(IW3CXMLConfiguration.CONTENT_ELEMENT)) {
if (fContent == null){
fContent = new ContentEntity();
- fContent.fromXML(child);
+ fContent.fromXML(child,zip);
}
}
@@ -337,4 +367,19 @@
}
}
+ /**
+ * Checks to see if the given list already contains an ILocalizedEntity
+ * with a language that matches that of the given entity. If it does,
then the
+ * method returns false.
+ * @param list a list of ILocalizedEntity instances
+ * @param ent an ILocalizedEntity
+ * @return true if the list contains an entity with matching language
+ */
+ @SuppressWarnings("unchecked")
+ private boolean isFirstLocalizedEntity(List list, ILocalizedEntity ent){
+ boolean first = true;
+ for (ILocalizedEntity entity:
(ILocalizedEntity[])list.toArray(new ILocalizedEntity[list.size()]))
+ if (StringUtils.equals(entity.getLanguage(),
ent.getLanguage())) first = false;
+ return first;
+ }
}
Modified: incubator/wookie/trunk/src/org/apache/wookie/server/Start.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/server/Start.java?rev=835686&r1=835685&r2=835686&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/server/Start.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/server/Start.java Fri Nov 13
01:09:02 2009
@@ -14,14 +14,11 @@
package org.apache.wookie.server;
-import java.io.BufferedReader;
-import java.io.FileReader;
import java.io.IOException;
-import java.net.URL;
import java.util.StringTokenizer;
+import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
-import org.apache.wookie.util.WidgetPackageUtils;
import org.apache.wookie.util.hibernate.DBManagerFactory;
import org.apache.wookie.util.hibernate.IDBManager;
import org.hibernate.SQLQuery;
@@ -48,7 +45,7 @@
*/
private static void configureDatabase() throws IOException {
logger.debug("Configuring Derby Database");
- String sqlScript =
WidgetPackageUtils.convertStreamToString(Start.class.getClassLoader().getResourceAsStream("widgetdb.sql"));
+ String sqlScript =
IOUtils.toString(Start.class.getClassLoader().getResourceAsStream("widgetdb.sql"));
final IDBManager dbManager = DBManagerFactory.getDBManager();
Modified:
incubator/wookie/trunk/src/org/apache/wookie/util/WidgetPackageUtils.java
URL:
http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/WidgetPackageUtils.java?rev=835686&r1=835685&r2=835686&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/WidgetPackageUtils.java
(original)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/WidgetPackageUtils.java
Fri Nov 13 01:09:02 2009
@@ -13,13 +13,12 @@
*/
package org.apache.wookie.util;
+import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
@@ -33,8 +32,9 @@
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadBase;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
-import org.apache.wookie.Messages;
import org.apache.wookie.exceptions.BadManifestException;
import org.apache.wookie.exceptions.BadWidgetZipFileException;
import org.apache.wookie.manifestmodel.IManifestModel;
@@ -48,8 +48,6 @@
public class WidgetPackageUtils {
static Logger _logger =
Logger.getLogger(WidgetPackageUtils.class.getName());
- public static final String[] START_FILES =
{"index.htm","index.html","index.svg","index.xhtml","index.xht"};
-
/**
* Identify the start file for a given zipfile and manifest, or throw
an exception
* @param widgetModel
@@ -59,29 +57,24 @@
* @throws BadWidgetZipFileException if a custom start file is
specified, but is not present
* @throws BadManifestException if no custom start file is found, and
no default start file can be located
*/
- public static String locateStartFile(IManifestModel widgetModel,
ZipFile zip, Messages localizedMessages) throws BadWidgetZipFileException,
BadManifestException{
+ public static String locateStartFile(IManifestModel widgetModel,
ZipFile zip) throws BadWidgetZipFileException, BadManifestException{
String startFile = null;
// Check for a custom start file
if (widgetModel.getContent() != null) {
- if (widgetModel.getContent().getSrc() != null){
- startFile = widgetModel.getContent().getSrc();
- // Check that the specified custom start file
exists
- if (zip.getEntry(startFile)==null){
- startFile = null;
- throw new
BadWidgetZipFileException(localizedMessages.getString("WidgetAdminServlet.22"));
//$NON-NLS-1$
- }
+ if (widgetModel.getContent().getSrc() != null &&
!widgetModel.getContent().getSrc().equals("")){
+ return widgetModel.getContent().getSrc();
}
}
// If no custom start file exists, look for defaults
- for (String s: START_FILES){
+ for (String s: IW3CXMLConfiguration.START_FILES){
if (startFile == null && zip.getEntry(s)!=null){
startFile = s;
}
}
// If no start file has been found, throw an exception
if (startFile == null)
- throw new
BadManifestException("WidgetAdminServlet.27"); //$NON-NLS-1$
+ throw new BadManifestException(); //$NON-NLS-1$
return startFile;
}
@@ -166,37 +159,14 @@
File pFolder = new File(convertPathToPlatform(serverPath));
try {
_logger.debug("Deleting
folder:"+pFolder.getCanonicalFile().toString()); //$NON-NLS-1$
- deleteDirectory(pFolder);
+ if (pFolder.getParent() != null) // never call on a
root folder
+ FileUtils.deleteDirectory(pFolder);
}
catch (Exception ex) {
_logger.error(ex);
}
return true;
}
-
- /**
- * Recursive delete of a folder
- * Based on a how-to article by Ral Gagnon at
http://www.rgagnon.com/javadetails/java-0483.html
- * @param path the directory to delete
- * @return true if the directory was deleted
- * @throws IOException
- */
- private static boolean deleteDirectory(File path) throws IOException{
- if( path.exists() ) {
- // This should never be called with a root folder
- assert path.getParentFile()!=null;
- File[] files = path.listFiles();
- for(int i=0; i<files.length; i++) {
- if(files[i].isDirectory()) {
- deleteDirectory(files[i]);
- }
- else {
- files[i].delete();
- }
- }
- }
- return( path.delete() );
- }
/**
* Checks for the existence of the Manifest.
@@ -216,8 +186,7 @@
*/
public static String extractManifest(ZipFile zipFile) throws
IOException{
ZipArchiveEntry entry =
zipFile.getEntry(IW3CXMLConfiguration.MANIFEST_FILE);
- InputStream content = zipFile.getInputStream(entry);
- return convertStreamToString(content);
+ return IOUtils.toString(zipFile.getInputStream(entry));
}
/**
@@ -236,9 +205,6 @@
BufferedOutputStream out = null;
InputStream in = null;
ZipArchiveEntry zipEntry;
- int bytesRead;
- final int bufSize = 512;
- byte buf[] = new byte[bufSize];
Enumeration entries = zipfile.getEntries();
try {
@@ -253,15 +219,13 @@
outFile.getParentFile().mkdirs();
}
// Read the entry
- in = zipfile.getInputStream(zipEntry);
- out = new BufferedOutputStream(new
FileOutputStream(outFile), bufSize);
- while((bytesRead = in.read(buf)) != -1)
{
- out.write(buf, 0, bytesRead);
- }
+ in = new
BufferedInputStream(zipfile.getInputStream(zipEntry));
+ out = new BufferedOutputStream(new
FileOutputStream(outFile));
+ IOUtils.copy(in, out);
// Restore time stamp
outFile.setLastModified(zipEntry.getTime());
+
// Close File
- out.flush();
out.close();
// Close Stream
in.close();
@@ -282,37 +246,4 @@
throw ex;
}
}
-
- /**
- * Taken from an example at http://www.kodejava.org/examples/266.html
- * @param is the InputStream to convert
- * @return a String representing the content of the Stream
- */
- public static String convertStreamToString(InputStream is) {
- /*
- * To convert the InputStream to String we use the
BufferedReader.readLine()
- * method. We iterate until the BufferedReader return null
which means
- * there's no more data to read. Each line will appended to a
StringBuilder
- * and returned as String.
- */
- BufferedReader reader = new BufferedReader(new
InputStreamReader(is));
- StringBuilder sb = new StringBuilder();
-
- String line = null;
- try {
- while ((line = reader.readLine()) != null) {
- sb.append(line + "\n");
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- return sb.toString();
- }
}