Skip to content

Commit

Permalink
Merge pull request #1037 from lat-lon/enhanceGFITemplatingMechanismTo…
Browse files Browse the repository at this point in the history
…ConvertXlinkHrefAttributeToLink-135

Enhance GFI templating mechanism to convert xlink:href attribute to link
  • Loading branch information
copierrj authored Sep 21, 2022
2 parents 1f23160 + 5b640d1 commit 5a13c19
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,18 @@
package org.deegree.featureinfo.templating.lang;

import static org.deegree.commons.utils.JavaUtils.generateToString;
import static org.deegree.commons.xml.CommonNamespaces.XLNNS;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Map;

import javax.xml.namespace.QName;

import org.deegree.commons.tom.TypedObjectNode;
import org.deegree.commons.tom.gml.property.Property;
import org.deegree.commons.tom.primitive.PrimitiveValue;
import org.deegree.commons.xml.CommonNamespaces;
import org.deegree.gml.reference.FeatureReference;
import org.slf4j.Logger;

/**
Expand All @@ -53,6 +62,8 @@ public class Link {

private static final Logger LOG = getLogger( Link.class );

public static final QName XLINK_HREF = new QName( XLNNS, "href" );

private String prefix;

private String text;
Expand Down Expand Up @@ -86,7 +97,7 @@ public void eval( StringBuilder sb, Object o ) {
LOG.warn( "Trying to get value as link while current object is a feature." );
return;
}
String val = ( (Property) o ).getValue().toString();
String val = getValueAsString( (Property) o );
if ( val == null || val.isEmpty() ) {
return;
}
Expand All @@ -107,4 +118,20 @@ public String toString() {
return generateToString( this );
}

private String getValueAsString( Property o ) {
TypedObjectNode value = o.getValue();
if ( value != null ) {
if ( value instanceof FeatureReference ) {
return ( (FeatureReference) value ).getURI();
}
return value.toString();
} else {
Map<QName, PrimitiveValue> attributes = o.getAttributes();
if ( attributes.containsKey( XLINK_HREF ) ) {
return attributes.get( XLINK_HREF ).getAsText();
}
}
return null;
}

}

0 comments on commit 5a13c19

Please sign in to comment.