Package de.innovationgate.webgate.api

Examples of de.innovationgate.webgate.api.WGTMLModule


          moduleFound = true;
        }
       
        // Try to retrieve the module directly from the open database
        else {
            WGTMLModule module = database.getTMLModule(layoutKeyCandidate, mediaKeyStr);
            if (module != null) {
                moduleFound = true;
            }
        }
        return moduleFound;
View Full Code Here


    else if (contextFunction.equals("$tml")) {
        int commaPos = contextExpression.indexOf(",");
        String name = contextExpression.substring(0, commaPos);
        String mediaKey = contextExpression.substring(commaPos + 1);
        WGTMLModule tml = db.getTMLModule(name, mediaKey);
        if (tml != null) {
            return context.getTMLContextForDocument(tml);
        }
        else {
            context.setLastError("Could not retrieve tml with name '" + name + "' and media key '" + mediaKey + "'");
View Full Code Here

            // change currentMediaKey-Option
            status.setOption(OPTION_CURRENT_MEDIAKEY, mediaKey, null);
        }

        // Fetch the TML module to include
        WGTMLModule tmllib;
        if (type.equals(TYPE_INNERLAYOUT)) {
          WGContent currentContent =  this.getTMLContext().content();
          if (currentContent.isDummy() || !currentContent.hasCompleteRelationships()) {
            throw new TMLException("The inner layout of this content cannot be determined, bc. it is either a dummy document, or it doesnt have complete document relationships.");
          }
          tmllib = currentContent.getStructEntry().getInnerLayout(mediaKey);
          designDBKey =  currentContent.getDatabase().getDbReference();
          if (tmllib == null || tmllib.isDummy()) {
            throw new TMLException("Cannot find inner layout for doctype " + this.getTMLContext().content().getStructEntry().getContentType().getName());
          }
        }
       
        else {
          WGDatabase designdb = database;
          if (designDBKey != null) {
            try {
              designdb = this.openContentDB(designDBKey);
            }
            catch (WGUnavailableException e1) {
            }
                catch (WGException e) {
                    throw new TMLException(e.getMessage(), true);
                }
            if (designdb == null || !designdb.isSessionOpen()) {
              throw new TMLException("Cannot open design db: " + designDBKey, true);
            }
          }
         
            tmllib = (WGTMLModule) designdb.getDesignObject(WGDocument.TYPE_TML, status.ref, mediaKey);
          if (tmllib == null) {
            throw new TMLException("Cannot find requested tml module: " + status.ref + " (" + mediaKey + ")");
          }
        }

        // Locate the resource
        try {
            tmlResource = this.getDeployer().locateTmlResource(tmllib);
        }
        catch (DeployerException e1) {
            throw new TMLException("Error deploying WebTML resource", e1, true);
        }
       
        if (tmlResource == null) {
          throw new TMLException("Cannot locate requested tml module: " + tmllib.getName() + " (" + tmllib.getMediaKey() + ")");
        }

        // Do the include
        this.pageContext.setAttribute(ATTRIB_INCLUDEPARENT, status, PageContext.REQUEST_SCOPE);
        String oldDesignDB = (String) getOption(Base.OPTION_DESIGNDB);
        status.setOption(Base.OPTION_DESIGNDB, designDBKey, null);
        try {
           this.pageContext.include(tmlResource);
        }
        catch (Exception e) {
          throw new TMLException("Error executing tml module \"" + tmllib.getName() + "/" + tmllib.getMediaKey() + "\"", e, false);
        }
        finally {
            this.pageContext.setAttribute(ATTRIB_INCLUDEPARENT, null, PageContext.REQUEST_SCOPE);
            status.setOption(Base.OPTION_DESIGNDB, oldDesignDB, null);
        }

        // Transfer result from included root to this tag
        if (status.rootTag != null) {
            this.setResult(status.rootTag.result);
            status.rootTag.result = null;
        } else {
            throw new TMLException("Could not retrieve result of included resource: " + tmlResource);
        }
       
        if (getTMLContext().getwgacore().isProfilingEnabled()) {
          HttpServletRequest request = getTMLContext().getrequest();
          if (request != null) {
            WGARequestInformation info = (WGARequestInformation) request.getAttribute(WGARequestInformation.REQUEST_ATTRIBUTENAME);
            if (info != null) {
              long duration = System.currentTimeMillis() - status._startTime;
              IncludeInformation includeInfo = new IncludeInformation(getType(), tmllib.getName(), duration);
              includeInfo.setDesignDb(tmllib.getDatabase().getDbReference());
              info.getIncludes().add(includeInfo);
            }
          }
        }
    }
View Full Code Here

        if (mediaKeyObj.isBinary()) {
            request.setAttribute(WGACore.ATTRIB_SERVLETRESPONSE, response);
        }

        // Determine tml design for this request
        WGTMLModule tmlLib = null;
        if (path.getLayoutKey() != null) {
            tmlLib = (WGTMLModule) database.getDesignObject(WGDocument.TYPE_TML, path.getLayoutKey(), mediaKey);
            if (tmlLib != null && tmlLib.isDirectAccessAllowed() == false) {
                throw new HttpErrorException(java.net.HttpURLConnection.HTTP_FORBIDDEN, "This design is not allowed for direct access: " + tmlLib.getName() + " (" + tmlLib.getMediaKey() + ")", path
                        .getDatabaseKey());
            }
        }
        else {
            WGStructEntry entry = content.getStructEntry();
            if (entry == null) {
                throw new HttpErrorException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Content " + content.getContentKey().toString() + " has no struct entry", path.getDatabaseKey());
            }
            tmlLib = entry.getOuterLayout(mediaKey);
        }

        if (tmlLib == null || tmlLib.isDummy()) {
            if (path.getLayoutKey() != null) {
                throw new HttpErrorException(404, "No WebTML layout '" + path.getLayoutKey() + "' for media key '" + mediaKey + "' available in app '" + database.getDbReference() + "'", path.getDatabaseKey());
            }
            else {
                throw new HttpErrorException(500, "Outer layout of struct entry '" + content.getStructEntry().getTitle() + "(" + content.getStructEntry().getStructKey() + ")"
                        + "' not available for media key '" + mediaKey + "'", path.getDatabaseKey());
            }
        }

        request.setAttribute(WGACore.ATTRIB_OUTER_DESIGN, tmlLib.getName());


        // TML Cache control
        if (tmlLib.isCacheable()) {
            response.setHeader("Cache-Control", "must-revalidate");

            long lastModified;
            // 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
            if (isBinary(response)) {
                lastModified = getCore().getDeployer().getLastChangedOrDeployed(database).getTime();
            }
            else {
                lastModified = Math.max(getCore().getDeployer().getLastChangedOrDeployed(database).getTime(), _core.getCharacterEncodingLastModified());
                lastModified = Math.max(lastModified, _core.getDesignEncodingLastModified(database.getDbReference()));
            }

            // Test modified since
            if (browserCacheIsValid(request, lastModified)) {
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                return;
            }
            else {
                response.setDateHeader("Last-Modified", lastModified);
                response.setHeader("ETag", '"' + String.valueOf(lastModified) + '"');
            }
        }
        else {
            response.setHeader("Pragma", "No-Cache");
            if (mediaKeyObj.isBinary()) {
                response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
            }
            else {
                response.setHeader("Cache-Control", "No-Cache");
            }
        }

        // check if we have an ajaxcall
        String encAjaxInfo = request.getParameter("$ajaxInfo");
        if (encAjaxInfo != null) {
            tmlLib = processAjaxCall(request, database, encAjaxInfo);
            ajax = true;
        }

        // Update usage statistics
        getCore().getUsageStatistics().addRequestStatistic(request, session, database, tmlUserProfile);

        // Dispatch to jsp
        String targetJSP = _core.getDeployer().locateTmlResource(tmlLib);

        try {
            if (targetJSP != null) {
                if (!"HEAD".equalsIgnoreCase(request.getMethod())) {
                    if (mediaKeyObj.isBinary()) {
                        if (request instanceof RenderServletRequestWrapper) {
                            HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) request;
                            wrapper.getRequest().getRequestDispatcher(targetJSP).include(wrapper.getRequest(), new DummyServletResponse(response));
                        }
                        else {
                            this.getServletContext().getRequestDispatcher(targetJSP).include(request, new DummyServletResponse(response));
                        }
                    }
                    else {
                        if (request instanceof RenderServletRequestWrapper) {
                            HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) request;
                            wrapper.getRequest().getRequestDispatcher(targetJSP).include(wrapper.getRequest(), response);
                        }
                        else {
                            this.getServletContext().getRequestDispatcher(targetJSP).include(request, response);
                        }
                    }
                }
            }
            else {
                throw new HttpErrorException(500, "tml design not active: " + tmlLib.getName(), path.getDatabaseKey());
            }

            // Eventually do redirect
            if (request.getAttribute(WGACore.ATTRIB_REDIRECT) != null) {
               
View Full Code Here

        }

    }

    private WGTMLModule processAjaxCall(javax.servlet.http.HttpServletRequest request, WGDatabase database, String encAjaxInfo) throws HttpErrorException, WGException {
        WGTMLModule tmlLib;
        AjaxInfo ajaxInfo = null;
        try {
            // decrypt
            byte[] zipped = this.getCore().getDesEncrypter().decrypt(encAjaxInfo);
            if (zipped == null) {
View Full Code Here

        // Creat folders
        getOrCreateFolders();

        // Deploy TMLs
        Iterator modules = getDB().getTMLModules().iterator();
        WGTMLModule mod;
        while (modules.hasNext()) {
            mod = (WGTMLModule) modules.next();
            if (isValidDesignName(mod.getName())) {
                initialDeployTMLModule(mod);
            }
            else {
                _log.warn("Could not use '" + mod.getDocumentKey() + "' for design deployment since the name contains invalid characters");
            }
        }

        // Deploy file containers
        Iterator containers = getDB().getFileContainers().iterator();
View Full Code Here

    private static WGTMLModule getModule(List modules, String libName,
            String mediaKey) throws WGAPIException {

        Iterator modsIt = modules.iterator();
        WGTMLModule mod;
        while (modsIt.hasNext()) {
            mod = (WGTMLModule) modsIt.next();
            if (mod.getName().equals(libName)
                    && mod.getMediaKey().equals(mediaKey)) {
                return mod;
            }
        }

        return null;
View Full Code Here

       
        TMLMetadata metaData = (TMLMetadata) readMetaData();
        String code = readCode(metaData);
       
       
        WGTMLModule mod = (WGTMLModule) db.getDocumentByDocumentKey(getDocumentKey());
        if (mod == null) {
            WGDocumentKey key = new WGDocumentKey(getDocumentKey());
            mod = db.createTMLModule(key.getName(), key.getMediakey());
        }
        mod.setCode(code);
        metaData.writeToDocument(mod);
        doSaveDocument(mod);
       
        resetUpdateInformation();
View Full Code Here

TOP

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

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.