From: <car...@us...> - 2010-08-26 14:39:15
|
Revision: 2906 http://openutils.svn.sourceforge.net/openutils/?rev=2906&view=rev Author: carlocolombo Date: 2010-08-26 14:38:38 +0000 (Thu, 26 Aug 2010) Log Message: ----------- Magnolia Mobile Module Added Paths: ----------- trunk/openutils-mgnlmobile/ trunk/openutils-mgnlmobile/pom.xml trunk/openutils-mgnlmobile/src/ trunk/openutils-mgnlmobile/src/main/ trunk/openutils-mgnlmobile/src/main/assembly/ trunk/openutils-mgnlmobile/src/main/assembly/assembly-bundle.xml trunk/openutils-mgnlmobile/src/main/etc/ trunk/openutils-mgnlmobile/src/main/etc/header.txt trunk/openutils-mgnlmobile/src/main/java/ trunk/openutils-mgnlmobile/src/main/java/net/ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/DefaultMobileWURFLManager.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/MobileFilter.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/MobileWURFLManager.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/magnolia/ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/magnolia/MobileModule.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/magnolia/MobileModuleVersionHandler.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/DevicePreview.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/MobilePreviewManager.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/MobilePreviewPage.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/tags/ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/tags/MobilePreviewButton.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/tags/MobilePreviewButtonTag.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/BaseMobileParagraphDecorator.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/BaseMobileTemplateDecorator.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/DefaultMobileParagraph.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/DefaultMobileParagraphDecorator.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/DefaultMobileTemplate.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/DefaultMobileTemplateDecorator.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/MobileParagraph.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/MobileParagraphManager.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/MobileTemplate.java trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/MobileTemplateManager.java trunk/openutils-mgnlmobile/src/main/resources/ trunk/openutils-mgnlmobile/src/main/resources/META-INF/ trunk/openutils-mgnlmobile/src/main/resources/META-INF/magnolia/ trunk/openutils-mgnlmobile/src/main/resources/META-INF/magnolia/mgnlmobile.xml trunk/openutils-mgnlmobile/src/main/resources/META-INF/mgnlmobile.tld trunk/openutils-mgnlmobile/src/main/resources/mgnl-bootstrap/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-bootstrap/mobile/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-bootstrap/mobile/config.modules.adminInterface.pages.mobilePreview.xml trunk/openutils-mgnlmobile/src/main/resources/mgnl-bootstrap/mobile/config.modules.mobile.devices-preview.apple_ipad_ver1.xml trunk/openutils-mgnlmobile/src/main/resources/mgnl-bootstrap/mobile/config.modules.mobile.devices-preview.apple_iphone_ver3.xml trunk/openutils-mgnlmobile/src/main/resources/mgnl-bootstrap/mobile/config.server.filters.mobile.xml trunk/openutils-mgnlmobile/src/main/resources/mgnl-bootstrap-samples/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-bootstrap-samples/mobile/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-bootstrap-samples/mobile/config.modules.mobile.dialogs.p-sample-mobile.xml trunk/openutils-mgnlmobile/src/main/resources/mgnl-bootstrap-samples/mobile/config.modules.mobile.paragraphs.p-sample-mobile.xml trunk/openutils-mgnlmobile/src/main/resources/mgnl-bootstrap-samples/mobile/config.modules.mobile.templates.sample-mobile.xml trunk/openutils-mgnlmobile/src/main/resources/mgnl-bootstrap-samples/mobile/website.sample-mobile.xml trunk/openutils-mgnlmobile/src/main/resources/mgnl-files/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-files/templates/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-files/templates/samples-mobile/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-files/templates/samples-mobile/index-ipad.jsp trunk/openutils-mgnlmobile/src/main/resources/mgnl-files/templates/samples-mobile/index-mobile.jsp trunk/openutils-mgnlmobile/src/main/resources/mgnl-files/templates/samples-mobile/index.jsp trunk/openutils-mgnlmobile/src/main/resources/mgnl-files/templates/samples-mobile/p-sample-ipad.jsp trunk/openutils-mgnlmobile/src/main/resources/mgnl-files/templates/samples-mobile/p-sample-mobile.jsp trunk/openutils-mgnlmobile/src/main/resources/mgnl-files/templates/samples-mobile/p-sample.jsp trunk/openutils-mgnlmobile/src/main/resources/mgnl-messages/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-messages/mobile/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-messages/mobile/messages_en.properties trunk/openutils-mgnlmobile/src/main/resources/mgnl-messages/mobile/messages_it.properties trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/SqueezeBox.css trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/img/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/img/bg_e.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/img/bg_n.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/img/bg_ne.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/img/bg_nw.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/img/bg_s.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/img/bg_se.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/img/bg_sw.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/img/bg_w.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/img/closebox.gif trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/img/closebox.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/img/spinner.gif trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/css/preview.css trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/images/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/images/24_iphone.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/images/IPhoneEmulator_3.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/images/ipad-landscape.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/images/ipad.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/images/iphone-interface.jpg trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/images/iphone_ver.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/images/iphone_ver_bars.png trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/js/ trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/js/SqueezeBox.js trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/js/button.js trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/js/preview.js trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/web_browsers_patch.xml trunk/openutils-mgnlmobile/src/main/resources/mgnl-resources/mgnlmobile/wurfl-2.0.18.xml.gz trunk/openutils-mgnlmobile/src/main/resources/net/ trunk/openutils-mgnlmobile/src/main/resources/net/sourceforge/ trunk/openutils-mgnlmobile/src/main/resources/net/sourceforge/openutils/ trunk/openutils-mgnlmobile/src/main/resources/net/sourceforge/openutils/mgnlmobile/ trunk/openutils-mgnlmobile/src/main/resources/net/sourceforge/openutils/mgnlmobile/lang/ trunk/openutils-mgnlmobile/src/main/resources/net/sourceforge/openutils/mgnlmobile/lang/messages_en.properties trunk/openutils-mgnlmobile/src/main/resources/net/sourceforge/openutils/mgnlmobile/preview/ trunk/openutils-mgnlmobile/src/main/resources/net/sourceforge/openutils/mgnlmobile/preview/MobilePreviewPage.html Property changes on: trunk/openutils-mgnlmobile ___________________________________________________________________ Added: svn:ignore + target Added: trunk/openutils-mgnlmobile/pom.xml =================================================================== --- trunk/openutils-mgnlmobile/pom.xml (rev 0) +++ trunk/openutils-mgnlmobile/pom.xml 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,134 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-parent</artifactId> + <version>1.5</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <packaging>jar</packaging> + <artifactId>openutils-mgnlmobile</artifactId> + <name>Magnolia - Mobile Module</name> + <version>0.0.1-SNAPSHOT</version> + <inceptionYear>2010</inceptionYear> + <licenses> + <license> + <name>GPLv3</name> + <url>http://www.gnu.org/licenses/gpl-3.0.txt</url> + </license> + </licenses> + <url>http://www.openmindlab.com/lab/products.html</url> + <issueManagement> + <system>jira</system> + <url>http://jira.openmindlab.com/browse/</url> + </issueManagement> + <scm> + <connection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/trunk/openutils-mgnlmobile</connection> + <developerConnection>scm:svn:https://openutils.svn.sourceforge.net/svnroot/openutils/trunk/openutils-mgnlmobile</developerConnection> + <url>http://openutils.svn.sourceforge.net/viewcvs.cgi/openutils/trunk/openutils-mgnlmobile</url> + </scm> + <build> + <resources> + <resource> + <filtering>false</filtering> + <directory>src/main/resources</directory> + <includes> + <include>**/*</include> + </includes> + </resource> + <resource> + <filtering>true</filtering> + <directory>src/main/resources</directory> + <includes> + <include>META-INF/magnolia/*</include> + </includes> + </resource> + </resources> + </build> + <reporting> + <plugins> + <plugin> + <groupId>net.sourceforge.maven-taglib</groupId> + <artifactId>maven-taglib-plugin</artifactId> + <version>2.4</version> + <configuration> + <parseHtml>true</parseHtml> + <dontRecurseIntoSubdirs>true</dontRecurseIntoSubdirs> + </configuration> + </plugin> + <plugin> + <artifactId>maven-changes-plugin</artifactId> + <version>2.3</version> + <reportSets> + <reportSet> + <reports> + <report>jira-report</report> + </reports> + </reportSet> + </reportSets> + </plugin> + </plugins> + </reporting> + <dependencies> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-core</artifactId> + <version>${magnolia.version}</version> + <exclusions> + <exclusion> + <groupId>commons-pool</groupId> + <artifactId>commons-pool</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-module-admininterface</artifactId> + <version>${magnolia.version}</version> + </dependency> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-taglib-cms</artifactId> + <version>${magnolia.version}</version> + </dependency> + <dependency> + <groupId>info.magnolia</groupId> + <artifactId>magnolia-gui</artifactId> + <version>${magnolia.version}</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>jsp-api</artifactId> + <version>2.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-log4j</artifactId> + <version>2.0.5</version> + </dependency> + <dependency> + <groupId>net.sourceforge.openutils</groupId> + <artifactId>openutils-mgnltasks</artifactId> + <version>4.1.2</version> + </dependency> + <dependency> + <groupId>net.sourceforge.wurfl</groupId> + <artifactId>wurfl</artifactId> + <version>1.0.1</version> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring-support</artifactId> + </exclusion> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <properties> + <magnolia.version>4.3.1</magnolia.version> + </properties> +</project> Added: trunk/openutils-mgnlmobile/src/main/assembly/assembly-bundle.xml =================================================================== --- trunk/openutils-mgnlmobile/src/main/assembly/assembly-bundle.xml (rev 0) +++ trunk/openutils-mgnlmobile/src/main/assembly/assembly-bundle.xml 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,33 @@ +<assembly> + <id>bundle</id> + <formats> + <format>zip</format> + </formats> + <includeBaseDirectory>false</includeBaseDirectory> + <fileSets> + <fileSet> + <filtered>true</filtered> + <outputDirectory>/</outputDirectory> + <lineEnding>crlf</lineEnding> + <directory>${basedir}/src/main/bundle</directory> + <includes> + <include>*</include> + </includes> + </fileSet> + <fileSet> + <directory>src/main/java/</directory> + <outputDirectory>/sources/</outputDirectory> + <includes> + <include>**/*</include> + </includes> + </fileSet> + </fileSets> + <dependencySets> + <dependencySet> + <outputDirectory>bin</outputDirectory> + <includes> + <include>net.sourceforge.openutils:*</include> + </includes> + </dependencySet> + </dependencySets> +</assembly> Added: trunk/openutils-mgnlmobile/src/main/etc/header.txt =================================================================== --- trunk/openutils-mgnlmobile/src/main/etc/header.txt (rev 0) +++ trunk/openutils-mgnlmobile/src/main/etc/header.txt 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,16 @@ + +${name} (${url}) +Copyright(C) ${year}, Openmind S.r.l. http://www.openmindonline.it + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. \ No newline at end of file Added: trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/DefaultMobileWURFLManager.java =================================================================== --- trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/DefaultMobileWURFLManager.java (rev 0) +++ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/DefaultMobileWURFLManager.java 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,122 @@ +/** + * + * Magnolia - Mobile Module (http://www.openmindlab.com/lab/products.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmobile.filters; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import net.sourceforge.wurfl.core.CustomWURFLHolder; +import net.sourceforge.wurfl.core.WURFLHolder; +import net.sourceforge.wurfl.core.WURFLManager; +import net.sourceforge.wurfl.core.WURFLUtils; +import net.sourceforge.wurfl.core.resource.WURFLResource; +import net.sourceforge.wurfl.core.resource.WURFLResources; +import net.sourceforge.wurfl.core.resource.XMLResource; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author molaschi + * @version $Id: $ + */ +public class DefaultMobileWURFLManager implements MobileWURFLManager +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(DefaultMobileWURFLManager.class); + + private WURFLHolder wurflHolder; + + public DefaultMobileWURFLManager() + { + String mainPath = "/mgnl-resources/mgnlmobile/wurfl-2.0.18.xml.gz"; + File fileMain = getResource(mainPath, "wurfl", ".xml.gz"); + if (fileMain != null) + { + WURFLResource root = new XMLResource(fileMain); + WURFLResources patches = new WURFLResources(); + String[] patchesPath = new String[]{"/mgnl-resources/mgnlmobile/web_browsers_patch.xml" }; + for (int index = 0; index < patchesPath.length; index++) + { + File filePatch = getResource(patchesPath[index], "web_browsers_patch", ".xml"); + if (filePatch != null) + { + WURFLResource patch = new XMLResource(filePatch); + patches.add(patch); + } + else + { + log.error("Error on reading file: " + filePatch); + } + } + wurflHolder = new CustomWURFLHolder(root, patches); + } + else + { + log.error("Error on reading file: " + mainPath); + } + } + + protected File getResource(String name, String prefix, String suffix) + { + File fileTemp = null; + try + { + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( + StringUtils.removeStart(name, "/")); + fileTemp = File.createTempFile(prefix, suffix); + fileTemp.deleteOnExit(); + OutputStream fos = new FileOutputStream(fileTemp); + IOUtils.copy(is, fos); + IOUtils.closeQuietly(fos); + } + catch (IOException e) + { + log.error("Error on reading file: " + name, e); + } + return fileTemp; + } + + /** + * {@inheritDoc} + */ + public WURFLManager getWURFLManager() + { + return wurflHolder.getWURFLManager(); + } + + /** + * {@inheritDoc} + */ + public WURFLUtils getWURFLUtils() + { + return wurflHolder.getWURFLUtils(); + } + +} Added: trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/MobileFilter.java =================================================================== --- trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/MobileFilter.java (rev 0) +++ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/MobileFilter.java 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,225 @@ +/** + * + * Magnolia - Mobile Module (http://www.openmindlab.com/lab/products.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmobile.filters; + +import info.magnolia.cms.filters.InterceptFilter; +import info.magnolia.cms.filters.OncePerRequestAbstractMgnlFilter; +import info.magnolia.context.MgnlContext; +import info.magnolia.objectfactory.Components; + +import java.io.IOException; + +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.sourceforge.wurfl.core.Device; +import net.sourceforge.wurfl.core.DeviceNotDefinedException; +import net.sourceforge.wurfl.core.MarkUp; +import net.sourceforge.wurfl.core.WURFLManager; + +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author Luca Boati + * @version $Id: $ + */ +public class MobileFilter extends OncePerRequestAbstractMgnlFilter +{ + + private static final String DEVICE_ID = "mgnlDeviceId"; + + private static final String DEVICE = "mgnlDevice"; + + private static final String MARKUP = "mgnlMarkup"; + + private static final String IS_MOBILE = "mgnlIsMobile"; + + private static final String IS_MOBILE_ACTIVE = "mgnlMobileActive"; + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(MobileFilter.class); + + private MobileWURFLManager mobileWURFLManager; + + public static boolean isMobileRequest() + { + return MgnlContext.isWebContext() && BooleanUtils.isTrue((Boolean) MgnlContext.getWebContext().getRequest().getAttribute(IS_MOBILE)); + } + + public static boolean isActive() + { + return MgnlContext.isWebContext() && BooleanUtils.isTrue((Boolean) MgnlContext.getWebContext().getRequest().getAttribute(IS_MOBILE_ACTIVE)); + } + + public static Device getDevice() + { + return (Device) MgnlContext.getWebContext().getRequest().getAttribute(DEVICE); + } + + public static Device getMarkUp() + { + return (Device) MgnlContext.getWebContext().getRequest().getAttribute(MARKUP); + } + + /** + * {@inheritDoc} + */ + @Override + public void init(FilterConfig filterConfig) throws ServletException + { + if (this.isEnabled()) + { + super.init(filterConfig); + + if (mobileWURFLManager == null) + { + mobileWURFLManager = Components.getComponentProvider().newInstance(MobileWURFLManager.class); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) + throws IOException, ServletException + { + if (mobileWURFLManager != null) + { + request.setAttribute(IS_MOBILE_ACTIVE, true); + WURFLManager wurfl = mobileWURFLManager.getWURFLManager(); + try + { + // check if device is forced + Device device = getDeviceFromParameterOrSession(request); + + // try to get it from request + if (device == null) + { + device = wurfl.getDeviceForRequest(request); + } + + if (device != null) + { + // log capabilities + log.debug("Device: " + device.getId()); + if (log.isDebugEnabled() && MapUtils.isNotEmpty(device.getCapabilities())) + { + log.debug("Device capabilities:"); + for (Object key : device.getCapabilities().keySet()) + { + log.debug("{}: {}", new Object[]{key, device.getCapabilities().get(key) }); + } + } + + // Markup + MarkUp markUp = device.getMarkUp(); + log.debug("MarkUp: " + markUp); + + request.setAttribute(MARKUP, markUp); + request.setAttribute(DEVICE, device); + + // check if it is mobile + if (StringUtils.isNotBlank(device.getCapability("mobile_browser"))) + { + request.setAttribute(IS_MOBILE, true); + } + } + } + catch (DeviceNotDefinedException e) + { + log.warn(e.getMessage()); + } + + // request.getRequestDispatcher("WEB-INF/jsp/" + jspView).forward(request, response); + } + chain.doFilter(request, response); + } + + public Device getDeviceFromParameterOrSession(HttpServletRequest request) + { + // if preview is closing remove device from session (if present) + if (StringUtils.isNotBlank(request.getParameter(InterceptFilter.INTERCEPT)) + && "preview".equalsIgnoreCase(request.getParameter(InterceptFilter.INTERCEPT)) + && "false".equalsIgnoreCase(request.getParameter("mgnlPreview")) + && request.getSession(true).getAttribute(DEVICE_ID) != null) + { + request.getSession().removeAttribute(DEVICE_ID); + return null; + } + + String deviceId = null; + // check if it is forced and start preview Session + if (StringUtils.isNotBlank(request.getParameter(DEVICE_ID)) + && request.getSession(true).getAttribute(DEVICE_ID) == null) + { + deviceId = request.getParameter(DEVICE_ID); + if (mobileWURFLManager.getWURFLUtils().isDeviceDefined(deviceId)) + { + log.debug("Forced device with id: {}", deviceId); + request.getSession(true).setAttribute(DEVICE_ID, deviceId); + } + else + { + log.warn("Cannot find device with id {}", deviceId); + return null; + } + } + if (StringUtils.isBlank(deviceId)) + { + deviceId = (String) request.getSession(true).getAttribute(DEVICE_ID); + } + if (StringUtils.isNotBlank(deviceId)) + { + return mobileWURFLManager.getWURFLUtils().getDeviceById(deviceId); + } + return null; + } + + /** + * Returns the mobileWURFLManager. + * @return the mobileWURFLManager + */ + public MobileWURFLManager getMobileWURFLManager() + { + return mobileWURFLManager; + } + + /** + * Sets the mobileWURFLManager. + * @param mobileWURFLManager the mobileWURFLManager to set + */ + public void setMobileWURFLManager(MobileWURFLManager mobileWURFLManager) + { + this.mobileWURFLManager = mobileWURFLManager; + } + +} Added: trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/MobileWURFLManager.java =================================================================== --- trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/MobileWURFLManager.java (rev 0) +++ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/filters/MobileWURFLManager.java 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,36 @@ +/** + * + * Magnolia - Mobile Module (http://www.openmindlab.com/lab/products.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmobile.filters; + +import net.sourceforge.wurfl.core.WURFLManager; +import net.sourceforge.wurfl.core.WURFLUtils; + + +/** + * @author molaschi + * @version $Id: $ + */ +public interface MobileWURFLManager +{ + + WURFLManager getWURFLManager(); + + WURFLUtils getWURFLUtils(); +} Added: trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/magnolia/MobileModule.java =================================================================== --- trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/magnolia/MobileModule.java (rev 0) +++ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/magnolia/MobileModule.java 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,49 @@ +/** + * + * Magnolia - Mobile Module (http://www.openmindlab.com/lab/products.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmobile.magnolia; + +import net.sourceforge.openutils.mgnlmobile.preview.MobilePreviewManager; +import info.magnolia.module.ModuleLifecycle; +import info.magnolia.module.ModuleLifecycleContext; + + +/** + * @author molaschi + * @version $Id: $ + */ +public class MobileModule implements ModuleLifecycle +{ + + /** + * {@inheritDoc} + */ + public void start(ModuleLifecycleContext moduleLifecycleContext) + { + moduleLifecycleContext.registerModuleObservingComponent("devices-preview", MobilePreviewManager.getInstance()); + } + + /** + * {@inheritDoc} + */ + public void stop(ModuleLifecycleContext moduleLifecycleContext) + { + } + +} Added: trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/magnolia/MobileModuleVersionHandler.java =================================================================== --- trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/magnolia/MobileModuleVersionHandler.java (rev 0) +++ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/magnolia/MobileModuleVersionHandler.java 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,60 @@ +/** + * + * Magnolia - Mobile Module (http://www.openmindlab.com/lab/products.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmobile.magnolia; + +import info.magnolia.cms.core.SystemProperty; +import info.magnolia.module.InstallContext; +import info.magnolia.module.delta.FilterOrderingTask; +import info.magnolia.module.delta.Task; +import it.openutils.mgnltasks.SamplesExtractionTask; +import it.openutils.mgnltasks.SimpleModuleVersionHandler; + +import java.util.ArrayList; +import java.util.List; + + +/** + * @author Luca Boati + */ +public class MobileModuleVersionHandler extends SimpleModuleVersionHandler +{ + + /** + * {@inheritDoc} + */ + @Override + public List<Task> getStartupTasks(InstallContext installContext) + { + + List<Task> tasks = new ArrayList<Task>(); + // WURFL + tasks.add(new FilterOrderingTask("mobile", "Mobile filter after unicodeNormalization", new String[]{ + "multipartRequest", + "unicodeNormalization" })); + + if (SystemProperty.getBooleanProperty(SystemProperty.MAGNOLIA_BOOTSTRAP_SAMPLES)) + { + tasks.add(new SamplesExtractionTask()); + } + + return tasks; + } + +} Added: trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/DevicePreview.java =================================================================== --- trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/DevicePreview.java (rev 0) +++ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/DevicePreview.java 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,217 @@ +/** + * + * Magnolia - Mobile Module (http://www.openmindlab.com/lab/products.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmobile.preview; + +/** + * @author molaschi + * @version $Id: $ + */ +public class DevicePreview +{ + + private String deviceId; + + private String deviceDescription; + + private int previewWidth; + + private int previewHeight; + + private int screenWidth; + + private int screenHeight; + + private int screenTop = -1; + + private int screenLeft = -1; + + private String previewImage; + + /** + * Returns the deviceId. + * @return the deviceId + */ + public String getDeviceId() + { + return deviceId; + } + + /** + * Sets the deviceId. + * @param deviceId the deviceId to set + */ + public void setDeviceId(String deviceId) + { + this.deviceId = deviceId; + } + + /** + * Returns the previewWidth. + * @return the previewWidth + */ + public int getPreviewWidth() + { + return previewWidth; + } + + /** + * Sets the previewWidth. + * @param previewWidth the previewWidth to set + */ + public void setPreviewWidth(int previewWidth) + { + this.previewWidth = previewWidth; + } + + /** + * Returns the previewHeight. + * @return the previewHeight + */ + public int getPreviewHeight() + { + return previewHeight; + } + + /** + * Sets the previewHeight. + * @param previewHeight the previewHeight to set + */ + public void setPreviewHeight(int previewHeight) + { + this.previewHeight = previewHeight; + } + + /** + * Returns the screenWidth. + * @return the screenWidth + */ + public int getScreenWidth() + { + return screenWidth; + } + + /** + * Sets the screenWidth. + * @param screenWidth the screenWidth to set + */ + public void setScreenWidth(int screenWidth) + { + this.screenWidth = screenWidth; + } + + /** + * Returns the screenHeight. + * @return the screenHeight + */ + public int getScreenHeight() + { + return screenHeight; + } + + /** + * Sets the screenHeight. + * @param screenHeight the screenHeight to set + */ + public void setScreenHeight(int screenHeight) + { + this.screenHeight = screenHeight; + } + + /** + * Returns the screenTop. + * @return the screenTop + */ + public int getScreenTop() + { + if (screenTop == -1) + { + screenTop = (previewHeight - screenHeight) / 2; + } + return screenTop; + } + + /** + * Sets the screenTop. + * @param screenTop the screenTop to set + */ + public void setScreenTop(int screenTop) + { + this.screenTop = screenTop; + } + + /** + * Returns the screenLeft. + * @return the screenLeft + */ + public int getScreenLeft() + { + if (screenLeft == -1) + { + screenLeft = (previewWidth - screenWidth) / 2; + } + return screenLeft; + } + + /** + * Sets the screenLeft. + * @param screenLeft the screenLeft to set + */ + public void setScreenLeft(int screenLeft) + { + this.screenLeft = screenLeft; + } + + /** + * Returns the previewImage. + * @return the previewImage + */ + public String getPreviewImage() + { + return previewImage; + } + + /** + * Sets the previewImage. + * @param previewImage the previewImage to set + */ + public void setPreviewImage(String previewImage) + { + this.previewImage = previewImage; + } + + /** + * Returns the deviceDescription. + * @return the deviceDescription + */ + public String getDeviceDescription() + { + return deviceDescription; + } + + /** + * Sets the deviceDescription. + * @param deviceDescription the deviceDescription to set + */ + public void setDeviceDescription(String deviceDescription) + { + this.deviceDescription = deviceDescription; + } + +} Added: trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/MobilePreviewManager.java =================================================================== --- trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/MobilePreviewManager.java (rev 0) +++ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/MobilePreviewManager.java 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,112 @@ +/** + * + * Magnolia - Mobile Module (http://www.openmindlab.com/lab/products.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmobile.preview; + +import info.magnolia.cms.beans.config.ObservedManager; +import info.magnolia.cms.core.Content; +import info.magnolia.cms.util.ContentUtil; +import info.magnolia.content2bean.Content2BeanException; +import info.magnolia.content2bean.Content2BeanUtil; +import info.magnolia.objectfactory.Components; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author molaschi + * @version $Id: $ + */ +public class MobilePreviewManager extends ObservedManager +{ + + public static MobilePreviewManager getInstance() + { + return Components.getSingleton(MobilePreviewManager.class); + } + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(MobilePreviewManager.class); + + private Map<String, DevicePreview> devices = new HashMap<String, DevicePreview>(); + + /** + * {@inheritDoc} + */ + @Override + protected void onClear() + { + devices.clear(); + } + + /** + * {@inheritDoc} + */ + @Override + protected void onRegister(Content node) + { + for (Content deviceNode : ContentUtil.collectAllChildren(node)) + { + String deviceId = deviceNode.getName(); + DevicePreview device; + try + { + device = (DevicePreview) Content2BeanUtil.toBean(deviceNode, DevicePreview.class); + if (StringUtils.isBlank(device.getDeviceId())) + { + device.setDeviceId(deviceId); + } + devices.put(device.getDeviceId(), device); + } + catch (Content2BeanException e) + { + log.error("Error converting node {} to DevicePreview", e); + } + } + } + + public DevicePreview getDeviceById(String deviceId) + { + DevicePreview devicePreview = devices.get(deviceId); + if (devicePreview == null) + { + // get first one + for (DevicePreview dp : devices.values()) + { + devicePreview = dp; + break; + } + } + return devicePreview; + } + + public Collection<DevicePreview> getDevicesList() + { + return devices.values(); + } + +} Added: trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/MobilePreviewPage.java =================================================================== --- trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/MobilePreviewPage.java (rev 0) +++ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/preview/MobilePreviewPage.java 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,117 @@ +/** + * + * Magnolia - Mobile Module (http://www.openmindlab.com/lab/products.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmobile.preview; + +import info.magnolia.module.admininterface.TemplatedMVCHandler; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import net.sourceforge.openutils.mgnlmobile.filters.MobileFilter; + + +/** + * @author molaschi + * @version $Id: $ + */ +public class MobilePreviewPage extends TemplatedMVCHandler +{ + + private String deviceId; + + private String url; + + private DevicePreview device; + + /** + * @param name + * @param request + * @param response + */ + public MobilePreviewPage(String name, HttpServletRequest request, HttpServletResponse response) + { + super(name, request, response); + } + + /** + * {@inheritDoc} + */ + @Override + public String show() + { + device = MobilePreviewManager.getInstance().getDeviceById(MobileFilter.getDevice().getId()); + return super.show(); + } + + /** + * Returns the deviceId. + * @return the deviceId + */ + public String getDeviceId() + { + return deviceId; + } + + /** + * Sets the deviceId. + * @param deviceId the deviceId to set + */ + public void setDeviceId(String deviceId) + { + this.deviceId = deviceId; + } + + /** + * Returns the device. + * @return the device + */ + public DevicePreview getDevice() + { + return device; + } + + /** + * Sets the device. + * @param device the device to set + */ + public void setDevice(DevicePreview device) + { + this.device = device; + } + + /** + * Returns the url. + * @return the url + */ + public String getUrl() + { + return url; + } + + /** + * Sets the url. + * @param url the url to set + */ + public void setUrl(String url) + { + this.url = url; + } + +} Added: trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/tags/MobilePreviewButton.java =================================================================== --- trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/tags/MobilePreviewButton.java (rev 0) +++ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/tags/MobilePreviewButton.java 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,105 @@ +/** + * + * Magnolia - Mobile Module (http://www.openmindlab.com/lab/products.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmobile.tags; + +import info.magnolia.cms.gui.control.Button; +import net.sourceforge.openutils.mgnlmobile.preview.DevicePreview; +import net.sourceforge.openutils.mgnlmobile.preview.MobilePreviewManager; + +import org.apache.commons.lang.StringUtils; + + +/** + * @author molaschi + * @version $Id: $ + */ +public class MobilePreviewButton extends Button +{ + + private static final String JS_INCLUDED = "mobileJsPreviewIncluded"; + + /** + * {@inheritDoc} + */ + @Override + public String getHtml() + { + StringBuffer sb = new StringBuffer(); + if (this.getRequest().getAttribute(JS_INCLUDED) == null) + { + sb + .append("<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/mootools/1.2.2/mootools-yui-compressed.js\"><!-- --></script>"); + sb.append("<script type=\"text/javascript\" src=\"" + + this.getRequest().getContextPath() + + "/.resources/mgnlmobile/js/SqueezeBox.js\"><!-- --></script>"); + sb.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + + this.getRequest().getContextPath() + + "/.resources/mgnlmobile/css/SqueezeBox.css\" />"); + sb.append("<script type=\"text/javascript\" src=\"" + + this.getRequest().getContextPath() + + "/.resources/mgnlmobile/js/button.js\"><!-- --></script>"); + this.getRequest().setAttribute(JS_INCLUDED, true); + // sb.append("<div id=\"MB_PREVIEW_OL\" style=\"background: #999;position:absolute;top:0px;left:0px;width:100%;height:100%;z-index:10000;display:none\"></div>"); + } + sb + .append("<span class=\"mgnlControlButton\" style=\" cursor: pointer; padding-left:24px !important; background: transparent url(" + + this.getRequest().getContextPath() + + "/.resources/mgnlmobile/images/24_iphone.png) no-repeat top left;\" onclick=\"selectPreview()\">Mobile Preview</span>"); +// sb.append("<select onchange=\"openPreview(this.options[this.selectedIndex].value)\"><option>---</option>"); +// for (DevicePreview device : MobilePreviewManager.getInstance().getDevicesList()) +// { +// sb +// .append("<option value=\"") +// .append(device.getDeviceId()) +// .append(",") +// .append(device.getPreviewWidth()) +// .append(",") +// .append(device.getPreviewHeight()) +// .append("\">") +// .append(device.getDeviceId()) +// .append("</option>"); +// } +// sb.append("</select>"); + sb.append("<div id=\"selectPreview\" style=\"display:none\" >"); + sb + .append("<h3 style=\"margin:0px; line-height:1.1em;padding-left:30px;background: transparent no-repeat top left url(" + + this.getRequest().getContextPath() + + "/.resources/mgnlmobile/images/24_iphone.png)\">"); + sb.append("Select device to preview:"); + sb.append("</h3>"); + sb.append("<ul>"); + for (DevicePreview device : MobilePreviewManager.getInstance().getDevicesList()) + { + String description = StringUtils.isNotBlank(device.getDeviceDescription()) + ? device.getDeviceDescription() + : device.getDeviceId(); + sb.append("<li>").append("<a href=\"javascript:void(0)\" onclick=\"openPreview('").append( + device.getDeviceId()).append(",").append(device.getPreviewWidth()).append(",").append( + device.getPreviewHeight()).append("'); \">").append(description).append("</a></li>"); + } + sb.append("</ul>"); + sb.append("<a href=\"javascript:void(0)\" class=\"closeButton\" onclick=\"redirectToHome()\" >"); + sb.append("Close preview mode"); + sb.append("</a>"); + sb.append("</div>"); + + return sb.toString(); + } +} Added: trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/tags/MobilePreviewButtonTag.java =================================================================== --- trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/tags/MobilePreviewButtonTag.java (rev 0) +++ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/tags/MobilePreviewButtonTag.java 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,87 @@ +/** + * + * Magnolia - Mobile Module (http://www.openmindlab.com/lab/products.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmobile.tags; + +import info.magnolia.cms.taglibs.BarTag; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.tagext.TagSupport; + +import net.sourceforge.openutils.mgnlmobile.filters.MobileFilter; + + +/** + * @author molaschi + * @version $Id: $ + */ +public class MobilePreviewButtonTag extends TagSupport +{ + + /** + * + */ + private static final long serialVersionUID = 4539087366872958772L; + + /** + * position (<code>left|right</code>). + */ + private String position; + + /** + * Where to add this button. Can be "left" or "right". Default is "left". + * @jsp.attribute required="true" rtexprvalue="true" + */ + public void setPosition(String position) + { + this.position = position; + } + + public int doEndTag() throws JspException + { + + if (MobileFilter.isActive()) + { + BarTag bartag = (BarTag) findAncestorWithClass(this, BarTag.class); + if (bartag == null) + { + throw new JspException("button tag should be enclosed in a mainbar or newbar tag"); + } + + MobilePreviewButton button = new MobilePreviewButton(); + + if ("right".equalsIgnoreCase(position)) + { + bartag.addButtonRight(button); + } + else + { + bartag.addButtonLeft(button); + } + } + + return EVAL_PAGE; + } + + public void release() + { + super.release(); + this.position = null; + } +} \ No newline at end of file Added: trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/BaseMobileParagraphDecorator.java =================================================================== --- trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/BaseMobileParagraphDecorator.java (rev 0) +++ trunk/openutils-mgnlmobile/src/main/java/net/sourceforge/openutils/mgnlmobile/templating/BaseMobileParagraphDecorator.java 2010-08-26 14:38:38 UTC (rev 2906) @@ -0,0 +1,323 @@ +/** + * + * Magnolia - Mobile Module (http://www.openmindlab.com/lab/products.html) + * Copyright(C) 2010-2010, Openmind S.r.l. http://www.openmindonline.it + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package net.sourceforge.openutils.mgnlmobile.templating; + +import info.magnolia.cms.core.Content; +import info.magnolia.module.templating.Paragraph; +import info.magnolia.module.templating.RenderableDefinition; +import info.magnolia.module.templating.RenderingModel; + +import java.lang.reflect.InvocationTargetException; +import java.util.Map; + +import net.sourceforge.openutils.mgnlmobile.filters.MobileFilter; + + +/** + * @author molaschi + * @version $Id: $ + */ +public abstract class BaseMobileParagraphDecorator extends Paragraph +{ + + private Paragraph innerParagraph; + + protected abstract boolean hasMobileParagraph(); + + protected abstract Paragraph getMobileParagraph(); + + /** + * Returns the innerParagraph. + * @return the innerParagraph + */ + public Paragraph getInnerParagraph() + { + return innerParagraph; + } + + /** + * Sets the innerParagraph. + * @param innerParagraph the innerParagraph to set + */ + public void setInnerParagraph(Paragraph innerParagraph) + { + this.innerParagraph = innerParagraph; + } + + // customized template methods + + /** + * @return + * @see info.magnolia.module.templating.AbstractRenderable#getTemplatePath() + */ + public String getTemplatePath() + { + return resolveTemplate().getTemplatePath(); + } + + /** + * @return + * @see info.magnolia.module.templating.AbstractRenderable#getType() + */ + public String getType() + { + return resolveTemplate().getType(); + } + + protected Paragraph resolveTemplate() + { + if (MobileFilter.isMobileRequest() && hasMobileParagraph()) + { + Paragraph p = getMobileParagraph(); + if (p != null) + { + return p; + } + } + return innerParagraph; + } + + // delegated paragraph methods + + /** + * @param actionResult + * @param model + * @return + * @see info.magnolia.module.templating.AbstractRenderable#determineTemplatePath(java.lang.String, + * info.magnolia.module.templating.RenderingModel) + */ + public String determineTemplatePath(String actionResult, RenderingModel model) + { + return super.determineTemplatePath(actionResult, model); + } + + /** + * @return + * @see info.magnolia.module.templating.AbstractRenderable#getDescription() + */ + public String getDescription() + { + return innerParagraph.getDescription(); + } + + /** + * @return + * @see info.magnolia.module.templating.AbstractRenderable#getDialog() + */ + public String getDialog() + { + return innerParagraph.getDialog(); + } + + /** + * @param path + * @return + * @deprecated + * @see info.magnolia.module.templati... [truncated message content] |