/* * Copyright 2000-2018 Vaadin Ltd. * * 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 com.vaadin.server; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.text.ParseException; import java.util.Enumeration; import javax.portlet.ClientDataRequest; import javax.portlet.PortletPreferences; import javax.portlet.PortletRequest; import javax.portlet.PortletSession; import javax.portlet.ResourceRequest; import javax.portlet.filter.PortletRequestWrapper; import com.vaadin.shared.ApplicationConstants; /** * Wrapper for {@link PortletRequest} and its subclasses. * * @author Vaadin Ltd. * @since 7.0 * * @see VaadinRequest * @see VaadinPortletResponse */ public class VaadinPortletRequest extends PortletRequestWrapper implements VaadinRequest { private final VaadinPortletService vaadinService; /** * Wraps a portlet request and an associated vaadin service. * * @param request * the portlet request to wrap * @param vaadinService * the associated vaadin service */ public VaadinPortletRequest(PortletRequest request, VaadinPortletService vaadinService) { super(request); this.vaadinService = vaadinService; } @Override public int getContentLength() { try { return ((ClientDataRequest) getRequest()).getContentLength(); } catch (ClassCastException e) { throw new IllegalStateException( "Content lenght only available for ClientDataRequests"); } } @Override public InputStream getInputStream() throws IOException { try { return ((ClientDataRequest) getRequest()).getPortletInputStream(); } catch (ClassCastException e) { throw new IllegalStateException( "Input data only available for ClientDataRequests"); } } @Override public BufferedReader getReader() throws IOException { try { return ((ClientDataRequest) getRequest()).getReader(); } catch (ClassCastException e) { throw new IllegalStateException( "Reader only available for ClientDataRequests"); } } @Override public String getPathInfo() { PortletRequest request = getRequest(); if (request instanceof ResourceRequest) { ResourceRequest resourceRequest = (ResourceRequest) request; String resourceID = resourceRequest.getResourceID(); if (VaadinPortlet.RESOURCE_URL_ID.equals(resourceID)) { String resourcePath = resourceRequest .getParameter(ApplicationConstants.V_RESOURCE_PATH); return resourcePath; } return resourceID; } else { return null; } } @Override public WrappedSession getWrappedSession() { return getWrappedSession(true); } @Override public WrappedSession getWrappedSession(boolean allowSessionCreation) { PortletSession session = getPortletSession(allowSessionCreation); if (session != null) { return new WrappedPortletSession(session); } else { return null; } } /** * Gets the original, unwrapped portlet request. * * @return the unwrapped portlet request */ public PortletRequest getPortletRequest() { return getRequest(); } @Override public String getContentType() { try { return ((ResourceRequest) getRequest()).getContentType(); } catch (ClassCastException e) { throw new IllegalStateException( "Content type only available for ResourceRequests"); } } @Override public String getCharacterEncoding() { try { return ((ClientDataRequest) getRequest()).getCharacterEncoding(); } catch (ClassCastException e) { throw new IllegalStateException( "Character encoding only available for ClientDataRequest"); } } @Override public String getMethod() { try { return ((ClientDataRequest) getRequest()).getMethod(); } catch (ClassCastException e) { throw new IllegalStateException( "Method only available for ClientDataRequest"); } } @Override public String getRemoteAddr() { return null; } @Override public String getRemoteHost() { return null; } @Override public int getRemotePort() { return -1; } @Override public String getHeader(String string) { return null; } /** * Reads a portal property from the portal context of the Vaadin request. * * @param name * a string with the name of the portal property to get * @return a string with the value of the property, or null if * the property is not defined */ public String getPortalProperty(String name) { return getRequest().getPortalContext().getProperty(name); } /** * Reads a portlet preference from the portlet of the request. * * @param name * The name of the portlet preference. Cannot be * null. * * @return The value of the portlet preference, null if the * preference is not defined. */ public String getPortletPreference(String name) { PortletRequest request = getRequest(); PortletPreferences preferences = request.getPreferences(); return preferences.getValue(name, null); } @Override public VaadinPortletService getService() { return vaadinService; } @Override public long getDateHeader(String name) { String header = getHeader(name); if (header == null) { return -1; } else { try { return VaadinPortletResponse.HTTP_DATE_FORMAT.parse(header) .getTime(); } catch (ParseException e) { throw new IllegalArgumentException(e); } } } @Override public Enumeration getHeaderNames() { return null; } @Override public Enumeration getHeaders(String name) { return null; } /** * Gets the currently processed portlet request. The current portlet request * is automatically defined when the request is started. The current portlet * request can not be used in e.g. background threads because of the way * server implementations reuse request instances. * * @return the current portlet request instance if available, otherwise * null * @since 7.3 */ public static PortletRequest getCurrentPortletRequest() { return VaadinPortletService.getCurrentPortletRequest(); } /** * Gets the currently processed Vaadin portlet request. The current request * is automatically defined when the request is started. The current request * can not be used in e.g. background threads because of the way server * implementations reuse request instances. * * @return the current Vaadin portlet request instance if available, * otherwise null * @since 7.3 */ public static VaadinPortletRequest getCurrent() { return VaadinPortletService.getCurrentRequest(); } } 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<title>Button Static Test : Default</title>
	<link rel="stylesheet" href="../static.css" type="text/css" />
	<link rel="stylesheet" href="../../../themes/base/jquery.ui.base.css" type="text/css" />
	<link rel="stylesheet" href="../../../themes/base/jquery.ui.theme.css" type="text/css" title="ui-theme" />
	<script type="text/javascript" src="../../../jquery-1.7.js"></script>
	<script type="text/javascript" src="../static.js"></script>
	<style>
		div { margin: 0 0 1em; }
		h2 { margin: 2em 0 1em; }
	</style>	
</head>
<body>
	
	<h2>Using button elements</h2>

	<div>
		<button class="ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-text">Button</span>
		</button>
		
		<button class="ui-button ui-button-icon-only ui-widget ui-state-default ui-corner-all" title="Button">
			<span class="ui-button-icon-primary ui-icon ui-icon-gear"></span>
			<span class="ui-button-text">Primary icon</span>
		</button>

		<button class="ui-button ui-button-icon-only ui-widget ui-state-default ui-corner-all" title="Button">
			<span class="ui-button-text">Secondary icon</span>
			<span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
		</button>

		<button class="ui-button ui-button-text-icon-primary ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-icon-primary ui-icon ui-icon-gear"></span>
			<span class="ui-button-text">Primary icon</span>
		</button>

		<button class="ui-button ui-button-text-icon-secondary ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-text">Secondary icon</span>
			<span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
		</button>
		
		<button class="ui-button ui-button-text-icons ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-icon-primary ui-icon ui-icon-gear"></span>
			<span class="ui-button-text">Both icons</span>
			<span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
		</button>
		
		<button class="ui-button ui-button-icons-only ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-icon-primary ui-icon ui-icon-gear"></span>
			<span class="ui-button-text">No text</span>
			<span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
		</button>
	</div>
	
	<h2>Using anchor elements</h2>

	<div>
		<a href="#" class="ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-text">Button</span>
		</a>
		
		<a href="#" class="ui-button ui-button-icon-only ui-widget ui-state-default ui-corner-all" title="Button">
			<span class="ui-button-icon-primary ui-icon ui-icon-gear"></span>
			<span class="ui-button-text">Primary icon</span>
		</a>
		
		<a href="#" class="ui-button ui-button-icon-only ui-widget ui-state-default ui-corner-all" title="Button">
			<span class="ui-button-text">Secondary icon</span>
			<span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
		</a>
		
		<a href="#" class="ui-button ui-button-text-icon-primary ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-icon-primary ui-icon ui-icon-gear"></span>
			<span class="ui-button-text">Primary icon</span>
		</a>

		<a href="#" class="ui-button ui-button-text-icon-secondary ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-text">Secondary icon</span>
			<span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
		</a>
		
		<a href="#" class="ui-button ui-button-text-icons ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-icon-primary ui-icon ui-icon-gear"></span>
			<span class="ui-button-text">Both icons</span>
			<span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
		</a>
		
		<a href="#" class="ui-button ui-button-icons-only ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-icon-primary ui-icon ui-icon-gear"></span>
			<span class="ui-button-text">No text</span>
			<span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
		</a>
	</div>
	
	
	
	<h2>Using label elements (used when proxying to radio or check inputs)</h2>

	<div>
		<label class="ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-text">Button</span>
		</label>
		
		<label class="ui-button ui-button-icon-only ui-widget ui-state-default ui-corner-all" title="Button">
			<span class="ui-button-icon-primary ui-icon ui-icon-gear"></span>
			<span class="ui-button-text">Primary icon</span>
		</label>
		
		<label class="ui-button ui-button-icon-only ui-widget ui-state-default ui-corner-all" title="Button">
			<span class="ui-button-text">Secondary icon</span>
			<span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
		</label>
		
		<label class="ui-button ui-button-text-icon-primary ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-icon-primary ui-icon ui-icon-gear"></span>
			<span class="ui-button-text">Primary icon</span>
		</label>
		
		<label class="ui-button ui-button-text-icon-secondary ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-text">Secondary icon</span>
			<span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
		</label>
		
		<label class="ui-button ui-button-text-icons ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-icon-primary ui-icon ui-icon-gear"></span>
			<span class="ui-button-text">Both icons</span>
			<span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
		</label>
		
		<label class="ui-button ui-button-icons-only ui-widget ui-state-default ui-corner-all">
			<span class="ui-button-icon-primary ui-icon ui-icon-gear"></span>
			<span class="ui-button-text">No text</span>
			<span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
		</label>
	</div>
	
	
	<h2>Button Sets</h2>
	
	<div class="ui-buttonset">
		<button class="ui-button ui-button-text-only ui-widget ui-state-default ui-corner-left"><span class="ui-button-text">First</span></button>
		<button class="ui-button ui-button-text-only ui-widget ui-state-default"><span class="ui-button-text">Middle</span></button>
		<button class="ui-button ui-button-text-only ui-widget ui-state-default"><span class="ui-button-text">Middle</span></button>
		<button class="ui-button ui-button-text-only ui-widget ui-state-default ui-corner-right"><span class="ui-button-text">Last</span></button>
	</div>
	
	

<script type="text/javascript" src="http://jqueryui.com/themeroller/themeswitchertool/"></script>
<script>
	$('<div/>').css({
		position: "absolute",
		right: 10,
		top: 10
	}).appendTo(document.body).themeswitcher();
</script>
</body>
</html>