Examples of WGContent


Examples of de.innovationgate.webgate.api.WGContent

    }

    TMLContext processSimpleExpression(TMLContext context, TMLContext errorReturnContext, WGContentNavigator navigator) throws WGAPIException {
       
        String contextExpression = getExpression();
        WGContent content = context.content();
        if (content == null) {
            context.setLastError(
                    "Cannot process expression '" + getExpression() + "' on a non-content context: " + context.getdocument().getDocumentKey());
            return errorReturnContext;
        }
       
        WGStructEntry struct = content.getStructEntry();
        WGDatabase db = context.getdocument().getDatabase();
   
        if (contextExpression.equals("parent")) {
   
            if (content.isDummy()) {
                context.setLastError("Cannot retrieve parent of dummy content");
                return errorReturnContext;
            }
   
            if (struct.isRoot()) {
                context.setLastError("Cannot get parent of root document");
                return errorReturnContext;
            }
            else {
                WGContent parentContent = navigator.getParentContent(content);
                if (parentContent != null) {
                    return context.getTMLContextForDocument(parentContent);
                }
                else {
                    context.setLastError(
                        "Could not retrieve parent content: "
                            + content.getTitle()
                            + " ("
                            + content.getContentKey().toString()
                            + ")");
                    return errorReturnContext;
                }
            }
        }
   
        else if (contextExpression.equals("root")) {
            WGContent rootContent = null;
            if (!content.isDummy()) {
                rootContent = navigator.getRootContent(content);
            }
            else {
                rootContent = content.getDatabase().getFirstReleasedContent(_languageChooser, true);
            }
   
            if (rootContent != null) {
                return context.getTMLContextForDocument(rootContent);
            }
            else {
                context.setLastError("Could not retrieve root content");
                return errorReturnContext;
            }
        }
   
        else if (contextExpression.equals("main") || contextExpression.equals("currentdocument")) {
            TMLContext mainContext = context.getmaincontext();
            return new TMLContext(mainContext.getdocument(), context);
        }
   
        else if (contextExpression.startsWith("children")) {
   
            if (content.isDummy()) {
                context.setLastError("Cannot retrieve children of dummy content");
                return errorReturnContext;
            }
   
            String idxString = contextExpression.substring(contextExpression.indexOf("[") + 1, contextExpression.indexOf("]"));
            int idx;
            try {
                idx = Integer.parseInt(idxString);
            }
            catch (NumberFormatException exc) {
                context.setLastError("Can't parse children index: " + contextExpression);
                return errorReturnContext;
            }
            WGContent childContent = navigator.getChildContent(content, idx, WGContent.SEARCHORDER_ASCENDING);
            if (childContent != null) {
                return context.getTMLContextForDocument(childContent);
            }
            else {
                context.setLastError("Cant retrieve child content idx " + idx);
                return errorReturnContext;
            }
        }
   
        else if (contextExpression.equals("selectedchild")) {
   
            if (content.isDummy()) {
                context.setLastError("Cannot retrieve children of dummy content");
                return errorReturnContext;
            }
   
            WGContent mainContentParent = context.getmaincontext().content();
            while (mainContentParent != null && !mainContentParent.isDummy() && !mainContentParent.getStructEntry().isRoot()) {
                if (mainContentParent.getStructEntry().getParentEntry().equals(struct)) {
                    return context.getTMLContextForDocument(mainContentParent);
                }
                else {
                    mainContentParent = navigator.getParentContent(mainContentParent);
                }
            }
            context.setLastError("Could not retrieve selected child");
            return errorReturnContext;
   
        }
   
        else if (contextExpression.startsWith("siblings")) {
   
            if (content.isDummy()) {
                context.setLastError("Cannot retrieve siblings of dummy content");
                return errorReturnContext;
            }
   
            String idxString =
                contextExpression.substring(contextExpression.indexOf("[") + 1, contextExpression.indexOf("]")).trim();
            boolean relative = (idxString.charAt(0) == '+' || idxString.charAt(0) == '-' ? true : false);
            if (idxString.charAt(0) == '+') {
                idxString = idxString.substring(1);
            }
            int idx = 0;
            try {
                idx = Integer.parseInt(idxString);
            }
            catch (NumberFormatException exc) {
                context.setLastError("Can't parse siblings index: " + contextExpression);
                return errorReturnContext;
            }
   
            WGContent sibling = navigator.getSiblingContent(content, idx, relative);
            if (sibling != null) {
                return context.getTMLContextForDocument(sibling);
            }
            else {
                context.setLastError("Could not retrieve sibling " + idxString);
View Full Code Here

Examples of de.innovationgate.webgate.api.WGContent

   
    boolean isBI = (context.getDesignContext().getTag() != null ? context.getDesignContext().getTag().isBrowserInterface() : false);

    // Retrieve context by content key or unid
    if (contextFunction.equals("docid") || contextFunction.equals("content")) {
        WGContent content = null;
        WGContentKey tmpKey;
        try {
            tmpKey = WGContentKey.parse(contextExpression, context.getdocument().getDatabase());
        }
        catch (WGAPIException e) {
            context.setLastError("Error parsing contextExpression. Exception: " + e.getClass().getName() + " message: " + e.getMessage());
            return errorReturnContext;
        }
        if (tmpKey != null) {
            content = context.content().getDatabase().getContentByKey(tmpKey);
            if (content != null) {
                return context.getTMLContextForDocument(content);
            }
        }

        content =
                WGPDispatcher.getContentByAnyKey(
                    contextExpression,
                    context.content().getDatabase(),
                    _languageChooser,
                    context.isbrowserinterface());


        if (content != null) {
            return context.getTMLContextForDocument(navigator.chooseRelevantContent(content, mainContent));
        }
        else {
            context.setLastError("docid could not be resolved: " + contextExpression);
            return errorReturnContext;
        }

    }

    else if (contextFunction.equals("name")) {
       

        WGContent content = _languageChooser.selectContentForName(context.content().getDatabase(), contextExpression, context.isbrowserinterface());
        if (content != null) {
            return context.getTMLContextForDocument(navigator.chooseRelevantContent(content, mainContent));
        }
   
        context.setLastError("Could not retrieve content for name: " + contextExpression);
        return errorReturnContext;
       
    }

    // Retrieve the context of another tag
    else if (contextFunction.equals("tag")) {

        if (context.getDesignContext().getTag() == null) {
            context.setLastError("Cannot retrieve tag because this script does not run on a WebTML page");
            return errorReturnContext;
        }

        BaseTagStatus refTag = context.getDesignContext().getTag().getTagStatusById(contextExpression);
        if (refTag != null) {
            TMLContext tagContext = refTag.tmlContext;
            if (tagContext != null) {
                return tagContext;
            }
            else {
                context.setLastError("Context of this Tag could not be retrieved: " + contextExpression);
                return errorReturnContext;
            }
        }
        else {
            context.setLastError("Tag could not be retrieved: " + contextExpression);
            return errorReturnContext;
        }
    }

    else if (contextFunction.equals("db") || contextFunction.equals("plugin")) {
       
        if (contextFunction.equals("plugin")) {
            WGAPlugin plugin = context.getwgacore().getPluginSet().getPluginByUniqueName(contextExpression);
            if (plugin != null) {
                contextExpression = plugin.buildDatabaseKey();
            }
            else {
                context.setLastError("Unknown plugin unique name: " + contextExpression);
                return errorReturnContext;
            }
        }
       
        WGDatabase dbTarget = null;
        try {
            dbTarget = context.db(context.resolveDBKey(contextExpression));
        }
        catch (WGUnavailableException e1) {
            context.setLastError("Database '" + contextExpression + "' is currently unavailable");
            return errorReturnContext;
        }
        catch (WGException e) {
            context.setLastError("Unable to open database '" + contextExpression + "'. Exception: " + e.getClass().getName() + " message: " + e.getMessage());
            return errorReturnContext;
        }

        if (dbTarget == null) {
            context.setLastError("No database with key " + contextExpression);
            return errorReturnContext;
        }

        if (dbTarget.isSessionOpen() == false) {
            context.setLastError("User cannot open database '" + contextExpression + "'");
            return errorReturnContext;
        }

        if (dbTarget.getSessionContext().getAccessLevel() <= WGDatabase.ACCESSLEVEL_NOACCESS) {
            context.setLastError("User has no access to database '" + contextExpression + "'");
            return errorReturnContext;
        }

        TMLContext dbContext = context.dbContext(dbTarget);
        if (dbContext == null) {
            context.setLastError("Target database " + contextExpression + " does not support db context changes");
            return errorReturnContext;
        }
        else {
            return dbContext;
        }
    }

    else if (contextFunction.equals("area")) {

        WGArea area = db.getArea(contextExpression);
        if (area == null) {
            context.setLastError("No area of name '" + contextExpression + "'");
            return errorReturnContext;
        }

        WGContent content = navigator.getRootContent(area);
        if (content != null) {
            return context.getTMLContextForDocument(content);
        }
        else {
            context.setLastError("No root content in area '" + contextExpression + "'");
            return errorReturnContext;
        }

    }

    else if (contextFunction.equals("query")) {

        if (context.getDesignContext().getTag() == null) {
            context.setLastError("Cannot retrieve tag because this script does not run on a WebTML page");
            return errorReturnContext;
        }

        BaseTagStatus tag = context.getDesignContext().getTag().getTagStatusById(contextExpression);
        if (tag != null && tag instanceof Query.Status) {
            Query.Status queryTag = (Query.Status) tag;
            WGContent content = queryTag.getFirstContent();
            if (content != null) {
                return context.getTMLContextForDocument(queryTag.getFirstContent());
            }
            else {
                context.setLastError(
                    "Could not retrieve context by query tag \"" + contextExpression + "\". Query had no result.");
                return errorReturnContext;
            }
        }
        else {
            context.setLastError("No query tag with id: " + contextExpression);
            return errorReturnContext;
        }
    }
   
    else if (contextFunction.equals("role")) {
        setRole(contextExpression);
        return context;
    }
   
    else if (contextFunction.equals("relation")) {
        WGContent relationContent = context.content().getRelation(contextExpression);
        if (relationContent != null) {
            return context.getTMLContextForDocument(relationContent);
        }
        else {
            context.setLastError("Content " + context.meta("KEY") + " has no relation named '" + contextExpression + "'");
            return errorReturnContext;
        }
    }
    else if (contextFunction.equals("level")) {
       
        int level;
        try {
            level = Integer.parseInt(contextExpression);
        }
        catch (NumberFormatException e) {
            context.setLastError("Cannot be parsed as level number: " + contextExpression);
            return errorReturnContext;
        }
       
        WGContent con = context.content();
        if (!con.hasCompleteRelationships()) {
            context.setLastError("Current content does not belong to a page hierarchy");
            return errorReturnContext;
        }
       
        WGStructEntry struct = con.getStructEntry();
        while (struct != null && struct.getLevel() > level) {
            struct = struct.getParentEntry();
        }
       
        if (struct != null) {
            WGContent targetCon = _languageChooser.selectContentForPage(struct, isBI);
            if (targetCon != null) {
                return context.getTMLContextForDocument(targetCon);
            }
            else {
                context.setLastError("Page on level " + level + " has no appropriate content document");
                return errorReturnContext;
            }
        }
        else {
            context.setLastError("Failed to go to page level " + level);
            return errorReturnContext;
        }
       
    }
    else if (contextFunction.equals("np")) {
        String namePart = UniqueNamePartFormatter.INSTANCE.format(contextExpression);
        String uname = context.content().getUniqueName();
        if (WGUtils.isEmpty(uname)) {
            uname = context.content().getStructEntry().getUniqueName();
        }
       
        String fullname;
        if (!WGUtils.isEmpty(uname)) {
            fullname = uname + "." + namePart;
        }
        else {
            fullname = namePart;
        }
       
        WGContent content = _languageChooser.selectContentForName(context.content().getDatabase(), fullname, context.isbrowserinterface());
        if (content != null) {
            return context.getTMLContextForDocument(navigator.chooseRelevantContent(content, mainContent));
        }
   
        context.setLastError("Could not retrieve content for hdb unique name " + fullname);
View Full Code Here

Examples of de.innovationgate.webgate.api.WGContent

   
   
   
   
    // Create necessary context objects
        WGContent dummyContent;
        try {
            dummyContent = db.getDummyContent(db.getDefaultLanguage());
        }
        catch (WGAPIException e) {
            throw new TaskException("Unable to retrieve dummy content context from database " + db.getDbReference(), e);
View Full Code Here

Examples of de.innovationgate.webgate.api.WGContent

   */
  public void tmlEndTag() throws TMLException, WGAPIException {

    try {
            TMLContext context = this.getTMLContext();
            WGContent content = context.content()
           
            // Build link body
            String contentURL = context.contenturl(this.getMedium(), this.getLayout());
            String imageBaseURL = context.contenturl(this.getMedium(), this.getLayout(), true);
            String linkBody = null;
            String moEventAttributes = "";
           
           
            linkBody = content.getTitle();
           
            String linkTarget = content.getLinkTarget();
            if (linkTarget != null && !linkTarget.equals("")) {
              linkTarget = "target=\"" + linkTarget + "\" ";
            }
            else {
              linkTarget = "";
View Full Code Here

Examples of de.innovationgate.webgate.api.WGContent

    }

    private void initModel(Element modelNode, WGContent parent) throws WGAPIException {
       
        Iterator children;
        WGContent document;
       
        if (modelNode.getName().equals("storage")) {
       
            if (parent != null) {
                if (_hdb.isStorage(parent)) {
                    document = _hdb.getOrCreateStorage(parent, modelNode.attributeValue("sid"));
                }
                else {
                    HDBModelParams params = new HDBModelParams(TYPE_STORAGE);
                    document = _hdb.getOrCreateUIDContent(parent, modelNode.attributeValue("sid"), params);
                }
            }
            else {
                document = _hdb.getOrCreateStorage(modelNode.attributeValue("sid"));
            }
           
           
            // If the store does not yet have a type item we regard it as just created an initialize it
            if (!document.hasItem(ITEM_TYPE)) {
                _hdb.setListener(document, HDBModelListener.class.getName());
                document.setItemValue(ITEM_TYPE, TYPE_STORAGE);
                document.setItemValue(ITEM_STORAGE_ID, modelNode.attributeValue("sid"));
                document.save();
            }
   
            // Initialize eventual children
            children = modelNode.elements().iterator();       
            while (children.hasNext()) {
                Element child = (Element) children.next();
                initModel(child, document);
            }
           
        }
       
        else if (modelNode.getName().equals("singleton-content")) {
           
            HDBModelParams params = new HDBModelParams(TYPE_CONTENT);
            document = _hdb.getOrCreateUIDContent(parent, modelNode.attributeValue("sid"), params);
           
            // If the document does not yet have a type item we regard it as just created an initialize it
            if (!document.hasItem(ITEM_TYPE)) {
                _hdb.setListener(document, HDBModelListener.class.getName());
                document.setItemValue(ITEM_TYPE, TYPE_CONTENT);
                document.save();
            }
           
            Map<String, Object> itemDefaultValues = fetchItemDefaultValues(modelNode, parent);
            initContentItems(document, itemDefaultValues);
           
View Full Code Here

Examples of de.innovationgate.webgate.api.WGContent

        Iterator contentPath = getContentPath(content).iterator();
        Element currentModelNode = _definition.getRootElement();

        while (contentPath.hasNext()) {
            WGContent partContent = (WGContent) contentPath.next();
            Element foundModel = findChildModelForContent(currentModelNode, partContent);
            if (foundModel != null) {
                currentModelNode = foundModel;
            }
            else {
View Full Code Here

Examples of de.innovationgate.webgate.api.WGContent

        if (refModel != null) {
            Iterator models = modelsList.iterator();
            while (models.hasNext()) {
                Element contentClassModel = (Element) models.next();
                if (contentClassModel.getPath().startsWith(refModel.getPath())) {
                    WGContent parent = findContentForModel(potentialParent, contentClassModel.getParent(), true);
                    if (parent != null) {
                        return parent;
                    }
                }   
            }
        }

        // Second try: Find a general position in the hierarchy
        if (!forceRelative) {
            Iterator models = modelsList.iterator();
            while (models.hasNext()) {
                Element contentClassModel = (Element) models.next();
                WGContent parent = findContentForModel(null, contentClassModel.getParent(), false);
                if (parent != null) {
                    return parent;
                }
            }
        }
View Full Code Here

Examples of de.innovationgate.webgate.api.WGContent

        else {
            children = _hdb.getRootDocuments().iterator();
        }

        while (children.hasNext()) {
            WGContent child = (WGContent) children.next();
            if (isModelMatchingContent(child, pathModel)) {
                return child;
            }
        }
View Full Code Here

Examples of de.innovationgate.webgate.api.WGContent

    }

    public WGContent createContent(HDBModelParams params, WGContent ref) throws HDBModelException, WGAPIException {
       
        // Search for the right parent to store this document
        WGContent parent = getParentForContentClass(params.getContentClass(), ref, false);
        if (parent == null) {
            if (ref != null) {
                throw new HDBModelException("HDB model cannot find correct parent for content class '" + params.getContentClass() + "' on ref document '" + ref.getDocumentKey() + "' of class " + ref.getContentClass());
            }
            else {
                throw new HDBModelException("HDB model cannot find correct parent for content class '" + params.getContentClass() + "' without ref document");
            }
        }
           
        // Create the content
        params.setCreateContentID(UIDGenerator.generateUID());
        WGContent newContent = _hdb.createContent(parent, params.getContentClass() + " " + params.getCreateContentID(), params);
        return newContent;
    }
View Full Code Here

Examples of de.innovationgate.webgate.api.WGContent

        _hdb.deleteContent(content, params);
    }
   
    public void moveContent(WGContent content, WGContent ref) throws WGAPIException, HDBModelException {
        HDBModelParams params = new HDBModelParams(content);
        WGContent newParent = getParentForContentClass(params.getContentClass(), ref, true);
        if (newParent == null) {
            throw new HDBModelException("Cannot find valid position for content class '" + params.getContentClass() + "' below move target " + ref.getDocumentKey());
        }
        _hdb.moveContent(content, newParent);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.