use of org.glassfish.admingui.connector.IntegrationPoint in project Payara by payara.
the class IntegrationPointComparator method compare.
/**
* <p> This method compares two {@link IntegrationPoint}s. It will first
* check the <code>parentId</code>, then the <code>priority</code> if
* the <code>parentId</code>s are equal. If the priorities happen to
* be equal as well, it will compare the <code>id</code>s.</p>
*/
public int compare(IntegrationPoint ip1, IntegrationPoint ip2) {
// First check parentIds
String left = "" + ip1.getParentId();
int result = left.compareTo("" + ip2.getParentId());
if (result == 0) {
// parentIds are the same, check the priorities
result = ip1.getPriority() - ip2.getPriority();
if (result == 0) {
// priorities are the same, check the ids
left = "" + ip1.getId();
result = left.compareTo("" + ip2.getId());
if (result == 0) {
// Equal
return 0;
}
}
}
// Return the answer
return (result < 0) ? -1 : 1;
}
use of org.glassfish.admingui.connector.IntegrationPoint in project Payara by payara.
the class ThemeHandlers method getLowestPriorityNum.
private static int getLowestPriorityNum(List ipList) {
Iterator iter = ipList.iterator();
// assuming priority values can only be 1 to 100
int lowest = 101;
while (iter.hasNext()) {
IntegrationPoint iP = (IntegrationPoint) iter.next();
if (iP.getPriority() < lowest) {
lowest = iP.getPriority();
}
}
return lowest;
}
use of org.glassfish.admingui.connector.IntegrationPoint in project Payara by payara.
the class PluginHandlers method getContentOfIntegrationPoints.
/**
* Finds the integration point of the specified type. Returns the contents of this IP type as a list.
* The content can be a comma separated String.
* This is useful for the case such as dropdown or list box to allow additional options in the component.
*/
@Handler(id = "getContentOfIntegrationPoints", input = { @HandlerInput(name = "type", type = String.class, required = true) }, output = { @HandlerOutput(name = "labels", type = List.class), @HandlerOutput(name = "values", type = List.class) })
public static void getContentOfIntegrationPoints(HandlerContext handlerCtx) throws java.io.IOException {
// Get the input
String type = (String) handlerCtx.getInputValue("type");
// Get the IntegrationPoints
FacesContext ctx = handlerCtx.getFacesContext();
Set<IntegrationPoint> points = getSortedIntegrationPoints(getIntegrationPoints(ctx, type));
List labels = new ArrayList();
List values = new ArrayList();
if (points != null) {
for (IntegrationPoint it : points) {
String content = it.getContent();
if (GuiUtil.isEmpty(content)) {
GuiUtil.getLogger().warning("No Content specified for Integration Point: " + type + " id : " + it.getId());
continue;
}
List<String> labelsAndValues = GuiUtil.parseStringList(content, "|");
values.add(labelsAndValues.get(0));
labels.add(GuiUtil.getMessage(labelsAndValues.get(1), labelsAndValues.get(2)));
}
}
handlerCtx.setOutputValue("labels", labels);
handlerCtx.setOutputValue("values", values);
}
use of org.glassfish.admingui.connector.IntegrationPoint in project Payara by payara.
the class PluginHandlers method includeIntegrationPoints.
/**
* @param points This parameter should be the {@link IntegrationPoint}s
* to include in the order in which you want to include
* them if that matters (i.e. use <code>SortedSet</code>).
*/
public static void includeIntegrationPoints(FacesContext ctx, UIComponent root, Set<IntegrationPoint> points) {
if (points == null) {
// Do nothing...
return;
}
if (root == null) {
// No root is specified, search whole page
root = ctx.getViewRoot();
}
// Iterate
IntegrationPoint point;
Iterator<IntegrationPoint> it = null;
int lastSize = 0;
int currSize = points.size();
String parentId = null;
String lastParentId = null;
while (currSize != lastSize) {
// Stop loop by comparing previous size
lastSize = currSize;
it = points.iterator();
lastParentId = "";
UIComponent parent = root;
// Iterate through the IntegrationPoints
while (it.hasNext()) {
point = it.next();
// Optimize for multiple plugins for the same parent
parentId = point.getParentId();
// Resolve any EL that may be used in identifying the parent ID
parentId = (String) ComponentUtil.getInstance(ctx).resolveValue(ctx, null, root, parentId);
if ((parentId == null) || !parentId.equals(lastParentId)) {
// New parent (or root -- null)
parent = getIntegrationPointParent(ctx, root, point);
}
if (parent == null) {
// Didn't find the one specified!
// FIXME: log FINE! Note this may not be a problem, keep iterating to see if we find it later.
// System.out.println("The specified parentId (" + parentId + ") was not found!");
lastParentId = null;
continue;
}
lastParentId = parent.getId();
// Add the content
includeIntegrationPoint(ctx, parent, point);
// We found the parent, remove from our list of IPs to add
it.remove();
}
// Get the set size to see if we have any left to process
currSize = points.size();
}
}
use of org.glassfish.admingui.connector.IntegrationPoint in project Payara by payara.
the class PluginHandlers method includeFirstIntegrationPoint.
/**
* Includes the first IP based on priority for the given type. It adds
* the content to the given UIComponent root. If the IP content looks
* like a URL (contains ://), a StaticText component will be added with
* the value of the content from the URL.
*/
@Handler(id = "includeFirstIntegrationPoint", input = { @HandlerInput(name = "type", type = String.class, required = true), @HandlerInput(name = "root", type = UIComponent.class, required = false) })
public static void includeFirstIntegrationPoint(HandlerContext handlerCtx) throws java.io.IOException {
// Get the input
String type = (String) handlerCtx.getInputValue("type");
UIComponent root = (UIComponent) handlerCtx.getInputValue("root");
// Get the IntegrationPoints
FacesContext ctx = handlerCtx.getFacesContext();
Set<IntegrationPoint> points = getSortedIntegrationPoints(getIntegrationPoints(ctx, type));
if (points != null) {
Iterator<IntegrationPoint> it = points.iterator();
if (it.hasNext()) {
// Get the first one...
IntegrationPoint point = it.next();
root = getIntegrationPointParent(ctx, root, point);
// Check to see if IP points to an external URL...
if (point.getContent().lastIndexOf("://", 15) != -1) {
// Treat content as a url...
URL contentURL = FileUtil.searchForFile(point.getContent(), null);
if (contentURL == null) {
throw new IOException("Unable to locate file: " + point.getContent());
}
// Read the content...
String content = new String(FileUtil.readFromURL(contentURL));
// Create a StaticText component and add it under the
// "root" component.
LayoutComponent stDesc = new LayoutComponent(null, "externalContent", new ComponentType("tmpTextCT", "com.sun.jsftemplating.component.factory.basic.StaticTextFactory"));
stDesc.addOption("value", content);
ComponentUtil.getInstance(ctx).createChildComponent(ctx, stDesc, root);
} else {
// Include the first one...
includeIntegrationPoint(ctx, root, point);
}
}
}
}
Aggregations