Package de.innovationgate.webgate.api

Examples of de.innovationgate.webgate.api.WGDatabase


            throw new HttpErrorException(HttpURLConnection.HTTP_INTERNAL_ERROR, "Retrieved AjaxInfo could not be restored. Check log for details.", null);
        }

        // fetch correct db for ajax (if designdb on include tag is present use
        // design db, if not use current db)
        WGDatabase ajaxDB = null;
        String ajaxDesignDBKey = ajaxInfo.getDesignDB();
        if (ajaxDesignDBKey != null) {
            // fetch design db
            try {
                ajaxDB = _core.openContentDB(ajaxDesignDBKey, request);
            }
            catch (WGUnavailableException e) {
                throw new HttpErrorException(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "The website is currently unavailable", ajaxDesignDBKey);
            }
            catch (de.innovationgate.wgpublisher.AuthenticationException e) {
                throw new HttpErrorException(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage(), null);
            }
            catch (AccessException e) {
                throw new HttpErrorException(HttpServletResponse.SC_FORBIDDEN, e.getMessage(), null);
            }

            if (ajaxDB == null) {
                throw new HttpErrorException(HttpServletResponse.SC_NOT_FOUND, "No database of key " + ajaxDesignDBKey, null);
            }
            else if (ajaxDB.isSessionOpen() == false) {
                throw new HttpErrorException(HttpServletResponse.SC_FORBIDDEN, "Database '" + ajaxDesignDBKey + "' could not be opened by ajaxCall.", null);
            }
        }
        else {
            ajaxDB = database;
        }

        // search for tml module
        tmlLib = (WGTMLModule) ajaxDB.getDesignObject(WGDocument.TYPE_TML, ajaxInfo.getTmlmodule(), ajaxInfo.getMediaKey());

        if (tmlLib == null) {
            throw new HttpErrorException(HttpServletResponse.SC_NOT_FOUND, "No WebTML layout '" + ajaxInfo.getTmlmodule() + "' for media key '" + ajaxInfo.getMediaKey() + "' available in app '" + ajaxDB.getDbReference() + "'", ajaxDB
                    .getDbReference());
        }

        return tmlLib;
    }
View Full Code Here


        if (domain == null) {
            return null;
        }

        // Tr to get pers db from domain
        WGDatabase persDB = null;
        try {
            persDB = _core.openPersonalisationDB(domain, session);
        }
        catch (WGAPIException e1) {
            _core.getLog().error("Error opening personalisation db for domain '" + domain + "'", e1);
            throw e1;
        }

        // Try to use content database as pers db or use an external self
        // personalisation db
        if (persDB == null) {
            if (database.hasFeature(WGDatabase.FEATURE_SELF_PERSONALIZABLE)) {
                persDB = database;
            }
            else {
                persDB = (WGDatabase) database.getAttribute(WGACore.DBATTRIB_EXTERNAL_SELF_PERSONALISATION_DB);
                if (persDB != null) {
                    if (!persDB.isSessionOpen()) {
                        persDB.openSession();
                    }
                }
                else {
                    return null;
                }
            }
        }

        // Try to retrieve previously stored user profile in session
        String wgpid = (String) session.getAttribute(SESSION_PROFILENAME_INDIVIDUALDB + database.getDbReference());
        if (wgpid != null) {
            WGUserProfile profile = persDB.getUserProfile(wgpid);
            if (profile != null) {
                TMLUserProfile tmlProfile = new TMLUserProfile(profile, getCore());
                request.setAttribute(WGACore.ATTRIB_PROFILE + database.getDbReference(), tmlProfile);
                return tmlProfile;
            }
        }

        // Fetch user profile using database's persmode. If not available we
        // take the default value for the option
        String persModeStr = (String) _core.readPublisherOptionOrDefault(database, WGACore.DBATTRIB_PERSMODE);
        Integer persMode;
        if (persModeStr != null) {
            persMode = Integer.valueOf(persModeStr);
        }
        // Backup for sure, which should not happen as the option is defined for
        // all databases
        else {
            persMode = Constants.PERSMODE_AUTO;
        }

        // If in Mode AUTO, the User Profile is retrieved automatically
        // (otherwise it is set in the login process)
        WGUserProfile userProfile = null;
        boolean created = false;
        if (persMode == Constants.PERSMODE_AUTO) {
            boolean secureMode = database.getBooleanAttribute(WGACore.DBATTRIB_SECURE_APP, false);
            String cookieName = COOKIE_WGPID;
            if (secureMode) {
                cookieName = COOKIE_SECURE_WGPID;
            }

            wgpid = this.findCookie(request.getCookies(), cookieName);
            if (wgpid != null) {
                userProfile = persDB.getUserProfile(wgpid);
            }

            if (userProfile == null) {
                userProfile = createUserProfile((String) request.getHeader("User-Agent"), persDB, wgpid, Constants.PERSMODE_AUTO);
                created = true;
            }

            if (userProfile != null && !userProfile.isDummy()) {
                Cookie wgpidCookie = new Cookie(cookieName, userProfile.getName());
                wgpidCookie.setPath("/");
                wgpidCookie.setSecure(secureMode);
                wgpidCookie.setMaxAge(60 * 60 * 24 * 365);
                response.addCookie(wgpidCookie);
            }
        }

        else if (persMode == Constants.PERSMODE_LOGIN) {
            if (database.getSessionContext().isAnonymous()) {
                // no profile for anonymous
                return null;
            }
            String userName = database.getSessionContext().getUser();
            userProfile = persDB.getUserProfile(userName);
            if (userProfile == null) {
                userProfile = createUserProfile((String) request.getHeader("User-Agent"), persDB, userName, Constants.PERSMODE_LOGIN);
                created =  true;
            }
        }
View Full Code Here

    private void dispatchFileRequest(WGPRequestPath path, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception {

        WGARequestInformation info = (WGARequestInformation) request.getAttribute(WGARequestInformation.REQUEST_ATTRIBUTENAME);

        // Fetch database
        WGDatabase database = path.getDatabase();
        if (info != null) {
            info.setType(WGARequestInformation.TYPE_FILE);
            if (database != null) {
                info.setDatabase(database);
            }
        }

        // Parse container key - This may be a path when we have the /~file/
        // syntax. We use different parts depending on the type of container
        String containerKey = path.getContainerKey();
        List containerKeyElems = WGUtils.deserializeCollection(containerKey, "/");
        String containerKeyLastElement = (String) containerKeyElems.get(containerKeyElems.size() - 1);

        // Fetch the file container
        WGDocument fileContainer = database.getFileContainer(containerKeyLastElement);
        if (fileContainer == null) {

            // Container addressed by some kind of content key?
            WGContent content = getContentByAnyKey(containerKeyLastElement, database, request);

            // Container addressed by Title path?
            if (content == null) {
                TitlePathManager tpm = (TitlePathManager) database.getAttribute(WGACore.DBATTRIB_TITLEPATHMANAGER);
                if (tpm != null && tpm.isGenerateTitlePathURLs()) {
                    TitlePathManager.TitlePath url = tpm.parseTitlePathURL(containerKeyElems);
                    if (url != null) {
                        path.setTitlePathURL(url);
                        content = path.getContentByTitlePath(request);
                    }
                }
            }

            if (content == null || !content.mayBePublished(isBrowserInterface(request.getSession()) || isAuthoringMode(database.getDbReference(), request.getSession()), WGContent.DISPLAYTYPE_NONE)) {
                sendNoFileContainerNotification(path, request, response, database);
                return;
            }

            fileContainer = content;
        }

        if (info != null && fileContainer != null && fileContainer instanceof WGContent) {
            info.setContent((WGContent) fileContainer);
        }

        String fileName = path.getFileName();
        if (fileName == null || fileName.equals("")) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No file name in file URL: " + path.getCompleteURL());
            return;
        }

        ExternalFileServingConfig externalFileServingConfig = _core.getExternalFileServingConfig();

        if (externalFileServingConfig.isEnabled() && database.getBooleanAttribute(WGACore.DBATTRIB_EXTERNAL_FILE_SERVING_ENABLED, false)) {

            // check if file is anonymous accessible
            boolean isAnonymousAccessible = database.isAnonymousAccessible();

            if (isAnonymousAccessible) {
                // perform further document level checks
                if (fileContainer != null && fileContainer instanceof WGContent) {
                    // check status
View Full Code Here

        if (info != null) {
            info.setType(WGARequestInformation.TYPE_SCRIPT);
        }

        // Fetch the database
        WGDatabase database = path.getDatabase();

        // Fetch the library
        String codeType;
        switch (path.getPathType()) {

            case WGPRequestPath.TYPE_CSS:
                codeType = WGScriptModule.CODETYPE_CSS;
                break;

            case WGPRequestPath.TYPE_JS:
                codeType = WGScriptModule.CODETYPE_JS;
                break;

            default:
                throw new HttpErrorException(500, "Invalid path type to dispatch a css/js request: " + path.getPathType(), path.getDatabaseKey());

        }

        WGCSSJSModule lib = database.getScriptModule(path.getCssjsKey(), codeType);
        if (lib == null) {
            throw new HttpErrorException(404, "No css/js resource of name " + path.getCssjsKey(), path.getDatabaseKey());
        }

        // determine mime type and encoding
        String mimeType;
        String libType = lib.getCodeType();
        if (libType.equals(WGCSSJSModule.CODETYPE_CSS)) {
            mimeType = "text/css";
        }
        else if (libType.equals(WGCSSJSModule.CODETYPE_JS)) {
            mimeType = "text/javascript";
        }
        else if (libType.equals(WGCSSJSModule.CODETYPE_VBS)) {
            mimeType = "text/vbscript";
        }
        else {
            mimeType = "text/" + libType;
        }
        response.setContentType(mimeType);

        // Set expiration time
        int fileExpirationMinutes = ((Integer) _core.readPublisherOptionOrDefault(database, WGACore.DBATTRIB_FILEEXPIRATION_MINUTES)).intValue();
        if (fileExpirationMinutes > 0) {
            int fileExpirationSeconds = fileExpirationMinutes * 60;
            response.setHeader("Cache-Control", "max-age=" + fileExpirationSeconds + ", must-revalidate");
        }

        // determine lastModified
        // - last modified of binary response depends only on resource change
        // date
        // - last change date of textual response additionally depends on
        // character encoding change date
        long lastModified;
        if (isBinary(response)) {
            lastModified = lib.getLastModified().getTime();
        }
        else {
            lastModified = Math.max(lib.getLastModified().getTime(), _core.getCharacterEncodingLastModified());
            lastModified = Math.max(lastModified, _core.getDesignEncodingLastModified(database.getDbReference()));
        }
        if (browserCacheIsValid(request, lastModified)) {
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            return;
        }
View Full Code Here

        if (info != null) {
            info.setType(WGARequestInformation.TYPE_STATIC);
        }

        // Fetch the database
        WGDatabase database = path.getDatabase();
        String contentKey = path.getContentKey();
        String jspName = path.getResourcePath();

        if (database != null) {
            WGContent content = null;
            LanguageBehaviour langBehaviour = LanguageBehaviourTools.retrieve(database);

            // Determine the content for this request
            if (contentKey != null) {
                content = getContentByAnyKey(contentKey, database, request);
                if (content == null) {
                    if (request.getQueryString() != null && request.getQueryString().toLowerCase().indexOf("login") != -1) {
                        sendRedirect(response, getLoginURL(request, database, path.getCompleteURL()));
                    }
                    else {
                        throw new HttpErrorException(404, "No content of name/id " + contentKey, path.getDatabaseKey());
                    }
                    return;
                }
                if (!content.isVisible() && !isBrowserInterface(request.getSession())) {
                    throw new HttpErrorException(404, "No content of name/id " + contentKey, path.getDatabaseKey());
                }
            }
            else {
                WGLanguage lang = langBehaviour.requestSelectDatabaseLanguage(database, request);
                content = database.getDummyContent(lang.getName());
            }

            // Test browsability of content
            if (!content.isDummy() && getBrowsingSecurity(database) <= BrowsingSecurity.NO_BROWSING) {
                throw new HttpErrorException(java.net.HttpURLConnection.HTTP_FORBIDDEN, "Browsing not allowed in database '" + path.getDatabaseKey() + "'", path.getDatabaseKey());
            }

            request.setAttribute(WGACore.ATTRIB_MAINCONTEXT, content);
            request.setAttribute(WGACore.ATTRIB_MEDIAKEY, database.getAttribute(WGACore.DBATTRIB_DEFAULT_MEDIAKEY));

        }

        // Set context attributes for jsps
        String completeURL = path.getCompleteURL();
View Full Code Here

            status.formInfo.setTargetContextPath(getTMLContext().getpath());
            status.formInfo.setContentClass(getContentclass());
            status.formInfo.setDefinitionModule(getStatus().getTMLModuleName());
            status.formInfo.setDefinitionDatabase(getDesignDBKey());
           
            WGDatabase designDB = getCore().getContentdbs().get(getDesignDBKey());
            if (designDB != null) { // May be in StaticTML
                CSConfig csConfig = (CSConfig) designDB.getAttribute(WGACore.DBATTRIB_CSCONFIG);
                if (csConfig != null) {
                    status.formInfo.setVersionCompliance(csConfig.getVersionCompliance());
                }
            }
           
View Full Code Here

            if (context.getEnvironment().getRootEnvironmentUserData() != null) {
                _rootEnvironmentUserData = context.getEnvironment().getRootEnvironmentUserData();
            }
            else {
                try {
                    WGDatabase theDB = context.db(getMainContext().getdocument().getDatabase().getDbReference());
                    // We try to take the root environent user data of our main context db. If the root user has no access to it we take the parent context dbs data instead.
                    if (theDB.isSessionOpen()) {
                        _rootEnvironmentUserData = new RootEnvironmentUserData(theDB.getDbReference(), theDB.getSessionContext().getUserAccess());
                    }
                    else {
                        _rootEnvironmentUserData = new RootEnvironmentUserData(context.db().getDbReference(), context.db().getSessionContext().getUserAccess());
                    }
                }
View Full Code Here

        }

        public WGDatabase openDB(WGDatabase db) throws WGException {
          // B00005CCA
          boolean useMaster = false;
          WGDatabase hintDB = _mainContext.getdocument().getDatabase();         
          if (hintDB != null && hintDB.getSessionContext() != null) {
            useMaster = hintDB.getSessionContext().isMasterSession();
          }
            return _core.openContentDB(db, null, useMaster, hintDB);
        }
View Full Code Here

    public void close() {
    }

    public void databaseUpdate(WGDatabaseEvent event) {
        try {
            WGDatabase db = event.getDatabase();
            if (event.getEditedDocument() == null) {
                updateRootNames();
            }
            else if (event.getEditedDocument() instanceof WGArea) {
                updateRootNames();
View Full Code Here

        // Try to retrieve XPL set by Attrib defaultxpl in Range-Tag
        String xplang = (String) this.getOption(Base.OPTION_DEFAULT_XPLANGUAGE);

        // Get XPL by current design db
        if (xplang == null) {
            WGDatabase db = null;
            try {
                db = openContentDB(getDesignDBKey());
            }
            catch (WGException e) {
            }
            if (db != null) {
                xplang = (String) db.getAttribute(WGACore.DBATTRIB_EXPRESSION_DEFAULT);
            }
            else {
                return ExpressionEngineFactory.ENGINE_TMLSCRIPT;
            }
        }
View Full Code Here

TOP

Related Classes of de.innovationgate.webgate.api.WGDatabase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.