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

📄 rdbmuserlayoutstore.java

📁 uPortal是开放源码的Portal门户产品
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/** * Copyright ? 2001, 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;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;import java.util.Enumeration;import java.util.HashMap;import java.util.HashSet;import java.util.Hashtable;import java.util.Vector;import javax.xml.transform.Transformer;import javax.xml.transform.TransformerFactory;import javax.xml.transform.dom.DOMResult;import javax.xml.transform.sax.SAXSource;import org.jasig.portal.channels.CError;import org.jasig.portal.i18n.LocaleManager;import org.jasig.portal.properties.PropertiesManager;import org.jasig.portal.security.IPerson;import org.jasig.portal.security.ISecurityContext;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.jasig.portal.utils.CounterStoreFactory;import org.jasig.portal.utils.DocumentFactory;import org.jasig.portal.utils.ICounterStore;import org.jasig.portal.utils.IPortalDocument;import org.jasig.portal.utils.ResourceLoader;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.xml.sax.InputSource;/** * SQL implementation for the 2.x relational database model * @author George Lindholm * @version $Revision: 1.171.2.4 $ */public class RDBMUserLayoutStore implements IUserLayoutStore {    private static final Log log = LogFactory.getLog(RDBMUserLayoutStore.class);      //This class is instantiated ONCE so NO class variables can be used to keep state between calls  protected static int DEBUG = 0;  protected static final String channelPrefix = "n";  protected static final String folderPrefix = "s";  protected IChannelRegistryStore crs;  protected ICounterStore csdb;  // I18n propertiy  protected static final boolean localeAware = PropertiesManager.getPropertyAsBoolean("org.jasig.portal.i18n.LocaleManager.locale_aware");  /**   * LayoutStructure   * Encapsulate the layout structure   */   protected final class LayoutStructure {    private class StructureParameter {      String name;      String value;      public StructureParameter(String name, String value) {        this.name = name;        this.value = value;      }    }    int structId;    int nextId;    int childId;    int chanId;    String name;    String type;    boolean hidden;    boolean unremovable;    boolean immutable;    ArrayList parameters;    String locale;    /**     *     */    public LayoutStructure(int structId, int nextId,int childId,int chanId, String hidden, String unremovable, String immutable) {      this.nextId = nextId;      this.childId = childId;      this.chanId = chanId;      this.structId = structId;      this.hidden = RDBMServices.dbFlag(hidden);      this.immutable = RDBMServices.dbFlag(immutable);      this.unremovable = RDBMServices.dbFlag(unremovable);      if (DEBUG > 1) {        System.err.println("New layout: id=" + structId + ", next=" + nextId + ", child=" + childId +", chan=" +chanId);      }    }    public LayoutStructure(int structId, int nextId,int childId,int chanId, String hidden, String unremovable, String immutable, String locale) {      this.nextId = nextId;      this.childId = childId;      this.chanId = chanId;      this.structId = structId;      this.hidden = RDBMServices.dbFlag(hidden);      this.immutable = RDBMServices.dbFlag(immutable);      this.unremovable = RDBMServices.dbFlag(unremovable);      this.locale = locale; // for i18n by Shoji      if (DEBUG > 1) {        System.err.println("New layout: id=" + structId + ", next=" + nextId + ", child=" + childId +", chan=" +chanId);      }    }    public void addFolderData(String name, String type) {      this.name = name;      this.type = type;    }    public boolean isChannel () {return chanId != 0;}    public void addParameter(String name, String value) {      if (parameters == null) {        parameters = new ArrayList(5);      }      parameters.add(new StructureParameter(name, value));    }    public int getNextId () {return nextId;}    public int getChildId () {return childId;}    public int getChanId () {return chanId;}    public Element getStructureDocument(Document doc) throws Exception {      Element structure = null;      if (isChannel()) {        ChannelDefinition channelDef = crs.getChannelDefinition(chanId);        if (channelDef != null && channelApproved(channelDef.getApprovalDate())) {            if (localeAware) {                channelDef.setLocale(locale); // for i18n by Shoji            }          structure = channelDef.getDocument(doc, channelPrefix + structId);        } else {          // Create an error channel if channel is missing or not approved          ChannelDefinition cd = new ChannelDefinition(chanId);          cd.setTitle("Missing channel");          cd.setName("Missing channel");          cd.setTimeout(20000);          String missingChannel = "Unknown";          if (channelDef != null) {            missingChannel = channelDef.getName();          }          structure = cd.getDocument(doc, channelPrefix + structId,           "The '" + missingChannel + "' channel is no longer available. Please remove it from your layout.",           CError.CHANNEL_MISSING_EXCEPTION);        }      } else {        structure = doc.createElement("folder");        ((IPortalDocument)doc).putIdentifier(folderPrefix+structId, structure);        structure.setAttribute("ID", folderPrefix + structId);        structure.setAttribute("name", name);        structure.setAttribute("type", (type != null ? type : "regular"));      }      structure.setAttribute("hidden", (hidden ? "true" : "false"));      structure.setAttribute("immutable", (immutable ? "true" : "false"));      structure.setAttribute("unremovable", (unremovable ? "true" : "false"));      if (localeAware) {          structure.setAttribute("locale", locale);  // for i18n by Shoji      }      if (parameters != null) {        for (int i = 0; i < parameters.size(); i++) {          StructureParameter sp = (StructureParameter)parameters.get(i);          if (!isChannel()) {        // Folder            structure.setAttribute(sp.name, sp.value);          } else {                    // Channel            NodeList nodeListParameters = structure.getElementsByTagName("parameter");            for (int j = 0; j < nodeListParameters.getLength(); j++) {              Element parmElement = (Element)nodeListParameters.item(j);              NamedNodeMap nm = parmElement.getAttributes();              String nodeName = nm.getNamedItem("name").getNodeValue();              if (nodeName.equals(sp.name)) {                Node override = nm.getNamedItem("override");                if (override != null && override.getNodeValue().equals("yes")) {                  Node valueNode = nm.getNamedItem("value");                  valueNode.setNodeValue(sp.value);                }              }            }          }        }      }      return structure;    }  }  public RDBMUserLayoutStore () throws Exception {    crs = ChannelRegistryStoreFactory.getChannelRegistryStoreImpl();    csdb = CounterStoreFactory.getCounterStoreImpl();    if (RDBMServices.supportsOuterJoins) {      if (RDBMServices.joinQuery instanceof RDBMServices.JdbcDb) {        RDBMServices.joinQuery.addQuery("layout",          "{oj UP_LAYOUT_STRUCT ULS LEFT OUTER JOIN UP_LAYOUT_PARAM USP ON ULS.USER_ID = USP.USER_ID AND ULS.STRUCT_ID = USP.STRUCT_ID} WHERE");        RDBMServices.joinQuery.addQuery("ss_struct", "{oj UP_SS_STRUCT USS LEFT OUTER JOIN UP_SS_STRUCT_PAR USP ON USS.SS_ID=USP.SS_ID} WHERE");        RDBMServices.joinQuery.addQuery("ss_theme", "{oj UP_SS_THEME UTS LEFT OUTER JOIN UP_SS_THEME_PARM UTP ON UTS.SS_ID=UTP.SS_ID} WHERE");      } else if (RDBMServices.joinQuery instanceof RDBMServices.PostgreSQLDb) {         RDBMServices.joinQuery.addQuery("layout",          "UP_LAYOUT_STRUCT ULS LEFT OUTER JOIN UP_LAYOUT_PARAM USP ON ULS.USER_ID = USP.USER_ID AND ULS.STRUCT_ID = USP.STRUCT_ID WHERE");        RDBMServices.joinQuery.addQuery("ss_struct", "UP_SS_STRUCT USS LEFT OUTER JOIN UP_SS_STRUCT_PAR USP ON USS.SS_ID=USP.SS_ID WHERE");        RDBMServices.joinQuery.addQuery("ss_theme", "UP_SS_THEME UTS LEFT OUTER JOIN UP_SS_THEME_PARM UTP ON UTS.SS_ID=UTP.SS_ID WHERE");     } else if (RDBMServices.joinQuery instanceof RDBMServices.OracleDb) {        RDBMServices.joinQuery.addQuery("layout",          "UP_LAYOUT_STRUCT ULS, UP_LAYOUT_PARAM USP WHERE ULS.STRUCT_ID = USP.STRUCT_ID(+) AND ULS.USER_ID = USP.USER_ID(+) AND");        RDBMServices.joinQuery.addQuery("ss_struct", "UP_SS_STRUCT USS, UP_SS_STRUCT_PAR USP WHERE USS.SS_ID=USP.SS_ID(+) AND");        RDBMServices.joinQuery.addQuery("ss_theme", "UP_SS_THEME UTS, UP_SS_THEME_PARM UTP WHERE UTS.SS_ID=UTP.SS_ID(+) AND");      } else {        throw new Exception("Unknown database driver");      }    }  }  /**   * Registers a NEW structure stylesheet with the database.   * @param ssd the Stylesheet description object   * @return an <code>Integer</code> id for the registered Stylesheet description object   */  public Integer addStructureStylesheetDescription (StructureStylesheetDescription ssd) throws Exception {    Connection con = RDBMServices.getConnection();    try {      // Set autocommit false for the connection      RDBMServices.setAutoCommit(con, false);      Statement stmt = con.createStatement();      try {        // we assume that this is a new stylesheet.        int id = csdb.getIncrementIntegerId("UP_SS_STRUCT");        ssd.setId(id);        String sQuery = "INSERT INTO UP_SS_STRUCT (SS_ID,SS_NAME,SS_URI,SS_DESCRIPTION_URI,SS_DESCRIPTION_TEXT) VALUES ("            + id + ",'" + ssd.getStylesheetName() + "','" + ssd.getStylesheetURI() + "','" + ssd.getStylesheetDescriptionURI()            + "','" + ssd.getStylesheetWordDescription() + "')";        log.debug("RDBMUserLayoutStore::addStructureStylesheetDescription(): " + sQuery);        stmt.executeUpdate(sQuery);        // insert all stylesheet params        for (Enumeration e = ssd.getStylesheetParameterNames(); e.hasMoreElements();) {          String pName = (String)e.nextElement();          sQuery = "INSERT INTO UP_SS_STRUCT_PAR (SS_ID,PARAM_NAME,PARAM_DEFAULT_VAL,PARAM_DESCRIPT,TYPE) VALUES (" + id              + ",'" + pName + "','" + ssd.getStylesheetParameterDefaultValue(pName) + "','" + ssd.getStylesheetParameterWordDescription(pName)              + "',1)";          log.debug("RDBMUserLayoutStore::addStructureStylesheetDescription(): " + sQuery);          stmt.executeUpdate(sQuery);        }        // insert all folder attributes        for (Enumeration e = ssd.getFolderAttributeNames(); e.hasMoreElements();) {          String pName = (String)e.nextElement();          sQuery = "INSERT INTO UP_SS_STRUCT_PAR (SS_ID,PARAM_NAME,PARAM_DEFAULT_VAL,PARAM_DESCRIPT,TYPE) VALUES (" + id              + ",'" + pName + "','" + ssd.getFolderAttributeDefaultValue(pName) + "','" + ssd.getFolderAttributeWordDescription(pName)              + "',2)";          log.debug("RDBMUserLayoutStore::addStructureStylesheetDescription(): " + sQuery);          stmt.executeUpdate(sQuery);        }        // insert all channel attributes        for (Enumeration e = ssd.getChannelAttributeNames(); e.hasMoreElements();) {          String pName = (String)e.nextElement();          sQuery = "INSERT INTO UP_SS_STRUCT_PAR (SS_ID,PARAM_NAME,PARAM_DEFAULT_VAL,PARAM_DESCRIPT,TYPE) VALUES (" + id              + ",'" + pName + "','" + ssd.getChannelAttributeDefaultValue(pName) + "','" + ssd.getChannelAttributeWordDescription(pName)              + "',3)";          log.debug("RDBMUserLayoutStore::addStructureStylesheetDescription(): " + sQuery);          stmt.executeUpdate(sQuery);        }        // Commit the transaction        RDBMServices.commit(con);        return  new Integer(id);      } catch (Exception e) {

⌨️ 快捷键说明

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