⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jahiafieldset.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        JahiaFieldDefinitionsRegistry.getInstance().setDefinition( aDef );                    }                }            } else {                // hell, the definition doesn't exist in the memory !                // this can mean two things :                //  - either this is the first time Jahia encounters this template                //  - or the database data was screwed                // in any case, we got to :                //  - add it into the registry (memory)                //  - add it into the database (database)                //  - change the values in jData (memory)                Hashtable subDefs = new Hashtable();                subDefs.put( new Integer(pageDefID), new JahiaFieldSubDefinition( 0, 0, pageDefID, fieldTitle, fieldType, defaultValue ) );                aDef = new JahiaFieldDefinition( 0, jData.params().getPage().getJahiaID(),                                                fieldName, subDefs );                JahiaFieldDefinitionsRegistry.getInstance().setDefinition( aDef );            }            // we check to see if the declared field was already present in the database            JahiaField theField = (JahiaField) fields.get( fieldName );            // if the field is null :            //  - create the field            //  - store it in the database            //  - adds it in the bean fields vector            if (theField == null) {                // create the new field                JahiaField newField = ServicesRegistry.getInstance().                                      getJahiaFieldService().createJahiaField(                                      0, jData.params().getPage().getJahiaID(),                                      jData.params().getPage().getID(),0,                                      aDef.getID(), fieldType, 0,                                      defaultValue, 0, 0 );                //JahiaField newField = new JahiaField( 0, jData.params().getPage().getJahiaID(),                //                                    jData.params().getPage().getID(),                //                                    0, aDef.getID(), fieldType, 0, defaultValue, 0, 0 );                ServicesRegistry.getInstance().getJahiaFieldService().saveField( newField, jData.params().getPage().getAclID(), null );                // Force the field to be loaded from database as if it was loaded for the first time.                // Doing so, we ensure that all load field treatment are applied.                newField = ServicesRegistry.getInstance().getJahiaFieldService().loadField( newField.getID(), jData.params() );                addField( newField );                JahiaConsole.println("JahiaFieldSet.declareField","created new field with name=" + aDef.getName());            }            // we declare that the field has been loaded, in order to avoid double definitions            declaredFields.add( fieldName );        } else {            // the field is already declared, or has a null name/title : let the user have it... ;)            String errorMsg = "Field already declared or has a null name - title : " + fieldName;            JahiaConsole.println( "JahiaFieldSet.declareField", errorMsg + " -> BAILING OUT" );            throw new JahiaException( errorMsg, errorMsg, JahiaException.TEMPLATE_ERROR,                                    JahiaException.CRITICAL );        }    } // end declareField    /***        * checkDeclared        * EV    29.12.2000        *        */    public boolean checkDeclared( String fieldName )    {        return declaredFields.contains(fieldName);    } // end checkDeclared    /***        * getField        * EV    29.12.2000        *        * !!! Warning : this method can return a null value !!!        */    public JahiaField getField( String fieldName )    throws JahiaException    {        if (checkDeclared( fieldName ))        {            JahiaField theField = (JahiaField) fields.get( fieldName );                return theField;        }        return null;    } // end getField    /***        * getField        * EV    29.12.2000        *        * !!! Warning : this method can return a null value !!!        */    public JahiaField getField( int fieldID )    throws JahiaException    {        Enumeration theFields   = fields.elements();        while (theFields.hasMoreElements()) {            JahiaField aField = (JahiaField) theFields.nextElement();            if (aField.getID() == fieldID) {                return aField;            }        }        return null;    } // end getField    //-------------------------------------------------------------------------    /***        * gets a field in another page (absolute page reference by its id)        *        * @param        fieldName       the field name        * @param        pageID          the page ID        * @return       a JahiaField object, or null if nothing found        * @see          org.jahia.data.fields.JahiaField        *        * !!! Warning : this method can return a null value !!!        */    public JahiaField getAbsoluteField( String fieldName, int pageID )    throws JahiaException    {        //System.out.println( "\nEntering getAbsoluteField for " + fieldName );        int fieldID = ServicesRegistry.getInstance().getJahiaFieldService(                                ).getFieldID( fieldName, pageID );        if (fieldID != -1)        {            // let's update cross reference table            FieldXRefManager.getInstance().                setAbsoluteFieldPageID(jData.params().getSiteKey(),                                       fieldName,                                       pageID,                                       jData.params().getPageID());            //System.out.println( "   found field ID : " + fieldID );            return ServicesRegistry.getInstance().getJahiaFieldService(                                ).loadField( fieldID, LoadFlags.ALL, jData.params() );        } else {            // not found : gets definition id, then creates fake field and saves it into memory            JahiaFieldDefinition fieldDef = JahiaFieldDefinitionsRegistry.getInstance().                    getDefinition( jData.params().getSiteID(), fieldName );            JahiaPage sourcePage = ServicesRegistry.getInstance().getJahiaPageService().                    lookupPage( pageID, jData.params() );            if (sourcePage != null) {                //System.out.println( "   sourcePage is not null !" );                int pageDefID = sourcePage.getPageTemplateID();                if (fieldDef != null) {                    //System.out.println( "   fieldDef is not null !" );                    int fieldType = fieldDef.getType(pageDefID);                    if (fieldType != -1) {                        // let's update cross reference table                        FieldXRefManager.getInstance().                            setAbsoluteFieldPageID(jData.params().getSiteKey(),                                                   fieldName,                                                   pageID,                                                   jData.params().getPageID());                        //System.out.println( "   fieldType is " + fieldType );                        //JahiaField fakeField = new JahiaField(0, fieldDef.getJahiaID(),                        //        pageID, 0, fieldDef.getID(), fieldDef.getType(0), 0,                        //        fieldDef.getDefaultValue(fieldDef.getID()), 0, 0 );                        JahiaField fakeField = ServicesRegistry.getInstance().                                   getJahiaFieldService().createJahiaField(                                   0, fieldDef.getJahiaID(), pageID, 0,                                   fieldDef.getID(), fieldDef.getType(0), 0,                                   fieldDef.getDefaultValue(fieldDef.getID()),                                   0, 0 );                        addField( fakeField );                        return fakeField;                    }                }            }            return null;        }    } // end getAbsoluteField} // end JahiaFieldSet

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -