Skip to content

Commit

Permalink
For #5707: use Option, indent, rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Bruchez committed Nov 7, 2024
1 parent e74e1b5 commit 3e0e45e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ trait FormRunnerPDF {

// Used by:
//
// - `print-pdf-notemplate.xsl`
// - Form Builder
// - form compilation in `view.xsl`
// - `print-pdf-notemplate.xsl`: `rendered-page-orientation`/`rendered-page-size`
// - Form Builder: `html-page-layout`
// - `view.xsl`: `html-page-layout`
//
//@XPathFunction
def optionFromMetadataOrPropertiesXPath(
Expand All @@ -109,8 +109,9 @@ trait FormRunnerPDF {
): Option[String] =
FormRunner.optionFromMetadataOrProperties(
metadataInstanceRootElem = metadataInstanceRootElem,
featureName = featureName)(
p = FormRunnerParams(app, form, 1, None, None, mode)
featureName = featureName
)(
formRunnerParams = FormRunnerParams(app, form, 1, None, None, mode)
)

import URLFinder._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,9 @@ trait FormRunnerBaseOps extends FormRunnerPlatform {

def optionFromMetadataOrProperties(
metadataInstanceRootElem : NodeInfo,
featureName : String)(implicit
p : FormRunnerParams
featureName : String
)(implicit
formRunnerParams : FormRunnerParams
): Option[String] =
metadataInstanceRootElem.elemValueOpt(featureName) orElse
formRunnerProperty(s"oxf.fr.detail.$featureName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ object FRComponentParamSupport {
property = property
)

fromAttributes orElse fromMetadataAndProperties map {
case paramValue: StringValue => stringToStringValue(sourceComponent.evaluateAvt(paramValue.getStringValue, EventCollector.Throw))
case paramValue => paramValue
fromAttributes orElse fromMetadataAndProperties flatMap {
case paramValue: StringValue => sourceComponent.evaluateAvt(paramValue.getStringValue, EventCollector.Throw).map(stringToStringValue)
case paramValue => paramValue.some
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ trait ControlExtensionAttributesSupport {
else if (isRelevant)
// NOTE: evaluateAvt can return null if there is no context
// WARNING: don't use `mapValues`, which return a view which can't be stored in the back control tree
staticControl.extensionAttributes map { case (k, v) => k -> (Option(evaluateAvt(v, EventCollector.ToReview)) getOrElse "") }
staticControl.extensionAttributes map { case (k, v) => k -> evaluateAvt(v, EventCollector.ToReview).getOrElse("") }
else
// Don't attempt to evaluate expression when the control is non-relevant
staticControl.nonRelevantExtensionAttributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ trait ControlXPathSupport {
if (staticControl ne null) staticControl.namespaceMapping else container.getNamespaceMappings(element)

def evaluateBooleanAvt(attributeValue: String, collector: ErrorEventCollector): Boolean =
evaluateAvt(attributeValue, collector) == "true"
evaluateAvt(attributeValue, collector).contains("true")

/**
* Evaluate an attribute of the control as an AVT.
*
* @param attributeValue value of the attribute
* @return value of the AVT or null if cannot be computed
* @return value of the AVT or `None` if cannot be computed
*/
def evaluateAvt(attributeValue: String, collector: ErrorEventCollector): String = {
def evaluateAvt(attributeValue: String, collector: ErrorEventCollector): Option[String] = {

assert(isRelevant)

Expand All @@ -63,7 +63,7 @@ trait ControlXPathSupport {
locationData = getLocationData,
eventTarget = this,
collector = collector
)(newFunctionContext).orNull
)(newFunctionContext)
}

// Evaluate an XPath expression as a string in the context of this control.
Expand Down Expand Up @@ -130,8 +130,10 @@ object ControlXPathSupport {
container : XBLContainer, // used for `PartAnalysis` and `XFCD`
locationData : LocationData,
eventTarget : XFormsEventTarget,
collector : ErrorEventCollector,
)(implicit xfc: XFormsFunction.Context): Option[String] = {
collector : ErrorEventCollector
)(implicit
xfc : XFormsFunction.Context
): Option[String] = {

if (! XMLUtils.maybeAVT(attributeValue))
// Definitely not an AVT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class XXFormsAttributeControl(

// Value comes from the AVT value attribute
override def computeValue(collector: ErrorEventCollector): String =
Option(evaluateAvt(attributeValue, collector)) getOrElse ""
evaluateAvt(attributeValue, collector).getOrElse("")

protected override def getRelevantEscapedExternalValue(collector: ErrorEventCollector): String = {
// Rewrite URI attribute if needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ object ComponentParamSupport {
// level.
def fromElemAlsoTryAvt(
atts : QName => Option[String],
evaluateAvt : String => String,
evaluateAvt : String => Option[String],
paramName : QName
): Option[StringValue] =
atts(paramName) map evaluateAvt map stringToStringValue
atts(paramName) flatMap evaluateAvt map stringToStringValue

def fromElem(
atts : QName => Option[String],
Expand Down

0 comments on commit 3e0e45e

Please sign in to comment.