Search in sources :

Example 6 with RHExtension

use of lucee.runtime.extension.RHExtension in project Lucee by lucee.

the class ConfigServerImpl method loadLocalExtensions.

@Override
public List<ExtensionDefintion> loadLocalExtensions() {
    Resource[] locReses = getLocalExtensionProviderDirectory().listResources(new ExtensionResourceFilter(".lex"));
    if (localExtensions == null || localExtSize != locReses.length || extHash(locReses) != localExtHash) {
        localExtensions = new ArrayList<ExtensionDefintion>();
        Map<String, String> map = new HashMap<String, String>();
        RHExtension ext;
        String v, fileName, uuid, version;
        ExtensionDefintion ed;
        for (int i = 0; i < locReses.length; i++) {
            ed = null;
            // we stay happy with the file name when it has the right pattern (uuid-version.lex)
            fileName = locReses[i].getName();
            if (fileName.length() > 39) {
                uuid = fileName.substring(0, 35);
                version = fileName.substring(36, fileName.length() - 4);
                if (Decision.isUUId(uuid)) {
                    ed = new ExtensionDefintion(uuid, version);
                    ed.setSource(this, locReses[i]);
                }
            }
            if (ed == null) {
                try {
                    ext = new RHExtension(this, locReses[i], false);
                    ed = new ExtensionDefintion(ext.getId(), ext.getVersion());
                    ed.setSource(ext);
                } catch (Exception e) {
                    SystemOut.printDate(e);
                }
            }
            if (ed != null) {
                // check if we already have an extension with the same id to avoid having more than once
                v = map.get(ed.getId());
                if (v != null && v.compareToIgnoreCase(ed.getId()) > 0)
                    continue;
                map.put(ed.getId(), ed.getVersion());
                localExtensions.add(ed);
            }
        }
        localExtHash = extHash(locReses);
        // we store the size because localExtensions size could be smaller because of duplicates
        localExtSize = locReses.length;
    }
    return localExtensions;
}
Also used : RHExtension(lucee.runtime.extension.RHExtension) ExtensionDefintion(lucee.runtime.extension.ExtensionDefintion) HashMap(java.util.HashMap) Resource(lucee.commons.io.res.Resource) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) FunctionLibException(lucee.transformer.library.function.FunctionLibException) PageException(lucee.runtime.exp.PageException) TagLibException(lucee.transformer.library.tag.TagLibException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ExpressionException(lucee.runtime.exp.ExpressionException) ApplicationException(lucee.runtime.exp.ApplicationException)

Example 7 with RHExtension

use of lucee.runtime.extension.RHExtension in project Lucee by lucee.

the class ConfigServerImpl method getAllRHExtensions.

@Override
public Collection<RHExtension> getAllRHExtensions() {
    Map<String, RHExtension> rtn = new HashMap<>();
    // server (this)
    RHExtension[] arr = getRHExtensions();
    for (RHExtension rhe : arr) {
        rtn.put(rhe.getId(), rhe);
    }
    // webs
    ConfigWeb[] cws = getConfigWebs();
    for (ConfigWeb cw : cws) {
        arr = ((ConfigWebImpl) cw).getRHExtensions();
        for (RHExtension rhe : arr) {
            rtn.put(rhe.getId(), rhe);
        }
    }
    return rtn.values();
}
Also used : RHExtension(lucee.runtime.extension.RHExtension) HashMap(java.util.HashMap)

Example 8 with RHExtension

use of lucee.runtime.extension.RHExtension in project Lucee by lucee.

the class ExportImportHandler method _export.

private static Map<String, Object> _export(ConfigImpl config, short types, Resource dir, String pathAppendix, boolean addOptionalArtifacts, String regularMappingFilter, String componentMappingFilter, String customtagMappingFilter) throws IOException {
    Map<String, Object> map = new HashMap<String, Object>();
    // Core
    if ((types & TYPE_CONFIGURATION) > 0) {
    }
    // Extension
    if ((types & TYPE_EXTENSION) > 0) {
        Resource extDir = dir.getRealResource("extensions");
        extDir.mkdirs();
        List<Object> extensions = new ArrayList<Object>();
        map.put("extensions", extensions);
        Map<String, String> m;
        for (RHExtension ext : config.getRHExtensions()) {
            m = new HashMap<String, String>();
            extensions.add(m);
            m.put("id", ext.getId());
            m.put("version", ext.getVersion());
            if (dir != null) {
                m.put("artifact", pathAppendix + "/extensions/" + ext.getExtensionFile().getName());
                if (addOptionalArtifacts)
                    IOUtil.copy(ext.getExtensionFile(), extDir.getRealResource(ext.getExtensionFile().getName()));
            }
        }
    }
    // Core
    if ((types & TYPE_CORE) > 0 && config instanceof ConfigServer) {
        map.put("core", CFMLEngineFactory.getInstance().getInfo().getVersion().toString());
    }
    // Files
    if ((types & TYPE_FILES) > 0) {
        Resource mapDir = dir.getRealResource("mappings");
        HashMap<String, Object> mappings = new HashMap<String, Object>();
        map.put("mappings", mappings);
        mappings.put("regular", exportMapping(config.getMappings(), mapDir.getRealResource("regular"), pathAppendix + "/mappings/regular/", regularMappingFilter));
        mappings.put("component", exportMapping(config.getComponentMappings(), mapDir.getRealResource("component"), pathAppendix + "/mappings/component/", componentMappingFilter));
        mappings.put("customtag", exportMapping(config.getCustomTagMappings(), mapDir.getRealResource("customtag"), pathAppendix + "/mappings/customtag/", customtagMappingFilter));
    }
    return map;
}
Also used : RHExtension(lucee.runtime.extension.RHExtension) HashMap(java.util.HashMap) Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList)

Example 9 with RHExtension

use of lucee.runtime.extension.RHExtension in project Lucee by lucee.

the class XMLConfigAdmin method updateRHExtension.

public void updateRHExtension(Config config, Resource ext, boolean reload) throws PageException {
    RHExtension rhext;
    try {
        rhext = new RHExtension(config, ext, true);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        DeployHandler.moveToFailedFolder(ext.getParentResource(), ext);
        throw Caster.toPageException(t);
    }
    updateRHExtension(config, rhext, reload);
}
Also used : RHExtension(lucee.runtime.extension.RHExtension)

Example 10 with RHExtension

use of lucee.runtime.extension.RHExtension in project Lucee by lucee.

the class Admin method doGetLocalExtension.

private void doGetLocalExtension() throws PageException {
    String id = getString("admin", action, "id");
    boolean asBinary = getBoolV("asBinary", false);
    if (asBinary) {
        Iterator<ExtensionDefintion> it = DeployHandler.getLocalExtensions(config).iterator();
        ExtensionDefintion ext;
        while (it.hasNext()) {
            ext = it.next();
            if (id.equalsIgnoreCase(ext.getId())) {
                try {
                    pageContext.setVariable(getString("admin", action, "returnVariable"), IOUtil.toBytes(ext.getSource()));
                    return;
                } catch (IOException e) {
                    throw Caster.toPageException(e);
                }
            }
        }
        throw new ApplicationException("there is no local extension with id " + id);
    } else {
        List<RHExtension> locals = RHExtension.toRHExtensions(DeployHandler.getLocalExtensions(config));
        Query qry = RHExtension.toQuery(config, locals.toArray(new RHExtension[locals.size()]));
        int rows = qry.getRecordcount();
        String _id;
        int row = 0;
        for (int r = 1; r <= rows; r++) {
            _id = Caster.toString(qry.getAt(KeyConstants._id, r), null);
            if (id.equalsIgnoreCase(_id)) {
                row = r;
                break;
            }
        }
        if (row == 0)
            throw new ApplicationException("there is no local extension with id " + id);
        pageContext.setVariable(getString("admin", action, "returnVariable"), Caster.toStruct(qry, row));
    }
}
Also used : RHExtension(lucee.runtime.extension.RHExtension) ApplicationException(lucee.runtime.exp.ApplicationException) Query(lucee.runtime.type.Query) ExtensionDefintion(lucee.runtime.extension.ExtensionDefintion) IOException(java.io.IOException)

Aggregations

RHExtension (lucee.runtime.extension.RHExtension)15 ApplicationException (lucee.runtime.exp.ApplicationException)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Resource (lucee.commons.io.res.Resource)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 PageException (lucee.runtime.exp.PageException)5 FunctionLibException (lucee.transformer.library.function.FunctionLibException)5 TagLibException (lucee.transformer.library.tag.TagLibException)5 MalformedURLException (java.net.MalformedURLException)4 ClassException (lucee.commons.lang.ClassException)4 SecurityException (lucee.runtime.exp.SecurityException)4 ExtensionDefintion (lucee.runtime.extension.ExtensionDefintion)4 BundleInfo (lucee.runtime.osgi.BundleInfo)4 BundleException (org.osgi.framework.BundleException)4 Element (org.w3c.dom.Element)4 ZipInputStream (java.util.zip.ZipInputStream)3 BundleDefinition (lucee.runtime.osgi.OSGiUtil.BundleDefinition)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 UnknownHostException (java.net.UnknownHostException)2