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

📄 fragmentloader.java

📁 uPortal是开放源码的Portal门户产品
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * Copyright ? 2002 The JA-SIG Collaborative.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * 3. Redistributions of any form whatsoever must retain the following *    acknowledgment: *    "This product includes software developed by the JA-SIG Collaborative *    (http://www.jasig.org/)." * * THIS SOFTWARE IS PROVIDED BY THE JA-SIG COLLABORATIVE "AS IS" AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE JA-SIG COLLABORATIVE OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. **/package org.jasig.portal.layout.utils;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.Statement;import java.util.HashMap;import java.util.Map;import java.util.Set;import java.util.Iterator;import javax.xml.transform.TransformerFactory;import javax.xml.transform.sax.SAXTransformerFactory;import javax.xml.transform.sax.TransformerHandler;import javax.xml.transform.stream.StreamResult;import javax.xml.transform.stream.StreamSource;import org.jasig.portal.ChannelDefinition;import org.jasig.portal.IChannelRegistryStore;import org.jasig.portal.ChannelRegistryStoreFactory;import org.jasig.portal.layout.IAggregatedUserLayoutStore;import org.jasig.portal.UserLayoutStoreFactory;import org.jasig.portal.IUserLayoutStore;import org.jasig.portal.EntityIdentifier;import org.jasig.portal.PortalException;import org.jasig.portal.RDBMServices;import org.jasig.portal.groups.IEntityGroup;import org.jasig.portal.groups.IGroupConstants;import org.jasig.portal.services.GroupService;import org.jasig.portal.utils.SAX2FilterImpl;import org.xml.sax.Attributes;import org.xml.sax.ContentHandler;import org.xml.sax.InputSource;import org.xml.sax.SAXException;import org.xml.sax.XMLReader;import org.xml.sax.helpers.AttributesImpl;import org.xml.sax.helpers.XMLReaderFactory;/** * A utility class to load pushed fragment configuration into the database * used by the pushfragment ant target. * * @author <a href="mailto:pkharchenko@interactivebusiness.com">Peter Kharchenko</a> * @author <a href="mailto:mvi@immagic.com">Michael Ivanov</a> * @version 1.0 */public class FragmentLoader {    static final String configXSL="/properties/al/FragmentLoader.xsl";    public static void main(String[] args) throws Exception {        String alConfigFile=args[0];        String outputDataFile=args[1];        HashMap rNames=new HashMap();        // compile a table of restriction types        Connection con=null;        try {            con=RDBMServices.getConnection();            if(con!=null) {                Statement stmt = con.createStatement();                String query="SELECT RESTRICTION_TYPE,RESTRICTION_NAME FROM UP_RESTRICTIONS";                ResultSet rs=stmt.executeQuery(query);                while(rs.next()) {                    rNames.put(rs.getString("RESTRICTION_NAME"),rs.getString("RESTRICTION_TYPE"));                    System.out.println("DEBUG: restriction type mapping "+rs.getString("RESTRICTION_NAME")+" -> "+rs.getString("RESTRICTION_TYPE"));                }            } else {                System.out.println("ERROR: unable to obtain database connection.");                System.exit(1);            }        } catch (Exception e) {            System.out.println("ERROR: exception raised while reading restriction type mappings:");            e.printStackTrace();            System.exit(1);        } finally {            if(con!=null) {                RDBMServices.releaseConnection(con);            }        }        // instantiate transfomer        SAXTransformerFactory saxTFactory=(SAXTransformerFactory) TransformerFactory.newInstance();        System.out.println("DEBUG: reading XSLT from url="+FragmentLoader.class.getResource(configXSL));        XMLReader reader = XMLReaderFactory.createXMLReader();        // for some weird weird reason, the following way of instantiating the parser causes all elements to dissapear ...        // nothing like a bizzare bug like that to take up your afternoon :(        //        XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();        TransformerHandler thand=saxTFactory.newTransformerHandler(new StreamSource(FragmentLoader.class.getResourceAsStream(configXSL)));        // instantiate filter        ConfigFilter filter=new ConfigFilter(thand,rNames);        reader.setContentHandler(filter);        thand.setResult(new StreamResult(outputDataFile));        boolean isException = false;        try {         reader.parse(new InputSource(FragmentLoader.class.getResourceAsStream(alConfigFile)));        } catch ( Exception e ) {			isException = true;			System.out.println ( "The pushed fragment file \""+alConfigFile+"\" caused the exception: " );        	e.printStackTrace();          }        if ( !isException ) {         // Cleaning the database before the DbLoader is called         DbCleaner.cleanTables(filter.getFragmentIds());         System.out.println("DEBUG: done");        }         System.exit(0);    }     /**     * Cleans up the tables contained the old data of the fragments to be reloaded     * It is used before the DbLoader utility is called     *     */  private static class DbCleaner {   public static void cleanTables( Map fragmentIds ) {    Connection con = RDBMServices.getConnection();    if ( fragmentIds != null && !fragmentIds.isEmpty() ) {     try {      PreparedStatement fragmentIdstmt = con.prepareStatement("SELECT FRAGMENT_ID FROM UP_OWNER_FRAGMENT WHERE FRAGMENT_NAME = ?");      Map oldFragmentIds = new HashMap();      for ( Iterator i = fragmentIds.keySet().iterator(); i.hasNext(); ) {       String name = (String)i.next();       fragmentIdstmt.setString(1,name);       ResultSet rs = fragmentIdstmt.executeQuery();       if ( rs.next() ) oldFragmentIds.put(rs.getString(1),name);       if ( rs != null ) rs.close();      }      if ( fragmentIdstmt != null ) fragmentIdstmt.close();      if ( oldFragmentIds.size() > 0 ) {        System.out.println("DEBUG: cleaning tables...");         con.setAutoCommit(false);         //PreparedStatement deleteLayoutStruct = con.prepareStatement("DELETE FROM UP_LAYOUT_STRUCT_AGGR WHERE FRAGMENT_ID = ?");         PreparedStatement updateLayoutStruct = con.prepareStatement("UPDATE UP_LAYOUT_STRUCT_AGGR SET FRAGMENT_ID = ? WHERE FRAGMENT_ID = ?");         PreparedStatement deleteFragments = con.prepareStatement("DELETE FROM UP_FRAGMENTS WHERE FRAGMENT_ID = ?");         PreparedStatement deleteFragmentRestrictions = con.prepareStatement("DELETE FROM UP_FRAGMENT_RESTRICTIONS WHERE FRAGMENT_ID = ?");         PreparedStatement deleteFragmentParams = con.prepareStatement("DELETE FROM UP_FRAGMENT_PARAM WHERE FRAGMENT_ID = ?");         PreparedStatement deleteOwnerFragment = con.prepareStatement("DELETE FROM UP_OWNER_FRAGMENT WHERE FRAGMENT_ID = ?");         PreparedStatement deleteGroupFragment = con.prepareStatement("DELETE FROM UP_GROUP_FRAGMENT WHERE FRAGMENT_ID = ?");         try {          for ( Iterator i = oldFragmentIds.keySet().iterator(); i.hasNext(); ) {           String oldId = (String) i.next();            int fragmentId = Integer.parseInt(oldId);           // Setting the parameter - fragment id           String newId = (String) fragmentIds.get(oldFragmentIds.get(oldId));           updateLayoutStruct.setInt(1,Integer.parseInt(newId));           updateLayoutStruct.setInt(2,fragmentId);           deleteFragments.setInt(1,fragmentId);           deleteFragmentRestrictions.setInt(1,fragmentId);           deleteFragmentParams.setInt(1,fragmentId);           deleteOwnerFragment.setInt(1,fragmentId);           deleteGroupFragment.setInt(1,fragmentId);           // Executing statements           updateLayoutStruct.executeUpdate();           deleteFragments.executeUpdate();           deleteFragmentRestrictions.executeUpdate();           deleteFragmentParams.executeUpdate();           deleteOwnerFragment.executeUpdate();           deleteGroupFragment.executeUpdate();          }          // Commit          con.commit();         } catch ( Exception sqle ) {            con.rollback();            System.out.println ( "DEBUG: " + sqle.getMessage() );            sqle.printStackTrace();           }         if ( updateLayoutStruct != null ) updateLayoutStruct.close();         if ( deleteFragments != null ) deleteFragments.close();         if ( deleteFragmentRestrictions != null ) deleteFragmentRestrictions.close();         if ( deleteFragmentParams != null ) deleteFragmentParams.close();         if ( deleteOwnerFragment != null ) deleteOwnerFragment.close();         if ( deleteGroupFragment != null ) deleteGroupFragment.close();         if ( con != null ) con.close();         System.out.println("DEBUG: cleaning done...");       } // if end      } catch ( Exception e ) {            System.out.println ( "DEBUG: " + e.getMessage() );            e.printStackTrace();        }     } // if end    }  }

⌨️ 快捷键说明

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