use of com.ibm.xsp.registry.FacesProperty 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.FacesProperty in project org.openntf.nsfodp by OpenNTF.
the class AbstractSchemaServlet method findInGroups.
private Element findInGroups(FacesProperty prop, Document propDoc, Collection<String> groups) throws XMLException {
if (groups == null || groups.isEmpty()) {
return null;
}
Element groupElement = groups.stream().map(group -> {
try {
return DOMUtil.nodes(propDoc, "/faces-config/group/group-type[normalize-space(text())='" + group + "']");
} catch (XMLException e) {
throw new RuntimeException(e);
}
}).filter(nodes -> nodes.length > 0).map(nodes -> nodes[0]).map(Element.class::cast).map(Element::getParentNode).map(Element.class::cast).findFirst().orElse(null);
if (groupElement == null) {
// No dice
return null;
}
// Check the group for a property element
Object[] nodes = DOMUtil.nodes(groupElement, "property/property-name[normalize-space(text())='" + prop.getName() + "']");
if (nodes.length > 0) {
// Then we found it
return (Element) ((Element) nodes[0]).getParentNode();
} else {
// Otherwise, search the group's group refs
List<String> groupRefs = Stream.of(DOMUtil.nodes(groupElement, "group-type-ref")).map(Element.class::cast).map(el -> el.getTextContent()).collect(Collectors.toList());
return findInGroups(prop, propDoc, groupRefs);
}
}
use of com.ibm.xsp.registry.FacesProperty in project org.openntf.nsfodp by OpenNTF.
the class StockComponentsServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setBufferSize(0);
// $NON-NLS-1$ //$NON-NLS-2$
resp.setHeader("Content-Type", "text/json");
ServletOutputStream os = resp.getOutputStream();
try {
if (componentInfo == null) {
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();
componentInfo = new JsonJavaObject();
JsonArray defs = new JsonJavaArray();
facesRegistry.findComponentDefs().stream().filter(FacesComponentDefinition::isTag).map(def -> {
try {
JsonObject defObj = new JsonJavaObject();
// $NON-NLS-1$
defObj.putJsonProperty("namespaceUri", def.getNamespaceUri());
// $NON-NLS-1$
defObj.putJsonProperty("tagName", def.getTagName());
// $NON-NLS-1$
defObj.putJsonProperty("class", def.getJavaClass().getName());
// $NON-NLS-1$
defObj.putJsonProperty("since", def.getSince());
// $NON-NLS-1$
defObj.putJsonProperty("defaultPrefix", def.getFirstDefaultPrefix());
// $NON-NLS-1$
defObj.putJsonProperty("componentFamily", def.getComponentFamily());
// $NON-NLS-1$
defObj.putJsonProperty("componentType", def.getComponentType());
// $NON-NLS-1$
defObj.putJsonProperty("id", def.getId());
JsonArray facetNames = new JsonJavaArray();
for (String facetName : def.getFacetNames()) {
facetNames.add(facetName);
}
// $NON-NLS-1$
defObj.putJsonProperty("facetNames", facetNames);
FacesProperty defaultProp = def.getDefaultFacesProperty();
if (defaultProp != null) {
JsonObject defaultPropObj = new JsonJavaObject();
// $NON-NLS-1$
defaultPropObj.putJsonProperty("name", defaultProp.getName());
// $NON-NLS-1$
defaultPropObj.putJsonProperty("since", defaultProp.getSince());
// $NON-NLS-1$
defaultPropObj.putJsonProperty("class", defaultProp.getJavaClass().getName());
// $NON-NLS-1$
defaultPropObj.putJsonProperty("required", defaultProp.isRequired());
// $NON-NLS-1$
defaultPropObj.putJsonProperty("attribute", defaultProp.isAttribute());
}
JsonArray properties = new JsonJavaArray();
for (String propName : def.getPropertyNames()) {
FacesProperty prop = def.getProperty(propName);
JsonObject propObj = new JsonJavaObject();
// $NON-NLS-1$
propObj.putJsonProperty("name", propName);
// $NON-NLS-1$
propObj.putJsonProperty("class", prop.getJavaClass().getName());
// $NON-NLS-1$
propObj.putJsonProperty("since", prop.getSince());
// $NON-NLS-1$
propObj.putJsonProperty("required", prop.isRequired());
// $NON-NLS-1$
propObj.putJsonProperty("attribute", prop.isAttribute());
properties.add(propObj);
}
// $NON-NLS-1$
defObj.putJsonProperty("properties", properties);
return defObj;
} catch (JsonException e) {
throw new RuntimeException(e);
}
}).forEach(defObj -> {
try {
defs.add(defObj);
} catch (JsonException e) {
throw new RuntimeException(e);
}
});
// $NON-NLS-1$
componentInfo.putJsonProperty("components", defs);
}
os.print(componentInfo.toString());
} catch (Throwable e) {
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter out = new PrintWriter(baos);
e.printStackTrace(out);
out.flush();
os.println(LineDelimitedJsonProgressMonitor.message(// $NON-NLS-1$ //$NON-NLS-2$
"type", // $NON-NLS-1$ //$NON-NLS-2$
"error", // $NON-NLS-1$
"stackTrace", // $NON-NLS-1$
baos.toString()));
}
}
use of com.ibm.xsp.registry.FacesProperty in project org.openntf.nsfodp by OpenNTF.
the class StockComponentsServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setBufferSize(0);
// $NON-NLS-1$ //$NON-NLS-2$
resp.setHeader("Content-Type", "text/json");
ServletOutputStream os = resp.getOutputStream();
try {
if (componentInfo == null) {
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();
componentInfo = new JsonJavaObject();
JsonArray defs = new JsonJavaArray();
facesRegistry.findComponentDefs().stream().filter(FacesComponentDefinition::isTag).map(def -> {
try {
JsonObject defObj = new JsonJavaObject();
// $NON-NLS-1$
defObj.putJsonProperty("namespaceUri", def.getNamespaceUri());
// $NON-NLS-1$
defObj.putJsonProperty("tagName", def.getTagName());
// $NON-NLS-1$
defObj.putJsonProperty("class", def.getJavaClass().getName());
// $NON-NLS-1$
defObj.putJsonProperty("since", def.getSince());
// $NON-NLS-1$
defObj.putJsonProperty("defaultPrefix", def.getFirstDefaultPrefix());
// $NON-NLS-1$
defObj.putJsonProperty("componentFamily", def.getComponentFamily());
// $NON-NLS-1$
defObj.putJsonProperty("componentType", def.getComponentType());
// $NON-NLS-1$
defObj.putJsonProperty("id", def.getId());
JsonArray facetNames = new JsonJavaArray();
for (String facetName : def.getFacetNames()) {
facetNames.add(facetName);
}
// $NON-NLS-1$
defObj.putJsonProperty("facetNames", facetNames);
FacesProperty defaultProp = def.getDefaultFacesProperty();
if (defaultProp != null) {
JsonObject defaultPropObj = new JsonJavaObject();
// $NON-NLS-1$
defaultPropObj.putJsonProperty("name", defaultProp.getName());
// $NON-NLS-1$
defaultPropObj.putJsonProperty("since", defaultProp.getSince());
// $NON-NLS-1$
defaultPropObj.putJsonProperty("class", defaultProp.getJavaClass().getName());
// $NON-NLS-1$
defaultPropObj.putJsonProperty("required", defaultProp.isRequired());
// $NON-NLS-1$
defaultPropObj.putJsonProperty("attribute", defaultProp.isAttribute());
}
JsonArray properties = new JsonJavaArray();
for (String propName : def.getPropertyNames()) {
FacesProperty prop = def.getProperty(propName);
JsonObject propObj = new JsonJavaObject();
// $NON-NLS-1$
propObj.putJsonProperty("name", propName);
// $NON-NLS-1$
propObj.putJsonProperty("class", prop.getJavaClass().getName());
// $NON-NLS-1$
propObj.putJsonProperty("since", prop.getSince());
// $NON-NLS-1$
propObj.putJsonProperty("required", prop.isRequired());
// $NON-NLS-1$
propObj.putJsonProperty("attribute", prop.isAttribute());
properties.add(propObj);
}
// $NON-NLS-1$
defObj.putJsonProperty("properties", properties);
return defObj;
} catch (JsonException e) {
throw new RuntimeException(e);
}
}).forEach(defObj -> {
try {
defs.add(defObj);
} catch (JsonException e) {
throw new RuntimeException(e);
}
});
// $NON-NLS-1$
componentInfo.putJsonProperty("components", defs);
}
os.print(JsonGenerator.toJson(JsonJavaFactory.instance, componentInfo, false));
} catch (Throwable e) {
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter out = new PrintWriter(baos);
e.printStackTrace(out);
out.flush();
os.println(baos.toString());
}
}
use of com.ibm.xsp.registry.FacesProperty in project org.openntf.nsfodp by OpenNTF.
the class AbstractSchemaServlet method outProperties.
private void outProperties(FacesDefinition def, Element element, SharableRegistryImpl registry) {
Collection<String> names = def.getPropertyNames();
for (String propName : names) {
FacesProperty prop = def.getProperty(propName);
outProperty(def, prop, element, registry);
}
// TODO see if xp:key can be restricted to when it's immediately under a facets tag
if (!names.contains("id")) {
Element all = (Element) element.getFirstChild();
Element thisId = DOMUtil.createElement(element.getOwnerDocument(), all, "xs:element");
thisId.setAttribute("name", "this.id");
thisId.setAttribute("type", extMap.get(this.namespace) + ":attrLoadBinding");
Element attrId = DOMUtil.createElement(element.getOwnerDocument(), element, "xs:attribute");
attrId.setAttribute("name", "id");
attrId.setAttribute("type", "xs:ID");
}
if (!names.contains("xp:key")) {
Element attrId = DOMUtil.createElement(element.getOwnerDocument(), element, "xs:attribute");
attrId.setAttribute("ref", "xp:key");
}
// Special handling for xp:actionGroup et al to allow for actions without this.actions
if (isWorkaroundContainerType(def)) {
Element all = (Element) element.getFirstChild();
DOMUtil.createElement(element.getOwnerDocument(), all, "xs:any").setAttribute("processContents", "lax");
}
// if(names.isEmpty()) {
// // Add an xs:anyAttribute here to make this extensible down the line
// DOMUtil.createElement(element.getOwnerDocument(), element, "xs:anyAttribute");
// }
}
Aggregations