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

📄 jahiafieldbaseservice.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        String message = "Could not create an ACL object for a new field in container.";                        JahiaConsole.println ("", message+" -> Stop container creation!");                        throw new JahiaException ("AddContainer_Engine", message,                                JahiaException.ACL_ERROR, JahiaException.CRITICAL);                    } else {                        JahiaConsole.println ("JahiaFieldBaseService.saveField", "ACL ["+acl.getID()+"] has just been created!");                    }                } else {                    throw new JahiaException ("JahiaFieldBaseService.saveField", "Could not instanciate the JahiaBaseACL class",                            JahiaException.ACL_ERROR, JahiaException.CRITICAL);                }                // End Create ACL                theField.setAclID( acl.getID() );            }            //--------- start add to search engine + fire event --------------            if (savemode == 0)            // CREATE            {                toDebug ("saveField(): CREATE - savemode: "+savemode);                JahiaField theTempField = (JahiaField)theField.clone();                theTempField.setValue (tmpVal);                fieldsDB.db_create_field( theTempField );                fieldsDB.db_update_field( theTempField );                cacheFields.setValue (theTempField, new Integer(theField.getID()));                // Search Engine                if ( (theField.getConnectType() == ConnectionTypes.LOCAL) ||                     (theField.getConnectType() == ConnectionTypes.HTMLEDITOR) ||                     (theField.getConnectType() == ConnectionTypes.HTMLEDITORAX) )                {                    ServicesRegistry.getInstance().getJahiaSearchService().addFieldToSearchEngine( theField );                }                // fire event if we're not in a PortletList container                if (jParams != null)                {                    if( logMe(theField) ) {                        JahiaEvent theEvent = new JahiaEvent( this, jParams, theField );                        ServicesRegistry.getInstance().getJahiaEventService().                                fireAddField( theEvent );                    }                }            } else            // UPDATE            {                toDebug ("saveField(): UPDATE - savemode: "+savemode);                JahiaField oldField  = this.loadField( theField.getID(), LoadFlags.TEXTS );                if (oldField.getConnectType() == ConnectionTypes.LOCAL) {                    ServicesRegistry.getInstance().getJahiaSearchService().removeFieldFromSearchEngine( oldField );                }                // JB 02.08.2001 - Add HTMLEditor Types                if (oldField.getConnectType() == ConnectionTypes.HTMLEDITOR) {                    ServicesRegistry.getInstance().getJahiaSearchService().removeFieldFromSearchEngine( oldField );                }                if (oldField.getConnectType() == ConnectionTypes.HTMLEDITORAX) {                    ServicesRegistry.getInstance().getJahiaSearchService().removeFieldFromSearchEngine( oldField );                }                JahiaField theTempField = (JahiaField)theField.clone();                theTempField.setValue (tmpVal);                fieldsDB.db_update_field( theTempField );                cacheFields.setValue (theTempField, new Integer(theField.getID()));                if (theField.getConnectType() == ConnectionTypes.LOCAL) {                    ServicesRegistry.getInstance().getJahiaSearchService().addFieldToSearchEngine( theField );                }                // JB 02.08.2001 - Add HTMLEditor Types                if (theField.getConnectType() == ConnectionTypes.HTMLEDITOR) {                    ServicesRegistry.getInstance().getJahiaSearchService().addFieldToSearchEngine( theField );                }                if (theField.getConnectType() == ConnectionTypes.HTMLEDITORAX) {                    ServicesRegistry.getInstance().getJahiaSearchService().addFieldToSearchEngine( theField );                }                // fire event if we're not in a PortletList container                if( logMe(theField) ) {                    JahiaEvent theEvent = new JahiaEvent( this, jParams, theField );                    ServicesRegistry.getInstance().getJahiaEventService().                                fireUpdateField( theEvent );                }            }            //--------- end add to search engine + fire event --------------            // saves field additionnal info, if needed            theField.save(jParams);    } // saveField   /***        * deletes a field        *        * @param        fieldID             the field id to delete        *        */    public void deleteField( int fieldID, ParamBean jParams )    throws JahiaException    {        JahiaField theField = loadField( fieldID );		boolean doIndexField = !ServicesRegistry.getInstance().getJahiaSitesService().isSiteToBeDeleted(theField.getJahiaID());        if (theField.getConnectType() == ConnectionTypes.LOCAL) {            if ( doIndexField ){            	ServicesRegistry.getInstance().getJahiaSearchService().removeFieldFromSearchEngine( theField );            }        }        // JB 02.08.2001 - Add HTMLEditor Types        if (theField.getConnectType() == ConnectionTypes.HTMLEDITOR) {            if ( doIndexField ){            	ServicesRegistry.getInstance().getJahiaSearchService().removeFieldFromSearchEngine( theField );        	}        }        if (theField.getConnectType() == ConnectionTypes.HTMLEDITORAX) {            if ( doIndexField ){            	ServicesRegistry.getInstance().getJahiaSearchService().removeFieldFromSearchEngine( theField );        	}        }        int pageDefID = ServicesRegistry.getInstance().getJahiaPageService().                lookupPage(theField.getPageID()).getPageTemplateID();        int fieldType = theField.getDefinition().getType(pageDefID);        if (fieldType == FieldTypes.UNDEFINED) {            fieldType = theField.getType();        }        // delete info specific to field type        theField.delete(jParams);        try {            JahiaBaseACL theACL = new JahiaBaseACL (theField.getAclID());            theACL.delete ();        }        catch (ACLNotFoundException ex) {            JahiaException je = new JahiaException ("", "Could not find the ACL ["+Integer.toString (theField.getAclID())+                                "] while removing field ["+Integer.toString(fieldID)+"]",                                JahiaException.ACL_ERROR, JahiaException.WARNING);        }        if( logMe(theField) ) {            JahiaEvent theEvent = new JahiaEvent( this, jParams, theField );            ServicesRegistry.getInstance().getJahiaEventService().                        fireDeleteField( theEvent );        }        fieldsDB.db_delete_field( theField.getID() );        cacheFields.removeValue(new Integer(theField.getID()));    } // deleteField    /***        * Loads a Field Definition by its id        *        * @param        defID               the field definition id        * @return       a JahiaFieldDefinition object        * @see          org.jahia.data.fields.JahiaFieldDefinition        *        */    public JahiaFieldDefinition loadFieldDefinition( int defID )    throws JahiaException    {        return f_defs.db_load_field_definition( defID );    } // loadFieldDefinition    /***        * Saves a Field Definition        *        * @param        theDef              the JahiaFieldDefinition object to save        * @see          org.jahia.data.fields.JahiaFieldDefinition        *        */    public void saveFieldDefinition( JahiaFieldDefinition theDef )    throws JahiaException    {        if (theDef.getID() == 0 || theDef.getID() == -1) {            f_defs.db_create_field_definition( theDef );        } else {            f_defs.db_update_field_definition( theDef );        }    } // saveFieldDefinition    /***        * Delete a Field Definition and it's sub definition.        *        * @param int the field def ID        */    public void deleteFieldDefinition(int fieldDefID)    throws JahiaException{        JahiaConsole.println("JhaiaFieldBaseService.deleteFieldDefinition","fieldDef=" + fieldDefID);        //remove from registry        JahiaFieldDefinitionsRegistry.getInstance().removeFieldDefinition( fieldDefID );        // remove from database        f_defs.db_delete_field_definition( fieldDefID );    }   /**    * Method getTextFileService    * @author NK    * @return a JahiaTextFileService instance    */   protected JahiaTextFileService getTextFileService(){      return ServicesRegistry.getInstance().getJahiaTextFileService();   }    //-------------------------------------------------------------------------    private boolean logMe (JahiaField theField)    {        boolean out = false;        int ctnid = theField.getctnid();        if( ctnid > 0 ) {            ServicesRegistry sReg =  ServicesRegistry.getInstance();            if( sReg != null ) {                JahiaContainersService ctnSrv = sReg.getJahiaContainersService();                if( ctnSrv != null ) {                    try {                        JahiaContainer container = ctnSrv.loadContainerInfo(ctnid);                        if( container != null ) {                            String containerName = container.getDefinition().getName();                            if( !containerName.equals("PortletList")) {                                out = true;                            }                         }                    }                    catch(JahiaException je) {                        // do nothing                    }                }            }        }        return out;    }    //-------------------------------------------------------------------------    private synchronized void toDebug (String message)    {        if (false)        {            System.out.println (message);        }    }    //--------------------------------------------------------------------------    /**     * returns a DOM representation of all fields of a site     *     * @param int siteID     * @auhtor NK     */    public JahiaDOMObject getFieldsAsDOM( int siteID ) throws JahiaException{        return fieldsDB.getFieldsAsDOM (siteID);    }    //--------------------------------------------------------------------------    /**     * returns a DOM representation of all field def of a site     *     * @param int siteID     * @auhtor NK     */    public JahiaDOMObject getFieldDefsAsDOM( int siteID ) throws JahiaException{        return f_defs.getFieldDefsAsDOM (siteID);    }    //--------------------------------------------------------------------------    /**     * returns a DOM representation of all field def props of a site     *     * @param int siteID     * @auhtor NK     */    public JahiaDOMObject getFieldDefPropsAsDOM( int siteID ) throws JahiaException{        return f_defs.getFieldDefPropsAsDOM (siteID);    }    //--------------------------------------------------------------------------    /**     * Returns a vector of all Acl ID used by fields for a site     * Need this for site extraction     *     * @param int siteID     * @auhtor NK     */    public Vector getAclIDs( int siteID )    throws JahiaException{        return f_utils.db_get_all_acl_id(siteID);    }    /**     * Compose the file absolute path to a flat file containing the default value for a field definition.     *     * @param siteID     * @param name     * @return     */    public String composeFieldDefDefaultValueFilePath(int siteID, String name){        StringBuffer buff = new StringBuffer(this.jahiaVarDiskPath);        buff.append(File.separator);        buff.append("field_definitions");        buff.append(File.separator);        buff.append(siteID);        buff.append("_");        buff.append(name);        buff.append("_defaultvalue.txt");        return buff.toString();    }    /**     * Returns the path to the folder containing the field definitions     *     * @return     */    public String getFieldDefinitionsDiskPath(){        StringBuffer buff = new StringBuffer(this.jahiaVarDiskPath);        buff.append(File.separator);        buff.append("field_definitions");        return buff.toString();    }    private void createFileDefinitionRepository(){        StringBuffer buff =                new StringBuffer(this.jahiaVarDiskPath);        buff.append(File.separator);        buff.append("field_definitions");        File f = new File(buff.toString());        f.mkdir();    }} // end JahiaFieldBaseService

⌨️ 快捷键说明

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