Search in sources :

Example 26 with Mapping

use of lucee.runtime.Mapping in project Lucee by lucee.

the class ConfigImpl method getPageSourceExisting.

public PageSource getPageSourceExisting(PageContext pc, Mapping[] mappings, String realPath, boolean onlyTopLevel, boolean useSpecialMappings, boolean useDefaultMapping, boolean onlyPhysicalExisting) {
    realPath = realPath.replace('\\', '/');
    String lcRealPath = StringUtil.toLowerCase(realPath) + '/';
    Mapping mapping;
    PageSource ps;
    if (mappings != null) {
        for (int i = 0; i < mappings.length; i++) {
            mapping = mappings[i];
            // print.err(lcRealPath+".startsWith"+(mapping.getStrPhysical()));
            if (lcRealPath.startsWith(mapping.getVirtualLowerCaseWithSlash(), 0)) {
                ps = mapping.getPageSource(realPath.substring(mapping.getVirtual().length()));
                if (onlyPhysicalExisting) {
                    if (ps.physcalExists())
                        return ps;
                } else if (ps.exists())
                    return ps;
            }
        }
    }
    // / special mappings
    if (useSpecialMappings && lcRealPath.startsWith("/mapping-", 0)) {
        String virtual = "/mapping-tag";
        // tag mappings
        Mapping[] tagMappings = (this instanceof ConfigWebImpl) ? new Mapping[] { ((ConfigWebImpl) this).getServerTagMapping(), getTagMapping() } : new Mapping[] { getTagMapping() };
        if (lcRealPath.startsWith(virtual, 0)) {
            for (int i = 0; i < tagMappings.length; i++) {
                mapping = tagMappings[i];
                // if(lcRealPath.startsWith(mapping.getVirtualLowerCaseWithSlash(),0)) {
                ps = mapping.getPageSource(realPath.substring(virtual.length()));
                if (onlyPhysicalExisting) {
                    if (ps.physcalExists())
                        return ps;
                } else if (ps.exists())
                    return ps;
            // }
            }
        }
        // customtag mappings
        tagMappings = getCustomTagMappings();
        virtual = "/mapping-customtag";
        if (lcRealPath.startsWith(virtual, 0)) {
            for (int i = 0; i < tagMappings.length; i++) {
                mapping = tagMappings[i];
                // if(lcRealPath.startsWith(mapping.getVirtualLowerCaseWithSlash(),0)) {
                ps = mapping.getPageSource(realPath.substring(virtual.length()));
                if (onlyPhysicalExisting) {
                    if (ps.physcalExists())
                        return ps;
                } else if (ps.exists())
                    return ps;
            // }
            }
        }
    }
    // component mappings (only used for gateway)
    if (pc != null && ((PageContextImpl) pc).isGatewayContext()) {
        boolean isCFC = Constants.isComponentExtension(ResourceUtil.getExtension(realPath, null));
        if (isCFC) {
            Mapping[] cmappings = getComponentMappings();
            for (int i = 0; i < cmappings.length; i++) {
                ps = cmappings[i].getPageSource(realPath);
                if (onlyPhysicalExisting) {
                    if (ps.physcalExists())
                        return ps;
                } else if (ps.exists())
                    return ps;
            }
        }
    }
    // config mappings
    for (int i = 0; i < this.mappings.length - 1; i++) {
        mapping = this.mappings[i];
        if ((!onlyTopLevel || mapping.isTopLevel()) && lcRealPath.startsWith(mapping.getVirtualLowerCaseWithSlash(), 0)) {
            ps = mapping.getPageSource(realPath.substring(mapping.getVirtual().length()));
            if (onlyPhysicalExisting) {
                if (ps.physcalExists())
                    return ps;
            } else if (ps.exists())
                return ps;
        }
    }
    if (useDefaultMapping) {
        ps = this.mappings[this.mappings.length - 1].getPageSource(realPath);
        if (onlyPhysicalExisting) {
            if (ps.physcalExists())
                return ps;
        } else if (ps.exists())
            return ps;
    }
    return null;
}
Also used : Mapping(lucee.runtime.Mapping) PageSource(lucee.runtime.PageSource)

Example 27 with Mapping

use of lucee.runtime.Mapping in project Lucee by lucee.

the class ConfigImpl method setMappings.

/**
 * @param mappings The mappings to set.
 */
protected void setMappings(Mapping[] mappings) {
    Arrays.sort(mappings, new Comparator() {

        public int compare(Object left, Object right) {
            Mapping r = ((Mapping) right);
            Mapping l = ((Mapping) left);
            int rtn = r.getVirtualLowerCaseWithSlash().length() - l.getVirtualLowerCaseWithSlash().length();
            if (rtn == 0)
                return slashCount(r) - slashCount(l);
            return rtn;
        }

        private int slashCount(Mapping l) {
            String str = l.getVirtualLowerCaseWithSlash();
            int count = 0, lastIndex = -1;
            while ((lastIndex = str.indexOf('/', lastIndex)) != -1) {
                count++;
                lastIndex++;
            }
            return count;
        }
    });
    this.mappings = mappings;
}
Also used : Mapping(lucee.runtime.Mapping) Comparator(java.util.Comparator)

Example 28 with Mapping

use of lucee.runtime.Mapping in project Lucee by lucee.

the class ConfigWebImpl method getApplicationMapping.

public Mapping getApplicationMapping(String type, String virtual, String physical, String archive, boolean physicalFirst, boolean ignoreVirtual) {
    String key = type + ":" + virtual.toLowerCase() + ":" + (physical == null ? "" : physical.toLowerCase()) + ":" + (archive == null ? "" : archive.toLowerCase()) + ":" + physicalFirst;
    key = Long.toString(HashUtil.create64BitHash(key), Character.MAX_RADIX);
    Mapping m = applicationMappings.get(key);
    if (m == null) {
        m = new MappingImpl(this, virtual, physical, archive, Config.INSPECT_UNDEFINED, physicalFirst, false, false, false, true, ignoreVirtual, null, -1, -1);
        applicationMappings.put(key, m);
    }
    return m;
}
Also used : Mapping(lucee.runtime.Mapping) MappingImpl(lucee.runtime.MappingImpl)

Example 29 with Mapping

use of lucee.runtime.Mapping in project Lucee by lucee.

the class ExportImportHandler method exportMapping.

private static List<Object> exportMapping(Mapping[] mappings, Resource dir, String pathAppendix, String filter) throws IOException {
    List<Object> list = new ArrayList<Object>();
    Map<String, Object> m;
    for (Mapping mapping : mappings) {
        MappingImpl mi = (MappingImpl) mapping;
        m = new HashMap<String, Object>();
        list.add(m);
        m.put("virtual", mapping.getVirtual());
        m.put("inspect", ConfigWebUtil.inspectTemplate(mi.getInspectTemplateRaw(), ""));
        m.put("toplevel", mapping.isTopLevel());
        m.put("readonly", mapping.isReadonly());
        m.put("hidden", mapping.isHidden());
        m.put("physicalFirst", mapping.isPhysicalFirst());
        m.put("hidden", mapping.isHidden());
        // archive
        if (mapping.hasArchive()) {
            Resource archive = mapping.getArchive();
            if (archive.isFile()) {
                Resource arcDir = dir.getRealResource("archive/");
                arcDir.mkdir();
                m.put("archive", pathAppendix + "archive/" + archive.getName());
                IOUtil.copy(archive, arcDir.getRealResource(archive.getName()));
            }
        }
        // physical
        if (mapping.hasPhysical()) {
            Resource physical = mi.getPhysical();
            if (physical.isDirectory()) {
                String id = CreateUniqueId.invoke();
                Resource phyDir = dir.getRealResource("physical/" + id);
                phyDir.mkdirs();
                m.put("physical", pathAppendix + "physical/" + id);
                ResourceFilter f = null;
                if (!StringUtil.isEmpty(filter)) {
                    f = new OrResourceFilter(new ResourceFilter[] { new WildcardPatternFilter(filter, ","), DirectoryResourceFilter.FILTER });
                }
                if (// PATCH this needs more digging
                !physical.getAbsolutePath().equals("/"))
                    ResourceUtil.copyRecursive(physical, phyDir, f);
            }
        }
    }
    return list;
}
Also used : OrResourceFilter(lucee.commons.io.res.filter.OrResourceFilter) ResourceFilter(lucee.commons.io.res.filter.ResourceFilter) DirectoryResourceFilter(lucee.commons.io.res.filter.DirectoryResourceFilter) OrResourceFilter(lucee.commons.io.res.filter.OrResourceFilter) ArrayList(java.util.ArrayList) Resource(lucee.commons.io.res.Resource) Mapping(lucee.runtime.Mapping) WildcardPatternFilter(lucee.commons.io.res.util.WildcardPatternFilter) MappingImpl(lucee.runtime.MappingImpl)

Example 30 with Mapping

use of lucee.runtime.Mapping in project Lucee by lucee.

the class GetUsageData method call.

public static Struct call(PageContext pc) throws PageException {
    ConfigWeb cw = pc.getConfig();
    ConfigServer cs = cw.getConfigServer("server");
    ConfigWeb[] webs = cs.getConfigWebs();
    CFMLEngineFactory.getInstance();
    CFMLEngineImpl engine = (CFMLEngineImpl) cs.getCFMLEngine();
    Struct sct = new StructImpl();
    // Locks
    /*LockManager manager = pc.getConfig().getLockManager();
        String[] locks = manager.getOpenLockNames();
        for(int i=0;i<locks.length;i++){
        	locks[i].
        }
        if(!ArrayUtil.isEmpty(locks)) 
        	strLocks=" open locks at this time ("+List.arrayToList(locks, ", ")+").";
		*/
    // Requests
    Query req = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._uri, START_TIME, KeyConstants._timeout }, 0, "requests");
    sct.setEL(KeyConstants._requests, req);
    // Template Cache
    Query tc = new QueryImpl(new Collection.Key[] { KeyConstants._web, ELEMENTS, KeyConstants._size }, 0, "templateCache");
    sct.setEL(KeyImpl.init("templateCache"), tc);
    // Scopes
    Struct scopes = new StructImpl();
    sct.setEL(KeyConstants._scopes, scopes);
    Query app = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, ELEMENTS, KeyConstants._size }, 0, "templateCache");
    scopes.setEL(KeyConstants._application, app);
    Query sess = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, USERS, ELEMENTS, KeyConstants._size }, 0, "templateCache");
    scopes.setEL(KeyConstants._session, sess);
    // Query
    Query qry = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, START_TIME, KeyConstants._sql }, 0, "requests");
    sct.setEL(QUERIES, qry);
    // Locks
    Query lck = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, KeyConstants._name, START_TIME, KeyConstants._timeout, KeyConstants._type }, 0, "requests");
    sct.setEL(LOCKS, lck);
    // Loop webs
    ConfigWebImpl web;
    Map<Integer, PageContextImpl> pcs;
    PageContextImpl _pc;
    int row, openConnections = 0;
    CFMLFactoryImpl factory;
    ActiveQuery[] queries;
    ActiveQuery aq;
    ActiveLock[] locks;
    ActiveLock al;
    for (int i = 0; i < webs.length; i++) {
        // Loop requests
        web = (ConfigWebImpl) webs[i];
        factory = (CFMLFactoryImpl) web.getFactory();
        pcs = factory.getActivePageContexts();
        Iterator<PageContextImpl> it = pcs.values().iterator();
        while (it.hasNext()) {
            _pc = it.next();
            if (_pc.isGatewayContext())
                continue;
            // Request
            row = req.addRow();
            req.setAt(KeyConstants._web, row, web.getLabel());
            req.setAt(KeyConstants._uri, row, getPath(_pc.getHttpServletRequest()));
            req.setAt(START_TIME, row, new DateTimeImpl(pc.getStartTime(), false));
            req.setAt(KeyConstants._timeout, row, new Double(pc.getRequestTimeout()));
            // Query
            queries = _pc.getActiveQueries();
            if (queries != null) {
                for (int y = 0; y < queries.length; y++) {
                    aq = queries[y];
                    row = qry.addRow();
                    qry.setAt(KeyConstants._web, row, web.getLabel());
                    qry.setAt(KeyConstants._application, row, _pc.getApplicationContext().getName());
                    qry.setAt(START_TIME, row, new DateTimeImpl(web, aq.startTime, true));
                    qry.setAt(KeyConstants._sql, row, aq.sql);
                }
            }
            // Lock
            locks = _pc.getActiveLocks();
            if (locks != null) {
                for (int y = 0; y < locks.length; y++) {
                    al = locks[y];
                    row = lck.addRow();
                    lck.setAt(KeyConstants._web, row, web.getLabel());
                    lck.setAt(KeyConstants._application, row, _pc.getApplicationContext().getName());
                    lck.setAt(KeyConstants._name, row, al.name);
                    lck.setAt(START_TIME, row, new DateTimeImpl(web, al.startTime, true));
                    lck.setAt(KeyConstants._timeout, row, Caster.toDouble(al.timeoutInMillis / 1000));
                    lck.setAt(KeyConstants._type, row, al.type == LockManager.TYPE_EXCLUSIVE ? "exclusive" : "readonly");
                }
            }
        }
        Iterator<Integer> _it = web.getDatasourceConnectionPool().openConnections().values().iterator();
        while (_it.hasNext()) {
            openConnections += _it.next().intValue();
        }
        // Template Cache
        Mapping[] mappings = ConfigWebUtil.getAllMappings(web);
        long[] tce = templateCacheElements(mappings);
        row = tc.addRow();
        tc.setAt(KeyConstants._web, row, web.getLabel());
        tc.setAt(KeyConstants._size, row, new Double(tce[1]));
        tc.setAt(ELEMENTS, row, new Double(tce[0]));
        // Scope Application
        getAllApplicationScopes(web, factory.getScopeContext(), app);
        getAllCFSessionScopes(web, factory.getScopeContext(), sess);
    }
    // Datasource
    Struct ds = new StructImpl();
    sct.setEL(KeyConstants._datasources, ds);
    // there is only one cache for all contexts
    ds.setEL(CACHED_QUERIES, Caster.toDouble(pc.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_QUERY, null).size(pc)));
    // ds.setEL(CACHED_QUERIES, Caster.toDouble(pc.getQueryCache().size(pc))); // there is only one cache for all contexts
    ds.setEL(OPEN_CONNECTIONS, Caster.toDouble(openConnections));
    // Memory
    Struct mem = new StructImpl();
    sct.setEL(KeyConstants._memory, mem);
    mem.setEL("heap", SystemUtil.getMemoryUsageAsStruct(SystemUtil.MEMORY_TYPE_HEAP));
    mem.setEL("nonheap", SystemUtil.getMemoryUsageAsStruct(SystemUtil.MEMORY_TYPE_NON_HEAP));
    // uptime
    sct.set("uptime", new DateTimeImpl(engine.uptime(), true));
    // now
    sct.set("now", new DateTimeImpl(pc));
    return sct;
}
Also used : ActiveQuery(lucee.runtime.debug.ActiveQuery) Query(lucee.runtime.type.Query) Mapping(lucee.runtime.Mapping) Struct(lucee.runtime.type.Struct) QueryImpl(lucee.runtime.type.QueryImpl) ActiveLock(lucee.runtime.debug.ActiveLock) CFMLFactoryImpl(lucee.runtime.CFMLFactoryImpl) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) ConfigServer(lucee.runtime.config.ConfigServer) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) CFMLEngineImpl(lucee.runtime.engine.CFMLEngineImpl) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) StructImpl(lucee.runtime.type.StructImpl) ActiveQuery(lucee.runtime.debug.ActiveQuery) Collection(lucee.runtime.type.Collection)

Aggregations

Mapping (lucee.runtime.Mapping)30 MappingImpl (lucee.runtime.MappingImpl)11 PageSource (lucee.runtime.PageSource)7 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)7 ArrayList (java.util.ArrayList)6 PageContextImpl (lucee.runtime.PageContextImpl)6 Resource (lucee.commons.io.res.Resource)5 Struct (lucee.runtime.type.Struct)5 Iterator (java.util.Iterator)4 Entry (java.util.Map.Entry)4 lucee.aprint (lucee.aprint)4 Query (lucee.runtime.type.Query)4 QueryImpl (lucee.runtime.type.QueryImpl)4 Element (org.w3c.dom.Element)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ApplicationException (lucee.runtime.exp.ApplicationException)3 ExpressionException (lucee.runtime.exp.ExpressionException)3 Key (lucee.runtime.type.Collection.Key)3 StructImpl (lucee.runtime.type.StructImpl)3