Search in sources :

Example 1 with IRootObject

use of com.servoy.j2db.persistence.IRootObject in project servoy-client by Servoy.

the class SharedMediaResource method getResource.

private ResourceState getResource(final String iconId, final String solutionName) {
    return new ResourceState() {

        private String contentType;

        private int length;

        byte[] array = null;

        @Override
        public Time lastModifiedTime() {
            try {
                IRootObject solution = ApplicationServerRegistry.get().getLocalRepository().getActiveRootObject(solutionName, IRepository.SOLUTIONS);
                if (solution != null)
                    return Time.valueOf(solution.getLastModifiedTime());
            } catch (Exception e) {
                Debug.trace(e);
            }
            return time;
        }

        @Override
        public byte[] getData() {
            if (array == null) {
                boolean closeFS = false;
                try {
                    final IRepository repository = ApplicationServerRegistry.get().getLocalRepository();
                    FlattenedSolution fs = null;
                    try {
                        if (Session.exists() && ((WebClientSession) Session.get()).getWebClient() != null) {
                            fs = ((WebClientSession) Session.get()).getWebClient().getFlattenedSolution();
                        }
                        if (fs == null) {
                            SolutionMetaData solutionMetaData = (SolutionMetaData) repository.getRootObjectMetaData(solutionName, IRepository.SOLUTIONS);
                            if (solutionMetaData == null)
                                return new byte[0];
                            closeFS = true;
                            IApplicationServer as = ApplicationServerRegistry.getService(IApplicationServer.class);
                            fs = new FlattenedSolution(solutionMetaData, new AbstractActiveSolutionHandler(as) {

                                @Override
                                public IRepository getRepository() {
                                    return repository;
                                }
                            });
                        }
                        Media m = fs.getMedia(iconId);
                        if (m == null) {
                            try {
                                Integer iIconID = new Integer(iconId);
                                m = fs.getMedia(iIconID.intValue());
                            } catch (NumberFormatException ex) {
                                Debug.error("no media found for: " + iconId);
                            }
                        }
                        if (m != null) {
                            array = m.getMediaData();
                            contentType = m.getMimeType();
                        }
                    } finally {
                        if (closeFS && fs != null) {
                            fs.close(null);
                        }
                    }
                    if (array != null) {
                        if (contentType == null) {
                            contentType = MimeTypes.getContentType(array);
                        }
                        length = array.length;
                    }
                } catch (Exception ex) {
                    Debug.error(ex);
                }
            }
            return array == null ? new byte[0] : array;
        }

        /**
         * @see wicket.markup.html.DynamicWebResource.ResourceState#getLength()
         */
        @Override
        public int getLength() {
            return length;
        }

        @Override
        public String getContentType() {
            return contentType;
        }
    };
}
Also used : Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IApplicationServer(com.servoy.j2db.server.shared.IApplicationServer) IRootObject(com.servoy.j2db.persistence.IRootObject) StringValueConversionException(org.apache.wicket.util.string.StringValueConversionException) SolutionMetaData(com.servoy.j2db.persistence.SolutionMetaData) AbstractActiveSolutionHandler(com.servoy.j2db.AbstractActiveSolutionHandler) IRepository(com.servoy.j2db.persistence.IRepository)

Example 2 with IRootObject

use of com.servoy.j2db.persistence.IRootObject in project servoy-client by Servoy.

the class FlattenedSolution method getScopesPerSolution.

private Map<String, Pair<String, IRootObject>> getScopesPerSolution() {
    if (mainSolution == null && loginFlattenedSolution != null) {
        return loginFlattenedSolution.getScopesPerSolution();
    }
    Map<String, Pair<String, IRootObject>> scopes = new HashMap<String, Pair<String, IRootObject>>();
    if (mainSolution != null) {
        for (String scopeName : mainSolution.getScopeNames()) {
            scopes.put(scopeName, new Pair<String, IRootObject>(scopeName, mainSolution));
        }
        if (modules != null) {
            for (Solution s : modules) {
                if (s != mainSolution) {
                    for (String scopeName : s.getScopeNames()) {
                        if (!scopes.containsKey(scopeName)) {
                            // TODO: check if same scope exists with different modules
                            scopes.put(scopeName, new Pair<String, IRootObject>(scopeName, s));
                        }
                    }
                }
            }
        }
    }
    addGlobalsScope(scopes);
    return scopes;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IRootObject(com.servoy.j2db.persistence.IRootObject) Solution(com.servoy.j2db.persistence.Solution) Pair(com.servoy.j2db.util.Pair)

Aggregations

IRootObject (com.servoy.j2db.persistence.IRootObject)2 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)1 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 IRepository (com.servoy.j2db.persistence.IRepository)1 Media (com.servoy.j2db.persistence.Media)1 Solution (com.servoy.j2db.persistence.Solution)1 SolutionMetaData (com.servoy.j2db.persistence.SolutionMetaData)1 IApplicationServer (com.servoy.j2db.server.shared.IApplicationServer)1 Pair (com.servoy.j2db.util.Pair)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 StringValueConversionException (org.apache.wicket.util.string.StringValueConversionException)1