use of com.ibm.xsp.registry.FacesDefinition in project org.openntf.nsfodp by OpenNTF.
the class AbstractSchemaServlet method findDefinitionElement.
/**
* Finds the XML element for the given property in its original .xsp-config file.
*
* @param def the containing {@link FacesDefinition} for the property
* @param prop the {@link FacesProperty} to search for
* @return an {@link Element} describing the definition, or {@code null} if it cannot be found
*/
private Element findDefinitionElement(FacesDefinition def, FacesProperty prop) {
try {
Element parent = findDefinitionElement(def);
if (parent != null) {
// Check for the property directly
Element propElement = Stream.of(DOMUtil.nodes(parent, "property/property-name[normalize-space(text())='" + prop.getName() + "']")).filter(Element.class::isInstance).map(Element.class::cast).map(el -> el.getParentNode()).map(Element.class::cast).findFirst().orElse(null);
if (propElement != null) {
// Great!
return propElement;
}
// Check its parent
if (def.getParent() != null) {
propElement = findDefinitionElement(def.getParent(), prop);
if (propElement != null) {
return propElement;
}
}
Collection<String> groups = def.getGroupTypeRefs();
if (groups != null && !groups.isEmpty()) {
String propFile = prop.getFile().getFilePath();
Document propDoc = getXspConfig(propFile);
if (propDoc != null) {
return findInGroups(prop, propDoc, groups);
}
}
}
return null;
} catch (XMLException e) {
throw new RuntimeException(e);
}
}
use of com.ibm.xsp.registry.FacesDefinition in project org.openntf.nsfodp by OpenNTF.
the class AbstractSchemaServlet method outProperty.
private void outProperty(FacesDefinition def, FacesProperty prop, Element element, SharableRegistryImpl registry) {
// TODO check run/load binding from FacesSimpleProperty
Class<?> clazz = prop.getJavaClass();
if (prop instanceof AbstractContainerProperty) {
clazz = ((AbstractContainerProperty) prop).getItemProperty().getJavaClass();
}
if (isBindingType(prop)) {
outAttribute(def, prop, element, extMap.get(this.namespace) + ":attrBinding", false);
} else if (byte.class.equals(clazz) || short.class.equals(clazz) || int.class.equals(clazz) || long.class.equals(clazz) || Byte.class.equals(clazz) || Short.class.equals(clazz) || Integer.class.equals(clazz) || Long.class.equals(clazz)) {
outAttribute(def, prop, element, extMap.get(namespace) + ":attrInteger", false);
} else if (boolean.class.equals(clazz) || Boolean.class.equals(clazz)) {
outAttribute(def, prop, element, extMap.get(namespace) + ":attrBoolean", false);
} else if (float.class.equals(clazz) || double.class.equals(clazz) || Number.class.isAssignableFrom(clazz)) {
outAttribute(def, prop, element, extMap.get(namespace) + ":attrDecimal", false);
} else if (LocalTime.class.isAssignableFrom(clazz)) {
outAttribute(def, prop, element, extMap.get(namespace) + ":attrTime", false);
} else if (Date.class.equals(clazz) || TemporalAccessor.class.isAssignableFrom(clazz)) {
outAttribute(def, prop, element, extMap.get(namespace) + ":attrDate", false);
} else if ("id".equals(prop.getName())) {
outAttribute(def, prop, element, "xs:ID", false);
} else if (CharSequence.class.isAssignableFrom(clazz)) {
outAttribute(def, prop, element, "xs:string", false);
} else if (Object.class.equals(clazz) || FacesListener.class.isAssignableFrom(clazz)) {
// FacesListeners lead to an xp: prefix below if left unhandled
outAttribute(def, prop, element, "xs:string", false);
} else {
// Figure out if it's complex or not
Class<?> finalClazz = clazz;
FacesDefinition propDef = registry.findDefs().stream().filter(def2 -> def2.getJavaClass().equals(finalClazz)).findFirst().orElse(null);
if (propDef != null) {
outAttribute(def, prop, element, extMap.get(propDef.getNamespaceUri()) + ':' + toElementName(propDef, false), true);
} else {
outAttribute(def, prop, element, "xs:string", false);
}
}
}
use of com.ibm.xsp.registry.FacesDefinition in project org.openntf.nsfodp by OpenNTF.
the class AbstractSchemaServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
Document doc = DOMUtil.createDocument(namespace, "xs:schema");
doc.setXmlStandalone(true);
Element schema = doc.getDocumentElement();
schema.setAttribute("xmlns:xs", "http://www.w3.org/2001/XMLSchema");
schema.setAttribute("xmlns:" + extMap.get(namespace), namespace);
schema.setAttribute("targetNamespace", namespace);
schema.setAttribute("elementFormDefault", "qualified");
for (String importUri : this.imports) {
schema.setAttribute("xmlns:" + extMap.get(importUri), importUri);
Element importEl = DOMUtil.createElement(doc, schema, "xs:import");
importEl.setAttribute("namespace", importUri);
// importEl.setAttribute("schemaLocation", URI.create(req.getRequestURL().toString()).resolve(extMap.get(importUri) + ".xsd").toString());
importEl.setAttribute("schemaLocation", extMap.get(importUri) + ".xsd");
}
outSimpleTypes(schema);
SharableRegistryImpl facesRegistry = new SharableRegistryImpl(getClass().getPackage().getName());
// $NON-NLS-1$
List<Object> libraries = ExtensionManager.findServices((List<Object>) null, LibraryServiceLoader.class, "com.ibm.xsp.Library");
libraries.stream().filter(lib -> lib instanceof XspLibrary).map(XspLibrary.class::cast).map(lib -> new LibraryWrapper(lib.getLibraryId(), lib)).map(wrapper -> {
SimpleRegistryProvider provider = new SimpleRegistryProvider();
provider.init(wrapper);
return provider;
}).map(XspRegistryProvider::getRegistry).forEach(facesRegistry::addDepend);
facesRegistry.refreshReferences();
@SuppressWarnings("unchecked") List<FacesDefinition> defs = (List<FacesDefinition>) (List<?>) facesRegistry.findDefs();
defs.stream().filter(FacesDefinition::isTag).filter(def -> StringUtil.equals(namespace, def.getNamespaceUri())).forEach(def -> outComponentDefinition(def, schema, facesRegistry, false));
resp.setContentType("text/xml");
DOMUtil.serialize(resp.getOutputStream(), doc, new Format(2, true, "UTF-8"));
} catch (Throwable e) {
e.printStackTrace();
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getLocalizedMessage());
resp.setContentType("text/plain");
e.printStackTrace(new PrintWriter(resp.getOutputStream()));
resp.getOutputStream().flush();
e.printStackTrace();
}
}
Aggregations