/** * locate and return a json node inside a structure. * * @param parent * @param path slash separated path * @return requested node */ public static JsonNode getByPath(JsonNode parent, String path) { if (path == null || parent == null) return null; JsonNode cur = parent; for (String part : path.split("/")) { if (MString.isSet(part)) cur = cur.get(part); if (cur == null) return null; } return cur; }
public String getMsgCaption() { if (MString.isSet(msg) && msg.startsWith("m=")) { Map<String, String> msgParts = MUri.explode(msg); return msgParts.get("c"); } return null; }
public String getMsgMessage() { if (MString.isSet(msg) && msg.startsWith("m=")) { Map<String, String> msgParts = MUri.explode(msg); return msgParts.get("m"); } return msg; }
@Override public String createSqlSelect(Class<?> clazz, String columns, String qualification) { StringBuilder sql = new StringBuilder(); sql.append("SELECT ").append(columns).append(" FROM $db.").append(getMappingName(clazz)).append("$ "); if (MString.isSet(qualification)) { String low = qualification.trim().substring(0, Math.min(qualification.length(), 6)).toLowerCase(); if (low.startsWith("order ") || low.startsWith("limit ")) sql.append(qualification); else sql.append("WHERE ").append(qualification); } String s = sql.toString(); return s; }
@Override public void menuSelected(MenuItem selectedItem) { String text = selectedItem.getDescription(); if (MString.isSet(text)) { String[] parts = text.split("\\|", 4); if (parts.length == 4) { if (parts[2].equals("null")) parts[2] = null; if (parts[3].equals("null")) parts[3] = null; openSpace(parts[1], parts[2], parts[3]); } } }
public FilterRequest(String text) { LinkedList<String> lText = new LinkedList<String>(); facets = new HashMap<String, String>(); for (String part : text.split(" ")) { part = part.trim(); if (MString.isSet(part)) { if (part.indexOf(':') > 0) { facets.put(MString.beforeIndex(part, ':'), MString.afterIndex(part, ':')); } else { lText.add(part); } } } this.text = lText.toArray(new String[lText.size()]); }
public FilterRequest(String text) { if (text == null) return; LinkedList<String> lText = new LinkedList<String>(); facets = new HashMap<String, String>(); for (String part : text.split(" ")) { part = part.trim(); if (MString.isSet(part)) { if (part.startsWith("'") && part.endsWith("'") && part.length() > 1) { part = MUri.decode(part.substring(1,part.length()-1)); } int p = part.indexOf(':'); if (p > 0) { facets.put(part.substring(0, p), part.substring(p+1)); } else { lText.add(part); } } } this.text = lText.toArray(new String[lText.size()]); }
@Override public <T> long getMaxByQualification(DbConnection con, T object, String registryName, String field, String qualification, Map<String,Object> attributes) throws MException { reloadLock.waitWithException(MAX_LOCK); Class<?> clazz = schema.findClassForObject(object,this); StringBuilder sql = new StringBuilder(); sql.append("SELECT max($db.").append(getMappingName(clazz)).append(".").append(field).append("$) AS max FROM $db.").append(getMappingName(clazz)).append("$ "); if (MString.isSet(qualification)) { String low = qualification.trim().toLowerCase(); if (low.startsWith("order ") || low.startsWith("limit ")) sql.append(qualification); else sql.append("WHERE ").append(qualification); } return executeCountQuery(con, "max", sql.toString(), attributes); }
private void findVersion() { valid = false; version = null; if (binary == null || binary.indexOf("soffice") < 0) return; try { String[] res = MSystem.execute(binary,"--version"); version = res[0]; valid = MString.isSet(version) && version.startsWith("LibreOffice "); } catch (IOException e) { if (MSystem.isUnix()) { // retry with unix default location File f = new File("/usr/bin/soffice"); if (f.exists() && f.canExecute()) { binary = f.getPath(); try { String[] res = MSystem.execute(binary,"--version"); version = res[0]; valid = MString.isSet(version) && version.startsWith("LibreOffice "); } catch (IOException e2) { } } } } }
public static SecureString create(String pubKey, String secret) { if (MString.isSet(pubKey)) return new CryptedString(pubKey, secret); return new SecureString(secret); }
@Override public CaoNode getResourceByPath(String path) { synchronized (this) { AdbNode node = cache.get(path); if (node != null) { if (node.isValid()) return node; cache.remove(path); } node = (AdbNode) getRoot(); for (String part : path.split("/")) { if (MString.isSet(part)) { node = (AdbNode) node.getNode(part); if (node == null) return null; } } cache.put(path, node); return node; } }
@Override public CaoNode getResourceByPath(String path) { checkState(); synchronized (this) { FsNode node = cache == null ? null : cache.get(path); if (node != null) { if (node.isValid()) return node; cache.remove(path); } node = root; for (String part : path.split("/")) { if (MString.isSet(part)) { node = (FsNode) node.getNode(part); if (node == null) return null; } } if (cache != null) cache.put(path, node); return node; } }
@Override public <T,R> List<R> getAttributeByQualification(DbConnection con, Class<? extends T> clazz, String registryName, String attribute, String qualification, Map<String,Object> attributes) throws MException { getSchema().authorizeReadAttributes(con, this, clazz, registryName, attribute); reloadLock.waitWithException(MAX_LOCK); Class<? extends Persistable> clazz2 = schema.findClassForObject(clazz,this); StringBuilder sql = new StringBuilder(); sql.append("SELECT $db.").append(getMappingName(clazz2)).append(".").append(attribute).append("$ AS value FROM $db.").append(getMappingName(clazz2)).append("$ "); if (MString.isSet(qualification)) { String low = qualification.trim().toLowerCase(); if (low.startsWith("order ") || low.startsWith("limit ")) sql.append(qualification); else sql.append("WHERE ").append(qualification); } return executeAttributeQuery(con, "value", sql.toString(), attributes); }
@Override public CaoNode getResourceByPath(String path) { checkState(); if (path == null) return null; synchronized (this) { FdbNode node = cache == null ? null : cache.get(path); if (node != null) { if (node.isValid()) return node; cache.remove(path); } node = root; for (String part : path.split("/")) { if (MString.isSet(part)) { node = (FdbNode) node.getNode(part); if (node == null) return null; } } if (cache != null) cache.put(path, node); return node; } }
try { byte[] encKey = key.getBytesBlock(); if (MString.isSet(passphrase)) encKey = Blowfish.decrypt(encKey, passphrase); PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(encKey);
@Override public void doInitialize(IApiInternal internal, CfgManager manager, IConfig config) { ResourceNode<?> system = manager.getCfg("system"); try { String key = MConstants.PROP_BASE_DIR; String name = system.getString(key); if (MString.isEmpty(name)) name = System.getProperty(MConstants.PROP_PREFIX + key); if (MString.isSet(name)) internal.setBaseDir( new File(name) ); } catch (Throwable t) {MApi.dirtyLog(t);} }
@Override public PemBlock sign(PemPriv key, String text, String passphrase) throws MException { try { byte[] encKey = key.getBytesBlock(); if (MString.isSet(passphrase)) encKey = Blowfish.decrypt(encKey, passphrase); PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(encKey); KeyFactory keyFactory = KeyFactory.getInstance("ECDSA", "BC"); PrivateKey privKey = keyFactory.generatePrivate(privKeySpec); Signature dsa = Signature.getInstance("SHA512WITHECDSA", "BC"); dsa.initSign(privKey); byte[] buffer = text.getBytes(); dsa.update(buffer, 0, buffer.length); byte[] realSig = dsa.sign(); PemBlockModel out = new PemBlockModel(PemBlock.BLOCK_SIGN, realSig); CryptUtil.prepareSignOut(key, out, getName()); return out; } catch (Exception e) { throw new MException(e); } }
if (MString.isSet(passphrase)) encKey = Blowfish.decrypt(encKey, passphrase); PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(encKey);
@Override public PemBlock sign(PemPriv key, String text, String passphrase) throws MException { try { byte[] encKey = key.getBytesBlock(); if (MString.isSet(passphrase)) encKey = Blowfish.decrypt(encKey, passphrase); PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(encKey); KeyFactory keyFactory = KeyFactory.getInstance("DSA", "SUN"); PrivateKey privKey = keyFactory.generatePrivate(privKeySpec); Signature dsa = Signature.getInstance("SHA1withDSA", "SUN"); dsa.initSign(privKey); byte[] buffer = text.getBytes(); dsa.update(buffer, 0, buffer.length); byte[] realSig = dsa.sign(); PemBlockModel out = new PemBlockModel(PemBlock.BLOCK_SIGN, realSig); CryptUtil.prepareSignOut(key, out, getName()); return out; } catch (Exception e) { throw new MException(e); } }
@Override public String getConnectInfo() { return (CFG_TLS.value() ? "tls:" : "smtp:") + "//"+ (MString.isSet(CFG_MAIL_USER.value()) ? CFG_MAIL_USER.value() + "@" : "") + CFG_HOST.value() + ":" + CFG_PORT.value(); }