<commit_before>/**
 * Copyright (C) 2011 Orbeon, Inc.
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License as published by the Free Software Foundation; either version
 * 2.1 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
 */
package org.orbeon.oxf.xforms.processor.handlers.xhtml;

import org.apache.commons.collections.map.CompositeMap;
import org.orbeon.oxf.pipeline.api.ExternalContext;
import org.orbeon.oxf.pipeline.api.XMLReceiver;
import org.orbeon.oxf.util.URLRewriterUtils;
import org.orbeon.oxf.xforms.*;
import org.orbeon.oxf.xforms.control.XFormsControl;
import org.orbeon.oxf.xforms.control.controls.XXFormsDialogControl;
import org.orbeon.oxf.xforms.event.EventHandler;
import org.orbeon.oxf.xforms.event.XFormsEvents;
import org.orbeon.oxf.xforms.state.XFormsStateManager;
import org.orbeon.oxf.xml.*;
import org.orbeon.oxf.xml.XMLUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

import java.io.Serializable;
import java.util.*;

/**
 * Handle xhtml:head.
 */
public abstract class XHTMLHeadHandlerBase extends XFormsBaseHandlerXHTML {

    private String formattingPrefix;

    public XHTMLHeadHandlerBase() {
        super(false, true);
    }

    public void start(String uri, String localname, String qName, Attributes attributes) throws SAXException {

        final XMLReceiver xmlReceiver = handlerContext.getController().getOutput();

        // Register control handlers on controller
        {
            final ElementHandlerController controller = handlerContext.getController();
            controller.registerHandler(XXFormsTextHandler.class.getName(), XFormsConstants.XXFORMS_NAMESPACE_URI, "text", XHTMLBodyHandler.ANY_MATCHER);
        }

        // Declare xmlns:f
        formattingPrefix = handlerContext.findFormattingPrefixDeclare();

        // Open head element
        xmlReceiver.startElement(uri, localname, qName, attributes);

        final ContentHandlerHelper helper = new ContentHandlerHelper(xmlReceiver);
        final String xhtmlPrefix = XMLUtils.prefixFromQName(qName); // current prefix for XHTML

        // Create prefix for combined resources if needed
        final boolean isMinimal = XFormsProperties.isMinimalResources();
        final boolean isVersionedResources = URLRewriterUtils.isResourcesVersioned();

        // Include static XForms CSS. This makes sure that
        final String requestPath = handlerContext.getExternalContext().getRequest().getRequestPath();
        helper.element("", XMLConstants.XINCLUDE_URI, "include", new String[] {
                "href", XHTMLBodyHandler.getIncludedResourceURL(requestPath, "static-xforms-css.xml"),
                "fixup-xml-base", "false"
        });

        // Stylesheets
        final AttributesImpl attributesImpl = new AttributesImpl();
        outputCSSResources(helper, xhtmlPrefix, isMinimal, attributesImpl);

        // Scripts
        // TODO: Have option to put this at the bottom of the page. See theme-plain.xsl and http://developer.yahoo.com/performance/rules.html#js_bottom -->
        if (!handlerContext.isNoScript() && !XFormsProperties.isReadonly(containingDocument)) {

            // Main JavaScript resources
            outputJavaScriptResources(helper, xhtmlPrefix, isMinimal, attributesImpl);

            // Configuration properties
            outputConfigurationProperties(helper, xhtmlPrefix, isVersionedResources);

            // User-defined (with xxforms:script) and XForms scripts
            final String focusElementId = containingDocument.getClientFocusControlEffectiveId();
            final List<XFormsContainingDocument.Message> messagesToRun = containingDocument.getMessagesToRun();
            final List<XXFormsDialogControl> dialogsToOpen = new ArrayList<XXFormsDialogControl>(); {
                final Map<String, XFormsControl> dialogsMap = containingDocument.getControls().getCurrentControlTree().getDialogControls();
                if (dialogsMap != null && dialogsMap.size() > 0) {
                    for (final XFormsControl control: dialogsMap.values()) {
                        final XXFormsDialogControl dialogControl = (XXFormsDialogControl) control;
                        if (dialogControl.isVisible()) {<commit_msg>Comment<commit_after>/**
 * Copyright (C) 2011 Orbeon, Inc.
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License as published by the Free Software Foundation; either version
 * 2.1 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * The full text of the license is available at http://www.gnu.org/copyleft/lesser.html
 */
package org.orbeon.oxf.xforms.processor.handlers.xhtml;

import org.apache.commons.collections.map.CompositeMap;
import org.orbeon.oxf.pipeline.api.ExternalContext;
import org.orbeon.oxf.pipeline.api.XMLReceiver;
import org.orbeon.oxf.util.URLRewriterUtils;
import org.orbeon.oxf.xforms.*;
import org.orbeon.oxf.xforms.control.XFormsControl;
import org.orbeon.oxf.xforms.control.controls.XXFormsDialogControl;
import org.orbeon.oxf.xforms.event.EventHandler;
import org.orbeon.oxf.xforms.event.XFormsEvents;
import org.orbeon.oxf.xforms.state.XFormsStateManager;
import org.orbeon.oxf.xml.*;
import org.orbeon.oxf.xml.XMLUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

import java.io.Serializable;
import java.util.*;

/**
 * Handle xhtml:head.
 */
public abstract class XHTMLHeadHandlerBase extends XFormsBaseHandlerXHTML {

    private String formattingPrefix;

    public XHTMLHeadHandlerBase() {
        super(false, true);
    }

    public void start(String uri, String localname, String qName, Attributes attributes) throws SAXException {

        final XMLReceiver xmlReceiver = handlerContext.getController().getOutput();

        // Register control handlers on controller
        {
            final ElementHandlerController controller = handlerContext.getController();
            controller.registerHandler(XXFormsTextHandler.class.getName(), XFormsConstants.XXFORMS_NAMESPACE_URI, "text", XHTMLBodyHandler.ANY_MATCHER);
        }

        // Declare xmlns:f
        formattingPrefix = handlerContext.findFormattingPrefixDeclare();

        // Open head element
        xmlReceiver.startElement(uri, localname, qName, attributes);

        final ContentHandlerHelper helper = new ContentHandlerHelper(xmlReceiver);
        final String xhtmlPrefix = XMLUtils.prefixFromQName(qName); // current prefix for XHTML

        // Create prefix for combined resources if needed
        final boolean isMinimal = XFormsProperties.isMinimalResources();
        final boolean isVersionedResources = URLRewriterUtils.isResourcesVersioned();

        // Include static XForms CSS. This makes sure that
        final String requestPath = handlerContext.getExternalContext().getRequest().getRequestPath();
        helper.element("", XMLConstants.XINCLUDE_URI, "include", new String[] {
                "href", XHTMLBodyHandler.getIncludedResourceURL(requestPath, "static-xforms-css.xml"),
                "fixup-xml-base", "false"
        });

        // Stylesheets
        final AttributesImpl attributesImpl = new AttributesImpl();
        outputCSSResources(helper, xhtmlPrefix, isMinimal, attributesImpl);

        // Scripts
        if (!handlerContext.isNoScript() && !XFormsProperties.isReadonly(containingDocument)) {

            // Main JavaScript resources
            outputJavaScriptResources(helper, xhtmlPrefix, isMinimal, attributesImpl);

            // Configuration properties
            outputConfigurationProperties(helper, xhtmlPrefix, isVersionedResources);

            // User-defined (with xxforms:script) and XForms scripts
            final String focusElementId = containingDocument.getClientFocusControlEffectiveId();
            final List<XFormsContainingDocument.Message> messagesToRun = containingDocument.getMessagesToRun();
            final List<XXFormsDialogControl> dialogsToOpen = new ArrayList<XXFormsDialogControl>(); {
                final Map<String, XFormsControl> dialogsMap = containingDocument.getControls().getCurrentControlTree().getDialogControls();
                if (dialogsMap != null && dialogsMap.size() > 0) {
                    for (final XFormsControl control: dialogsMap.values()) {
                        final XXFormsDialogControl dialogControl = (XXFormsDialogControl) control;
                        if (dialogControl.isVisible()) {
{'fraction_non_alphanumeric': 0.08836907082521117, 'fraction_numerical': 0.0015161360190599957, 'mean_word_length': 3.529180971064247, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '422544', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2372, 'n_words': 626}