@Nonnull public SimpleURL getLinkToMenuItem (@Nonnull @Nonempty final String sAppID, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final Locale aDisplayLocale, @Nonnull final String sMenuItemID) { // Get the servlet path from the app ID final String sServletPath = PhotonGlobalState.state (sAppID).getServletPath (); // Prepend the context path final String sBasePath = aRequestScope.getContextPath () + sServletPath; return m_aRequestParamHdl.buildURL (aRequestScope, sBasePath, aDisplayLocale, sMenuItemID); }
@Nonnull public static PhotonGlobalStatePerApp state (@Nonnull @Nonempty final String sAppID) { ValueEnforcer.notEmpty (sAppID, "AppID"); final PhotonGlobalState aGlobalState = getInstance (); return aGlobalState.m_aStateMap.computeIfAbsent (sAppID, k -> { // By default set first app ID as default if (!aGlobalState.hasDefaultApplicationID ()) aGlobalState.setDefaultApplicationID (sAppID); return new PhotonGlobalStatePerApp (); }); }
/** * @return <code>true</code> if a default application ID is present, * <code>false</code> otherwise. * @since 8.0.3 */ public boolean hasDefaultApplicationID () { return StringHelper.hasText (getDefaultApplicationID ()); }
public static void clear () { final PhotonGlobalState aGlobalState = getInstance (); aGlobalState.m_aStateMap.clear (); aGlobalState.setDefaultApplicationID (null); }
if (!PhotonGlobalState.containsAnyApplicationServletPathMapping ()) PhotonGlobalState.state (CApplicationID.APP_ID_PUBLIC) .setServletPath (AbstractPublicApplicationServlet.SERVLET_DEFAULT_PATH); PhotonGlobalState.state (CApplicationID.APP_ID_SECURE) .setServletPath (AbstractSecureApplicationServlet.SERVLET_DEFAULT_PATH); PhotonGlobalState.getInstance ().setDefaultApplicationID (CApplicationID.APP_ID_PUBLIC);
sAppID = aSessionState.getLastApplicationID (); if (StringHelper.hasNoText (sAppID)) sAppID = PhotonGlobalState.getInstance ().getDefaultApplicationID (); aRequestState = new PhotonRequestState (PhotonGlobalState.state (sAppID));
public static boolean containsNoState () { return getInstance ().m_aStateMap.isEmpty (); }
@Nullable private static String _getApplicationIDOrNull (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope) { String sAppID = aRequestScope.attrs ().getCastedValue (REQUEST_ATTR_APP_ID); if (StringHelper.hasNoText (sAppID)) { // Fallback to last saved state from session final PhotonSessionState aPSS = PhotonSessionState.getInstanceIfInstantiated (); if (aPSS != null) sAppID = aPSS.getLastApplicationID (); // None in request nor session -> fall back to default if (StringHelper.hasNoText (sAppID)) sAppID = PhotonGlobalState.getInstance ().getDefaultApplicationID (); } return sAppID; }
@Override protected void fillContent (@Nonnull final WPECTYPE aWPEC) { final HCNodeList aNodeList = aWPEC.getNodeList (); final Locale aDisplayLocale = aWPEC.getDisplayLocale (); final HCTable aTable = new HCTable (new DTCol (EText.MSG_APPID.getDisplayText (aDisplayLocale)).setInitialSorting (ESortOrder.ASCENDING), new DTCol (EText.MSG_APP_SERVLET_PATH.getDisplayText (aDisplayLocale))).setID (getID ()); for (final Map.Entry <String, String> aEntry : PhotonGlobalState.getAppIDToServletPathMap ().entrySet ()) { final String sAppID = aEntry.getKey (); final HCRow aRow = aTable.addBodyRow (); aRow.addCell (sAppID); aRow.addCell (aEntry.getValue ()); } aNodeList.addChild (aTable); final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables (aWPEC, aTable); aNodeList.addChild (aDataTables); } }
@Nonnull public static PhotonGlobalState getInstance () { return getGlobalSingleton (PhotonGlobalState.class); }
public static void removeAllApplicationServletPathMappings () { getInstance ().m_aStateMap.forEachValue (PhotonGlobalStatePerApp::removeServletPath); }
@Override protected void fillContent (@Nonnull final WPECTYPE aWPEC) { final HCNodeList aNodeList = aWPEC.getNodeList (); final Locale aDisplayLocale = aWPEC.getDisplayLocale (); final HCTable aTable = new HCTable (new DTCol (EText.MSG_APPID.getDisplayText (aDisplayLocale)).setInitialSorting (ESortOrder.ASCENDING), new DTCol (EText.MSG_APP_SERVLET_PATH.getDisplayText (aDisplayLocale))).setID (getID ()); for (final Map.Entry <String, String> aEntry : PhotonGlobalState.getAppIDToServletPathMap ().entrySet ()) { final String sAppID = aEntry.getKey (); final HCRow aRow = aTable.addBodyRow (); aRow.addCell (sAppID); aRow.addCell (aEntry.getValue ()); } aNodeList.addChild (aTable); final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables (aWPEC, aTable); aNodeList.addChild (aDataTables); } }
@Override protected void initMenu () { // Determine backend // Required before menu! SMPMetaManager.initBackendFromConfiguration (); // Create all menu items { final MenuTree aMenuTree = new MenuTree (); MenuPublic.init (aMenuTree); PhotonGlobalState.state (CApplicationID.APP_ID_PUBLIC).setMenuTree (aMenuTree); } { final MenuTree aMenuTree = new MenuTree (); MenuSecure.init (aMenuTree); PhotonGlobalState.state (CApplicationID.APP_ID_SECURE).setMenuTree (aMenuTree); } }
public static boolean containsAnyApplicationServletPathMapping () { return getInstance ().m_aStateMap.containsAnyValue (x -> x.internalGetServletPath () != null); }
@Override protected void initMenu () { // Determine backend // Required before menu! SMPMetaManager.initBackendFromConfiguration (); // Create all menu items { final MenuTree aMenuTree = new MenuTree (); MenuPublic.init (aMenuTree); PhotonGlobalState.state (CApplicationID.APP_ID_PUBLIC).setMenuTree (aMenuTree); } { final MenuTree aMenuTree = new MenuTree (); MenuSecure.init (aMenuTree); PhotonGlobalState.state (CApplicationID.APP_ID_SECURE).setMenuTree (aMenuTree); } }
@Nonnull @ReturnsMutableCopy public static ICommonsMap <String, String> getAppIDToServletPathMap () { final ICommonsMap <String, String> ret = new CommonsHashMap <> (); getInstance ().m_aStateMap.forEach ( (sAppID, aState) -> ret.put (sAppID, aState.getServletPath ())); return ret; } }
@Nullable private static PhotonRequestState _getRequestStateOrNull (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope) { PhotonRequestState ret = aRequestScope.attrs ().getCastedValue (REQUEST_ATTR_STATE); if (ret == null) { // Fallback to last saved state from session final String sAppID = _getApplicationIDOrNull (aRequestScope); if (StringHelper.hasText (sAppID)) { final PhotonSessionState aSessionState = PhotonSessionState.getInstanceIfInstantiated (); if (aSessionState != null) { final PhotonSessionStatePerApp aSessionStatePerApp = aSessionState.state (sAppID); // Is e.g. empty if a new session state was created! if (aSessionStatePerApp.isNotEmpty ()) ret = new PhotonRequestState (aSessionStatePerApp); } // Global state as last resort if (ret == null) ret = new PhotonRequestState (PhotonGlobalState.state (sAppID)); } // else - no app ID - we're lost } return ret; }
final PhotonGlobalStatePerApp aAppGlobalState = PhotonGlobalState.state (sAppID);