use of eu.esdihumboldt.hale.io.xsd.constraint.XmlElements in project hale by halestudio.
the class XmlElementsFactory method restore.
@Override
public XmlElements restore(Value value, Definition<?> definition, TypeResolver typeResolver, ClassResolver classResolver) throws Exception {
XmlElements result = new XmlElements();
ValueList list = value.as(ValueList.class);
if (list != null) {
for (Value val : list) {
XmlElement element = valueToElement(val, definition, typeResolver);
if (element != null) {
result.addElement(element);
}
}
}
return result;
}
use of eu.esdihumboldt.hale.io.xsd.constraint.XmlElements in project hale by halestudio.
the class XmlTypeDefinition method getDescription.
@Override
public String getDescription() {
String desc = super.getDescription();
if (desc != null && !desc.isEmpty()) {
return desc;
}
// if no description is present, try the description of the associated
// element
XmlElements elements = getConstraint(XmlElements.class);
if (elements.getElements().size() == 1) {
// only use element description if it's unique
XmlElement element = elements.getElements().iterator().next();
return element.getDescription();
}
return desc;
}
use of eu.esdihumboldt.hale.io.xsd.constraint.XmlElements in project hale by halestudio.
the class XslTransformationUtil method selectInstances.
/**
* Create a XPath statement to select instances specified by the given type
* entity definition.
*
* @param ted the type entity definition
* @param context the context for the XPath expression, e.g. the empty
* string for the document root or <code>/</code> for anywhere in
* the document
* @param namespaces the namespace context
* @return the XPath expression or <code>null</code> if there are no
* elements that match the type
*/
public static String selectInstances(TypeEntityDefinition ted, String context, NamespaceContext namespaces) {
TypeDefinition type = ted.getDefinition();
// get the XML elements associated to the type
XmlElements elements = type.getConstraint(XmlElements.class);
if (elements.getElements().isEmpty()) {
/*
* XXX dirty hack
*
* In CityGML 1.0 no element for AppearanceType is defined, only a
* property that is not detected in this way. The source route
* element is not known here, so we also cannot do a search based on
* the type. Thus for now we handle it as a special case.
*/
QName typeName = ted.getDefinition().getName();
if ("http://www.opengis.net/citygml/appearance/1.0".equals(typeName.getNamespaceURI()) && "AppearanceType".equals(typeName.getLocalPart())) {
// create a dummy XML element
elements = new XmlElements();
elements.addElement(new XmlElement(new QName("http://www.opengis.net/citygml/appearance/1.0", "Appearance"), ted.getDefinition(), null));
} else
// XXX dirty hack end
return null;
}
// XXX which elements should be used?
// for now use all elements
StringBuilder select = new StringBuilder();
boolean first = true;
for (XmlElement element : elements.getElements()) {
if (first) {
first = false;
} else {
select.append(" | ");
}
select.append(context);
select.append('/');
String ns = element.getName().getNamespaceURI();
if (ns != null && !ns.isEmpty()) {
String prefix = namespaces.getPrefix(ns);
if (prefix != null && !prefix.isEmpty()) {
select.append(prefix);
select.append(':');
}
}
select.append(element.getName().getLocalPart());
}
// filter
if (ted.getFilter() != null) {
String filterxpath = FilterToXPath.toXPath(ted.getDefinition(), namespaces, ted.getFilter());
if (filterxpath != null && !filterxpath.isEmpty()) {
select.insert(0, '(');
select.append(")[");
select.append(StringEscapeUtils.escapeXml(filterxpath));
select.append(']');
}
}
return select.toString();
}
Aggregations