📄 websession.java
字号:
return;}/*****************************************************************************//* *//* Method: getCurrentTitle *//* Description: get the title of the current page of the session. *//* Parameters: none *//* Returns: the title of the current page of the session. If there is no *//* title, an empty string is returned. *//* *//*****************************************************************************/ public String getCurrentTitle() { try { return parser.getTitle(); } catch (Exception e) { // Ignore errors (like DOMExceptions, NullPointerException) when // getting the title to so that a QUERY SESSION or LIST SESSIONS // request won't fail just because could not get the title for a // session. return ""; } }/*****************************************************************************//* *//* Method: getCurrentUrl *//* Description: get the url of the current page of the session. *//* Parameters: none *//* Returns: the current url *//* *//*****************************************************************************/ public String getCurrentUrl() { try{ String url = lastRequest.getURI().getURI(); return url; }catch (NullPointerException e){ // no previous requests }catch (URIException e){ } return ""; } /*****************************************************************************//* *//* Method: getCurrentStatusCode *//* Description: get the status code of the last request of the session. *//* Parameters: none *//* Returns: the current status code *//* *//*****************************************************************************/ public int getCurrentStatusCode() { try{ return lastRequest.getStatusCode(); }catch (NullPointerException e){ // no previous requests } return -1; } /*****************************************************************************//* *//* Method: getCurrentStatusText *//* Description: get the status message of the last request of the session. *//* Parameters: none *//* Returns: the current status message *//* *//*****************************************************************************/ public String getCurrentStatusText() { try{ return lastRequest.getStatusText(); }catch (NullPointerException e){ // no previous requests } return ""; } /*****************************************************************************//* *//* Method: getCurrentStatus *//* Description: get the status of the last request of the session. *//* Parameters: none *//* Returns: the current status *//* *//*****************************************************************************/ public String getCurrentStatus() { int rc = getCurrentStatusCode(); String rm = getCurrentStatusText(); return rc + "\n" + rm; } /*****************************************************************************//* *//* Method: getCookiePolicy *//* Description: get the cookie handling policy for this session. *//* Parameters: none *//* Returns: the cookie handling policy *//* *//*****************************************************************************/ public String getCookiePolicy() { return session.getParams().getCookiePolicy(); } /*****************************************************************************//* *//* Method: setCookiePolicy *//* Description: set the cookie handling policy for this session. If an *//* invalid policy is selected the DEFAULT policy is set. *//* Valid types: NETSCAPE, RFC2109, BROWSER, IGNORE *//* Default policy is RFC2109. *//* Parameters: policy - the new cookie handling policy for the session. *//* Returns: void *//* *//*****************************************************************************/ public void setCookiePolicy(String policy) { CookieAccess.setCookiePolicy(policy, session); } /*****************************************************************************//* *//* Method: getCookieNames *//* Description: get a list of cookies associated with this session. *//* Parameters: none *//* Returns: a list of cookies associated with this session *//* *//*****************************************************************************/ public Vector getCookieNames() { return CookieAccess.getCookieNames(session); } /*****************************************************************************//* *//* Method: getCookieValue *//* Description: get the value of the cookie with the specified name. *//* This may need to change to get cookie summary to obtain *//* domain and path information about a specific cookie. *//* Parameters: name - the name of the cookie *//* Returns: the value of the specified cookie. *//* *//*****************************************************************************/ public String getCookieValue(String name) throws InvalidCookieIDException { return CookieAccess.getCookieValue(name, session); }/*****************************************************************************//* *//* Method: setCookieValue *//* Description: sets the value of the specifed cookie to the specified value *//* Parameters: name - name of the cookie *//* value - new value for the cookie *//* Returns: void *//* Throws: InvalidCookieIDException if the cookie does not exist *//* *//*****************************************************************************/ public void setCookieValue (String name, String value) throws InvalidCookieIDException { CookieAccess.setCookieValue(name, value, session); }/*****************************************************************************//* *//* Method: addCookie *//* Description: Add a new cookie to the session. This may need more *//* parameters if path and domain are to be specified. *//* Parameters: name - name of the cookie *//* value - new value for the cookie *//* Returns: void *//* *//*****************************************************************************/ public void addCookie(String name, String value) { CookieAccess.addCookie(CookieAccess.createCookie(name,value), session); }/*****************************************************************************//* *//* Method: deleteCookie *//* Description: Delete the specified cookie from the session. If the cookie *//* does not exist, no error is declared. *//* Parameters: name - name of the cookie *//* Returns: void *//* *//*****************************************************************************/ public void deleteCookie(String name) throws InvalidCookieIDException { CookieAccess.deleteCookie(name, session); } /*****************************************************************************//* *//* Method: summarizeCookie *//* Description: Get the information about a cookie. If the cookie is not in *//* the session throw an InvalidElementException. *//* Parameters: name - name of the cookie *//* Returns: description of the cookie *//* *//*****************************************************************************/ public HashMap summarizeCookie(String name) throws InvalidCookieIDException { return CookieAccess.getCookieSummary(name, session); } /*****************************************************************************//* *//* Method: listCookies *//* Description: return a summary of all cookies in the current page *//* Parameters: None *//* Returns: the summary of all cookies in the current page *//* *//*****************************************************************************/ public HashMap[] listCookies() { return CookieAccess.listCookies(session); }/*****************************************************************************//* *//* Method: findLink *//* Description: Find the specified link in the current page. If the link is *//* not in the page or an invalid id type or an invalid value *//* was specified throw an InvalidElementException. *//* Parameters: linkID - the identified for the link *//* idType - the type of id used to identify the link *//* ID_ID_TYPE and NAME_ID_TYPE are accepted *//* Returns: the link *//* *//*****************************************************************************/ protected WebLink findLink(String linkID, int idType) throws InvalidElementIDException { if (idType == ID_ID_TYPE) return parser.getLinkByID(linkID); if (idType == NAME_ID_TYPE) return parser.getLinkByName(linkID); if (idType == INDEX_ID_TYPE) { // Make sure specified index is numeric try { int index = (new Integer(linkID)).intValue(); }catch (NumberFormatException e) { throw new InvalidElementIDException( linkID, "LINK INDEX " + linkID + " is not an integer"); } return parser.getLinkByIndex(Integer.parseInt(linkID)); } throw new InvalidElementIDException(linkID, "Bad ID Type."); }/*****************************************************************************//* *//* Method: summarizeLink *//* Description: Get the information about a link. If the link is not in the *//* page or an invalid id type was specified throw an *//* InvalidElementException. *//* Parameters: linkID - the identified for the link *//* idType - the type of id used to identify the link */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -