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

📄 jahiafieldset.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////  JahiaFieldSet//  EV      31.10.2000//  JT      14.08.2001////  build//  addField//  removeField//  declareField//  checkDeclared//  getField( fieldName )//  getField( fieldID )//package org.jahia.data.fields;import java.util.*;                     // HashTableimport org.jahia.utils.*;           // JahiaConsoleimport org.jahia.data.*;            // JahiaDataimport org.jahia.services.pages.*;  // JahiaPageDefinitionimport org.jahia.data.fields.*;     // JahiaFieldimport org.jahia.registries.*;      // FieldsDefinitionsRegistryimport org.jahia.exceptions.JahiaException;import org.jahia.content.*;import org.jahia.services.pages.JahiaPage;public class JahiaFieldSet {    private JahiaData       jData;    /**     * @associates JahiaField     */    private Hashtable       fields;    /**     * @associates String     */    private Set             declaredFields;    /***        * constructor        * EV    29.12.2000        *        */    public JahiaFieldSet( JahiaData jData )    throws JahiaException    {        this.jData          = jData;        this.fields         = new Hashtable();        this.declaredFields = new HashSet();    } // end constructor    /***        * addField        * EV    29.12.2000        *        */    public void addField( JahiaField theField )    throws JahiaException    {        fields.put( theField.getDefinition().getName(), theField );    } // end addFieldList    /***        * removeField        * EV    29.12.2000        *        */    public void removeField( JahiaField theField )    throws JahiaException    {        fields.remove( theField.getDefinition().getName() );    } // end removeFieldList    /***        * declareField        * EV    29.12.2000        *        */    public void declareField( String fieldName, String fieldTitle, int fieldType, String defaultValue )    throws JahiaException    {        // ensure that the data provided by the user has no special chars in it        fieldName    = FormDataManager.getInstance().encode( fieldName );        fieldTitle   = FormDataManager.getInstance().encode( fieldTitle );        defaultValue = FormDataManager.getInstance().encode( defaultValue );        // we check if a field with the same name was not already declared, of if the field has no        // empty name or title        if ((!checkDeclared(fieldName)) &&            (!jData.containers().checkDeclared(fieldName)) &&            (!fieldName.equals("")) && (!fieldTitle.equals(""))) {            // first, let's check to see if the declared field has already a field definition in the            // FieldsDefinitionsRegistry (which means also in the jahia_fields_def table)            JahiaFieldDefinition aDef = JahiaFieldDefinitionsRegistry.getInstance().getDefinition( jData.params().getSiteID(),fieldName );            int pageDefID = jData.params().getPage().getPageTemplateID();            if (aDef != null) {                // okay, it seems the definition already exists.                // now has it the same data than in the database (title, type, defaultval) ?                if ( aDef.getType(pageDefID) == -1 ){                    // sub def for this page def doesn't exist                    // have to create it                    JahiaConsole.println("JahiaFieldSet.declareField","Create new field sub def for pageDef=" + pageDefID + " and fieldName=" + fieldName + "");                    aDef.setType( fieldType, pageDefID );                    aDef.setTitle( fieldTitle, pageDefID );                    aDef.setDefaultValue( defaultValue, pageDefID );                    JahiaFieldDefinitionsRegistry.getInstance().setDefinition( aDef );                } else if (!((aDef.getTitle(pageDefID).equals(fieldTitle)) &&                    (aDef.getType(pageDefID) == fieldType) &&                    (aDef.getDefaultValue(pageDefID).equals(defaultValue)))) {                    JahiaConsole.println("JahiaFieldSet.declareField",                                         "Field Data for field " + fieldName +                                         " is not synchronized between template and database !" );                    if ( !aDef.getTitle(pageDefID).equals(fieldTitle) ){                        JahiaConsole.println("JahiaFieldSet.declareField", "Title: " +                                             aDef.getTitle(pageDefID) +                                             " is not equal to " + fieldTitle + "" );                    }                    if ( aDef.getType(pageDefID) != fieldType ){                        JahiaConsole.println("JahiaFieldSet.declareField", "Type: " +                                             aDef.getType(pageDefID) +                                             " is not equal to " + fieldType + "");                    }                    if ( !aDef.getDefaultValue(pageDefID).equals(defaultValue) ){                        if (defaultValue.length() > 250) { /** @todo FIXME this                            hardcoded value comes from database field declaration */                            JahiaConsole.println("JahiaFieldSet.declareField", "Default value is too big to fit in database.");                        } else {                            JahiaConsole.println("JahiaFieldSet.declareField", "Default Value: " +                                                 aDef.getDefaultValue(pageDefID) +                                                 "\n is not equal to \n" + defaultValue + "");                        }                    }                    // well, data is not the same in the registry and in the declare() method !                    // this means the user has changed the field declaration in the template...                    // before doing anything else, we have to be sure that the user didn't change the                    // field data type, because this could crash the whole application !                    if ((aDef.getType(pageDefID) != fieldType) && (aDef.getType(pageDefID) != -1)) {                        // okay, this user think he's smart : he tried to change the data type of                        // fields already existing...                        // let's send him a Jahia error to learn him a little lesson                        String errorMsg = "Cannot change field type because field data already exists : " + fieldName;                        JahiaConsole.println( "JahiaFieldSet.declareField", errorMsg + " -> BAILING OUT" );                        throw new JahiaException( errorMsg, errorMsg, JahiaException.TEMPLATE_ERROR,                                    JahiaException.CRITICAL );                    } else {                        // okay, no alert ahead, the type hasn't been modified                        // let's synchronize the data between :                        //  - the template declaration (file)                        //  - the database declaration (database)                        //  - the registry declaration (memory)                        // the synchronizeData method handles all this for us... pfew :)                        aDef.setType( fieldType, pageDefID );                        aDef.setTitle( fieldTitle, pageDefID );                        aDef.setDefaultValue( defaultValue, pageDefID );

⌨️ 快捷键说明

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