public PatchedServletRunner(File webXml, String contextPath) throws IOException, SAXException { try { Field _application = getAccessibleField(getClass(), "_application"); _application.set(this, new PatchedWebApplication(HttpUnitUtils.newParser().parse(webXml), webXml .getParentFile().getParentFile(), contextPath)); Method completeInitialization = getAccessibleMethod(getClass(), "completeInitialization", new Class<?>[] { String.class }); completeInitialization.invoke(this, contextPath); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } patchInvocationContextFactory(); }
/** * Returns an interpretation of the specified URL-encoded string, using the iso-8859-1 character set. * * @since 1.6 **/ public static String decode( String byteString ) { return decode( byteString, "iso-8859-1" ); }
/** * get the relative URL for a weblink * change spaces to %20 * @return the relative URL as a string */ protected String getRelativeURL() { String result = HttpUnitUtils.encodeSpaces( HttpUnitUtils.trimFragment( getDestination() ) ); if (result.trim().length() == 0) result = getBaseURL().getFile(); return result; }
public boolean matchesCriteria( Object htmlElement, Object criteria ) { return HttpUnitUtils.matches( ((WebLink) htmlElement).getText(), (String) criteria ); } };
WebApplet[] getAppletsInPage() { try { return _response.getApplets(); } catch (SAXException e) { HttpUnitUtils.handleException(e); // should never happen. return null; } }
/** * parse the given inputStream with a new Parser * @param inputStream * @return the document parsed from the input Stream */ public static Document parse(InputStream inputStream) throws SAXException,IOException { DocumentBuilder db=newParser(); try { Document doc=db.parse(inputStream); return doc; } catch (java.net.MalformedURLException mue) { if (EXCEPTION_DEBUG) { String msg=mue.getMessage(); if (msg!=null) { System.err.println(msg); } InputStream is=inputStream; is.reset(); String content=parseISToString(is); System.err.println(content); } throw mue; } }
/** * Gets all parameters from a URL **/ private String getParametersString() { String url = HttpUnitUtils.trimFragment( getDestination() ); if (url.trim().length() == 0) url = getBaseURL().toExternalForm(); if (HttpUnitUtils.isJavaScriptURL( url )) return ""; final int questionMarkIndex = url.indexOf("?"); if (questionMarkIndex >= 1 && questionMarkIndex < url.length() - 1) { return url.substring( questionMarkIndex + 1 ); } return ""; }
/** * Strips the fragment identifier (if any) from the Url. */ static String trimFragment( String rawUrl ) { if (isJavaScriptURL( rawUrl )) return rawUrl; final int hashIndex = rawUrl.indexOf( '#' ); return hashIndex < 0 ? rawUrl: rawUrl.substring( 0, hashIndex ); }
public boolean matchesCriteria( Object htmlElement, Object criteria ) { return HttpUnitUtils.contains( ((WebLink) htmlElement).getText(), (String) criteria ); } };
/** * Constructor which expects an input stream containing the web.xml for the application. * @param webXML * @param contextPath * @throws IOException * @throws SAXException */ public ServletRunner( InputStream webXML, String contextPath ) throws IOException, SAXException { InputSource inputSource=new InputSource( webXML ); Document doc=HttpUnitUtils.parse(inputSource); try { _application = new WebApplication( doc, contextPath ); completeInitialization( contextPath ); } catch (java.net.MalformedURLException mue) { throw mue; } }
public boolean matchesCriteria( Object htmlElement, Object criteria ) { WebTable table = ((WebTable) htmlElement); for (int row = 0; row < table.getRowCount(); row++) { for (int col = 0; col < table.getColumnCount(); col++) { if (HttpUnitUtils.hasPrefix( table.getCellAsText( row, col ).trim(), (String) criteria)) return true; } } return false; } };
/** * Decodes a URL safe string into its original form using the * specified character set. Escaped characters are converted back * to their original representation. * * This method is copied from the <b>Jakarta Commons Codec</b>; * <code>org.apache.commons.codec.net.URLCodec</code> class. * * @param string URL safe string to convert into its original form * @return original string * @throws IllegalArgumentException thrown if URL decoding is unsuccessful, */ public static String decode( String string, String charset ) { try { if (string == null) return null; return new String( decodeUrl( string.getBytes( "US-ASCII" ) ), charset ); } catch (UnsupportedEncodingException e) { throw new RuntimeException( e.toString() ); } }
public boolean matchesCriteria( Object htmlElement, Object criteria ) { return HttpUnitUtils.matches( ((WebLink) htmlElement).getID(), (String) criteria ); } };
public void associate( WebResponse response ) { try { JavaScript.run( response ); } catch (RuntimeException e) { throw e; } catch (Exception e) { HttpUnitUtils.handleException(e); throw new RuntimeException( e.toString() ); } }
/** * parse the given inputStream with a new Parser * @param inputStream * @return the document parsed from the input Stream */ public static Document parse(InputStream inputStream) throws SAXException,IOException { DocumentBuilder db=newParser(); try { Document doc=db.parse(inputStream); return doc; } catch (java.net.MalformedURLException mue) { if (EXCEPTION_DEBUG) { String msg=mue.getMessage(); if (msg!=null) { System.err.println(msg); } InputStream is=inputStream; is.reset(); String content=parseISToString(is); System.err.println(content); } throw mue; } }
/** * Gets all parameters from a URL **/ private String getParametersString() { String url = HttpUnitUtils.trimFragment( getDestination() ); if (url.trim().length() == 0) url = getBaseURL().toExternalForm(); if (HttpUnitUtils.isJavaScriptURL( url )) return ""; final int questionMarkIndex = url.indexOf("?"); if (questionMarkIndex >= 1 && questionMarkIndex < url.length() - 1) { return url.substring( questionMarkIndex + 1 ); } return ""; }
/** * Strips the fragment identifier (if any) from the Url. */ static String trimFragment( String rawUrl ) { if (isJavaScriptURL( rawUrl )) return rawUrl; final int hashIndex = rawUrl.indexOf( '#' ); return hashIndex < 0 ? rawUrl: rawUrl.substring( 0, hashIndex ); }
public boolean matchesCriteria( Object htmlElement, Object criteria ) { return HttpUnitUtils.contains( ((WebLink) htmlElement).getURLString(), (String) criteria ); } };
/** * Constructor which expects an input stream containing the web.xml for the application. * @param webXML * @param contextPath * @throws IOException * @throws SAXException */ public ServletRunner( InputStream webXML, String contextPath ) throws IOException, SAXException { InputSource inputSource=new InputSource( webXML ); Document doc=HttpUnitUtils.parse(inputSource); try { _application = new WebApplication( doc, contextPath ); completeInitialization( contextPath ); } catch (java.net.MalformedURLException mue) { throw mue; } }
public boolean matchesCriteria( Object htmlElement, Object criteria ) { WebTable table = ((WebTable) htmlElement); for (int row = 0; row < table.getRowCount(); row++) { for (int col = 0; col < table.getColumnCount(); col++) { if (HttpUnitUtils.hasPrefix( table.getCellAsText( row, col ).trim(), (String) criteria)) return true; } } return false; } };