001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.rest.widget; 014 015import static org.apache.juneau.dto.html5.HtmlBuilder.*; 016 017import org.apache.juneau.dto.html5.*; 018import org.apache.juneau.rest.*; 019import org.apache.juneau.utils.*; 020 021/** 022 * Widget that returns back a list of hyperlinks for rendering the contents of a page in the various default styles. 023 * 024 * <p> 025 * The variable it resolves is <js>"$W{StyleMenuItem}"</js>. 026 * 027 * <p> 028 * An example of this widget can be found in the <code>PetStoreResource</code> in the examples that provides 029 * a drop-down menu item for rendering all other supported content types in plain text: 030 * <p class='bcode'> 031 * <ja>@RestMethod</ja>( 032 * name=<jsf>GET</jsf>, 033 * path=<js>"/"</js>, 034 * widgets={ 035 * StyleMenuItem.<jk>class</jk>, 036 * }, 037 * htmldoc=<ja>@HtmlDoc</ja>( 038 * navlinks={ 039 * <js>"up: ..."</js>, 040 * <js>"options: ..."</js>, 041 * <js>"$W{QueryMenuItem}"</js>, 042 * <js>"$W{ContentTypeMenuItem}"</js>, 043 * <js>"$W{StyleMenuItem}"</js>, 044 * <js>"source: ..."</js> 045 * } 046 * ) 047 * ) 048 * <jk>public</jk> Collection<Pet> getPets() { 049 * </p> 050 * 051 * <h5 class='section'>See Also:</h5> 052 * <ul> 053 * <li class='link'><a class="doclink" href="../../../../../overview-summary.html#juneau-rest-server.Widgets">Overview > juneau-rest-server > Widgets</a> 054 * </ul> 055 */ 056public class StyleMenuItem extends MenuItemWidget { 057 058 private static final String[] BUILT_IN_STYLES = {"devops", "light", "original", "dark"}; 059 060 @Override /* Widget */ 061 public String getLabel(RestRequest req) { 062 return "styles"; 063 } 064 /** 065 * Looks at the supported media types from the request and constructs a list of hyperlinks to render the data 066 * as plain-text. 067 */ 068 @Override /* MenuItemWidget */ 069 public Div getContent(RestRequest req) throws Exception { 070 Div div = div(); 071 for (String s : BUILT_IN_STYLES) { 072 java.net.URI uri = req.getUri(true, new AMap<String,String>().append("stylesheet", "styles/"+s+".css")); 073 div.children(a(uri, s), br()); 074 } 075 return div; 076 } 077}