void WMLSelectElement::calculateDefaultOptionIndices() { WMLPageState* pageState = wmlPageStateForDocument(document()); if (!pageState) return; String variable; // Spec: If the 'iname' attribute is specified and names a variable that is set, // then the default option index is the validated value of that variable. String iname = this->iname(); if (!iname.isEmpty()) { variable = pageState->getVariable(iname); if (!variable.isEmpty()) m_defaultOptionIndices = parseIndexValueString(variable); } // Spec: If the default option index is empty and the 'ivalue' attribute is specified, // then the default option index is the validated attribute value. String ivalue = this->ivalue(); if (m_defaultOptionIndices.isEmpty() && !ivalue.isEmpty()) m_defaultOptionIndices = parseIndexValueString(ivalue); // Spec: If the default option index is empty, and the 'name' attribute is specified // and the 'name' ttribute names a variable that is set, then for each value in the 'name' // variable that is present as a value in the select's option elements, the index of the // first option element containing that value is added to the default index if that // index has not been previously added. String name = this->name(); if (m_defaultOptionIndices.isEmpty() && !name.isEmpty()) { variable = pageState->getVariable(name); if (!variable.isEmpty()) m_defaultOptionIndices = valueStringToOptionIndices(variable); } String value = parseValueSubstitutingVariableReferences(getAttribute(HTMLNames::valueAttr)); // Spec: If the default option index is empty and the 'value' attribute is specified then // for each value in the 'value' attribute that is present as a value in the select's // option elements, the index of the first option element containing that value is added // to the default index if that index has not been previously added. if (m_defaultOptionIndices.isEmpty() && !value.isEmpty()) m_defaultOptionIndices = valueStringToOptionIndices(value); // Spec: If the default option index is empty and the select is a multi-choice, then the // default option index is set to zero. If the select is single-choice, then the default // option index is set to one. if (m_defaultOptionIndices.isEmpty()) m_defaultOptionIndices.append((unsigned) !m_data.multiple()); }
void WMLInputElement::initialize() { String nameVariable = formControlName(); String variableValue; WMLPageState* pageSate = wmlPageStateForDocument(document()); ASSERT(pageSate); if (!nameVariable.isEmpty()) variableValue = pageSate->getVariable(nameVariable); if (variableValue.isEmpty() || !isConformedToInputMask(variableValue)) { String val = value(); if (isConformedToInputMask(val)) variableValue = val; else variableValue = ""; pageSate->storeVariable(nameVariable, variableValue); } setValue(variableValue); if (!hasAttribute(WMLNames::emptyokAttr)) { if (m_formatMask.isEmpty() || // check if the format codes is just "*f" (m_formatMask.length() == 2 && m_formatMask[0] == '*' && formatCodes().find(m_formatMask[1]) != notFound)) m_isEmptyOk = true; } }
String substituteVariableReferences(const String& reference, Document* document, WMLVariableEscapingMode escapeMode) { ASSERT(document); if (reference.isEmpty()) return reference; WMLPageState* pageState = wmlPageStateForDocument(document); if (!pageState) return reference; bool isValid = true; String remainingInput = reference; String result; while (!remainingInput.isEmpty()) { ASSERT(isValid); int start = remainingInput.find("$"); if (start == -1) { // Consume all remaining characters, as there's nothing more to substitute result += remainingInput; break; } // Consume all characters until the variable reference beginning result += remainingInput.left(start); remainingInput.remove(0, start); // Transform adjacent dollar signs into a single dollar sign as string literal if (remainingInput[1] == '$') { result += "$"; remainingInput.remove(0, 2); continue; } String variableName; String conversionMode; if (remainingInput[1] == '(') { int referenceEndPosition = remainingInput.find(")"); if (referenceEndPosition == -1) { isValid = false; break; } variableName = remainingInput.substring(2, referenceEndPosition - 2); remainingInput.remove(0, referenceEndPosition + 1); // Determine variable conversion mode string int pos = variableName.find(':'); if (pos != -1) { conversionMode = variableName.substring(pos + 1, variableName.length() - (pos + 1)); variableName = variableName.left(pos); } } else { int length = remainingInput.length(); int referenceEndPosition = 1; for (; referenceEndPosition < length; ++referenceEndPosition) { if (!isValidVariableNameCharacter(remainingInput[referenceEndPosition])) break; } variableName = remainingInput.substring(1, referenceEndPosition - 1); remainingInput.remove(0, referenceEndPosition); } isValid = isValidVariableName(variableName); if (!isValid) break; ASSERT(!variableName.isEmpty()); String variableValue = pageState->getVariable(variableName); if (variableValue.isEmpty()) continue; if (containsVariableReference(variableValue, isValid)) { if (!isValid) break; variableValue = substituteVariableReferences(variableValue, document, escapeMode); continue; } if (!conversionMode.isEmpty()) { // Override default escape mode, if desired WMLVariableEscapingMode specifiedEscapeMode = WMLVariableEscapingNone; if ((isValid = isValidVariableEscapingModeString(conversionMode, specifiedEscapeMode))) escapeMode = specifiedEscapeMode; if (!isValid) break; } switch (escapeMode) { case WMLVariableEscapingNone: break; case WMLVariableEscapingEscape: variableValue = encodeWithURLEscapeSequences(variableValue); break; case WMLVariableEscapingUnescape: variableValue = decodeURLEscapeSequences(variableValue); break; } result += variableValue; ASSERT(isValid); } if (!isValid) { reportWMLError(document, WMLErrorInvalidVariableReference); return reference; } return result; }