Search in sources :

Example 1 with JavaScriptConfiguration

use of com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration in project htmlunit by HtmlUnit.

the class DefaultElementFactory method createElementNS.

/**
 * @param page the owning page
 * @param namespaceURI the URI that identifies an XML namespace
 * @param qualifiedName the qualified name of the element type to instantiate
 * @param attributes initial attributes, possibly {@code null}
 * @param checkBrowserCompatibility if true and the page doesn't support this element, return null
 * @return the newly created element
 */
@Override
public HtmlElement createElementNS(final SgmlPage page, final String namespaceURI, final String qualifiedName, final Attributes attributes, final boolean checkBrowserCompatibility) {
    final Map<String, DomAttr> attributeMap = toMap(page, attributes);
    final HtmlElement element;
    final String tagName;
    final int colonIndex = qualifiedName.indexOf(':');
    if (colonIndex == -1) {
        tagName = qualifiedName.toLowerCase(Locale.ROOT);
    } else {
        tagName = qualifiedName.substring(colonIndex + 1).toLowerCase(Locale.ROOT);
    }
    boolean doBrowserCompatibilityCheck = checkBrowserCompatibility;
    switch(tagName) {
        case KEYGEN_:
            final BrowserVersion browserVersion = page.getWebClient().getBrowserVersion();
            if (browserVersion.hasFeature(KEYGEN_AS_BLOCK)) {
                element = new HtmlBlockQuote(qualifiedName, page, attributeMap);
            } else {
                element = new HtmlUnknownElement(page, qualifiedName, attributeMap);
            }
            break;
        case HtmlAbbreviated.TAG_NAME:
            element = new HtmlAbbreviated(qualifiedName, page, attributeMap);
            break;
        case HtmlAcronym.TAG_NAME:
            element = new HtmlAcronym(qualifiedName, page, attributeMap);
            break;
        case HtmlAddress.TAG_NAME:
            element = new HtmlAddress(qualifiedName, page, attributeMap);
            break;
        case HtmlAnchor.TAG_NAME:
            element = new HtmlAnchor(qualifiedName, page, attributeMap);
            break;
        case HtmlApplet.TAG_NAME:
            element = new HtmlApplet(qualifiedName, page, attributeMap);
            break;
        case HtmlArea.TAG_NAME:
            element = new HtmlArea(qualifiedName, page, attributeMap);
            break;
        case HtmlArticle.TAG_NAME:
            element = new HtmlArticle(qualifiedName, page, attributeMap);
            break;
        case HtmlAside.TAG_NAME:
            element = new HtmlAside(qualifiedName, page, attributeMap);
            break;
        case HtmlAudio.TAG_NAME:
            element = new HtmlAudio(qualifiedName, page, attributeMap);
            break;
        case HtmlBackgroundSound.TAG_NAME:
            element = new HtmlBackgroundSound(qualifiedName, page, attributeMap);
            break;
        case HtmlBase.TAG_NAME:
            element = new HtmlBase(qualifiedName, page, attributeMap);
            break;
        case HtmlBaseFont.TAG_NAME:
            element = new HtmlBaseFont(qualifiedName, page, attributeMap);
            break;
        case HtmlBidirectionalIsolation.TAG_NAME:
            element = new HtmlBidirectionalIsolation(qualifiedName, page, attributeMap);
            break;
        case HtmlBidirectionalOverride.TAG_NAME:
            element = new HtmlBidirectionalOverride(qualifiedName, page, attributeMap);
            break;
        case HtmlBig.TAG_NAME:
            element = new HtmlBig(qualifiedName, page, attributeMap);
            break;
        case HtmlBlink.TAG_NAME:
            element = new HtmlBlink(qualifiedName, page, attributeMap);
            break;
        case HtmlBlockQuote.TAG_NAME:
            element = new HtmlBlockQuote(qualifiedName, page, attributeMap);
            break;
        case HtmlBody.TAG_NAME:
            element = new HtmlBody(qualifiedName, page, attributeMap, false);
            // Force script object creation now to forward onXXX handlers to window.
            if (page instanceof HtmlPage) {
                if (page.getWebClient().isJavaScriptEngineEnabled()) {
                    element.getScriptableObject();
                }
            }
            break;
        case HtmlBold.TAG_NAME:
            element = new HtmlBold(qualifiedName, page, attributeMap);
            break;
        case HtmlBreak.TAG_NAME:
            element = new HtmlBreak(qualifiedName, page, attributeMap);
            break;
        case HtmlButton.TAG_NAME:
            element = new HtmlButton(qualifiedName, page, attributeMap);
            break;
        case HtmlCanvas.TAG_NAME:
            element = new HtmlCanvas(qualifiedName, page, attributeMap);
            break;
        case HtmlCaption.TAG_NAME:
            element = new HtmlCaption(qualifiedName, page, attributeMap);
            break;
        case HtmlCenter.TAG_NAME:
            element = new HtmlCenter(qualifiedName, page, attributeMap);
            break;
        case HtmlCitation.TAG_NAME:
            element = new HtmlCitation(qualifiedName, page, attributeMap);
            break;
        case HtmlCode.TAG_NAME:
            element = new HtmlCode(qualifiedName, page, attributeMap);
            break;
        case HtmlCommand.TAG_NAME:
            element = new HtmlCommand(qualifiedName, page, attributeMap);
            break;
        case HtmlData.TAG_NAME:
            element = new HtmlData(qualifiedName, page, attributeMap);
            break;
        case HtmlDataList.TAG_NAME:
            element = new HtmlDataList(qualifiedName, page, attributeMap);
            break;
        case HtmlDefinition.TAG_NAME:
            element = new HtmlDefinition(qualifiedName, page, attributeMap);
            break;
        case HtmlDefinitionDescription.TAG_NAME:
            element = new HtmlDefinitionDescription(qualifiedName, page, attributeMap);
            break;
        case HtmlDefinitionList.TAG_NAME:
            element = new HtmlDefinitionList(qualifiedName, page, attributeMap);
            break;
        case HtmlDefinitionTerm.TAG_NAME:
            element = new HtmlDefinitionTerm(qualifiedName, page, attributeMap);
            break;
        case HtmlDeletedText.TAG_NAME:
            element = new HtmlDeletedText(qualifiedName, page, attributeMap);
            break;
        case HtmlDetails.TAG_NAME:
            element = new HtmlDetails(qualifiedName, page, attributeMap);
            break;
        case HtmlDialog.TAG_NAME:
            element = new HtmlDialog(qualifiedName, page, attributeMap);
            break;
        case HtmlDirectory.TAG_NAME:
            element = new HtmlDirectory(qualifiedName, page, attributeMap);
            break;
        case HtmlDivision.TAG_NAME:
            element = new HtmlDivision(qualifiedName, page, attributeMap);
            break;
        case HtmlEmbed.TAG_NAME:
            element = new HtmlEmbed(qualifiedName, page, attributeMap);
            break;
        case HtmlEmphasis.TAG_NAME:
            element = new HtmlEmphasis(qualifiedName, page, attributeMap);
            break;
        case HtmlExample.TAG_NAME:
            element = new HtmlExample(qualifiedName, page, attributeMap);
            break;
        case HtmlFieldSet.TAG_NAME:
            element = new HtmlFieldSet(qualifiedName, page, attributeMap);
            break;
        case HtmlFigure.TAG_NAME:
            element = new HtmlFigure(qualifiedName, page, attributeMap);
            break;
        case HtmlFigureCaption.TAG_NAME:
            element = new HtmlFigureCaption(qualifiedName, page, attributeMap);
            break;
        case HtmlFont.TAG_NAME:
            element = new HtmlFont(qualifiedName, page, attributeMap);
            break;
        case HtmlForm.TAG_NAME:
            element = new HtmlForm(qualifiedName, page, attributeMap);
            break;
        case HtmlFooter.TAG_NAME:
            element = new HtmlFooter(qualifiedName, page, attributeMap);
            break;
        case HtmlFrame.TAG_NAME:
            if (attributeMap != null) {
                final DomAttr srcAttribute = attributeMap.get(DomElement.SRC_ATTRIBUTE);
                if (srcAttribute != null) {
                    srcAttribute.setValue(srcAttribute.getValue().trim());
                }
            }
            element = new HtmlFrame(qualifiedName, page, attributeMap);
            break;
        case HtmlFrameSet.TAG_NAME:
            element = new HtmlFrameSet(qualifiedName, page, attributeMap);
            break;
        case HtmlHead.TAG_NAME:
            element = new HtmlHead(qualifiedName, page, attributeMap);
            break;
        case HtmlHeader.TAG_NAME:
            element = new HtmlHeader(qualifiedName, page, attributeMap);
            break;
        case HtmlHeading1.TAG_NAME:
            element = new HtmlHeading1(qualifiedName, page, attributeMap);
            break;
        case HtmlHeading2.TAG_NAME:
            element = new HtmlHeading2(qualifiedName, page, attributeMap);
            break;
        case HtmlHeading3.TAG_NAME:
            element = new HtmlHeading3(qualifiedName, page, attributeMap);
            break;
        case HtmlHeading4.TAG_NAME:
            element = new HtmlHeading4(qualifiedName, page, attributeMap);
            break;
        case HtmlHeading5.TAG_NAME:
            element = new HtmlHeading5(qualifiedName, page, attributeMap);
            break;
        case HtmlHeading6.TAG_NAME:
            element = new HtmlHeading6(qualifiedName, page, attributeMap);
            break;
        case HtmlHorizontalRule.TAG_NAME:
            element = new HtmlHorizontalRule(qualifiedName, page, attributeMap);
            break;
        case HtmlHtml.TAG_NAME:
            element = new HtmlHtml(qualifiedName, page, attributeMap);
            break;
        case HtmlImage.TAG_NAME:
        case HtmlImage.TAG_NAME2:
            element = new HtmlImage(qualifiedName, page, attributeMap);
            break;
        case HtmlInlineFrame.TAG_NAME:
            if (attributeMap != null) {
                final DomAttr srcAttribute = attributeMap.get(DomElement.SRC_ATTRIBUTE);
                if (srcAttribute != null) {
                    srcAttribute.setValue(srcAttribute.getValue().trim());
                }
            }
            element = new HtmlInlineFrame(qualifiedName, page, attributeMap);
            break;
        case HtmlInlineQuotation.TAG_NAME:
            element = new HtmlInlineQuotation(qualifiedName, page, attributeMap);
            break;
        case HtmlInput.TAG_NAME:
            element = createInputElement(qualifiedName, page, attributeMap);
            doBrowserCompatibilityCheck = false;
            break;
        case HtmlInsertedText.TAG_NAME:
            element = new HtmlInsertedText(qualifiedName, page, attributeMap);
            break;
        case HtmlIsIndex.TAG_NAME:
            element = new HtmlIsIndex(qualifiedName, page, attributeMap);
            break;
        case HtmlItalic.TAG_NAME:
            element = new HtmlItalic(qualifiedName, page, attributeMap);
            break;
        case HtmlKeyboard.TAG_NAME:
            element = new HtmlKeyboard(qualifiedName, page, attributeMap);
            break;
        case HtmlLabel.TAG_NAME:
            element = new HtmlLabel(qualifiedName, page, attributeMap);
            break;
        case HtmlLayer.TAG_NAME:
            element = new HtmlLayer(qualifiedName, page, attributeMap);
            break;
        case HtmlLegend.TAG_NAME:
            element = new HtmlLegend(qualifiedName, page, attributeMap);
            break;
        case HtmlLink.TAG_NAME:
            element = new HtmlLink(qualifiedName, page, attributeMap);
            break;
        case HtmlListing.TAG_NAME:
            element = new HtmlListing(qualifiedName, page, attributeMap);
            break;
        case HtmlListItem.TAG_NAME:
            element = new HtmlListItem(qualifiedName, page, attributeMap);
            break;
        case HtmlMain.TAG_NAME:
            element = new HtmlMain(qualifiedName, page, attributeMap);
            break;
        case HtmlMap.TAG_NAME:
            element = new HtmlMap(qualifiedName, page, attributeMap);
            break;
        case HtmlMark.TAG_NAME:
            element = new HtmlMark(qualifiedName, page, attributeMap);
            break;
        case HtmlMarquee.TAG_NAME:
            element = new HtmlMarquee(qualifiedName, page, attributeMap);
            break;
        case HtmlMenu.TAG_NAME:
            element = new HtmlMenu(qualifiedName, page, attributeMap);
            break;
        case HtmlMenuItem.TAG_NAME:
            element = new HtmlMenuItem(qualifiedName, page, attributeMap);
            break;
        case HtmlMeta.TAG_NAME:
            element = new HtmlMeta(qualifiedName, page, attributeMap);
            break;
        case HtmlMeter.TAG_NAME:
            element = new HtmlMeter(qualifiedName, page, attributeMap);
            break;
        case HtmlMultiColumn.TAG_NAME:
            element = new HtmlMultiColumn(qualifiedName, page, attributeMap);
            break;
        case HtmlNav.TAG_NAME:
            element = new HtmlNav(qualifiedName, page, attributeMap);
            break;
        case HtmlNextId.TAG_NAME:
            element = new HtmlNextId(qualifiedName, page, attributeMap);
            break;
        case HtmlNoBreak.TAG_NAME:
            element = new HtmlNoBreak(qualifiedName, page, attributeMap);
            break;
        case HtmlNoEmbed.TAG_NAME:
            element = new HtmlNoEmbed(qualifiedName, page, attributeMap);
            break;
        case HtmlNoFrames.TAG_NAME:
            element = new HtmlNoFrames(qualifiedName, page, attributeMap);
            break;
        case HtmlNoLayer.TAG_NAME:
            element = new HtmlNoLayer(qualifiedName, page, attributeMap);
            break;
        case HtmlNoScript.TAG_NAME:
            element = new HtmlNoScript(qualifiedName, page, attributeMap);
            break;
        case HtmlObject.TAG_NAME:
            element = new HtmlObject(qualifiedName, page, attributeMap);
            break;
        case HtmlOption.TAG_NAME:
            element = new HtmlOption(qualifiedName, page, attributeMap);
            break;
        case HtmlOptionGroup.TAG_NAME:
            element = new HtmlOptionGroup(qualifiedName, page, attributeMap);
            break;
        case HtmlOrderedList.TAG_NAME:
            element = new HtmlOrderedList(qualifiedName, page, attributeMap);
            break;
        case HtmlOutput.TAG_NAME:
            element = new HtmlOutput(qualifiedName, page, attributeMap);
            break;
        case HtmlParagraph.TAG_NAME:
            element = new HtmlParagraph(qualifiedName, page, attributeMap);
            break;
        case HtmlParameter.TAG_NAME:
            element = new HtmlParameter(qualifiedName, page, attributeMap);
            break;
        case HtmlPicture.TAG_NAME:
            element = new HtmlPicture(qualifiedName, page, attributeMap);
            break;
        case HtmlPlainText.TAG_NAME:
            element = new HtmlPlainText(qualifiedName, page, attributeMap);
            break;
        case HtmlPreformattedText.TAG_NAME:
            element = new HtmlPreformattedText(qualifiedName, page, attributeMap);
            break;
        case HtmlProgress.TAG_NAME:
            element = new HtmlProgress(qualifiedName, page, attributeMap);
            break;
        case HtmlRp.TAG_NAME:
            element = new HtmlRp(qualifiedName, page, attributeMap);
            break;
        case HtmlRt.TAG_NAME:
            element = new HtmlRt(qualifiedName, page, attributeMap);
            break;
        case HtmlRuby.TAG_NAME:
            element = new HtmlRuby(qualifiedName, page, attributeMap);
            break;
        case HtmlS.TAG_NAME:
            element = new HtmlS(qualifiedName, page, attributeMap);
            break;
        case HtmlSample.TAG_NAME:
            element = new HtmlSample(qualifiedName, page, attributeMap);
            break;
        case HtmlScript.TAG_NAME:
            element = new HtmlScript(qualifiedName, page, attributeMap);
            break;
        case HtmlSection.TAG_NAME:
            element = new HtmlSection(qualifiedName, page, attributeMap);
            break;
        case HtmlSelect.TAG_NAME:
            element = new HtmlSelect(qualifiedName, page, attributeMap);
            break;
        case HtmlSmall.TAG_NAME:
            element = new HtmlSmall(qualifiedName, page, attributeMap);
            break;
        case HtmlSlot.TAG_NAME:
            element = new HtmlSlot(qualifiedName, page, attributeMap);
            break;
        case HtmlSource.TAG_NAME:
            element = new HtmlSource(qualifiedName, page, attributeMap);
            break;
        case HtmlSpan.TAG_NAME:
            element = new HtmlSpan(qualifiedName, page, attributeMap);
            break;
        case HtmlStrike.TAG_NAME:
            element = new HtmlStrike(qualifiedName, page, attributeMap);
            break;
        case HtmlStrong.TAG_NAME:
            element = new HtmlStrong(qualifiedName, page, attributeMap);
            break;
        case HtmlStyle.TAG_NAME:
            element = new HtmlStyle(qualifiedName, page, attributeMap);
            break;
        case HtmlSubscript.TAG_NAME:
            element = new HtmlSubscript(qualifiedName, page, attributeMap);
            break;
        case HtmlSummary.TAG_NAME:
            element = new HtmlSummary(qualifiedName, page, attributeMap);
            break;
        case HtmlSuperscript.TAG_NAME:
            element = new HtmlSuperscript(qualifiedName, page, attributeMap);
            break;
        case HtmlSvg.TAG_NAME:
            element = new HtmlSvg(qualifiedName, page, attributeMap);
            break;
        case HtmlTable.TAG_NAME:
            element = new HtmlTable(qualifiedName, page, attributeMap);
            break;
        case HtmlTableBody.TAG_NAME:
            element = new HtmlTableBody(qualifiedName, page, attributeMap);
            break;
        case HtmlTableColumn.TAG_NAME:
            element = new HtmlTableColumn(qualifiedName, page, attributeMap);
            break;
        case HtmlTableColumnGroup.TAG_NAME:
            element = new HtmlTableColumnGroup(qualifiedName, page, attributeMap);
            break;
        case HtmlTableDataCell.TAG_NAME:
            element = new HtmlTableDataCell(qualifiedName, page, attributeMap);
            doBrowserCompatibilityCheck = false;
            break;
        case HtmlTableFooter.TAG_NAME:
            element = new HtmlTableFooter(qualifiedName, page, attributeMap);
            break;
        case HtmlTableHeader.TAG_NAME:
            element = new HtmlTableHeader(qualifiedName, page, attributeMap);
            break;
        case HtmlTableHeaderCell.TAG_NAME:
            element = new HtmlTableHeaderCell(qualifiedName, page, attributeMap);
            doBrowserCompatibilityCheck = false;
            break;
        case HtmlTableRow.TAG_NAME:
            element = new HtmlTableRow(qualifiedName, page, attributeMap);
            break;
        case HtmlTeletype.TAG_NAME:
            element = new HtmlTeletype(qualifiedName, page, attributeMap);
            break;
        case HtmlTemplate.TAG_NAME:
            element = new HtmlTemplate(qualifiedName, page, attributeMap);
            break;
        case HtmlTextArea.TAG_NAME:
            element = new HtmlTextArea(qualifiedName, page, attributeMap);
            break;
        case HtmlTime.TAG_NAME:
            element = new HtmlTime(qualifiedName, page, attributeMap);
            break;
        case HtmlTitle.TAG_NAME:
            element = new HtmlTitle(qualifiedName, page, attributeMap);
            break;
        case HtmlTrack.TAG_NAME:
            element = new HtmlTrack(qualifiedName, page, attributeMap);
            break;
        case HtmlUnderlined.TAG_NAME:
            element = new HtmlUnderlined(qualifiedName, page, attributeMap);
            break;
        case HtmlUnorderedList.TAG_NAME:
            element = new HtmlUnorderedList(qualifiedName, page, attributeMap);
            break;
        case HtmlVariable.TAG_NAME:
            element = new HtmlVariable(qualifiedName, page, attributeMap);
            break;
        case HtmlVideo.TAG_NAME:
            element = new HtmlVideo(qualifiedName, page, attributeMap);
            break;
        case HtmlWordBreak.TAG_NAME:
            element = new HtmlWordBreak(qualifiedName, page, attributeMap);
            break;
        default:
            throw new IllegalStateException("Cannot find HtmlElement for " + qualifiedName);
    }
    if (doBrowserCompatibilityCheck) {
        final JavaScriptConfiguration config = JavaScriptConfiguration.getInstance(page.getWebClient().getBrowserVersion());
        if (config.getDomJavaScriptMappingFor(element.getClass()) == null) {
            return UnknownElementFactory.instance.createElementNS(page, namespaceURI, qualifiedName, attributes);
        }
    }
    return element;
}
Also used : JavaScriptConfiguration(com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion)

Example 2 with JavaScriptConfiguration

use of com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration in project htmlunit by HtmlUnit.

the class HostConstantsTest method getExpectedString.

private String getExpectedString() throws Exception {
    if (host_.endsWith("Array") || "Image".equals(host_) || "Option".equals(host_)) {
        return "";
    }
    if ("Error".equals(host_) && getBrowserVersion().hasFeature(JS_ERROR_STACK_TRACE_LIMIT)) {
        return "stackTraceLimit:10";
    }
    final JavaScriptConfiguration javaScriptConfig = JavaScriptConfiguration.getInstance(getBrowserVersion());
    final List<String> constants = new ArrayList<>();
    ClassConfiguration classConfig = javaScriptConfig.getClassConfiguration(host_);
    boolean first = true;
    while (classConfig != null) {
        if (first && !classConfig.isJsObject()) {
            break;
        }
        if (first || classConfig.getJsConstructor() != null) {
            final List<ConstantInfo> constantInfos = classConfig.getConstants();
            if (constantInfos != null) {
                for (final ConstantInfo constantInfo : constantInfos) {
                    constants.add(constantInfo.getName() + ":" + constantInfo.getValue());
                }
            }
        }
        classConfig = javaScriptConfig.getClassConfiguration(classConfig.getExtendedClassName());
        first = false;
    }
    Collections.sort(constants, new Comparator<String>() {

        @Override
        public int compare(final String o1, final String o2) {
            return o1.substring(0, o1.indexOf(':')).compareTo(o2.substring(0, o2.indexOf(':')));
        }
    });
    final StringBuilder builder = new StringBuilder();
    for (final String key : constants) {
        builder.append(key).append(' ');
    }
    return builder.toString().trim();
}
Also used : ConstantInfo(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.ConstantInfo) ArrayList(java.util.ArrayList) JavaScriptConfiguration(com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration) ClassConfiguration(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration)

Aggregations

JavaScriptConfiguration (com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration)2 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)1 ClassConfiguration (com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration)1 ConstantInfo (com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.ConstantInfo)1 ArrayList (java.util.ArrayList)1