use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.
the class HTMLAnchorElement method getPathname.
/**
* Returns the pathname portion of the link's URL.
* @return the pathname portion of the link's URL
* @see <a href="http://msdn.microsoft.com/en-us/library/ms534332.aspx">MSDN Documentation</a>
*/
@JsxGetter
public String getPathname() {
try {
final URL url = getUrl();
if (!url.getProtocol().startsWith("http") && getBrowserVersion().hasFeature(JS_ANCHOR_PATHNAME_NONE_FOR_NONE_HTTP_URL)) {
return "";
}
if (getBrowserVersion().hasFeature(JS_ANCHOR_PATHNAME_DETECT_WIN_DRIVES_URL)) {
final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
String href = anchor.getHrefAttribute();
if (href.length() > 1 && Character.isLetter(href.charAt(0)) && ':' == href.charAt(1)) {
if (getBrowserVersion().hasFeature(JS_ANCHOR_PROTOCOL_COLON_UPPER_CASE_DRIVE_LETTERS)) {
href = StringUtils.capitalize(href);
}
if (getBrowserVersion().hasFeature(JS_ANCHOR_PATHNAME_PREFIX_WIN_DRIVES_URL)) {
href = "/" + href;
}
return href;
}
}
return url.getPath();
} catch (final MalformedURLException e) {
final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
if (anchor.getHrefAttribute().startsWith("http") && getBrowserVersion().hasFeature(JS_ANCHOR_PATHNAME_NONE_FOR_BROKEN_URL)) {
return "";
}
return "/";
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.
the class HTMLAnchorElement method getHref.
/**
* Returns the value of this link's {@code href} property.
* @return the value of this link's {@code href} property
*/
@JsxGetter
public String getHref() {
final HtmlAnchor anchor = (HtmlAnchor) getDomNodeOrDie();
final String hrefAttr = anchor.getHrefAttribute();
if (ATTRIBUTE_NOT_DEFINED == hrefAttr) {
return "";
}
try {
return getUrl().toString();
} catch (final MalformedURLException e) {
return hrefAttr;
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.
the class HTMLInputElement method getValue.
/**
* Returns the value of the JavaScript attribute {@code value}.
*
* @return the value of this attribute
*/
@JsxGetter
@Override
public String getValue() {
final HtmlInput htmlInput = getDomNodeOrDie();
if (htmlInput instanceof HtmlFileInput) {
final File[] files = ((HtmlFileInput) htmlInput).getFiles();
if (files == null || files.length == 0) {
return ATTRIBUTE_NOT_DEFINED;
}
final File first = files[0];
final String name = first.getName();
if (name.isEmpty()) {
return name;
}
return "C:\\fakepath\\" + name;
}
if (htmlInput instanceof HtmlNumberInput) {
final HtmlNumberInput htmlNumberInput = (HtmlNumberInput) htmlInput;
final String valueAttr = htmlInput.getAttributeDirect("value");
if (!valueAttr.isEmpty()) {
if ("-".equals(valueAttr) || "+".equals(valueAttr)) {
return "";
}
final int lastPos = valueAttr.length() - 1;
if (lastPos >= 0 && valueAttr.charAt(lastPos) == '.') {
if (htmlNumberInput.hasFeature(JS_INPUT_NUMBER_DOT_AT_END_IS_DOUBLE)) {
return "";
}
}
try {
Double.parseDouble(valueAttr);
} catch (final NumberFormatException e) {
return "";
}
}
}
return htmlInput.getAttributeDirect("value");
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.
the class HTMLLabelElement method getControl.
/**
* @return the HTMLElement labeled by the given label object
*/
@JsxGetter({ CHROME, EDGE, FF, FF_ESR })
public HTMLElement getControl() {
final HtmlLabel label = (HtmlLabel) getDomNodeOrDie();
final HtmlElement labeledElement = label.getLabeledElement();
if (labeledElement == null) {
return null;
}
return (HTMLElement) getScriptableFor(labeledElement);
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter in project htmlunit by HtmlUnit.
the class HTMLLabelElement method getForm.
/**
* Returns the value of the JavaScript {@code form} attribute.
*
* @return the value of the JavaScript {@code form} attribute
*/
@JsxGetter
@Override
public HTMLFormElement getForm() {
if (getBrowserVersion().hasFeature(JS_LABEL_FORM_OF_SELF)) {
final HtmlForm form = getDomNodeOrDie().getEnclosingForm();
if (form == null) {
return null;
}
return (HTMLFormElement) getScriptableFor(form);
}
final HtmlLabel label = (HtmlLabel) getDomNodeOrDie();
final HtmlElement labeledElement = label.getLabeledElement();
if (labeledElement == null) {
return null;
}
final HtmlForm form = labeledElement.getEnclosingForm();
if (form == null) {
return null;
}
return (HTMLFormElement) getScriptableFor(form);
}
Aggregations