public static boolean setProjectionDefault(Object flavor, String tableName, ValMap map) { if (ProfileManager.transportsLoaded()) { String xpath = ProfileManager.transportsSelector + flavorSelector(flavor); Element element = selectElement(ProfileManager.transports, xpath); if (element != null && notNullOrEmpty(tableName)) { Element el = ProfileManager.transports.createElement("PROJECTION"); try { BidiMultiMap projection = (BidiMultiMap) map.get("projection"); xmlSerialize(projection, el, null); el.setAttribute("version", "" + map.get("version")); el.setAttribute("table", tableName); } catch (Exception e) { Log.e(TAG, "setDefaultProjection", e); return false; } NodeList nodes = evaluateXPath(element, "." + projectionSelector(tableName)); if (nodes != null && nodes.getLength() > 0) { Node node = nodes.item(0); node.getParentNode().replaceChild(el, node); } else element.appendChild(el); ProfileManager.saveTransports(); return true; } } return false; }
@SuppressWarnings("unchecked") private void updateModel(boolean refresh, boolean save, boolean keepSelection, Object... params) { String function = param(getFunction(), 0, params); if (ProfileManager.transportsLoaded()) { if (refresh) { blockDirty( new Job<Void>() { public void perform(Void t, Object[] params) throws Exception { DefaultComboBoxModel model = (DefaultComboBoxModel) comboBoxes[0].getModel(); model.removeAllElements(); NodeList nodes = evaluateXPath(ProfileManager.transports, selector + "/FUNCTION"); for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); model.addElement(element.getAttribute("name")); } comboBoxes[0].setModel(model); } }); } if (save) ProfileManager.saveTransports(); } if (!refresh) return; if (!keepSelection) function = getFunction(); setFunction(function); }
@Override protected Element select(Object... function) { if (ProfileManager.transportsLoaded()) { String xpath = selector; if (isAvailable(0, function)) { xpath += "/FUNCTION[@name='" + function[0] + "'"; if (notNullOrEmpty(profile)) xpath += " and @profile='" + profile + "'"; xpath += "]"; } return selectElement(ProfileManager.transports, xpath); } return null; }
public static Object doConversion(Object value, String function, String oper, Object... params) { try { if (!ProfileManager.transportsLoaded() || nullOrEmpty(function)) return value; NameSpace tmp = new NameSpace(BeanShell.getNameSpace(), "transport"); tmp.setVariable("value", value); tmp.setVariable("oper", oper); Element el = selectElement(ProfileManager.transports, "//FUNCTION[@name='" + function + "']"); if (el == null) { BerichtsheftPlugin.consoleMessage("berichtsheft.doConversion.message.1", function); return value; } String script = param(el.getTextContent(), 0, params); return BeanShell.eval(null, tmp, script); } catch (Exception e) { BerichtsheftPlugin.consoleMessage("berichtsheft.doConversion.message.2", function, value); return null; } }
@Override protected boolean addItem(boolean refresh, Object function) { if (ProfileManager.transportsLoaded()) { String body = textArea.getText(); if (notNullOrEmpty(body)) { Element element = ProfileManager.transports.createElement("FUNCTION"); element.setAttribute("name", stringValueOf(function)); if (notNullOrEmpty(profile)) element.setAttribute("profile", profile); Element el = ProfileManager.transports.createElement("BODY"); CDATASection cdata = ProfileManager.transports.createCDATASection(body); el.appendChild(cdata); element.appendChild(el); select().appendChild(element); updateModel(true, true, true, function); return true; } } return false; }
public static ValMap getProjectionDefault(Object flavor, String tableName) { ValMap map = vmap(); if (ProfileManager.transportsLoaded()) { String xpath = ProfileManager.transportsSelector + flavorSelector(flavor); Element element = selectElement(ProfileManager.transports, xpath); if (element != null) { NodeList nodes = evaluateXPath(element, "." + projectionSelector(tableName)); if (nodes != null && nodes.getLength() > 0) { element = (Element) nodes.item(0); try { map.put("table", tableName); map.put("version", toInt(-1, element.getAttribute("version"))); map.put("projection", xmlDeserialize(element, null)); } catch (Exception e) { Log.e(TAG, "getDefaultProjection", e); } } } } return map; }