2014-09-24 34 views
0

我有一段代碼從門戶頁面uniquename獲取WebSphere Portal URL。但是生成的URL也有我不需要的導航狀態細節。我需要沒有任何狀態信息的網址。請幫忙。提前致謝!!用於獲取無導航狀態的URL的WebSphere Portal API

URLFactory urlFactory = null; 
    SelectionAccessorController selCtrl = null; 
    PortletServiceHome serviceHome = null; 
    Context ctx = null; 
    try { 
     ctx = new InitialContext(); 
     serviceHome = (PortletServiceHome) ctx.lookup("portletservice/com.ibm.portal.state.service.PortletStateManagerService"); 
     PortletStateManagerService service = 
       (PortletStateManagerService) serviceHome 
         .getPortletService(PortletStateManagerService.class); 

     try { 
      PortletStateManager manager = service.getPortletStateManager(request, response); 
      urlFactory = manager.getURLFactory(); 
      EngineURL url = urlFactory.newURL(Constants.EMPTY_COPY); 
      com.ibm.portal.state.accessors.selection.SelectionAccessorFactory selFct = 
        (com.ibm.portal.state.accessors.selection.SelectionAccessorFactory) manager 
          .getAccessorFactory(com.ibm.portal.state.accessors.selection.SelectionAccessorFactory.class); 
      selCtrl = selFct.getSelectionAccessorController(url.getState()); 
      selCtrl.setSelection(uniqueName); 
      return url.writeDispose(new StringWriter()).toString(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
      throw e; 
     } finally { 
      if (null != selCtrl) 
       selCtrl.dispose(); 
      if (null != urlFactory) 
       urlFactory.dispose(); 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } finally { 
     if (null != selCtrl) 
      selCtrl.dispose(); 
     if (null != urlFactory) 
      urlFactory.dispose(); 
    } 
    return null; 

} 

回答

0

而不是使用EngineUrl嘗試使用FriendlyUrl來生成Url。

FriendlyURL url=urlFactory.newURL(Constants.EMPTY_COPY); 
url.setSelection("ibm.portal.Home"); 
url.dispose(); 
0

我嘗試這樣做,用短網址的工作:

的EngineURL URL = urlFactory.newURL(Constants.DEEP_COPY);

我用Constants.DEEP_COPY代替Constants.EMPTY_COPY