Author: taylor Date: Fri Feb 27 23:33:58 2015 New Revision: 1662855 URL: http://svn.apache.org/r1662855 Log: JS2-1316: implemented new J2-Admin Profiler portlet with AngularJS framework. This portlet currently requires a responsive decorator
Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppAuthResult.java portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppCredentials.java portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortlet.java portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppTokenPortlet.java portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/ProfilerAdminPortlet.java portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/RestAuthClient.java portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/dto/ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/dto/DtoAdminBasePrefs.java portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/dto/DtoError.java portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/wro.properties portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/wro.xml portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/app.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/angular-cookies.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/angular-route.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/angular.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/bootstrap.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/jquery.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/lodash.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/modernizr-2.8.3.min.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/moment.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/ng-grid-2.0.14.min.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/ng-grid-flexible-height.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/ui-bootstrap-tpls.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_licenses/ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_licenses/BOILERPLATE_LICENSE.md portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_licenses/BOOTSTRAP_LICENSE portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_licenses/JQUERY_MIT_LICENSE.txt portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_licenses/LODASH_LICENSE portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_licenses/MIT_LICENSE portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_licenses/MOMENT_LICENSE portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_licenses/NG_GRID_LICENSE.md portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/images/ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/j2-admin-skin.css portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/PortletService.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/RestApiService.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/ServerService.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/TextMessages.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/controllers.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/directives.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/filters.js portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/styles/ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/styles/app.css portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/styles/default.css portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/styles/ng-grid.min.css portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/views/ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/views/modals/ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/views/modals/criteria-detail.html portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/views/modals/profile-detail.html portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/views/modals/profiles-delete.html portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/views/profiler-admin-edit.jsp portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/views/profiler-admin.jsp Modified: portals/jetspeed-2/applications/j2-admin/trunk/pom.xml portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml Modified: portals/jetspeed-2/applications/j2-admin/trunk/pom.xml URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/pom.xml?rev=1662855&r1=1662854&r2=1662855&view=diff ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/pom.xml (original) +++ portals/jetspeed-2/applications/j2-admin/trunk/pom.xml Fri Feb 27 23:33:58 2015 @@ -59,6 +59,7 @@ <velocity.version>1.6.4</velocity.version> <xerces.version>2.8.1</xerces.version> <wicket.version>1.4.17</wicket.version> + <jackson.version>2.2.3</jackson.version> </properties> <!-- Dependencies --> @@ -199,6 +200,11 @@ <artifactId>commons-codec</artifactId> <version>${commons-codec.version}</version> </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <version>${jackson.version}</version> + </dependency> <!-- Runtime Dependencies --> <dependency> @@ -447,9 +453,37 @@ <skip>true</skip> </configuration> </plugin> + <plugin> + <groupId>ro.isdc.wro4j</groupId> + <artifactId>wro4j-maven-plugin</artifactId> + <version>1.6.3</version> + </plugin> </plugins> </pluginManagement> - + <plugins> + <plugin> + <groupId>ro.isdc.wro4j</groupId> + <artifactId>wro4j-maven-plugin</artifactId> + <executions> + <execution> + <phase>compile</phase> + <goals> + <goal>run</goal> + </goals> + </execution> + </executions> + <configuration> + <targetGroups>J2_ADMIN_EXTERNAL_JS,J2_ADMIN_INTERNAL_JS</targetGroups> + <minimize>false</minimize> + <destinationFolder>${basedir}/target/${project.artifactId}-${project.version}/wro/</destinationFolder> + <!--<cssDestinationFolder>d:/static/css/</cssDestinationFolder>--> + <!--<jsDestinationFolder>d:/static/js/</jsDestinationFolder>--> + <contextFolder>${basedir}/src/main/webapp/</contextFolder> + <wroFile>${basedir}/src/main/webapp/WEB-INF/wro.xml</wroFile> + <ignoreMissingResources>false</ignoreMissingResources> + </configuration> + </plugin> + </plugins> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppAuthResult.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppAuthResult.java?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppAuthResult.java (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppAuthResult.java Fri Feb 27 23:33:58 2015 @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jetspeed.jetapp; + +/** + * + * @author <a href="mailto:tay...@apache.org">David Sean Taylor</a> + * @version $Id: $ + */ +public class JetAppAuthResult { + + private boolean success = true; + private String token = "42"; + + public JetAppAuthResult() {} + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } +} Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppCredentials.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppCredentials.java?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppCredentials.java (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppCredentials.java Fri Feb 27 23:33:58 2015 @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jetspeed.jetapp; + +/** + * + * @author <a href="mailto:tay...@apache.org">David Sean Taylor</a> + * @version $Id: $ + */ +public class JetAppCredentials { + + private String username; + private String password; + private String endpoint; + private String appName; + + public JetAppCredentials(String username, String password, String endpoint, String appName) { + this.username = username; + this.password = password; + this.endpoint = endpoint; + this.appName = appName; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getEndpoint() { + return endpoint; + } + + public void setEndpoint(String endpoint) { + this.endpoint = endpoint; + } + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } +} Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortlet.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortlet.java?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortlet.java (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortlet.java Fri Feb 27 23:33:58 2015 @@ -0,0 +1,226 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jetspeed.jetapp; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jetspeed.PortalReservedParameters; +import org.apache.jetspeed.jetapp.dto.DtoError; +import org.w3c.dom.Element; + +import javax.portlet.GenericPortlet; +import javax.portlet.MimeResponse; +import javax.portlet.PortletConfig; +import javax.portlet.PortletException; +import javax.portlet.PortletRequestDispatcher; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.io.Reader; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Method; + +/** + * Base Jet App portlet, providing a little help for managing Jet App CSS and JS resource by injecting + * web resources into portal header phase. Jetspeed handles duplicated resources by ID, ensuring only + * one resource is included. Recommended to use with a web resource optimizer. + * In J2-Admin, we employ WRO4J + * + * @author <a href="mailto:tay...@apache.org">David Sean Taylor</a> + * @version $Id: $ + */ +public class JetAppPortlet extends GenericPortlet { + + protected static Log log = LogFactory.getLog(JetAppPortlet.class); + + // Web Resource IDs + protected static final String J2_ADMIN_CSS_ID = "j2admin_css"; + protected static final String J2_ADMIN_EXTERNAL_SCRIPT_ID = "j2admin_ext_script"; + protected static final String J2_ADMIN_INTERNAL_SCRIPT_ID = "j2admin_int_script"; + + // Web Resources + protected static String[][] PRODUCTION_STYLES = { + // {"/wro/J2_ADMIN_CSS.css", J2_ADMIN_CSS_ID}, + {"/jetapp/j2-admin-skin.css", J2_ADMIN_CSS_ID} + }; + + protected static String[][] DEV_STYLES = { + {"/jetapp/j2-admin-skin.css", J2_ADMIN_CSS_ID} + }; + + protected static String[][] PRODUCTION_SCRIPTS = { + {"/wro/J2_ADMIN_EXTERNAL_JS.js", J2_ADMIN_EXTERNAL_SCRIPT_ID}, + {"/wro/J2_ADMIN_INTERNAL_JS.js", J2_ADMIN_INTERNAL_SCRIPT_ID} + }; + + protected static String[][] DEV_SCRIPTS = { + { "/wro/J2_ADMIN_EXTERNAL_JS.js", J2_ADMIN_EXTERNAL_SCRIPT_ID}, + { "/jetapp/scripts/TextMessages.js", "j2admin_text"}, + { "/jetapp/scripts/ServerService.js", "j2admin_server"}, + { "/jetapp/scripts/RestApiService.js", "j2admin_services"}, + { "/jetapp/scripts/PortletService.js", "j2admin_portlet"}, + { "/jetapp/app.js", "j2admin_app"}, + { "/jetapp/scripts/controllers.js", "j2admin_controllers"}, + { "/jetapp/scripts/directives.js", "j2admin_directives"}, + { "/jetapp/scripts/filters.js", "j2admin_filters"} + }; + + protected final static String PREFS_VIEW = "View"; + protected final static String PREFS_EDIT = "Edit"; + + + // use merged and minified resources when releasing + public static final boolean DEV_MODE = true; + + @Override + public void init(PortletConfig config) throws PortletException { + super.init(config); + } + + @Override + protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { + + response.setContentType("text/html"); + if (authenticate(request, response)) { + String url = request.getPreferences().getValue(PREFS_VIEW, "/jetapp/views/profiler-admin.jsp" ); + PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher(url); + dispatcher.include(request, response); + } + } + + protected boolean authenticate(RenderRequest request, RenderResponse response) throws PortletException, IOException { + return true; + } + + private void addJavaScript(RenderResponse response, String scriptPath, String scriptId) { + Element headElem = response.createElement("script"); + headElem.setAttribute("language", "javascript"); + if (scriptId != null) { + headElem.setAttribute("id", scriptId); + } + headElem.setAttribute("src", scriptPath); + headElem.setAttribute("type", "text/javascript"); + response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, headElem); + } + + private void addStyleLink(RenderResponse response, String cssPath, String cssId) { + Element headElem = response.createElement("link"); + headElem.setAttribute("rel", "stylesheet"); + if (cssId != null) { + headElem.setAttribute("id", cssId); + } + headElem.setAttribute("href", cssPath); + headElem.setAttribute("type", "text/css"); + response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, headElem); + } + + @Override + protected void doHeaders(RenderRequest request, RenderResponse response) { + super.doHeaders(request, response); + + if (alreadyContributedHeaders(request)) + return; + + String[][] styles = (DEV_MODE) ? DEV_STYLES : PRODUCTION_STYLES; + String[][] scripts = (DEV_MODE) ? DEV_SCRIPTS : PRODUCTION_SCRIPTS; + + for (String[] pair : styles) { + addStyleLink(response, request.getContextPath() + pair[0], pair[1]); + } + + for (String[] pair : scripts) { + addJavaScript(response, request.getContextPath() + pair[0], pair[1]); + } + + } + + + + public String createError(int httpCode, String message) throws IOException { + DtoError error = new DtoError(httpCode, message); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true); + StringWriter writer = new StringWriter(); + objectMapper.writeValue(writer, error); + return writer.toString(); + } + + protected static HttpServletRequest getServletRequest(RenderRequest request) { + Object context = request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE); + if (context != null) { + try { + Method getRequest = context.getClass().getMethod("getRequest"); + if (getRequest != null) { + return (HttpServletRequest)getRequest.invoke(context); + } + } + catch (Exception e2) { + log.error("Failed to retrieve portal servlet request: " + e2.getMessage(), e2); + return null; + } + } + return null; + } + // JBossAS7... + // try { + // return (HttpServletRequest) PolicyContext.getContext("javax.servlet.http.HttpServletRequest"); + // } + // catch (Exception e) { + // log.error("Failed to retrieve portal servlet request: " + e.getMessage(), e); + // } + + + protected final static String GW_DASHBOARD_PORTLET_FLAG = "gw.dashboard.portlet.flag"; + + protected boolean alreadyContributedHeaders(RenderRequest renderRequest) { + HttpServletRequest request = getServletRequest(renderRequest); + if (request == null) + return false; + Boolean contributed = (Boolean)request.getAttribute(GW_DASHBOARD_PORTLET_FLAG); + if (contributed == null || contributed == false) { + request.setAttribute(GW_DASHBOARD_PORTLET_FLAG, Boolean.TRUE); + return false; + } + return true; + } + + private static final int BLOCK_SIZE = 4096; + + public static void drain(Reader r, Writer w) throws IOException { + char[] bytes = new char[BLOCK_SIZE]; + try { + int length = r.read(bytes); + while (length != -1) { + if (length != 0) { + w.write(bytes, 0, length); + } + length = r.read(bytes); + } + } finally { + bytes = null; + } + + } + +} + + + Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java Fri Feb 27 23:33:58 2015 @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jetspeed.jetapp; + +import javax.portlet.PortletException; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; +import javax.portlet.filter.FilterChain; +import javax.portlet.filter.FilterConfig; +import javax.portlet.filter.RenderFilter; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; + +/** + * Injects a single angular initialization function, ensuring that only one angular bootstrap statement + * is included per rendered page of portlets + * + * @author <a href="mailto:tay...@apache.org">David Sean Taylor</a> + * @version $Id: $ + */ +public class JetAppPortletFilter implements RenderFilter { + + protected final static String JET_DASHBOARD_ANGULAR_FLAG = "jet.dashboard.angular.flag"; + + + public void doFilter(RenderRequest request, RenderResponse response, + FilterChain filterChain) throws IOException, PortletException { + filterChain.doFilter(request, response); + includeAngular(request, response); + } + + public void destroy() { + } + + public void init(FilterConfig filterConfig) throws PortletException { + } + + protected void includeAngular(RenderRequest request, RenderResponse response) throws PortletException, IOException { + String useAngular = request.getPreferences().getValue("jetapp", null); + if (useAngular != null && useAngular.equalsIgnoreCase("true")) { + if (!alreadyContributedAngular(request)) { + response.getWriter().println("<script>\n angular.element(document).ready(function() {\n" + + " angular.bootstrap(document, ['j2admin']);\n" + + " });\n</script>\n"); + } + } + } + + protected boolean alreadyContributedAngular(RenderRequest renderRequest) { + HttpServletRequest request = JetAppPortlet.getServletRequest(renderRequest); + if (request == null) + return false; + Boolean contributed = (Boolean) request.getAttribute(JET_DASHBOARD_ANGULAR_FLAG); + if (contributed == null || contributed == false) { + request.setAttribute(JET_DASHBOARD_ANGULAR_FLAG, Boolean.TRUE); + return false; + } + return true; + } + + +} Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppTokenPortlet.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppTokenPortlet.java?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppTokenPortlet.java (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppTokenPortlet.java Fri Feb 27 23:33:58 2015 @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jetspeed.jetapp; + +import javax.portlet.PortletException; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; +import javax.servlet.http.Cookie; +import java.io.IOException; + +/** + * Extends JetApp Portlet, adding support for using API Tokens from server side + * + * @author <a href="mailto:tay...@apache.org">David Sean Taylor</a> + * @version $Id: $ + */ +public class JetAppTokenPortlet extends JetAppPortlet { + + protected final static String MSG_MISSING_REST_SERVICE_PARAM = "<b>Missing initialization parameter. Cannot connect to API Server - missing param: %s</b>"; + protected static final String MISSING_INIT_PARAMETER = "Missing initialization parameter for app: "; + + protected final static String SESSION_JETAPP_TOKEN = "JetAppToken"; + protected final static String JET_APP_NAME = "j2-admin"; + + protected static final String COOKIE_JETAPP_TOKEN = "JetAppToken"; + protected static final String COOKIE_JETAPP_REST_SERVICE = "JetAppRestService"; + protected final static String MSG_FAILED_AUTHENTICATE = "<b>Failed to authenticate. Cannot connect to API Server</b>"; + + protected JetAppCredentials getCredentials() { + return new JetAppCredentials("user", "user", "http://localhost/services", JET_APP_NAME); + } + protected boolean authenticate(RenderRequest request, RenderResponse response) throws PortletException, IOException { + String token = (String)request.getPortletSession(true).getAttribute(SESSION_JETAPP_TOKEN); + if (token == null) { + JetAppCredentials credentials = getCredentials(); + Cookie restCookie = new Cookie(COOKIE_JETAPP_REST_SERVICE, credentials.getEndpoint()); + restCookie.setPath("/"); + response.addProperty(restCookie); + + try { + RestAuthClient client = new RestAuthClient(credentials); + JetAppAuthResult result = client.login(); + if (result.isSuccess()) { + token = result.getToken(); + Cookie tokenCookie = new Cookie(COOKIE_JETAPP_TOKEN, token); + tokenCookie.setPath("/"); + response.addProperty(tokenCookie); + request.getPortletSession().setAttribute(SESSION_JETAPP_TOKEN, token); + return true; + } + log.error("Failed authentication in for app: " + JET_APP_NAME); + response.getWriter().println(MSG_FAILED_AUTHENTICATE); + return false; + } + catch (Exception e) { + log.error("Exception during authentication in Dashboard: " + e.getMessage(), e); + response.getWriter().println(MSG_FAILED_AUTHENTICATE); + return false; + } + } + return true; + } + +} Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/ProfilerAdminPortlet.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/ProfilerAdminPortlet.java?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/ProfilerAdminPortlet.java (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/ProfilerAdminPortlet.java Fri Feb 27 23:33:58 2015 @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jetspeed.jetapp; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jetspeed.jetapp.dto.DtoAdminBasePrefs; + +import javax.portlet.PortletConfig; +import javax.portlet.PortletException; +import javax.portlet.PortletRequestDispatcher; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; +import javax.portlet.ResourceRequest; +import javax.portlet.ResourceResponse; +import java.io.IOException; +import java.io.StringWriter; + +/** + * + * @author <a href="mailto:tay...@apache.org">David Sean Taylor</a> + * @version $Id: $ + */ +public class ProfilerAdminPortlet extends JetAppPortlet { + + protected static Log log = LogFactory.getLog(ProfilerAdminPortlet.class); + + protected static final String PREFS_ROWS_PER_PAGE = "rowsPerPage"; + + @Override + public void init(PortletConfig config) throws PortletException { + super.init(config); + } + + @Override + protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { + super.doView(request, response); + } + + @Override + protected void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException { + response.setContentType("text/html"); + if (authenticate(request, response)) { + PortletRequestDispatcher dispatcher = null; + String url = request.getPreferences().getValue(PREFS_EDIT, "/jetapp/views/profiler-admin-edit.jsp" ); + dispatcher = getPortletContext().getRequestDispatcher(url); + dispatcher.include(request, response); + } + } + + @Override + public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException { + String resourceID = request.getResourceID(); + if (resourceID == null) { + response.addProperty(ResourceResponse.HTTP_STATUS_CODE, "400"); + response.getWriter().println(createError(400, "invalid resource id")); + return; + } + if (resourceID.equals("writePrefs")) { + StringWriter writer = new StringWriter(); + drain(request.getReader(), writer); + String json = writer.toString(); + ObjectMapper writeMapper = new ObjectMapper(); + DtoAdminBasePrefs update = writeMapper.readValue(json, DtoAdminBasePrefs.class); + request.getPreferences().setValue(PREFS_ROWS_PER_PAGE , Integer.toString(update.getRowsPerPage())); + request.getPreferences().store(); + } + DtoAdminBasePrefs prefs = new DtoAdminBasePrefs(); + prefs.setRowsPerPage(Integer.parseInt(request.getPreferences().getValue(PREFS_ROWS_PER_PAGE , "20"))); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true); + StringWriter writer = new StringWriter(); + objectMapper.writeValue(writer, prefs); + response.getWriter().println(writer); + } + + + +} Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/RestAuthClient.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/RestAuthClient.java?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/RestAuthClient.java (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/RestAuthClient.java Fri Feb 27 23:33:58 2015 @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jetspeed.jetapp; + +/** + * Extends JetApp Portlet, adding support for using API Tokens from server side + * + * @author <a href="mailto:tay...@apache.org">David Sean Taylor</a> + * @version $Id: $ + */ +public class RestAuthClient { + + public RestAuthClient(JetAppCredentials credentials) {} + + public JetAppAuthResult login() { + return new JetAppAuthResult(); + } +} Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/dto/DtoAdminBasePrefs.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/dto/DtoAdminBasePrefs.java?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/dto/DtoAdminBasePrefs.java (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/dto/DtoAdminBasePrefs.java Fri Feb 27 23:33:58 2015 @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jetspeed.jetapp.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +/** + * + * @author <a href="mailto:tay...@apache.org">David Sean Taylor</a> + * @version $Id: $ + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class DtoAdminBasePrefs { + + private int rowsPerPage; + + public int getRowsPerPage() { + return rowsPerPage; + } + + public void setRowsPerPage(int rowsPerPage) { + this.rowsPerPage = rowsPerPage; + } + +} Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/dto/DtoError.java URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/dto/DtoError.java?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/dto/DtoError.java (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/dto/DtoError.java Fri Feb 27 23:33:58 2015 @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.jetspeed.jetapp.dto; + +/** + * + * @author <a href="mailto:tay...@apache.org">David Sean Taylor</a> + * @version $Id: $ + */ +public class DtoError { + + private int status; + private String message; + + public DtoError(int status, String message) { + this.status = status; + this.message = message; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml?rev=1662855&r1=1662854&r2=1662855&view=diff ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml (original) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml Fri Feb 27 23:33:58 2015 @@ -2719,7 +2719,43 @@ <keywords>clone,portlet,management,admin</keywords> </portlet-info> </portlet> - + + <portlet> + <description>Profiler Maintenance</description> + <portlet-name>ProfilerAdmin</portlet-name> + <display-name>Profiler Maintenance</display-name> + <portlet-class>org.apache.jetspeed.jetapp.ProfilerAdminPortlet</portlet-class> + <supports> + <mime-type>text/html</mime-type> + <portlet-mode>VIEW</portlet-mode> + <portlet-mode>EDIT</portlet-mode> + </supports> + <supported-locale>en</supported-locale> + <portlet-info> + <title>Profiler Admin</title> + <short-title>Profiler</short-title> + <keywords>admin,profiler</keywords> + </portlet-info> + <portlet-preferences> + <preference> + <name>View</name> + <value>/jetapp/views/profiler-admin.jsp</value> + </preference> + <preference> + <name>Edit</name> + <value>/jetapp/views/profiler-admin-edit.jsp</value> + </preference> + <preference> + <name>rowsPerPage</name> + <value>20</value> + </preference> + <preference> + <name>jetapp</name> + <value>true</value> + </preference> + </portlet-preferences> + </portlet> + <custom-portlet-mode> <description>Custom About Mode</description> <portlet-mode>about</portlet-mode> @@ -2740,5 +2776,16 @@ <description>Custom Print Mode</description> <portlet-mode>print</portlet-mode> </custom-portlet-mode> - + + <filter> + <filter-name>JetAppPortletFilter</filter-name> + <filter-class>org.apache.jetspeed.jetapp.JetAppPortletFilter</filter-class> + <lifecycle>RENDER_PHASE</lifecycle> + </filter> + + <filter-mapping> + <filter-name>JetAppPortletFilter</filter-name> + <portlet-name>*</portlet-name> + </filter-mapping> + </portlet-app> Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/wro.properties URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/wro.properties?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/wro.properties (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/wro.properties Fri Feb 27 23:33:58 2015 @@ -0,0 +1,51 @@ +#If true, it is DEVELOPMENT mode, by default this value is true +debug=false +# Integer value for specifying how often (in seconds) the resource changes should be checked. +# When this value is 0, the cache is never refreshed. When a resource change is detected, the +# cached group containing changed resource will be invalidated. This is useful during development, +# when resources are changed often. +# resourceChangeUpdateInterval=5 + +# Default is true +gzipEnabled=true +jmxEnabled=false +# MBean name to be used if JMX is enabled +mbeanName=wro +# Default is 0 +# cacheUpdatePeriod=7200 +cacheUpdatePeriod=0 +# Default is 0 +#modelUpdatePeriod=7200 +modelUpdatePeriod=0 +# Default is false. +disableCache=false +# Default is UTF-8 +encoding=UTF-8 + +# The alias of the HashStrategy used to compute ETags & cache keys. Value can be CRC32/MD5/SHA-1. +hashStrategy=MD5 +# The alias of the NamingStrategy used to rename bundles. Value can be noOp/timestamp/hashEncoder/folderHashEncoder. +namingStrategy=folderHashEncoder +# Connection timeout, for external resources (JS/CSS files from other sites) +connectionTimeout=5000 + +# When this flag is disabled (false), any missing resource will cause an exception. Default is true. +ignoreMissingResources=true +# When a group is empty and this flag is false, the processing will fail. Default is true. +ignoreEmptyGroup=true +# When this flag is true, any failure during processing will leave the content unchanged. Default is false. +ignoreFailingProcessor=true + +cacheGzippedContent=true + +parallelPreprocessing=true +managerFactoryClassName=ro.isdc.wro.manager.factory.ConfigurableWroManagerFactory +#managerFactoryClassName=ro.isdc.wro.examples.manager.CustomWroManagerFactory +#managerFactoryClassName=ro.isdc.wro.examples.manager.CustomExtensionsWroManagerFactory +#preProcessors=fallbackCssDataUri,cssUrlRewriting,cssImport,semicolonAppender,yuiCssMin +#,lessCss,coffeeScript +#,cssMin,lessCss,coffeeScript, +uriLocators=servletContext.DISPATCHER_FIRST,uri,classpath +#servletContext.SERVLET_CONTEXT_FIRST +#postProcessors=jsMin +#header=Expires: Thu, 15 Apr 2020 20:00:00 GMT | cache-control:public Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/wro.xml URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/wro.xml?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/wro.xml (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/wro.xml Fri Feb 27 23:33:58 2015 @@ -0,0 +1,41 @@ +<groups xmlns="http://www.isdc.ro/wro"> + + + <!--<group name="J2_ADMIN_CSS">--> + <!--<css>/jetapp/bower_components/html5-boilerplate/dist/css/normalize.css</css>--> + <!--<css>/jetapp/bower_components/html5-boilerplate/dist/css/main.css</css>--> + <!--<css>/jetapp/bower_components/bootstrap/dist/css/bootstrap.min.css</css>--> + <!--<css>/jetapp/bower_components/bootstrap/dist/css/bootstrap-theme.min.css</css>--> + <!--<css>/jetapp/styles/ng-grid.min.css</css>--> + <!--<css>/jetapp/styles/app.css</css>--> + <!--<css>/jetapp/styles/default.css</css>--> + <!--</group>--> + + + <group name="J2_ADMIN_EXTERNAL_JS"> + <js minimize="false">/jetapp/bower_components/jquery.js</js> + <js minimize="false">/jetapp/bower_components/modernizr-2.8.3.min.js</js> + <js minimize="false">/jetapp/bower_components/bootstrap.js</js> + <js minimize="false">/jetapp/bower_components/lodash.js</js> + <js minimize="false">/jetapp/bower_components/moment.js</js> + <js minimize="false">/jetapp/bower_components/angular.js</js> + <js minimize="false">/jetapp/bower_components/angular-route.js</js> + <js minimize="false">/jetapp/bower_components/ui-bootstrap-tpls.js</js> + <js minimize="false">/jetapp/bower_components/angular-cookies.js</js> + <js minimize="false">/jetapp/bower_components/ng-grid-2.0.14.min.js</js> + <js minimize="false">/jetapp/bower_components/ng-grid-flexible-height.js</js> + </group> + + <!-- TODO: minimize in production build --> + <group name="J2_ADMIN_INTERNAL_JS"> + <js minimize="false">/jetapp/scripts/TextMessages.js</js> + <js minimize="false">/jetapp/scripts/ServerService.js</js> + <js minimize="false">/jetapp/scripts/RestApiService.js</js> + <js minimize="false">/jetapp/scripts/PortletService.js</js> + <js minimize="false">/jetapp/app.js</js> + <js minimize="false">/jetapp/scripts/controllers.js</js> + <js minimize="false">/jetapp/scripts/directives.js</js> + <js minimize="false">/jetapp/scripts/filters.js</js> + </group> + +</groups> Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/app.js URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/app.js?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/app.js (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/app.js Fri Feb 27 23:33:58 2015 @@ -0,0 +1,21 @@ +'use strict'; + +// Declare app level module which depends on filters, and services +angular.module('j2admin', [ + 'ngRoute', + 'ngGrid', + 'ui.bootstrap', + 'ngCookies', + 'j2admin.filters', +// 'j2admin.services', + 'j2admin.directives', + 'j2admin.controllers' +]) + .factory('ServerService', ['$cookies', ServerService]) + .factory('TextMessages', [TextMessages]) + .factory('DataService', ['$http', '$q', 'ServerService', RestService]) + .factory('PortletService', ['$http', '$q', 'ServerService', PortletService]) + .config(['$routeProvider', function ($routeProvider) { + $routeProvider.when('/monitor', {templateUrl: 'views/monitor.html'}); + $routeProvider.otherwise({redirectTo: '/monitor'}); + }]); Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/angular-cookies.js URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/angular-cookies.js?rev=1662855&view=auto ============================================================================== --- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/angular-cookies.js (added) +++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/bower_components/angular-cookies.js Fri Feb 27 23:33:58 2015 @@ -0,0 +1,206 @@ +/** + * @license AngularJS v1.3.11 + * (c) 2010-2014 Google, Inc. http://angularjs.org + * License: MIT + */ +(function(window, angular, undefined) {'use strict'; + +/** + * @ngdoc module + * @name ngCookies + * @description + * + * # ngCookies + * + * The `ngCookies` module provides a convenient wrapper for reading and writing browser cookies. + * + * + * <div doc-module-components="ngCookies"></div> + * + * See {@link ngCookies.$cookies `$cookies`} and + * {@link ngCookies.$cookieStore `$cookieStore`} for usage. + */ + + +angular.module('ngCookies', ['ng']). + /** + * @ngdoc service + * @name $cookies + * + * @description + * Provides read/write access to browser's cookies. + * + * Only a simple Object is exposed and by adding or removing properties to/from this object, new + * cookies are created/deleted at the end of current $eval. + * The object's properties can only be strings. + * + * Requires the {@link ngCookies `ngCookies`} module to be installed. + * + * @example + * + * ```js + * angular.module('cookiesExample', ['ngCookies']) + * .controller('ExampleController', ['$cookies', function($cookies) { + * // Retrieving a cookie + * var favoriteCookie = $cookies.myFavorite; + * // Setting a cookie + * $cookies.myFavorite = 'oatmeal'; + * }]); + * ``` + */ + factory('$cookies', ['$rootScope', '$browser', function($rootScope, $browser) { + var cookies = {}, + lastCookies = {}, + lastBrowserCookies, + runEval = false, + copy = angular.copy, + isUndefined = angular.isUndefined; + + //creates a poller fn that copies all cookies from the $browser to service & inits the service + $browser.addPollFn(function() { + var currentCookies = $browser.cookies(); + if (lastBrowserCookies != currentCookies) { //relies on browser.cookies() impl + lastBrowserCookies = currentCookies; + copy(currentCookies, lastCookies); + copy(currentCookies, cookies); + if (runEval) $rootScope.$apply(); + } + })(); + + runEval = true; + + //at the end of each eval, push cookies + //TODO: this should happen before the "delayed" watches fire, because if some cookies are not + // strings or browser refuses to store some cookies, we update the model in the push fn. + $rootScope.$watch(push); + + return cookies; + + + /** + * Pushes all the cookies from the service to the browser and verifies if all cookies were + * stored. + */ + function push() { + var name, + value, + browserCookies, + updated; + + //delete any cookies deleted in $cookies + for (name in lastCookies) { + if (isUndefined(cookies[name])) { + $browser.cookies(name, undefined); + } + } + + //update all cookies updated in $cookies + for (name in cookies) { + value = cookies[name]; + if (!angular.isString(value)) { + value = '' + value; + cookies[name] = value; + } + if (value !== lastCookies[name]) { + $browser.cookies(name, value); + updated = true; + } + } + + //verify what was actually stored + if (updated) { + updated = false; + browserCookies = $browser.cookies(); + + for (name in cookies) { + if (cookies[name] !== browserCookies[name]) { + //delete or reset all cookies that the browser dropped from $cookies + if (isUndefined(browserCookies[name])) { + delete cookies[name]; + } else { + cookies[name] = browserCookies[name]; + } + updated = true; + } + } + } + } + }]). + + + /** + * @ngdoc service + * @name $cookieStore + * @requires $cookies + * + * @description + * Provides a key-value (string-object) storage, that is backed by session cookies. + * Objects put or retrieved from this storage are automatically serialized or + * deserialized by angular's toJson/fromJson. + * + * Requires the {@link ngCookies `ngCookies`} module to be installed. + * + * @example + * + * ```js + * angular.module('cookieStoreExample', ['ngCookies']) + * .controller('ExampleController', ['$cookieStore', function($cookieStore) { + * // Put cookie + * $cookieStore.put('myFavorite','oatmeal'); + * // Get cookie + * var favoriteCookie = $cookieStore.get('myFavorite'); + * // Removing a cookie + * $cookieStore.remove('myFavorite'); + * }]); + * ``` + */ + factory('$cookieStore', ['$cookies', function($cookies) { + + return { + /** + * @ngdoc method + * @name $cookieStore#get + * + * @description + * Returns the value of given cookie key + * + * @param {string} key Id to use for lookup. + * @returns {Object} Deserialized cookie value. + */ + get: function(key) { + var value = $cookies[key]; + return value ? angular.fromJson(value) : value; + }, + + /** + * @ngdoc method + * @name $cookieStore#put + * + * @description + * Sets a value for given cookie key + * + * @param {string} key Id for the `value`. + * @param {Object} value Value to be stored. + */ + put: function(key, value) { + $cookies[key] = angular.toJson(value); + }, + + /** + * @ngdoc method + * @name $cookieStore#remove + * + * @description + * Remove given cookie + * + * @param {string} key Id of the key-value pair to delete. + */ + remove: function(key) { + delete $cookies[key]; + } + }; + + }]); + + +})(window, window.angular); --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscr...@portals.apache.org For additional commands, e-mail: jetspeed-dev-h...@portals.apache.org