You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by pr...@apache.org on 2014/04/17 04:43:28 UTC
[48/52] [partial] forking carbon ui bundle in to stratos code base
and removing license incompatible JS and packing the new module to carbon
runtime, through dropins
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/JspServlet.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/JspServlet.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/JspServlet.java
new file mode 100644
index 0000000..7e2792f
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/JspServlet.java
@@ -0,0 +1,458 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.ui;
+
+import org.osgi.framework.Bundle;
+
+import javax.servlet.*;
+import javax.servlet.descriptor.JspConfigDescriptor;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.util.*;
+
+/**
+ * <p>
+ * JSPServlet wraps the Apache Jasper Servlet making it appropriate for running in an OSGi environment under the Http Service.
+ * The Jasper JSPServlet makes use of the Thread Context Classloader to support compile and runtime of JSPs and to accommodate running
+ * in an OSGi environment, a Bundle is used to provide the similar context normally provided by the webapp.
+ * </p>
+ * <p>
+ * The Jasper Servlet will search the ServletContext to find JSPs, tag library descriptors, and additional information in the web.xml
+ * as per the JSP 2.0 specification. In addition to the ServletContext this implementation will search the bundle (but not attached
+ * fragments) for matching resources in a manner consistent with the Http Service's notion of a resource. By using alias and bundleResourcePath the JSP lookup should be in
+ * line with the resource mapping specified in {102.4} of the OSGi HttpService.
+ * </p>
+ * <p>
+ * TLD discovery is slightly different, to clarify it occurs in one of three ways:
+ * <ol>
+ * <li> declarations found in /WEB-INF/web.xml (found either on the bundleResourcePath in the bundle or in the ServletContext)</li>
+ * <li> tld files found under /WEB-INF (found either on the bundleResourcePath in the bundle or in the ServletContext)</li>
+ * <li> tld files found in jars on the Bundle-Classpath (see org.eclipse.equinox.internal.jsp.jasper.JSPClassLoader)</li>
+ * </ol>
+ * </p>
+ * <p>
+ * Other than the setting and resetting of the thread context classloader and additional resource lookups in the bundle the JSPServlet
+ * is behaviourally consistent with the JSP 2.0 specification and regular Jasper operation.
+ * </p>
+ */
+public class JspServlet extends HttpServlet {
+
+ private static class BundlePermissionCollection extends PermissionCollection {
+ private Bundle bundle;
+
+ public BundlePermissionCollection(Bundle bundle) {
+ this.bundle = bundle;
+ super.setReadOnly();
+ }
+
+ public void add(Permission permission) {
+ throw new SecurityException();
+ }
+
+ public boolean implies(Permission permission) {
+ return bundle.hasPermission(permission);
+ }
+
+ public Enumeration elements() {
+ return Collections.enumeration(Collections.EMPTY_LIST);
+ }
+ }
+
+ private Servlet jspServlet = new org.apache.jasper.servlet.JspServlet();
+ Bundle bundle;
+ private BundlePermissionCollection bundlePermissions;
+ private URLClassLoader jspLoader;
+ private String bundleResourcePath;
+ private String alias;
+ private UIResourceRegistry uiResourceRegistry;
+
+ public JspServlet(Bundle bundle, UIResourceRegistry uiResourceRegistry, String alias) {
+ this.bundle = bundle;
+ this.uiResourceRegistry = uiResourceRegistry;
+ this.alias = (alias == null || alias.equals("/")) ? null : alias; //$NON-NLS-1$
+ try {
+ if (System.getSecurityManager() != null) {
+ bundlePermissions = new BundlePermissionCollection(bundle);
+ }
+ jspLoader = new JspClassLoader(bundle, bundlePermissions);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+ public JspServlet(Bundle bundle, UIResourceRegistry uiResourceRegistry) {
+ this(bundle, uiResourceRegistry, null);
+ }
+
+ public void init(ServletConfig config) throws ServletException {
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(jspLoader);
+ jspServlet.init(new ServletConfigAdaptor(config));
+ // If a SecurityManager is set we need to override the permissions collection set in Jasper's JSPRuntimeContext
+ if (System.getSecurityManager() != null) {
+ try {
+ Field jspRuntimeContextField = jspServlet.getClass().getDeclaredField("rctxt"); //$NON-NLS-1$
+ jspRuntimeContextField.setAccessible(true);
+ Object jspRuntimeContext = jspRuntimeContextField.get(jspServlet);
+ Field permissionCollectionField = jspRuntimeContext.getClass().getDeclaredField("permissionCollection"); //$NON-NLS-1$
+ permissionCollectionField.setAccessible(true);
+ permissionCollectionField.set(jspRuntimeContext, bundlePermissions);
+ } catch (Exception e) {
+ throw new ServletException("Cannot initialize JSPServlet. Failed to set JSPRuntimeContext permission collection."); //$NON-NLS-1$
+ }
+ }
+ } finally {
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+
+ public void destroy() {
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(jspLoader);
+ jspServlet.destroy();
+ } finally {
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+
+ public void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException,
+ IOException {
+ String pathInfo = request.getPathInfo();
+ if (pathInfo != null && pathInfo.startsWith("/WEB-INF/")) { //$NON-NLS-1$
+ response.sendError(HttpServletResponse.SC_NOT_FOUND);
+ return;
+ }
+
+ ClassLoader original = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(jspLoader);
+ jspServlet.service(request, response);
+ } finally {
+ Thread.currentThread().setContextClassLoader(original);
+ }
+ }
+
+ public ServletConfig getServletConfig() {
+ return jspServlet.getServletConfig();
+ }
+
+ public String getServletInfo() {
+ return jspServlet.getServletInfo();
+ }
+
+ public class ServletConfigAdaptor implements ServletConfig {
+ private ServletConfig config;
+ private ServletContext context;
+
+ public ServletConfigAdaptor(ServletConfig config) {
+ this.config = config;
+ this.context = new ServletContextAdaptor(config.getServletContext());
+ }
+
+ public String getInitParameter(String arg0) {
+ return config.getInitParameter(arg0);
+ }
+
+ public Enumeration getInitParameterNames() {
+ return config.getInitParameterNames();
+ }
+
+ public ServletContext getServletContext() {
+ return context;
+ }
+
+ public String getServletName() {
+ return config.getServletName();
+ }
+ }
+
+ public class ServletContextAdaptor implements ServletContext {
+ private ServletContext delegate;
+
+ public ServletContextAdaptor(ServletContext delegate) {
+ this.delegate = delegate;
+ }
+
+ public URL getResource(String name) throws MalformedURLException {
+ if (alias != null && name.startsWith(alias)) {
+ name = name.substring(alias.length());
+ }
+
+ URL url = uiResourceRegistry.getUIResource(name);
+ if (url != null) {
+ return url;
+ }
+
+ return delegate.getResource(name);
+ }
+
+ public InputStream getResourceAsStream(String name) {
+ try {
+ URL resourceURL = getResource(name);
+ if (resourceURL != null) {
+ return resourceURL.openStream();
+ }
+ } catch (IOException e) {
+ log("Error opening stream for resource '" + name + "'",
+ e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return null;
+ }
+
+ public Set getResourcePaths(String name) {
+ Set<String> result = delegate.getResourcePaths(name);
+ Set<String> resultFromProviders = uiResourceRegistry.getUIResourcePaths(name);
+
+ //Merging two sets.
+ if (resultFromProviders != null && result != null) {
+ for (String resourcePath : resultFromProviders) {
+ result.add(resourcePath);
+ }
+ return result;
+ } else if (resultFromProviders != null) {
+ return resultFromProviders;
+ } else {
+ return result;
+ }
+
+ }
+
+ public RequestDispatcher getRequestDispatcher(String arg0) {
+ return delegate.getRequestDispatcher(arg0);
+ }
+
+ public Object getAttribute(String arg0) {
+ return delegate.getAttribute(arg0);
+ }
+
+ public Enumeration getAttributeNames() {
+ return delegate.getAttributeNames();
+ }
+
+ public ServletContext getContext(String arg0) {
+ return delegate.getContext(arg0);
+ }
+
+ public String getInitParameter(String arg0) {
+ return delegate.getInitParameter(arg0);
+ }
+
+ public Enumeration getInitParameterNames() {
+ return delegate.getInitParameterNames();
+ }
+
+ public boolean setInitParameter(String s, String s1) {
+ return delegate.setInitParameter(s,s1);
+ }
+
+ public int getMajorVersion() {
+ return delegate.getMajorVersion();
+ }
+
+ public String getMimeType(String arg0) {
+ return delegate.getMimeType(arg0);
+ }
+
+ public int getMinorVersion() {
+ return delegate.getMinorVersion();
+ }
+
+ public int getEffectiveMajorVersion() {
+ return delegate.getEffectiveMajorVersion();
+ }
+
+ public int getEffectiveMinorVersion() {
+ return delegate.getEffectiveMinorVersion();
+ }
+
+ public RequestDispatcher getNamedDispatcher(String arg0) {
+ return delegate.getNamedDispatcher(arg0);
+ }
+
+ public String getRealPath(String arg0) {
+ return delegate.getRealPath(arg0);
+ }
+
+ public String getServerInfo() {
+ return delegate.getServerInfo();
+ }
+
+ /**
+ * @deprecated *
+ */
+ public Servlet getServlet(String arg0) throws ServletException {
+ return delegate.getServlet(arg0);
+ }
+
+ public String getServletContextName() {
+ return delegate.getServletContextName();
+ }
+
+ public ServletRegistration.Dynamic addServlet(String s, String s1) {
+ return delegate.addServlet(s, s1);
+ }
+
+ public ServletRegistration.Dynamic addServlet(String s, Servlet servlet) {
+ return delegate.addServlet(s, servlet);
+ }
+
+ public ServletRegistration.Dynamic addServlet(String s, Class<? extends Servlet> aClass) {
+ return delegate.addServlet(s, aClass);
+ }
+
+ public <T extends Servlet> T createServlet(Class<T> tClass) throws ServletException {
+ return delegate.createServlet(tClass);
+ }
+
+ public ServletRegistration getServletRegistration(String s) {
+ return delegate.getServletRegistration(s);
+ }
+
+ public Map<String, ? extends ServletRegistration> getServletRegistrations() {
+ return delegate.getServletRegistrations();
+ }
+
+ public FilterRegistration.Dynamic addFilter(String s, String s1) {
+ return delegate.addFilter(s,s1);
+ }
+
+ public FilterRegistration.Dynamic addFilter(String s, Filter filter) {
+ return delegate.addFilter(s, filter);
+ }
+
+ public FilterRegistration.Dynamic addFilter(String s, Class<? extends Filter> aClass) {
+ return delegate.addFilter(s, aClass);
+ }
+
+ public <T extends Filter> T createFilter(Class<T> tClass) throws ServletException {
+ return delegate.createFilter(tClass);
+ }
+
+ public FilterRegistration getFilterRegistration(String s) {
+ return delegate.getFilterRegistration(s);
+ }
+
+ public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
+ return delegate.getFilterRegistrations();
+ }
+
+ public SessionCookieConfig getSessionCookieConfig() {
+ return delegate.getSessionCookieConfig();
+ }
+
+ public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes) throws IllegalStateException, IllegalArgumentException {
+ delegate.setSessionTrackingModes(sessionTrackingModes);
+ }
+
+ public Set<SessionTrackingMode> getDefaultSessionTrackingModes() {
+ return delegate.getDefaultSessionTrackingModes();
+ }
+
+ public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() {
+ return delegate.getEffectiveSessionTrackingModes();
+ }
+
+ public void addListener(Class<? extends EventListener> aClass) {
+ delegate.addListener(aClass);
+ }
+
+ public void addListener(String s) {
+ delegate.addListener(s);
+ }
+
+ public <T extends EventListener> void addListener(T t) {
+ delegate.addListener(t);
+ }
+
+ public <T extends EventListener> T createListener(Class<T> tClass) throws ServletException {
+ return delegate.createListener(tClass);
+ }
+
+ public void declareRoles(String... strings) {
+ delegate.declareRoles(strings);
+ }
+
+ public ClassLoader getClassLoader() {
+ return delegate.getClassLoader();
+ }
+
+ public JspConfigDescriptor getJspConfigDescriptor() {
+ return delegate.getJspConfigDescriptor();
+ }
+
+ /**
+ * @deprecated *
+ */
+ public Enumeration getServletNames() {
+ return delegate.getServletNames();
+ }
+
+ /**
+ * @deprecated *
+ */
+ public Enumeration getServlets() {
+ return delegate.getServlets();
+ }
+
+ /**
+ * @deprecated *
+ */
+ public void log(Exception arg0, String arg1) {
+ delegate.log(arg0, arg1);
+ }
+
+ public void log(String arg0, Throwable arg1) {
+ delegate.log(arg0, arg1);
+ }
+
+ public void log(String arg0) {
+ delegate.log(arg0);
+ }
+
+ public void removeAttribute(String arg0) {
+ delegate.removeAttribute(arg0);
+ }
+
+ public void setAttribute(String arg0, Object arg1) {
+ delegate.setAttribute(arg0, arg1);
+ }
+
+ // Added in Servlet 2.5
+ public String getContextPath() {
+ try {
+ Method getContextPathMethod =
+ delegate.getClass().getMethod("getContextPath", null); //$NON-NLS-1$
+ return (String) getContextPathMethod.invoke(delegate, null);
+ } catch (Exception e) {
+ // ignore
+ }
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/MenuAdminClient.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/MenuAdminClient.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/MenuAdminClient.java
new file mode 100644
index 0000000..ab51b62
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/MenuAdminClient.java
@@ -0,0 +1,735 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.wso2.carbon.ui;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.wso2.carbon.ui.deployment.beans.BreadCrumbItem;
+import org.wso2.carbon.ui.deployment.beans.CarbonUIDefinitions;
+import org.wso2.carbon.ui.deployment.beans.Menu;
+import org.wso2.carbon.utils.ServerConstants;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.*;
+
+public class MenuAdminClient {
+ private static Log log = LogFactory.getLog(MenuAdminClient.class);
+ private Menu[] menus;
+ private StringBuffer menuContent;
+ private Map<String, Menu> parentMenuItems;
+ private Map<String, ArrayList<Menu>> childMenuItems;
+ private Map<String, String> breadcrumbMap = new HashMap<String, String>();
+ //eg: holds ../service-mgt/index.jsp : region1,services_list_menu
+ private Map<String, String> indexPageBreadcrumbParamMap;
+ public static final String USER_MENU_ITEMS = "UserMenuItems";
+ public static final String USER_CUSTOM_MENU_ITEMS = "UserCustomMenuItems";
+ public static final String USER_MENU_ITEMS_FILTERED = "UserMenuItemsFiltered";
+
+ public MenuAdminClient() {
+
+ }
+
+ public Map<String, String> getBreadcrumbMap() {
+ return breadcrumbMap;
+ }
+
+ public void setBreadcrumbMap(HashMap<String, String> breadcrumbMap) {
+ this.breadcrumbMap = breadcrumbMap;
+ }
+
+ /**
+ * Calls the OSGi service for UI & retrieves Menu definitions
+ */
+ private void populateMenuDefinitionsFromOSGiService(String loggedInUserName
+ ,boolean isSuperTenant
+ ,ArrayList<String> userPermission
+ ,HttpServletRequest request) {
+
+ if(loggedInUserName != null){
+ //A user has logged in, get menus from user's session
+ Menu[] userMenus = (Menu[]) request.getSession().getAttribute(USER_MENU_ITEMS);
+ if (userMenus != null) {
+ Set<Menu> menuList = new LinkedHashSet<Menu>();
+ menuList.addAll(Arrays.<Menu>asList(userMenus));
+ Menu[] customMenus = (Menu[]) request.getSession().getAttribute(USER_CUSTOM_MENU_ITEMS);
+ if (customMenus != null) {
+ menuList.addAll(Arrays.<Menu>asList(customMenus));
+ }
+ menus = menuList.toArray(new Menu[menuList.size()]);
+ }
+ if (menus == null){
+ setDefaultMenus(loggedInUserName, isSuperTenant, userPermission, request);
+ }
+
+ String filtered = (String)request.getSession().getAttribute(MenuAdminClient.USER_MENU_ITEMS_FILTERED);
+ if("false".equals(filtered)){
+ CarbonUIDefinitions o = new CarbonUIDefinitions();
+ Menu[] filteredMenus = o.getMenuDefinitions(loggedInUserName, isSuperTenant, userPermission, request, menus);
+ menus = filteredMenus;
+ request.getSession().setAttribute(USER_MENU_ITEMS,menus);
+ }
+ if(menus != null){
+ if(log.isDebugEnabled()){
+ log.debug("Loaded menu items from user session");
+ }
+ return;
+ }
+ }
+
+ setDefaultMenus(loggedInUserName, isSuperTenant, userPermission, request);
+ }
+
+ private void setDefaultMenus(String loggedInUserName,
+ boolean isSuperTenant,
+ ArrayList<String> userPermission,
+ HttpServletRequest request) {
+ BundleContext bundleContext = CarbonUIUtil.getBundleContext();
+ if (bundleContext != null) {
+ ServiceReference reference = bundleContext.getServiceReference(CarbonUIDefinitions.class.getName());
+ CarbonUIDefinitions carbonUIDefinitions;
+ if (reference != null) {
+ carbonUIDefinitions = (CarbonUIDefinitions) bundleContext.getService(reference);
+ Menu[] userMenus = carbonUIDefinitions.getMenuDefinitions(loggedInUserName,
+ isSuperTenant, userPermission,request);
+ if (userMenus != null) {
+ Set<Menu> menuList = new LinkedHashSet<Menu>();
+ menuList.addAll(Arrays.<Menu>asList(userMenus));
+ Menu[] customMenus =
+ (Menu[]) request.getSession().getAttribute(USER_CUSTOM_MENU_ITEMS);
+ if (customMenus != null) {
+ menuList.addAll(Arrays.<Menu>asList(customMenus));
+ }
+ menus = menuList.toArray(new Menu[menuList.size()]);
+ if (log.isDebugEnabled()) {
+ log.debug("Found exiting menu items in OSGI context");
+ }
+ }
+ }
+ }
+ }
+
+ private String findNavigationPathFromRoot(String lastMenuItem, String path) {
+ for (int a = 0; a < menus.length; a++) {
+ Menu menu = menus[a];
+ if (log.isDebugEnabled()) {
+ log.debug(a + " : " + lastMenuItem + " : " + menu.getId());
+ }
+ if (menu.getId() != null && menu.getId().equals(lastMenuItem)) {
+ //path = ":"+menu.getI18nKey()+"#"+menu.getI18nBundle() + path;
+ path = "," + menu.getId() + path;
+ String parentMenuId = menu.getParentMenu();
+ if (parentMenuId.trim().length() > 0) {
+ path = findNavigationPathFromRoot(parentMenuId, path);
+ } else {
+ break;
+ }
+ }
+ }
+ return path;
+ }
+
+ /**
+ *
+ */
+ public void setBreadCrumbMap(HttpServletRequest request) {
+ Locale locale;
+ HashMap<String, BreadCrumbItem> breadCrumbs = new HashMap<String, BreadCrumbItem>();
+ if (menus != null) {
+ for (int a = 0; a < menus.length; a++) {
+ Menu menu = menus[a];
+ if (menu.getId() != null) {
+ BreadCrumbItem bc = new BreadCrumbItem();
+ CarbonUIUtil.setLocaleToSession(request);
+
+ locale = CarbonUIUtil.getLocaleFromSession(request);
+ java.util.ResourceBundle bundle = null;
+ try {
+ if(menu.getI18nBundle() != null){
+ bundle = java.util.ResourceBundle.getBundle(menu.getI18nBundle(), locale);
+ }
+ } catch (java.util.MissingResourceException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Cannot find resource bundle : " + menu.getI18nBundle());
+ }
+ }
+
+ String menuText = menu.getI18nKey();
+ if (bundle != null) {
+ String tmp = null;
+ try {
+ if(menu.getI18nKey() != null){
+ tmp = bundle.getString(menu.getI18nKey());
+ }
+ } catch (java.util.MissingResourceException e) {
+ //Missing key should not be a blocking factor for UI rendering
+ if (log.isDebugEnabled()) {
+ log.debug("Cannot find resource for key :" + menu.getI18nKey());
+ }
+ }
+ if (tmp != null) {
+ menuText = tmp;
+ }
+ }
+
+ bc.setConvertedText(menuText);
+ bc.setI18nBundle(menu.getI18nBundle());
+ bc.setI18nKey(menu.getI18nKey());
+ bc.setId(menu.getId());
+ bc.setLink(menu.getLink() + "?region=" + menu.getRegion() + "&item=" +
+ menu.getId() + (menu.getUrlParameters() != null ?
+ "&" + menu.getUrlParameters() : "") + "&ordinal=0");
+ breadCrumbs.put(menu.getId(), bc);
+ }
+ }
+ }
+ request.getSession().setAttribute("breadcrumbs", breadCrumbs);
+ }
+
+ /**
+ * Returns left hand side menu as a String
+ *
+ * @param region
+ */
+ public String getMenuContent(String region, HttpServletRequest request) {
+ boolean authenticated = isAuthenticated(request);
+ ArrayList<String> userPermission = new ArrayList<String>();
+
+ String loggedInUserName = null;
+ boolean isSuperTenant = false;
+ if (authenticated) {
+ loggedInUserName = (String) request.getSession().getAttribute(CarbonSecuredHttpContext.LOGGED_USER);
+ userPermission = (ArrayList<String>) request.getSession().getAttribute(ServerConstants.USER_PERMISSIONS);
+ isSuperTenant = CarbonUIUtil.isSuperTenant(request);
+ }
+
+
+ populateMenuDefinitionsFromOSGiService(loggedInUserName,isSuperTenant,userPermission,request);
+ //populate();
+ checkForIndexPageBreadcrumbParamMap(request);
+ if (menus != null && menus.length > 0) {
+ if (log.isDebugEnabled()) {
+ log.debug("Size of menu items for region : " + region + " is " + menus.length);
+ for (int a = 0; a < menus.length; a++) {
+ log.debug(menus[a]);
+ }
+ }
+
+ menuContent = new StringBuffer();
+ appendMenuHeader();
+ if (region.equals("region1")) {
+ Locale locale =CarbonUIUtil.getLocaleFromSession(request);
+ appendHomeLink(locale);
+ }
+
+ //build a hierarchy of MenuItems
+ parentMenuItems = new HashMap<String, Menu>();
+ childMenuItems = new HashMap<String, ArrayList<Menu>>();
+
+ for (int a = 0; a < menus.length; a++) {
+ boolean display = false;
+ if (!authenticated) {
+ if (!menus[a].getRequireAuthentication()) {
+ display = true;
+ }
+ } else {
+ //display all menu items for logged in user
+ display = true;
+ }
+
+ if (region.equals(menus[a].getRegion()) && display) {
+ if ("".equals(menus[a].getParentMenu())) {
+ parentMenuItems.put(menus[a].getId(), menus[a]);
+ } else {
+ ArrayList<Menu> childMenus = (ArrayList) childMenuItems.get(menus[a].getParentMenu());
+ if (childMenus != null && childMenus.size() > 0) {
+ childMenus.add(menus[a]);
+ } else {
+ ArrayList<Menu> tmp = new ArrayList();
+ tmp.add(menus[a]);
+ childMenuItems.put(menus[a].getParentMenu(), tmp);
+ }
+ }
+ }
+ }
+
+ //Iterate through the parent menu items & build the menu style
+ String[] sortedParentMenuIds = sortMenuItems(parentMenuItems);
+ for (int a = 0; a < sortedParentMenuIds.length; a++) {
+ String key = sortedParentMenuIds[a];
+ Menu menu = (Menu) parentMenuItems.get(key);
+ ArrayList childMenusForParent = (ArrayList) childMenuItems.get(menu.getId());
+ if(childMenusForParent != null){ //if no child menu items, do not print the parent
+ menuContent.append(getHtmlForMenuItem(menu, request));
+ prepareHTMLForChildMenuItems(menu.getId(), request);
+ }
+ }
+ //Old way of generating menu items without ordering
+/*
+ Iterator itrParentMenuKeys = parentMenuItems.keySet().iterator();
+ while(itrParentMenuKeys.hasNext()){
+ String key = (String)itrParentMenuKeys.next();
+ Menu menu = (Menu)parentMenuItems.get(key);
+ menuContent.append(getHtmlForMenuItem(menu,locale));
+ prepareHTMLForChildMenuItems(key,locale);
+ }
+*/
+ appendMenuFooter();
+ request.getSession().setAttribute(region + "menu-id-breadcrumb-map", breadcrumbMap);
+ request.getSession().setAttribute("index-page-breadcrumb-param-map", indexPageBreadcrumbParamMap);
+
+ return menuContent.toString();
+ } else {
+ //no menu, return empty String
+ return "";
+ }
+ }
+
+ private void checkForIndexPageBreadcrumbParamMap(HttpServletRequest request) {
+ HashMap<String, String> tmp = (HashMap<String, String>) request.getSession().getAttribute("index-page-breadcrumb-param-map");
+ if (tmp != null) {
+ this.indexPageBreadcrumbParamMap = tmp;
+ } else {
+ this.indexPageBreadcrumbParamMap = new HashMap<String, String>();
+ }
+ }
+
+ /**
+ * check for authenticated session
+ *
+ * @param request
+ * @return
+ */
+ private boolean isAuthenticated(HttpServletRequest request) {
+ Boolean authenticatedObj = (Boolean) request.getSession().getAttribute("authenticated");
+ boolean authenticated = false;
+ if (authenticatedObj != null) {
+ authenticated = authenticatedObj.booleanValue();
+ }
+ return authenticated;
+ }
+
+ /**
+ * @param menuItems
+ * @return
+ */
+ private String[] sortMenuItems(Map menuItems) {
+ Iterator itrMenuKeys = menuItems.keySet().iterator();
+ int[] menuOrder = new int[menuItems.size()];
+ String[] menuIds = new String[menuItems.size()];
+
+ int index = 0;
+ while (itrMenuKeys.hasNext()) {
+ String key = (String) itrMenuKeys.next();
+ Menu menu = (Menu) menuItems.get(key);
+ int ordinal;
+ try {
+ ordinal = Integer.parseInt(menu.getOrder());
+ } catch (NumberFormatException e) {
+ //if provided value is NaN, this menu item deserves the last position ;-)
+ ordinal = 200;
+ log.debug("Hey...whoever defined the menu item : " + menu.getId()
+ + ",please provide a integer value for 'order'", e);
+ }
+ menuOrder[index] = ordinal;
+ menuIds[index] = menu.getId();
+ index++;
+ }
+ sortArray(menuOrder, menuIds);
+ return menuIds;
+ }
+
+ /**
+ * @param parentMenuId
+ */
+ private void prepareHTMLForChildMenuItems(String parentMenuId, HttpServletRequest request) {
+ Locale locale = request.getLocale();
+ ArrayList childMenusForParent = (ArrayList) childMenuItems.get(parentMenuId);
+ if (childMenusForParent != null) {
+ //create a hashmap of child Menu items for parent
+ Iterator itrChildMenusForParent = childMenusForParent.iterator();
+ HashMap childMenus = new HashMap();
+ for (; itrChildMenusForParent.hasNext();) {
+ Menu menu = (Menu) itrChildMenusForParent.next();
+ childMenus.put(menu.getId(), menu);
+ }
+ String[] sortedMenuIds = sortMenuItems(childMenus);
+
+ if (sortedMenuIds.length > 0) {
+ menuContent.append("<li class=\"normal\">");
+ menuContent.append("<ul class=\"sub\">");
+ for (int a = 0; a < sortedMenuIds.length; a++) {
+ Menu menu = (Menu) childMenus.get(sortedMenuIds[a]);
+
+ ArrayList childs = (ArrayList) childMenuItems.get(menu.getId());
+ if(childs == null){
+ if(! menu.getLink().equals("#") && menu.getLink().trim().length() > 0){
+ //This is the last menu item, print it
+ menuContent.append(getHtmlForMenuItem(menu, request));
+ }
+ }else{
+ //If no childs & current menu item does not contain an link
+ //do not print
+ menuContent.append(getHtmlForMenuItem(menu, request));
+ prepareHTMLForChildMenuItems(menu.getId(), request);
+ }
+ }
+ menuContent.append("</ul>");
+ menuContent.append("</li>");
+ }
+ }
+ }
+
+ /**
+ * @param menu
+ * @return
+ */
+ private String getHtmlForMenuItem(Menu menu, HttpServletRequest request) {
+ Locale locale;
+ CarbonUIUtil.setLocaleToSession(request);
+ locale = CarbonUIUtil.getLocaleFromSession(request);
+ java.util.ResourceBundle bundle = null;
+ try {
+ if (menu.getI18nBundle() != null) {
+ bundle = java.util.ResourceBundle.getBundle(menu.getI18nBundle(), locale);
+ }
+ } catch (MissingResourceException e) {
+ if(log.isDebugEnabled()){
+ log.debug("Cannot find resource bundle : "+menu.getI18nBundle());
+ }
+ }
+
+ String menuText = menu.getI18nKey();
+ if (bundle != null) {
+ String tmp = null;
+ try {
+ tmp = bundle.getString(menu.getI18nKey());
+ } catch (MissingResourceException e) {
+ //Missing key should not be a blocking factor for UI rendering
+
+ if(log.isDebugEnabled()){
+ log.debug("Cannot find resource for key :"+menu.getI18nKey());
+ }
+ }
+ if (tmp != null) {
+ menuText = tmp;
+ }
+ }
+
+ String html = "";
+ if (menu.getParentMenu().trim().length() == 0
+ || menu.getLink().trim().length() == 0) {
+ html = "<li id=\""
+ +menu.getRegion()
+ +"_"+ menu.getId()
+ +"\" class=\"menu-header\" onclick=\"mainMenuCollapse(this.childNodes[0])\" style=\"cursor:pointer\">"
+ + "<img src=\"../admin/images/up-arrow.gif\" " +
+ "class=\"mMenuHeaders\" id=\""+menu.getRegion()+"_"+ menu.getId()+"\"/>"
+ + menuText
+ + "</li>";
+ } else {
+ String link = menu.getLink() + "?region=" + menu.getRegion() + "&item=" + menu.getId();
+
+ //if user has set url parameters, append it to link
+ String urlParameters = menu.getUrlParameters();
+ if(urlParameters != null && urlParameters.trim().length() > 0){
+ link = link +"&"+menu.getUrlParameters();
+ }
+
+ String iconPath = "../admin/images/default-menu-icon.gif";
+ if (menu.getIcon() != null && menu.getIcon().trim().length() > 0) {
+ iconPath = menu.getIcon();
+ }
+ String breadCrumbPath = findNavigationPathFromRoot(menu.getId(), "");
+ breadCrumbPath = breadCrumbPath.replaceFirst(",", "");
+ breadcrumbMap.put(menu.getRegion().trim() + "-" + menu.getId().trim(), breadCrumbPath);
+ String params = menu.getRegion().trim() + "," + menu.getId().trim();
+ indexPageBreadcrumbParamMap.put(link, params);
+
+ String style = "";
+ if (menu.getLink().equals("#")) {
+ style = "menu-disabled-link";
+ html = "<li class=\"" + style + "\" style=\"background-image: url(" + iconPath + ");\">"+ menuText + "</li>" + "\n";
+ } else {
+ style = "menu-default";
+ html = "<li><a href=\"" + link + "\" class=\"" + style + "\" style=\"background-image: url(" + iconPath + ");\">" + menuText + "</a></li>" + "\n";
+ }
+
+ //html = "<li><a href=\"" + menu.getLink() + "?region=" + menu.getRegion() + "&item=" + menu.getId() + "\" class=\"" + style + "\" style=\"background-image: url(" + iconPath + ");\">" + menuText + "</a></li>" + "\n";
+ }
+ return html;
+ }
+
+
+ private void appendHomeLink(Locale locale) {
+ String homeText = CarbonUIUtil.geti18nString("component.home", "org.wso2.carbon.i18n.Resources", locale);
+ menuContent.append("<li><a href=\""+ CarbonUIUtil.getHomePage() +"\" class=\"menu-home\">"+homeText+"</a></li>");
+ }
+
+ /**
+ *
+ */
+ private void appendMenuHeader() {
+ menuContent.append("<div id=\"menu\">");
+ menuContent.append(" <ul class=\"main\">");
+ }
+
+ /**
+ *
+ */
+ private void appendMenuFooter() {
+ menuContent.append(" </ul>");
+ menuContent.append("</div>");
+ }
+
+ /**
+ * @param a
+ * @param names
+ */
+ static void sortArray(int[] a, String[] names) {
+ for (int i = 0; i < a.length - 1; i++) {
+ for (int j = i + 1; j < a.length; j++) {
+ if (a[i] > a[j]) {
+ int temp = a[i];
+ String name = names[i];
+ a[i] = a[j];
+ names[i] = names[j];
+ a[j] = temp;
+ names[j] = name;
+ }
+ }
+ }
+ }
+
+
+ /**
+ * To be used only for testing purposes
+ *
+ * @param region
+ * @param locale
+ * @return
+ */
+ /*
+ static void printArray(int[] a) {
+ for (int i = 0; i < a.length; i++)
+ System.out.print(" " + a[i]);
+ System.out.print("\n");
+ }
+
+ static void printArray(String[] a) {
+ for (int i = 0; i < a.length; i++)
+ System.out.print(" " + a[i]);
+ System.out.print("\n");
+ }
+
+ public static void main(String[] args) {
+ int[] num = {1,7,4,3,6};
+ String[] names = {"nandika","dinuka","prabath","sumedha","chamara"};
+ printArray(num);
+ sortArray(num,names);
+ printArray(num);
+ printArray(names);
+ }
+
+ public String getStaticMenuContent(String region,Locale locale){
+ String menuContent = "";
+ if("region1".equals(region)){
+ menuContent =
+ "<div id=\"menu\">"+
+ "<div class=\"menu-content\">"+
+ " <ul class=\"main\">"+
+ " <li class=\"home\"><a href=\"../server-admin/index.jsp\">Home</a></li>"+
+ " <li class=\"manage\">Manage</li>"+
+ " <li class=\"normal\">"+
+ " <ul class=\"sub\">"+
+ " <li class=\"list-ds\"><a href=\"../service-mgt/service_mgt.jsp\">Services</a></li>"+
+ " <li>"+
+ " <ul class=\"sub\">"+
+ " <li class=\"list-ds\"><a href=\"../axis1/index.jsp\">Axis1</a></li>"+
+ " <li class=\"list-ds\"><a href=\"../bpel/index.jsp\">BPEL</a></li>"+
+ " <li class=\"list-ds\"><a href=\"../ejb/index.jsp\">EJB</a></li>"+
+ " <li class=\"list-ds\"><a href=\"../jaxws/index.jsp\">JAXWS</a></li>"+
+ " <li class=\"list-ds\"><a href=\"../pojo/index.jsp\">POJO</a></li>"+
+ " <li class=\"list-ds\"><a href=\"../spring/index.jsp\">JAXWS</a></li>"+
+ " </ul>"+
+ " </li>"+
+ " <li class=\"global\"><a href=\"../modulemgt/index.jsp\">Global Configurations</a></li>"+
+ " <li class=\"logging\"><a href=\"../log-admin/index.html\" >Logging</a></li>"+
+ " <li class=\"transports\"><a href=\"../transport-mgt/index.html\" >Transports</a></li>"+
+ " <li class=\"security\">Security</li>"+
+ " <li>"+
+ " <ul class=\"sub\">"+
+ " <li class=\"user-stores\"><a href=\"../security/userstoremgt/userstore-mgt.jsp\">User Stores</a></li>"+
+ " <li class=\"user-groups\"><a href=\"../security/usergroupmgt/usergroup-mgt.jsp\" >User Groups</a></li>"+
+ " <li class=\"keystores\"><a href=\"../security/keystoremgt/keystore-mgt.jsp\" >Keystores</a></li>"+
+ " <li class=\"users\"><a href=\"../security/usermgt/user-mgt.jsp\" >Users</a></li>"+
+ " </ul>"+
+ " </li>"+
+ " <li class=\"restart\"><a href=\"../server-admin/shutdown.jsp\">Shutdown/Restart</a></li>"+
+ " <li class=\"restart\"><a href=\"../viewflows/index.jsp\">Flows</a></li>"+
+ " </ul>"+
+ " </li>"+
+ " <li class=\"monitor\">Monitor</li>"+
+ " <li class=\"normal\">"+
+ " <ul class=\"sub\">"+
+ " <li class=\"logs\"><a href=\"../log-view/index.html\" >Logs</a></li>"+
+ " <li class=\"tracer\"><a href=\"../tracer/index.html\" >Tracer</a></li>"+
+ " <li class=\"stats\"><a href=\"../statistics/index.html\" >Statistics</a></li>"+
+ " </ul>"+
+ " </li>"+
+ " </ul>"+
+ "</div>"+
+ "<div class=\"menu-bottom\"></div>"+
+ "</div>";
+ }
+ return menuContent;
+ }
+
+ */
+
+ /*
+ public static void main(String[] args) {
+ MenuAdminClient a = new MenuAdminClient();
+ a.populate();
+ System.out.println(a.getMenuContent("region1",Locale.getDefault()));
+ //System.out.println(a.findNavigationPathFromRoot("security_user_stores",""));
+ }
+
+ private void populate(){
+ menus = new Menu[6];
+
+ menus[0] = new Menu();
+ menus[0].setId("root_home");
+ menus[0].setI18nKey("component.home");
+ menus[0].setI18nBundle("org.wso2.carbon.i18n.Resources");
+ menus[0].setParentMenu("");
+ menus[0].setLink("../home/link.html");
+ menus[0].setRegion("region1");
+ menus[0].setOrder("1");
+ menus[0].setIcon("../home/home.ico");
+ menus[0].setStyleClass("home");
+
+ menus[1] = new Menu();
+ menus[1].setId("root_manage");
+ menus[1].setI18nKey("component.manage");
+ menus[1].setI18nBundle("org.wso2.carbon.i18n.Resources");
+ menus[1].setParentMenu("");
+ menus[1].setLink("#");
+ menus[1].setRegion("region1");
+ menus[1].setOrder("2");
+ menus[1].setIcon("../home/manage.ico");
+ menus[1].setStyleClass("manage");
+
+ menus[2] = new Menu();
+ menus[2].setId("root_monitor");
+ menus[2].setI18nKey("component.monitor");
+ menus[2].setI18nBundle("org.wso2.carbon.i18n.Resources");
+ menus[2].setParentMenu("");
+ menus[2].setLink("#");
+ menus[2].setRegion("region1");
+ menus[2].setOrder("2");
+ menus[2].setIcon("../home/monitor.ico");
+ menus[2].setStyleClass("monitor");
+
+ menus[3] = new Menu();
+ menus[3].setId("manage_security");
+ menus[3].setI18nKey("manage.security");
+ menus[3].setI18nBundle("org.wso2.carbon.i18n.Resources");
+ menus[3].setParentMenu("root_manage");
+ menus[3].setLink("#");
+ menus[3].setRegion("region1");
+ menus[3].setOrder("2");
+ menus[3].setIcon("../home/security.ico");
+ menus[3].setStyleClass("security");
+
+
+ menus[4] = new Menu();
+ menus[4].setId("manage_transports");
+ menus[4].setI18nKey("manage.transports");
+ menus[4].setI18nBundle("org.wso2.carbon.i18n.Resources");
+ menus[4].setParentMenu("root_manage");
+ menus[4].setLink("#");
+ menus[4].setRegion("region1");
+ menus[4].setOrder("2");
+ menus[4].setIcon("../home/transports.ico");
+ menus[4].setStyleClass("transports");
+
+
+ menus[5] = new Menu();
+ menus[5].setId("security_user_stores");
+ menus[5].setI18nKey("security.user-stores");
+ menus[5].setI18nBundle("org.wso2.carbon.i18n.Resources");
+ menus[5].setParentMenu("manage_security");
+ menus[5].setLink("../security/userStore.jsp");
+ menus[5].setRegion("region1");
+ menus[5].setOrder("2");
+ menus[5].setIcon("../home/transports.ico");
+ menus[5].setStyleClass("user-stores");
+
+
+
+ menus[6] = new Menu();
+ menus[6].setId("security_user_groups");
+ menus[6].setI18nKey("security.user-groups");
+ menus[6].setI18nBundle("org.wso2.carbon.i18n.Resources");
+ menus[6].setParentMenu("manage_security");
+ menus[6].setLink("../security/userGroups.jsp");
+ menus[6].setRegion("region1");
+ menus[6].setOrder("2");
+ menus[6].setIcon("../home/transports.ico");
+ menus[6].setStyleClass("user-groups");
+
+ menus[7] = new Menu();
+ menus[7].setId("root_manage");
+ menus[7].setI18nKey("component.manage");
+ menus[7].setI18nBundle("org.wso2.carbon.i18n.Resources");
+ menus[7].setParentMenu("");
+ menus[7].setLink("#");
+ menus[7].setRegion("region2");
+ menus[7].setOrder("2");
+ menus[7].setIcon("../home/manage.ico");
+ menus[7].setStyleClass("manage");
+
+ menus[8] = new Menu();
+ menus[8].setId("security_user_stores");
+ menus[8].setI18nKey("security.user-stores");
+ menus[8].setI18nBundle("org.wso2.carbon.i18n.Resources");
+ menus[8].setParentMenu("manage_security");
+ menus[8].setLink("../security/userStore.jsp");
+ menus[8].setRegion("region2");
+ menus[8].setOrder("2");
+ menus[8].setIcon("../home/transports.ico");
+ menus[8].setStyleClass("user-stores");
+
+ menus[9] = new Menu();
+ menus[9].setId("manage_security");
+ menus[9].setI18nKey("manage.security");
+ menus[9].setI18nBundle("org.wso2.carbon.i18n.Resources");
+ menus[9].setParentMenu("root_manage");
+ menus[9].setLink("#");
+ menus[9].setRegion("region2");
+ menus[9].setOrder("2");
+ menus[9].setIcon("../home/security.ico");
+ menus[9].setStyleClass("security");
+ }
+ */
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/SecuredComponentEntryHttpContext.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/SecuredComponentEntryHttpContext.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/SecuredComponentEntryHttpContext.java
new file mode 100644
index 0000000..ca5b2af
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/SecuredComponentEntryHttpContext.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.ui;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.equinox.http.helper.BundleEntryHttpContext;
+import org.osgi.framework.Bundle;
+import org.wso2.carbon.registry.core.Registry;
+
+public class SecuredComponentEntryHttpContext extends BundleEntryHttpContext {
+
+ private String bundlePath;
+
+ protected Registry registry;
+
+ protected UIResourceRegistry uiResourceRegistry;
+
+ protected Log log = LogFactory.getLog(this.getClass());
+
+ public SecuredComponentEntryHttpContext(Bundle bundle) {
+ super(bundle);
+ }
+
+ public SecuredComponentEntryHttpContext(Bundle bundle, String bundlePath, UIResourceRegistry uiResourceRegistry) {
+ super(bundle, bundlePath);
+ this.bundlePath = bundlePath;
+ this.uiResourceRegistry = uiResourceRegistry;
+ }
+
+ public SecuredComponentEntryHttpContext(Bundle bundle, String s, Registry registry) {
+ super(bundle, s);
+ this.registry = registry;
+ }
+
+ public URL getResource(String resourceName) {
+ URL url = super.getResource(resourceName);
+ if (url != null) {
+ return url;
+ }
+
+ url = uiResourceRegistry.getUIResource(resourceName);
+
+ if (url != null) {
+ return url;
+ } else {
+ int lastSlash = resourceName.lastIndexOf('/');
+ if (lastSlash == -1) {
+ return null;
+ }
+ String file = resourceName.substring(lastSlash + 1);
+ if (file.endsWith(".js") && isListed(file)) {
+ try {
+ return new URL("carbon://generate/" + file);
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+ return null;
+ }
+ }
+
+
+
+ /**
+ * TODO: fix this from a configuration file
+ *
+ * @param file
+ * File
+ * @return bool
+ */
+ private boolean isListed(String file) {
+ return "global-params.js".equals(file);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/TextJavascriptHandler.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/TextJavascriptHandler.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/TextJavascriptHandler.java
new file mode 100644
index 0000000..8df231e
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/TextJavascriptHandler.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.ui;
+
+/**
+ *
+ */
+public class TextJavascriptHandler extends TextPlainHandler {
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/TextPlainHandler.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/TextPlainHandler.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/TextPlainHandler.java
new file mode 100644
index 0000000..d2fa16e
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/TextPlainHandler.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.ui;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.ContentHandler;
+import java.net.URLConnection;
+
+/**
+ *
+ */
+public class TextPlainHandler extends ContentHandler {
+
+ public Object getContent(URLConnection conn) throws IOException {
+ InputStream in = conn.getInputStream();
+ InputStreamReader r = new InputStreamReader(in);
+ StringBuffer sb = new StringBuffer();
+ int c;
+ while ((c = r.read()) >= 0) {
+ sb.append((char) c);
+ }
+ r.close();
+ in.close();
+ return sb.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/TilesJspServlet.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/TilesJspServlet.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/TilesJspServlet.java
new file mode 100644
index 0000000..0b6773e
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/TilesJspServlet.java
@@ -0,0 +1,107 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.wso2.carbon.ui;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+import org.wso2.carbon.ui.action.ActionHelper;
+import org.wso2.carbon.ui.deployment.beans.CarbonUIDefinitions;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+
+public class TilesJspServlet extends JspServlet {
+ private static final long serialVersionUID = 1L;
+ private static Log log = LogFactory.getLog(TilesJspServlet.class);
+
+ public TilesJspServlet(Bundle bundle, UIResourceRegistry uiResourceRegistry) {
+ super(bundle, uiResourceRegistry);
+ }
+
+ public void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ String actionUrl = request.getRequestURI();
+
+ //This is the layout page defined in
+ //"/org.wso2.carbon.component/src/main/resources/web/WEB-INF/tiles/main_defs.xml"
+ //Need to serve http requests other than to tiles body page,
+ //using the normal OSGi way
+
+ //retrieve urls that should be by-passed from tiles servlet
+ String resourceURI = actionUrl.replaceFirst(request.getContextPath() + "/", "../");
+
+ HashMap<String, String> urlsToBeByPassed = new HashMap<String, String>();
+ if (bundle != null) {
+ ServiceReference reference = bundle.getBundleContext()
+ .getServiceReference(CarbonUIDefinitions.class.getName());
+ CarbonUIDefinitions carbonUIDefinitions = null;
+ if (reference != null) {
+ carbonUIDefinitions =
+ (CarbonUIDefinitions) bundle.getBundleContext().getService(reference);
+ if (carbonUIDefinitions != null) {
+ urlsToBeByPassed = carbonUIDefinitions.getSkipTilesUrls();
+ }
+ }
+ }
+
+ //if the current uri is marked to be by-passed, let it pass through
+ if (!urlsToBeByPassed.isEmpty()) {
+ if (urlsToBeByPassed.containsKey(resourceURI)) {
+ super.service(request, response);
+ return;
+ }
+ }
+
+
+ if ((actionUrl.lastIndexOf("/admin/layout/template.jsp") > -1)
+ || actionUrl.lastIndexOf("ajaxprocessor.jsp") > -1
+ || actionUrl.indexOf("gadgets/js") > -1) {
+ super.service(request, response);
+ } else if (actionUrl.startsWith("/carbon/registry/web/resources/foo/bar")) {
+ //TODO : consider the renamed ROOT war scenario
+ String resourcePath = actionUrl.replaceFirst("/carbon/registry/web/", "");
+ String pathToRegistry = "path=" + resourcePath;
+ if (log.isTraceEnabled()) {
+ log.trace("Forwarding to registry : " + pathToRegistry);
+ }
+ RequestDispatcher dispatcher =
+ request.getRequestDispatcher("../registry/registry-web.jsp?" + pathToRegistry);
+ dispatcher.forward(request, response);
+ } else {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("request.getContextPath() : " + request.getContextPath());
+ log.debug("actionUrl : " + actionUrl);
+ }
+ String newPath = actionUrl.replaceFirst(request.getContextPath(), "");
+
+ //todo: Insert filter work here
+
+ ActionHelper.render(newPath, request, response);
+ } catch (Exception e) {
+ log.fatal("Fatal error occurred while rendering UI using Tiles.", e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIAnnouncement.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIAnnouncement.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIAnnouncement.java
new file mode 100644
index 0000000..0d22f91
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIAnnouncement.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2005-2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. 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.wso2.carbon.ui;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpSession;
+
+public interface UIAnnouncement {
+ String getAnnouncementHtml(HttpSession session, ServletConfig config);
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIAuthenticationExtender.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIAuthenticationExtender.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIAuthenticationExtender.java
new file mode 100644
index 0000000..1542d76
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIAuthenticationExtender.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2005-2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. 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.wso2.carbon.ui;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * An instance of this interface can be registered as an OSGi service, which will allow the Carbon
+ * UI to extend its authentication process.
+ */
+public interface UIAuthenticationExtender {
+
+ /**
+ * Method that will be executed if the login was successful.
+ *
+ * @param request the HTTP Request.
+ * @param userName the name of the logged in user.
+ * @param domain the tenant domain.
+ * @param serverURL the URL of the BE server.
+ */
+ void onSuccessAdminLogin(HttpServletRequest request, String userName, String domain,
+ String serverURL);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIExtender.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIExtender.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIExtender.java
new file mode 100644
index 0000000..3e2ad00
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIExtender.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.ui;
+
+/**
+ *
+ */
+public interface UIExtender {
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIResourceRegistry.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIResourceRegistry.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIResourceRegistry.java
new file mode 100644
index 0000000..232b908
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/UIResourceRegistry.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2009-2010 WSO2, Inc. (http://wso2.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.ui;
+
+import org.wso2.carbon.ui.util.UIResourceProvider;
+import org.osgi.framework.*;
+
+import java.net.URL;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * This class acts as a registry for UI resources. JspServlet and other parties who need UI resources,
+ * use an instance of this class to load UI resources.
+ * <p/>
+ * First this class loads the requested resource from the default resourceProvider, which is the
+ * BundleBasedUIResourceProvider. If it fails, the this class loads the resource from the custom UIResourceProviders
+ */
+public class UIResourceRegistry implements UIResourceProvider, ServiceListener {
+
+ private UIResourceProvider defaultUIResourceProvider;
+ private Set<UIResourceProvider> resourceProviderSet;
+ private BundleContext bundleContext;
+
+ public void initialize(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ resourceProviderSet = new HashSet<UIResourceProvider>();
+
+ try {
+ //1. Registering this class as a ServiceListener which is interested in services
+ //registered with UIResourceProvider key.
+ bundleContext.addServiceListener(this,
+ "(" + Constants.OBJECTCLASS + "=" + UIResourceProvider.class.getName() + ")");
+
+ //2. Getting registered UIResourceProvider OSGi services.
+ ServiceReference[] references = bundleContext.getServiceReferences((String)null,
+ "(" + Constants.OBJECTCLASS + "=" + UIResourceProvider.class.getName() + ")");
+
+ if (references != null && references.length > 0) {
+ for (ServiceReference reference : references) {
+ UIResourceProvider uiResourceProvider = (UIResourceProvider) bundleContext.getService(reference);
+ if (uiResourceProvider != null) {
+ //Synchronized all the add methods, because this method may be invoked concurrently
+ resourceProviderSet.add(uiResourceProvider);
+ }
+ }
+ }
+ } catch (InvalidSyntaxException ignored) {
+ }
+ }
+
+ public URL getUIResource(String path) {
+ URL url = defaultUIResourceProvider.getUIResource(path);
+ if (url == null) {
+ for (UIResourceProvider resourceProvider : resourceProviderSet) {
+ url = resourceProvider.getUIResource(path);
+ if (url != null) {
+ break;
+ }
+ }
+ }
+ return url;
+ }
+
+ public Set<String> getUIResourcePaths(String path) {
+ Set<String> resourcePathSet = defaultUIResourceProvider.getUIResourcePaths(path);
+ if (resourcePathSet.isEmpty()) {
+ for (UIResourceProvider resourceProvider : resourceProviderSet) {
+ resourcePathSet = resourceProvider.getUIResourcePaths(path);
+ if (!resourcePathSet.isEmpty()) {
+ break;
+ }
+ }
+ }
+ return resourcePathSet;
+ }
+
+ public void setDefaultUIResourceProvider(UIResourceProvider defaultUIResourceProvider) {
+ this.defaultUIResourceProvider = defaultUIResourceProvider;
+ }
+
+ public void serviceChanged(ServiceEvent serviceEvent) {
+ if (serviceEvent.getType() == ServiceEvent.REGISTERED) {
+ UIResourceProvider uiResourceProvider = (UIResourceProvider)
+ bundleContext.getService(serviceEvent.getServiceReference());
+ resourceProviderSet.add(uiResourceProvider);
+
+ } else if (serviceEvent.getType() == ServiceEvent.UNREGISTERING) {
+ UIResourceProvider uiResourceProvider = (UIResourceProvider)
+ bundleContext.getService(serviceEvent.getServiceReference());
+ resourceProviderSet.remove(uiResourceProvider);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/Utils.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/Utils.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/Utils.java
new file mode 100644
index 0000000..00433b4
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/Utils.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.ui;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.CarbonException;
+import org.wso2.carbon.base.ServerConfiguration;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Enumeration;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+
+/**
+ *
+ */
+public class Utils {
+
+ private static Log log = LogFactory.getLog(Utils.class);
+
+ public static void transform(InputStream xmlStream, InputStream xslStream,
+ OutputStream outputStream) throws TransformerException {
+ Source xmlStreamSource = new StreamSource(xmlStream);
+ Source xslStreamSource = new StreamSource(xslStream);
+ Result result = new StreamResult(outputStream);
+ Transformer transformer = TransformerFactory.newInstance().newTransformer(xslStreamSource);
+ transformer.transform(xmlStreamSource, result);
+ }
+
+ public static void copyDirectory(File sourceLocation, File targetLocation) throws IOException {
+
+ if (sourceLocation.isDirectory()) {
+ if (!targetLocation.exists()) {
+ targetLocation.mkdir();
+ }
+
+ String[] children = sourceLocation.list();
+ for (String aChildren : children) {
+ copyDirectory(new File(sourceLocation, aChildren),
+ new File(targetLocation, aChildren));
+ }
+ } else {
+ InputStream in = new FileInputStream(sourceLocation);
+ OutputStream out = new FileOutputStream(targetLocation);
+
+ // Copy the bits from instream to outstream
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ }
+ }
+
+
+ /**
+ * For a given Zip file, process each entry.
+ *
+ * @param zipFileLocation zipFileLocation
+ * @param targetLocation targetLocation
+ * @throws org.wso2.carbon.core.CarbonException
+ * CarbonException
+ */
+ public static void deployZipFile(File zipFileLocation, File targetLocation)
+ throws CarbonException {
+ try {
+ SortedSet<String> dirsMade = new TreeSet<String>();
+ JarFile jarFile = new JarFile(zipFileLocation);
+ Enumeration all = jarFile.entries();
+ while (all.hasMoreElements()) {
+ getFile((ZipEntry) all.nextElement(), jarFile, targetLocation, dirsMade);
+ }
+ } catch (IOException e) {
+ log.error("Error while copying component", e);
+ throw new CarbonException(e);
+ }
+ }
+
+ /**
+ * Process one file from the zip, given its name.
+ * Either print the name, or create the file on disk.
+ *
+ * @param e zip entry
+ * @param zippy jarfile
+ * @param targetLocation target
+ * @param dirsMade dir
+ * @throws java.io.IOException will be thrown
+ */
+ private static void getFile(ZipEntry e, JarFile zippy, File targetLocation,
+ SortedSet<String> dirsMade)
+ throws IOException {
+ byte[] b = new byte[1024];
+ String zipName = e.getName();
+
+ if (zipName.startsWith("/")) {
+ zipName = zipName.substring(1);
+ }
+ //Process only fliles that start with "ui"
+ if (!zipName.startsWith("ui")) {
+ return;
+ }
+ // Strip off the ui bit
+ zipName = zipName.substring(2);
+ // if a directory, just return. We mkdir for every file,
+ // since some widely-used Zip creators don't put out
+ // any directory entries, or put them in the wrong place.
+ if (zipName.endsWith("/")) {
+ return;
+ }
+ // Else must be a file; open the file for output
+ // Get the directory part.
+ int ix = zipName.lastIndexOf('/');
+ if (ix > 0) {
+ String dirName = zipName.substring(0, ix);
+ if (!dirsMade.contains(dirName)) {
+ File d = new File(targetLocation, dirName);
+ // If it already exists as a dir, don't do anything
+ if (!(d.exists() && d.isDirectory())) {
+ // Try to create the directory, warn if it fails
+ if (log.isDebugEnabled()) {
+ log.debug("Deploying Directory: " + dirName);
+ }
+ if (!d.mkdirs()) {
+ log.warn("Warning: unable to mkdir " + dirName);
+ }
+ dirsMade.add(dirName);
+ }
+ }
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Deploying " + zipName);
+ }
+ File file = new File(targetLocation, zipName);
+ FileOutputStream os = new FileOutputStream(file);
+ InputStream is = zippy.getInputStream(e);
+ int n;
+ while ((n = is.read(b)) > 0) {
+ os.write(b, 0, n);
+ }
+ is.close();
+ os.close();
+ }
+
+ /**
+ * Deletes all files and subdirectories under dir.
+ * Returns true if all deletions were successful.
+ * If a deletion fails, the method stops attempting to delete and returns false.
+ *
+ * @param dir directory to delete
+ * @return status
+ */
+ public static boolean deleteDir(File dir) {
+ if (dir.isDirectory()) {
+ String[] children = dir.list();
+ for (int i = 0; i < children.length; i++) {
+ boolean success = deleteDir(new File(dir, children[i]));
+ if (!success) {
+ return false;
+ }
+ }
+ }
+ // The directory is now empty so delete it
+ return dir.delete();
+ }
+
+ /**
+ * Read context name from carbon.xml
+ * "carbon" will be the default value
+ *
+ * @return webcontext name
+ */
+ public static String getWebContextName() {
+ String webContext = "carbon";
+ ServerConfiguration sc = ServerConfiguration.getInstance();
+ if (sc != null) {
+ String value = sc.getFirstProperty("WebContext");
+ if (value != null) {
+ webContext = value;
+ }
+ }
+ return webContext;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/action/ActionHelper.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/action/ActionHelper.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/action/ActionHelper.java
new file mode 100644
index 0000000..99d3455
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/action/ActionHelper.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.ui.action;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tiles.Attribute;
+import org.apache.tiles.AttributeContext;
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.access.TilesAccess;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ */
+public class ActionHelper {
+ private static Log log = LogFactory.getLog(ActionHelper.class);
+
+ /**
+ *
+ * @param actionUrl url should be start with "/"
+ * @param request HttpServletRequest
+ * @param response HttpServletResponse
+ * @throws Exception Exception
+ */
+ public static void render(String actionUrl, HttpServletRequest request,
+ HttpServletResponse response) throws Exception {
+ TilesContainer container = TilesAccess.getContainer(
+ request.getSession().getServletContext());
+ if(log.isDebugEnabled()){
+ log.debug("Rendering tiles main.layout with page : "+actionUrl+"("+request.getSession().getId()+")");
+ }
+ AttributeContext attributeContext = container.startContext(request, response);
+ Attribute attr = new Attribute(actionUrl);
+ attributeContext.putAttribute("body", attr);
+ try {
+ container.render("main.layout", request, response);
+ container.endContext(request, response);
+ } catch (Exception e) {
+ if (log.isDebugEnabled()) { // Intentionally logged at debug level
+ log.debug("Error occurred while rendering." +
+ " We generally see this 'harmless' exception on WebLogic. Hiding it.", e);
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/action/ComponentAction.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/action/ComponentAction.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/action/ComponentAction.java
new file mode 100644
index 0000000..a483e5e
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/action/ComponentAction.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.ui.action;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import static org.wso2.carbon.ui.action.ActionHelper.render;
+
+/**
+*
+*/
+public class ComponentAction {
+
+ public ComponentAction() {
+ }
+
+ public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
+ String actionUrl = ""; //TODO fix this
+ render(actionUrl, request, response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/action/ServiceAction.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/action/ServiceAction.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/action/ServiceAction.java
new file mode 100644
index 0000000..a5104a7
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/action/ServiceAction.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.ui.action;
+
+
+/**
+ * org.wso2.carbon.action.ServiceAction interface for rendering definitions.
+ * This class is used only to hold reference in OSGi
+ */
+public interface ServiceAction {
+
+ /**
+ * This will set the component root which can be used in Services
+ * @param componentRoot componentRoot
+ */
+ void setComponentRoot(String componentRoot);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/6b1dba58/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/clients/FileDownloadServiceClient.java
----------------------------------------------------------------------
diff --git a/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/clients/FileDownloadServiceClient.java b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/clients/FileDownloadServiceClient.java
new file mode 100644
index 0000000..0422c13
--- /dev/null
+++ b/dependencies/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/clients/FileDownloadServiceClient.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wso2.carbon.ui.clients;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.core.common.IFileDownload;
+import org.wso2.carbon.core.commons.stub.filedownload.FileDownloadServiceStub;
+
+import javax.activation.DataHandler;
+import javax.servlet.http.HttpSession;
+import java.rmi.RemoteException;
+
+/**
+ *
+ */
+public class FileDownloadServiceClient implements IFileDownload {
+
+ private static final Log log = LogFactory.getLog(FileDownloadServiceClient.class);
+ private FileDownloadServiceStub stub;
+ private HttpSession session;
+
+ public FileDownloadServiceClient(ConfigurationContext ctx, String serverURL,
+ String cookie, HttpSession session) throws AxisFault {
+ this.session = session;
+ String serviceEPR = serverURL + "FileDownloadService";
+ stub = new FileDownloadServiceStub(ctx, serviceEPR);
+ ServiceClient client = stub._getServiceClient();
+ Options options = client.getOptions();
+ options.setManageSession(true);
+ if (cookie != null) {
+ options.setProperty(HTTPConstants.COOKIE_STRING, cookie);
+ }
+ }
+
+ public DataHandler downloadFile(String id) {
+ try {
+ return stub.downloadFile(id);
+ } catch (RemoteException e) {
+ log.error("File download failed. ID: " + id);
+ }
+ return null;
+ }
+}