Compare commits
1 Commits
v1
...
tags/DISKC
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76d0ff3c3f |
6
mozilla/netwerk/cache/public/MANIFEST
vendored
Normal file
6
mozilla/netwerk/cache/public/MANIFEST
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
nsICachedNetData.idl
|
||||
nsINetDataCache.idl
|
||||
nsINetDataCacheManager.idl
|
||||
nsINetDataCacheRecord.idl
|
||||
nsINetDataDiskCache.idl
|
||||
nsIStreamAsFile.idl
|
||||
56
mozilla/netwerk/cache/public/Makefile.in
vendored
Normal file
56
mozilla/netwerk/cache/public/Makefile.in
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
MODULE = nkcache
|
||||
XPIDL_MODULE = necko_cache
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsICachedNetData.idl \
|
||||
nsINetDataCacheManager.idl \
|
||||
nsINetDataCache.idl \
|
||||
nsINetDataCacheRecord.idl \
|
||||
nsINetDataDiskCache.idl \
|
||||
nsIStreamAsFile.idl \
|
||||
$(NULL)
|
||||
|
||||
|
||||
ifdef MOZ_NEW_CACHE
|
||||
XPIDLSRCS += \
|
||||
nsICache.idl \
|
||||
nsICacheEntryDescriptor.idl \
|
||||
nsICacheListener.idl \
|
||||
nsICacheService.idl \
|
||||
nsICacheSession.idl \
|
||||
nsICacheVisitor.idl \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
51
mozilla/netwerk/cache/public/Makefile.win
vendored
Executable file
51
mozilla/netwerk/cache/public/Makefile.win
vendored
Executable file
@@ -0,0 +1,51 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
MODULE = necko
|
||||
XPIDL_MODULE = necko_cache
|
||||
|
||||
DEPTH = ..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
.\nsICachedNetData.idl \
|
||||
.\nsINetDataCacheManager.idl \
|
||||
.\nsINetDataCache.idl \
|
||||
.\nsINetDataCacheRecord.idl \
|
||||
.\nsINetDataDiskCache.idl \
|
||||
.\nsIStreamAsFile.idl \
|
||||
!ifdef MOZ_NEW_CACHE
|
||||
.\nsICache.idl \
|
||||
.\nsICacheEntryDescriptor.idl \
|
||||
.\nsICacheListener.idl \
|
||||
.\nsICacheService.idl \
|
||||
.\nsICacheSession.idl \
|
||||
.\nsICacheVisitor.idl \
|
||||
!endif
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
|
||||
158
mozilla/netwerk/cache/public/nsICache.idl
vendored
Normal file
158
mozilla/netwerk/cache/public/nsICache.idl
vendored
Normal file
@@ -0,0 +1,158 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsICache.idl, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
typedef long nsCacheStoragePolicy;
|
||||
typedef long nsCacheAccessMode;
|
||||
|
||||
/**
|
||||
* nsICache is a namespace for various cache constants. It does not represent
|
||||
* an actual object.
|
||||
*/
|
||||
[scriptable, uuid(ec1c0063-197d-44bb-84ba-7525d50fc937)]
|
||||
interface nsICache
|
||||
{
|
||||
/**
|
||||
* Access Modes
|
||||
*
|
||||
*
|
||||
* Mode Requested | Not Cached | Cached
|
||||
* ------------------------------------------------------------------------
|
||||
* READ | KEY_NOT_FOUND | NS_OK
|
||||
* | Mode = NONE | Mode = READ
|
||||
* | No Descriptor | Descriptor
|
||||
* ------------------------------------------------------------------------
|
||||
* WRITE | NS_OK | NS_OK (Cache service
|
||||
* | Mode = WRITE | Mode = WRITE dooms existing
|
||||
* | Descriptor | Descriptor cache entry)
|
||||
* ------------------------------------------------------------------------
|
||||
* READ_WRITE | NS_OK | NS_OK
|
||||
* (1st req.) | Mode = WRITE | Mode = READ_WRITE
|
||||
* | Descriptor | Descriptor
|
||||
* ------------------------------------------------------------------------
|
||||
* READ_WRITE | N/A | NS_OK
|
||||
* (Nth req.) | | Mode = READ
|
||||
* | | Descriptor
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
*
|
||||
* Access Requested:
|
||||
*
|
||||
* READ - I only want to READ, if there isn't an entry just fail
|
||||
* WRITE - I have something new I want to write into the cache, make
|
||||
* me a new entry and doom the old one, if any.
|
||||
* READ_WRITE - I want to READ, but I'm willing to update an existing
|
||||
* entry if necessary, or create a new one if none exists.
|
||||
*
|
||||
*
|
||||
* Access Granted:
|
||||
*
|
||||
* NONE - No descriptor is provided. You get zilch. Nada. Nothing.
|
||||
* READ - You can READ from this descriptor.
|
||||
* WRITE - You must WRITE to this descriptor because the cache entry
|
||||
* was just created for you.
|
||||
* READ_WRITE - You can READ the descriptor to determine if it's valid,
|
||||
* you may WRITE if it needs updating.
|
||||
*
|
||||
*
|
||||
* Comments:
|
||||
*
|
||||
* If you think that you might need to modify cached data or meta data,
|
||||
* then you must open a cache entry requesting WRITE access. Only one
|
||||
* cache entry descriptor, per cache entry, will be granted WRITE access.
|
||||
*
|
||||
* Usually, you will request READ_WRITE access in order to first test the
|
||||
* meta data and informational fields to determine if a write (ie. going
|
||||
* to the net) may actually be necessary. If you determine that it is
|
||||
* not, then you would mark the cache entry as valid (using MarkValid) and
|
||||
* then simply read the data from the cache.
|
||||
*
|
||||
* A descriptor granted WRITE access has exclusive access to the cache
|
||||
* entry up to the point at which it marks it as valid. Once the cache
|
||||
* entry has been "validated", other descriptors with READ access may be
|
||||
* opened to the cache entry.
|
||||
*
|
||||
* If you make a request for READ_WRITE access to a cache entry, the cache
|
||||
* service will downgrade your access to READ if there is already a
|
||||
* cache entry descriptor open with WRITE access.
|
||||
*
|
||||
* If you make a request for only WRITE access to a cache entry and another
|
||||
* descriptor with WRITE access is currently open, then the existing cache
|
||||
* entry will be 'doomed', and you will be given a descriptor (with WRITE
|
||||
* access only) to a new cache entry.
|
||||
*
|
||||
*/
|
||||
const nsCacheAccessMode ACCESS_NONE = 0;
|
||||
const nsCacheAccessMode ACCESS_READ = 1;
|
||||
const nsCacheAccessMode ACCESS_WRITE = 2;
|
||||
const nsCacheAccessMode ACCESS_READ_WRITE = 3;
|
||||
|
||||
/**
|
||||
* Storage Policy
|
||||
*
|
||||
* The storage policy of a cache entry determines the device(s) to which
|
||||
* it belongs. See nsICacheSession and nsICacheEntryDescriptor for more
|
||||
* details.
|
||||
*
|
||||
* STORE_ANYWHERE - Allows the cache entry to be stored in any device.
|
||||
* The cache service decides which cache device to use
|
||||
* based on "some resource management calculation."
|
||||
* STORE_IN_MEMORY - Requires the cache entry to reside in non-persistent
|
||||
* storage (ie. typically in system RAM).
|
||||
* STORE_ON_DISK - Requires the cache entry to reside in persistent
|
||||
* storage (ie. typically on a system's hard disk).
|
||||
* STORE_ON_DISK_AS_DISK - Requires the cache entry to reside in persistent
|
||||
* storage, and in a specific file.
|
||||
*/
|
||||
const nsCacheStoragePolicy STORE_ANYWHERE = 0;
|
||||
const nsCacheStoragePolicy STORE_IN_MEMORY = 1;
|
||||
const nsCacheStoragePolicy STORE_ON_DISK = 2;
|
||||
const nsCacheStoragePolicy STORE_ON_DISK_AS_FILE = 3;
|
||||
|
||||
/**
|
||||
* All entries for a cache session are stored as streams of data or
|
||||
* as objects. These constant my be used to specify the type of entries
|
||||
* when calling nsICacheService::CreateSession().
|
||||
*/
|
||||
const long NOT_STREAM_BASED = 0;
|
||||
const long STREAM_BASED = 1;
|
||||
};
|
||||
|
||||
|
||||
%{C++
|
||||
|
||||
/**
|
||||
* Cache specific nsresult error codes
|
||||
*/
|
||||
#define NS_ERROR_CACHE_KEY_NOT_FOUND NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 60)
|
||||
#define NS_ERROR_CACHE_DATA_IS_STREAM NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 61)
|
||||
#define NS_ERROR_CACHE_DATA_IS_NOT_STREAM NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 62)
|
||||
#define NS_ERROR_CACHE_WAIT_FOR_VALIDATION NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 63)
|
||||
#define NS_ERROR_CACHE_ENTRY_DOOMED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 64)
|
||||
#define NS_ERROR_CACHE_READ_ACCESS_DENIED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 65)
|
||||
#define NS_ERROR_CACHE_WRITE_ACCESS_DENIED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 66)
|
||||
|
||||
%}
|
||||
121
mozilla/netwerk/cache/public/nsICacheEntryDescriptor.idl
vendored
Normal file
121
mozilla/netwerk/cache/public/nsICacheEntryDescriptor.idl
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsICacheEntryDescriptor.idl, released
|
||||
* February 10, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsICacheVisitor.idl"
|
||||
#include "nsICache.idl"
|
||||
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsICacheListener;
|
||||
interface nsITransport;
|
||||
interface nsIFile;
|
||||
|
||||
[scriptable, uuid(49c1a11d-f5d2-4f09-8262-551e64908ada)]
|
||||
interface nsICacheEntryDescriptor : nsICacheEntryInfo
|
||||
{
|
||||
/**
|
||||
* Set the time at which the cache entry should be considered invalid (in
|
||||
* seconds since the Epoch).
|
||||
*/
|
||||
void setExpirationTime(in PRUint32 expirationTime);
|
||||
|
||||
/**
|
||||
* Set the cache entry data size. This will fail if the cache entry
|
||||
* IS stream based.
|
||||
*/
|
||||
void setDataSize(in unsigned long size);
|
||||
|
||||
/**
|
||||
* Get a transport to the cache data. This will fail if the cache entry
|
||||
* IS NOT stream based.
|
||||
*/
|
||||
readonly attribute nsITransport transport;
|
||||
|
||||
/**
|
||||
* Get/set the cache data element. This will fail if the cache entry
|
||||
* IS stream based. The cache entry holds a strong reference to this
|
||||
* object. The object will be released when the cache entry is destroyed.
|
||||
*/
|
||||
attribute nsISupports cacheElement;
|
||||
|
||||
/**
|
||||
* Get the access granted to this descriptor. See nsICache.idl for the
|
||||
* definitions of the access modes and a thorough description of their
|
||||
* corresponding meanings.
|
||||
*/
|
||||
readonly attribute nsCacheAccessMode accessGranted;
|
||||
|
||||
/**
|
||||
* Get/set the storage policy of the cache entry. See nsICache.idl for
|
||||
* the definitions of the storage policies.
|
||||
*/
|
||||
attribute nsCacheStoragePolicy storagePolicy;
|
||||
|
||||
/**
|
||||
* Get the disk file associated with the cache entry.
|
||||
*/
|
||||
readonly attribute nsIFile file;
|
||||
|
||||
/**
|
||||
* Get/set security info on the cache entry for this descriptor. This fails
|
||||
* if the storage policy is not STORE_IN_MEMORY.
|
||||
*/
|
||||
attribute nsISupports securityInfo;
|
||||
|
||||
/**
|
||||
* Doom the cache entry this descriptor references in order to slate it for
|
||||
* removal. Once doomed a cache entry cannot be undoomed.
|
||||
*
|
||||
* A descriptor with WRITE access can doom the cache entry and choose to
|
||||
* fail pending requests. This means that pending requests will not get
|
||||
* a cache descriptor. This is meant as a tool for clients that wish to
|
||||
* instruct pending requests to skip the cache.
|
||||
*/
|
||||
void doom();
|
||||
void doomAndFailPendingRequests(in nsresult status);
|
||||
|
||||
/**
|
||||
* A writer must validate this cache object before any readers are given
|
||||
* a descriptor to the object.
|
||||
*/
|
||||
void markValid();
|
||||
|
||||
/**
|
||||
* Explicitly close the descriptor (optional).
|
||||
*/
|
||||
|
||||
void close();
|
||||
|
||||
/**
|
||||
* Methods for accessing meta data. Meta data is a table of key/value
|
||||
* string pairs. The strings do not have to conform to any particular
|
||||
* charset, but they must be null terminated.
|
||||
*/
|
||||
string getMetaDataElement(in string key);
|
||||
void setMetaDataElement(in string key, in string value);
|
||||
|
||||
nsISimpleEnumerator getMetaDataEnumerator(); /* todo */
|
||||
};
|
||||
|
||||
44
mozilla/netwerk/cache/public/nsICacheListener.idl
vendored
Normal file
44
mozilla/netwerk/cache/public/nsICacheListener.idl
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsICacheListener.idl, released January 19, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsICache.idl"
|
||||
|
||||
|
||||
interface nsICacheEntryDescriptor;
|
||||
|
||||
[scriptable, uuid(638c3848-778b-4851-8ff3-9400f65b8773)]
|
||||
interface nsICacheListener : nsISupports
|
||||
{
|
||||
/**
|
||||
* Called when the requested access (or appropriate subset) is
|
||||
* acquired. The status parameter equals NS_OK on success.
|
||||
* See nsICacheService.idl for accessGranted values.
|
||||
*/
|
||||
void onCacheEntryAvailable(in nsICacheEntryDescriptor descriptor,
|
||||
in nsCacheAccessMode accessGranted,
|
||||
in nsresult status);
|
||||
};
|
||||
80
mozilla/netwerk/cache/public/nsICacheService.idl
vendored
Normal file
80
mozilla/netwerk/cache/public/nsICacheService.idl
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsICacheService.idl, released February 10, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsICache.idl"
|
||||
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsICacheListener;
|
||||
interface nsICacheSession;
|
||||
interface nsICacheVisitor;
|
||||
|
||||
[scriptable, uuid(0ebec4c7-742f-4f27-8e7b-7c8a0cc76348)]
|
||||
interface nsICacheService : nsISupports
|
||||
{
|
||||
/**
|
||||
* Initialize the cache service.
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Shutdown the cache service.
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* Create a cache session
|
||||
*
|
||||
* A cache session represents a client's access into the cache. The cache
|
||||
* session is not "owned" by the cache service. Hence, it is possible to
|
||||
* create duplicate cache sessions. Entries created by a cache session
|
||||
* are invisible to other cache sessions, unless the cache sessions are
|
||||
* equivalent.
|
||||
*
|
||||
* @param clientID - Specifies the name of the client using the cache.
|
||||
* @param storagePolicy - Limits the storage policy for all entries
|
||||
* accessed via the returned session. As a result, devices excluded
|
||||
* by the storage policy will not be searched when opening entries
|
||||
* from the returned session.
|
||||
* @param streamBased - Indicates whether or not the data being cached
|
||||
* can be represented as a stream. The storagePolicy must be
|
||||
* consistent with the value of this field. For example, a non-stream-
|
||||
* based cache entry can only have a storage policy of STORE_IN_MEMORY.
|
||||
* @return new cache session.
|
||||
*/
|
||||
nsICacheSession createSession(in string clientID,
|
||||
in nsCacheStoragePolicy storagePolicy,
|
||||
in boolean streamBased);
|
||||
|
||||
/**
|
||||
* Visit entries stored in the cache. Used to implement about:cache.
|
||||
*/
|
||||
void visitEntries(in nsICacheVisitor visitor);
|
||||
|
||||
/**
|
||||
* Evicts all entries in all devices implied by the storage policy.
|
||||
*/
|
||||
void evictEntries(in nsCacheStoragePolicy storagePolicy);
|
||||
};
|
||||
71
mozilla/netwerk/cache/public/nsICacheSession.idl
vendored
Normal file
71
mozilla/netwerk/cache/public/nsICacheSession.idl
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsICacheSession.idl, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsICache.idl"
|
||||
|
||||
interface nsICacheEntryDescriptor;
|
||||
interface nsICacheListener;
|
||||
|
||||
[scriptable, uuid(b4b419ad-28b7-4d25-9988-20fa98505a19)]
|
||||
interface nsICacheSession : nsISupports
|
||||
{
|
||||
/**
|
||||
* Expired entries will be doomed or evicted if this attribute is set to
|
||||
* true. If false, expired entries will be returned (useful for offline-
|
||||
* mode and clients, such as HTTP, that can update the valid lifetime of
|
||||
* cached content). This attribute defaults to true.
|
||||
*/
|
||||
attribute PRBool doomEntriesIfExpired;
|
||||
|
||||
/**
|
||||
* A cache session can only give out one descriptor with WRITE access
|
||||
* to a given cache entry at a time. Until the client calls MarkValid on
|
||||
* its descriptor, other attempts to open the same cache entry will block.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Synchronous cache access. This returns a unique descriptor each
|
||||
* time it is called, even if the same key is specified. When
|
||||
* called by multiple threads for write access, only one writable
|
||||
* descriptor will be granted.
|
||||
*/
|
||||
nsICacheEntryDescriptor openCacheEntry(in string key,
|
||||
in nsCacheAccessMode accessRequested);
|
||||
|
||||
/**
|
||||
* Asynchronous cache access. Does not block the calling thread.
|
||||
* Instead, the listener will be notified when the descriptor is
|
||||
* available.
|
||||
*/
|
||||
void asyncOpenCacheEntry(in string key,
|
||||
in nsCacheAccessMode accessRequested,
|
||||
in nsICacheListener listener);
|
||||
|
||||
/**
|
||||
* Evict all entries for this session's clientID according to its storagePolicy.
|
||||
*/
|
||||
void evictEntries();
|
||||
};
|
||||
137
mozilla/netwerk/cache/public/nsICacheVisitor.idl
vendored
Normal file
137
mozilla/netwerk/cache/public/nsICacheVisitor.idl
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsICacheVisitor.idl, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/* XXX we should define device and entry info as well (stats, etc) */
|
||||
|
||||
interface nsICacheDeviceInfo;
|
||||
interface nsICacheEntryInfo;
|
||||
|
||||
|
||||
[scriptable, uuid(f8c08c4b-d778-49d1-a59b-866fdc500d95)]
|
||||
interface nsICacheVisitor : nsISupports
|
||||
{
|
||||
/**
|
||||
* Called to provide information about a cache device.
|
||||
*
|
||||
* @param deviceID - specifies the device being visited.
|
||||
* @param deviceInfo - specifies information about this device.
|
||||
*
|
||||
* @return true to start visiting all entries for this device.
|
||||
* @return false to advance to the next device.
|
||||
*/
|
||||
boolean visitDevice(in string deviceID,
|
||||
in nsICacheDeviceInfo deviceInfo);
|
||||
|
||||
/**
|
||||
* Called to provide information about a cache entry.
|
||||
*
|
||||
* @param deviceID - specifies the device being visited.
|
||||
* @param entryInfo - specifies information about this entry.
|
||||
*
|
||||
* @return true to visit the next entry on the current device, or if the
|
||||
* end of the device has been reached, advance to the next device.
|
||||
* @return false to advance to the next device.
|
||||
*/
|
||||
boolean visitEntry(in string deviceID,
|
||||
in nsICacheEntryInfo entryInfo);
|
||||
};
|
||||
|
||||
|
||||
[scriptable, uuid(31d1c294-1dd2-11b2-be3a-c79230dca297)]
|
||||
interface nsICacheDeviceInfo : nsISupports
|
||||
{
|
||||
/**
|
||||
* Get a human readable description of the cache device.
|
||||
*/
|
||||
readonly attribute string description;
|
||||
|
||||
/**
|
||||
* Get a usage report, statistics, miscellaneous data about
|
||||
* the cache device.
|
||||
*/
|
||||
readonly attribute string usageReport;
|
||||
|
||||
/**
|
||||
* Get the number of stored cache entries.
|
||||
*/
|
||||
readonly attribute unsigned long entryCount;
|
||||
|
||||
/**
|
||||
* Get the total size of the stored cache entries.
|
||||
*/
|
||||
readonly attribute unsigned long totalSize;
|
||||
|
||||
/**
|
||||
* Get the upper limit of the size of the data the cache can store.
|
||||
*/
|
||||
readonly attribute unsigned long maximumSize;
|
||||
};
|
||||
|
||||
|
||||
[scriptable, uuid(72c64022-1dd2-11b2-b3a5-b8b859e0a1b2)]
|
||||
interface nsICacheEntryInfo : nsISupports
|
||||
{
|
||||
/**
|
||||
* Get the client id associated with this cache entry.
|
||||
*/
|
||||
readonly attribute string clientID;
|
||||
|
||||
/**
|
||||
* Get the key identifying the cache entry.
|
||||
*/
|
||||
readonly attribute string key;
|
||||
|
||||
/**
|
||||
* Get the number of times the cache entry has been opened.
|
||||
*/
|
||||
readonly attribute long fetchCount;
|
||||
|
||||
/**
|
||||
* Get the last time the cache entry was opened (in seconds since the Epoch).
|
||||
*/
|
||||
readonly attribute PRUint32 lastFetched;
|
||||
|
||||
/**
|
||||
* Get the last time the cache entry was modified (in seconds since the Epoch).
|
||||
*/
|
||||
readonly attribute PRUint32 lastModified;
|
||||
|
||||
/**
|
||||
* Get the expiration time of the cache entry (in seconds since the Epoch).
|
||||
*/
|
||||
readonly attribute PRUint32 expirationTime;
|
||||
|
||||
/**
|
||||
* Get the cache entry data size.
|
||||
*/
|
||||
readonly attribute unsigned long dataSize;
|
||||
|
||||
/**
|
||||
* Find out whether or not the cache entry is stream based.
|
||||
*/
|
||||
boolean isStreamBased();
|
||||
};
|
||||
240
mozilla/netwerk/cache/public/nsICachedNetData.idl
vendored
Normal file
240
mozilla/netwerk/cache/public/nsICachedNetData.idl
vendored
Normal file
@@ -0,0 +1,240 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsrootidl.idl"
|
||||
#include "nsISupports.idl"
|
||||
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIObserver;
|
||||
interface nsIChannel;
|
||||
interface nsINetDataCache;
|
||||
interface nsINetDataCacheRecord;
|
||||
interface nsILoadGroup;
|
||||
interface nsIStreamListener;
|
||||
|
||||
/**
|
||||
* The nsICachedNetData interface represents a single entry in a database that
|
||||
* caches data retrieved from the network. This interface is implemented by the
|
||||
* cache manager on top of the low-level nsINetDataCacheRecord and
|
||||
* nsINetDataCache interfaces that are implemented by the database.
|
||||
*
|
||||
* Each cache record may contain both content and metadata. The content may
|
||||
* be, for example, GIF image data or HTML, and it is accessed through
|
||||
* nsIChannel's streaming API. The opaque metadata, which may contain HTTP
|
||||
* headers among other things, is stored as a byte array. Each entry in the
|
||||
* cache is indexed by two different keys: a record id number and a key created
|
||||
* by combining the URI with a "secondary key", e.g. HTTP post data.
|
||||
*
|
||||
* @See nsINetDataCacheRecord
|
||||
* @See nsINetDataCache
|
||||
* @See nsINetDataDiskCache
|
||||
* @See nsINetDataCacheManager
|
||||
*/
|
||||
[scriptable, uuid(6aeb2a40-6d43-11d3-90c8-000064657374)]
|
||||
interface nsICachedNetData : nsISupports
|
||||
{
|
||||
/**
|
||||
* String form of the URI provided as an argument to the call to
|
||||
* nsINetDataCacheManager::GetCachedNetData() that created this record.
|
||||
*/
|
||||
readonly attribute string uriSpec;
|
||||
|
||||
/**
|
||||
* Getter for the opaque secondary database key provided as an argument to
|
||||
* the call to nsINetDataCacheManager::GetCachedNetData() that created this
|
||||
* record.
|
||||
*/
|
||||
void getSecondaryKey(out unsigned long length,
|
||||
[retval, size_is(length)] out string secondaryKey);
|
||||
|
||||
/**
|
||||
* This flag may be set by a protocol handler to indicate that it supports
|
||||
* partial fetching of data. In that case, the cache manager is permitted
|
||||
* to truncate the entry's content to accommodate incoming data for other
|
||||
* cache entries rather than deleting it wholesale.
|
||||
*/
|
||||
attribute boolean allowPartial;
|
||||
|
||||
/**
|
||||
* This flag indicates that the write stream supplying content data for the
|
||||
* cache did not complete normally and, therefore, the content may be
|
||||
* truncated.
|
||||
*/
|
||||
readonly attribute boolean partialFlag;
|
||||
|
||||
/**
|
||||
* This flag can be set and cleared by a protocol handler as a form of
|
||||
* self-notification, so as to avoid race conditions in which a protocol
|
||||
* handler issues two identical network requests to fill the same cache
|
||||
* entry. The cache manager itself largely ignores this flag.
|
||||
*/
|
||||
attribute boolean updateInProgress;
|
||||
|
||||
/**
|
||||
* inUse is set if any existing channels are associated with this cache
|
||||
* entry or if the updateInProgess flag is set. This can be used to
|
||||
* prevent writing to a cache entry by a protocol handler if it's being
|
||||
* read or written elsewhere.
|
||||
*/
|
||||
readonly attribute boolean inUse;
|
||||
|
||||
/**
|
||||
* Date/time that the document was last stored on the origin server, as
|
||||
* supplied by the protocol handler. This value is used as input to the
|
||||
* cache replacement policy, i.e. it is not used for validation. If the
|
||||
* protocol can't supply a last-modified time, this attribute should remain
|
||||
* unset. When unset, the value of this attribute is zero.
|
||||
*
|
||||
* FIXME: Should use nsIDateTime interface, once it's created
|
||||
* instead of PRTime, for improved scriptability ?
|
||||
*/
|
||||
attribute PRTime lastModifiedTime;
|
||||
|
||||
/**
|
||||
* Supplied by the protocol handler, the expirationTime attribute specifies
|
||||
* the time until which the document is guaranteed fresh, i.e. the document
|
||||
* does not have to be validated with the server and, therefore, any data
|
||||
* in cache is definitely usable. The value of this attribute serves as a
|
||||
* hint to the cache replacement policy. Only one of either staleTime or
|
||||
* expirationTime may be set for a single cache record. When unset, the
|
||||
* value of this attribute is zero.
|
||||
*/
|
||||
attribute PRTime expirationTime;
|
||||
|
||||
/**
|
||||
* Date/time supplied by the protocol handler, at which point the content
|
||||
* is *likely* to be stale, i.e. the data in the cache may be out-of-date
|
||||
* with respect to the data on the server. This heuristic date does not
|
||||
* necessarily correspond to the HTTP Expires header, as it does not
|
||||
* determine when cached network data must be validated with the origin
|
||||
* server, but only serves as a hint to the cache replacement policy. Only
|
||||
* one of either staleTime or expirationTime may be set for a single cache
|
||||
* record. When unset, the value of this attribute is zero.
|
||||
*/
|
||||
attribute PRTime staleTime;
|
||||
|
||||
/**
|
||||
* Date/time of last access of the data in this cache record, as determined
|
||||
* by the cache manager.
|
||||
*/
|
||||
readonly attribute PRTime lastAccessTime;
|
||||
|
||||
readonly attribute PRTime lastUpdateTime;
|
||||
|
||||
/**
|
||||
* Number of times this record has been accessed since it was first stored.
|
||||
*/
|
||||
readonly attribute PRUint16 numberAccesses;
|
||||
|
||||
/**
|
||||
* Accessor methods for opaque meta-data which can be read and updated
|
||||
* independently of the content data.
|
||||
*
|
||||
* The aTag argument can be used to accommodate multiple clients of the
|
||||
* cache API, each of which wants to store its own private meta-data into
|
||||
* the cache. For example, there could be a "headers" tag that the HTTP
|
||||
* protocol handler uses to store http response headers and a "image size"
|
||||
* tag used to store the image dimensions of a GIF file. The aData
|
||||
* argument refers to an opaque blob of arbitrary bytes.
|
||||
*
|
||||
* IMPORTANT: If aData does not contain byte-oriented data, i.e. it's not a
|
||||
* string, the contents of aData must be byte-swapped by the,
|
||||
* caller, so as to make the cache files endian-independent.
|
||||
*/
|
||||
void getAnnotation(in string aTag,
|
||||
out PRUint32 aLength, [size_is(aLength), retval] out string aData);
|
||||
void setAnnotation(in string aTag,
|
||||
in PRUint32 aLength, [size_is(aLength)] in string aData);
|
||||
|
||||
/**
|
||||
* As a getter, return the number of content bytes stored in the cache,
|
||||
* i.e. via the nsIChannel streaming APIs. This may be less than the
|
||||
* complete content length if a partial cache fill occurred. The cached
|
||||
* content can be truncated by setting the value of this attribute. The
|
||||
* value of the attribute represents a logical, not a physical, length. If
|
||||
* compression has been used, the content may consume less storage than
|
||||
* indicated by this attribute.
|
||||
*
|
||||
* When this attribute is set to zero the associated cache disk file, if
|
||||
* any, should be deleted.
|
||||
*/
|
||||
attribute PRUint32 storedContentLength;
|
||||
|
||||
/**
|
||||
* Length of stored content, which may be less than storage consumed if
|
||||
* compression is used
|
||||
*/
|
||||
readonly attribute PRUint32 logicalLength;
|
||||
|
||||
/**
|
||||
* Opaque security info associated with the cache entry; it can't be serialized
|
||||
* to disk, so it'll only make sense with memory cache
|
||||
*/
|
||||
attribute nsISupports securityInfo;
|
||||
|
||||
/**
|
||||
* Notify any observers associated with this cache entry of the deletion
|
||||
* request. If all observers drop their reference to the cache entry,
|
||||
* proceed to delete the underlying cache database record and associated
|
||||
* content storage.
|
||||
*/
|
||||
void delete();
|
||||
|
||||
/**
|
||||
* Flush any changes in this entry's data to the cache database. This
|
||||
* method will automatically be called when the last reference to the cache
|
||||
* is dropped, but it can also be called explicitly for a synchronous
|
||||
* effect.
|
||||
*/
|
||||
void commit();
|
||||
|
||||
/**
|
||||
* Parent container cache for this entry.
|
||||
*/
|
||||
readonly attribute nsINetDataCache cache;
|
||||
|
||||
/**
|
||||
* Create a channel for reading or writing a stream of content into the
|
||||
* entry. It is expected that many of the nsIChannel methods return
|
||||
* NS_NOT_IMPLEMENTED, including:
|
||||
*
|
||||
* + GetURI()
|
||||
* + GetContentType()
|
||||
* + GetContentLength()
|
||||
*
|
||||
* Though nsIChannel provides for both async and synchronous I/O APIs, both
|
||||
* may not be implemented. Only AsyncRead() and OpenOutputStream() is
|
||||
* required.
|
||||
*/
|
||||
nsIChannel newChannel(in nsILoadGroup aLoadGroup);
|
||||
|
||||
/**
|
||||
* This method can be used by a caching protocol handler to store data in
|
||||
* the cache by forking an asynchronous read stream so that it is
|
||||
* simultaneously sent to a requester and written into the cache. This
|
||||
* method implicitly sets the updateInProgress flag, if it has not already
|
||||
* been set.
|
||||
*/
|
||||
nsIStreamListener interceptAsyncRead(in nsIStreamListener aOriginalListener,
|
||||
in PRUint32 aStartOffset);
|
||||
};
|
||||
142
mozilla/netwerk/cache/public/nsINetDataCache.idl
vendored
Normal file
142
mozilla/netwerk/cache/public/nsINetDataCache.idl
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface nsINetDataCacheRecord;
|
||||
interface nsISimpleEnumerator;
|
||||
|
||||
/**
|
||||
* The nsINetDataCache defines the low-level API for a network-data
|
||||
* cache, used to cache the responses to network retrieval commands.
|
||||
* This interface, along with nsINetDataCacheRecord, is implemented by
|
||||
* the memory cache, the file cache and, optionally, by some extension
|
||||
* caches. This interface is essentially a pseudo-private API for the
|
||||
* cache manager. Other clients should never use this interface.
|
||||
*
|
||||
* Each cache entry may contain both content, e.g. GIF image data, and
|
||||
* associated metadata, e.g. HTTP headers. Each entry is indexed by two
|
||||
* different keys: a record id number and a key created by combining the URI
|
||||
* with a "secondary key", e.g. HTTP post data.
|
||||
*
|
||||
* The nsINetDataCache interface is agnostic as to where the data is
|
||||
* stored and whether the storage is volatile or persistent. The
|
||||
* memory cache, any disk caches and any extension caches must all
|
||||
* implement this interface.
|
||||
*
|
||||
*/
|
||||
[scriptable, uuid(ccfc58c0-6dde-11d3-90c8-000064657374)]
|
||||
interface nsINetDataCache : nsISupports
|
||||
{
|
||||
/**
|
||||
* Human-readable description of the cache module, e.g. "Disk Cache"
|
||||
*/
|
||||
readonly attribute wstring description;
|
||||
|
||||
/**
|
||||
* Returns true if cached data is available for the given opaque key,
|
||||
* even if only partial data is stored.
|
||||
*/
|
||||
boolean contains([size_is(length)] in string key, in PRUint32 length);
|
||||
|
||||
/**
|
||||
* Fetch the cache entry record for the given opaque key. If one does not
|
||||
* exist, create a new, empty record.
|
||||
*/
|
||||
nsINetDataCacheRecord getCachedNetData([size_is(length)] in string key,
|
||||
in PRUint32 length);
|
||||
|
||||
/**
|
||||
* Fetch the cache entry record for the given URI using the record ID as a key.
|
||||
*/
|
||||
nsINetDataCacheRecord getCachedNetDataByID(in PRInt32 RecordID);
|
||||
|
||||
/**
|
||||
* False indicates that this cache is entirely bypassed.
|
||||
*/
|
||||
attribute boolean enabled;
|
||||
|
||||
/**
|
||||
* Constants for flags attribute, below
|
||||
*/
|
||||
|
||||
// Used for extension caches, e.g. a CD-ROM cache
|
||||
const long READ_ONLY = 1 << 0;
|
||||
|
||||
// One of these bits must be set
|
||||
const long MEMORY_CACHE = 1 << 1;
|
||||
const long FLAT_FILE_CACHE = 1 << 2;
|
||||
const long FILE_PER_URL_CACHE = 1 << 3;
|
||||
|
||||
/**
|
||||
* See constants defined above.
|
||||
*/
|
||||
readonly attribute PRUint32 flags;
|
||||
|
||||
/**
|
||||
* Total number of URI entries stored in the cache.
|
||||
*/
|
||||
readonly attribute PRUint32 numEntries;
|
||||
|
||||
/**
|
||||
* Maximum number of URI entries that may be stored in the cache.
|
||||
*/
|
||||
readonly attribute PRUint32 maxEntries;
|
||||
|
||||
/**
|
||||
* Enumerate the URI entries stored in the cache.
|
||||
*/
|
||||
nsISimpleEnumerator newCacheEntryIterator();
|
||||
|
||||
/**
|
||||
* Contains a reference to the next cache in search order. For the memory
|
||||
* cache, this attribute always references the disk cache. For the disk
|
||||
* cache, it contains a reference to the first extension cache.
|
||||
*/
|
||||
attribute nsINetDataCache nextCache;
|
||||
|
||||
/**
|
||||
* An estimate of the amount of storage occupied by the cache, in kB.
|
||||
* Actual use may be slightly higher than reported due to cache overhead
|
||||
* and heap fragmentation (in the memory cache) or block quantization (in
|
||||
* the disk cache).
|
||||
*/
|
||||
readonly attribute PRUint32 storageInUse;
|
||||
|
||||
/**
|
||||
* Remove all entries from a writable cache. This could be used, for
|
||||
* example, after a guest ends a browser session. This is equivalent to
|
||||
* setting the cache's Capacity to zero, except that all cache entries,
|
||||
* even those in active use, will be deleted. Also, any global cache
|
||||
* database files will be deleted.
|
||||
*/
|
||||
void removeAll();
|
||||
};
|
||||
|
||||
%{ C++
|
||||
// ContractID prefix for Components that implement this interface
|
||||
#define NS_NETWORK_CACHE_CONTRACTID "@mozilla.org/network/cache;1"
|
||||
#define NS_NETWORK_MEMORY_CACHE_CONTRACTID NS_NETWORK_CACHE_CONTRACTID "?name=memory-cache"
|
||||
#define NS_NETWORK_FLAT_CACHE_CONTRACTID NS_NETWORK_CACHE_CONTRACTID "?name=flat-cache"
|
||||
#define NS_NETWORK_FILE_CACHE_CONTRACTID NS_NETWORK_CACHE_CONTRACTID "?name=file-cache"
|
||||
%}
|
||||
169
mozilla/netwerk/cache/public/nsINetDataCacheManager.idl
vendored
Normal file
169
mozilla/netwerk/cache/public/nsINetDataCacheManager.idl
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsINetDataCache.idl"
|
||||
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsICachedNetData;
|
||||
interface nsINetDataDiskCache;
|
||||
interface nsIURI;
|
||||
|
||||
/**
|
||||
* The network-response cache manager is partly responsible for the caching of
|
||||
* content and associated metadata that has been retrieved via the network.
|
||||
* (The remaining responsibility for caching lies with individual network
|
||||
* protocol handlers.)
|
||||
*
|
||||
* The cache manager supervises the actions of individual cache components,
|
||||
* such as the memory cache, the disk cache and any extension caches, e.g. a
|
||||
* read-only CD-ROM cache.
|
||||
*
|
||||
* @See nsINetDataCache
|
||||
* @See nsICachedNetData
|
||||
*/
|
||||
[scriptable, uuid(71c8ab00-6d5c-11d3-90c8-000064657374)]
|
||||
interface nsINetDataCacheManager : nsISupports
|
||||
{
|
||||
/**
|
||||
* Flag for the GetCachedNetData() method: If set, the memory cache is
|
||||
* neither searched nor will any data be stored into it. This might be
|
||||
* appropriate, for example, with images, because they have their own
|
||||
* cache for storing *decoded* images.
|
||||
*/
|
||||
const unsigned long BYPASS_MEMORY_CACHE = 1 << 0;
|
||||
|
||||
/**
|
||||
* Flag for the GetCachedNetData() method: If set, the disk cache
|
||||
* is neither searched nor will any be data stored into it.
|
||||
* However, read-only extension caches may be searched. This
|
||||
* might be used to avoid leaving persistent records of secure
|
||||
* data.
|
||||
*/
|
||||
const unsigned long BYPASS_PERSISTENT_CACHE = 1 << 1;
|
||||
|
||||
/**
|
||||
* Flag for the GetCachedNetData() method: If set, any stream
|
||||
* content is stored in the cache as a single disk file. Content
|
||||
* will not be cached in the memory cache nor is it cached in a
|
||||
* flat-file cache database. This is used to implement the jar
|
||||
* protocol handler and to provide the stream-as-file semantics
|
||||
* required by the classic bowser plugin API.
|
||||
*/
|
||||
const unsigned long CACHE_AS_FILE = 1 << 2;
|
||||
|
||||
/**
|
||||
These enum's are used for the ClearCache calls.
|
||||
*/
|
||||
const unsigned long ALL_CACHES = 1;
|
||||
const unsigned long MEM_CACHE = 1<<1;
|
||||
const unsigned long FILE_CACHE = 1<<2;
|
||||
const unsigned long FLAT_CACHE = 1<<3;
|
||||
/**
|
||||
* Fetch the cache entry record for the given URI. If one does not exist,
|
||||
* create a new, empty record. The normal search order for caches is:
|
||||
* + Memory cache
|
||||
* + Disk cache
|
||||
* + File cache (stream-as-file cache)
|
||||
* + All extension caches
|
||||
*
|
||||
* When writing, data is typically stored in both the memory cache and the
|
||||
* disk cache. Both the search order and this write policy can be modified by
|
||||
* setting one or more of the flag argument bits, as defined above.
|
||||
*
|
||||
* The optionally-NULL secondaryKey argument can be used, e.g. for form
|
||||
* post data or for HTTP headers in the case of HTTP.
|
||||
*/
|
||||
nsICachedNetData getCachedNetData(in string uri,
|
||||
[size_is(secondaryKeyLength)] in string secondaryKey,
|
||||
in PRUint32 secondaryKeyLength,
|
||||
in PRUint32 flags);
|
||||
|
||||
/**
|
||||
* Returns true if cached content is available for the given URI, even if
|
||||
* only partial data is stored. The flags argument behaves the same as for
|
||||
* the GetCachedNetData() method, above.
|
||||
*/
|
||||
boolean contains(in string uri,
|
||||
[size_is(secondaryKeyLength)] in string secondaryKey,
|
||||
in PRUint32 secondaryKeyLength,
|
||||
in PRUint32 flags);
|
||||
|
||||
/**
|
||||
* Total number of unexpired URI entries stored in all caches. This number
|
||||
* does not take into account duplicate URIs, e.g. because the memory cache
|
||||
* and the disk cache might each contain an entry for the same URI.
|
||||
*/
|
||||
readonly attribute PRUint32 numEntries;
|
||||
|
||||
/**
|
||||
* Enumerate the unexpired URI entries stored in all caches. Some URIs may
|
||||
* be enumerated more than once, e.g. because the the memory cache and the
|
||||
* disk cache might each contain an entry for the same URI.
|
||||
*/
|
||||
nsISimpleEnumerator newCacheEntryIterator();
|
||||
|
||||
/*
|
||||
* Enumerate all the loaded nsINetDataCache-implementing cache modules.
|
||||
* The first module enumerated will be the memory cache, the second will be
|
||||
* the disk cache, then the file cache, followed by all the extension
|
||||
* caches, in search order.
|
||||
*/
|
||||
nsISimpleEnumerator newCacheModuleIterator();
|
||||
|
||||
/**
|
||||
* Remove all entries from all writable caches. This could be used, for
|
||||
* example, after a guest ends a browser session. This is equivalent to
|
||||
* setting the DiskCacheCapacity to zero, except that all cache entries,
|
||||
* even those in active use, will be deleted. Also, any global cache
|
||||
* database files will be deleted.
|
||||
*/
|
||||
void removeAll();
|
||||
|
||||
/**
|
||||
* Clears the specified cache
|
||||
*/
|
||||
void clear( in PRUint32 aCacheToClear );
|
||||
|
||||
/**
|
||||
* The disk cache is made up of the file cache (for stream-as-file
|
||||
* requests) and a (possibly independent) persistent cache that handles all
|
||||
* other cache requests. This attribute sets/gets the combined capacity of
|
||||
* these caches, measured in KBytes. Setting the capacity lower than the
|
||||
* current amount of space currently in use may cause cache entries to be
|
||||
* evicted from the cache to accomodate the requested capacity.
|
||||
*/
|
||||
attribute PRUint32 diskCacheCapacity;
|
||||
|
||||
/**
|
||||
* This attribute sets/gets the capacity of the memory cache, measured in
|
||||
* KBytes. Setting the capacity lower than the current amount of space
|
||||
* currently in use may cause cache entries to be evicted from the cache to
|
||||
* accomodate the requested capacity.
|
||||
*/
|
||||
attribute PRUint32 memCacheCapacity;
|
||||
};
|
||||
|
||||
%{ C++
|
||||
// ContractID prefix for Components that implement this interface
|
||||
#define NS_NETWORK_CACHE_MANAGER_CONTRACTID NS_NETWORK_CACHE_CONTRACTID "?name=manager"
|
||||
%}
|
||||
131
mozilla/netwerk/cache/public/nsINetDataCacheRecord.idl
vendored
Normal file
131
mozilla/netwerk/cache/public/nsINetDataCacheRecord.idl
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsrootidl.idl"
|
||||
|
||||
interface nsIFile;
|
||||
interface nsIChannel;
|
||||
interface nsINetDataCache;
|
||||
|
||||
/**
|
||||
* The nsINetDataCacheRecord represents a single entry in a database that
|
||||
* caches data retrieved from the network. On top of this low-level interface
|
||||
* to the raw record data, the cache manager implements a higher-level record
|
||||
* interface, nsICachedNetData. Each instance of nsINetDataCacheRecord is
|
||||
* (internally) associated with a parent database, an instance of the
|
||||
* nsINetDataCache interface. This interface is essentially a pseudo-private
|
||||
* API for the cache manager. Other clients should never use this interface.
|
||||
*
|
||||
* Each cache record may contain both content and metadata. The content may
|
||||
* be, for example, GIF image data or HTML, and it is accessed through
|
||||
* nsIChannel's streaming API. The opaque metadata, which may contain HTTP
|
||||
* headers among other things, is accessed as a contiguous byte array. Each
|
||||
* entry in the cache is indexed by two different keys: a unique record id
|
||||
* number, generated by the cache, and an opaque string. The latter contains
|
||||
* the URI and other secondary key information, e.g. HTTP form post key/value
|
||||
* pairs.
|
||||
*
|
||||
* The nsINetDataCacheRecord interface is agnostic as to where the data is
|
||||
* stored and whether the storage is volatile or persistent. The memory cache,
|
||||
* the disk cache, a flat-file cache and any read-only extension caches must
|
||||
* all implement this interface.
|
||||
*
|
||||
* @See nsICachedNetData
|
||||
* @See nsINetDataCache
|
||||
* @See nsINetDataDiskCache
|
||||
* @See nsINetDataCacheManager
|
||||
*/
|
||||
|
||||
interface nsILoadGroup;
|
||||
|
||||
[scriptable, uuid(fdcdd6a0-7461-11d3-90ca-0040056a906e)]
|
||||
interface nsINetDataCacheRecord : nsISupports
|
||||
{
|
||||
/**
|
||||
* As far as the nsINetDataCacheRecord implementation is concerned, the
|
||||
* cache entry database key is an opaque blob, but it's intended to contain
|
||||
* both the URI and any secondary keys, such as HTTP post data.
|
||||
*/
|
||||
void getKey(out unsigned long length, [size_is(length), retval] out string key);
|
||||
|
||||
/**
|
||||
* A persistent record number assigned by the cache which must be unique
|
||||
* among all entries stored within the same cache. The record ID serves as
|
||||
* an alternate key to the cache record. Providing that they satisfy the
|
||||
* afforementioned uniqueness requirement, record IDs can be assigned any
|
||||
* value by the database except that they may never be zero.
|
||||
*/
|
||||
readonly attribute PRInt32 recordID;
|
||||
|
||||
/**
|
||||
* Opaque data which can be updated for each cache entry independently of
|
||||
* the content data. This data is a combination of protocol-independent
|
||||
* data provided by the cache manager and protocol-specific meta-data,
|
||||
* e.g. HTTP headers.
|
||||
*/
|
||||
void getMetaData(out PRUint32 length, [size_is(length), retval] out string metaData);
|
||||
void setMetaData(in PRUint32 length, [size_is(length)] in string data);
|
||||
|
||||
/**
|
||||
* Number of content bytes stored in the cache, i.e. via the nsIChannel
|
||||
* streaming APIs. This may be less than the complete content length if a
|
||||
* partial cache fill occurred. Additionally, the cached content can be
|
||||
* truncated by reducing the value of this attribute. When this attribute
|
||||
* is set to zero the associated cache disk file, if any, should be
|
||||
* deleted.
|
||||
*/
|
||||
attribute PRUint32 storedContentLength;
|
||||
|
||||
/**
|
||||
* Opaque security info associated with the cache entry; it can't be serialized
|
||||
* to disk, so it'll only make sense with memory cache
|
||||
*/
|
||||
attribute nsISupports securityInfo;
|
||||
|
||||
/**
|
||||
* Delete this cache entry and its associated content.
|
||||
*/
|
||||
void delete();
|
||||
|
||||
/**
|
||||
* Create a channel for reading or writing a stream of content into the
|
||||
* entry. However, many of the nsIChannel methods may return
|
||||
* NS_NOT_IMPLEMENTED, including:
|
||||
*
|
||||
* + GetURI()
|
||||
* + GetContentType()
|
||||
* + GetContentLength()
|
||||
*/
|
||||
nsIChannel newChannel(in nsILoadGroup loadGroup);
|
||||
|
||||
/**
|
||||
* If a cache is implemented such that it stores each URI's content in an
|
||||
* individual disk file, this method will identify the file corresponding
|
||||
* to this record. This may be used to implement the "stream-as-file"
|
||||
* semantics required by some plugins and by the 'jar:' protocol handler.
|
||||
* However, not all cache implementations are *required* to store the data
|
||||
* from each URI in an individual file, so it is acceptable for an
|
||||
* implementation of this method to signal NS_NOT_IMPLEMENTED.
|
||||
*/
|
||||
readonly attribute nsIFile file;
|
||||
};
|
||||
41
mozilla/netwerk/cache/public/nsINetDataDiskCache.idl
vendored
Normal file
41
mozilla/netwerk/cache/public/nsINetDataDiskCache.idl
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsINetDataCache.idl"
|
||||
|
||||
interface nsIFile;
|
||||
|
||||
/**
|
||||
* A network-data disk cache is used to persistently cache the responses to
|
||||
* network retrieval commands. Each cache entry may contain both content,
|
||||
* e.g. GIF image data, and associated metadata, e.g. HTTP headers.
|
||||
*/
|
||||
[scriptable, uuid(6408e390-6f13-11d3-90c8-000064657374)]
|
||||
interface nsINetDataDiskCache : nsINetDataCache
|
||||
{
|
||||
/**
|
||||
* This attribute must be set before calling any other methods of this
|
||||
* interface.
|
||||
*/
|
||||
attribute nsIFile diskCacheFolder;
|
||||
};
|
||||
|
||||
106
mozilla/netwerk/cache/public/nsIStreamAsFile.idl
vendored
Normal file
106
mozilla/netwerk/cache/public/nsIStreamAsFile.idl
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code, released
|
||||
* March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Scott Furman, fur@netscape.com
|
||||
*/
|
||||
#include "nsrootidl.idl"
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIFile;
|
||||
interface nsIStreamAsFileObserver;
|
||||
|
||||
/**
|
||||
* In addition to enhancing effective network response time via caching, the
|
||||
* cache manager serves a second purpose by providing the stream-as-file
|
||||
* service required by traditional browser plugins and the jar: protocol
|
||||
* handler. The interface below provides a means for a client to determine the
|
||||
* filename associated with a stream and to detect modification/deletion of
|
||||
* that file.
|
||||
*/
|
||||
[scriptable, uuid(0eedbbf0-92d9-11d3-90d3-0040056a906e)]
|
||||
interface nsIStreamAsFile : nsISupports
|
||||
{
|
||||
/**
|
||||
* Filename containing stream-as-file
|
||||
*/
|
||||
readonly attribute nsIFile file;
|
||||
|
||||
/**
|
||||
* Add an observer for this cache record. When the cache wants to delete
|
||||
* or truncate a record, so as to make space for another cache entry's
|
||||
* content data, it will call <code>aObserver</code>'s Observe() method,
|
||||
* passing the nsIStreamAsFile instance as the <code>aSubject</code>
|
||||
* argument and an appropriate message. If the observer does not wish to
|
||||
* inhibit deletion/truncation, it should Release() any references it has to the
|
||||
* cache record.
|
||||
*
|
||||
* @See nsIStreamAsFileObserver
|
||||
*/
|
||||
void addObserver(in nsIStreamAsFileObserver aObserver);
|
||||
|
||||
/**
|
||||
* Delete an observer that was added by the AddObserver() method.
|
||||
*/
|
||||
void removeObserver(in nsIStreamAsFileObserver aObserver);
|
||||
};
|
||||
|
||||
/**
|
||||
* This interface can be implemented by a client to receive notifications of
|
||||
* either modification or deletion of a file created by the cache manager using
|
||||
* the stream-as-file semantics.
|
||||
*/
|
||||
[scriptable, uuid(a26e27c0-92da-11d3-90d3-0040056a906e)]
|
||||
interface nsIStreamAsFileObserver : nsISupports
|
||||
{
|
||||
/**
|
||||
* Flag bits for argument to observeStreamAsFile() method.
|
||||
*/
|
||||
const long NOTIFY_AVAILABLE = 1 << 0; // Stream-as-file now available for reading
|
||||
const long NOTIFY_ERROR = 1 << 1; // Error while loading stream / creating file
|
||||
const long REQUEST_DELETION = 1 << 2; // Cache manager wishes to delete/truncate file
|
||||
const long INVALIDATE = 1 << 3; // File is out-of-date
|
||||
|
||||
// Convenience value
|
||||
const long MAKE_UNAVAILABLE = REQUEST_DELETION | INVALIDATE;
|
||||
|
||||
/**
|
||||
* Receive either a notification or a request concerning a file that has
|
||||
* been opened using stream-as-file. The aMessage and aError arguments
|
||||
* have varying values depending on the nature of the notification.
|
||||
* aMessage is set to NOTIFY_AVAILABLE when a complete stream has been read
|
||||
* and stored on disk in a file. At that point, and no sooner, may the
|
||||
* filename attribute of the associated nsIStreamAsFile be accessed via the
|
||||
* associated nsIStreamAsFile interface. If the aMessage argument is
|
||||
* NOTIFY_ERROR, the aError argument contains the relevant error code. If
|
||||
* the aMessage argument is either REQUEST_DELETION or REQUEST_TRUNCATION,
|
||||
* the callee should immediately Release() all references to the
|
||||
* nsIStreamAsFile (and any references to its associated nsICachedNetData
|
||||
* instances), unless it wishes to inhibit the requested file modification.
|
||||
* If the aMessage argument is INVALIDATE, the cache manager is replacing
|
||||
* the file with a more recent version. If a client wants to continue
|
||||
* using the (now out-of-date) file, it must delete it when it has finished,
|
||||
* as the cache manager will effectively relinquished ownership of the
|
||||
* file.
|
||||
*/
|
||||
void observeStreamAsFile(in nsIStreamAsFile aStreamAsFile,
|
||||
in PRUint32 aMessage,
|
||||
in nsresult aError);
|
||||
};
|
||||
70
mozilla/netwerk/cache/src/Makefile.in
vendored
Normal file
70
mozilla/netwerk/cache/src/Makefile.in
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = nkcache
|
||||
LIBRARY_NAME = nkcache
|
||||
SHORT_LIBNAME = nkcache
|
||||
IS_COMPONENT = 1
|
||||
REQUIRES = xpcom string necko pref
|
||||
|
||||
EXPORTS = \
|
||||
nsCacheService.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsANSIFileStreams.cpp \
|
||||
nsCache.cpp \
|
||||
nsCacheEntry.cpp \
|
||||
nsCacheEntryDescriptor.cpp \
|
||||
nsCacheMetaData.cpp \
|
||||
nsCacheModule.cpp \
|
||||
nsCacheService.cpp \
|
||||
nsCacheSession.cpp \
|
||||
nsDiskCacheDevice.cpp \
|
||||
nsDiskCacheEntry.cpp \
|
||||
nsDiskCacheMap.cpp \
|
||||
nsMemoryCacheDevice.cpp \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
EXTRA_LIBS += \
|
||||
$(XPCOM_LIBS) \
|
||||
$(NSPR_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
#EXTRA_LIBS = $(NSPR_LIBS)
|
||||
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a
|
||||
# static lib.
|
||||
#override NO_SHARED_LIB=1
|
||||
#override NO_STATIC_LIB=
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
68
mozilla/netwerk/cache/src/makefile.win
vendored
Executable file
68
mozilla/netwerk/cache/src/makefile.win
vendored
Executable file
@@ -0,0 +1,68 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
MODULE = nkcache
|
||||
DLLNAME=nkcache
|
||||
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
MAKE_OBJ_TYPE=DLL
|
||||
|
||||
LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET
|
||||
|
||||
EXPORTS = \
|
||||
nsCacheService.h \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsCache.obj \
|
||||
.\$(OBJDIR)\nsCacheEntry.obj \
|
||||
.\$(OBJDIR)\nsCacheEntryDescriptor.obj \
|
||||
.\$(OBJDIR)\nsCacheMetaData.obj \
|
||||
.\$(OBJDIR)\nsCacheModule.obj \
|
||||
.\$(OBJDIR)\nsCacheService.obj \
|
||||
.\$(OBJDIR)\nsCacheSession.obj \
|
||||
.\$(OBJDIR)\nsDiskCacheDevice.obj \
|
||||
.\$(OBJDIR)\nsDiskCacheEntry.obj \
|
||||
.\$(OBJDIR)\nsDiskCacheMap.obj \
|
||||
.\$(OBJDIR)\nsANSIFileStreams.obj \
|
||||
.\$(OBJDIR)\nsMemoryCacheDevice.obj \
|
||||
$(NULL)
|
||||
|
||||
|
||||
LLIBS = \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
|
||||
clobber::
|
||||
$(RM) $(DIST)\bin\components\$(DLLNAME).dll
|
||||
$(RM) $(DIST)\lib\$(DLLNAME).lib
|
||||
206
mozilla/netwerk/cache/src/nsANSIFileStreams.cpp
vendored
Normal file
206
mozilla/netwerk/cache/src/nsANSIFileStreams.cpp
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsANSIFileStreams.cpp, released March 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsANSIFileStreams.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsANSIInputStream, nsIInputStream, nsISeekableStream);
|
||||
|
||||
nsANSIInputStream::nsANSIInputStream(FILE* file) : mFile(file), mSize(0)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
if (file) {
|
||||
::fseek(file, 0, SEEK_END);
|
||||
mSize = ::ftell(file);
|
||||
::fseek(file, 0, SEEK_SET);
|
||||
}
|
||||
}
|
||||
|
||||
nsANSIInputStream::~nsANSIInputStream()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Close()
|
||||
{
|
||||
if (mFile) {
|
||||
::fclose(mFile);
|
||||
mFile = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Available(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = (mSize - ::ftell(mFile));
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Read(char * buf, PRUint32 count, PRUint32 *result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::fread(buf, 1, count, mFile);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::GetNonBlocking(PRBool *aNonBlocking)
|
||||
{
|
||||
*aNonBlocking = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::GetObserver(nsIInputStreamObserver * *aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::SetObserver(nsIInputStreamObserver * aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Seek(PRInt32 whence, PRInt32 offset)
|
||||
{
|
||||
if (mFile) {
|
||||
::fseek(mFile, offset, whence);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Tell(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::ftell(mFile);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsANSIOutputStream, nsIOutputStream, nsISeekableStream);
|
||||
|
||||
nsANSIOutputStream::nsANSIOutputStream(FILE* file) : mFile(file)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsANSIOutputStream::~nsANSIOutputStream()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Close()
|
||||
{
|
||||
if (mFile) {
|
||||
::fclose(mFile);
|
||||
mFile = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Flush()
|
||||
{
|
||||
if (mFile) {
|
||||
::fflush(mFile);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Write(const char *buffer, PRUint32 count, PRUint32 *result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::fwrite(buffer, 1, count, mFile);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::WriteFrom(nsIInputStream *input, PRUint32 count, PRUint32 *actualCount)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
PRUint32 totalCount = count;
|
||||
*actualCount = 0;
|
||||
while (totalCount > 0) {
|
||||
count = (totalCount < BUFSIZ ? totalCount : BUFSIZ);
|
||||
nsresult rv = input->Read(buffer, count, &count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = Write(buffer, count, &count);
|
||||
totalCount -= count;
|
||||
*actualCount += count;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::GetNonBlocking(PRBool *aNonBlocking)
|
||||
{
|
||||
*aNonBlocking = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsANSIOutputStream::SetNonBlocking(PRBool aNonBlocking)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::GetObserver(nsIOutputStreamObserver * *aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHODIMP nsANSIOutputStream::SetObserver(nsIOutputStreamObserver * aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Seek(PRInt32 whence, PRInt32 offset)
|
||||
{
|
||||
if (mFile) {
|
||||
::fseek(mFile, offset, whence);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Tell(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::ftell(mFile);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
54
mozilla/netwerk/cache/src/nsANSIFileStreams.h
vendored
Normal file
54
mozilla/netwerk/cache/src/nsANSIFileStreams.h
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsANSIFileStreams.h, released March 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsANSIFileStreams_h_
|
||||
#define _nsANSIFileStreams_h_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nsIFileStreams.h"
|
||||
|
||||
class nsANSIInputStream : public nsIInputStream, public nsISeekableStream {
|
||||
FILE* mFile;
|
||||
PRUint32 mSize;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIINPUTSTREAM
|
||||
NS_DECL_NSISEEKABLESTREAM
|
||||
|
||||
nsANSIInputStream(FILE* file);
|
||||
virtual ~nsANSIInputStream();
|
||||
};
|
||||
|
||||
class nsANSIOutputStream : public nsIOutputStream, public nsISeekableStream {
|
||||
FILE* mFile;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOUTPUTSTREAM
|
||||
NS_DECL_NSISEEKABLESTREAM
|
||||
|
||||
nsANSIOutputStream(FILE* file);
|
||||
virtual ~nsANSIOutputStream();
|
||||
};
|
||||
|
||||
#endif // _nsANSIFileStreams_h_
|
||||
131
mozilla/netwerk/cache/src/nsCache.cpp
vendored
Normal file
131
mozilla/netwerk/cache/src/nsCache.cpp
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCache.cpp, released March 18, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsCache.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
/**
|
||||
* Cache Service Utility Functions
|
||||
*/
|
||||
|
||||
#if 0
|
||||
// time conversion utils from nsCachedNetData.cpp
|
||||
// Convert PRTime to unix-style time_t, i.e. seconds since the epoch
|
||||
PRUint32
|
||||
ConvertPRTimeToSeconds(PRTime time64)
|
||||
{
|
||||
double fpTime;
|
||||
LL_L2D(fpTime, time64);
|
||||
return (PRUint32)(fpTime * 1e-6 + 0.5);
|
||||
}
|
||||
|
||||
|
||||
// Convert unix-style time_t, i.e. seconds since the epoch, to PRTime
|
||||
PRTime
|
||||
ConvertSecondsToPRTime(PRUint32 seconds)
|
||||
{
|
||||
PRInt64 t64;
|
||||
LL_I2L(t64, seconds);
|
||||
PRInt64 mil;
|
||||
LL_I2L(mil, 1000000);
|
||||
LL_MUL(t64, t64, mil);
|
||||
return t64;
|
||||
}
|
||||
#endif
|
||||
|
||||
PRUint32
|
||||
SecondsFromPRTime(PRTime prTime)
|
||||
{
|
||||
PRInt64 microSecondsPerSecond, intermediateResult;
|
||||
PRUint32 seconds;
|
||||
|
||||
LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC);
|
||||
LL_DIV(intermediateResult, prTime, microSecondsPerSecond);
|
||||
LL_L2UI(seconds, intermediateResult);
|
||||
return seconds;
|
||||
}
|
||||
|
||||
|
||||
PRTime
|
||||
PRTimeFromSeconds(PRUint32 seconds)
|
||||
{
|
||||
PRInt64 microSecondsPerSecond, intermediateResult;
|
||||
PRTime prTime;
|
||||
|
||||
LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC);
|
||||
LL_UI2L(intermediateResult, seconds);
|
||||
LL_MUL(prTime, intermediateResult, microSecondsPerSecond);
|
||||
return prTime;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
ClientIDFromCacheKey(const nsAReadableCString& key, char ** result)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
*result = nsnull;
|
||||
|
||||
nsReadingIterator<char> colon;
|
||||
key.BeginReading(colon);
|
||||
|
||||
nsReadingIterator<char> start;
|
||||
key.BeginReading(start);
|
||||
|
||||
nsReadingIterator<char> end;
|
||||
key.EndReading(end);
|
||||
|
||||
if (FindCharInReadable(':', colon, end)) {
|
||||
*result = ToNewCString( Substring(start, colon));
|
||||
if (!*result) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "FindCharInRead failed to find ':'");
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
ClientKeyFromCacheKey(const nsAReadableCString& key, char ** result)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
*result = nsnull;
|
||||
|
||||
nsReadingIterator<char> start;
|
||||
key.BeginReading(start);
|
||||
|
||||
nsReadingIterator<char> end;
|
||||
key.EndReading(end);
|
||||
|
||||
if (FindCharInReadable(':', start, end)) {
|
||||
++start; // advance past clientID ':' delimiter
|
||||
*result = ToNewCString( Substring(start, end));
|
||||
if (!*result) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "FindCharInRead failed to find ':'");
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
53
mozilla/netwerk/cache/src/nsCache.h
vendored
Normal file
53
mozilla/netwerk/cache/src/nsCache.h
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCache.h, released March 18, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Cache Service Utility Functions
|
||||
*/
|
||||
|
||||
#ifndef _nsCache_h_
|
||||
#define _nsCache_h_
|
||||
|
||||
#include "nsAReadableString.h"
|
||||
#include "prtime.h"
|
||||
#include "nsError.h"
|
||||
|
||||
#if 0
|
||||
// Convert PRTime to unix-style time_t, i.e. seconds since the epoch
|
||||
PRUint32 ConvertPRTimeToSeconds(PRTime time64);
|
||||
|
||||
// Convert unix-style time_t, i.e. seconds since the epoch, to PRTime
|
||||
PRTime ConvertSecondsToPRTime(PRUint32 seconds);
|
||||
#endif
|
||||
|
||||
|
||||
extern PRUint32 SecondsFromPRTime(PRTime prTime);
|
||||
extern PRTime PRTimeFromSeconds(PRUint32 seconds);
|
||||
|
||||
|
||||
extern nsresult ClientIDFromCacheKey(const nsAReadableCString& key, char ** result);
|
||||
extern nsresult ClientKeyFromCacheKey(const nsAReadableCString& key, char ** result);
|
||||
|
||||
#endif // _nsCache_h
|
||||
72
mozilla/netwerk/cache/src/nsCacheDevice.h
vendored
Normal file
72
mozilla/netwerk/cache/src/nsCacheDevice.h
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheDevice.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheDevice_h_
|
||||
#define _nsCacheDevice_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsError.h"
|
||||
#include "nsICache.h"
|
||||
|
||||
class nsIFile;
|
||||
class nsCString;
|
||||
class nsCacheEntry;
|
||||
class nsICacheVisitor;
|
||||
class nsITransport;
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheDevice
|
||||
*******************************************************************************/
|
||||
class nsCacheDevice {
|
||||
public:
|
||||
virtual ~nsCacheDevice() {}
|
||||
|
||||
virtual nsresult Init() = 0;
|
||||
virtual nsresult Shutdown() = 0;
|
||||
|
||||
virtual const char * GetDeviceID(void) = 0;
|
||||
virtual nsCacheEntry * FindEntry( nsCString * key ) = 0;
|
||||
|
||||
virtual nsresult DeactivateEntry( nsCacheEntry * entry ) = 0;
|
||||
virtual nsresult BindEntry( nsCacheEntry * entry ) = 0;
|
||||
virtual void DoomEntry( nsCacheEntry * entry ) = 0;
|
||||
|
||||
virtual nsresult GetTransportForEntry( nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport **result ) = 0;
|
||||
|
||||
virtual nsresult GetFileForEntry( nsCacheEntry * entry,
|
||||
nsIFile ** result ) = 0;
|
||||
|
||||
virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize ) = 0;
|
||||
|
||||
virtual nsresult Visit(nsICacheVisitor * visitor) = 0;
|
||||
|
||||
/**
|
||||
* Device must evict entries associated with clientID. If clientID == nsnull, all
|
||||
* entries must be evicted. Active entries must be doomed, rather than evicted.
|
||||
*/
|
||||
virtual nsresult EvictEntries(const char * clientID) = 0;
|
||||
};
|
||||
|
||||
#endif // _nsCacheDevice_h_
|
||||
569
mozilla/netwerk/cache/src/nsCacheEntry.cpp
vendored
Normal file
569
mozilla/netwerk/cache/src/nsCacheEntry.cpp
vendored
Normal file
@@ -0,0 +1,569 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheEntry.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsCacheEntry.h"
|
||||
#include "nsCacheEntryDescriptor.h"
|
||||
#include "nsCacheMetaData.h"
|
||||
#include "nsCacheRequest.h"
|
||||
#include "nsError.h"
|
||||
#include "nsICacheService.h"
|
||||
#include "nsCache.h"
|
||||
|
||||
|
||||
nsCacheEntry::nsCacheEntry(nsCString * key,
|
||||
PRBool streamBased,
|
||||
nsCacheStoragePolicy storagePolicy)
|
||||
: mKey(key),
|
||||
mFetchCount(0),
|
||||
mLastFetched(0),
|
||||
mExpirationTime(0),
|
||||
mFlags(0),
|
||||
mDataSize(0),
|
||||
mMetaSize(0),
|
||||
mCacheDevice(nsnull),
|
||||
mData(nsnull),
|
||||
mMetaData(nsnull)
|
||||
{
|
||||
PR_INIT_CLIST(this);
|
||||
PR_INIT_CLIST(&mRequestQ);
|
||||
PR_INIT_CLIST(&mDescriptorQ);
|
||||
|
||||
if (streamBased) MarkStreamBased();
|
||||
SetStoragePolicy(storagePolicy);
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntry::~nsCacheEntry()
|
||||
{
|
||||
delete mKey;
|
||||
delete mMetaData;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntry::Fetched()
|
||||
{
|
||||
mLastFetched = SecondsFromPRTime(PR_Now());
|
||||
++mFetchCount;
|
||||
MarkEntryDirty();
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::GetData(nsISupports **result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
NS_IF_ADDREF(*result = mData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsCacheEntry::TouchData()
|
||||
{
|
||||
mLastModified = SecondsFromPRTime(PR_Now());
|
||||
MarkDataDirty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::GetMetaDataElement( const nsAReadableCString& key,
|
||||
nsAReadableCString ** value)
|
||||
{
|
||||
*value = mMetaData ? mMetaData->GetElement(&key) : nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::SetMetaDataElement( const nsAReadableCString& key,
|
||||
const nsAReadableCString& value)
|
||||
{
|
||||
if (!mMetaData) {
|
||||
mMetaData = nsCacheMetaData::Create();
|
||||
if (!mMetaData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult rv = mMetaData->SetElement(key, value);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
mMetaSize = mMetaData->Size(); // calc new meta data size
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::FlattenMetaData(char ** data, PRUint32 * size)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(size);
|
||||
|
||||
if (mMetaData)
|
||||
return mMetaData->FlattenMetaData(data, size);
|
||||
|
||||
if (data) *data = nsnull;
|
||||
*size = 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::UnflattenMetaData(char * data, PRUint32 size)
|
||||
{
|
||||
delete mMetaData;
|
||||
mMetaData = nsCacheMetaData::Create();
|
||||
if (!mMetaData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsresult rv = mMetaData->UnflattenMetaData(data, size);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mMetaSize = mMetaData->Size();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntry::TouchMetaData()
|
||||
{
|
||||
mLastModified = SecondsFromPRTime(PR_Now());
|
||||
MarkMetaDataDirty();
|
||||
}
|
||||
|
||||
#if 0
|
||||
nsresult
|
||||
nsCacheEntry::GetKeyValueArray(nsCacheMetaDataKeyValuePair ** array,
|
||||
PRUint32 * count)
|
||||
{
|
||||
if (!array || !count) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (!mMetaData) {
|
||||
*array = nsnull;
|
||||
*count = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
return mMetaData->GetKeyValueArray(array, count);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::GetSecurityInfo( nsISupports ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
NS_IF_ADDREF(*result = mSecurityInfo);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* cache entry states
|
||||
* 0 descriptors (new entry)
|
||||
* 0 descriptors (existing, bound entry)
|
||||
* n descriptors (existing, bound entry) valid
|
||||
* n descriptors (existing, bound entry) not valid (wait until valid or doomed)
|
||||
*/
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::RequestAccess(nsCacheRequest * request, nsCacheAccessMode *accessGranted)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!IsInitialized()) {
|
||||
// brand new, unbound entry
|
||||
request->mKey = nsnull; // steal ownership of the key string
|
||||
if (request->IsStreamBased()) MarkStreamBased();
|
||||
MarkInitialized();
|
||||
|
||||
*accessGranted = request->AccessRequested() & nsICache::ACCESS_WRITE;
|
||||
NS_ASSERTION(*accessGranted, "new cache entry for READ-ONLY request");
|
||||
PR_APPEND_LINK(request, &mRequestQ);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (IsDoomed()) return NS_ERROR_CACHE_ENTRY_DOOMED;
|
||||
|
||||
if (IsStreamData() != request->IsStreamBased()) {
|
||||
*accessGranted = nsICache::ACCESS_NONE;
|
||||
return request->IsStreamBased() ?
|
||||
NS_ERROR_CACHE_DATA_IS_NOT_STREAM : NS_ERROR_CACHE_DATA_IS_STREAM;
|
||||
}
|
||||
|
||||
if (PR_CLIST_IS_EMPTY(&mDescriptorQ)) {
|
||||
// 1st descriptor for existing bound entry
|
||||
*accessGranted = request->AccessRequested();
|
||||
if (*accessGranted & nsICache::ACCESS_WRITE) {
|
||||
MarkInvalid();
|
||||
} else {
|
||||
MarkValid();
|
||||
}
|
||||
} else {
|
||||
// nth request for existing, bound entry
|
||||
*accessGranted = request->AccessRequested() & ~nsICache::ACCESS_WRITE;
|
||||
if (!IsValid())
|
||||
rv = NS_ERROR_CACHE_WAIT_FOR_VALIDATION;
|
||||
}
|
||||
PR_APPEND_LINK(request,&mRequestQ);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::CreateDescriptor(nsCacheRequest * request,
|
||||
nsCacheAccessMode accessGranted,
|
||||
nsICacheEntryDescriptor ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(request && result);
|
||||
|
||||
nsCacheEntryDescriptor * descriptor =
|
||||
new nsCacheEntryDescriptor(this, accessGranted);
|
||||
|
||||
// XXX check request is on q
|
||||
PR_REMOVE_AND_INIT_LINK(request); // remove request regardless of success
|
||||
|
||||
if (descriptor == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PR_APPEND_LINK(descriptor, &mDescriptorQ);
|
||||
|
||||
NS_ADDREF(*result = descriptor);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsCacheEntry::RemoveRequest(nsCacheRequest * request)
|
||||
{
|
||||
// XXX if debug: verify this request belongs to this entry
|
||||
PR_REMOVE_AND_INIT_LINK(request);
|
||||
|
||||
// return true if this entry should stay active
|
||||
return !((PR_CLIST_IS_EMPTY(&mRequestQ)) &&
|
||||
(PR_CLIST_IS_EMPTY(&mDescriptorQ)));
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsCacheEntry::RemoveDescriptor(nsCacheEntryDescriptor * descriptor)
|
||||
{
|
||||
// XXX if debug: verify this descriptor belongs to this entry
|
||||
PR_REMOVE_AND_INIT_LINK(descriptor);
|
||||
|
||||
if (!PR_CLIST_IS_EMPTY(&mDescriptorQ))
|
||||
return PR_TRUE; // stay active if we still have open descriptors
|
||||
|
||||
if (PR_CLIST_IS_EMPTY(&mRequestQ))
|
||||
return PR_FALSE; // no descriptors or requests, we can deactivate
|
||||
|
||||
return PR_TRUE; // find next best request to give a descriptor to
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntry::DetachDescriptors(void)
|
||||
{
|
||||
nsCacheEntryDescriptor * descriptor =
|
||||
(nsCacheEntryDescriptor *)PR_LIST_HEAD(&mDescriptorQ);
|
||||
|
||||
while (descriptor != &mDescriptorQ) {
|
||||
nsCacheEntryDescriptor * nextDescriptor =
|
||||
(nsCacheEntryDescriptor *)PR_NEXT_LINK(descriptor);
|
||||
|
||||
descriptor->ClearCacheEntry();
|
||||
PR_REMOVE_AND_INIT_LINK(descriptor);
|
||||
descriptor = nextDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryInfo - for implementing about:cache
|
||||
*****************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsCacheEntryInfo, nsICacheEntryInfo);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetClientID(char ** clientID)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(clientID);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientIDFromCacheKey(*mCacheEntry->Key(), clientID);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetKey(char ** key)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(key);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientKeyFromCacheKey(*mCacheEntry->Key(), key);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetFetchCount(PRInt32 * fetchCount)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(fetchCount);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*fetchCount = mCacheEntry->FetchCount();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetLastFetched(PRUint32 * lastFetched)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(lastFetched);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*lastFetched = mCacheEntry->LastFetched();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetLastModified(PRUint32 * lastModified)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(lastModified);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*lastModified = mCacheEntry->LastModified();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetExpirationTime(PRUint32 * expirationTime)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(expirationTime);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*expirationTime = mCacheEntry->ExpirationTime();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetDataSize(PRUint32 * dataSize)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(dataSize);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*dataSize = mCacheEntry->DataSize();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::IsStreamBased(PRBool * result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->IsStreamData();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryHashTable
|
||||
*****************************************************************************/
|
||||
|
||||
PLDHashTableOps
|
||||
nsCacheEntryHashTable::ops =
|
||||
{
|
||||
PL_DHashAllocTable,
|
||||
PL_DHashFreeTable,
|
||||
GetKey,
|
||||
HashKey,
|
||||
MatchEntry,
|
||||
MoveEntry,
|
||||
ClearEntry,
|
||||
Finalize
|
||||
};
|
||||
|
||||
|
||||
nsCacheEntryHashTable::nsCacheEntryHashTable()
|
||||
: initialized(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntryHashTable::~nsCacheEntryHashTable()
|
||||
{
|
||||
if (initialized)
|
||||
PL_DHashTableFinish(&table);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryHashTable::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
initialized = PL_DHashTableInit(&table, &ops, nsnull,
|
||||
sizeof(nsCacheEntryHashTableEntry), 512);
|
||||
|
||||
if (!initialized) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntry *
|
||||
nsCacheEntryHashTable::GetEntry( const nsCString * key)
|
||||
{
|
||||
PLDHashEntryHdr *hashEntry;
|
||||
nsCacheEntry *result = nsnull;
|
||||
|
||||
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
||||
hashEntry = PL_DHashTableOperate(&table, key, PL_DHASH_LOOKUP);
|
||||
if (PL_DHASH_ENTRY_IS_BUSY(hashEntry)) {
|
||||
result = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryHashTable::AddEntry( nsCacheEntry *cacheEntry)
|
||||
{
|
||||
PLDHashEntryHdr *hashEntry;
|
||||
|
||||
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
||||
if (!cacheEntry) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
hashEntry = PL_DHashTableOperate(&table, cacheEntry->mKey, PL_DHASH_ADD);
|
||||
#ifndef DEBUG_dougt
|
||||
NS_ASSERTION(((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry == 0,
|
||||
"### nsCacheEntryHashTable::AddEntry - entry already used");
|
||||
#endif
|
||||
((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry = cacheEntry;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntryHashTable::RemoveEntry( nsCacheEntry *cacheEntry)
|
||||
{
|
||||
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
||||
NS_ASSERTION(cacheEntry, "### cacheEntry == nsnull");
|
||||
|
||||
#if DEBUG
|
||||
// XXX debug code to make sure we have the entry we're trying to remove
|
||||
nsCacheEntry *check = GetEntry(cacheEntry->mKey);
|
||||
NS_ASSERTION(check == cacheEntry, "### Attempting to remove unknown cache entry!!!");
|
||||
#endif
|
||||
(void) PL_DHashTableOperate(&table, cacheEntry->mKey, PL_DHASH_REMOVE);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntryHashTable::VisitEntries( nsCacheEntryHashTable::Visitor *visitor)
|
||||
{
|
||||
PL_DHashTableEnumerate(&table, VisitEntry, visitor);
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheEntryHashTable::VisitEntry(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hashEntry,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
||||
nsCacheEntryHashTable::Visitor *visitor = (nsCacheEntryHashTable::Visitor*) arg;
|
||||
return (visitor->VisitEntry(cacheEntry) ? PL_DHASH_NEXT : PL_DHASH_STOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash table operation callback functions
|
||||
*/
|
||||
const void * PR_CALLBACK
|
||||
nsCacheEntryHashTable::GetKey( PLDHashTable * /*table*/, PLDHashEntryHdr *hashEntry)
|
||||
{
|
||||
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
||||
return cacheEntry->mKey;
|
||||
}
|
||||
|
||||
|
||||
PLDHashNumber PR_CALLBACK
|
||||
nsCacheEntryHashTable::HashKey( PLDHashTable *table, const void *key)
|
||||
{
|
||||
return PL_DHashStringKey(table,((nsCString *)key)->get());
|
||||
}
|
||||
|
||||
PRBool PR_CALLBACK
|
||||
nsCacheEntryHashTable::MatchEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr * hashEntry,
|
||||
const void * key)
|
||||
{
|
||||
NS_ASSERTION(key != nsnull, "### nsCacheEntryHashTable::MatchEntry : null key");
|
||||
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
||||
|
||||
return nsStr::StrCompare(*cacheEntry->mKey, *(nsCString *)key, -1, PR_FALSE) == 0;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheEntryHashTable::MoveEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to)
|
||||
{
|
||||
to->keyHash = from->keyHash;
|
||||
((nsCacheEntryHashTableEntry *)to)->cacheEntry =
|
||||
((nsCacheEntryHashTableEntry *)from)->cacheEntry;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheEntryHashTable::ClearEntry(PLDHashTable * /* table */,
|
||||
PLDHashEntryHdr * hashEntry)
|
||||
{
|
||||
((nsCacheEntryHashTableEntry *)hashEntry)->keyHash = 0;
|
||||
((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry = 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntryHashTable::Finalize(PLDHashTable * table)
|
||||
{
|
||||
(void) PL_DHashTableEnumerate(table, FreeCacheEntries, nsnull);
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheEntryHashTable::FreeCacheEntries(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheEntryHashTableEntry *entry = (nsCacheEntryHashTableEntry *)hdr;
|
||||
delete entry->cacheEntry;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
312
mozilla/netwerk/cache/src/nsCacheEntry.h
vendored
Normal file
312
mozilla/netwerk/cache/src/nsCacheEntry.h
vendored
Normal file
@@ -0,0 +1,312 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheEntry.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheEntry_h_
|
||||
#define _nsCacheEntry_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "pldhash.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsAReadableString.h"
|
||||
|
||||
#include "nsICache.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsCacheMetaData.h"
|
||||
|
||||
|
||||
class nsCacheDevice;
|
||||
class nsCacheMetaData;
|
||||
class nsCacheRequest;
|
||||
class nsCacheEntryDescriptor;
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntry
|
||||
*******************************************************************************/
|
||||
class nsCacheEntry : public PRCList
|
||||
{
|
||||
public:
|
||||
|
||||
nsCacheEntry(nsCString * key,
|
||||
PRBool streamBased,
|
||||
nsCacheStoragePolicy storagePolicy);
|
||||
~nsCacheEntry();
|
||||
|
||||
|
||||
nsCString * Key() { return mKey; }
|
||||
|
||||
PRInt32 FetchCount() { return mFetchCount;}
|
||||
void SetFetchCount( PRInt32 count) { mFetchCount = count;}
|
||||
void Fetched();
|
||||
|
||||
PRUint32 LastFetched() { return mLastFetched;}
|
||||
void SetLastFetched( PRUint32 lastFetched) { mLastFetched = lastFetched;}
|
||||
|
||||
PRUint32 LastModified() { return mLastModified;}
|
||||
void SetLastModified( PRUint32 lastModified) { mLastModified = lastModified;}
|
||||
|
||||
PRUint32 ExpirationTime() { return mExpirationTime;}
|
||||
void SetExpirationTime( PRUint32 expires) { mExpirationTime = expires;}
|
||||
|
||||
PRUint32 Size() { return mDataSize + mMetaSize; }
|
||||
|
||||
nsCacheDevice * CacheDevice() { return mCacheDevice;}
|
||||
void SetCacheDevice( nsCacheDevice * device) { mCacheDevice = device;}
|
||||
|
||||
|
||||
/**
|
||||
* Data accessors
|
||||
*/
|
||||
nsresult GetData( nsISupports ** result);
|
||||
void SetData( nsISupports * data) { mData = data; }
|
||||
|
||||
PRUint32 DataSize() { return mDataSize;}
|
||||
void SetDataSize( PRUint32 size) { mDataSize = size;}
|
||||
|
||||
void TouchData();
|
||||
|
||||
|
||||
/**
|
||||
* Meta data accessors
|
||||
*/
|
||||
nsresult GetMetaDataElement( const nsAReadableCString& key,
|
||||
nsAReadableCString ** value);
|
||||
nsresult SetMetaDataElement( const nsAReadableCString& key,
|
||||
const nsAReadableCString& value);
|
||||
|
||||
nsresult FlattenMetaData(char ** data, PRUint32 * size);
|
||||
nsresult UnflattenMetaData(char * data, PRUint32 size);
|
||||
|
||||
PRUint32 MetaDataSize() { return mMetaSize;}
|
||||
|
||||
void TouchMetaData();
|
||||
|
||||
|
||||
/**
|
||||
* Security Info accessors
|
||||
*/
|
||||
nsresult GetSecurityInfo( nsISupports ** result);
|
||||
void SetSecurityInfo( nsISupports * info) { mSecurityInfo = info; }
|
||||
|
||||
|
||||
// XXX enumerate MetaData method
|
||||
|
||||
|
||||
enum CacheEntryFlags {
|
||||
eStoragePolicyMask = 0x000000FF,
|
||||
eDoomedMask = 0x00000100,
|
||||
eEntryDirtyMask = 0x00000200,
|
||||
eDataDirtyMask = 0x00000400,
|
||||
eMetaDataDirtyMask = 0x00000800,
|
||||
eStreamDataMask = 0x00001000,
|
||||
eActiveMask = 0x00002000,
|
||||
eInitializedMask = 0x00004000,
|
||||
eValidMask = 0x00008000
|
||||
};
|
||||
|
||||
void MarkEntryDirty() { mFlags |= eEntryDirtyMask; }
|
||||
void MarkEntryClean() { mFlags &= ~eEntryDirtyMask; }
|
||||
void MarkDataDirty() { mFlags |= eDataDirtyMask; }
|
||||
void MarkDataClean() { mFlags &= ~eDataDirtyMask; }
|
||||
void MarkMetaDataDirty() { mFlags |= eMetaDataDirtyMask; }
|
||||
void MarkMetaDataClean() { mFlags &= ~eMetaDataDirtyMask; }
|
||||
void MarkStreamData() { mFlags |= eStreamDataMask; }
|
||||
void MarkValid() { mFlags |= eValidMask; }
|
||||
void MarkInvalid() { mFlags &= ~eValidMask; }
|
||||
// void MarkAllowedInMemory() { mFlags |= eAllowedInMemoryMask; }
|
||||
// void MarkAllowedOnDisk() { mFlags |= eAllowedOnDiskMask; }
|
||||
|
||||
PRBool IsDoomed() { return (mFlags & eDoomedMask) != 0; }
|
||||
PRBool IsEntryDirty() { return (mFlags & eEntryDirtyMask) != 0; }
|
||||
PRBool IsDataDirty() { return (mFlags & eDataDirtyMask) != 0; }
|
||||
PRBool IsMetaDataDirty() { return (mFlags & eMetaDataDirtyMask) != 0; }
|
||||
PRBool IsStreamData() { return (mFlags & eStreamDataMask) != 0; }
|
||||
PRBool IsActive() { return (mFlags & eActiveMask) != 0; }
|
||||
PRBool IsInitialized() { return (mFlags & eInitializedMask) != 0; }
|
||||
PRBool IsValid() { return (mFlags & eValidMask) != 0; }
|
||||
PRBool IsInvalid() { return (mFlags & eValidMask) == 0; }
|
||||
PRBool IsInUse() { return !(PR_CLIST_IS_EMPTY(&mRequestQ) &&
|
||||
PR_CLIST_IS_EMPTY(&mDescriptorQ)); }
|
||||
PRBool IsNotInUse() { return (PR_CLIST_IS_EMPTY(&mRequestQ) &&
|
||||
PR_CLIST_IS_EMPTY(&mDescriptorQ)); }
|
||||
|
||||
|
||||
PRBool IsAllowedInMemory()
|
||||
{
|
||||
return (StoragePolicy() == nsICache::STORE_ANYWHERE) ||
|
||||
(StoragePolicy() == nsICache::STORE_IN_MEMORY);
|
||||
}
|
||||
|
||||
PRBool IsAllowedOnDisk()
|
||||
{
|
||||
return (StoragePolicy() == nsICache::STORE_ANYWHERE) ||
|
||||
(StoragePolicy() == nsICache::STORE_ON_DISK) ||
|
||||
(StoragePolicy() == nsICache::STORE_ON_DISK_AS_FILE);
|
||||
}
|
||||
|
||||
nsCacheStoragePolicy StoragePolicy()
|
||||
{
|
||||
return (nsCacheStoragePolicy)(mFlags & eStoragePolicyMask);
|
||||
}
|
||||
|
||||
void SetStoragePolicy(nsCacheStoragePolicy policy)
|
||||
{
|
||||
NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
|
||||
mFlags &= ~eStoragePolicyMask; // clear storage policy bits
|
||||
mFlags |= policy;
|
||||
}
|
||||
|
||||
|
||||
// methods for nsCacheService
|
||||
nsresult RequestAccess( nsCacheRequest * request, nsCacheAccessMode *accessGranted);
|
||||
nsresult CreateDescriptor( nsCacheRequest * request,
|
||||
nsCacheAccessMode accessGranted,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
// nsresult Open(nsCacheRequest *request, nsICacheEntryDescriptor ** result);
|
||||
// nsresult AsyncOpen(nsCacheRequest *request);
|
||||
PRBool RemoveRequest( nsCacheRequest * request);
|
||||
PRBool RemoveDescriptor( nsCacheEntryDescriptor * descriptor);
|
||||
|
||||
private:
|
||||
friend class nsCacheEntryHashTable;
|
||||
friend class nsCacheService;
|
||||
|
||||
void DetachDescriptors(void);
|
||||
|
||||
// internal methods
|
||||
void MarkDoomed() { mFlags |= eDoomedMask; }
|
||||
void MarkStreamBased() { mFlags |= eStreamDataMask; }
|
||||
void MarkInitialized() { mFlags |= eInitializedMask; }
|
||||
void MarkActive() { mFlags |= eActiveMask; }
|
||||
void MarkInactive() { mFlags &= ~eActiveMask; }
|
||||
|
||||
nsCString * mKey; // 4 // XXX ask scc about const'ness
|
||||
PRUint32 mFetchCount; // 4
|
||||
PRUint32 mLastFetched; // 4
|
||||
PRUint32 mLastModified; // 4
|
||||
PRUint32 mLastValidated; // 4
|
||||
PRUint32 mExpirationTime; // 4
|
||||
PRUint32 mFlags; // 4
|
||||
PRUint32 mDataSize; // 4
|
||||
PRUint32 mMetaSize; // 4
|
||||
nsCacheDevice * mCacheDevice; // 4
|
||||
nsCOMPtr<nsISupports> mSecurityInfo; //
|
||||
nsCOMPtr<nsISupports> mData; //
|
||||
nsCacheMetaData * mMetaData; // 4
|
||||
PRCList mRequestQ; // 8
|
||||
PRCList mDescriptorQ; // 8
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryInfo
|
||||
*******************************************************************************/
|
||||
class nsCacheEntryInfo : public nsICacheEntryInfo {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHEENTRYINFO
|
||||
|
||||
nsCacheEntryInfo(nsCacheEntry* entry)
|
||||
: mCacheEntry(entry)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
virtual ~nsCacheEntryInfo() {}
|
||||
void DetachEntry() { mCacheEntry = nsnull; }
|
||||
|
||||
private:
|
||||
nsCacheEntry * mCacheEntry;
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryHashTable
|
||||
*******************************************************************************/
|
||||
typedef struct {
|
||||
PLDHashNumber keyHash;
|
||||
nsCacheEntry *cacheEntry;
|
||||
} nsCacheEntryHashTableEntry;
|
||||
|
||||
|
||||
class nsCacheEntryHashTable
|
||||
{
|
||||
public:
|
||||
nsCacheEntryHashTable();
|
||||
~nsCacheEntryHashTable();
|
||||
|
||||
nsresult Init();
|
||||
|
||||
nsCacheEntry *GetEntry( const nsCString * key);
|
||||
nsresult AddEntry( nsCacheEntry *entry);
|
||||
void RemoveEntry( nsCacheEntry *entry);
|
||||
|
||||
// XXX enumerate entries?
|
||||
class Visitor {
|
||||
public:
|
||||
virtual PRBool VisitEntry( nsCacheEntry *entry) = 0;
|
||||
};
|
||||
|
||||
void VisitEntries( Visitor *visitor);
|
||||
|
||||
private:
|
||||
friend class nsCacheService; // XXX redefine interface so this isn't necessary
|
||||
|
||||
// PLDHashTable operation callbacks
|
||||
static const void * PR_CALLBACK GetKey( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
||||
static PLDHashNumber PR_CALLBACK HashKey( PLDHashTable *table, const void *key);
|
||||
|
||||
static PRBool PR_CALLBACK MatchEntry( PLDHashTable * table,
|
||||
const PLDHashEntryHdr * entry,
|
||||
const void * key);
|
||||
|
||||
static void PR_CALLBACK MoveEntry( PLDHashTable *table,
|
||||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to);
|
||||
|
||||
static void PR_CALLBACK ClearEntry( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
||||
static void PR_CALLBACK Finalize( PLDHashTable *table);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK FreeCacheEntries(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK VisitEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
|
||||
// member variables
|
||||
static PLDHashTableOps ops;
|
||||
PLDHashTable table;
|
||||
PRBool initialized;
|
||||
};
|
||||
|
||||
#endif // _nsCacheEntry_h_
|
||||
|
||||
654
mozilla/netwerk/cache/src/nsCacheEntryDescriptor.cpp
vendored
Normal file
654
mozilla/netwerk/cache/src/nsCacheEntryDescriptor.cpp
vendored
Normal file
@@ -0,0 +1,654 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheEntryDescriptor.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#include "nsICache.h"
|
||||
#include "nsCache.h"
|
||||
#include "nsCacheService.h"
|
||||
#include "nsCacheEntryDescriptor.h"
|
||||
#include "nsCacheEntry.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIOutputStream.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsCacheEntryDescriptor, nsICacheEntryDescriptor)
|
||||
|
||||
|
||||
nsCacheEntryDescriptor::nsCacheEntryDescriptor(nsCacheEntry * entry,
|
||||
nsCacheAccessMode accessGranted)
|
||||
: mCacheEntry(entry),
|
||||
mAccessGranted(accessGranted)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
PR_INIT_CLIST(this);
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntryDescriptor::~nsCacheEntryDescriptor()
|
||||
{
|
||||
if (mCacheEntry)
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryDescriptor::Create(nsCacheEntry * entry, nsCacheAccessMode accessGranted,
|
||||
nsICacheEntryDescriptor ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
nsresult rv = nsnull;
|
||||
|
||||
nsCacheEntryDescriptor * descriptor =
|
||||
new nsCacheEntryDescriptor(entry, accessGranted);
|
||||
|
||||
if (descriptor == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(descriptor);
|
||||
rv = descriptor->QueryInterface(NS_GET_IID(nsICacheEntryDescriptor), (void**)result);
|
||||
NS_RELEASE(descriptor);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetClientID(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientIDFromCacheKey(*(mCacheEntry->Key()), result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetKey(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientKeyFromCacheKey(*(mCacheEntry->Key()), result);
|
||||
|
||||
#if 0
|
||||
nsCString * key;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
*result = nsnull;
|
||||
key = mCacheEntry->Key();
|
||||
|
||||
nsReadingIterator<char> start;
|
||||
key->BeginReading(start);
|
||||
|
||||
nsReadingIterator<char> end;
|
||||
key->EndReading(end);
|
||||
|
||||
if (FindCharInReadable(':', start, end)) {
|
||||
++start; // advance past clientID ':' delimiter
|
||||
*result = ToNewCString( Substring(start, end));
|
||||
if (!*result) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "FindCharInRead failed to find ':'");
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return rv;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetFetchCount(PRInt32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->FetchCount();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetLastFetched(PRUint32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->LastFetched();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetLastModified(PRUint32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->LastModified();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetExpirationTime(PRUint32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->ExpirationTime();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetExpirationTime(PRUint32 expirationTime)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
mCacheEntry->SetExpirationTime(expirationTime);
|
||||
mCacheEntry->MarkEntryDirty();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::IsStreamBased(PRBool *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->IsStreamData(); // XXX which name is better?
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::GetDataSize(PRUint32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->DataSize();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryDescriptor::RequestDataSizeChange(PRInt32 deltaSize)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsCacheService::GlobalInstance()->OnDataSizeChange(mCacheEntry, deltaSize);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// XXX review for signed/unsigned math errors
|
||||
PRUint32 newDataSize = mCacheEntry->DataSize() + deltaSize;
|
||||
mCacheEntry->SetDataSize(newDataSize);
|
||||
mCacheEntry->TouchData();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetDataSize(PRUint32 dataSize)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
// XXX review for signed/unsigned math errors
|
||||
PRInt32 deltaSize = dataSize - mCacheEntry->DataSize();
|
||||
|
||||
// this had better be NS_OK, this call instance is advisory
|
||||
nsresult rv = RequestDataSizeChange(deltaSize);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "failed SetDataSize() on memory cache object!");
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetTransport(nsITransport ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
if (!mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_NOT_STREAM;
|
||||
|
||||
NS_ADDREF(*result = &mTransportWrapper);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetCacheElement(nsISupports ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM;
|
||||
|
||||
return mCacheEntry->GetData(result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetCacheElement(nsISupports * cacheElement)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM;
|
||||
|
||||
mCacheEntry->SetData(cacheElement);
|
||||
mCacheEntry->TouchData();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetAccessGranted(nsCacheAccessMode *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = mAccessGranted;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetStoragePolicy(nsCacheStoragePolicy *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return mCacheEntry->StoragePolicy();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetStoragePolicy(nsCacheStoragePolicy policy)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
// XXX validate policy against session?
|
||||
mCacheEntry->SetStoragePolicy(policy);
|
||||
mCacheEntry->MarkEntryDirty();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetFile(nsIFile ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return nsCacheService::GlobalInstance()->GetFileForEntry(mCacheEntry, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetSecurityInfo(nsISupports ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return mCacheEntry->GetSecurityInfo(result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetSecurityInfo(nsISupports * securityInfo)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
mCacheEntry->SetSecurityInfo(securityInfo);
|
||||
mCacheEntry->MarkEntryDirty();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::Doom()
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return nsCacheService::GlobalInstance()->DoomEntry(mCacheEntry);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::DoomAndFailPendingRequests(nsresult status)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::MarkValid()
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
nsresult rv;
|
||||
rv = nsCacheService::GlobalInstance()->ValidateEntry(mCacheEntry);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::Close()
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
// tell nsCacheService we're going away
|
||||
nsCacheService::GlobalInstance()->CloseDescriptor(this);
|
||||
mCacheEntry = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetMetaDataElement(const char *key, char ** result)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
if (!key | !result) return NS_ERROR_NULL_POINTER;
|
||||
nsAReadableCString *value;
|
||||
*result = nsnull;
|
||||
|
||||
// XXX not thread safe
|
||||
nsresult rv = mCacheEntry->GetMetaDataElement(nsLiteralCString(key), &value);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!value) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = ToNewCString(*value);
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetMetaDataElement(const char *key, const char *value)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
if (!key) return NS_ERROR_NULL_POINTER;
|
||||
// XXX not thread safe
|
||||
// XXX allow null value, for clearing key?
|
||||
nsresult rv = mCacheEntry->SetMetaDataElement(nsLiteralCString(key),
|
||||
nsLiteralCString(value));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mCacheEntry->TouchMetaData();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetMetaDataEnumerator(nsISimpleEnumerator ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheTransportWrapper
|
||||
******************************************************************************/
|
||||
|
||||
// XXX NS_IMPL_ISUPPORTS1(nsCacheEntryDescriptor::nsTransportWrapper, nsITransport);
|
||||
NS_IMPL_QUERY_INTERFACE1(nsCacheEntryDescriptor::nsTransportWrapper, nsITransport)
|
||||
|
||||
|
||||
// special AddRef and Release, because we are part of the descriptor
|
||||
#define GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(_this) \
|
||||
((nsCacheEntryDescriptor*)((char*)(_this) - \
|
||||
offsetof(nsCacheEntryDescriptor, mTransportWrapper)))
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt) nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::AddRef(void)
|
||||
{
|
||||
return GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(this)->AddRef();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt) nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::Release(void)
|
||||
{
|
||||
return GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(this)->Release();
|
||||
}
|
||||
|
||||
|
||||
nsresult nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::EnsureTransportWithAccess(nsCacheAccessMode mode)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCacheEntryDescriptor * descriptor = GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(this);
|
||||
if (!descriptor->mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
if (!descriptor->mAccessGranted & mode) {
|
||||
rv = (mode == nsICache::ACCESS_READ) ?
|
||||
NS_ERROR_CACHE_READ_ACCESS_DENIED : NS_ERROR_CACHE_WRITE_ACCESS_DENIED;
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!mTransport) {
|
||||
rv = nsCacheService::GlobalInstance()->
|
||||
GetTransportForEntry(descriptor->mCacheEntry,
|
||||
descriptor->mAccessGranted,
|
||||
getter_AddRefs(mTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryDescriptor::NewOutputStreamWrapper(nsIOutputStream ** result,
|
||||
nsCacheEntryDescriptor * descriptor,
|
||||
nsIOutputStream * output)
|
||||
{
|
||||
nsOutputStreamWrapper* cacheOutput =
|
||||
new nsOutputStreamWrapper(descriptor, output);
|
||||
if (!cacheOutput) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsISupports> ref(cacheOutput);
|
||||
nsresult rv = cacheOutput->Init();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ADDREF(*result = cacheOutput);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::GetSecurityInfo(nsISupports ** securityInfo)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::GetNotificationCallbacks(nsIInterfaceRequestor **result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
// if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::SetNotificationCallbacks(nsIInterfaceRequestor *requestor,
|
||||
PRBool isBackground)
|
||||
{
|
||||
// if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::OpenInputStream(PRUint32 offset,
|
||||
PRUint32 count,
|
||||
PRUint32 flags,
|
||||
nsIInputStream ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
nsresult rv = EnsureTransportWithAccess(nsICache::ACCESS_READ);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mTransport->OpenInputStream(offset, count, flags, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::OpenOutputStream(PRUint32 offset,
|
||||
PRUint32 count,
|
||||
PRUint32 flags,
|
||||
nsIOutputStream ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
nsresult rv = EnsureTransportWithAccess(nsICache::ACCESS_WRITE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// XXX allow more than one output stream at a time on a descriptor? Why?
|
||||
|
||||
// Create the underlying output stream using the wrapped transport.
|
||||
nsCOMPtr<nsIOutputStream> output;
|
||||
rv = mTransport->OpenOutputStream(offset, count, flags, getter_AddRefs(output));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Wrap this output stream, with a stream that monitors how much data gets written,
|
||||
// to maintain the cache entry's size, and to inform the cache device. Eventually,
|
||||
// this mechanism will provide a way for the cache device to enforce space limits,
|
||||
// and to drive cache entry eviction.
|
||||
nsCacheEntryDescriptor * descriptor = GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(this);
|
||||
return NewOutputStreamWrapper(result, descriptor, output);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::AsyncRead(nsIStreamListener * listener,
|
||||
nsISupports * ctxt,
|
||||
PRUint32 offset,
|
||||
PRUint32 count,
|
||||
PRUint32 flags,
|
||||
nsIRequest ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
nsresult rv = EnsureTransportWithAccess(nsICache::ACCESS_READ);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mTransport->AsyncRead(listener, ctxt, offset, count, flags, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::AsyncWrite(nsIStreamProvider * provider,
|
||||
nsISupports * ctxt,
|
||||
PRUint32 offset,
|
||||
PRUint32 count,
|
||||
PRUint32 flags,
|
||||
nsIRequest ** result)
|
||||
{
|
||||
// we're not planning on implementing this
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
#if 0
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
nsresult rv = EnsureTransportWithAccess(nsICache::ACCESS_WRITE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mTransport->AsyncWrite(provider, ctxt, offset, count, flags, result);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheOutputStream - a wrapper for nsIOutputstream to track the amount of
|
||||
* data written to a cache entry.
|
||||
******************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsCacheEntryDescriptor::nsOutputStreamWrapper, nsIOutputStream);
|
||||
|
||||
nsresult nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::Init()
|
||||
{
|
||||
nsCacheAccessMode mode;
|
||||
nsresult rv = mDescriptor->GetAccessGranted(&mode);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (mode == nsICache::ACCESS_WRITE) {
|
||||
nsCacheEntry* cacheEntry = mDescriptor->CacheEntry();
|
||||
if (!cacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
nsCacheDevice* device = cacheEntry->CacheDevice();
|
||||
if (!device) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
// the entry has been truncated to zero bytes, inform the device.
|
||||
PRInt32 delta = -cacheEntry->DataSize();
|
||||
rv = device->OnDataSizeChange(cacheEntry, delta);
|
||||
cacheEntry->SetDataSize(0);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::Write(const char * buf,
|
||||
PRUint32 count,
|
||||
PRUint32 * result)
|
||||
{
|
||||
nsresult rv = OnWrite(count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mOutput->Write(buf, count, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::WriteFrom(nsIInputStream * inStr,
|
||||
PRUint32 count,
|
||||
PRUint32 * result)
|
||||
{
|
||||
nsresult rv = OnWrite(count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mOutput->WriteFrom(inStr, count, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::WriteSegments(nsReadSegmentFun reader,
|
||||
void * closure,
|
||||
PRUint32 count,
|
||||
PRUint32 * result)
|
||||
{
|
||||
nsresult rv = OnWrite(count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mOutput->WriteSegments(reader, closure, count, result);
|
||||
}
|
||||
|
||||
|
||||
nsresult nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::OnWrite(PRUint32 count)
|
||||
{
|
||||
// XXX if count > 2^31 error_write_too_big
|
||||
return mDescriptor->RequestDataSizeChange((PRInt32)count);
|
||||
}
|
||||
|
||||
|
||||
167
mozilla/netwerk/cache/src/nsCacheEntryDescriptor.h
vendored
Normal file
167
mozilla/netwerk/cache/src/nsCacheEntryDescriptor.h
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheEntryDescriptor.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _nsCacheEntryDescriptor_h_
|
||||
#define _nsCacheEntryDescriptor_h_
|
||||
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsCacheEntry.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsITransport.h"
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryDescriptor
|
||||
*******************************************************************************/
|
||||
class nsCacheEntryDescriptor :
|
||||
public PRCList,
|
||||
public nsICacheEntryDescriptor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHEENTRYDESCRIPTOR
|
||||
NS_DECL_NSICACHEENTRYINFO
|
||||
|
||||
nsCacheEntryDescriptor(nsCacheEntry * entry, nsCacheAccessMode mode);
|
||||
virtual ~nsCacheEntryDescriptor();
|
||||
|
||||
static nsresult Create(nsCacheEntry * entry, nsCacheAccessMode accessGranted,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
|
||||
/**
|
||||
* utility method to attempt changing data size of associated entry
|
||||
*/
|
||||
nsresult RequestDataSizeChange(PRInt32 deltaSize);
|
||||
|
||||
/**
|
||||
* methods callbacks for nsCacheService
|
||||
*/
|
||||
nsCacheEntry * CacheEntry(void) { return mCacheEntry; }
|
||||
void ClearCacheEntry(void) { mCacheEntry = nsnull; }
|
||||
|
||||
private:
|
||||
|
||||
/*************************************************************************
|
||||
* transport wrapper class -
|
||||
*
|
||||
* we want the transport wrapper to have the same lifetime as the
|
||||
* descriptor, but since they each need to reference the other, we have the
|
||||
* descriptor include the transport wrapper as a member, rather than just
|
||||
* pointing to it, which avoids circular AddRefs.
|
||||
*************************************************************************/
|
||||
class nsTransportWrapper : public nsITransport
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSITRANSPORT
|
||||
|
||||
nsTransportWrapper() : mTransport(nsnull) {}
|
||||
virtual ~nsTransportWrapper() {}
|
||||
|
||||
nsresult EnsureTransportWithAccess(nsCacheAccessMode mode);
|
||||
|
||||
nsCOMPtr<nsITransport> mTransport;
|
||||
}; // end of class nsTransportWrapper
|
||||
friend class nsTransportWrapper;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* output stream wrapper class -
|
||||
*
|
||||
* The output stream wrapper references the descriptor, but the descriptor
|
||||
* doesn't need any references to the stream wrapper, so we don't need the
|
||||
* same kind of tricks that we're using for the transport wrapper.
|
||||
*************************************************************************/
|
||||
class nsOutputStreamWrapper : public nsIOutputStream {
|
||||
private:
|
||||
nsCacheEntryDescriptor * mDescriptor;
|
||||
nsCOMPtr<nsIOutputStream> mOutput;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
// NS_DECL_NSIOUTPUTSTREAM
|
||||
NS_IMETHOD Close(void) { return mOutput->Close(); }
|
||||
NS_IMETHOD Flush(void) { return mOutput->Flush(); }
|
||||
|
||||
NS_IMETHOD Write(const char * buf,
|
||||
PRUint32 count,
|
||||
PRUint32 * result);
|
||||
|
||||
NS_IMETHOD WriteFrom(nsIInputStream * inStr,
|
||||
PRUint32 count,
|
||||
PRUint32 * result);
|
||||
|
||||
NS_IMETHOD WriteSegments(nsReadSegmentFun reader,
|
||||
void * closure,
|
||||
PRUint32 count,
|
||||
PRUint32 * result);
|
||||
|
||||
NS_IMETHOD GetNonBlocking(PRBool * nonBlocking)
|
||||
{ return mOutput->GetNonBlocking(nonBlocking); }
|
||||
|
||||
NS_IMETHOD SetNonBlocking(PRBool nonBlocking)
|
||||
{ return mOutput->SetNonBlocking(nonBlocking); }
|
||||
|
||||
NS_IMETHOD GetObserver(nsIOutputStreamObserver ** observer)
|
||||
{ return mOutput->GetObserver(observer); }
|
||||
|
||||
NS_IMETHOD SetObserver(nsIOutputStreamObserver * observer)
|
||||
{ return mOutput->SetObserver(observer); }
|
||||
|
||||
nsOutputStreamWrapper(nsCacheEntryDescriptor * descriptor,
|
||||
nsIOutputStream * output)
|
||||
: mDescriptor(nsnull), mOutput(output)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
NS_ADDREF(mDescriptor = descriptor);
|
||||
}
|
||||
|
||||
virtual ~nsOutputStreamWrapper()
|
||||
{
|
||||
NS_RELEASE(mDescriptor);
|
||||
}
|
||||
|
||||
nsresult Init();
|
||||
|
||||
|
||||
private:
|
||||
nsresult OnWrite(PRUint32 count);
|
||||
}; // end of class nsOutputStreamWrapper
|
||||
friend class nsOutputStreamWrapper;
|
||||
|
||||
|
||||
|
||||
static nsresult NewOutputStreamWrapper(nsIOutputStream ** result,
|
||||
nsCacheEntryDescriptor * descriptor,
|
||||
nsIOutputStream * output);
|
||||
private:
|
||||
/**
|
||||
* nsCacheEntryDescriptor data members
|
||||
*/
|
||||
nsCacheEntry * mCacheEntry; // we are a child of the entry
|
||||
nsCacheAccessMode mAccessGranted;
|
||||
nsTransportWrapper mTransportWrapper;
|
||||
};
|
||||
|
||||
|
||||
#endif // _nsCacheEntryDescriptor_h_
|
||||
301
mozilla/netwerk/cache/src/nsCacheMetaData.cpp
vendored
Normal file
301
mozilla/netwerk/cache/src/nsCacheMetaData.cpp
vendored
Normal file
@@ -0,0 +1,301 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheMetaData.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#include "nsCacheMetaData.h"
|
||||
#include "nsString.h"
|
||||
|
||||
|
||||
/*
|
||||
* nsCacheClientHashTable
|
||||
*/
|
||||
|
||||
PLDHashTableOps
|
||||
nsCacheMetaData::ops =
|
||||
{
|
||||
PL_DHashAllocTable,
|
||||
PL_DHashFreeTable,
|
||||
GetKey,
|
||||
HashKey,
|
||||
MatchEntry,
|
||||
MoveEntry,
|
||||
ClearEntry,
|
||||
Finalize
|
||||
};
|
||||
|
||||
|
||||
nsCacheMetaData::nsCacheMetaData()
|
||||
: initialized(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
nsCacheMetaData::~nsCacheMetaData()
|
||||
{
|
||||
if (initialized)
|
||||
PL_DHashTableFinish(&table);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
initialized = PL_DHashTableInit(&table, &ops, nsnull,
|
||||
sizeof(nsCacheMetaDataHashTableEntry), 16);
|
||||
|
||||
if (!initialized) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsCacheMetaData *
|
||||
nsCacheMetaData::Create()
|
||||
{
|
||||
nsCacheMetaData * metaData = new nsCacheMetaData();
|
||||
if (!metaData)
|
||||
return nsnull;
|
||||
|
||||
nsresult rv = metaData->Init();
|
||||
if (NS_FAILED(rv)) {
|
||||
delete metaData;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
return metaData;
|
||||
}
|
||||
|
||||
|
||||
nsAReadableCString *
|
||||
nsCacheMetaData::GetElement(const nsAReadableCString * key)
|
||||
{
|
||||
PLDHashEntryHdr * hashEntry;
|
||||
nsCString * result = nsnull;
|
||||
|
||||
// XXX need to copy string until we have scc's new flat string abstract class
|
||||
// XXX see nsCacheMetaData::HashKey below (bug 70075)
|
||||
nsCString * tempKey = new nsCString(*key);
|
||||
if (!tempKey) return result;
|
||||
|
||||
NS_ASSERTION(initialized, "nsCacheMetaDataHashTable not initialized");
|
||||
hashEntry = PL_DHashTableOperate(&table, tempKey, PL_DHASH_LOOKUP);
|
||||
if (PL_DHASH_ENTRY_IS_BUSY(hashEntry)) {
|
||||
result = ((nsCacheMetaDataHashTableEntry *)hashEntry)->value;
|
||||
}
|
||||
|
||||
delete tempKey;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::SetElement(const nsAReadableCString& key,
|
||||
const nsAReadableCString& value)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry * metaEntry;
|
||||
nsresult rv = NS_ERROR_OUT_OF_MEMORY; // presume the worst
|
||||
|
||||
NS_ASSERTION(initialized, "nsCacheMetaDataHashTable not initialized");
|
||||
|
||||
// XXX need to copy string until we have scc's new flat string abstract class
|
||||
// XXX see nsCacheMetaData::HashKey below (bug 70075)
|
||||
nsCString * tempKey = new nsCString(key);
|
||||
if (!tempKey) return rv;
|
||||
|
||||
// XXX should empty value remove the key?
|
||||
|
||||
metaEntry = (nsCacheMetaDataHashTableEntry *)
|
||||
PL_DHashTableOperate(&table, tempKey, PL_DHASH_ADD);
|
||||
if (!metaEntry) goto error_exit;
|
||||
|
||||
|
||||
if (metaEntry->key == nsnull) {
|
||||
metaEntry->key = new nsCString(key);
|
||||
if (metaEntry->key == nsnull) {
|
||||
goto error_exit;
|
||||
}
|
||||
}
|
||||
if (metaEntry->value != nsnull)
|
||||
delete metaEntry->value; // clear the old value
|
||||
|
||||
metaEntry->value = new nsCString(value);
|
||||
if (metaEntry->value == nsnull) {
|
||||
// XXX remove key?
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
rv = NS_OK;
|
||||
error_exit:
|
||||
delete tempKey;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
PRUint32
|
||||
nsCacheMetaData::Size(void)
|
||||
{
|
||||
PRUint32 size = 0;
|
||||
(void) PL_DHashTableEnumerate(&table, CalculateSize, &size);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::FlattenMetaData(char ** data, PRUint32 * size)
|
||||
{
|
||||
*size = 0;
|
||||
|
||||
if (PL_DHashTableEnumerate(&table, CalculateSize, size) != 0 && data) {
|
||||
*data = new char[*size];
|
||||
if (*data == nsnull) return NS_ERROR_OUT_OF_MEMORY;
|
||||
char* state = *data;
|
||||
PL_DHashTableEnumerate(&table, AccumulateElements, &state);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::UnflattenMetaData(char * data, PRUint32 size)
|
||||
{
|
||||
nsresult rv = NS_ERROR_UNEXPECTED;
|
||||
char* limit = data + size;
|
||||
while (data < limit) {
|
||||
const char* name = data;
|
||||
PRUint32 nameSize = nsCRT::strlen(name);
|
||||
data += 1 + nameSize;
|
||||
if (data < limit) {
|
||||
const char* value = data;
|
||||
PRUint32 valueSize = nsCRT::strlen(value);
|
||||
data += 1 + valueSize;
|
||||
rv = SetElement(nsLiteralCString(name, nameSize),
|
||||
nsLiteralCString(value, valueSize));
|
||||
if (NS_FAILED(rv)) break;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* hash table operation callback functions
|
||||
*/
|
||||
|
||||
const void * PR_CALLBACK
|
||||
nsCacheMetaData::GetKey( PLDHashTable * /* table */, PLDHashEntryHdr *hashEntry)
|
||||
{
|
||||
return ((nsCacheMetaDataHashTableEntry *)hashEntry)->key;
|
||||
}
|
||||
|
||||
|
||||
PLDHashNumber PR_CALLBACK
|
||||
nsCacheMetaData::HashKey( PLDHashTable * table, const void *key)
|
||||
{
|
||||
// XXX need scc's new flat string abstract class here (bug 70075)
|
||||
return PL_DHashStringKey(table, ((nsCString *)key)->get());
|
||||
}
|
||||
|
||||
|
||||
PRBool PR_CALLBACK
|
||||
nsCacheMetaData::MatchEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr * hashEntry,
|
||||
const void * key)
|
||||
{
|
||||
NS_ASSERTION(key != nsnull, "### nsCacheMetaDataHashTable::MatchEntry : null key");
|
||||
nsCString * entryKey = ((nsCacheMetaDataHashTableEntry *)hashEntry)->key;
|
||||
NS_ASSERTION(entryKey, "### hashEntry->key == nsnull");
|
||||
|
||||
return entryKey->Equals(*NS_STATIC_CAST(const nsAReadableCString*,key));
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheMetaData::MoveEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to)
|
||||
{
|
||||
to->keyHash = from->keyHash;
|
||||
((nsCacheMetaDataHashTableEntry *)to)->key =
|
||||
((nsCacheMetaDataHashTableEntry *)from)->key;
|
||||
((nsCacheMetaDataHashTableEntry *)to)->value =
|
||||
((nsCacheMetaDataHashTableEntry *)from)->value;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheMetaData::ClearEntry(PLDHashTable * /* table */,
|
||||
PLDHashEntryHdr * hashEntry)
|
||||
{
|
||||
((nsCacheMetaDataHashTableEntry *)hashEntry)->keyHash = 0;
|
||||
((nsCacheMetaDataHashTableEntry *)hashEntry)->key = 0;
|
||||
((nsCacheMetaDataHashTableEntry *)hashEntry)->value = 0;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheMetaData::Finalize(PLDHashTable * table)
|
||||
{
|
||||
(void) PL_DHashTableEnumerate(table, FreeElements, nsnull);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hash table enumeration callback functions
|
||||
*/
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheMetaData::CalculateSize(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry* hashEntry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
*(PRUint32*)arg += (2 + hashEntry->key->Length() + hashEntry->value->Length());
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheMetaData::AccumulateElements(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
char** bufferPtr = (char**) arg;
|
||||
nsCacheMetaDataHashTableEntry* hashEntry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
PRUint32 size = 1 + hashEntry->key->Length();
|
||||
nsCRT::memcpy(*bufferPtr, hashEntry->key->get(), size);
|
||||
*bufferPtr += size;
|
||||
size = 1 + hashEntry->value->Length();
|
||||
nsCRT::memcpy(*bufferPtr, hashEntry->value->get(), size);
|
||||
*bufferPtr += size;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheMetaData::FreeElements(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry *entry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
delete entry->key;
|
||||
delete entry->value;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
110
mozilla/netwerk/cache/src/nsCacheMetaData.h
vendored
Normal file
110
mozilla/netwerk/cache/src/nsCacheMetaData.h
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheMetaData.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheMetaData_h_
|
||||
#define _nsCacheMetaData_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "pldhash.h"
|
||||
#include "nscore.h"
|
||||
// #include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
// #include "nsAReadableString.h"
|
||||
|
||||
typedef struct {
|
||||
nsCString * key;
|
||||
nsCString * value;
|
||||
} nsCacheMetaDataKeyValuePair;
|
||||
|
||||
|
||||
typedef struct {
|
||||
PLDHashNumber keyHash;
|
||||
nsCString * key;
|
||||
nsCString * value;
|
||||
} nsCacheMetaDataHashTableEntry;
|
||||
|
||||
|
||||
class nsCacheMetaData {
|
||||
public:
|
||||
nsCacheMetaData();
|
||||
~nsCacheMetaData();
|
||||
|
||||
static
|
||||
nsCacheMetaData * Create(void);
|
||||
|
||||
nsresult Init(void);
|
||||
|
||||
nsAReadableCString * GetElement(const nsAReadableCString * key);
|
||||
|
||||
nsresult SetElement(const nsAReadableCString& key,
|
||||
const nsAReadableCString& value);
|
||||
|
||||
PRUint32 Size(void);
|
||||
|
||||
nsresult FlattenMetaData(char ** data, PRUint32 * size);
|
||||
|
||||
nsresult UnflattenMetaData(char * data, PRUint32 size);
|
||||
|
||||
private:
|
||||
// PLDHashTable operation callbacks
|
||||
static const void * PR_CALLBACK GetKey( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
||||
static PLDHashNumber PR_CALLBACK HashKey( PLDHashTable *table, const void *key);
|
||||
|
||||
static PRBool PR_CALLBACK MatchEntry( PLDHashTable * table,
|
||||
const PLDHashEntryHdr * entry,
|
||||
const void * key);
|
||||
|
||||
static void PR_CALLBACK MoveEntry( PLDHashTable *table,
|
||||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to);
|
||||
|
||||
static void PR_CALLBACK ClearEntry( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
||||
static void PR_CALLBACK Finalize( PLDHashTable *table);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK CalculateSize(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK AccumulateElements(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK FreeElements(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
|
||||
// member variables
|
||||
static PLDHashTableOps ops;
|
||||
PLDHashTable table;
|
||||
PRBool initialized;
|
||||
};
|
||||
|
||||
#endif // _nsCacheMetaData_h
|
||||
41
mozilla/netwerk/cache/src/nsCacheModule.cpp
vendored
Normal file
41
mozilla/netwerk/cache/src/nsCacheModule.cpp
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheModule.cpp, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsCacheService.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
// nsCacheService
|
||||
//
|
||||
|
||||
static nsModuleComponentInfo gResComponents[] = {
|
||||
{
|
||||
NS_CACHESERVICE_CLASSNAME,
|
||||
NS_CACHESERVICE_CID,
|
||||
NS_CACHESERVICE_CONTRACTID,
|
||||
nsCacheService::Create
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("cacheservice", gResComponents)
|
||||
171
mozilla/netwerk/cache/src/nsCacheRequest.h
vendored
Normal file
171
mozilla/netwerk/cache/src/nsCacheRequest.h
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheRequest.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheRequest_h_
|
||||
#define _nsCacheRequest_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsICache.h"
|
||||
#include "nsICacheListener.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsCacheSession.h"
|
||||
|
||||
|
||||
class nsCacheRequest : public PRCList
|
||||
{
|
||||
private:
|
||||
friend class nsCacheService;
|
||||
friend class nsCacheEntry;
|
||||
|
||||
nsCacheRequest( nsCString * key,
|
||||
nsICacheListener * listener,
|
||||
nsCacheAccessMode accessRequested,
|
||||
nsCacheSession * session)
|
||||
: mKey(key),
|
||||
mInfo(0),
|
||||
mListener(listener),
|
||||
mEventQ(nsnull),
|
||||
mLock(nsnull),
|
||||
mCondVar(nsnull)
|
||||
{
|
||||
PR_INIT_CLIST(this);
|
||||
SetAccessRequested(accessRequested);
|
||||
SetStoragePolicy(session->StoragePolicy());
|
||||
if (session->IsStreamBased()) MarkStreamBased();
|
||||
if (session->WillDoomEntriesIfExpired()) MarkDoomEntriesIfExpired();
|
||||
MarkWaitingForValidation();
|
||||
}
|
||||
|
||||
~nsCacheRequest()
|
||||
{
|
||||
delete mKey;
|
||||
if (mLock) PR_DestroyLock(mLock);
|
||||
if (mCondVar) PR_DestroyCondVar(mCondVar);
|
||||
NS_ASSERTION(PR_CLIST_IS_EMPTY(this), "request still on a list");
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Accessors
|
||||
*/
|
||||
enum CacheRequestInfo {
|
||||
eStoragePolicyMask = 0x000000FF,
|
||||
eStreamBasedMask = 0x00000100,
|
||||
eDoomEntriesIfExpiredMask = 0x00001000,
|
||||
eWaitingForValidationMask = 0x00010000,
|
||||
eAccessRequestedMask = 0xFF000000
|
||||
};
|
||||
|
||||
void SetAccessRequested(nsCacheAccessMode mode)
|
||||
{
|
||||
NS_ASSERTION(mode <= 0xFF, "too many bits in nsCacheAccessMode");
|
||||
mInfo &= ~eAccessRequestedMask;
|
||||
mInfo |= mode << 24;
|
||||
}
|
||||
|
||||
nsCacheAccessMode AccessRequested()
|
||||
{
|
||||
return (nsCacheAccessMode)((mInfo >> 24) & 0xFF);
|
||||
}
|
||||
|
||||
void MarkStreamBased() { mInfo |= eStreamBasedMask; }
|
||||
PRBool IsStreamBased() { return (mInfo & eStreamBasedMask) != 0; }
|
||||
|
||||
|
||||
void MarkDoomEntriesIfExpired() { mInfo |= eDoomEntriesIfExpiredMask; }
|
||||
PRBool WillDoomEntriesIfExpired() { return (mInfo & eDoomEntriesIfExpiredMask); }
|
||||
|
||||
void SetStoragePolicy(nsCacheStoragePolicy policy)
|
||||
{
|
||||
NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
|
||||
mInfo &= ~eStoragePolicyMask; // clear storage policy bits
|
||||
mInfo |= policy; // or in new bits
|
||||
}
|
||||
|
||||
nsCacheStoragePolicy StoragePolicy()
|
||||
{
|
||||
return (nsCacheStoragePolicy)(mInfo & 0xFF);
|
||||
}
|
||||
|
||||
void MarkWaitingForValidation() { mInfo |= eWaitingForValidationMask; }
|
||||
void DoneWaitingForValidation() { mInfo &= ~eWaitingForValidationMask; }
|
||||
PRBool WaitingForValidation()
|
||||
{
|
||||
return (mInfo & eWaitingForValidationMask) != 0;
|
||||
}
|
||||
|
||||
nsresult
|
||||
WaitForValidation(void)
|
||||
{
|
||||
if (!WaitingForValidation()) { // flag already cleared
|
||||
MarkWaitingForValidation(); // set up for next time
|
||||
return NS_OK; // early exit;
|
||||
}
|
||||
|
||||
if (!mLock) {
|
||||
mLock = PR_NewLock();
|
||||
if (!mLock) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ASSERTION(!mCondVar,"we have mCondVar, but didn't have mLock?");
|
||||
mCondVar = PR_NewCondVar(mLock);
|
||||
if (!mCondVar) {
|
||||
PR_DestroyLock(mLock);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
PRStatus status;
|
||||
PR_Lock(mLock);
|
||||
while (WaitingForValidation() && (status == PR_SUCCESS) ) {
|
||||
status = PR_WaitCondVar(mCondVar, PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
MarkWaitingForValidation(); // set up for next time
|
||||
PR_Unlock(mLock);
|
||||
|
||||
NS_ASSERTION(status == PR_SUCCESS, "PR_WaitCondVar() returned PR_FAILURE?");
|
||||
if (status == PR_FAILURE)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void WakeUp(void) {
|
||||
DoneWaitingForValidation();
|
||||
if (mLock) {
|
||||
PR_Lock(mLock);
|
||||
PR_NotifyCondVar(mCondVar);
|
||||
PR_Unlock(mLock);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data members
|
||||
*/
|
||||
nsCString * mKey;
|
||||
PRUint32 mInfo;
|
||||
nsCOMPtr<nsICacheListener> mListener;
|
||||
nsCOMPtr<nsIEventQueue> mEventQ;
|
||||
PRLock * mLock;
|
||||
PRCondVar * mCondVar;
|
||||
};
|
||||
|
||||
#endif // _nsCacheRequest_h_
|
||||
1037
mozilla/netwerk/cache/src/nsCacheService.cpp
vendored
Normal file
1037
mozilla/netwerk/cache/src/nsCacheService.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
181
mozilla/netwerk/cache/src/nsCacheService.h
vendored
Normal file
181
mozilla/netwerk/cache/src/nsCacheService.h
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheService.h, released February 10, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _nsCacheService_h_
|
||||
#define _nsCacheService_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsICacheService.h"
|
||||
#include "nsCacheSession.h"
|
||||
#include "nsCacheDevice.h"
|
||||
#include "nsCacheEntry.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsCacheRequest;
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheService
|
||||
******************************************************************************/
|
||||
|
||||
class nsCacheService : public nsICacheService, public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHESERVICE
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
nsCacheService();
|
||||
virtual ~nsCacheService();
|
||||
|
||||
// Define a Create method to be used with a factory:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* outer, const nsIID& iid, void* *result);
|
||||
|
||||
|
||||
/**
|
||||
* Methods called by nsCacheSession
|
||||
*/
|
||||
nsresult OpenCacheEntry(nsCacheSession * session,
|
||||
const char * key,
|
||||
nsCacheAccessMode accessRequested,
|
||||
nsICacheListener * listener,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
/**
|
||||
* Methods called by nsCacheEntryDescriptor
|
||||
*/
|
||||
|
||||
nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
|
||||
|
||||
nsresult ValidateEntry(nsCacheEntry * entry);
|
||||
|
||||
nsresult GetTransportForEntry(nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport ** result);
|
||||
|
||||
void CloseDescriptor(nsCacheEntryDescriptor * descriptor);
|
||||
|
||||
nsresult GetFileForEntry(nsCacheEntry * entry,
|
||||
nsIFile ** result);
|
||||
|
||||
/**
|
||||
* Methods called by any cache classes
|
||||
*/
|
||||
|
||||
static
|
||||
nsCacheService * GlobalInstance(void) { return gService; };
|
||||
|
||||
nsresult DoomEntry(nsCacheEntry * entry);
|
||||
|
||||
nsresult DoomEntry_Locked(nsCacheEntry * entry);
|
||||
|
||||
/**
|
||||
* Methods called by nsCachePrefObserver
|
||||
*/
|
||||
void SetCacheDevicesEnabled(PRBool disk, PRBool memory);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Internal Methods
|
||||
*/
|
||||
|
||||
nsresult CreateDiskDevice();
|
||||
nsresult CreateMemoryDevice();
|
||||
|
||||
nsresult CreateRequest(nsCacheSession * session,
|
||||
const char * clientKey,
|
||||
nsCacheAccessMode accessRequested,
|
||||
nsICacheListener * listener,
|
||||
nsCacheRequest ** request);
|
||||
|
||||
nsresult NotifyListener(nsCacheRequest * request,
|
||||
nsICacheEntryDescriptor * descriptor,
|
||||
nsCacheAccessMode accessGranted,
|
||||
nsresult error);
|
||||
|
||||
nsresult ActivateEntry(nsCacheRequest * request, nsCacheEntry ** entry);
|
||||
|
||||
nsCacheDevice * EnsureEntryHasDevice(nsCacheEntry * entry);
|
||||
|
||||
nsCacheEntry * SearchCacheDevices(nsCString * key, nsCacheStoragePolicy policy);
|
||||
|
||||
void DeactivateEntry(nsCacheEntry * entry);
|
||||
|
||||
nsresult ProcessRequest(nsCacheRequest * request,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
nsresult ProcessPendingRequests(nsCacheEntry * entry);
|
||||
|
||||
void ClearPendingRequests(nsCacheEntry * entry);
|
||||
void ClearDoomList(void);
|
||||
void ClearActiveEntries(void);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK DeactivateAndClearEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
|
||||
/**
|
||||
* Data Members
|
||||
*/
|
||||
|
||||
enum {
|
||||
cacheServiceActiveMask = 1
|
||||
};
|
||||
|
||||
static nsCacheService * gService; // there can be only one...
|
||||
|
||||
PRLock* mCacheServiceLock;
|
||||
|
||||
PRBool mEnableMemoryDevice;
|
||||
PRBool mEnableDiskDevice;
|
||||
|
||||
nsCacheDevice * mMemoryDevice;
|
||||
nsCacheDevice * mDiskDevice;
|
||||
|
||||
// nsCacheClientHashTable mClientIDs;
|
||||
nsCacheEntryHashTable mActiveEntries;
|
||||
PRCList mDoomedEntries;
|
||||
|
||||
// stats
|
||||
PRUint32 mTotalEntries;
|
||||
PRUint32 mCacheHits;
|
||||
PRUint32 mCacheMisses;
|
||||
PRUint32 mMaxKeyLength;
|
||||
PRUint32 mMaxDataSize;
|
||||
PRUint32 mMaxMetaSize;
|
||||
|
||||
// Unexpected error totals
|
||||
PRUint32 mDeactivateFailures;
|
||||
PRUint32 mDeactivatedUnboundEntries;
|
||||
};
|
||||
|
||||
|
||||
#endif // _nsCacheService_h_
|
||||
101
mozilla/netwerk/cache/src/nsCacheSession.cpp
vendored
Normal file
101
mozilla/netwerk/cache/src/nsCacheSession.cpp
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheSession.h, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsCacheSession.h"
|
||||
#include "nsCacheService.h"
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsCacheSession, nsICacheSession)
|
||||
|
||||
nsCacheSession::nsCacheSession(const char * clientID,
|
||||
nsCacheStoragePolicy storagePolicy,
|
||||
PRBool streamBased)
|
||||
: mClientID(clientID),
|
||||
mInfo(0)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
SetStoragePolicy(storagePolicy);
|
||||
|
||||
if (streamBased) MarkStreamBased();
|
||||
else SetStoragePolicy(nsICache::STORE_IN_MEMORY);
|
||||
}
|
||||
|
||||
nsCacheSession::~nsCacheSession()
|
||||
{
|
||||
/* destructor code */
|
||||
// notify service we are going away?
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::GetDoomEntriesIfExpired(PRBool *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = WillDoomEntriesIfExpired();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::SetDoomEntriesIfExpired(PRBool doomEntriesIfExpired)
|
||||
{
|
||||
if (doomEntriesIfExpired) MarkDoomEntriesIfExpired();
|
||||
else ClearDoomEntriesIfExpired();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheSession::OpenCacheEntry(const char * key,
|
||||
nsCacheAccessMode accessRequested,
|
||||
nsICacheEntryDescriptor ** result)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsCacheService::GlobalInstance()->OpenCacheEntry(this,
|
||||
key,
|
||||
accessRequested,
|
||||
nsnull, // no listener
|
||||
result);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const char *key,
|
||||
nsCacheAccessMode accessRequested,
|
||||
nsICacheListener *listener)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsCacheService::GlobalInstance()->OpenCacheEntry(this,
|
||||
key,
|
||||
accessRequested,
|
||||
listener,
|
||||
nsnull); // no result
|
||||
|
||||
if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) rv = NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::EvictEntries()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
76
mozilla/netwerk/cache/src/nsCacheSession.h
vendored
Normal file
76
mozilla/netwerk/cache/src/nsCacheSession.h
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheSession.h, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheSession_h_
|
||||
#define _nsCacheSession_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsError.h"
|
||||
#include "nsICacheSession.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsCacheSession : public nsICacheSession
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHESESSION
|
||||
|
||||
nsCacheSession(const char * clientID, nsCacheStoragePolicy storagePolicy, PRBool streamBased);
|
||||
virtual ~nsCacheSession();
|
||||
|
||||
nsCString * ClientID() { return &mClientID; }
|
||||
|
||||
enum SessionInfo {
|
||||
eStoragePolicyMask = 0x000000FF,
|
||||
eStreamBasedMask = 0x00000100,
|
||||
eDoomEntriesIfExpiredMask = 0x00001000
|
||||
};
|
||||
|
||||
void MarkStreamBased() { mInfo |= eStreamBasedMask; }
|
||||
void ClearStreamBased() { mInfo &= ~eStreamBasedMask; }
|
||||
PRBool IsStreamBased() { return (mInfo & eStreamBasedMask) != 0; }
|
||||
|
||||
void MarkDoomEntriesIfExpired() { mInfo |= eDoomEntriesIfExpiredMask; }
|
||||
void ClearDoomEntriesIfExpired() { mInfo &= ~eDoomEntriesIfExpiredMask; }
|
||||
PRBool WillDoomEntriesIfExpired() { return (mInfo & eDoomEntriesIfExpiredMask); }
|
||||
|
||||
nsCacheStoragePolicy StoragePolicy()
|
||||
{
|
||||
return (nsCacheStoragePolicy)(mInfo & eStoragePolicyMask);
|
||||
}
|
||||
|
||||
void SetStoragePolicy(nsCacheStoragePolicy policy)
|
||||
{
|
||||
NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
|
||||
mInfo &= ~eStoragePolicyMask; // clear storage policy bits
|
||||
mInfo |= policy;
|
||||
}
|
||||
|
||||
private:
|
||||
nsCString mClientID;
|
||||
PRUint32 mInfo;
|
||||
};
|
||||
|
||||
#endif // _nsCacheSession_h_
|
||||
199
mozilla/netwerk/cache/src/nsDiskCache.h
vendored
Normal file
199
mozilla/netwerk/cache/src/nsDiskCache.h
vendored
Normal file
@@ -0,0 +1,199 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsCacheDevice.h, released March 9, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _nsDiskCache_h_
|
||||
#define _nsDiskCache_h_
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prnetdb.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
class nsDiskCacheRecord {
|
||||
enum {
|
||||
eEvictionRankMask = 0xFF000000,
|
||||
eLocationSelectorMask = 0x00C00000,
|
||||
|
||||
eExtraBlocksMask = 0x00300000,
|
||||
eBlockNumberMask = 0x000FFFFF,
|
||||
|
||||
eFileReservedMask = 0x003F0000,
|
||||
eFileGenerationMask = 0x0000FFFF
|
||||
};
|
||||
|
||||
public:
|
||||
nsDiskCacheRecord()
|
||||
: mHashNumber(0), mEvictionRank(0), mLocation(0), mUnused(0)
|
||||
{
|
||||
}
|
||||
|
||||
PRUint32 HashNumber()
|
||||
{
|
||||
return mHashNumber;
|
||||
}
|
||||
|
||||
void SetHashNumber(PRUint32 hashNumber)
|
||||
{
|
||||
mHashNumber = hashNumber;
|
||||
}
|
||||
|
||||
PRUint32 EvictionRank()
|
||||
{
|
||||
return mEvictionRank;
|
||||
}
|
||||
|
||||
void SetEvictionRank(PRUint32 rank)
|
||||
{
|
||||
mEvictionRank = rank;
|
||||
}
|
||||
|
||||
PRUint32 LocationSelector()
|
||||
{
|
||||
return (PRUint32)(mLocation & eLocationSelectorMask) >> 22;
|
||||
}
|
||||
|
||||
void SetLocationSelector(PRUint32 selector)
|
||||
{
|
||||
mLocation &= ~eLocationSelectorMask; // clear location selector bits
|
||||
mLocation |= (selector & eLocationSelectorMask) << 22;
|
||||
}
|
||||
|
||||
PRUint32 BlockCount()
|
||||
{
|
||||
return (PRUint32)((mLocation & eExtraBlocksMask) >> 20) + 1;
|
||||
}
|
||||
|
||||
void SetBlockCount(PRUint32 count)
|
||||
{
|
||||
NS_ASSERTION( (count>=1) && (count<=4),"invalid block count");
|
||||
count = --count;
|
||||
mLocation &= ~eExtraBlocksMask; // clear extra blocks bits
|
||||
mLocation |= (count & eExtraBlocksMask) << 20;
|
||||
}
|
||||
|
||||
PRUint32 BlockNumber()
|
||||
{
|
||||
return (mLocation & eBlockNumberMask);
|
||||
}
|
||||
|
||||
void SetBlockNumber(PRUint32 blockNumber)
|
||||
{
|
||||
mLocation &= ~eBlockNumberMask; // clear block number bits
|
||||
mLocation |= blockNumber & eBlockNumberMask;
|
||||
}
|
||||
|
||||
PRUint16 FileGeneration()
|
||||
{
|
||||
return (mLocation & eFileGenerationMask);
|
||||
}
|
||||
|
||||
void SetFileGeneration(PRUint16 generation)
|
||||
{
|
||||
mLocation &= ~eFileGenerationMask; // clear file generation bits
|
||||
mLocation |= generation & eFileGenerationMask;
|
||||
}
|
||||
|
||||
void Swap()
|
||||
{
|
||||
mHashNumber = ::PR_htonl(mHashNumber);
|
||||
mEvictionRank = ::PR_htonl(mEvictionRank);
|
||||
mLocation = ::PR_htonl(mLocation);
|
||||
mUnused = ::PR_htonl(mUnused);
|
||||
}
|
||||
|
||||
void Unswap()
|
||||
{
|
||||
mHashNumber = ::PR_ntohl(mHashNumber);
|
||||
mEvictionRank = ::PR_ntohl(mEvictionRank);
|
||||
mLocation = ::PR_ntohl(mLocation);
|
||||
mUnused = ::PR_ntohl(mUnused);
|
||||
}
|
||||
|
||||
private:
|
||||
PRUint32 mHashNumber;
|
||||
PRUint32 mEvictionRank;
|
||||
PRUint32 mLocation;
|
||||
PRUint32 mUnused;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Cache Extent Table
|
||||
|
||||
|
||||
1111 1111 0000 0000 0000 0000 0000 0000 : eEvictionRankMask
|
||||
0000 0000 1100 0000 0000 0000 0000 0000 : eLocationSelectorMask (0-3)
|
||||
0000 0000 0011 0000 0000 0000 0000 0000 : number of extra contiguous blocks 1-4
|
||||
0000 0000 0000 1111 1111 1111 1111 1111 : block# 0-1,048,575
|
||||
|
||||
0000 0000 0011 1111 0000 0000 0000 0000 : eFileReservedMask
|
||||
0000 0000 0000 0000 1111 1111 1111 1111 : eFileGenerationMask
|
||||
|
||||
0 file
|
||||
1 256 bytes
|
||||
2 1024
|
||||
3 4096
|
||||
|
||||
|
||||
log2 of seconds = 5 bits
|
||||
|
||||
log2 minutes hours days years
|
||||
00000 1
|
||||
00001 2
|
||||
00010 4
|
||||
00011 8
|
||||
00100 16
|
||||
00101 32
|
||||
00110 64 1
|
||||
00111 128 2
|
||||
01000 256 4
|
||||
01001 512 8.5
|
||||
01010 1024 17
|
||||
01011 2048 34
|
||||
01100 68
|
||||
01101 136
|
||||
01110 273 11
|
||||
01111 22
|
||||
10000 45.5
|
||||
10001 91
|
||||
10010 182
|
||||
10011 364 1
|
||||
10100 2
|
||||
10101 3
|
||||
10110 4
|
||||
10111
|
||||
11000
|
||||
11001
|
||||
11010
|
||||
11011
|
||||
11100
|
||||
11101
|
||||
11110
|
||||
11111
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#endif // _nsDiskCache_h_
|
||||
1573
mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp
vendored
Normal file
1573
mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
116
mozilla/netwerk/cache/src/nsDiskCacheDevice.h
vendored
Normal file
116
mozilla/netwerk/cache/src/nsDiskCacheDevice.h
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsDiskCacheDevice.h, released February 20, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsDiskCacheDevice_h_
|
||||
#define _nsDiskCacheDevice_h_
|
||||
|
||||
#include "nsCacheDevice.h"
|
||||
#include "nsDiskCacheEntry.h"
|
||||
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
class nsDiskCacheEntry;
|
||||
class nsDiskCacheMap;
|
||||
class nsDiskCacheRecord;
|
||||
|
||||
class nsISupportsArray;
|
||||
class nsIInputStream;
|
||||
class nsIOutputStream;
|
||||
|
||||
class nsDiskCacheDevice : public nsCacheDevice {
|
||||
public:
|
||||
nsDiskCacheDevice();
|
||||
virtual ~nsDiskCacheDevice();
|
||||
|
||||
static nsresult Create(nsCacheDevice **result);
|
||||
|
||||
virtual nsresult Init();
|
||||
virtual nsresult Shutdown();
|
||||
|
||||
virtual const char * GetDeviceID(void);
|
||||
virtual nsCacheEntry * FindEntry(nsCString * key);
|
||||
virtual nsresult DeactivateEntry(nsCacheEntry * entry);
|
||||
virtual nsresult BindEntry(nsCacheEntry * entry);
|
||||
virtual void DoomEntry( nsCacheEntry * entry );
|
||||
|
||||
virtual nsresult GetTransportForEntry(nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport ** result);
|
||||
|
||||
virtual nsresult GetFileForEntry(nsCacheEntry * entry,
|
||||
nsIFile ** result);
|
||||
|
||||
virtual nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
|
||||
|
||||
virtual nsresult Visit(nsICacheVisitor * visitor);
|
||||
|
||||
virtual nsresult EvictEntries(const char * clientID);
|
||||
|
||||
/* private: */
|
||||
void setPrefsObserver(nsIObserver* observer);
|
||||
void getPrefsObserver(nsIObserver ** result);
|
||||
void setCacheDirectory(nsILocalFile* directory);
|
||||
void setCacheCapacity(PRUint32 capacity);
|
||||
PRUint32 getCacheCapacity();
|
||||
PRUint32 getCacheSize();
|
||||
PRUint32 getEntryCount();
|
||||
|
||||
nsresult getFileForHashNumber(PLDHashNumber hashNumber, PRBool meta, PRUint32 generation, nsIFile ** result);
|
||||
nsresult getFileForKey(const char* key, PRBool meta, PRUint32 generation, nsIFile ** result);
|
||||
nsresult getFileForDiskCacheEntry(nsDiskCacheEntry * diskEntry, PRBool meta, nsIFile ** result);
|
||||
|
||||
static nsresult getTransportForFile(nsIFile* file, nsCacheAccessMode mode, nsITransport ** result);
|
||||
static nsresult openInputStream(nsIFile* file, nsIInputStream ** result);
|
||||
static nsresult openOutputStream(nsIFile* file, nsIOutputStream ** result);
|
||||
|
||||
nsresult visitEntries(nsICacheVisitor * visitory);
|
||||
|
||||
nsresult readDiskCacheEntry(const char * key, nsDiskCacheEntry ** diskEntry);
|
||||
|
||||
nsresult updateDiskCacheEntries();
|
||||
nsresult updateDiskCacheEntry(nsDiskCacheEntry * diskEntry);
|
||||
nsresult deleteDiskCacheEntry(nsDiskCacheEntry * diskEntry);
|
||||
|
||||
nsresult scavengeDiskCacheEntries(nsDiskCacheEntry * diskEntry);
|
||||
|
||||
nsresult scanDiskCacheEntries(nsISupportsArray ** result);
|
||||
nsresult evictDiskCacheEntries();
|
||||
|
||||
nsresult readCacheMap();
|
||||
nsresult writeCacheMap();
|
||||
|
||||
nsresult updateCacheMap(nsDiskCacheEntry * diskEntry);
|
||||
nsresult evictDiskCacheRecord(nsDiskCacheRecord * record);
|
||||
|
||||
private:
|
||||
PRBool mInitialized;
|
||||
nsCOMPtr<nsIObserver> mPrefsObserver;
|
||||
nsCOMPtr<nsILocalFile> mCacheDirectory;
|
||||
nsDiskCacheEntryHashTable mBoundEntries;
|
||||
PRUint32 mCacheCapacity;
|
||||
nsDiskCacheMap* mCacheMap;
|
||||
};
|
||||
|
||||
#endif // _nsDiskCacheDevice_h_
|
||||
213
mozilla/netwerk/cache/src/nsDiskCacheEntry.cpp
vendored
Normal file
213
mozilla/netwerk/cache/src/nsDiskCacheEntry.cpp
vendored
Normal file
@@ -0,0 +1,213 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsMemoryCacheDevice.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "nsDiskCacheEntry.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS0(nsDiskCacheEntry);
|
||||
|
||||
PLDHashNumber
|
||||
nsDiskCacheEntry::Hash(const char* key)
|
||||
{
|
||||
PLDHashNumber h = 0;
|
||||
for (const PRUint8* s = (PRUint8*) key; *s != '\0'; ++s)
|
||||
h = (h >> (PL_DHASH_BITS - 4)) ^ (h << 4) ^ *s;
|
||||
return (h == 0 ? ULONG_MAX : h);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryHashTable
|
||||
*****************************************************************************/
|
||||
|
||||
PLDHashTableOps nsDiskCacheEntryHashTable::ops =
|
||||
{
|
||||
PL_DHashAllocTable,
|
||||
PL_DHashFreeTable,
|
||||
GetKey,
|
||||
HashKey,
|
||||
MatchEntry,
|
||||
MoveEntry,
|
||||
ClearEntry,
|
||||
Finalize
|
||||
};
|
||||
|
||||
nsDiskCacheEntryHashTable::nsDiskCacheEntryHashTable()
|
||||
: initialized(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsDiskCacheEntryHashTable::~nsDiskCacheEntryHashTable()
|
||||
{
|
||||
if (initialized)
|
||||
PL_DHashTableFinish(&table);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheEntryHashTable::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
initialized = PL_DHashTableInit(&table, &ops, nsnull,
|
||||
sizeof(HashTableEntry), 512);
|
||||
|
||||
if (!initialized) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsDiskCacheEntry *
|
||||
nsDiskCacheEntryHashTable::GetEntry(const char * key)
|
||||
{
|
||||
return GetEntry(nsDiskCacheEntry::Hash(key));
|
||||
}
|
||||
|
||||
|
||||
nsDiskCacheEntry *
|
||||
nsDiskCacheEntryHashTable::GetEntry(PLDHashNumber key)
|
||||
{
|
||||
nsDiskCacheEntry * result = nsnull;
|
||||
NS_ASSERTION(initialized, "nsDiskCacheEntryHashTable not initialized");
|
||||
HashTableEntry * hashEntry;
|
||||
hashEntry = (HashTableEntry*) PL_DHashTableOperate(&table, (void*) key, PL_DHASH_LOOKUP);
|
||||
if (PL_DHASH_ENTRY_IS_BUSY(hashEntry)) {
|
||||
result = hashEntry->mDiskCacheEntry;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheEntryHashTable::AddEntry(nsDiskCacheEntry * entry)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(entry);
|
||||
NS_ASSERTION(initialized, "nsDiskCacheEntryHashTable not initialized");
|
||||
|
||||
HashTableEntry * hashEntry;
|
||||
hashEntry = (HashTableEntry *) PL_DHashTableOperate(&table,
|
||||
(void*) entry->getHashNumber(),
|
||||
PL_DHASH_ADD);
|
||||
if (!hashEntry) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(hashEntry->mDiskCacheEntry = entry);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsDiskCacheEntryHashTable::RemoveEntry(nsDiskCacheEntry * entry)
|
||||
{
|
||||
NS_ASSERTION(initialized, "nsDiskCacheEntryHashTable not initialized");
|
||||
NS_ASSERTION(entry, "### cacheEntry == nsnull");
|
||||
|
||||
(void) PL_DHashTableOperate(&table, (void*) entry->getHashNumber(), PL_DHASH_REMOVE);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsDiskCacheEntryHashTable::VisitEntries(Visitor *visitor)
|
||||
{
|
||||
PL_DHashTableEnumerate(&table, VisitEntry, visitor);
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::VisitEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * header,
|
||||
PRUint32 number,
|
||||
void * arg)
|
||||
{
|
||||
HashTableEntry* hashEntry = (HashTableEntry *) header;
|
||||
Visitor *visitor = (Visitor*) arg;
|
||||
return (visitor->VisitEntry(hashEntry->mDiskCacheEntry) ? PL_DHASH_NEXT : PL_DHASH_STOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash table operation callback functions
|
||||
*/
|
||||
const void * PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::GetKey(PLDHashTable * /*table*/, PLDHashEntryHdr * header)
|
||||
{
|
||||
HashTableEntry * hashEntry = (HashTableEntry *) header;
|
||||
return (void*) hashEntry->mDiskCacheEntry->getHashNumber();
|
||||
}
|
||||
|
||||
|
||||
PLDHashNumber PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::HashKey( PLDHashTable *table, const void *key)
|
||||
{
|
||||
return (PLDHashNumber) key;
|
||||
}
|
||||
|
||||
PRBool PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::MatchEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr * header,
|
||||
const void * key)
|
||||
{
|
||||
HashTableEntry * hashEntry = (HashTableEntry *) header;
|
||||
return (hashEntry->mDiskCacheEntry->getHashNumber() == (PLDHashNumber) key);
|
||||
}
|
||||
|
||||
void PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::MoveEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr * fromHeader,
|
||||
PLDHashEntryHdr * toHeader)
|
||||
{
|
||||
HashTableEntry * fromEntry = (HashTableEntry *) fromHeader;
|
||||
HashTableEntry * toEntry = (HashTableEntry *) toHeader;
|
||||
toEntry->keyHash = fromEntry->keyHash;
|
||||
toEntry->mDiskCacheEntry = fromEntry->mDiskCacheEntry;
|
||||
fromEntry->mDiskCacheEntry = nsnull;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::ClearEntry(PLDHashTable * /* table */,
|
||||
PLDHashEntryHdr * header)
|
||||
{
|
||||
HashTableEntry* hashEntry = (HashTableEntry *) header;
|
||||
hashEntry->keyHash = 0;
|
||||
NS_IF_RELEASE(hashEntry->mDiskCacheEntry);
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::Finalize(PLDHashTable * table)
|
||||
{
|
||||
(void) PL_DHashTableEnumerate(table, FreeCacheEntries, nsnull);
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::FreeCacheEntries(PLDHashTable * /* table */,
|
||||
PLDHashEntryHdr * header,
|
||||
PRUint32 number,
|
||||
void * arg)
|
||||
{
|
||||
HashTableEntry *entry = (HashTableEntry *) header;
|
||||
NS_IF_RELEASE(entry->mDiskCacheEntry);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
165
mozilla/netwerk/cache/src/nsDiskCacheEntry.h
vendored
Normal file
165
mozilla/netwerk/cache/src/nsDiskCacheEntry.h
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsMemoryCacheDevice.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsDiskCacheEntry_h_
|
||||
#define _nsDiskCacheEntry_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "pldhash.h"
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsCacheEntry.h"
|
||||
|
||||
#ifdef MOZ_NEW_CACHE_REUSE_TRANSPORTS
|
||||
#include "nsITransport.h"
|
||||
#endif
|
||||
|
||||
class nsDiskCacheEntry : public nsISupports, public PRCList {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsDiskCacheEntry(nsCacheEntry* entry)
|
||||
: mCacheEntry(entry),
|
||||
mGeneration(0)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
PR_INIT_CLIST(this);
|
||||
mHashNumber = Hash(entry->Key()->get());
|
||||
}
|
||||
|
||||
virtual ~nsDiskCacheEntry()
|
||||
{
|
||||
PR_REMOVE_LINK(this);
|
||||
}
|
||||
|
||||
#ifdef MOZ_NEW_CACHE_REUSE_TRANSPORTS
|
||||
/**
|
||||
* Maps a cache access mode to a cached nsITransport for that access
|
||||
* mode. We keep these cached to avoid repeated trips to the
|
||||
* file transport service.
|
||||
*/
|
||||
nsCOMPtr<nsITransport>& getTransport(nsCacheAccessMode mode)
|
||||
{
|
||||
return mTransports[mode - 1];
|
||||
}
|
||||
|
||||
nsCOMPtr<nsITransport>& getMetaTransport(nsCacheAccessMode mode)
|
||||
{
|
||||
return mMetaTransports[mode - 1];
|
||||
}
|
||||
#endif
|
||||
|
||||
nsCacheEntry* getCacheEntry()
|
||||
{
|
||||
return mCacheEntry;
|
||||
}
|
||||
|
||||
PRUint32 getGeneration()
|
||||
{
|
||||
return mGeneration;
|
||||
}
|
||||
|
||||
void setGeneration(PRUint32 generation)
|
||||
{
|
||||
mGeneration = generation;
|
||||
}
|
||||
|
||||
PLDHashNumber getHashNumber()
|
||||
{
|
||||
return mHashNumber;
|
||||
}
|
||||
|
||||
static PLDHashNumber Hash(const char* key);
|
||||
|
||||
private:
|
||||
#ifdef MOZ_NEW_CACHE_REUSE_TRANSPORTS
|
||||
nsCOMPtr<nsITransport> mTransports[3];
|
||||
nsCOMPtr<nsITransport> mMetaTransports[3];
|
||||
#endif
|
||||
nsCacheEntry* mCacheEntry;
|
||||
PRUint32 mGeneration;
|
||||
PLDHashNumber mHashNumber;
|
||||
};
|
||||
|
||||
class nsDiskCacheEntryHashTable {
|
||||
public:
|
||||
nsDiskCacheEntryHashTable();
|
||||
~nsDiskCacheEntryHashTable();
|
||||
|
||||
nsresult Init();
|
||||
|
||||
nsDiskCacheEntry * GetEntry(const char * key);
|
||||
nsDiskCacheEntry * GetEntry(PLDHashNumber key);
|
||||
nsresult AddEntry(nsDiskCacheEntry * entry);
|
||||
void RemoveEntry(nsDiskCacheEntry * entry);
|
||||
|
||||
class Visitor {
|
||||
public:
|
||||
virtual PRBool VisitEntry(nsDiskCacheEntry * entry) = 0;
|
||||
};
|
||||
|
||||
void VisitEntries(Visitor * visitor);
|
||||
|
||||
private:
|
||||
struct HashTableEntry : PLDHashEntryHdr {
|
||||
nsDiskCacheEntry * mDiskCacheEntry; // STRONG ref?
|
||||
};
|
||||
|
||||
// PLDHashTable operation callbacks
|
||||
static const void * PR_CALLBACK GetKey(PLDHashTable * table,
|
||||
PLDHashEntryHdr * entry);
|
||||
|
||||
static PLDHashNumber PR_CALLBACK HashKey(PLDHashTable * table,
|
||||
const void * key);
|
||||
|
||||
static PRBool PR_CALLBACK MatchEntry(PLDHashTable * table,
|
||||
const PLDHashEntryHdr * entry,
|
||||
const void * key);
|
||||
|
||||
static void PR_CALLBACK MoveEntry(PLDHashTable * table,
|
||||
const PLDHashEntryHdr * from,
|
||||
PLDHashEntryHdr * to);
|
||||
|
||||
static void PR_CALLBACK ClearEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * entry);
|
||||
|
||||
static void PR_CALLBACK Finalize(PLDHashTable *table);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK FreeCacheEntries(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK VisitEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
|
||||
// member variables
|
||||
static PLDHashTableOps ops;
|
||||
PLDHashTable table;
|
||||
PRBool initialized;
|
||||
};
|
||||
|
||||
#endif /* _nsDiskCacheEntry_h_ */
|
||||
163
mozilla/netwerk/cache/src/nsDiskCacheMap.cpp
vendored
Normal file
163
mozilla/netwerk/cache/src/nsDiskCacheMap.cpp
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsDiskCacheMap.cpp, released March 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsDiskCacheMap.h"
|
||||
#include "nsIFileStreams.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
nsDiskCacheMap::nsDiskCacheMap()
|
||||
{
|
||||
}
|
||||
|
||||
nsDiskCacheMap::~nsDiskCacheMap()
|
||||
{
|
||||
}
|
||||
|
||||
nsDiskCacheRecord* nsDiskCacheMap::GetRecord(PRUint32 hashNumber)
|
||||
{
|
||||
nsDiskCacheBucket& bucket = mBuckets[(hashNumber & (kBucketsPerTable - 1))];
|
||||
nsDiskCacheRecord* oldestRecord = &bucket.mRecords[0];
|
||||
|
||||
for (int r = 0; r < kRecordsPerBucket; ++r) {
|
||||
nsDiskCacheRecord* record = &bucket.mRecords[r];
|
||||
if (record->HashNumber() == 0 || record->HashNumber() == hashNumber)
|
||||
return record;
|
||||
if (record->EvictionRank() < oldestRecord->EvictionRank())
|
||||
oldestRecord = record;
|
||||
}
|
||||
// if we don't find an empty record, return the oldest record for eviction.
|
||||
return oldestRecord;
|
||||
}
|
||||
|
||||
void nsDiskCacheMap::DeleteRecord(PRUint32 hashNumber)
|
||||
{
|
||||
nsDiskCacheBucket& bucket = mBuckets[(hashNumber & (kBucketsPerTable - 1))];
|
||||
for (int r = 0; r < kRecordsPerBucket; ++r) {
|
||||
nsDiskCacheRecord* record = &bucket.mRecords[r];
|
||||
if (record->HashNumber() == hashNumber) {
|
||||
nsDiskCacheRecord* deletedRecord = record;
|
||||
nsDiskCacheRecord* lastRecord = nsnull;
|
||||
// XXX use binary search to find the end, much quicker.
|
||||
// find the last record, to fill in the deleted record.
|
||||
for (int j = r + 1; j < kRecordsPerBucket; ++j) {
|
||||
record = &bucket.mRecords[j];
|
||||
if (record->HashNumber() == 0) {
|
||||
lastRecord = record - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// copy the last record, to the newly deleted record.
|
||||
if (lastRecord && deletedRecord != lastRecord) {
|
||||
*deletedRecord = *lastRecord;
|
||||
deletedRecord = lastRecord;
|
||||
}
|
||||
// mark record as free.
|
||||
deletedRecord->SetHashNumber(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsDiskCacheMap::Read(nsIInputStream* input)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 count;
|
||||
|
||||
// read the header.
|
||||
rv = input->Read((char*)&mHeader, sizeof(mHeader), &count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mHeader.Unswap();
|
||||
|
||||
// validate the version.
|
||||
if (mHeader.mVersion != nsDiskCacheHeader::kCurrentVersion) return NS_ERROR_FAILURE;
|
||||
|
||||
// seek to beginning of first bucket.
|
||||
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(input, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, sizeof(nsDiskCacheBucket));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// read the buckets.
|
||||
rv = input->Read((char*)&mBuckets[1], sizeof(mBuckets) - sizeof(nsDiskCacheBucket), &count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// unswap all of the active records.
|
||||
for (int b = 1; b < kBucketsPerTable; ++b) {
|
||||
nsDiskCacheBucket& bucket = mBuckets[b];
|
||||
for (int r = 0; r < kRecordsPerBucket; ++r) {
|
||||
nsDiskCacheRecord* record = &bucket.mRecords[r];
|
||||
if (record->HashNumber() == 0)
|
||||
break;
|
||||
record->Unswap();
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDiskCacheMap::Write(nsIOutputStream* output)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 count;
|
||||
int b;
|
||||
|
||||
// swap all of the active records.
|
||||
for (b = 1; b < kBucketsPerTable; ++b) {
|
||||
nsDiskCacheBucket& bucket = mBuckets[b];
|
||||
for (int r = 0; r < kRecordsPerBucket; ++r) {
|
||||
nsDiskCacheRecord* record = &bucket.mRecords[r];
|
||||
if (record->HashNumber() == 0)
|
||||
break;
|
||||
record->Swap();
|
||||
}
|
||||
}
|
||||
|
||||
// write the buckets.
|
||||
rv = output->Write((char*)&mBuckets, sizeof(mBuckets), &count);
|
||||
|
||||
// unswap all of the active records.
|
||||
for (b = 1; b < kBucketsPerTable; ++b) {
|
||||
nsDiskCacheBucket& bucket = mBuckets[b];
|
||||
for (int r = 0; r < kRecordsPerBucket; ++r) {
|
||||
nsDiskCacheRecord* record = &bucket.mRecords[r];
|
||||
if (record->HashNumber() == 0)
|
||||
break;
|
||||
record->Unswap();
|
||||
}
|
||||
}
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// seek back to beginning of file.
|
||||
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(output, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// write the header.
|
||||
mHeader.Swap();
|
||||
rv = output->Write((char*)&mHeader, sizeof(mHeader), &count);
|
||||
mHeader.Unswap();
|
||||
|
||||
return rv;
|
||||
}
|
||||
90
mozilla/netwerk/cache/src/nsDiskCacheMap.h
vendored
Normal file
90
mozilla/netwerk/cache/src/nsDiskCacheMap.h
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsDiskCacheMap.h, released March 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsDiskCacheMap_h_
|
||||
|
||||
#include "nsDiskCache.h"
|
||||
#include "nsError.h"
|
||||
|
||||
class nsIInputStream;
|
||||
class nsIOutputStream;
|
||||
|
||||
struct nsDiskCacheHeader {
|
||||
enum { kCurrentVersion = 0x00010000 };
|
||||
|
||||
PRUint32 mVersion; // cache version.
|
||||
PRUint32 mDataSize; // size of cache in bytes.
|
||||
PRUint32 mEntryCount; // number of entries stored in cache.
|
||||
// XXX need a bitmap?
|
||||
|
||||
nsDiskCacheHeader()
|
||||
: mVersion(kCurrentVersion), mDataSize(0), mEntryCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
void Swap()
|
||||
{
|
||||
mVersion = ::PR_htonl(mVersion);
|
||||
mDataSize = ::PR_htonl(mDataSize);
|
||||
mEntryCount = ::PR_htonl(mEntryCount);
|
||||
}
|
||||
|
||||
void Unswap()
|
||||
{
|
||||
mVersion = ::PR_ntohl(mVersion);
|
||||
mDataSize = ::PR_ntohl(mDataSize);
|
||||
mEntryCount = ::PR_ntohl(mEntryCount);
|
||||
}
|
||||
};
|
||||
|
||||
// XXX initial capacity, enough for 8192 distint entries.
|
||||
class nsDiskCacheMap {
|
||||
public:
|
||||
nsDiskCacheMap();
|
||||
~nsDiskCacheMap();
|
||||
|
||||
PRUint32& DataSize() { return mHeader.mDataSize; }
|
||||
|
||||
PRUint32& EntryCount() { return mHeader.mEntryCount; }
|
||||
|
||||
nsDiskCacheRecord* GetRecord(PRUint32 hashNumber);
|
||||
void DeleteRecord(PRUint32 hashNumber);
|
||||
|
||||
nsresult Read(nsIInputStream* input);
|
||||
nsresult Write(nsIOutputStream* output);
|
||||
|
||||
enum {
|
||||
kRecordsPerBucket = 256,
|
||||
kBucketsPerTable = (1 << 5) // must be a power of 2!
|
||||
};
|
||||
|
||||
private:
|
||||
struct nsDiskCacheBucket {
|
||||
nsDiskCacheRecord mRecords[kRecordsPerBucket];
|
||||
};
|
||||
|
||||
nsDiskCacheHeader mHeader;
|
||||
nsDiskCacheBucket mBuckets[kBucketsPerTable];
|
||||
};
|
||||
|
||||
#endif // _nsDiskCacheMap_h_
|
||||
413
mozilla/netwerk/cache/src/nsMemoryCacheDevice.cpp
vendored
Normal file
413
mozilla/netwerk/cache/src/nsMemoryCacheDevice.cpp
vendored
Normal file
@@ -0,0 +1,413 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsMemoryCacheDevice.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#include "nsMemoryCacheDevice.h"
|
||||
#include "nsCacheService.h"
|
||||
#include "nsICacheService.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsICacheVisitor.h"
|
||||
#include "nsITransport.h"
|
||||
#include "signal.h"
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kStorageTransportCID, NS_STORAGETRANSPORT_CID);
|
||||
|
||||
const char *gMemoryDeviceID = "memory";
|
||||
const char *gMemoryCacheSizePref = "browser.cache.memory_cache_size";
|
||||
|
||||
|
||||
nsMemoryCacheDevice::nsMemoryCacheDevice()
|
||||
: mHardLimit(0),
|
||||
mSoftLimit(0),
|
||||
mTotalSize(0),
|
||||
mInactiveSize(0),
|
||||
mEntryCount(0),
|
||||
mMaxEntryCount(0)
|
||||
{
|
||||
PR_INIT_CLIST(&mEvictionList);
|
||||
}
|
||||
|
||||
nsMemoryCacheDevice::~nsMemoryCacheDevice()
|
||||
{
|
||||
#if DEBUG
|
||||
printf("### starting ~nsMemoryCacheDevice()\n");
|
||||
#endif
|
||||
// XXX dealloc all memory
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
prefs->UnregisterCallback(gMemoryCacheSizePref, MemoryCacheSizeChanged, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int PR_CALLBACK
|
||||
nsMemoryCacheDevice::MemoryCacheSizeChanged(const char * pref, void * closure)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 softLimit = 0;
|
||||
nsMemoryCacheDevice * device = (nsMemoryCacheDevice *)closure;
|
||||
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = prefs->GetIntPref(gMemoryCacheSizePref, (PRInt32 *)&softLimit);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
softLimit *= 1024; // convert k into bytes
|
||||
PRUint32 hardLimit = softLimit + 1024*1024*2; // XXX find better limit than +2Meg
|
||||
device->AdjustMemoryLimits(softLimit, hardLimit);
|
||||
|
||||
return 0; // XXX what are we supposed to return?
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = mMemCacheEntries.Init();
|
||||
|
||||
// set some default memory limits, in case prefs aren't available
|
||||
mSoftLimit = 1024 * 1024 * 3;
|
||||
mHardLimit = mSoftLimit + 1024 *1024 * 2;
|
||||
|
||||
// read user prefs for memory cache limits
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
rv = prefs->RegisterCallback(gMemoryCacheSizePref, MemoryCacheSizeChanged, this);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Initialize the pref
|
||||
MemoryCacheSizeChanged(gMemoryCacheSizePref, this);
|
||||
}
|
||||
|
||||
// Register as a memory pressure observer
|
||||
NS_WITH_SERVICE(nsIObserverService,
|
||||
observerService,
|
||||
NS_OBSERVERSERVICE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// XXX rv = observerServcie->AddObserver(this, NS_MEMORY_PRESSURE_TOPIC);
|
||||
}
|
||||
// Ignore failure of memory pressure registration
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::Shutdown()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const char *
|
||||
nsMemoryCacheDevice::GetDeviceID()
|
||||
{
|
||||
return gMemoryDeviceID;
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntry *
|
||||
nsMemoryCacheDevice::FindEntry(nsCString * key)
|
||||
{
|
||||
nsCacheEntry * entry = mMemCacheEntries.GetEntry(key);
|
||||
if (!entry) return nsnull;
|
||||
|
||||
// move entry to the tail of the eviction list
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
PR_APPEND_LINK(entry, &mEvictionList);
|
||||
|
||||
mInactiveSize -= entry->Size();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::DeactivateEntry(nsCacheEntry * entry)
|
||||
{
|
||||
if (entry->IsDoomed()) {
|
||||
#if debug
|
||||
// XXX verify we've removed it from mMemCacheEntries & eviction list
|
||||
#endif
|
||||
delete entry;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCacheEntry * ourEntry = mMemCacheEntries.GetEntry(entry->Key());
|
||||
NS_ASSERTION(ourEntry, "DeactivateEntry called for an entry we don't have!");
|
||||
NS_ASSERTION(entry == ourEntry, "entry doesn't match ourEntry");
|
||||
if (ourEntry != entry)
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
|
||||
mInactiveSize += entry->Size();
|
||||
EvictEntriesIfNecessary();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::BindEntry(nsCacheEntry * entry)
|
||||
{
|
||||
NS_ASSERTION(PR_CLIST_IS_EMPTY(entry),"entry is already on a list!");
|
||||
|
||||
// append entry to the eviction list
|
||||
PR_APPEND_LINK(entry, &mEvictionList);
|
||||
|
||||
// add entry to hashtable of mem cache entries
|
||||
nsresult rv = mMemCacheEntries.AddEntry(entry);
|
||||
if (NS_FAILED(rv)) {
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
return rv;
|
||||
}
|
||||
|
||||
// add size of entry to memory totals
|
||||
++mEntryCount;
|
||||
if (mMaxEntryCount < mEntryCount) mMaxEntryCount = mEntryCount;
|
||||
|
||||
mTotalSize += entry->Size();
|
||||
EvictEntriesIfNecessary();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsMemoryCacheDevice::DoomEntry(nsCacheEntry * entry)
|
||||
{
|
||||
// XXX debug code to verify we have entry
|
||||
mMemCacheEntries.RemoveEntry(entry);
|
||||
|
||||
// remove entry from our eviction list
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
|
||||
// adjust our totals
|
||||
mTotalSize -= entry->Size();
|
||||
mInactiveSize -= entry->Size();
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::GetTransportForEntry( nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport ** transport )
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(entry);
|
||||
NS_ENSURE_ARG_POINTER(transport);
|
||||
|
||||
nsCOMPtr<nsISupports> data;
|
||||
|
||||
nsresult rv = entry->GetData(getter_AddRefs(data));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (data)
|
||||
return CallQueryInterface(data, transport);
|
||||
else {
|
||||
// create a new transport for this entry
|
||||
rv = nsComponentManager::CreateInstance(kStorageTransportCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsITransport),
|
||||
(void **) transport);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
entry->SetData(*transport);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::GetFileForEntry( nsCacheEntry * entry,
|
||||
nsIFile ** result )
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize)
|
||||
{
|
||||
if (entry->IsStreamData()) {
|
||||
// we have the right to refuse or pre-evict
|
||||
}
|
||||
|
||||
// adjust our totals
|
||||
mTotalSize += deltaSize;
|
||||
|
||||
EvictEntriesIfNecessary();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsMemoryCacheDevice::AdjustMemoryLimits(PRUint32 softLimit, PRUint32 hardLimit)
|
||||
{
|
||||
mSoftLimit = softLimit;
|
||||
mHardLimit = hardLimit;
|
||||
EvictEntriesIfNecessary();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsMemoryCacheDevice::EvictEntriesIfNecessary(void)
|
||||
{
|
||||
nsCacheEntry * entry, * next;
|
||||
|
||||
if ((mTotalSize < mHardLimit) && (mInactiveSize < mSoftLimit))
|
||||
return;
|
||||
|
||||
// XXX implement more sophisticated eviction ordering
|
||||
|
||||
entry = (nsCacheEntry *)PR_LIST_HEAD(&mEvictionList);
|
||||
while (entry != &mEvictionList) {
|
||||
if (entry->IsInUse()) {
|
||||
entry = (nsCacheEntry *)PR_NEXT_LINK(entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
// remove entry from our hashtable
|
||||
mMemCacheEntries.RemoveEntry(entry);
|
||||
|
||||
// remove entry from the eviction list
|
||||
next = (nsCacheEntry *)PR_NEXT_LINK(entry);
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
|
||||
// update statistics
|
||||
PRUint32 memoryRecovered = entry->Size();
|
||||
mTotalSize -= memoryRecovered;
|
||||
mInactiveSize -= memoryRecovered;
|
||||
--mEntryCount;
|
||||
|
||||
delete entry;
|
||||
entry = next;
|
||||
|
||||
if ((mTotalSize < mHardLimit) && (mInactiveSize < mSoftLimit))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::Visit(nsICacheVisitor * visitor)
|
||||
{
|
||||
nsMemoryCacheDeviceInfo * deviceInfo = new nsMemoryCacheDeviceInfo(this);
|
||||
nsCOMPtr<nsICacheDeviceInfo> deviceRef(deviceInfo);
|
||||
if (!deviceInfo) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PRBool keepGoing;
|
||||
nsresult rv = visitor->VisitDevice(gMemoryDeviceID, deviceInfo, &keepGoing);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!keepGoing)
|
||||
return NS_OK;
|
||||
|
||||
nsCacheEntry * entry;
|
||||
nsCOMPtr<nsICacheEntryInfo> entryRef;
|
||||
|
||||
entry = (nsCacheEntry *)PR_LIST_HEAD(&mEvictionList);
|
||||
while (entry != &mEvictionList) {
|
||||
nsCacheEntryInfo * entryInfo = new nsCacheEntryInfo(entry);
|
||||
if (!entryInfo) return NS_ERROR_OUT_OF_MEMORY;
|
||||
entryRef = entryInfo;
|
||||
|
||||
rv = visitor->VisitEntry(gMemoryDeviceID, entryInfo, &keepGoing);
|
||||
entryInfo->DetachEntry();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!keepGoing) break;
|
||||
|
||||
entry = (nsCacheEntry *)PR_NEXT_LINK(entry);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::EvictEntries(const char * clientID)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsMemoryCacheDeviceInfo - for implementing about:cache
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsMemoryCacheDeviceInfo, nsICacheDeviceInfo);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetDescription(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = nsCRT::strdup("Memory cache device");
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetUsageReport(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = nsCRT::strdup("Memory cache usage report:");
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetEntryCount(PRUint32 * result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
// XXX compare calculated count vs. mEntryCount
|
||||
*result = mDevice->mEntryCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetTotalSize(PRUint32 * result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = mDevice->mTotalSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetMaximumSize(PRUint32 * result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = mDevice->mHardLimit;
|
||||
return NS_OK;
|
||||
}
|
||||
110
mozilla/netwerk/cache/src/nsMemoryCacheDevice.h
vendored
Normal file
110
mozilla/netwerk/cache/src/nsMemoryCacheDevice.h
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is nsMemoryCacheDevice.h, released February 20, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 20-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsMemoryCacheDevice_h_
|
||||
#define _nsMemoryCacheDevice_h_
|
||||
|
||||
#include "nsCacheDevice.h"
|
||||
#include "pldhash.h"
|
||||
#include "nsCacheEntry.h"
|
||||
|
||||
|
||||
class nsMemoryCacheDeviceInfo;
|
||||
|
||||
/******************************************************************************
|
||||
* nsMemoryCacheDevice
|
||||
******************************************************************************/
|
||||
class nsMemoryCacheDevice : public nsCacheDevice
|
||||
{
|
||||
public:
|
||||
nsMemoryCacheDevice();
|
||||
virtual ~nsMemoryCacheDevice();
|
||||
|
||||
virtual nsresult Init();
|
||||
virtual nsresult Shutdown();
|
||||
|
||||
virtual const char * GetDeviceID(void);
|
||||
|
||||
virtual nsresult BindEntry( nsCacheEntry * entry );
|
||||
virtual nsCacheEntry * FindEntry( nsCString * key );
|
||||
virtual void DoomEntry( nsCacheEntry * entry );
|
||||
virtual nsresult DeactivateEntry( nsCacheEntry * entry );
|
||||
|
||||
virtual nsresult GetTransportForEntry( nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport **transport );
|
||||
|
||||
virtual nsresult GetFileForEntry( nsCacheEntry * entry,
|
||||
nsIFile ** result );
|
||||
|
||||
virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize );
|
||||
|
||||
virtual nsresult Visit( nsICacheVisitor * visitor );
|
||||
|
||||
virtual nsresult EvictEntries(const char * clientID);
|
||||
|
||||
static int PR_CALLBACK MemoryCacheSizeChanged(const char * pref, void * closure);
|
||||
|
||||
private:
|
||||
friend class nsMemoryCacheDeviceInfo;
|
||||
void AdjustMemoryLimits(PRUint32 softLimit, PRUint32 hardLimit);
|
||||
void EvictEntriesIfNecessary(void);
|
||||
|
||||
nsCacheEntryHashTable mMemCacheEntries;
|
||||
PRCList mEvictionList;
|
||||
|
||||
PRUint32 mHardLimit;
|
||||
PRUint32 mSoftLimit;
|
||||
|
||||
PRUint32 mTotalSize;
|
||||
PRUint32 mInactiveSize;
|
||||
|
||||
PRUint32 mEntryCount;
|
||||
|
||||
PRUint32 mMaxEntryCount;
|
||||
// XXX what other stats do we want to keep?
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsMemoryCacheDeviceInfo - used to call nsIVisitor for about:cache
|
||||
******************************************************************************/
|
||||
class nsMemoryCacheDeviceInfo : public nsICacheDeviceInfo {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHEDEVICEINFO
|
||||
|
||||
nsMemoryCacheDeviceInfo(nsMemoryCacheDevice* device)
|
||||
: mDevice(device)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
virtual ~nsMemoryCacheDeviceInfo() {}
|
||||
|
||||
private:
|
||||
nsMemoryCacheDevice* mDevice;
|
||||
};
|
||||
|
||||
|
||||
#endif // _nsMemoryCacheDevice_h_
|
||||
BIN
mozilla/netwerk/macbuild/cache.mcp
Normal file
BIN
mozilla/netwerk/macbuild/cache.mcp
Normal file
Binary file not shown.
@@ -1,5 +0,0 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine on
|
||||
RewriteRule ^$ webroot/ [L]
|
||||
RewriteRule (.*) webroot/$1 [L]
|
||||
</IfModule>
|
||||
@@ -1,69 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: app_controller.php,v 1.1.1.1 2006-05-24 19:14:24 uid815 Exp $ */
|
||||
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* This file is application-wide controller file. You can put all
|
||||
* application-wide controller-related methods here.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake
|
||||
* @since CakePHP v 0.2.9
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-05-24 19:14:24 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
* Add your application-wide methods in the class below, your controllers
|
||||
* will inherit them.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake
|
||||
*/
|
||||
|
||||
uses('Sanitize');
|
||||
|
||||
class AppController extends Controller {
|
||||
|
||||
/**
|
||||
* This function is intended to be used with url parameters when passing them to
|
||||
* a view. (This is useful when echoing values out in <input> tags, etc.
|
||||
* Note that the keys to the arrays are escaped as well.
|
||||
*
|
||||
* @param array dirty parameters
|
||||
* @return array cleaned values
|
||||
*/
|
||||
function decodeAndSanitize($params)
|
||||
{
|
||||
$clean = array();
|
||||
|
||||
foreach ($params as $var => $val) {
|
||||
$var = $this->Sanitize->html(urldecode($var));
|
||||
$val = $this->Sanitize->html(urldecode($val));
|
||||
|
||||
$clean[$var] = $val;
|
||||
}
|
||||
|
||||
return $clean;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,72 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: app_model.php,v 1.1.1.1 2006-05-24 19:14:24 uid815 Exp $ */
|
||||
|
||||
/**
|
||||
* Application model for Cake.
|
||||
*
|
||||
* This file is application-wide model file. You can put all
|
||||
* application-wide model-related methods here.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake
|
||||
* @since CakePHP v 0.2.9
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-05-24 19:14:24 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Application model for Cake.
|
||||
*
|
||||
* Add your application-wide methods in the class below, your models
|
||||
* will inherit them.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.cake
|
||||
*/
|
||||
|
||||
uses('sanitize');
|
||||
|
||||
class AppModel extends Model {
|
||||
|
||||
/**
|
||||
* Will clean arrays for input into SQL.
|
||||
* Note that the array keys are getting cleaned here as well. If you're using strings
|
||||
* (with escapable characters in them) as keys to your array, be extra careful.
|
||||
*
|
||||
* @access public
|
||||
* @param array to be cleaned
|
||||
* @return array with sql escaped
|
||||
*/
|
||||
function cleanArrayForSql($array)
|
||||
{
|
||||
$sanitize = new Sanitize();
|
||||
$clean = array();
|
||||
|
||||
foreach ($array as $var => $val)
|
||||
{
|
||||
$var = $sanitize->sql($var);
|
||||
$val = $sanitize->sql($val);
|
||||
$clean[$var] = $val;
|
||||
}
|
||||
|
||||
return $clean;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,76 +0,0 @@
|
||||
;<?php die() ?>
|
||||
; SVN FILE: $Id: acl.ini.php,v 1.1.1.1 2006-05-24 19:14:24 uid815 Exp $
|
||||
;/**
|
||||
; * Short description for file.
|
||||
; *
|
||||
; *
|
||||
; * PHP versions 4 and 5
|
||||
; *
|
||||
; * CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
; * Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
; * 1785 E. Sahara Avenue, Suite 490-204
|
||||
; * Las Vegas, Nevada 89104
|
||||
; *
|
||||
; * Licensed under The MIT License
|
||||
; * Redistributions of files must retain the above copyright notice.
|
||||
; *
|
||||
; * @filesource
|
||||
; * @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
; * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
; * @package cake
|
||||
; * @subpackage cake.app.config
|
||||
; * @since CakePHP v 0.10.0.1076
|
||||
; * @version $Revision: 1.1.1.1 $
|
||||
; * @modifiedby $LastChangedBy: phpnut $
|
||||
; * @lastmodified $Date: 2006-05-24 19:14:24 $
|
||||
; * @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
; */
|
||||
|
||||
; acl.ini.php - Cake ACL Configuration
|
||||
; ---------------------------------------------------------------------
|
||||
; Use this file to specify user permissions.
|
||||
; aco = access control object (something in your application)
|
||||
; aro = access request object (something requesting access)
|
||||
;
|
||||
; User records are added as follows:
|
||||
;
|
||||
; [uid]
|
||||
; groups = group1, group2, group3
|
||||
; allow = aco1, aco2, aco3
|
||||
; deny = aco4, aco5, aco6
|
||||
;
|
||||
; Group records are added in a similar manner:
|
||||
;
|
||||
; [gid]
|
||||
; allow = aco1, aco2, aco3
|
||||
; deny = aco4, aco5, aco6
|
||||
;
|
||||
; The allow, deny, and groups sections are all optional.
|
||||
; NOTE: groups names *cannot* ever be the same as usernames!
|
||||
;
|
||||
; ACL permissions are checked in the following order:
|
||||
; 1. Check for user denies (and DENY if specified)
|
||||
; 2. Check for user allows (and ALLOW if specified)
|
||||
; 3. Gather user's groups
|
||||
; 4. Check group denies (and DENY if specified)
|
||||
; 5. Check group allows (and ALLOW if specified)
|
||||
; 6. If no aro, aco, or group information is found, DENY
|
||||
;
|
||||
; ---------------------------------------------------------------------
|
||||
|
||||
;-------------------------------------
|
||||
;Users
|
||||
;-------------------------------------
|
||||
|
||||
[username-goes-here]
|
||||
groups = group1, group2
|
||||
deny = aco1, aco2
|
||||
allow = aco3, aco4
|
||||
|
||||
;-------------------------------------
|
||||
;Groups
|
||||
;-------------------------------------
|
||||
|
||||
[groupname-goes-here]
|
||||
deny = aco5, aco6
|
||||
allow = aco7, aco8
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: bootstrap.php,v 1.1.1.1 2006-05-24 19:14:24 uid815 Exp $ */
|
||||
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 0.10.8.2117
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-05-24 19:14:24 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* This file is loaded automatically by the app/webroot/index.php file after the core bootstrap.php is loaded
|
||||
* This is an application wide file to load any function that is not used within a class define.
|
||||
* You can also use this to include or require any files in your application.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* The settings below can be used to set additional paths to models, views and controllers.
|
||||
* This is related to Ticket #470 (https://trac.cakephp.org/ticket/470)
|
||||
*
|
||||
* $modelPaths = array('full path to models', 'second full path to models', 'etc...');
|
||||
* $viewPaths = array('this path to views', 'second full path to views', 'etc...');
|
||||
* $controllerPaths = array('this path to controllers', 'second full path to controllers', 'etc...');
|
||||
*
|
||||
*/
|
||||
|
||||
//EOF
|
||||
?>
|
||||
@@ -1,153 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: core.php,v 1.1.1.1 2006-05-24 19:14:24 uid815 Exp $ */
|
||||
|
||||
/**
|
||||
* This is core configuration file.
|
||||
*
|
||||
* Use it to configure core behaviour ofCake.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 0.2.9
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-05-24 19:14:24 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* If you do not have mod rewrite on your system
|
||||
* or if you prefer to use CakePHP pretty urls.
|
||||
* uncomment the line below.
|
||||
* Note: If you do have mod rewrite but prefer the
|
||||
* CakePHP pretty urls, you also have to remove the
|
||||
* .htaccess files
|
||||
* release/.htaccess
|
||||
* release/app/.htaccess
|
||||
* release/app/webroot/.htaccess
|
||||
*/
|
||||
//define ('BASE_URL', env('SCRIPT_NAME'));
|
||||
|
||||
/**
|
||||
* Set debug level here:
|
||||
* - 0: production
|
||||
* - 1: development
|
||||
* - 2: full debug with sql
|
||||
* - 3: full debug with sql and dump of the current object
|
||||
*
|
||||
* In production, the "flash messages" redirect after a time interval.
|
||||
* With the other debug levels you get to click the "flash message" to continue.
|
||||
*
|
||||
*/
|
||||
define('DEBUG', 0);
|
||||
/**
|
||||
* Turn of caching checking wide.
|
||||
* You must still use the controller var cacheAction inside you controller class.
|
||||
* You can either set it controller wide, or in each controller method.
|
||||
* use var $cacheAction = true; or in the controller method $this->cacheAction = true;
|
||||
*/
|
||||
define ('CACHE_CHECK', false);
|
||||
/**
|
||||
* Error constant. Used for differentiating error logging and debugging.
|
||||
* Currently PHP supports LOG_DEBUG
|
||||
*/
|
||||
define ('LOG_ERROR', 2);
|
||||
/**
|
||||
* CakePHP includes 3 types of session saves
|
||||
* database or file. Set this to your preferred method.
|
||||
* If you want to use your own save handler place it in
|
||||
* app/config/name.php DO NOT USE file or database as the name.
|
||||
* and use just the name portion below.
|
||||
*
|
||||
* Setting this to cake will save files to /cakedistro/tmp directory
|
||||
* Setting it to php will use the php default save path
|
||||
* Setting it to database will use the database
|
||||
*
|
||||
*
|
||||
*/
|
||||
define('CAKE_SESSION_SAVE', 'php');
|
||||
/**
|
||||
* Set a random string of used in session.
|
||||
*
|
||||
*/
|
||||
define('CAKE_SESSION_STRING', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
|
||||
/**
|
||||
* Set the name of session cookie
|
||||
*
|
||||
*/
|
||||
define('CAKE_SESSION_COOKIE', 'CAKEPHP');
|
||||
|
||||
/**
|
||||
* Set level of Cake security.
|
||||
*
|
||||
*/
|
||||
define('CAKE_SECURITY', 'high');
|
||||
|
||||
/**
|
||||
* Set Cake Session time out.
|
||||
* If CAKE_SECURITY define is set
|
||||
* high: multiplied by 10
|
||||
* medium: is multiplied by 100
|
||||
* low is: multiplied by 300
|
||||
*
|
||||
* Number below is seconds.
|
||||
*/
|
||||
define('CAKE_SESSION_TIMEOUT', '120');
|
||||
|
||||
/**
|
||||
* Uncomment the define below to use cake built in admin routes.
|
||||
* You can set this value to anything you want.
|
||||
* All methods related to the admin route should be prefixed with the
|
||||
* name you set CAKE_ADMIN to.
|
||||
* For example: admin_index, admin_edit
|
||||
*/
|
||||
//define('CAKE_ADMIN', 'admin');
|
||||
|
||||
/**
|
||||
* The define below is used to turn cake built webservices
|
||||
* on or off. Default setting is off.
|
||||
*/
|
||||
define('WEBSERVICES', 'off');
|
||||
|
||||
/**
|
||||
* Compress output CSS (removing comments, whitespace, repeating tags etc.)
|
||||
* This requires a/var/cache directory to be writable by the web server (caching).
|
||||
* To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use Controller::cssTag().
|
||||
*/
|
||||
define('COMPRESS_CSS', false);
|
||||
|
||||
/**
|
||||
* If set to true, helpers would output data instead of returning it.
|
||||
*/
|
||||
define('AUTO_OUTPUT', false);
|
||||
|
||||
/**
|
||||
* If set to false, session would not automatically be started.
|
||||
*/
|
||||
define('AUTO_SESSION', true);
|
||||
|
||||
/**
|
||||
* Set the max size of file to use md5() .
|
||||
*/
|
||||
define('MAX_MD5SIZE', (5*1024)*1024 );
|
||||
|
||||
/**
|
||||
* To use Access Control Lists with Cake...
|
||||
*/
|
||||
define('ACL_CLASSNAME', 'DB_ACL');
|
||||
define('ACL_FILENAME', 'dbacl'.DS.'db_acl');
|
||||
|
||||
?>
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: database.php.default,v 1.1.1.1 2006-05-24 19:14:24 uid815 Exp $ */
|
||||
|
||||
/**
|
||||
* This is core configuration file.
|
||||
*
|
||||
* Use it to configure core behaviour ofCake.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 0.2.9
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-05-24 19:14:24 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* In this file you set up your database connection details.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.config
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Database configuration class.
|
||||
* You can specify multiple configurations for production, development and testing.
|
||||
*
|
||||
* driver =>
|
||||
* mysql, postgres, sqlite, adodb-drivername, pear-drivername
|
||||
*
|
||||
* connect =>
|
||||
* MySQL set the connect to either mysql_pconnect of mysql_connect
|
||||
* PostgreSQL set the connect to either pg_pconnect of pg_connect
|
||||
* SQLite set the connect to sqlite_popen sqlite_open
|
||||
* ADOdb set the connect to one of these
|
||||
* (http://phplens.com/adodb/supported.databases.html) and
|
||||
* append it '|p' for persistent connection. (mssql|p for example, or just mssql for not persistent)
|
||||
*
|
||||
* host =>
|
||||
* the host you connect to the database
|
||||
* MySQL 'localhost' to add a port number use 'localhost:port#'
|
||||
* PostgreSQL 'localhost' to add a port number use 'localhost port=5432'
|
||||
*
|
||||
*/
|
||||
class DATABASE_CONFIG
|
||||
{
|
||||
var $default = array('driver' => 'mysql',
|
||||
'connect' => 'mysql_connect',
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
'password' => 'password',
|
||||
'database' => 'project_name',
|
||||
'prefix' => '');
|
||||
|
||||
var $test = array('driver' => 'mysql',
|
||||
'connect' => 'mysql_connect',
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
'password' => 'password',
|
||||
'database' => 'project_name-test',
|
||||
'prefix' => '');
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: inflections.php,v 1.1.1.1 2006-05-24 19:14:24 uid815 Exp $ */
|
||||
|
||||
/**
|
||||
* Custom Inflected Words.
|
||||
*
|
||||
* This file is used to hold words that are not matched in the normail Inflector::pluralize() and
|
||||
* Inflector::singularize()
|
||||
*
|
||||
* PHP versions 4 and %
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 1.0.0.2312
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-05-24 19:14:24 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a key => value array of regex used to match words.
|
||||
* If key matches then the value is returned.
|
||||
*
|
||||
* $pluralRules = array('/(s)tatus$/i' => '\1\2tatuses', '/^(ox)$/i' => '\1\2en', '/([m|l])ouse$/i' => '\1ice');
|
||||
*/
|
||||
$pluralRules = array();
|
||||
/**
|
||||
* This is a key only array of plural words that should not be inflected.
|
||||
* Notice the last comma
|
||||
*
|
||||
* $uninflectedPlural = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox');
|
||||
*/
|
||||
$uninflectedPlural = array();
|
||||
/**
|
||||
* This is a key => value array of plural irregular words.
|
||||
* If key matches then the value is returned.
|
||||
*
|
||||
* $irregularPlural = array('atlas' => 'atlases', 'beef' => 'beefs', 'brother' => 'brothers')
|
||||
*/
|
||||
$irregularPlural = array();
|
||||
/**
|
||||
* This is a key => value array of regex used to match words.
|
||||
* If key matches then the value is returned.
|
||||
*
|
||||
* $singularRules = array('/(s)tatuses$/i' => '\1\2tatus', '/(matr)ices$/i' =>'\1ix','/(vert|ind)ices$/i')
|
||||
*/
|
||||
$singularRules = array();
|
||||
/**
|
||||
* This is a key only array of singular words that should not be inflected.
|
||||
* You should not have to change this value below if you do change it use same format
|
||||
* as the $uninflectedPlural above.
|
||||
*/
|
||||
$uninflectedSingular = $uninflectedPlural;
|
||||
/**
|
||||
* This is a key => value array of singular irregular words.
|
||||
* Most of the time this will be a reverse of the above $irregularPlural array
|
||||
* You should not have to change this value below if you do change it use same format
|
||||
*
|
||||
* $irregularSingular = array('atlases' => 'atlas', 'beefs' => 'beef', 'brothers' => 'brother')
|
||||
*/
|
||||
$irregularSingular = array_flip($irregularPlural);
|
||||
?>
|
||||
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: routes.php,v 1.1.1.1 2006-05-24 19:14:24 uid815 Exp $ */
|
||||
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* In this file, you set up routes to your controllers and their actions.
|
||||
* Routes are very important mechanism that allows you to freely connect
|
||||
* different urls to chosen controllers and their actions (functions).
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 0.2.9
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-05-24 19:14:24 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Here, we are connecting '/' (base path) to controller called 'Pages',
|
||||
* its action called 'display', and we pass a param to select the view file
|
||||
* to use (in this case, /app/views/pages/home.thtml)...
|
||||
*/
|
||||
$Route->connect ('/', array('controller'=>'results', 'action'=>'', ''));
|
||||
|
||||
/**
|
||||
* ...and connect the rest of 'Pages' controller's urls.
|
||||
*/
|
||||
$Route->connect ('/pages/*', array('controller'=>'pages', 'action'=>'display'));
|
||||
|
||||
/**
|
||||
* Then we connect url '/test' to our test controller. This is helpfull in
|
||||
* developement.
|
||||
*/
|
||||
$Route->connect ('/tests', array('controller'=>'tests', 'action'=>'index'));
|
||||
|
||||
?>
|
||||
@@ -1,30 +0,0 @@
|
||||
CREATE TABLE `acos` (
|
||||
`id` int(11) NOT NULL auto_increment,
|
||||
`model` varchar(255) NOT NULL default '',
|
||||
`object_id` int(11) default NULL,
|
||||
`alias` varchar(255) NOT NULL default '',
|
||||
`lft` int(11) default NULL,
|
||||
`rght` int(11) default NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE `aros` (
|
||||
`id` int(11) NOT NULL auto_increment,
|
||||
`model` varchar(255) NOT NULL default '',
|
||||
`user_id` int(11) default NULL,
|
||||
`alias` varchar(255) NOT NULL default '',
|
||||
`lft` int(11) default NULL,
|
||||
`rght` int(11) default NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE `aros_acos` (
|
||||
`id` int(11) NOT NULL auto_increment,
|
||||
`aro_id` int(11) default NULL,
|
||||
`aco_id` int(11) default NULL,
|
||||
`_create` int(1) NOT NULL default '0',
|
||||
`_read` int(1) NOT NULL default '0',
|
||||
`_update` int(1) NOT NULL default '0',
|
||||
`_delete` int(11) NOT NULL default '0',
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
@@ -1,11 +0,0 @@
|
||||
-- @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
-- @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
-- @since CakePHP v 0.10.8.1997
|
||||
-- @version $Revision: 1.1.1.1 $
|
||||
|
||||
CREATE TABLE cake_sessions (
|
||||
id varchar(255) NOT NULL default '',
|
||||
data text,
|
||||
expires int(11) default NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
class ApplicationsController extends AppController {
|
||||
|
||||
var $name = 'Applications';
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
class IntentionsController extends AppController {
|
||||
|
||||
var $name = 'Intentions';
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
class IssuesController extends AppController {
|
||||
|
||||
var $name = 'Issues';
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -1,122 +0,0 @@
|
||||
<?php
|
||||
|
||||
/* Include the CSV library. It would be nice to make this OO sometime */
|
||||
vendor('csv/csv');
|
||||
|
||||
class ResultsController extends AppController {
|
||||
|
||||
var $name = 'Results';
|
||||
|
||||
/**
|
||||
* Model's this controller uses
|
||||
* @var array
|
||||
*/
|
||||
var $uses = array('Application','Result');
|
||||
|
||||
/**
|
||||
* Cake Helpers
|
||||
* @var array
|
||||
*/
|
||||
var $helpers = array('Html', 'Javascript', 'Export', 'Pagination','Time');
|
||||
|
||||
/**
|
||||
* Pagination helper variable array
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
var $pagination_parameters = array();
|
||||
|
||||
/**
|
||||
* Will hold a sanitize object
|
||||
* @var object
|
||||
*/
|
||||
var $Sanitize;
|
||||
|
||||
/**
|
||||
* Constructor - sets up the sanitizer and the pagination
|
||||
*/
|
||||
function ResultsController()
|
||||
{
|
||||
parent::AppController();
|
||||
|
||||
$this->Sanitize = new Sanitize();
|
||||
|
||||
// Pagination Stuff
|
||||
$this->pagination_parameters['show'] = empty($_GET['show'])? '10' : $this->Sanitize->paranoid($_GET['show']);
|
||||
$this->pagination_parameters['sortBy'] = empty($_GET['sort'])? 'created' : $this->Sanitize->paranoid($_GET['sort']);
|
||||
$this->pagination_parameters['direction'] = empty($_GET['direction'])? 'desc': $this->Sanitize->paranoid($_GET['direction']);
|
||||
$this->pagination_parameters['page'] = empty($_GET['page'])? '1': $this->Sanitize->paranoid($_GET['page']);
|
||||
$this->pagination_parameters['order'] = $this->modelClass.'.'.$this->pagination_parameters['sortBy'].' '.strtoupper($this->pagination_parameters['direction']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Front page will show the graph
|
||||
*/
|
||||
function index()
|
||||
{
|
||||
// Products dropdown
|
||||
$this->set('products', $this->Application->getApplications());
|
||||
|
||||
// Fill in all the data passed in $_GET
|
||||
$this->set('url_params',$this->decodeAndSanitize($this->params['url']));
|
||||
|
||||
// We'll need to include the graphing libraries
|
||||
$this->set('include_graph_libraries', true);
|
||||
|
||||
// Core data to show on page
|
||||
$this->set('descriptionAndTotalsData',$this->Result->getDescriptionAndTotalsData($this->params['url']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a table of user comments
|
||||
*/
|
||||
function comments()
|
||||
{
|
||||
// Products dropdown
|
||||
$this->set('products', $this->Application->getApplications());
|
||||
|
||||
// Fill in all the data passed in $_GET
|
||||
$this->set('url_params',$this->decodeAndSanitize($this->params['url']));
|
||||
|
||||
// Pagination settings
|
||||
$paging['style'] = 'html';
|
||||
$paging['link'] = "/results/comments/?product=".urlencode($this->params['url']['product'])."&start_date=".urlencode($this->params['url']['start_date'])."&end_date=".urlencode($this->params['url']['end_date'])."&show={$this->pagination_parameters['show']}&sort={$this->pagination_parameters['sortBy']}&direction={$this->pagination_parameters['direction']}&page=";
|
||||
$paging['count'] = $this->Result->getCommentCount($this->params['url']);
|
||||
$paging['page'] = $this->pagination_parameters['page'];
|
||||
$paging['limit'] = $this->pagination_parameters['show'];
|
||||
$paging['show'] = array('10','25','50');
|
||||
|
||||
// No point in showing them an error if they click on "show 50" but they are
|
||||
// already on the last page.
|
||||
if ($paging['count'] < ($this->pagination_parameters['page'] * ($this->pagination_parameters['show']/2))) {
|
||||
$this->pagination_parameters['page'] = $paging['page'] = 1;
|
||||
}
|
||||
|
||||
// Set pagination array
|
||||
$this->set('paging',$paging);
|
||||
|
||||
// Core data to show on page
|
||||
$this->set('commentsData',$this->Result->getComments($this->params['url'], $this->pagination_parameters));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a csv
|
||||
*/
|
||||
function csv()
|
||||
{
|
||||
// Get rid of the header/footer/etc.
|
||||
$this->layout = null;
|
||||
|
||||
// Our CSV library sends headers and everything. Keep the view empty!
|
||||
csv_send_csv($this->Result->getCsvExportData($this->params['url']));
|
||||
|
||||
// I'm not exiting here in case someone is going to use post callback stuff.
|
||||
// In development, that means extra lines get added to our CSVs, but in
|
||||
// production it should be clean.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: index.php,v 1.1.1.1 2006-05-24 19:14:24 uid815 Exp $ */
|
||||
|
||||
/**
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app
|
||||
* @since CakePHP v 0.10.0.1076
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-05-24 19:14:24 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
require 'webroot'.DIRECTORY_SEPARATOR.'index.php';
|
||||
?>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
class Application extends AppModel {
|
||||
var $name = 'Application';
|
||||
|
||||
var $hasOne = array('Result');
|
||||
|
||||
var $hasAndBelongsToMany = array(
|
||||
'Intention' => array('className' => 'Intention'),
|
||||
'Issue' => array('className' => 'Issue')
|
||||
);
|
||||
|
||||
/**
|
||||
* This was added because running findAll() on this model does a left join on the
|
||||
* results table which takes around 10 seconds to grab all the data. All I want
|
||||
* is a list of the applications...
|
||||
*
|
||||
* @return array rows representing each application
|
||||
*/
|
||||
function getApplications()
|
||||
{
|
||||
return $this->query('SELECT * FROM `applications` ORDER BY `id`');
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,12 +0,0 @@
|
||||
<?php
|
||||
class Intention extends AppModel {
|
||||
var $name = 'Intention';
|
||||
|
||||
var $hasOne = array('Result');
|
||||
|
||||
var $hasAndBelongsToMany = array('Application' =>
|
||||
array('className' => 'Application')
|
||||
);
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
class Issue extends AppModel {
|
||||
var $name = 'Issue';
|
||||
|
||||
var $hasAndBelongsToMany = array(
|
||||
'Application' => array('className' => 'Application'),
|
||||
'Result' => array('className' => 'Result')
|
||||
);
|
||||
}
|
||||
?>
|
||||
@@ -1,339 +0,0 @@
|
||||
<?php
|
||||
class Result extends AppModel {
|
||||
var $name = 'Result';
|
||||
|
||||
var $belongsTo = array('Application', 'Intention');
|
||||
|
||||
var $hasAndBelongsToMany = array('Issue' =>
|
||||
array('className' => 'Issue')
|
||||
);
|
||||
|
||||
/**
|
||||
* Count's all the comments, according to the parameters.
|
||||
* @param array URL parameters
|
||||
* @return Cake's findCount() value
|
||||
*/
|
||||
function getCommentCount($params)
|
||||
{
|
||||
// Clean parameters
|
||||
$params = $this->cleanArrayForSql($params);
|
||||
|
||||
// We only want to see rows with comments
|
||||
$_conditions = array("comments NOT LIKE ''");
|
||||
|
||||
if (!empty($params['start_date'])) {
|
||||
$_timestamp = strtotime($params['start_date']);
|
||||
|
||||
if (!($_timestamp == -1) || $_timestamp == false) {
|
||||
$_date = date('Y-m-d H:i:s', $_timestamp);//sql format
|
||||
array_push($_conditions, "`created` >= '{$_date}'");
|
||||
}
|
||||
}
|
||||
if (!empty($params['end_date'])) {
|
||||
$_timestamp = strtotime($params['end_date']);
|
||||
|
||||
if (!($_timestamp == -1) || $_timestamp == false) {
|
||||
$_date = date('Y-m-d H:i:s', $_timestamp);//sql format
|
||||
array_push($_conditions, "`created` <= '{$_date}'");
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['product'])) {
|
||||
// product's come in looking like:
|
||||
// Mozilla Firefox 1.5.0.1
|
||||
$_exp = explode(' ',urldecode($params['product']));
|
||||
|
||||
if(count($_exp) == 3) {
|
||||
$_product = $_exp[0].' '.$_exp[1];
|
||||
|
||||
$_version = $_exp[2];
|
||||
|
||||
/* Note that 'Application' is not the actual name of the table! You can
|
||||
* thank cake for that.*/
|
||||
array_push($_conditions, "`Application`.`name` LIKE '%{$_product}%'");
|
||||
array_push($_conditions, "`Application`.`version` LIKE '%{$_version}%'");
|
||||
} else {
|
||||
// defaults I guess?
|
||||
array_push($_conditions, "`Application`.`name` LIKE 'Mozilla Firefox'");
|
||||
array_push($_conditions, "`Application`.`version` LIKE '1.5'");
|
||||
}
|
||||
|
||||
} else {
|
||||
// I'm providing a default here, because otherwise all results will be
|
||||
// returned (across all applications) and that is not desired
|
||||
array_push($_conditions, "`Application`.`name` LIKE 'Mozilla Firefox'");
|
||||
array_push($_conditions, "`Application`.`version` LIKE '1.5'");
|
||||
}
|
||||
|
||||
// Do the actual query
|
||||
$comments = $this->findCount($_conditions);
|
||||
|
||||
return $comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will retrieve all the comments within param's and pagination's parameters
|
||||
* @param array URL parameters
|
||||
* @param array pagination values from the controller
|
||||
* @param boolean if privacy is true phone numbers and email addresses will be
|
||||
* masked
|
||||
* @return cake result set
|
||||
*/
|
||||
function getComments($params, $pagination, $privacy=true)
|
||||
{
|
||||
$params = $this->cleanArrayForSql($params);
|
||||
|
||||
// We only want to see rows with comments
|
||||
$_conditions = array("comments NOT LIKE ''");
|
||||
|
||||
if (!empty($params['start_date'])) {
|
||||
$_timestamp = strtotime($params['start_date']);
|
||||
|
||||
if (!($_timestamp == -1) || $_timestamp == false) {
|
||||
$_date = date('Y-m-d H:i:s', $_timestamp);//sql format
|
||||
array_push($_conditions, "`created` >= '{$_date}'");
|
||||
}
|
||||
}
|
||||
if (!empty($params['end_date'])) {
|
||||
$_timestamp = strtotime($params['end_date']);
|
||||
|
||||
if (!($_timestamp == -1) || $_timestamp == false) {
|
||||
$_date = date('Y-m-d H:i:s', $_timestamp);//sql format
|
||||
array_push($_conditions, "`created` <= '{$_date}'");
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['product'])) {
|
||||
// product's come in looking like:
|
||||
// Mozilla Firefox 1.5.0.1
|
||||
$_exp = explode(' ',urldecode($params['product']));
|
||||
|
||||
if(count($_exp) == 3) {
|
||||
$_product = $_exp[0].' '.$_exp[1];
|
||||
|
||||
$_version = $_exp[2];
|
||||
|
||||
/* Note that 'Application' is not the actual name of the table! You can
|
||||
* thank cake for that.*/
|
||||
array_push($_conditions, "`Application`.`name` LIKE '%{$_product}%'");
|
||||
array_push($_conditions, "`Application`.`version` LIKE '%{$_version}%'");
|
||||
} else {
|
||||
// defaults I guess?
|
||||
array_push($_conditions, "`Application`.`name` LIKE 'Mozilla Firefox'");
|
||||
array_push($_conditions, "`Application`.`version` LIKE '1.5'");
|
||||
}
|
||||
|
||||
} else {
|
||||
// I'm providing a default here, because otherwise all results will be
|
||||
// returned (across all applications) and that is not desired
|
||||
array_push($_conditions, "`Application`.`name` LIKE 'Mozilla Firefox'");
|
||||
array_push($_conditions, "`Application`.`version` LIKE '1.5'");
|
||||
}
|
||||
|
||||
$comments = $this->findAll($_conditions, null, $pagination['order'], $pagination['show'], $pagination['page']);
|
||||
|
||||
if ($privacy) {
|
||||
// Pull out all the email addresses and phone numbers
|
||||
foreach ($comments as $var => $val) {
|
||||
|
||||
// Handle foo@bar.com
|
||||
$_email_regex = '/\ ?(.+)?@(.+)?\.(.+)?\ ?/';
|
||||
$comments[$var]['Result']['comments'] = preg_replace($_email_regex,'$1@****.$3',$comments[$var]['Result']['comments']);
|
||||
$comments[$var]['Result']['intention_text'] = preg_replace($_email_regex,'$1@****.$3',$comments[$var]['Result']['intention_text']);
|
||||
|
||||
// Handle xxx-xxx-xxxx
|
||||
$_phone_regex = '/([0-9]{3})[ .-]?[0-9]{4}/';
|
||||
$comments[$var]['Result']['comments'] = preg_replace($_phone_regex,'$1-****',$comments[$var]['Result']['comments']);
|
||||
$comments[$var]['Result']['intention_text'] = preg_replace($_phone_regex,'$1-****',$comments[$var]['Result']['intention_text']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $comments;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function runs the query to get the export data for the CSV file.
|
||||
*
|
||||
* @param array URL parameters
|
||||
* @param boolean if privacy is true phone numbers and email addresses will be
|
||||
* masked
|
||||
* @return array two dimensional array that should be pretty easy to transform
|
||||
* into a CSV.
|
||||
*/
|
||||
function getCsvExportData($params, $privacy=true)
|
||||
{
|
||||
$params = $this->cleanArrayForSql($params);
|
||||
|
||||
// We have to use a left join here because there isn't always an intention
|
||||
$_query = "
|
||||
SELECT
|
||||
`results`.`id`,
|
||||
`results`.`created`,
|
||||
`results`.`intention_text` as `intention_other`,
|
||||
`results`.`comments`,
|
||||
`intentions`.`description` as `intention`
|
||||
FROM `results`
|
||||
LEFT JOIN `intentions` ON `results`.`intention_id`=`intentions`.`id`
|
||||
INNER JOIN `applications` ON `applications`.`id` = `results`.`application_id`
|
||||
WHERE
|
||||
1=1
|
||||
";
|
||||
|
||||
if (!empty($params['start_date'])) {
|
||||
$_timestamp = strtotime($params['start_date']);
|
||||
|
||||
if (!($_timestamp == -1) || $_timestamp == false) {
|
||||
$_date = date('Y-m-d H:i:s', $_timestamp);//sql format
|
||||
$_query .= " AND `results`.`created` >= '{$_date}'";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['end_date'])) {
|
||||
$_timestamp = strtotime($params['end_date']);
|
||||
|
||||
if (!($_timestamp == -1) || $_timestamp == false) {
|
||||
$_date = date('Y-m-d H:i:s', $_timestamp);//sql format
|
||||
$_query .= " AND `results`.`created` <= '{$_date}'";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['product'])) {
|
||||
// product's come in looking like:
|
||||
// Mozilla Firefox 1.5.0.1
|
||||
$_exp = explode(' ',urldecode($params['product']));
|
||||
|
||||
if(count($_exp) == 3) {
|
||||
$_product = $_exp[0].' '.$_exp[1];
|
||||
|
||||
$_version = $_exp[2];
|
||||
|
||||
$_query .= " AND `applications`.`name` LIKE '{$_product}'";
|
||||
$_query .= " AND `applications`.`version` LIKE '{$_version}'";
|
||||
} else {
|
||||
// defaults I guess?
|
||||
$_query .= " AND `applications`.`name` LIKE 'Mozilla Firefox'";
|
||||
$_query .= " AND `applications`.`version` LIKE '1.5'";
|
||||
}
|
||||
} else {
|
||||
// I'm providing a default here, because otherwise all results will be
|
||||
// returned (across all applications) and that is not desired
|
||||
$_query .= " AND `applications`.`name` LIKE 'Mozilla Firefox'";
|
||||
$_query .= " AND `applications`.`version` LIKE '1.5'";
|
||||
}
|
||||
|
||||
$_query .= " ORDER BY `results`.`created` ASC";
|
||||
|
||||
$res = $this->query($_query);
|
||||
|
||||
// Since we're exporting to a CSV, we need to flatten the results into a 2
|
||||
// dimensional table array
|
||||
$newdata = array();
|
||||
|
||||
foreach ($res as $result) {
|
||||
|
||||
$newdata[] = array_merge($result['results'], $result['intentions']);
|
||||
}
|
||||
|
||||
if ($privacy) {
|
||||
// Pull out all the email addresses and phone numbers
|
||||
foreach ($newdata as $var => $val) {
|
||||
|
||||
// Handle foo@bar.com
|
||||
$_email_regex = '/\ ?(.+)?@(.+)?\.(.+)?\ ?/';
|
||||
$newdata[$var]['comments'] = preg_replace($_email_regex,'$1@****.$3',$newdata[$var]['comments']);
|
||||
$newdata[$var]['intention_other'] = preg_replace($_email_regex,'$1@****.$3',$newdata[$var]['intention_other']);
|
||||
|
||||
// Handle xxx-xxx-xxxx
|
||||
$_phone_regex = '/([0-9]{3})[ .-]?[0-9]{4}/';
|
||||
$newdata[$var]['comments'] = preg_replace($_phone_regex,'$1-****',$newdata[$var]['comments']);
|
||||
$newdata[$var]['intention_other'] = preg_replace($_phone_regex,'$1-****',$newdata[$var]['intention_other']);
|
||||
}
|
||||
}
|
||||
|
||||
// Our CSV library just prints out everything in order, so we have to put the
|
||||
// column labels on here ourselves
|
||||
$newdata = array_merge(array(array_keys($newdata[0])), $newdata);
|
||||
|
||||
return $newdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will retrieve the information used for graphing.
|
||||
* @param the url parameters (unescaped)
|
||||
* @return a result set
|
||||
*/
|
||||
function getDescriptionAndTotalsData($params)
|
||||
{
|
||||
// Clean parameters for inserting into SQL
|
||||
$params = $this->cleanArrayForSql($params);
|
||||
|
||||
/* It would be nice to drop something like this in the SELECT:
|
||||
*
|
||||
* CONCAT(COUNT(*)/(SELECT COUNT(*) FROM our_giant_query_all_over_again)*100,'%') AS `percentage`
|
||||
*/
|
||||
|
||||
$_query = "
|
||||
SELECT
|
||||
issues.description,
|
||||
COUNT( DISTINCT results.id ) AS total
|
||||
FROM
|
||||
issues
|
||||
LEFT JOIN
|
||||
issues_results ON issues_results.issue_id=issues.id
|
||||
LEFT JOIN results ON results.id=issues_results.result_id AND results.application_id=applications.id
|
||||
JOIN applications_issues ON applications_issues.issue_id=issues.id
|
||||
JOIN applications ON applications.id=applications_issues.application_id
|
||||
WHERE 1=1
|
||||
";
|
||||
|
||||
if (!empty($params['start_date'])) {
|
||||
$_timestamp = strtotime($params['start_date']);
|
||||
|
||||
if (!($_timestamp == -1) || $_timestamp == false) {
|
||||
$_date = date('Y-m-d H:i:s', $_timestamp);//sql format
|
||||
$_query.= " AND `results`.`created` >= '{$_date}'";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['end_date'])) {
|
||||
$_timestamp = strtotime($params['end_date']);
|
||||
|
||||
if (!($_timestamp == -1) || $_timestamp == false) {
|
||||
$_date = date('Y-m-d H:i:s', $_timestamp);//sql format
|
||||
$_query .= " AND `results`.`created` <= '{$_date}'";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['product'])) {
|
||||
// product's come in looking like:
|
||||
// Mozilla Firefox 1.5.0.1
|
||||
$_exp = explode(' ',urldecode($params['product']));
|
||||
|
||||
if(count($_exp) == 3) {
|
||||
$_product = $_exp[0].' '.$_exp[1];
|
||||
|
||||
$_version = $_exp[2];
|
||||
|
||||
$_query .= " AND `applications`.`name` LIKE '{$_product}'";
|
||||
$_query .= " AND `applications`.`version` LIKE '{$_version}'";
|
||||
} else {
|
||||
// defaults I guess?
|
||||
$_query .= " AND `applications`.`name` LIKE 'Mozilla Firefox'";
|
||||
$_query .= " AND `applications`.`version` LIKE '1.5'";
|
||||
}
|
||||
} else {
|
||||
// I'm providing a default here, because otherwise all results will be
|
||||
// returned (across all applications) and that is not desired
|
||||
$_query .= " AND `applications`.`name` LIKE 'Mozilla Firefox'";
|
||||
$_query .= " AND `applications`.`version` LIKE '1.5'";
|
||||
}
|
||||
|
||||
$_query .= " GROUP BY `issues`.`description`
|
||||
ORDER BY `issues`.`description` DESC";
|
||||
|
||||
return $this->query($_query);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,188 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Functions that take a db result and export it to CSV.
|
||||
* Usage example:
|
||||
* <code>
|
||||
* if ($_GET['csv'])
|
||||
* {
|
||||
* $res=db_query("SELECT * FROM fic_courses");
|
||||
* csv_send_csv($res);
|
||||
* exit;
|
||||
* }
|
||||
* </code>
|
||||
* @package libs
|
||||
* @subpackage csv
|
||||
* @author Richard Faaberg <faabergr@onid.orst.edu>
|
||||
* @author Mike Morgan <mike.morgan@oregonstate.edu>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Use a resource or two dimensional array, then send the CSV results to user.
|
||||
* @param mixed $res MySQL resource / result, or a two dimensional array
|
||||
* @param string $name name of the export file
|
||||
* @return bool true if file sent, false otherwise
|
||||
*/
|
||||
function csv_send_csv($res,$name=null)
|
||||
{
|
||||
// set name of the export file
|
||||
$filename=(is_null($name))?'export-'.date('Y-m-d').'.csv':$name.'.csv';
|
||||
// check for valid resource
|
||||
if ( is_resource($res) )
|
||||
{
|
||||
$csv=csv_export_to_csv($res);
|
||||
}
|
||||
elseif( is_array($res) && !empty($res) )
|
||||
{
|
||||
foreach ($res as $row)
|
||||
{
|
||||
if ( !is_array($row) )
|
||||
;
|
||||
else
|
||||
$csv[] = csv_array_to_csv($row)."\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_array($csv) )
|
||||
{
|
||||
// stream csv to user
|
||||
header("Content-type: application/x-csv");
|
||||
header('Content-disposition: inline; filename="'.$filename.'"');
|
||||
header('Cache-Control: private');
|
||||
header('Pragma: public');
|
||||
foreach ($csv as $row)
|
||||
{
|
||||
echo $row;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace quotes inside of a field with double quotes, which is something CSV requires.
|
||||
* @param string $string unquoted quotes
|
||||
* @return string $string quoted quotes
|
||||
*/
|
||||
function csv_fix_quotes($string)
|
||||
{
|
||||
return preg_replace('/"/','""',$string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace line breaks with commas trailed by a space.
|
||||
* @param string $string string containing line breaks
|
||||
* @param string string without line breaks
|
||||
*/
|
||||
function csv_fix_line_breaks($string)
|
||||
{
|
||||
return preg_replace('/(\n\r|\r)/','\n',$string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces instances of double quotes in a string with a single quote.
|
||||
* @param string $string the string to perform the replacement on
|
||||
* @return string the string with "" replaced by "
|
||||
*/
|
||||
function csv_unfix_quotes($string)
|
||||
{
|
||||
return preg_replace('/""/', '"', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Place quotes outside of every field, which inherently solves space, line break issues.
|
||||
* @param string $string
|
||||
* @return string $string with quotes around it
|
||||
*/
|
||||
function csv_add_quotes($string)
|
||||
{
|
||||
return '"'.$string.'"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes quotes from the beginning and the end of a string.
|
||||
* @param string $string the string to remove the quotes from
|
||||
* @return string the string, sans quotes at the beginning and end
|
||||
*/
|
||||
function csv_remove_quotes($string)
|
||||
{
|
||||
$pattern = "/^\"(.*)\"$/";
|
||||
$replacement = "$1";
|
||||
return preg_replace($pattern, $replacement, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an array into a CSV string with quotes around each value.
|
||||
* @param array $array
|
||||
* @return string the values in $array surrounded by quotes and separated by commas
|
||||
*/
|
||||
function csv_array_to_csv($array)
|
||||
{
|
||||
$csv_arr = array();
|
||||
foreach ($array as $value)
|
||||
{
|
||||
$csv_arr[]=csv_add_quotes(csv_fix_quotes(csv_fix_line_breaks($value)));
|
||||
}
|
||||
$csv_string=implode(',',$csv_arr);
|
||||
|
||||
return $csv_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a CSV string into an array.
|
||||
* Please use sparingly - this creates temp files
|
||||
* @param string $string the CSV string
|
||||
* @return array the elements from the CSV string in an array
|
||||
*/
|
||||
function csv_csv_to_array($string)
|
||||
{
|
||||
$return = array();
|
||||
$length = strlen($string);
|
||||
|
||||
// create a temp file and write the string to it
|
||||
$tmpfname = tempnam('/tmp', 'csvlib');
|
||||
$fh = fopen($tmpfname, 'w');
|
||||
fwrite($fh, $string);
|
||||
fclose($fh);
|
||||
|
||||
// open the file for csv parsing
|
||||
$csvh = fopen($tmpfname, 'r');
|
||||
while (($arraydata = fgetcsv($csvh, $length, ',')) !== false)
|
||||
{
|
||||
$return = array_merge($return, $arraydata);
|
||||
}
|
||||
|
||||
fclose($csvh);
|
||||
unlink($tmpfname);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a CSV file into a two dimensional array
|
||||
* It returns all the rows in the file, so if the first row are headers, you'd need to take care of that in the returned array
|
||||
* @param string $filepath the path to the csv file
|
||||
* @param string $delimiter delimiter, default to ','
|
||||
* @param string $enclosure enclosure character, default to '"'
|
||||
* @return &array the two dimensional array with the csv file content, or an empty if an error occured
|
||||
*/
|
||||
function &csv_csv_file_to_array($filepath, $delimiter=',', $enclosure='"')
|
||||
{
|
||||
$return = array();
|
||||
|
||||
if (!file_exists($filepath) || !is_readable($filepath))
|
||||
return $return;
|
||||
|
||||
$fh =& fopen($filepath, 'r');
|
||||
$size = filesize($filepath)+1;
|
||||
|
||||
while ($data =& fgetcsv($fh, $size, $delimiter, $enclosure))
|
||||
{
|
||||
$return[] = $data;
|
||||
}
|
||||
|
||||
fclose($fh);
|
||||
|
||||
return $return;
|
||||
}
|
||||
?>
|
||||
@@ -1,11 +0,0 @@
|
||||
<div id="t_footer">
|
||||
</div>
|
||||
|
||||
<!-- t_wrapper -->
|
||||
</div>
|
||||
|
||||
<!-- t_border -->
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,26 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>Mozilla Uninstall Survey Data</title>
|
||||
<meta name="author" content="Mozilla Corporation" />
|
||||
<meta name="copyright" content="Mozilla Corporation" />
|
||||
<?php echo $html->charset('UTF-8'); ?>
|
||||
<?php echo $html->css('screen'); ?>
|
||||
<?php if (isset($include_graph_libraries) && $include_graph_libraries):
|
||||
echo $javascript->link('mochikit/MochiKit.js');
|
||||
echo $javascript->link('plotkit/Base.js');
|
||||
echo $javascript->link('plotkit/Layout.js');
|
||||
echo $javascript->link('plotkit/Canvas.js');
|
||||
echo $javascript->link('plotkit/SweetCanvas.js');
|
||||
endif; ?>
|
||||
</head>
|
||||
<body>
|
||||
<div id="t_border">
|
||||
<div id="t_wrapper">
|
||||
<a class="skipnav" href="#t_content">Skip Navigation Links</a>
|
||||
<div id="t_header">
|
||||
<div id="t_title">
|
||||
<h1>Mozilla Firefox Uninstall Survey Data</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
<div id="t_nav">
|
||||
<ul>
|
||||
<li><?php echo $html->link('Results', '/results'); ?></li>
|
||||
<li><?php echo $html->link('Comments', '/results/comments'); ?></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* When we're exporting data, we end up having to pass all the parameters
|
||||
* via $_GET. Since we're doing this a few times per page (each graph, and the
|
||||
* export hrefs) this helper should make that easier.
|
||||
*/
|
||||
class ExportHelper
|
||||
{
|
||||
/**
|
||||
* Method to collect the current $_GET parameters and build another string from
|
||||
* them.
|
||||
*
|
||||
* @param string cake URL that you want prepended to the result. eg: reports/graph/
|
||||
* @param array the array of GET variables to add. These need to be
|
||||
* pre-sanitized to print in html! This is designed to
|
||||
* be used from the calling controller like:
|
||||
* $params = $this->sanitize->html($url_parameters);
|
||||
* @param string string to put between url and arguments (probably either '?' or
|
||||
* '&')
|
||||
* @param array array of strings which will be ignored
|
||||
* @return string string with the url variables appeneded to it
|
||||
*/
|
||||
function buildUrlString($url, $params, $seperator='?', $ignore=array('url'))
|
||||
{
|
||||
$arguments = '';
|
||||
|
||||
foreach ($params as $var => $val) {
|
||||
if (!in_array($var, $ignore)) {
|
||||
$arguments .= empty($arguments) ? "{$var}={$val}" : "&{$var}={$val}";
|
||||
}
|
||||
}
|
||||
|
||||
return "{$url}{$seperator}{$arguments}";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,196 +0,0 @@
|
||||
<?php
|
||||
class PaginationHelper {
|
||||
|
||||
var $helpers = array('Html','Ajax');
|
||||
var $_pageDetails = array();
|
||||
var $link = '';
|
||||
var $show = array();
|
||||
var $page;
|
||||
var $style;
|
||||
|
||||
/**
|
||||
* Sets the default pagination options.
|
||||
*
|
||||
* @param array $paging an array detailing the page options
|
||||
*/
|
||||
function setPaging($paging)
|
||||
{
|
||||
if(!empty($paging))
|
||||
{
|
||||
|
||||
$this->link = $paging['link'];
|
||||
$this->show = $paging['show'];
|
||||
$this->page = $paging['page'];
|
||||
$this->style = $paging['style'];
|
||||
|
||||
$pageCount = ceil($paging['count'] / $paging['limit'] );
|
||||
|
||||
$this->_pageDetails = array(
|
||||
'page'=>$paging['page'],
|
||||
'recordCount'=>$paging['count'],
|
||||
'pageCount' =>$pageCount,
|
||||
'nextPage'=> ($paging['page'] < $pageCount) ? $paging['page']+1 : '',
|
||||
'previousPage'=> ($paging['page']>1) ? $paging['page']-1 : '',
|
||||
'limit'=>$paging['limit']
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Displays limits for the query
|
||||
*
|
||||
* @param string $text - text to display before limits
|
||||
* @param string $separator - display a separate between limits
|
||||
*
|
||||
**/
|
||||
function show($text=null, $separator=null)
|
||||
{
|
||||
if (empty($this->_pageDetails)) { return false; }
|
||||
if ( !empty($this->_pageDetails['recordCount']) )
|
||||
{
|
||||
$t = '';
|
||||
if(is_array($this->show))
|
||||
{
|
||||
$t = $text.$separator;
|
||||
foreach($this->show as $value)
|
||||
{
|
||||
$link = preg_replace('/show=(.*?)&/','show='.$value.'&',$this->link);
|
||||
if($this->_pageDetails['limit'] == $value)
|
||||
{
|
||||
$t .= '<em>'.$value.'</em>'.$separator;
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->style == 'ajax')
|
||||
{
|
||||
$t .= $this->Ajax->linkToRemote($value, array("fallback"=>$this->action."#","url" => $link.$this->_pageDetails['page'],"update" => "ajax_update","method"=>"get")).$separator;
|
||||
}
|
||||
else
|
||||
{
|
||||
$t .= $this->Html->link($value,$link.$this->_pageDetails['page']).$separator;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
/**
|
||||
* Displays current result information
|
||||
*
|
||||
* @param string $text - text to preceeding the number of results
|
||||
*
|
||||
**/
|
||||
function result($text)
|
||||
{
|
||||
if (empty($this->_pageDetails)) { return false; }
|
||||
if ( !empty($this->_pageDetails['recordCount']) )
|
||||
{
|
||||
if($this->_pageDetails['recordCount'] > $this->_pageDetails['limit'])
|
||||
{
|
||||
$start_row = $this->_pageDetails['page'] > 1 ? (($this->_pageDetails['page']-1)*$this->_pageDetails['limit'])+1:'1';
|
||||
$end_row = ($this->_pageDetails['recordCount'] < ($start_row + $this->_pageDetails['limit']-1)) ? $this->_pageDetails['recordCount'] : ($start_row + $this->_pageDetails['limit']-1);
|
||||
$t = $text.$start_row.'-'.$end_row.' of '.$this->_pageDetails['recordCount'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$t = $text.$this->_pageDetails['recordCount'];
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Returns a list of page numbers separated by $separator
|
||||
*
|
||||
* @param string $separator - defaults to null
|
||||
*
|
||||
**/
|
||||
function pageNumbers($separator=null)
|
||||
{
|
||||
if (empty($this->_pageDetails) || $this->_pageDetails['pageCount'] == 1) { return false; }
|
||||
$t = array();
|
||||
$text = '';
|
||||
$pc = 1;
|
||||
do
|
||||
{
|
||||
if($pc == $this->_pageDetails['page'])
|
||||
{
|
||||
$text = '<em>'.$pc.'</em>';
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->style == 'ajax')
|
||||
{
|
||||
$text = $this->Ajax->linkToRemote($pc, array("fallback"=>$this->action."#","url" =>$this->link.$pc,"update" => "ajax_update","method"=>"get"));
|
||||
}
|
||||
else
|
||||
{
|
||||
$text = $this->Html->link($pc,$this->link.$pc);
|
||||
}
|
||||
}
|
||||
|
||||
$t[] = $text;
|
||||
$pc++;
|
||||
}
|
||||
while ($pc<=$this->_pageDetails['pageCount']);
|
||||
|
||||
$t = implode($separator, $t);
|
||||
|
||||
return $t;
|
||||
}
|
||||
/**
|
||||
* Displays a link to the previous page, where the page doesn't exist then
|
||||
* display the $text
|
||||
*
|
||||
* @param string $text - text display: defaults to next
|
||||
*
|
||||
**/
|
||||
function prevPage($text='prev')
|
||||
{
|
||||
if (empty($this->_pageDetails)) { return false; }
|
||||
if ( !empty($this->_pageDetails['previousPage']) )
|
||||
{
|
||||
if($this->style == 'ajax')
|
||||
{
|
||||
$t = $this->Ajax->linkToRemote($text, array("fallback"=>$this->action."#","url" => $this->link.$this->_pageDetails['previousPage'],"update" => "ajax_update","method"=>"get"));
|
||||
}
|
||||
else
|
||||
{
|
||||
$t = $this->Html->link($text,$this->link.$this->_pageDetails['previousPage']);
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Displays a link to the next page, where the page doesn't exist then
|
||||
* display the $text
|
||||
*
|
||||
* @param string $text - text to display: defaults to next
|
||||
*
|
||||
**/
|
||||
function nextPage($text='next')
|
||||
{
|
||||
if (empty($this->_pageDetails)) { return false; }
|
||||
if (!empty($this->_pageDetails['nextPage']))
|
||||
{
|
||||
if($this->style == 'ajax')
|
||||
{
|
||||
$t = $this->Ajax->linkToRemote($text, array("fallback"=>$this->action."#","url" => $this->link.$this->_pageDetails['nextPage'],"update" => "ajax_update","method"=>"get"));
|
||||
}
|
||||
else
|
||||
{
|
||||
$t = $this->Html->link($text,$this->link.$this->_pageDetails['nextPage']);
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php echo $this->renderElement( 'header' ); ?>
|
||||
<?php echo $this->renderElement( 'nav' ); ?>
|
||||
<div id="t_content_container">
|
||||
<div id="t_content">
|
||||
<?php echo $content_for_layout;?>
|
||||
</div>
|
||||
</div>
|
||||
<?php echo $this->renderElement( 'footer'); ?>
|
||||
@@ -1,51 +0,0 @@
|
||||
<h1><?php echo Inflector::humanize($this->name); ?></h1>
|
||||
|
||||
<div id="queryform">
|
||||
<?php echo $html->formTag('/results/comments/','get'); ?>
|
||||
<span>
|
||||
<label for="start_date">Start Date:</label>
|
||||
<input type="text" name="start_date" id="start_date" value="<? echo isset($url_params['start_date']) ? $url_params['start_date'] : ''; ?>" />
|
||||
<label for="end_date">End Date:</label>
|
||||
<input type="text" name="end_date" id="end_date" value="<? echo isset($url_params['end_date']) ? $url_params['end_date'] : ''; ?>" />
|
||||
</span>
|
||||
|
||||
<label for="product">Product:</label>
|
||||
<select name="product" id="product">
|
||||
<?php
|
||||
foreach ($products as $select) :
|
||||
$product = $select['applications']['name'].' '.$select['applications']['version'];
|
||||
$selected = ($product == trim($url_params['product'])) ? ' selected="selected" ' : '';
|
||||
?>
|
||||
<option<?=$selected?>><?=$product?></option>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<input type="submit" name="submit" id="submit" value="Go" />
|
||||
</form>
|
||||
<br />
|
||||
<span><small>Date format is yyyy-mm-dd. A blank date will use the largest possible range.</small></span>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($commentsData)) : ?>
|
||||
|
||||
<table class="comments" summary="User submitted comments.">
|
||||
<tr><th>Date Recorded</th><th>Comment</th></tr>
|
||||
<?php foreach ($commentsData as $var => $val) : ?>
|
||||
<tr><td><?php echo $time->niceShort($val['Result']['created']); ?></td><td><?php echo nl2br(htmlspecialchars($val['Result']['comments'])); ?></td></tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
<?php if($pagination->setPaging($paging)):?>
|
||||
<ul id="page-numbers">
|
||||
<li><?php echo $pagination->show('Show ', ' '); ?></li>
|
||||
<li><?php echo $pagination->result('Results: '); ?></li>
|
||||
<li><?php echo $pagination->pageNumbers(' '); ?></li>
|
||||
</ul>
|
||||
<?php endif;?>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<div id="notice">There is no data available for your parameters. Please review your search criteria.</div>
|
||||
|
||||
<?php endif; ?>
|
||||
@@ -1,91 +0,0 @@
|
||||
<h1><?php echo Inflector::humanize($this->name); ?></h1>
|
||||
|
||||
<div id="queryform">
|
||||
<?php echo $html->formTag('/results/','get'); ?>
|
||||
<span>
|
||||
<label for="start_date">Start Date:</label>
|
||||
<input type="text" name="start_date" id="start_date" value="<? echo isset($url_params['start_date']) ? $url_params['start_date'] : ''; ?>" />
|
||||
<label for="end_date">End Date:</label>
|
||||
<input type="text" name="end_date" id="end_date" value="<? echo isset($url_params['end_date']) ? $url_params['end_date'] : ''; ?>" />
|
||||
</span>
|
||||
|
||||
<label for="product">Product:</label>
|
||||
<select name="product" id="product">
|
||||
<?php
|
||||
foreach ($products as $select) :
|
||||
$product = $select['applications']['name'].' '.$select['applications']['version'];
|
||||
$selected = ($product == trim($url_params['product'])) ? ' selected="selected" ' : '';
|
||||
?>
|
||||
<option<?=$selected?>><?=$product?></option>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
<input type="submit" name="submit" id="submit" value="Go" />
|
||||
</form>
|
||||
<br />
|
||||
<span><small>Date format is yyyy-mm-dd. A blank date will use the largest possible range.</small></span>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($descriptionAndTotalsData)) : ?>
|
||||
<?php
|
||||
/* Prepare data for graphing */
|
||||
$_dataset = '';
|
||||
$_count = 0;
|
||||
$_total = 0;
|
||||
/* We've got to do 2 loops here because I need the totals to calculate
|
||||
* percentages.
|
||||
*/
|
||||
foreach ($descriptionAndTotalsData as $var => $val) {
|
||||
$_total += $val[0]['total'];
|
||||
}
|
||||
foreach ($descriptionAndTotalsData as $var => $val) {
|
||||
// We're putting this in a js string, so escape the double quotes
|
||||
$_description = str_replace('"','\"',$val['issues']['description']);
|
||||
$_percentage = intval(($val[0]['total'] / $_total)*100);
|
||||
|
||||
$_dataset .= "[{$_count}, {$val[0]['total']}, \"{$_description} (n={$val[0]['total']}, {$_percentage}%)\"], ";
|
||||
$_count++;
|
||||
}
|
||||
$_dataset = "[{$_dataset}]";
|
||||
?>
|
||||
<div id="graphcontainer">
|
||||
<canvas id="graph" height="400" width="800">
|
||||
<table class="results" summary="Firefox Uninstallation results.">
|
||||
<tr><th>Reason for uninstalling</th><th>Total</th></tr>
|
||||
<?php foreach ($descriptionAndTotalsData as $var => $val) : ?>
|
||||
<tr><td><?=$val['issues']['description']?></td><td><?=$val[0]['total']?></td></tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</canvas>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var layout = new PlotKit.Layout("bar", {"barOrientation":"horizontal"});
|
||||
layout.addDataset("results", <?=$_dataset?>);
|
||||
layout.evaluate();
|
||||
|
||||
var canvas = MochiKit.DOM.getElement("graph");
|
||||
var plotter = new PlotKit.SweetCanvasRenderer(canvas, layout,
|
||||
{
|
||||
"drawYAxis" : false,
|
||||
"drawXAxis" : false,
|
||||
"backgroundColor" : Color.fromHexString('#78c'),
|
||||
"strokeColor" : Color.fromHexString('#777'),
|
||||
"strokeWidth" : 1.0,
|
||||
"enableEvents" : false
|
||||
});
|
||||
|
||||
plotter.render();
|
||||
</script>
|
||||
|
||||
|
||||
<div id="exportbox">
|
||||
<a href="<?php echo $export->buildUrlString('results/comments/',$url_params); ?>">View Any Associated Comments»</a><br />
|
||||
<a href="<?php echo $export->buildUrlString('results/csv/',$url_params); ?>">Download this Data»</a>
|
||||
</div>
|
||||
|
||||
<?php else: ?>
|
||||
|
||||
<div id="notice">There is no data available for your parameters. Please review your search criteria.</div>
|
||||
|
||||
<?php endif; ?>
|
||||
@@ -1,6 +0,0 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
|
||||
</IfModule>
|
||||
@@ -1,116 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: css.php,v 1.1.1.1 2006-05-24 19:14:24 uid815 Exp $ */
|
||||
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.webroot
|
||||
* @since CakePHP v 0.2.9
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-05-24 19:14:24 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*/
|
||||
require(CONFIGS.'paths.php');
|
||||
require(CAKE.'basics.php');
|
||||
require(LIBS.'folder.php');
|
||||
require(LIBS.'file.php');
|
||||
require(LIBS.'legacy.php');
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $path
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
*/
|
||||
function make_clean_css ($path, $name)
|
||||
{
|
||||
require(VENDORS.'csspp'.DS.'csspp.php');
|
||||
|
||||
$data = file_get_contents($path);
|
||||
$csspp = new csspp();
|
||||
$output = $csspp->compress($data);
|
||||
|
||||
$ratio = 100-(round(strlen($output)/strlen($data), 3)*100);
|
||||
$output = " /* file: $name, ratio: $ratio% */ " . $output;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $path
|
||||
* @param unknown_type $content
|
||||
* @return unknown
|
||||
*/
|
||||
function write_css_cache ($path, $content)
|
||||
{
|
||||
if (!is_dir(dirname($path)))
|
||||
mkdir(dirname($path));
|
||||
|
||||
$cache = new File($path);
|
||||
return $cache->write($content);
|
||||
}
|
||||
|
||||
if (preg_match('|\.\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs))
|
||||
die('Wrong file name.');
|
||||
|
||||
$filename = 'css/'.$regs[1];
|
||||
$filepath = CSS.$regs[1];
|
||||
$cachepath = CACHE.'css'.DS.str_replace(array('/','\\'), '-', $regs[1]);
|
||||
|
||||
if (!file_exists($filepath))
|
||||
die('Wrong file name.');
|
||||
|
||||
|
||||
if (file_exists($cachepath))
|
||||
{
|
||||
$templateModified = filemtime($filepath);
|
||||
$cacheModified = filemtime($cachepath);
|
||||
|
||||
if ($templateModified > $cacheModified)
|
||||
{
|
||||
$output = make_clean_css ($filepath, $filename);
|
||||
write_css_cache ($cachepath, $output);
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = file_get_contents($cachepath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = make_clean_css ($filepath, $filename);
|
||||
write_css_cache ($cachepath, $output);
|
||||
}
|
||||
|
||||
header("Date: ".date("D, j M Y G:i:s ", $templateModified).'GMT');
|
||||
header("Content-Type: text/css");
|
||||
header("Expires: ".gmdate("D, j M Y H:i:s", time()+DAY)." GMT");
|
||||
header("Cache-Control: cache");// HTTP/1.1
|
||||
header("Pragma: cache");// HTTP/1.0
|
||||
print $output;
|
||||
|
||||
?>
|
||||
@@ -1,195 +0,0 @@
|
||||
/* CSS Document */
|
||||
@import url("cake.forms.css");
|
||||
|
||||
* {
|
||||
padding:0;
|
||||
margin:0;
|
||||
}
|
||||
body {
|
||||
font: 76% Verdana, Arial, Sans-serif;
|
||||
color: #333;
|
||||
}
|
||||
img {
|
||||
border:0;
|
||||
}
|
||||
#wrapper {
|
||||
text-align:left;
|
||||
}
|
||||
#header {
|
||||
height: 101px;
|
||||
background: #0D5087 url(../img/cake.header_bg.png) repeat-x left top;
|
||||
border-bottom: 1px solid #000;
|
||||
}
|
||||
#content {
|
||||
min-height:400px;
|
||||
background-color: #fff;
|
||||
padding:2em 4em;
|
||||
}
|
||||
#footer {
|
||||
text-align:center;
|
||||
padding:1em 0;
|
||||
font-size:smaller;
|
||||
border-top:1px solid #333;
|
||||
background-color: #063260;
|
||||
color:#fff;
|
||||
line-height:1.5;
|
||||
}
|
||||
#footer a {
|
||||
color:#fff;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4 {
|
||||
padding-bottom:0.5em;
|
||||
}
|
||||
h1 {
|
||||
font-family:"Trebuchet MS",Verdana,Arial,Sans-serif;
|
||||
}
|
||||
h1, a {
|
||||
color:#DB8101;
|
||||
}
|
||||
h1 em, a em {
|
||||
color:#008BCC;
|
||||
font-style: normal;
|
||||
}
|
||||
ul.colored a em
|
||||
h2 {
|
||||
font-style: italic;
|
||||
font-weight: bold;
|
||||
color:#666;
|
||||
}
|
||||
a:hover, a:hover em {
|
||||
color:#A22424;
|
||||
text-decoration:none;
|
||||
}
|
||||
#content p, #content ul, #content ol {
|
||||
line-height:1.5;
|
||||
padding-bottom:1em;
|
||||
}
|
||||
ul, ol {
|
||||
margin-left:3em;
|
||||
}
|
||||
|
||||
/* tables */
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
background-color: #fff;
|
||||
border: 1px solid #333;
|
||||
clear:both;
|
||||
margin: 0 0 2em 0;
|
||||
white-space: normal;
|
||||
}
|
||||
th {
|
||||
background-color: #ccc;
|
||||
border-top: 1px solid #fff;
|
||||
border-right: 1px solid #666;
|
||||
border-bottom: 1px solid #666;
|
||||
text-align: center;
|
||||
padding:3px;
|
||||
}
|
||||
table tr td {
|
||||
border-right: 1px solid #ccc;
|
||||
padding:4px 4px;
|
||||
vertical-align:top;
|
||||
text-align: center;
|
||||
}
|
||||
table tr.altRow td {
|
||||
background: #f4f4f4;
|
||||
}
|
||||
|
||||
/* scaffold show */
|
||||
|
||||
|
||||
div.related {
|
||||
clear:both;
|
||||
display:block;
|
||||
}
|
||||
dl {
|
||||
line-height:2em;
|
||||
margin:1em;
|
||||
}
|
||||
dt {
|
||||
font-weight: bold;
|
||||
vertical-align:top;
|
||||
}
|
||||
dd {
|
||||
margin-left:10em;
|
||||
margin-top:-2em;
|
||||
vertical-align:top;
|
||||
}
|
||||
|
||||
/* scaffold buttons */
|
||||
|
||||
|
||||
.notice {
|
||||
color: #DB8101;
|
||||
background-color: #ddd;
|
||||
display: block;
|
||||
padding: 1em;
|
||||
}
|
||||
.tip {
|
||||
color: #DB8101;
|
||||
background-color: #ddd;
|
||||
display: block;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
ul.actions {
|
||||
list-style: none;
|
||||
text-align:left;
|
||||
margin:2em 0;
|
||||
padding: 0;
|
||||
}
|
||||
ul.actions li {
|
||||
margin-left:1em;
|
||||
list-style: none;
|
||||
display: inline;
|
||||
}
|
||||
ul.actions li a, ul.actions li input {
|
||||
padding: 2px 12px;
|
||||
color: #DB8101;
|
||||
background-color:#ccc;
|
||||
text-decoration: none;
|
||||
border: 1px solid #666;
|
||||
line-height: 24px;
|
||||
font-weight: bold;
|
||||
text-align:center;
|
||||
text-decoration: none;
|
||||
}
|
||||
ul.actions li a:hover {
|
||||
color: #DB8101;
|
||||
background-color:#fff;
|
||||
text-decoration: none;
|
||||
}
|
||||
td.listactions {
|
||||
width: 14em;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
td.listactions a {
|
||||
padding: 0px 8px;
|
||||
text-align:center;
|
||||
font-weight: bold;
|
||||
color: #DB8101;
|
||||
background-color:#ccc;
|
||||
text-decoration: none;
|
||||
border: 1px solid #666;
|
||||
white-space: nowrap;
|
||||
}
|
||||
td.listactions a:hover {
|
||||
color: #fff;
|
||||
background-color:#DB8101;
|
||||
}
|
||||
|
||||
/* index links */
|
||||
|
||||
ul.colored a {
|
||||
|
||||
}
|
||||
ul.colored a em {
|
||||
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: bold;
|
||||
}
|
||||
@@ -1,279 +0,0 @@
|
||||
/* form.css */
|
||||
|
||||
form {
|
||||
margin: 0 4px;
|
||||
font-size: 120%;
|
||||
border-width: 0px 0px 0px 0px;
|
||||
border-style: solid;
|
||||
border-color: #DB8101;
|
||||
}
|
||||
|
||||
form fieldset {
|
||||
font-size: 100%;
|
||||
border-color: #000000;
|
||||
border-width: 1px 0px 0px 0px;
|
||||
border-style: solid none none none;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
form fieldset legend {
|
||||
font-size: 150%;
|
||||
font-weight: normal;
|
||||
color: #000;
|
||||
padding: 0px 5px;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 150%;
|
||||
}
|
||||
|
||||
label u {
|
||||
font-style: normal;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
input, select, textarea {
|
||||
font-family: Tahoma, Arial, sans-serif;
|
||||
font-size: 100%;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
textarea {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
form div {
|
||||
clear: left;
|
||||
display: block;
|
||||
margin: 5px 0px 0px 0px;
|
||||
padding: 1px 3px;
|
||||
}
|
||||
|
||||
form fieldset div.notes {
|
||||
float: right;
|
||||
width: 158px;
|
||||
height: auto;
|
||||
margin: 0px 0px 10px 10px;
|
||||
padding: 5px;
|
||||
border: 1px solid #666;
|
||||
background-color: #ffffe1;
|
||||
color: #666;
|
||||
font-size: 88%;
|
||||
}
|
||||
|
||||
form fieldset div.notes h4 {
|
||||
background-image: url(/images/icon_info.gif);
|
||||
background-repeat: no-repeat;
|
||||
background-position: top left;
|
||||
padding: 3px 0px 3px 27px;
|
||||
border-width: 0px 0px 1px 0px;
|
||||
border-style: solid;
|
||||
border-color: #666;
|
||||
color: #666;
|
||||
font-size: 110%;
|
||||
}
|
||||
|
||||
form fieldset div.notes p {
|
||||
margin: 0em 0em 1.2em 0em;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
form fieldset div.notes p.last {
|
||||
margin: 0em;
|
||||
}
|
||||
|
||||
form div fieldset {
|
||||
clear: none;
|
||||
border-width: 0px 1px 0px 1px;
|
||||
border-style: solid;
|
||||
border-color: #666;
|
||||
margin: 0px 0px 0px 142px;
|
||||
padding: 0px 5px 5px 5px;
|
||||
}
|
||||
|
||||
form div fieldset legend {
|
||||
font-size: 100%;
|
||||
padding: 0px 3px 0px 9px;
|
||||
}
|
||||
|
||||
form div.required fieldset legend {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
form div label {
|
||||
display: block;
|
||||
float: left;
|
||||
width: 200px;
|
||||
background-color: #f4f4f4;
|
||||
font-size: 16px;
|
||||
padding: 3px 5px;
|
||||
margin: 0px 0px 5px 0px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
form div.optional label, label.optional {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
form div.required label, label.required {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
form div label.labelCheckbox, form div label.labelRadio {
|
||||
float: none;
|
||||
display: block;
|
||||
margin: 0px 0px 5px 142px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
form div fieldset label.labelCheckbox, form div fieldset label.labelRadio {
|
||||
margin: 0px 0px 5px 0px;
|
||||
}
|
||||
p.error {
|
||||
color: #DB8101;
|
||||
background-color: #DBA941;
|
||||
font-size: 14px;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
form div input, form div select, form div textarea {
|
||||
padding: 1px 3px;
|
||||
margin: 0px 0px 0px 0px;
|
||||
}
|
||||
|
||||
form div input.inputFile {
|
||||
width: 211px;
|
||||
}
|
||||
|
||||
form div select.selectOne, form div select.selectMultiple {
|
||||
width: 211px;
|
||||
padding: 1px 3px;
|
||||
}
|
||||
|
||||
form div input.inputCheckbox, form div input.inputRadio, input.inputCheckbox, input.inputRadio {
|
||||
display: inline;
|
||||
height: 14px;
|
||||
width: 14px;
|
||||
background-color: transparent;
|
||||
border-width: 0px;
|
||||
}
|
||||
|
||||
form div.submit {
|
||||
padding: 0px 0px 0px 140px;
|
||||
clear:both;
|
||||
display:block;
|
||||
}
|
||||
|
||||
div.submit input {
|
||||
padding: 2px 12px;
|
||||
color: #DB8101;
|
||||
background-color:#ccc;
|
||||
text-decoration: none;
|
||||
border: 1px solid #666;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
text-align:center;
|
||||
text-decoration: none;
|
||||
width: auto;
|
||||
}
|
||||
div.submit input:hover {
|
||||
padding: 2px 12px;
|
||||
color: #fff;
|
||||
background-color:#DB8101;
|
||||
text-decoration: none;
|
||||
border: 1px solid #666;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
text-align:center;
|
||||
text-decoration: none;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
form div.submit div input.inputSubmit, form div.submit div input.inputButton {
|
||||
float: right;
|
||||
margin: 0px 0px 0px 5px;
|
||||
}
|
||||
|
||||
form div small {
|
||||
display: block;
|
||||
margin: 0px 0px 5px 142px;
|
||||
padding: 1px 3px;
|
||||
font-size: 88%;
|
||||
}
|
||||
|
||||
/* form.import.css */
|
||||
|
||||
form fieldset legend {
|
||||
line-height: 150%;
|
||||
}
|
||||
|
||||
form input, form select, form textarea {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
div.optional label:before {
|
||||
content: '';
|
||||
}
|
||||
|
||||
div.required label:before {
|
||||
content: '';
|
||||
}
|
||||
|
||||
form div label.labelCheckbox, form div label.labelRadio, label.labelCheckbox, label.labelRadio {
|
||||
display: block;
|
||||
width: 190px;
|
||||
padding: 4px 0px 0px 18px;
|
||||
text-indent: -18px;
|
||||
line-height: 120%;
|
||||
}
|
||||
|
||||
form div label.labelCheckbox input.inputCheckbox, form div label.labelRadio input.inputRadio, label.labelCheckbox input.inputCheckbox, label.labelRadio input.inputRadio {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
form div fieldset input.inputText, form div fieldset input.inputPassword, form div fieldset input.inputFile, form div fieldset textarea.inputTextarea {
|
||||
width: 160px;
|
||||
margin: 0px 0px 0px 18px;
|
||||
}
|
||||
|
||||
form div label.compact {
|
||||
display: inline;
|
||||
width: auto;
|
||||
padding: 4px 10px 0px 0px;
|
||||
text-indent: 0px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
form div.wide label {
|
||||
float: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
form div label.wide {
|
||||
width: 348px;
|
||||
}
|
||||
|
||||
form div.wide input.inputText, form div.wide input.inputPassword, form div.wide input.inputFile, form div.wide select, form div.wide textarea {
|
||||
width: 344px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
form div.notes p, form div small {
|
||||
line-height: 125%;
|
||||
}
|
||||
|
||||
form div.wide small {
|
||||
margin: 0px 0px 5px 0px;
|
||||
}
|
||||
|
||||
div.date select {
|
||||
width:auto;
|
||||
}
|
||||
|
||||
select.autoWidth {
|
||||
width:auto;
|
||||
}
|
||||
|
||||
option {
|
||||
padding-left:1em;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
form div,
|
||||
form div label.labelCheckbox, form div label.labelRadio,
|
||||
form div small,
|
||||
form div label.labelCheckbox, form div label.labelRadio, label.labelCheckbox, label.labelRadio {
|
||||
height: expression('1%');
|
||||
}
|
||||
form div fieldset input.inputText, form div fieldset input.inputPassword, form div fieldset input.inputFile, form div fieldset textarea.inputTextarea {
|
||||
margin: expression('0px 0px 0px -124px');
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
/* Screen Stylesheet */
|
||||
|
||||
/* This is temporary while we use the scaffolding */
|
||||
@import url("cake.default.css");
|
||||
table { clear:none; }
|
||||
|
||||
/* CORE STYLES */
|
||||
|
||||
body{
|
||||
background-color:#788;
|
||||
}
|
||||
div#t_title{
|
||||
background-color:#ddd;
|
||||
height:50px;
|
||||
padding-left:8px;
|
||||
}
|
||||
div#t_title h1{
|
||||
font-size:1.7em;
|
||||
padding-top:10px;
|
||||
color:#677;
|
||||
}
|
||||
div#t_content_container{
|
||||
}
|
||||
div#t_content{
|
||||
padding: 20px 10px 100px 10px;
|
||||
margin-left:151px;
|
||||
background-image:url('../img/bg.jpg');
|
||||
background-position:bottom right;
|
||||
background-repeat:no-repeat;
|
||||
min-height:200px;
|
||||
}
|
||||
div#t_wrapper{
|
||||
margin:0px;
|
||||
padding:0px;
|
||||
background-color:#fff;
|
||||
}
|
||||
|
||||
div#t_border{
|
||||
border-left:1px solid #111;
|
||||
border-right:1px solid #111;
|
||||
border-bottom:1px solid #111;
|
||||
margin:0px 30px 0px 30px;
|
||||
}
|
||||
|
||||
div#t_nav {
|
||||
padding:20px 0px 50px 0px;
|
||||
float:left;
|
||||
width:151px;
|
||||
}
|
||||
div#t_nav ul {
|
||||
list-style-type:none;
|
||||
padding:2px 0px 0px 0px;
|
||||
margin:0px;
|
||||
}
|
||||
div#t_nav ul li{
|
||||
padding:2px 0px 2px 0px;
|
||||
}
|
||||
div#t_nav ul li a{
|
||||
text-decoration:none;
|
||||
font-size:.8em;
|
||||
padding:6px 0px 6px 8px;
|
||||
margin:0px 0px 0px 0px;
|
||||
color:#566;
|
||||
border:none;
|
||||
}
|
||||
div#t_nav ul li a:hover{
|
||||
color:#f80;
|
||||
}
|
||||
div#t_nav h3 {
|
||||
padding:5px 0px 0px 5px;
|
||||
font-size:.9em;
|
||||
}
|
||||
div#t_footer {
|
||||
clear:both;
|
||||
border-top:1px solid #111;
|
||||
}
|
||||
|
||||
div#t_content h1 {
|
||||
margin-bottom:100px;
|
||||
font-size:1.6em;
|
||||
}
|
||||
|
||||
a.skipnav {
|
||||
position:absolute;
|
||||
visibility:hidden;
|
||||
}
|
||||
|
||||
div#queryform {
|
||||
margin: 5px 20px 5px 20px;
|
||||
padding-bottom:20px;
|
||||
width:700px;
|
||||
}
|
||||
div#queryform label {
|
||||
font-size:.8em;
|
||||
font-weight:bold;
|
||||
}
|
||||
div#queryform input[type="text"]{
|
||||
width:7em;
|
||||
}
|
||||
|
||||
div#exportbox {
|
||||
}
|
||||
|
||||
/* Classes for graph/table data. (Generally just padding) */
|
||||
.results {
|
||||
padding: 5px 5px 5px 5px;
|
||||
margin: 5px 5px 5px 5px;
|
||||
}
|
||||
|
||||
div#notice {
|
||||
background-color:#ecc;
|
||||
border:1px dashed #daa;
|
||||
text-align:center;
|
||||
padding:6px 6px 6px 6px;
|
||||
margin:6px 20px 6px 20px;
|
||||
}
|
||||
|
||||
table.comments tr {
|
||||
}
|
||||
|
||||
table.comments tr td{
|
||||
text-align:left;
|
||||
border-bottom: 1px solid #222;
|
||||
}
|
||||
|
||||
div.bar_chart_label {
|
||||
position: absolute;
|
||||
text-align: left;
|
||||
font-size: small;
|
||||
color: #fff;
|
||||
overflow: hidden;
|
||||
z-index: 10;
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 6.2 KiB |
@@ -1 +0,0 @@
|
||||
deny from all
|
||||
@@ -1,244 +0,0 @@
|
||||
2006-04-29 v1.3.1 (bug fix release)
|
||||
|
||||
- Fix sendXMLHttpRequest sendContent regression
|
||||
- Internet Explorer fix in MochiKit.Logging (printfire exception)
|
||||
- Internet Explorer XMLHttpRequest object leak fixed in MochiKit.Async
|
||||
|
||||
2006-04-26 v1.3 "warp zone"
|
||||
|
||||
- IMPORTANT: Renamed MochiKit.Base.forward to forwardCall (for export)
|
||||
- IMPORTANT: Renamed MochiKit.Base.find to findValue (for export)
|
||||
- New MochiKit.Base.method as a convenience form of bind that takes the
|
||||
object before the method
|
||||
- New MochiKit.Base.flattenArguments for flattening a list of arguments to
|
||||
a single Array
|
||||
- Refactored MochiRegExp example to use MochiKit.Signal
|
||||
- New key_events example demonstrating use of MochiKit.Signal's key handling
|
||||
capabilities.
|
||||
- MochiKit.DOM.createDOM API change for convenience: if attrs is a string,
|
||||
null is used and the string will be considered the first node. This
|
||||
allows for the more natural P("foo") rather than P(null, "foo").
|
||||
- MochiKit Interpreter example refactored to use MochiKit.Signal and now
|
||||
provides multi-line input and a help() function to get MochiKit function
|
||||
signature from the documentation.
|
||||
- Native Console Logging for the default MochiKit.Logging logger
|
||||
- New MochiKit.Async.DeferredList, gatherResults, maybeDeferred
|
||||
- New MochiKit.Signal example: draggable
|
||||
- Added sanity checking to Deferred to ensure that errors happen when chaining
|
||||
is used incorrectly
|
||||
- Opera sendXMLHttpRequest fix (sends empty string instead of null by default)
|
||||
- Fix a bug in MochiKit.Color that incorrectly generated hex colors for
|
||||
component values smaller than 16/255.
|
||||
- Fix a bug in MochiKit.Logging that prevented logs from being capped at a
|
||||
maximum size
|
||||
- MochiKit.Async.Deferred will now wrap thrown objects that are not instanceof
|
||||
Error, so that the errback chain is used instead of the callback chain.
|
||||
- MochiKit.DOM.appendChildNodes and associated functions now append iterables
|
||||
in the correct order.
|
||||
- New MochiKit-based SimpleTest test runner as a replacement for Test.Simple
|
||||
- MochiKit.Base.isNull no longer matches undefined
|
||||
- example doctypes changed to HTML4
|
||||
- isDateLike no longer throws error on null
|
||||
- New MochiKit.Signal module, modeled after the slot/signal mechanism in Qt
|
||||
- updated elementDimensions to calculate width from offsetWidth instead
|
||||
of clientWidth
|
||||
- formContents now works with FORM tags that have a name attribute
|
||||
- Documentation now uses MochiKit to generate a function index
|
||||
|
||||
2006-01-26 v1.2 "the ocho"
|
||||
|
||||
- Fixed MochiKit.Color.Color.lighterColorWithLevel
|
||||
- Added new MochiKit.Base.findIdentical function to find the index of an
|
||||
element in an Array-like object. Uses === for identity comparison.
|
||||
- Added new MochiKit.Base.find function to find the index of an element in
|
||||
an Array-like object. Uses compare for rich comparison.
|
||||
- MochiKit.Base.bind will accept a string for func, which will be immediately
|
||||
looked up as self[func].
|
||||
- MochiKit.DOM.formContents no longer skips empty form elements for Zope
|
||||
compatibility
|
||||
- MochiKit.Iter.forEach will now catch StopIteration to break
|
||||
- New MochiKit.DOM.elementDimensions(element) for determining the width and
|
||||
height of an element in the document
|
||||
- MochiKit.DOM's initialization is now compatible with
|
||||
HTMLUnit + JWebUnit + Rhino
|
||||
- MochiKit.LoggingPane will now re-use a ``_MochiKit_LoggingPane`` DIV element
|
||||
currently in the document instead of always creating one.
|
||||
- MochiKit.Base now has operator.mul
|
||||
- MochiKit.DOM.formContents correctly handles unchecked checkboxes that have
|
||||
a custom value attribute
|
||||
- Added new MochiKit.Color constructors fromComputedStyle and fromText
|
||||
- MochiKit.DOM.setNodeAttribute should work now
|
||||
- MochiKit.DOM now has a workaround for an IE bug when setting the style
|
||||
property to a string
|
||||
- MochiKit.DOM.createDOM now has workarounds for IE bugs when setting the
|
||||
name and for properties
|
||||
- MochiKit.DOM.scrapeText now walks the DOM tree in-order
|
||||
- MochiKit.LoggingPane now sanitizes the window name to work around IE bug
|
||||
- MochiKit.DOM now translates usemap to useMap to work around IE bug
|
||||
- MochiKit.Logging is now resistant to Prototype's dumb Object.prototype hacks
|
||||
- Added new MochiKit.DOM documentation on element visibility
|
||||
- New MochiKit.DOM.elementPosition(element[, relativeTo={x: 0, y: 0}])
|
||||
for determining the position of an element in the document
|
||||
- Added new MochiKit.DOM createDOMFunc aliases: CANVAS, STRONG
|
||||
|
||||
2005-11-14 v1.1
|
||||
|
||||
- Fixed a bug in numberFormatter with large numbers
|
||||
- Massively overhauled documentation
|
||||
- Fast-path for primitives in MochiKit.Base.compare
|
||||
- New groupby and groupby_as_array in MochiKit.Iter
|
||||
- Added iterator factory adapter for objects that implement iterateNext()
|
||||
- Fixed isoTimestamp to handle timestamps with time zone correctly
|
||||
- Added new MochiKit.DOM createDOMFunc aliases: SELECT, OPTION, OPTGROUP,
|
||||
LEGEND, FIELDSET
|
||||
- New MochiKit.DOM formContents and enhancement to queryString to support it
|
||||
- Updated view_source example to use dp.SyntaxHighlighter 1.3.0
|
||||
- MochiKit.LoggingPane now uses named windows based on the URL so that
|
||||
a given URL will get the same LoggingPane window after a reload
|
||||
(at the same position, etc.)
|
||||
- MochiKit.DOM now has currentWindow() and currentDocument() context
|
||||
variables that are set with withWindow() and withDocument(). These
|
||||
context variables affect all MochiKit.DOM functionality (getElement,
|
||||
createDOM, etc.)
|
||||
- MochiKit.Base.items will now catch and ignore exceptions for properties
|
||||
that are enumerable but not accessible (e.g. permission denied)
|
||||
- MochiKit.Async.Deferred's addCallback/addErrback/addBoth
|
||||
now accept additional arguments that are used to create a partially
|
||||
applied function. This differs from Twisted in that the callback/errback
|
||||
result becomes the *last* argument, not the first when this feature
|
||||
is used.
|
||||
- MochiKit.Async's doSimpleXMLHttpRequest will now accept additional
|
||||
arguments which are used to create a GET query string
|
||||
- Did some refactoring to reduce the footprint of MochiKit by a few
|
||||
kilobytes
|
||||
- escapeHTML to longer escapes ' (apos) and now uses
|
||||
String.replace instead of iterating over every char.
|
||||
- Added DeferredLock to Async
|
||||
- Renamed getElementsComputedStyle to computedStyle and moved
|
||||
it from MochiKit.Visual to MochiKit.DOM
|
||||
- Moved all color support out of MochiKit.Visual and into MochiKit.Color
|
||||
- Fixed range() to accept a negative step
|
||||
- New alias to MochiKit.swapDOM called removeElement
|
||||
- New MochiKit.DOM.setNodeAttribute(node, attr, value) which sets
|
||||
an attribute on a node without raising, roughly equivalent to:
|
||||
updateNodeAttributes(node, {attr: value})
|
||||
- New MochiKit.DOM.getNodeAttribute(node, attr) which gets the value of
|
||||
a node's attribute or returns null without raising
|
||||
- Fixed a potential IE memory leak if using MochiKit.DOM.addToCallStack
|
||||
directly (addLoadEvent did not leak, since it clears the handler)
|
||||
|
||||
2005-10-24 v1.0
|
||||
|
||||
- New interpreter example that shows usage of MochiKit.DOM to make
|
||||
an interactive JavaScript interpreter
|
||||
- New MochiKit.LoggingPane for use with the MochiKit.Logging
|
||||
debuggingBookmarklet, with logging_pane example to show its usage
|
||||
- New mochiregexp example that demonstrates MochiKit.DOM and MochiKit.Async
|
||||
in order to provide a live regular expression matching tool
|
||||
- Added advanced number formatting capabilities to MochiKit.Format:
|
||||
numberFormatter(pattern, placeholder="", locale="default") and
|
||||
formatLocale(locale="default")
|
||||
- Added updatetree(self, obj[, ...]) to MochiKit.Base, and changed
|
||||
MochiKit.DOM's updateNodeAttributes(node, attrs) to use it when appropiate.
|
||||
- Added new MochiKit.DOM createDOMFunc aliases: BUTTON, TT, PRE
|
||||
- Added truncToFixed(aNumber, precision) and roundToFixed(aNumber, precision)
|
||||
to MochiKit.Format
|
||||
- MochiKit.DateTime can now handle full ISO 8601 timestamps, specifically
|
||||
isoTimestamp(isoString) will convert them to Date objects, and
|
||||
toISOTimestamp(date, true) will return an ISO 8601 timestamp in UTC
|
||||
- Fixed missing errback for sendXMLHttpRequest when the server does not
|
||||
respond
|
||||
- Fixed infinite recusion bug when using roundClass("DIV", ...)
|
||||
- Fixed a bug in MochiKit.Async wait (and callLater) that prevented them
|
||||
from being cancelled properly
|
||||
- Workaround in MochiKit.Base bind (and partial) for functions that don't
|
||||
have an apply method, such as alert
|
||||
- Reliably return null from the string parsing/manipulation functions if
|
||||
the input can't be coerced to a string (s + "") or the input makes no sense;
|
||||
e.g. isoTimestamp(null) and isoTimestamp("") return null
|
||||
|
||||
2005-10-08 v0.90
|
||||
|
||||
- Fixed ISO compliance with toISODate
|
||||
- Added missing operator.sub
|
||||
- Placated Mozilla's strict warnings a bit
|
||||
- Added JSON serialization and unserialization support to MochiKit.Base:
|
||||
serializeJSON, evalJSON, registerJSON. This is very similar to the repr
|
||||
API.
|
||||
- Fixed a bug in the script loader that failed in some scenarios when a script
|
||||
tag did not have a "src" attribute (thanks Ian!)
|
||||
- Added new MochiKit.DOM createDOMFunc aliases: H1, H2, H3, BR, HR, TEXTAREA,
|
||||
P, FORM
|
||||
- Use encodeURIComponent / decodeURIComponent for MochiKit.Base urlEncode
|
||||
and parseQueryString, when available.
|
||||
|
||||
2005-08-12 v0.80
|
||||
|
||||
- Source highlighting in all examples, moved to a view-source example
|
||||
- Added some experimental syntax highlighting for the Rounded Corners example,
|
||||
via the LGPL dp.SyntaxHighlighter 1.2.0 now included in examples/common/lib
|
||||
- Use an indirect binding for the logger conveniences, so that the global
|
||||
logger could be replaced by setting MochiKit.Logger.logger to something else
|
||||
(though an observer is probably a better choice).
|
||||
- Allow MochiKit.DOM.getElementsByTagAndClassName to take a string for parent,
|
||||
which will be looked up with getElement
|
||||
- Fixed bug in MochiKit.Color.fromBackground (was using node.parent instead of
|
||||
node.parentNode)
|
||||
- Consider a 304 (NOT_MODIFIED) response from XMLHttpRequest to be success
|
||||
- Disabled Mozilla map(...) fast-path due to Deer Park compatibility issues
|
||||
- Possible workaround for Safari issue with swapDOM, where it would get
|
||||
confused because two elements were in the DOM at the same time with the
|
||||
same id
|
||||
- Added missing THEAD convenience function to MochiKit.DOM
|
||||
- Added lstrip, rstrip, strip to MochiKit.Format
|
||||
- Added updateNodeAttributes, appendChildNodes, replaceChildNodes to
|
||||
MochiKit.DOM
|
||||
- MochiKit.Iter.iextend now has a fast-path for array-like objects
|
||||
- Added HSV color space support to MochiKit.Visual
|
||||
- Fixed a bug in the sortable_tables example, it now converts types
|
||||
correctly
|
||||
- Fixed a bug where MochiKit.DOM referenced MochiKit.Iter.next from global
|
||||
scope
|
||||
|
||||
2005-08-04 v0.70
|
||||
|
||||
- New ajax_tables example, which shows off XMLHttpRequest, ajax, json, and
|
||||
a little TAL-ish DOM templating attribute language.
|
||||
- sendXMLHttpRequest and functions that use it (loadJSONDoc, etc.) no longer
|
||||
ignore requests with status == 0, which seems to happen for cached or local
|
||||
requests
|
||||
- Added sendXMLHttpRequest to MochiKit.Async.EXPORT, d'oh.
|
||||
- Changed scrapeText API to return a string by default. This is API-breaking!
|
||||
It was dumb to have the default return value be the form you almost never
|
||||
want. Sorry.
|
||||
- Added special form to swapDOM(dest, src). If src is null, dest is removed
|
||||
(where previously you'd likely get a DOM exception).
|
||||
- Added three new functions to MochiKit.Base for dealing with URL query
|
||||
strings: urlEncode, queryString, parseQueryString
|
||||
- MochiKit.DOM.createDOM will now use attr[k] = v for all browsers if the name
|
||||
starts with "on" (e.g. "onclick"). If v is a string, it will set it to
|
||||
new Function(v).
|
||||
- Another workaround for Internet "worst browser ever" Explorer's setAttribute
|
||||
usage in MochiKit.DOM.createDOM (checked -> defaultChecked).
|
||||
- Added UL, OL, LI convenience createDOM aliases to MochiKit.DOM
|
||||
- Packing is now done by Dojo's custom Rhino interpreter, so it's much smaller
|
||||
now!
|
||||
|
||||
2005-07-29 v0.60
|
||||
|
||||
- Beefed up the MochiKit.DOM test suite
|
||||
- Fixed return value for MochiKit.DOM.swapElementClass, could return
|
||||
false unexpectedly before
|
||||
- Added an optional "parent" argument to
|
||||
MochiKit.DOM.getElementsByTagAndClassName
|
||||
- Added a "packed" version in packed/MochiKit/MochiKit.js
|
||||
- Changed build script to rewrite the URLs in tests to account for the
|
||||
JSAN-required reorganization
|
||||
- MochiKit.Compat to potentially work around IE 5.5 issues
|
||||
(5.0 still not supported). Test.Simple doesn't seem to work there,
|
||||
though.
|
||||
- Several minor documentation corrections
|
||||
|
||||
2005-07-27 v0.50
|
||||
|
||||
- Initial Release
|
||||
@@ -1,69 +0,0 @@
|
||||
MochiKit is dual-licensed software. It is available under the terms of the
|
||||
MIT License, or the Academic Free License version 2.1. The full text of
|
||||
each license is included below.
|
||||
|
||||
MIT License
|
||||
===========
|
||||
|
||||
Copyright (c) 2005 Bob Ippolito. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
Academic Free License v. 2.1
|
||||
============================
|
||||
|
||||
Copyright (c) 2005 Bob Ippolito. All rights reserved.
|
||||
|
||||
This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following notice immediately following the copyright notice for the Original Work:
|
||||
|
||||
Licensed under the Academic Free License version 2.1
|
||||
|
||||
1) Grant of Copyright License. Licensor hereby grants You a world-wide, royalty-free, non-exclusive, perpetual, sublicenseable license to do the following:
|
||||
|
||||
a) to reproduce the Original Work in copies;
|
||||
|
||||
b) to prepare derivative works ("Derivative Works") based upon the Original Work;
|
||||
|
||||
c) to distribute copies of the Original Work and Derivative Works to the public;
|
||||
|
||||
d) to perform the Original Work publicly; and
|
||||
|
||||
e) to display the Original Work publicly.
|
||||
|
||||
2) Grant of Patent License. Licensor hereby grants You a world-wide, royalty-free, non-exclusive, perpetual, sublicenseable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, to make, use, sell and offer for sale the Original Work and Derivative Works.
|
||||
|
||||
3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor hereby agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work, and by publishing the address of that information repository in a notice immediately following the copyright notice that applies to the Original Work.
|
||||
|
||||
4) Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior written permission of the Licensor. Nothing in this License shall be deemed to grant any rights to trademarks, copyrights, patents, trade secrets or any other intellectual property of Licensor except as expressly stated herein. No patent license is granted to make, use, sell or offer to sell embodiments of any patent claims other than the licensed claims defined in Section 2. No right is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under different terms from this License any Original Work that Licensor otherwise would have a right to license.
|
||||
|
||||
5) This section intentionally omitted.
|
||||
|
||||
6) Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
|
||||
|
||||
7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately proceeding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to Original Work is granted hereunder except under this disclaimer.
|
||||
|
||||
8) Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to any person for any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to liability for death or personal injury resulting from Licensor's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You.
|
||||
|
||||
9) Acceptance and Termination. If You distribute copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. Nothing else but this License (or another written agreement between Licensor and You) grants You permission to create Derivative Works based upon the Original Work or to exercise any of the rights granted in Section 1 herein, and any attempt to do so except under the terms of this License (or another written agreement between Licensor and You) is expressly prohibited by U.S. copyright law, the equivalent laws of other countries, and by international treaty. Therefore, by exercising any of the rights granted to You in Section 1 herein, You indicate Your acceptance of this License and all of its terms and conditions.
|
||||
|
||||
10) Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
|
||||
|
||||
11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 et seq., the equivalent laws of other countries, and international treaty. This section shall survive the termination of this License.
|
||||
|
||||
12) Attorneys Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
|
||||
|
||||
13) Miscellaneous. This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
|
||||
|
||||
14) Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
15) Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
|
||||
|
||||
This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights reserved. Permission is hereby granted to copy and distribute this license without modification. This license may not be modified without the express written permission of its copyright owner.
|
||||
|
||||
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
Changes
|
||||
META.json
|
||||
MANIFEST This list of files
|
||||
LICENSE.txt
|
||||
doc/html/MochiKit/Async.html
|
||||
doc/html/MochiKit/Base.html
|
||||
doc/html/MochiKit/Color.html
|
||||
doc/html/MochiKit/DateTime.html
|
||||
doc/html/MochiKit/DOM.html
|
||||
doc/html/MochiKit/Format.html
|
||||
doc/html/MochiKit/index.html
|
||||
doc/html/MochiKit/Iter.html
|
||||
doc/html/MochiKit/Logging.html
|
||||
doc/html/MochiKit/LoggingPane.html
|
||||
doc/html/MochiKit/Signal.html
|
||||
doc/html/MochiKit/VersionHistory.html
|
||||
doc/html/MochiKit/Visual.html
|
||||
doc/js/toc.js
|
||||
doc/rst/MochiKit/Async.rst
|
||||
doc/rst/MochiKit/Base.rst
|
||||
doc/rst/MochiKit/Color.rst
|
||||
doc/rst/MochiKit/DateTime.rst
|
||||
doc/rst/MochiKit/DOM.rst
|
||||
doc/rst/MochiKit/Format.rst
|
||||
doc/rst/MochiKit/index.rst
|
||||
doc/rst/MochiKit/Iter.rst
|
||||
doc/rst/MochiKit/Logging.rst
|
||||
doc/rst/MochiKit/LoggingPane.rst
|
||||
doc/rst/MochiKit/Signal.rst
|
||||
doc/rst/MochiKit/VersionHistory.rst
|
||||
doc/rst/MochiKit/Visual.rst
|
||||
examples/ajax_tables/ajax_tables.css
|
||||
examples/ajax_tables/ajax_tables.js
|
||||
examples/ajax_tables/domains.json
|
||||
examples/ajax_tables/domains.xml
|
||||
examples/ajax_tables/index.html
|
||||
examples/color_wheel/color_wheel.css
|
||||
examples/color_wheel/color_wheel.js
|
||||
examples/color_wheel/index.html
|
||||
examples/draggable/draggable.css
|
||||
examples/draggable/draggable.js
|
||||
examples/draggable/index.html
|
||||
examples/interpreter/index.html
|
||||
examples/interpreter/interpreter.css
|
||||
examples/interpreter/interpreter.js
|
||||
examples/key_events/index.html
|
||||
examples/key_events/key_events.css
|
||||
examples/key_events/key_events.js
|
||||
examples/logging_pane/index.html
|
||||
examples/logging_pane/logging_pane.css
|
||||
examples/logging_pane/logging_pane.js
|
||||
examples/mochiregexp/index.html
|
||||
examples/mochiregexp/mochiregexp.css
|
||||
examples/mochiregexp/mochiregexp.js
|
||||
examples/rounded_corners/index.html
|
||||
examples/rounded_corners/rounded_corners.css
|
||||
examples/rounded_corners/rounded_corners.js
|
||||
examples/sortable_tables/index.html
|
||||
examples/sortable_tables/sortable_tables.css
|
||||
examples/sortable_tables/sortable_tables.js
|
||||
examples/view-source/view-source.css
|
||||
examples/view-source/view-source.html
|
||||
examples/view-source/view-source.js
|
||||
examples/view-source/lib/SyntaxHighlighter/shBrushCSharp.js
|
||||
examples/view-source/lib/SyntaxHighlighter/shBrushDelphi.js
|
||||
examples/view-source/lib/SyntaxHighlighter/shBrushJScript.js
|
||||
examples/view-source/lib/SyntaxHighlighter/shBrushPhp.js
|
||||
examples/view-source/lib/SyntaxHighlighter/shBrushPython.js
|
||||
examples/view-source/lib/SyntaxHighlighter/shBrushSql.js
|
||||
examples/view-source/lib/SyntaxHighlighter/shBrushVb.js
|
||||
examples/view-source/lib/SyntaxHighlighter/shBrushXml.js
|
||||
examples/view-source/lib/SyntaxHighlighter/shCore.js
|
||||
examples/view-source/lib/SyntaxHighlighter/SyntaxHighlighter.css
|
||||
examples/view-source/lib/SyntaxHighlighter/Tests.html
|
||||
include/css/documentation.css
|
||||
include/css/general.css
|
||||
MochiKit/__package__.js
|
||||
MochiKit/Async.js
|
||||
MochiKit/Base.js
|
||||
MochiKit/Color.js
|
||||
MochiKit/DateTime.js
|
||||
MochiKit/DOM.js
|
||||
MochiKit/Format.js
|
||||
MochiKit/Iter.js
|
||||
MochiKit/Logging.js
|
||||
MochiKit/LoggingPane.js
|
||||
MochiKit/MochiKit.js
|
||||
MochiKit/MockDOM.js
|
||||
MochiKit/Signal.js
|
||||
MochiKit/Test.js
|
||||
MochiKit/Visual.js
|
||||
packed/MochiKit/__package__.js
|
||||
packed/MochiKit/MochiKit.js
|
||||
tests/index.html
|
||||
tests/test_Base.js
|
||||
tests/test_Color.js
|
||||
tests/test_DateTime.js
|
||||
tests/test_Format.js
|
||||
tests/test_Iter.js
|
||||
tests/test_Logging.js
|
||||
tests/test_MochiKit-Async.html
|
||||
tests/test_MochiKit-Base.html
|
||||
tests/test_MochiKit-Color.html
|
||||
tests/test_MochiKit-DateTime.html
|
||||
tests/test_MochiKit-DOM.html
|
||||
tests/test_MochiKit-Format.html
|
||||
tests/test_MochiKit-Iter.html
|
||||
tests/test_MochiKit-JSAN.html
|
||||
tests/test_MochiKit-Logging.html
|
||||
tests/test_MochiKit-MochiKit.html
|
||||
tests/test_MochiKit-Signal.html
|
||||
tests/test_Signal.js
|
||||
tests/SimpleTest/SimpleTest.js
|
||||
tests/SimpleTest/test.css
|
||||
tests/SimpleTest/TestRunner.js
|
||||
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"recommends": {
|
||||
"JSAN": "0.10"
|
||||
},
|
||||
"name": "MochiKit",
|
||||
"license": "mit",
|
||||
"author": [
|
||||
"Bob Ippolito <bob@redivi.com>"
|
||||
],
|
||||
"abstract": "Python-inspired JavaScript kit",
|
||||
"generated_by": "MochiKit's build script",
|
||||
"build_requires": {
|
||||
"Test.Simple": "0.11"
|
||||
},
|
||||
"version": "1.3.1",
|
||||
"provides": {}
|
||||
}
|
||||
@@ -1,606 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
||||
<title>MochiKit.Async - manage asynchronous tasks</title>
|
||||
|
||||
<link rel="stylesheet" href="../../../include/css/documentation.css" type="text/css" />
|
||||
<script type="text/javascript" src="../../../packed/lib/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="../../js/toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document">
|
||||
<div class="section">
|
||||
<h1><a id="name" name="name">Name</a></h1>
|
||||
<p>MochiKit.Async - manage asynchronous tasks</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="synopsis" name="synopsis">Synopsis</a></h1>
|
||||
<pre class="literal-block">
|
||||
var url = "/src/b/bo/bob/MochiKit.Async/META.json";
|
||||
/*
|
||||
|
||||
META.json looks something like this:
|
||||
|
||||
{"name": "MochiKit", "version": "0.5"}
|
||||
|
||||
*/
|
||||
var d = loadJSONDoc(url);
|
||||
var gotMetadata = function (meta) {
|
||||
if (MochiKit.Async.VERSION == meta.version) {
|
||||
alert("You have the newest MochiKit.Async!");
|
||||
} else {
|
||||
alert("MochiKit.Async "
|
||||
+ meta.version
|
||||
+ " is available, upgrade!");
|
||||
}
|
||||
};
|
||||
var metadataFetchFailed = function (err) {
|
||||
alert("The metadata for MochiKit.Async could not be fetched :(");
|
||||
};
|
||||
d.addCallbacks(gotMetadata, metadataFetchFailed);
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="description" name="description">Description</a></h1>
|
||||
<p>MochiKit.Async provides facilities to manage asynchronous
|
||||
(as in AJAX <a class="footnote-reference" href="#id7" id="id1" name="id1">[1]</a>) tasks. The model for asynchronous computation
|
||||
used in this module is heavily inspired by Twisted <a class="footnote-reference" href="#id8" id="id2" name="id2">[2]</a>.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="dependencies" name="dependencies">Dependencies</a></h1>
|
||||
<ul class="simple">
|
||||
<li><a class="mochiref reference" href="Base.html">MochiKit.Base</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="overview" name="overview">Overview</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="deferred" name="deferred">Deferred</a></h2>
|
||||
<p>The Deferred constructor encapsulates a single value that
|
||||
is not available yet. The most important example of this
|
||||
in the context of a web browser would be an <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt>
|
||||
to a server. The importance of the Deferred is that it
|
||||
allows a consistent API to be exposed for all asynchronous
|
||||
computations that occur exactly once.</p>
|
||||
<p>The producer of the Deferred is responsible for doing all
|
||||
of the complicated work behind the scenes. This often
|
||||
means waiting for a timer to fire, or waiting for an event
|
||||
(e.g. <tt class="docutils literal"><span class="pre">onreadystatechange</span></tt> of <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt>).
|
||||
It could also be coordinating several events (e.g.
|
||||
<tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt> with a timeout, or several Deferreds
|
||||
(e.g. fetching a set of XML documents that should be
|
||||
processed at the same time).</p>
|
||||
<p>Since these sorts of tasks do not respond immediately, the
|
||||
producer of the Deferred does the following steps before
|
||||
returning to the consumer:</p>
|
||||
<ol class="arabic simple">
|
||||
<li>Create a <tt class="docutils literal"><span class="pre">new</span></tt> <a class="mochiref reference" href="#fn-deferred">Deferred();</a> object and keep a reference
|
||||
to it, because it will be needed later when the value is
|
||||
ready.</li>
|
||||
<li>Setup the conditions to create the value requested (e.g.
|
||||
create a new <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt>, set its
|
||||
<tt class="docutils literal"><span class="pre">onreadystatechange</span></tt>).</li>
|
||||
<li>Return the <a class="mochiref reference" href="#fn-deferred">Deferred</a> object.</li>
|
||||
</ol>
|
||||
<p>Since the value is not yet ready, the consumer attaches
|
||||
a function to the Deferred that will be called when the
|
||||
value is ready. This is not unlike <tt class="docutils literal"><span class="pre">setTimeout</span></tt>, or
|
||||
other similar facilities you may already be familiar with.
|
||||
The consumer can also attach an "errback" to the
|
||||
<a class="mochiref reference" href="#fn-deferred">Deferred</a>, which is a callback for error handling.</p>
|
||||
<p>When the value is ready, the producer simply calls
|
||||
<tt class="docutils literal"><span class="pre">myDeferred.callback(theValue)</span></tt>. If an error occurred,
|
||||
it should call <tt class="docutils literal"><span class="pre">myDeferred.errback(theValue)</span></tt> instead.
|
||||
As soon as this happens, the callback that the consumer
|
||||
attached to the <a class="mochiref reference" href="#fn-deferred">Deferred</a> is called with <tt class="docutils literal"><span class="pre">theValue</span></tt>
|
||||
as the only argument.</p>
|
||||
<p>There are quite a few additional "advanced" features
|
||||
baked into <a class="mochiref reference" href="#fn-deferred">Deferred</a>, such as cancellation and
|
||||
callback chains, so take a look at the API
|
||||
reference if you would like to know more!</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="api-reference" name="api-reference">API Reference</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="errors" name="errors">Errors</a></h2>
|
||||
<p>
|
||||
<a name="fn-alreadycallederror"></a>
|
||||
<a class="mochidef reference" href="#fn-alreadycallederror">AlreadyCalledError</a>:</p>
|
||||
<blockquote>
|
||||
Thrown by a <a class="mochiref reference" href="#fn-deferred">Deferred</a> if <tt class="docutils literal"><span class="pre">.callback</span></tt> or
|
||||
<tt class="docutils literal"><span class="pre">.errback</span></tt> are called more than once.</blockquote>
|
||||
<p>
|
||||
<a name="fn-browsercomplianceerror"></a>
|
||||
<a class="mochidef reference" href="#fn-browsercomplianceerror">BrowserComplianceError</a>:</p>
|
||||
<blockquote>
|
||||
Thrown when the JavaScript runtime is not capable of performing
|
||||
the given function. Currently, this happens if the browser
|
||||
does not support <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-cancellederror"></a>
|
||||
<a class="mochidef reference" href="#fn-cancellederror">CancelledError</a>:</p>
|
||||
<blockquote>
|
||||
Thrown by a <a class="mochiref reference" href="#fn-deferred">Deferred</a> when it is cancelled,
|
||||
unless a canceller is present and throws something else.</blockquote>
|
||||
<p>
|
||||
<a name="fn-genericerror"></a>
|
||||
<a class="mochidef reference" href="#fn-genericerror">GenericError</a>:</p>
|
||||
<blockquote>
|
||||
Results passed to <tt class="docutils literal"><span class="pre">.fail</span></tt> or <tt class="docutils literal"><span class="pre">.errback</span></tt> of a <a class="mochiref reference" href="#fn-deferred">Deferred</a>
|
||||
are wrapped by this <tt class="docutils literal"><span class="pre">Error</span></tt> if <tt class="docutils literal"><span class="pre">!(result</span> <span class="pre">instanceof</span> <span class="pre">Error)</span></tt>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-xmlhttprequesterror"></a>
|
||||
<a class="mochidef reference" href="#fn-xmlhttprequesterror">XMLHttpRequestError</a>:</p>
|
||||
<blockquote>
|
||||
Thrown when an <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt> does not complete successfully
|
||||
for any reason. The <tt class="docutils literal"><span class="pre">req</span></tt> property of the error is the failed
|
||||
<tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt> object, and for convenience the <tt class="docutils literal"><span class="pre">number</span></tt>
|
||||
property corresponds to <tt class="docutils literal"><span class="pre">req.status</span></tt>.</blockquote>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="constructors" name="constructors">Constructors</a></h2>
|
||||
<p>
|
||||
<a name="fn-deferred"></a>
|
||||
<a class="mochidef reference" href="#fn-deferred">Deferred()</a>:</p>
|
||||
<blockquote>
|
||||
Encapsulates a sequence of callbacks in response to a value that
|
||||
may not yet be available. This is modeled after the Deferred class
|
||||
from Twisted <a class="footnote-reference" href="#id9" id="id3" name="id3">[3]</a>.</blockquote>
|
||||
<blockquote>
|
||||
<p>Why do we want this? JavaScript has no threads, and even if it did,
|
||||
threads are hard. Deferreds are a way of abstracting non-blocking
|
||||
events, such as the final response to an <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt>.</p>
|
||||
<p>The sequence of callbacks is internally represented as a list
|
||||
of 2-tuples containing the callback/errback pair. For example,
|
||||
the following call sequence:</p>
|
||||
<pre class="literal-block">
|
||||
var d = new Deferred();
|
||||
d.addCallback(myCallback);
|
||||
d.addErrback(myErrback);
|
||||
d.addBoth(myBoth);
|
||||
d.addCallbacks(myCallback, myErrback);
|
||||
</pre>
|
||||
<p>is translated into a <a class="mochiref reference" href="#fn-deferred">Deferred</a> with the following internal
|
||||
representation:</p>
|
||||
<pre class="literal-block">
|
||||
[
|
||||
[myCallback, null],
|
||||
[null, myErrback],
|
||||
[myBoth, myBoth],
|
||||
[myCallback, myErrback]
|
||||
]
|
||||
</pre>
|
||||
<p>The <a class="mochiref reference" href="#fn-deferred">Deferred</a> also keeps track of its current status (fired).
|
||||
Its status may be one of the following three values:</p>
|
||||
<blockquote>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="14%" />
|
||||
<col width="86%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th class="head">Value</th>
|
||||
<th class="head">Condition</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td>-1</td>
|
||||
<td>no value yet (initial condition)</td>
|
||||
</tr>
|
||||
<tr><td>0</td>
|
||||
<td>success</td>
|
||||
</tr>
|
||||
<tr><td>1</td>
|
||||
<td>error</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</blockquote>
|
||||
<p>A <a class="mochiref reference" href="#fn-deferred">Deferred</a> will be in the error state if one of the following
|
||||
conditions are met:</p>
|
||||
<ol class="arabic simple">
|
||||
<li>The result given to callback or errback is "<tt class="docutils literal"><span class="pre">instanceof</span> <span class="pre">Error</span></tt>"</li>
|
||||
<li>The callback or errback threw while executing. If the thrown object
|
||||
is not <tt class="docutils literal"><span class="pre">instanceof</span> <span class="pre">Error</span></tt>, it will be wrapped with
|
||||
<a class="mochiref reference" href="#fn-genericerror">GenericError</a>.</li>
|
||||
</ol>
|
||||
<p>Otherwise, the <a class="mochiref reference" href="#fn-deferred">Deferred</a> will be in the success state. The state
|
||||
of the <a class="mochiref reference" href="#fn-deferred">Deferred</a> determines the next element in the callback
|
||||
sequence to run.</p>
|
||||
<p>When a callback or errback occurs with the example deferred chain, something
|
||||
equivalent to the following will happen (imagine that exceptions are caught
|
||||
and returned as-is):</p>
|
||||
<pre class="literal-block">
|
||||
// d.callback(result) or d.errback(result)
|
||||
if (!(result instanceof Error)) {
|
||||
result = myCallback(result);
|
||||
}
|
||||
if (result instanceof Error) {
|
||||
result = myErrback(result);
|
||||
}
|
||||
result = myBoth(result);
|
||||
if (result instanceof Error) {
|
||||
result = myErrback(result);
|
||||
} else {
|
||||
result = myCallback(result);
|
||||
}
|
||||
</pre>
|
||||
<p>The result is then stored away in case another step is added to the
|
||||
callback sequence. Since the <a class="mochiref reference" href="#fn-deferred">Deferred</a> already has a value
|
||||
available, any new callbacks added will be called immediately.</p>
|
||||
<p>There are two other "advanced" details about this implementation that are
|
||||
useful:</p>
|
||||
<p>Callbacks are allowed to return <a class="mochiref reference" href="#fn-deferred">Deferred</a> instances,
|
||||
so you can build complicated sequences of events with (relative) ease.</p>
|
||||
<p>The creator of the <a class="mochiref reference" href="#fn-deferred">Deferred</a> may specify a canceller. The
|
||||
canceller is a function that will be called if
|
||||
<a class="mochiref reference" href="#fn-deferred.prototype.cancel">Deferred.prototype.cancel</a> is called before the
|
||||
<a class="mochiref reference" href="#fn-deferred">Deferred</a> fires. You can use this to allow an
|
||||
<tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt> to be cleanly cancelled, for example. Note that
|
||||
cancel will fire the <a class="mochiref reference" href="#fn-deferred">Deferred</a> with a
|
||||
<a class="mochiref reference" href="#fn-cancellederror">CancelledError</a> (unless your canceller throws or returns
|
||||
a different <tt class="docutils literal"><span class="pre">Error</span></tt>), so errbacks should be prepared to handle that
|
||||
<tt class="docutils literal"><span class="pre">Error</span></tt> gracefully for cancellable <a class="mochiref reference" href="#fn-deferred">Deferred</a> instances.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-deferred.prototype.addboth"></a>
|
||||
<a class="mochidef reference" href="#fn-deferred.prototype.addboth">Deferred.prototype.addBoth(func)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Add the same function as both a callback and an errback as the
|
||||
next element on the callback sequence. This is useful for code
|
||||
that you want to guarantee to run, e.g. a finalizer.</p>
|
||||
<p>If additional arguments are given, then <tt class="docutils literal"><span class="pre">func</span></tt> will be replaced
|
||||
with <a class="mochiref reference" href="Base.html#fn-partial">MochiKit.Base.partial.apply(null, arguments)</a>. This
|
||||
differs from <a class="reference" href="http://twistedmatrix.com/">Twisted</a>, because the result of the callback or
|
||||
errback will be the <em>last</em> argument passed to <tt class="docutils literal"><span class="pre">func</span></tt>.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">func</span></tt> returns a <a class="mochiref reference" href="#fn-deferred">Deferred</a>, then it will be chained
|
||||
(its value or error will be passed to the next callback). Note that
|
||||
once the returned <tt class="docutils literal"><span class="pre">Deferred</span></tt> is chained, it can no longer accept new
|
||||
callbacks.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-deferred.prototype.addcallback"></a>
|
||||
<a class="mochidef reference" href="#fn-deferred.prototype.addcallback">Deferred.prototype.addCallback(func[, ...])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Add a single callback to the end of the callback sequence.</p>
|
||||
<p>If additional arguments are given, then <tt class="docutils literal"><span class="pre">func</span></tt> will be replaced
|
||||
with <a class="mochiref reference" href="Base.html#fn-partial">MochiKit.Base.partial.apply(null, arguments)</a>. This
|
||||
differs from <a class="reference" href="http://twistedmatrix.com/">Twisted</a>, because the result of the callback will
|
||||
be the <em>last</em> argument passed to <tt class="docutils literal"><span class="pre">func</span></tt>.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">func</span></tt> returns a <a class="mochiref reference" href="#fn-deferred">Deferred</a>, then it will be chained
|
||||
(its value or error will be passed to the next callback). Note that
|
||||
once the returned <tt class="docutils literal"><span class="pre">Deferred</span></tt> is chained, it can no longer accept new
|
||||
callbacks.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-deferred.prototype.addcallbacks"></a>
|
||||
<a class="mochidef reference" href="#fn-deferred.prototype.addcallbacks">Deferred.prototype.addCallbacks(callback, errback)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Add separate callback and errback to the end of the callback
|
||||
sequence. Either callback or errback may be <tt class="docutils literal"><span class="pre">null</span></tt>,
|
||||
but not both.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">callback</span></tt> or <tt class="docutils literal"><span class="pre">errback</span></tt> returns a <a class="mochiref reference" href="#fn-deferred">Deferred</a>,
|
||||
then it will be chained (its value or error will be passed to the
|
||||
next callback). Note that once the returned <tt class="docutils literal"><span class="pre">Deferred</span></tt> is chained,
|
||||
it can no longer accept new callbacks.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-deferred.prototype.adderrback"></a>
|
||||
<a class="mochidef reference" href="#fn-deferred.prototype.adderrback">Deferred.prototype.addErrback(func)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Add a single errback to the end of the callback sequence.</p>
|
||||
<p>If additional arguments are given, then <tt class="docutils literal"><span class="pre">func</span></tt> will be replaced
|
||||
with <a class="mochiref reference" href="Base.html#fn-partial">MochiKit.Base.partial.apply(null, arguments)</a>. This
|
||||
differs from <a class="reference" href="http://twistedmatrix.com/">Twisted</a>, because the result of the errback will
|
||||
be the <em>last</em> argument passed to <tt class="docutils literal"><span class="pre">func</span></tt>.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">func</span></tt> returns a <a class="mochiref reference" href="#fn-deferred">Deferred</a>, then it will be chained
|
||||
(its value or error will be passed to the next callback). Note that
|
||||
once the returned <tt class="docutils literal"><span class="pre">Deferred</span></tt> is chained, it can no longer accept new
|
||||
callbacks.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-deferred.prototype.callback"></a>
|
||||
<a class="mochidef reference" href="#fn-deferred.prototype.callback">Deferred.prototype.callback([result])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Begin the callback sequence with a non-<tt class="docutils literal"><span class="pre">Error</span></tt> result. Result
|
||||
may be any value except for a <a class="mochiref reference" href="#fn-deferred">Deferred</a>.</p>
|
||||
<p>Either <tt class="docutils literal"><span class="pre">.callback</span></tt> or <tt class="docutils literal"><span class="pre">.errback</span></tt> should
|
||||
be called exactly once on a <a class="mochiref reference" href="#fn-deferred">Deferred</a>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-deferred.prototype.cancel"></a>
|
||||
<a class="mochidef reference" href="#fn-deferred.prototype.cancel">Deferred.prototype.cancel()</a>:</p>
|
||||
<blockquote>
|
||||
<p>Cancels a <a class="mochiref reference" href="#fn-deferred">Deferred</a> that has not yet received a value,
|
||||
or is waiting on another <a class="mochiref reference" href="#fn-deferred">Deferred</a> as its value.</p>
|
||||
<p>If a canceller is defined, the canceller is called.
|
||||
If the canceller did not return an <tt class="docutils literal"><span class="pre">Error</span></tt>, or there
|
||||
was no canceller, then the errback chain is started
|
||||
with <a class="mochiref reference" href="#fn-cancellederror">CancelledError</a>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-deferred.prototype.errback"></a>
|
||||
<a class="mochidef reference" href="#fn-deferred.prototype.errback">Deferred.prototype.errback([result])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Begin the callback sequence with an error result.
|
||||
Result may be any value except for a <a class="mochiref reference" href="#fn-deferred">Deferred</a>,
|
||||
but if <tt class="docutils literal"><span class="pre">!(result</span> <span class="pre">instanceof</span> <span class="pre">Error)</span></tt>, it will be wrapped
|
||||
with <a class="mochiref reference" href="#fn-genericerror">GenericError</a>.</p>
|
||||
<p>Either <tt class="docutils literal"><span class="pre">.callback</span></tt> or <tt class="docutils literal"><span class="pre">.errback</span></tt> should
|
||||
be called exactly once on a
|
||||
<a name="fn-deferred"></a>
|
||||
<a class="mochidef reference" href="#fn-deferred">Deferred</a>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-deferredlock"></a>
|
||||
<a class="mochidef reference" href="#fn-deferredlock">DeferredLock()</a>:</p>
|
||||
<blockquote>
|
||||
<p>A lock for asynchronous systems.</p>
|
||||
<p>The <tt class="docutils literal"><span class="pre">locked</span></tt> property of a <a class="mochiref reference" href="#fn-deferredlock">DeferredLock</a> will be <tt class="docutils literal"><span class="pre">true</span></tt> if
|
||||
it locked, <tt class="docutils literal"><span class="pre">false</span></tt> otherwise. Do not change this property.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-deferredlock.prototype.acquire"></a>
|
||||
<a class="mochidef reference" href="#fn-deferredlock.prototype.acquire">DeferredLock.prototype.acquire()</a>:</p>
|
||||
<blockquote>
|
||||
Attempt to acquire the lock. Returns a <a class="mochiref reference" href="#fn-deferred">Deferred</a> that fires on
|
||||
lock acquisition with the <a class="mochiref reference" href="#fn-deferredlock">DeferredLock</a> as the value.
|
||||
If the lock is locked, then the <a class="mochiref reference" href="#fn-deferred">Deferred</a> goes into a waiting
|
||||
list.</blockquote>
|
||||
<p>
|
||||
<a name="fn-deferredlock.prototype.release"></a>
|
||||
<a class="mochidef reference" href="#fn-deferredlock.prototype.release">DeferredLock.prototype.release()</a>:</p>
|
||||
<blockquote>
|
||||
Release the lock. If there is a waiting list, then the first
|
||||
<a class="mochiref reference" href="#fn-deferred">Deferred</a> in that waiting list will be called back.</blockquote>
|
||||
<p>
|
||||
<a name="fn-deferredlist"></a>
|
||||
<a class="mochidef reference" href="#fn-deferredlist">DeferredList(list, [fireOnOneCallback, fireOnOneErrback, consumeErrors, canceller])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Combine a list of <a class="mochiref reference" href="#fn-deferred">Deferred</a> into one. Track the callbacks and
|
||||
return a list of (success, result) tuples, 'success' being a boolean
|
||||
indicating whether result is a normal result or an error.</p>
|
||||
<p>Once created, you have access to all <a class="mochiref reference" href="#fn-deferred">Deferred</a> methods, like
|
||||
addCallback, addErrback, addBoth. The behaviour can be changed by the
|
||||
following options:</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">fireOnOneCallback</span></tt>:</dt>
|
||||
<dd>Flag for launching the callback once the first Deferred of the list
|
||||
has returned.</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">fireOnOneErrback</span></tt>:</dt>
|
||||
<dd>Flag for calling the errback at the first error of a Deferred.</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">consumeErrors</span></tt>:</dt>
|
||||
<dd>Flag indicating that any errors raised in the Deferreds should be
|
||||
consumed by the DeferredList.</dd>
|
||||
</dl>
|
||||
<p>Example:</p>
|
||||
<pre class="literal-block">
|
||||
// We need to fetch data from 2 different urls
|
||||
var d1 = loadJSONDoc(url1);
|
||||
var d2 = loadJSONDoc(url2);
|
||||
var l1 = new DeferredList([d1, d2], false, false, true);
|
||||
l1.addCallback(function (resultList) {
|
||||
MochiKit.Base.map(function (result) {
|
||||
if (result[0]) {
|
||||
alert("Data is here: " + result[1]);
|
||||
} else {
|
||||
alert("Got an error: " + result[1]);
|
||||
}
|
||||
}, resultList);
|
||||
});
|
||||
</pre>
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="functions" name="functions">Functions</a></h2>
|
||||
<p>
|
||||
<a name="fn-calllater"></a>
|
||||
<a class="mochidef reference" href="#fn-calllater">callLater(seconds, func[, args...])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Call <tt class="docutils literal"><span class="pre">func(args...)</span></tt> after at least <tt class="docutils literal"><span class="pre">seconds</span></tt> seconds have elapsed.
|
||||
This is a convenience method for:</p>
|
||||
<pre class="literal-block">
|
||||
func = partial.apply(extend(null, arguments, 1));
|
||||
return wait(seconds).addCallback(function (res) { return func() });
|
||||
</pre>
|
||||
<p>Returns a cancellable <a class="mochiref reference" href="#fn-deferred">Deferred</a>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-dosimplexmlhttprequest"></a>
|
||||
<a class="mochidef reference" href="#fn-dosimplexmlhttprequest">doSimpleXMLHttpRequest(url[, queryArguments...])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Perform a simple <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt> and wrap it with a
|
||||
<a class="mochiref reference" href="#fn-deferred">Deferred</a> that may be cancelled.</p>
|
||||
<p>Note that currently, only <tt class="docutils literal"><span class="pre">200</span></tt> (OK) and <tt class="docutils literal"><span class="pre">304</span></tt>
|
||||
(NOT_MODIFIED) are considered success codes at this time, other
|
||||
status codes will result in an errback with an <tt class="docutils literal"><span class="pre">XMLHttpRequestError</span></tt>.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">url</span></tt>:</dt>
|
||||
<dd>The URL to GET</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">queryArguments</span></tt>:</dt>
|
||||
<dd><p class="first">If this function is called with more than one argument, a <tt class="docutils literal"><span class="pre">"?"</span></tt>
|
||||
and the result of <a class="mochiref reference" href="Base.html#fn-querystring">MochiKit.Base.queryString</a> with
|
||||
the rest of the arguments are appended to the URL.</p>
|
||||
<p>For example, this will do a GET request to the URL
|
||||
<tt class="docutils literal"><span class="pre">http://example.com?bar=baz</span></tt>:</p>
|
||||
<pre class="last literal-block">
|
||||
doSimpleXMLHttpRequest("http://example.com", {bar: "baz"});
|
||||
</pre>
|
||||
</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd><a class="mochiref reference" href="#fn-deferred">Deferred</a> that will callback with the <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt>
|
||||
instance on success</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-evaljsonrequest"></a>
|
||||
<a class="mochidef reference" href="#fn-evaljsonrequest">evalJSONRequest(req)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Evaluate a JSON <a class="footnote-reference" href="#id10" id="id4" name="id4">[4]</a> <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt></p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">req</span></tt>:</dt>
|
||||
<dd>The request whose <tt class="docutils literal"><span class="pre">.responseText</span></tt> property is to be evaluated</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd>A JavaScript object</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-fail"></a>
|
||||
<a class="mochidef reference" href="#fn-fail">fail([result])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return a <a class="mochiref reference" href="#fn-deferred">Deferred</a> that has already had <tt class="docutils literal"><span class="pre">.errback(result)</span></tt>
|
||||
called.</p>
|
||||
<p>See <tt class="docutils literal"><span class="pre">succeed</span></tt> documentation for rationale.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">result</span></tt>:</dt>
|
||||
<dd>The result to give to <a class="mochiref reference" href="#fn-deferred.prototype.errback">Deferred.prototype.errback(result)</a>.</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd>A <tt class="docutils literal"><span class="pre">new</span></tt> <a class="mochiref reference" href="#fn-deferred">Deferred()</a></dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-gatherresults"></a>
|
||||
<a class="mochidef reference" href="#fn-gatherresults">gatherResults(deferreds)</a>:</p>
|
||||
<blockquote>
|
||||
A convenience function that returns a <a class="mochiref reference" href="#fn-deferredlist">DeferredList</a>
|
||||
from the given <tt class="docutils literal"><span class="pre">Array</span></tt> of <a class="mochiref reference" href="#fn-deferred">Deferred</a> instances
|
||||
that will callback with an <tt class="docutils literal"><span class="pre">Array</span></tt> of just results when
|
||||
they're available, or errback on the first array.</blockquote>
|
||||
<p>
|
||||
<a name="fn-getxmlhttprequest"></a>
|
||||
<a class="mochidef reference" href="#fn-getxmlhttprequest">getXMLHttpRequest()</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return an <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt> compliant object for the current
|
||||
platform.</p>
|
||||
<p>In order of preference:</p>
|
||||
<ul class="simple">
|
||||
<li><tt class="docutils literal"><span class="pre">new</span> <span class="pre">XMLHttpRequest()</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">new</span> <span class="pre">ActiveXObject('Msxml2.XMLHTTP')</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">new</span> <span class="pre">ActiveXObject('Microsoft.XMLHTTP')</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">new</span> <span class="pre">ActiveXObject('Msxml2.XMLHTTP.4.0')</span></tt></li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-maybedeferred"></a>
|
||||
<a class="mochidef reference" href="#fn-maybedeferred">maybeDeferred(func[, argument...])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Call a <tt class="docutils literal"><span class="pre">func</span></tt> with the given arguments and ensure the result is a
|
||||
<a class="mochiref reference" href="#fn-deferred">Deferred</a>.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">func</span></tt>:</dt>
|
||||
<dd>The function to call.</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd>A new <a class="mochiref reference" href="#fn-deferred">Deferred</a> based on the call to <tt class="docutils literal"><span class="pre">func</span></tt>. If <tt class="docutils literal"><span class="pre">func</span></tt>
|
||||
does not naturally return a <a class="mochiref reference" href="#fn-deferred">Deferred</a>, its result or error
|
||||
value will be wrapped by one.</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-loadjsondoc"></a>
|
||||
<a class="mochidef reference" href="#fn-loadjsondoc">loadJSONDoc(url)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Do a simple <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt> to a URL and get the response
|
||||
as a JSON <a class="footnote-reference" href="#id10" id="id5" name="id5">[4]</a> document.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">url</span></tt>:</dt>
|
||||
<dd>The URL to GET</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd><a class="mochiref reference" href="#fn-deferred">Deferred</a> that will callback with the evaluated JSON <a class="footnote-reference" href="#id10" id="id6" name="id6">[4]</a>
|
||||
response upon successful <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt></dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-sendxmlhttprequest"></a>
|
||||
<a class="mochidef reference" href="#fn-sendxmlhttprequest">sendXMLHttpRequest(req[, sendContent])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Set an <tt class="docutils literal"><span class="pre">onreadystatechange</span></tt> handler on an <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt> object
|
||||
and send it off. Will return a cancellable <a class="mochiref reference" href="#fn-deferred">Deferred</a> that will
|
||||
callback on success.</p>
|
||||
<p>Note that currently, only <tt class="docutils literal"><span class="pre">200</span></tt> (OK) and <tt class="docutils literal"><span class="pre">304</span></tt>
|
||||
(NOT_MODIFIED) are considered success codes at this time, other
|
||||
status codes will result in an errback with an <tt class="docutils literal"><span class="pre">XMLHttpRequestError</span></tt>.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">req</span></tt>:</dt>
|
||||
<dd>An preconfigured <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt> object (open has been called).</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">sendContent</span></tt>:</dt>
|
||||
<dd>Optional string or DOM content to send over the <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt>.</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd><a class="mochiref reference" href="#fn-deferred">Deferred</a> that will callback with the <tt class="docutils literal"><span class="pre">XMLHttpRequest</span></tt>
|
||||
instance on success.</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-succeed"></a>
|
||||
<a class="mochidef reference" href="#fn-succeed">succeed([result])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return a <a class="mochiref reference" href="#fn-deferred">Deferred</a> that has already had <tt class="docutils literal"><span class="pre">.callback(result)</span></tt>
|
||||
called.</p>
|
||||
<p>This is useful when you're writing synchronous code to an asynchronous
|
||||
interface: i.e., some code is calling you expecting a <a class="mochiref reference" href="#fn-deferred">Deferred</a>
|
||||
result, but you don't actually need to do anything asynchronous. Just
|
||||
return <tt class="docutils literal"><span class="pre">succeed(theResult)</span></tt>.</p>
|
||||
<p>See <tt class="docutils literal"><span class="pre">fail</span></tt> for a version of this function that uses a failing
|
||||
<a class="mochiref reference" href="#fn-deferred">Deferred</a> rather than a successful one.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">result</span></tt>:</dt>
|
||||
<dd>The result to give to <a class="mochiref reference" href="#fn-deferred.prototype.callback">Deferred.prototype.callback(result)</a></dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd>a <tt class="docutils literal"><span class="pre">new</span></tt> <a class="mochiref reference" href="#fn-deferred">Deferred</a></dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-wait"></a>
|
||||
<a class="mochidef reference" href="#fn-wait">wait(seconds[, res])</a>:</p>
|
||||
<blockquote>
|
||||
Return a new cancellable <a class="mochiref reference" href="#fn-deferred">Deferred</a> that will <tt class="docutils literal"><span class="pre">.callback(res)</span></tt>
|
||||
after at least <tt class="docutils literal"><span class="pre">seconds</span></tt> seconds have elapsed.</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="see-also" name="see-also">See Also</a></h1>
|
||||
<table class="docutils footnote" frame="void" id="id7" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id1" name="id7">[1]</a></td><td>AJAX, Asynchronous JavaScript and XML: <a class="reference" href="http://en.wikipedia.org/wiki/AJAX">http://en.wikipedia.org/wiki/AJAX</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="id8" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id2" name="id8">[2]</a></td><td>Twisted, an event-driven networking framework written in Python: <a class="reference" href="http://twistedmatrix.com/">http://twistedmatrix.com/</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="id9" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id3" name="id9">[3]</a></td><td>Twisted Deferred Reference: <a class="reference" href="http://twistedmatrix.com/projects/core/documentation/howto/defer.html">http://twistedmatrix.com/projects/core/documentation/howto/defer.html</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="id10" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a name="id10">[4]</a></td><td><em>(<a class="fn-backref" href="#id4">1</a>, <a class="fn-backref" href="#id5">2</a>, <a class="fn-backref" href="#id6">3</a>)</em> JSON, JavaScript Object Notation: <a class="reference" href="http://json.org/">http://json.org/</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="authors" name="authors">Authors</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="copyright" name="copyright">Copyright</a></h1>
|
||||
<p>Copyright 2005 Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>>. This program is dual-licensed
|
||||
free software; you can redistribute it and/or modify it under the terms of the
|
||||
<a class="reference" href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> or the <a class="reference" href="http://www.opensource.org/licenses/afl-2.1.php">Academic Free License v2.1</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,509 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
||||
<title>MochiKit.Color - color abstraction with CSS3 support</title>
|
||||
|
||||
<link rel="stylesheet" href="../../../include/css/documentation.css" type="text/css" />
|
||||
<script type="text/javascript" src="../../../packed/lib/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="../../js/toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document">
|
||||
<div class="section">
|
||||
<h1><a id="name" name="name">Name</a></h1>
|
||||
<p>MochiKit.Color - color abstraction with CSS3 support</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="synopsis" name="synopsis">Synopsis</a></h1>
|
||||
<pre class="literal-block">
|
||||
// RGB color expressions are supported
|
||||
assert(
|
||||
objEqual(Color.whiteColor(), Color.fromString("rgb(255,100%, 255)"))
|
||||
);
|
||||
|
||||
// So is instantiating directly from HSL or RGB values.
|
||||
// Note that fromRGB and fromHSL take numbers between 0.0 and 1.0!
|
||||
assert( objEqual(Color.fromRGB(1.0, 1.0, 1.0), Color.fromHSL(0.0, 0.0, 1.0) );
|
||||
|
||||
// Or even SVG color keyword names, as per CSS3!
|
||||
assert( Color.fromString("aquamarine"), "#7fffd4" );
|
||||
|
||||
// NSColor-like colors built in
|
||||
assert( Color.whiteColor().toHexString() == "#ffffff" );
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="description" name="description">Description</a></h1>
|
||||
<p>MochiKit.Color is an abstraction for handling colors and strings that
|
||||
represent colors.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="dependencies" name="dependencies">Dependencies</a></h1>
|
||||
<ul class="simple">
|
||||
<li><a class="mochiref reference" href="Base.html">MochiKit.Base</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="overview" name="overview">Overview</a></h1>
|
||||
<p>MochiKit.Color provides an abstraction of RGB, HSL and HSV colors with alpha.
|
||||
It supports parsing and generating of CSS3 colors, and has a full CSS3 (SVG)
|
||||
color table.</p>
|
||||
<p>All of the functionality in this module is exposed through a Color constructor
|
||||
and its prototype, but a few of its internals are available for direct use at
|
||||
module level.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="api-reference" name="api-reference">API Reference</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="constructors" name="constructors">Constructors</a></h2>
|
||||
<p>
|
||||
<a name="fn-color"></a>
|
||||
<a class="mochidef reference" href="#fn-color">Color()</a>:</p>
|
||||
<blockquote>
|
||||
<p>Represents a color. Component values should be integers between <tt class="docutils literal"><span class="pre">0.0</span></tt>
|
||||
and <tt class="docutils literal"><span class="pre">1.0</span></tt>. You should use one of the <a class="mochiref reference" href="#fn-color">Color</a> factory
|
||||
functions such as <a class="mochiref reference" href="#fn-color.fromrgb">Color.fromRGB</a>, <a class="mochiref reference" href="#fn-color.fromhsl">Color.fromHSL</a>,
|
||||
etc. instead of constructing <a class="mochiref reference" href="#fn-color">Color</a> objects directly.</p>
|
||||
<p><a class="mochiref reference" href="#fn-color">Color</a> instances can be compared with
|
||||
<a class="mochiref reference" href="Base.html#fn-compare">MochiKit.Base.compare</a> (though ordering is on RGB, so is not
|
||||
particularly meaningful except for equality), and the default <tt class="docutils literal"><span class="pre">toString</span></tt>
|
||||
implementation returns <a class="mochiref reference" href="#fn-color.prototype.tohexstring">Color.prototype.toHexString()</a>.</p>
|
||||
<p><a class="mochiref reference" href="#fn-color">Color</a> instances are immutable, and much of the architecture is
|
||||
inspired by AppKit's NSColor <a class="footnote-reference" href="#id6" id="id1" name="id1">[1]</a></p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.frombackground"></a>
|
||||
<a class="mochidef reference" href="#fn-color.frombackground">Color.fromBackground(elem)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Returns a <a class="mochiref reference" href="#fn-color">Color</a> object based on the background of the provided
|
||||
element. Equivalent to:</p>
|
||||
<pre class="literal-block">
|
||||
c = Color.fromComputedStyle(
|
||||
elem, "backgroundColor", "background-color") || Color.whiteColor();
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.fromcomputedstyle"></a>
|
||||
<a class="mochidef reference" href="#fn-color.fromcomputedstyle">Color.fromComputedStyle(elem, style, mozillaEquivalentCSS)</a>:</p>
|
||||
<blockquote>
|
||||
Returns a <a class="mochiref reference" href="#fn-color">Color</a> object based on the result of
|
||||
<a class="mochiref reference" href="DOM.html#fn-computedstyle">MochiKit.DOM.computedStyle(elem, style, mozillaEquivalentCSS)</a>
|
||||
or <tt class="docutils literal"><span class="pre">null</span></tt> if not found.</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.fromhexstring"></a>
|
||||
<a class="mochidef reference" href="#fn-color.fromhexstring">Color.fromHexString(hexString)</a>:</p>
|
||||
<blockquote>
|
||||
Returns a <a class="mochiref reference" href="#fn-color">Color</a> object from the given hexadecimal color string.
|
||||
For example, <tt class="docutils literal"><span class="pre">"#FFFFFF"</span></tt> would return a <a class="mochiref reference" href="#fn-color">Color</a> with
|
||||
RGB values <tt class="docutils literal"><span class="pre">[255/255,</span> <span class="pre">255/255,</span> <span class="pre">255/255]</span></tt> (white).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.fromhsl"></a>
|
||||
<a class="mochidef reference" href="#fn-color.fromhsl">Color.fromHSL(hue, saturation, lightness, alpha=1.0)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return a <a class="mochiref reference" href="#fn-color">Color</a> object from the given <tt class="docutils literal"><span class="pre">hue</span></tt>, <tt class="docutils literal"><span class="pre">saturation</span></tt>,
|
||||
<tt class="docutils literal"><span class="pre">lightness</span></tt> values. Values should be numbers between <tt class="docutils literal"><span class="pre">0.0</span></tt> and
|
||||
<tt class="docutils literal"><span class="pre">1.0</span></tt>.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">alpha</span></tt> is not given, then <tt class="docutils literal"><span class="pre">1.0</span></tt> (completely opaque) will be used.</p>
|
||||
<dl class="docutils">
|
||||
<dt>Alternate form:</dt>
|
||||
<dd><a class="mochiref reference" href="#fn-color.fromhsl">Color.fromHSL({h: hue, s: saturation, l: lightness, a: alpha})</a></dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.fromhslstring"></a>
|
||||
<a class="mochidef reference" href="#fn-color.fromhslstring">Color.fromHSLString(hslString)</a>:</p>
|
||||
<blockquote>
|
||||
Returns a <a class="mochiref reference" href="#fn-color">Color</a> object from the given decimal hsl color string.
|
||||
For example, <tt class="docutils literal"><span class="pre">"hsl(0,0%,100%)"</span></tt> would return a <a class="mochiref reference" href="#fn-color">Color</a> with
|
||||
HSL values <tt class="docutils literal"><span class="pre">[0/360,</span> <span class="pre">0/360,</span> <span class="pre">360/360]</span></tt> (white).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.fromhsv"></a>
|
||||
<a class="mochidef reference" href="#fn-color.fromhsv">Color.fromHSV(hue, saturation, value, alpha=1.0)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return a <a class="mochiref reference" href="#fn-color">Color</a> object from the given <tt class="docutils literal"><span class="pre">hue</span></tt>, <tt class="docutils literal"><span class="pre">saturation</span></tt>,
|
||||
<tt class="docutils literal"><span class="pre">value</span></tt> values. Values should be numbers between <tt class="docutils literal"><span class="pre">0.0</span></tt> and
|
||||
<tt class="docutils literal"><span class="pre">1.0</span></tt>.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">alpha</span></tt> is not given, then <tt class="docutils literal"><span class="pre">1.0</span></tt> (completely opaque) will be used.</p>
|
||||
<dl class="docutils">
|
||||
<dt>Alternate form:</dt>
|
||||
<dd><a class="mochiref reference" href="#fn-color.fromhsv">Color.fromHSV({h: hue, s: saturation, v: value, a: alpha})</a></dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.fromname"></a>
|
||||
<a class="mochidef reference" href="#fn-color.fromname">Color.fromName(colorName)</a>:</p>
|
||||
<blockquote>
|
||||
Returns a <a class="mochiref reference" href="#fn-color">Color</a> object corresponding to the given
|
||||
SVG 1.0 color keyword name <a class="footnote-reference" href="#id7" id="id2" name="id2">[2]</a> as per the W3C CSS3
|
||||
Color Module <a class="footnote-reference" href="#id8" id="id3" name="id3">[3]</a>. <tt class="docutils literal"><span class="pre">"transparent"</span></tt> is also accepted
|
||||
as a color name, and will return <a class="mochiref reference" href="#fn-color.transparentcolor">Color.transparentColor()</a>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.fromrgb"></a>
|
||||
<a class="mochidef reference" href="#fn-color.fromrgb">Color.fromRGB(red, green, blue, alpha=1.0)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return a <a class="mochiref reference" href="#fn-color">Color</a> object from the given <tt class="docutils literal"><span class="pre">red</span></tt>, <tt class="docutils literal"><span class="pre">green</span></tt>,
|
||||
<tt class="docutils literal"><span class="pre">blue</span></tt>, and <tt class="docutils literal"><span class="pre">alpha</span></tt> values. Values should be numbers between <tt class="docutils literal"><span class="pre">0</span></tt>
|
||||
and <tt class="docutils literal"><span class="pre">1.0</span></tt>.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">alpha</span></tt> is not given, then <tt class="docutils literal"><span class="pre">1.0</span></tt> (completely opaque) will be used.</p>
|
||||
<dl class="docutils">
|
||||
<dt>Alternate form:</dt>
|
||||
<dd><a class="mochiref reference" href="#fn-color.fromrgb">Color.fromRGB({r: red, g: green, b: blue, a: alpha})</a></dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.fromrgbstring"></a>
|
||||
<a class="mochidef reference" href="#fn-color.fromrgbstring">Color.fromRGBString(rgbString)</a>:</p>
|
||||
<blockquote>
|
||||
Returns a <a class="mochiref reference" href="#fn-color">Color</a> object from the given decimal rgb color string.
|
||||
For example, <tt class="docutils literal"><span class="pre">"rgb(255,255,255)"</span></tt> would return a <a class="mochiref reference" href="#fn-color">Color</a> with
|
||||
RGB values <tt class="docutils literal"><span class="pre">[255/255,</span> <span class="pre">255/255,</span> <span class="pre">255/255]</span></tt> (white).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.fromtext"></a>
|
||||
<a class="mochidef reference" href="#fn-color.fromtext">Color.fromText(elem)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Returns a <a class="mochiref reference" href="#fn-color">Color</a> object based on the text color of the provided
|
||||
element. Equivalent to:</p>
|
||||
<pre class="literal-block">
|
||||
c = Color.fromComputedStyle(elem, "color") || Color.whiteColor();
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.fromstring"></a>
|
||||
<a class="mochidef reference" href="#fn-color.fromstring">Color.fromString(rgbOrHexString)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Returns a <a class="mochiref reference" href="#fn-color">Color</a> object from the given RGB, HSL, hex, or name.
|
||||
Will return <tt class="docutils literal"><span class="pre">null</span></tt> if the string can not be parsed by any of these
|
||||
methods.</p>
|
||||
<p>See <a class="mochiref reference" href="#fn-color.fromhexstring">Color.fromHexString</a>, <a class="mochiref reference" href="#fn-color.fromrgbstring">Color.fromRGBString</a>,
|
||||
<a class="mochiref reference" href="#fn-color.fromhslstring">Color.fromHSLString</a> and <a class="mochiref reference" href="#fn-color.fromname">Color.fromName</a> more
|
||||
information.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.namedcolors"></a>
|
||||
<a class="mochidef reference" href="#fn-color.namedcolors">Color.namedColors()</a>:</p>
|
||||
<blockquote>
|
||||
Returns an object with properties for each SVG 1.0 color keyword
|
||||
name <a class="footnote-reference" href="#id7" id="id4" name="id4">[2]</a> supported by CSS3 <a class="footnote-reference" href="#id8" id="id5" name="id5">[3]</a>. Property names are the color keyword
|
||||
name in lowercase, and the value is a string suitable for
|
||||
<a class="mochiref reference" href="#fn-color.fromstring">Color.fromString()</a>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.colorwithalpha"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.colorwithalpha">Color.prototype.colorWithAlpha(alpha)</a>:</p>
|
||||
<blockquote>
|
||||
Return a new <a class="mochiref reference" href="#fn-color">Color</a> based on this color, but with the provided
|
||||
<tt class="docutils literal"><span class="pre">alpha</span></tt> value.</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.colorwithhue"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.colorwithhue">Color.prototype.colorWithHue(hue)</a>:</p>
|
||||
<blockquote>
|
||||
Return a new <a class="mochiref reference" href="#fn-color">Color</a> based on this color, but with the provided
|
||||
<tt class="docutils literal"><span class="pre">hue</span></tt> value.</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.colorwithsaturation"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.colorwithsaturation">Color.prototype.colorWithSaturation(saturation)</a>:</p>
|
||||
<blockquote>
|
||||
Return a new <a class="mochiref reference" href="#fn-color">Color</a> based on this color, but with the provided
|
||||
<tt class="docutils literal"><span class="pre">saturation</span></tt> value (using the HSL color model).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.colorwithlightness"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.colorwithlightness">Color.prototype.colorWithLightness(lightness)</a>:</p>
|
||||
<blockquote>
|
||||
Return a new <a class="mochiref reference" href="#fn-color">Color</a> based on this color, but with the provided
|
||||
<tt class="docutils literal"><span class="pre">lightness</span></tt> value.</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.darkercolorwithlevel"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.darkercolorwithlevel">Color.prototype.darkerColorWithLevel(level)</a>:</p>
|
||||
<blockquote>
|
||||
Return a new <a class="mochiref reference" href="#fn-color">Color</a> based on this color, but darker by the given
|
||||
<tt class="docutils literal"><span class="pre">level</span></tt> (between <tt class="docutils literal"><span class="pre">0</span></tt> and <tt class="docutils literal"><span class="pre">1.0</span></tt>).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.lightercolorwithlevel"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.lightercolorwithlevel">Color.prototype.lighterColorWithLevel(level)</a>:</p>
|
||||
<blockquote>
|
||||
Return a new <a class="mochiref reference" href="#fn-color">Color</a> based on this color, but lighter by the given
|
||||
<tt class="docutils literal"><span class="pre">level</span></tt> (between <tt class="docutils literal"><span class="pre">0</span></tt> and <tt class="docutils literal"><span class="pre">1.0</span></tt>).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.blendedcolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.blendedcolor">Color.prototype.blendedColor(other, fraction=0.5)</a>:</p>
|
||||
<blockquote>
|
||||
Return a new <a class="mochiref reference" href="#fn-color">Color</a> whose RGBA component values are a weighted sum
|
||||
of this color and <tt class="docutils literal"><span class="pre">other</span></tt>. Each component of the returned color
|
||||
is the <tt class="docutils literal"><span class="pre">fraction</span></tt> of other's value plus <tt class="docutils literal"><span class="pre">1</span> <span class="pre">-</span> <span class="pre">fraction</span></tt> of this
|
||||
color's.</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.islight"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.islight">Color.prototype.isLight()</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return <tt class="docutils literal"><span class="pre">true</span></tt> if the lightness value of this color is greater than
|
||||
<tt class="docutils literal"><span class="pre">0.5</span></tt>.</p>
|
||||
<p>Note that <tt class="docutils literal"><span class="pre">alpha</span></tt> is ignored for this calculation (color components
|
||||
are not premultiplied).</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.isdark"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.isdark">Color.prototype.isDark()</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return <tt class="docutils literal"><span class="pre">true</span></tt> if the lightness value of this color is less than or
|
||||
equal to <tt class="docutils literal"><span class="pre">0.5</span></tt>.</p>
|
||||
<p>Note that <tt class="docutils literal"><span class="pre">alpha</span></tt> is ignored for this calculation (color components
|
||||
are not premultiplied).</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.torgbstring"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.torgbstring">Color.prototype.toRGBString()</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return the decimal <tt class="docutils literal"><span class="pre">"rgb(red,</span> <span class="pre">green,</span> <span class="pre">blue)"</span></tt> string representation of this
|
||||
color.</p>
|
||||
<p>If the alpha component is not <tt class="docutils literal"><span class="pre">1.0</span></tt> (fully opaque), the
|
||||
<tt class="docutils literal"><span class="pre">"rgba(red,</span> <span class="pre">green,</span> <span class="pre">blue,</span> <span class="pre">alpha)"</span></tt> string representation will be used.</p>
|
||||
<p>For example:</p>
|
||||
<pre class="literal-block">
|
||||
assert( Color.whiteColor().toRGBString() == "rgb(255,255,255)" );
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.tohslstring"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.tohslstring">Color.prototype.toHSLString()</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return the decimal <tt class="docutils literal"><span class="pre">"hsl(hue,</span> <span class="pre">saturation,</span> <span class="pre">lightness)"</span></tt>
|
||||
string representation of this color.</p>
|
||||
<p>If the alpha component is not <tt class="docutils literal"><span class="pre">1.0</span></tt> (fully opaque), the
|
||||
<tt class="docutils literal"><span class="pre">"hsla(hue,</span> <span class="pre">saturation,</span> <span class="pre">lightness,</span> <span class="pre">alpha)"</span></tt> string representation
|
||||
will be used.</p>
|
||||
<p>For example:</p>
|
||||
<pre class="literal-block">
|
||||
assert( Color.whiteColor().toHSLString() == "hsl(0,0,360)" );
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.tohexstring"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.tohexstring">Color.prototype.toHexString()</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return the hexadecimal <tt class="docutils literal"><span class="pre">"#RRGGBB"</span></tt> string representation of this color.</p>
|
||||
<p>Note that the alpha component is completely ignored for hexadecimal
|
||||
string representations!</p>
|
||||
<p>For example:</p>
|
||||
<pre class="literal-block">
|
||||
assert( Color.whiteColor().toHexString() == "#FFFFFF" );
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.asrgb"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.asrgb">Color.prototype.asRGB()</a>:</p>
|
||||
<blockquote>
|
||||
Return the RGB (red, green, blue, alpha) components of this color as an
|
||||
object with <tt class="docutils literal"><span class="pre">r</span></tt>, <tt class="docutils literal"><span class="pre">g</span></tt>, <tt class="docutils literal"><span class="pre">b</span></tt>, and <tt class="docutils literal"><span class="pre">a</span></tt> properties that have
|
||||
values between <tt class="docutils literal"><span class="pre">0.0</span></tt> and <tt class="docutils literal"><span class="pre">1.0</span></tt>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.ashsl"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.ashsl">Color.prototype.asHSL()</a>:</p>
|
||||
<blockquote>
|
||||
Return the HSL (hue, saturation, lightness, alpha) components of this
|
||||
color as an object with <tt class="docutils literal"><span class="pre">h</span></tt>, <tt class="docutils literal"><span class="pre">s</span></tt>, <tt class="docutils literal"><span class="pre">l</span></tt> and <tt class="docutils literal"><span class="pre">a</span></tt> properties
|
||||
that have values between <tt class="docutils literal"><span class="pre">0.0</span></tt> and <tt class="docutils literal"><span class="pre">1.0</span></tt>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.prototype.ashsv"></a>
|
||||
<a class="mochidef reference" href="#fn-color.prototype.ashsv">Color.prototype.asHSV()</a>:</p>
|
||||
<blockquote>
|
||||
Return the HSV (hue, saturation, value, alpha) components of this
|
||||
color as an object with <tt class="docutils literal"><span class="pre">h</span></tt>, <tt class="docutils literal"><span class="pre">s</span></tt>, <tt class="docutils literal"><span class="pre">v</span></tt> and <tt class="docutils literal"><span class="pre">a</span></tt> properties
|
||||
that have values between <tt class="docutils literal"><span class="pre">0.0</span></tt> and <tt class="docutils literal"><span class="pre">1.0</span></tt>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.blackcolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.blackcolor">Color.blackColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 0, 0, 0
|
||||
(#000000).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.bluecolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.bluecolor">Color.blueColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 0, 0, 1
|
||||
(#0000ff).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.browncolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.browncolor">Color.brownColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 0.6, 0.4, 0.2
|
||||
(#996633).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.cyancolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.cyancolor">Color.cyanColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 0, 1, 1
|
||||
(#00ffff).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.darkgraycolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.darkgraycolor">Color.darkGrayColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 1/3, 1/3, 1/3
|
||||
(#555555).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.graycolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.graycolor">Color.grayColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 0.5, 0.5, 0.5
|
||||
(#808080).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.greencolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.greencolor">Color.greenColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 0, 1, 0.
|
||||
(#00ff00).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.lightgraycolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.lightgraycolor">Color.lightGrayColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 2/3, 2/3, 2/3
|
||||
(#aaaaaa).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.magentacolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.magentacolor">Color.magentaColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 1, 0, 1
|
||||
(#ff00ff).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.orangecolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.orangecolor">Color.orangeColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 1, 0.5, 0
|
||||
(#ff8000).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.purplecolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.purplecolor">Color.purpleColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 0.5, 0, 0.5
|
||||
(#800080).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.redcolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.redcolor">Color.redColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 1, 0, 0
|
||||
(#ff0000).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.whitecolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.whitecolor">Color.whiteColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 1, 1, 1
|
||||
(#ffffff).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.yellowcolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.yellowcolor">Color.yellowColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object whose RGB values are 1, 1, 0
|
||||
(#ffff00).</blockquote>
|
||||
<p>
|
||||
<a name="fn-color.transparentcolor"></a>
|
||||
<a class="mochidef reference" href="#fn-color.transparentcolor">Color.transparentColor()</a>:</p>
|
||||
<blockquote>
|
||||
Return a <a class="mochiref reference" href="#fn-color">Color</a> object that is completely transparent
|
||||
(has alpha component of 0).</blockquote>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="functions" name="functions">Functions</a></h2>
|
||||
<p>
|
||||
<a name="fn-clampcolorcomponent"></a>
|
||||
<a class="mochidef reference" href="#fn-clampcolorcomponent">clampColorComponent(num, scale)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Returns <tt class="docutils literal"><span class="pre">num</span> <span class="pre">*</span> <span class="pre">scale</span></tt> clamped between <tt class="docutils literal"><span class="pre">0</span></tt> and <tt class="docutils literal"><span class="pre">scale</span></tt>.</p>
|
||||
<p><a class="mochiref reference" href="#fn-clampcolorcomponent">clampColorComponent</a> is not exported by default when using JSAN.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-hsltorgb"></a>
|
||||
<a class="mochidef reference" href="#fn-hsltorgb">hslToRGB(hue, saturation, lightness, alpha)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Computes RGB values from the provided HSL values. The return value is a
|
||||
mapping with <tt class="docutils literal"><span class="pre">"r"</span></tt>, <tt class="docutils literal"><span class="pre">"g"</span></tt>, <tt class="docutils literal"><span class="pre">"b"</span></tt> and <tt class="docutils literal"><span class="pre">"a"</span></tt> keys.</p>
|
||||
<dl class="docutils">
|
||||
<dt>Alternate form:</dt>
|
||||
<dd><a class="mochiref reference" href="#fn-hsltorgb">hslToRGB({h: hue, s: saturation, l: lightness, a: alpha})</a>.</dd>
|
||||
</dl>
|
||||
<p><a class="mochiref reference" href="#fn-hsltorgb">hslToRGB</a> is not exported by default when using JSAN.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-hsvtorgb"></a>
|
||||
<a class="mochidef reference" href="#fn-hsvtorgb">hsvToRGB(hue, saturation, value, alpha)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Computes RGB values from the provided HSV values. The return value is a
|
||||
mapping with <tt class="docutils literal"><span class="pre">"r"</span></tt>, <tt class="docutils literal"><span class="pre">"g"</span></tt>, <tt class="docutils literal"><span class="pre">"b"</span></tt> and <tt class="docutils literal"><span class="pre">"a"</span></tt> keys.</p>
|
||||
<dl class="docutils">
|
||||
<dt>Alternate form:</dt>
|
||||
<dd><a class="mochiref reference" href="#fn-hsvtorgb">hsvToRGB({h: hue, s: saturation, v: value, a: alpha})</a>.</dd>
|
||||
</dl>
|
||||
<p><a class="mochiref reference" href="#fn-hsvtorgb">hsvToRGB</a> is not exported by default when using JSAN.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-tocolorpart"></a>
|
||||
<a class="mochidef reference" href="#fn-tocolorpart">toColorPart(num)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Convert num to a zero padded hexadecimal digit for use in a hexadecimal
|
||||
color string. Num should be an integer between <tt class="docutils literal"><span class="pre">0</span></tt> and <tt class="docutils literal"><span class="pre">255</span></tt>.</p>
|
||||
<p><a class="mochiref reference" href="#fn-tocolorpart">toColorPart</a> is not exported by default when using JSAN.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-rgbtohsl"></a>
|
||||
<a class="mochidef reference" href="#fn-rgbtohsl">rgbToHSL(red, green, blue, alpha)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Computes HSL values based on the provided RGB values. The return value is
|
||||
a mapping with <tt class="docutils literal"><span class="pre">"h"</span></tt>, <tt class="docutils literal"><span class="pre">"s"</span></tt>, <tt class="docutils literal"><span class="pre">"l"</span></tt> and <tt class="docutils literal"><span class="pre">"a"</span></tt> keys.</p>
|
||||
<dl class="docutils">
|
||||
<dt>Alternate form:</dt>
|
||||
<dd><a class="mochiref reference" href="#fn-rgbtohsl">rgbToHSL({r: red, g: green, b: blue, a: alpha})</a>.</dd>
|
||||
</dl>
|
||||
<p><a class="mochiref reference" href="#fn-rgbtohsl">rgbToHSL</a> is not exported by default when using JSAN.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-rgbtohsv"></a>
|
||||
<a class="mochidef reference" href="#fn-rgbtohsv">rgbToHSV(red, green, blue, alpha)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Computes HSV values based on the provided RGB values. The return value is
|
||||
a mapping with <tt class="docutils literal"><span class="pre">"h"</span></tt>, <tt class="docutils literal"><span class="pre">"s"</span></tt>, <tt class="docutils literal"><span class="pre">"v"</span></tt> and <tt class="docutils literal"><span class="pre">"a"</span></tt> keys.</p>
|
||||
<dl class="docutils">
|
||||
<dt>Alternate form:</dt>
|
||||
<dd><a class="mochiref reference" href="#fn-rgbtohsv">rgbToHSV({r: red, g: green, b: blue, a: alpha})</a>.</dd>
|
||||
</dl>
|
||||
<p><a class="mochiref reference" href="#fn-rgbtohsv">rgbToHSV</a> is not exported by default when using JSAN.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="see-also" name="see-also">See Also</a></h1>
|
||||
<table class="docutils footnote" frame="void" id="id6" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id1" name="id6">[1]</a></td><td>Application Kit Reference - NSColor: <a class="reference" href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSColor.html">http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSColor.html</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="id7" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a name="id7">[2]</a></td><td><em>(<a class="fn-backref" href="#id2">1</a>, <a class="fn-backref" href="#id4">2</a>)</em> SVG 1.0 color keywords: <a class="reference" href="http://www.w3.org/TR/SVG/types.html#ColorKeywords">http://www.w3.org/TR/SVG/types.html#ColorKeywords</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="id8" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a name="id8">[3]</a></td><td><em>(<a class="fn-backref" href="#id3">1</a>, <a class="fn-backref" href="#id5">2</a>)</em> W3C CSS3 Color Module: <a class="reference" href="http://www.w3.org/TR/css3-color/#svg-color">http://www.w3.org/TR/css3-color/#svg-color</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="authors" name="authors">Authors</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="copyright" name="copyright">Copyright</a></h1>
|
||||
<p>Copyright 2005 Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>>. This program is dual-licensed
|
||||
free software; you can redistribute it and/or modify it under the terms of the
|
||||
<a class="reference" href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> or the <a class="reference" href="http://www.opensource.org/licenses/afl-2.1.php">Academic Free License v2.1</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,798 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
||||
<title>MochiKit.DOM - painless DOM manipulation API</title>
|
||||
|
||||
<link rel="stylesheet" href="../../../include/css/documentation.css" type="text/css" />
|
||||
<script type="text/javascript" src="../../../packed/lib/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="../../js/toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document">
|
||||
<div class="section">
|
||||
<h1><a id="name" name="name">Name</a></h1>
|
||||
<p>MochiKit.DOM - painless DOM manipulation API</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="synopsis" name="synopsis">Synopsis</a></h1>
|
||||
<pre class="literal-block">
|
||||
var rows = [
|
||||
["dataA1", "dataA2", "dataA3"],
|
||||
["dataB1", "dataB2", "dataB3"]
|
||||
];
|
||||
row_display = function (row) {
|
||||
return TR(null, map(partial(TD, null), row));
|
||||
}
|
||||
var newTable = TABLE({'class': 'prettytable'},
|
||||
THEAD(null,
|
||||
row_display(["head1", "head2", "head3"])),
|
||||
TFOOT(null,
|
||||
row_display(["foot1", "foot2", "foot3"])),
|
||||
TBODY(null,
|
||||
map(row_display, rows)));
|
||||
// put that in your document.createElement and smoke it!
|
||||
swapDOM(oldTable, newTable);
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="description" name="description">Description</a></h1>
|
||||
<p>As you probably know, the DOM APIs are some of the most painful Java-inspired
|
||||
APIs you'll run across from a highly dynamic language. Don't worry about that
|
||||
though, because they provide a reasonable basis to build something that
|
||||
sucks a lot less.</p>
|
||||
<p>MochiKit.DOM takes much of its inspiration from Nevow's <a class="footnote-reference" href="#id5" id="id1" name="id1">[1]</a> stan <a class="footnote-reference" href="#id6" id="id2" name="id2">[2]</a>.
|
||||
This means you choose a tag, give it some attributes, then stuff it full
|
||||
of <em>whatever objects you want</em>. MochiKit.DOM isn't stupid, it knows that
|
||||
a string should be a text node, and that you want functions to be called,
|
||||
and that <tt class="docutils literal"><span class="pre">Array</span></tt>-like objects should be expanded, and stupid <tt class="docutils literal"><span class="pre">null</span></tt> values
|
||||
should be skipped.</p>
|
||||
<p>Hell, it will let you return strings from functions, and use iterators from
|
||||
<a class="mochiref reference" href="Iter.html">MochiKit.Iter</a>. If that's not enough, just teach it new tricks with
|
||||
<a class="mochiref reference" href="#fn-registerdomconverter">registerDOMConverter</a>. If you have never used an API like this for
|
||||
creating DOM elements, you've been wasting your damn time. Get with it!</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="dependencies" name="dependencies">Dependencies</a></h1>
|
||||
<ul class="simple">
|
||||
<li><a class="mochiref reference" href="Base.html">MochiKit.Base</a></li>
|
||||
<li><a class="mochiref reference" href="Iter.html">MochiKit.Iter</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="overview" name="overview">Overview</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="dom-coercion-rules" name="dom-coercion-rules">DOM Coercion Rules</a></h2>
|
||||
<p>In order of precedence, <a class="mochiref reference" href="#fn-createdom">createDOM</a> coerces given arguments to DOM
|
||||
nodes using the following rules:</p>
|
||||
<ol class="arabic simple">
|
||||
<li>Functions are called with a <tt class="docutils literal"><span class="pre">this</span></tt> of the parent
|
||||
node and their return value is subject to the
|
||||
following rules (even this one).</li>
|
||||
<li><tt class="docutils literal"><span class="pre">undefined</span></tt> and <tt class="docutils literal"><span class="pre">null</span></tt> are ignored.</li>
|
||||
<li>Iterables (see <a class="mochiref reference" href="Iter.html">MochiKit.Iter</a>) are flattened
|
||||
(as if they were passed in-line as nodes) and each
|
||||
return value is subject to all of these rules.</li>
|
||||
<li>Values that look like DOM nodes (objects with a
|
||||
<tt class="docutils literal"><span class="pre">.nodeType</span> <span class="pre">></span> <span class="pre">0</span></tt>) are <tt class="docutils literal"><span class="pre">.appendChild</span></tt>'ed to the created
|
||||
DOM fragment.</li>
|
||||
<li>Strings are wrapped up with <tt class="docutils literal"><span class="pre">document.createTextNode</span></tt></li>
|
||||
<li>Objects that are not strings are run through the <tt class="docutils literal"><span class="pre">domConverters</span></tt>
|
||||
<a class="mochiref reference" href="Base.html#fn-adapterregistry">MochiKit.Base.AdapterRegistry</a>
|
||||
(see <a class="mochiref reference" href="#fn-registerdomconverter">registerDOMConverter</a>).
|
||||
The value returned by the adapter is subject to these same rules (e.g.
|
||||
adapters are allowed to return a string, which will be coerced into a
|
||||
text node).</li>
|
||||
<li>If no adapter is available, <tt class="docutils literal"><span class="pre">.toString()</span></tt> is used to create a text node.</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="creating-dom-element-trees" name="creating-dom-element-trees">Creating DOM Element Trees</a></h2>
|
||||
<p><a class="mochiref reference" href="#fn-createdom">createDOM</a> provides you with an excellent facility for creating DOM trees
|
||||
that is easy on the wrists. One of the best ways to understand how to use
|
||||
it is to take a look at an example:</p>
|
||||
<pre class="literal-block">
|
||||
var rows = [
|
||||
["dataA1", "dataA2", "dataA3"],
|
||||
["dataB1", "dataB2", "dataB3"]
|
||||
];
|
||||
row_display = function (row) {
|
||||
return TR(null, map(partial(TD, null), row));
|
||||
}
|
||||
var newTable = TABLE({'class': 'prettytable'},
|
||||
THEAD(null,
|
||||
row_display(["head1", "head2", "head3"])),
|
||||
TFOOT(null,
|
||||
row_display(["foot1", "foot2", "foot3"])),
|
||||
TBODY(null,
|
||||
map(row_display, rows)));
|
||||
</pre>
|
||||
<p>This will create a table with the following visual layout (if it
|
||||
were inserted into the document DOM):</p>
|
||||
<blockquote>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="33%" />
|
||||
<col width="33%" />
|
||||
<col width="33%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th class="head">head1</th>
|
||||
<th class="head">head2</th>
|
||||
<th class="head">head3</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td>dataA1</td>
|
||||
<td>dataA2</td>
|
||||
<td>dataA3</td>
|
||||
</tr>
|
||||
<tr><td>dataB1</td>
|
||||
<td>dataB2</td>
|
||||
<td>dataB3</td>
|
||||
</tr>
|
||||
<tr><td>foot1</td>
|
||||
<td>foot2</td>
|
||||
<td>foot3</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</blockquote>
|
||||
<p>Corresponding to the following HTML:</p>
|
||||
<pre class="literal-block">
|
||||
<table class="prettytable">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>head1</td>
|
||||
<td>head2</td>
|
||||
<td>head3</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td>foot1</td>
|
||||
<td>foot2</td>
|
||||
<td>foot3</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>dataA1</td>
|
||||
<td>dataA2</td>
|
||||
<td>dataA3</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>dataB1</td>
|
||||
<td>dataB2</td>
|
||||
<td>dataB3</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="dom-context" name="dom-context">DOM Context</a></h2>
|
||||
<p>In order to prevent having to pass a <tt class="docutils literal"><span class="pre">window</span></tt> and/or <tt class="docutils literal"><span class="pre">document</span></tt>
|
||||
variable to every MochiKit.DOM function (e.g. when working with a
|
||||
child window), MochiKit.DOM maintains a context variable for each
|
||||
of them. They are managed with the <a class="mochiref reference" href="#fn-withwindow">withWindow</a> and
|
||||
<a class="mochiref reference" href="#fn-withdocument">withDocument</a> functions, and can be acquired with
|
||||
<a class="mochiref reference" href="#fn-currentwindow">currentWindow()</a> and <a class="mochiref reference" href="#fn-currentdocument">currentDocument()</a></p>
|
||||
<p>For example, if you are creating DOM nodes in a child window, you
|
||||
could do something like this:</p>
|
||||
<pre class="literal-block">
|
||||
withWindow(child, function () {
|
||||
var doc = currentDocument();
|
||||
appendChildNodes(doc.body, H1(null, "This is in the child!"));
|
||||
});
|
||||
</pre>
|
||||
<p>Note that <a class="mochiref reference" href="#fn-withwindow">withWindow(win, ...)</a> also implies
|
||||
<a class="mochiref reference" href="#fn-withdocument">withDocument(win.document, ...)</a>.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="element-visibility" name="element-visibility">Element Visibility</a></h2>
|
||||
<p>The <a class="mochiref reference" href="#fn-hideelement">hideElement</a> and <a class="mochiref reference" href="#fn-showelement">showElement</a> functions are
|
||||
provided as a convenience, but only work for elements that are
|
||||
<tt class="docutils literal"><span class="pre">display:</span> <span class="pre">block</span></tt>. For a general solution to showing, hiding, and checking
|
||||
the explicit visibility of elements, we recommend using a solution that
|
||||
involves a little CSS. Here's an example:</p>
|
||||
<pre class="literal-block">
|
||||
<style type="text/css">
|
||||
.invisible { display: none; }
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
function toggleVisible(elem) {
|
||||
toggleElementClass("invisible", elem);
|
||||
}
|
||||
|
||||
function makeVisible(elem) {
|
||||
removeElementClass(elem, "invisible");
|
||||
}
|
||||
|
||||
function makeInvisible(elem) {
|
||||
addElementClass(elem, "invisible");
|
||||
}
|
||||
|
||||
function isVisible(elem) {
|
||||
// you may also want to check for
|
||||
// getElement(elem).style.display == "none"
|
||||
return !hasElementClass(elem, "invisible");
|
||||
};
|
||||
</script>
|
||||
</pre>
|
||||
<p>MochiKit doesn't ship with such a solution, because there is no reliable and
|
||||
portable method for adding CSS rules on the fly with JavaScript.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="api-reference" name="api-reference">API Reference</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="functions" name="functions">Functions</a></h2>
|
||||
<p>
|
||||
<a name="fn-$"></a>
|
||||
<a class="mochidef reference" href="#fn-$">$(id[, ...])</a>:</p>
|
||||
<blockquote>
|
||||
An alias for <a class="mochiref reference" href="#fn-getelement">getElement(id[, ...])</a></blockquote>
|
||||
<p>
|
||||
<a name="fn-addelementclass"></a>
|
||||
<a class="mochidef reference" href="#fn-addelementclass">addElementClass(element, className)</a>:</p>
|
||||
<blockquote>
|
||||
Ensure that the given <tt class="docutils literal"><span class="pre">element</span></tt> has <tt class="docutils literal"><span class="pre">className</span></tt> set as part of its
|
||||
class attribute. This will not disturb other class names.
|
||||
<tt class="docutils literal"><span class="pre">element</span></tt> is looked up with <a class="mochiref reference" href="#fn-getelement">getElement</a>, so string identifiers
|
||||
are also acceptable.</blockquote>
|
||||
<p>
|
||||
<a name="fn-addloadevent"></a>
|
||||
<a class="mochidef reference" href="#fn-addloadevent">addLoadEvent(func)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Note that <a class="mochiref reference" href="#fn-addloadevent">addLoadEvent</a> can not be used in combination with
|
||||
<a class="mochiref reference" href="Signal.html">MochiKit.Signal</a> if the <tt class="docutils literal"><span class="pre">onload</span></tt> event is connected.
|
||||
Once an event is connected with <a class="mochiref reference" href="Signal.html">MochiKit.Signal</a>, no other APIs
|
||||
may be used for that same event.</p>
|
||||
<p>This will stack <tt class="docutils literal"><span class="pre">window.onload</span></tt> functions on top of each other.
|
||||
Each function added will be called after <tt class="docutils literal"><span class="pre">onload</span></tt> in the
|
||||
order that they were added.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-addtocallstack"></a>
|
||||
<a class="mochidef reference" href="#fn-addtocallstack">addToCallStack(target, path, func[, once])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Note that <a class="mochiref reference" href="#fn-addtocallstack">addToCallStack</a> is not compatible with
|
||||
<a class="mochiref reference" href="Signal.html">MochiKit.Signal</a>. Once an event is connected with
|
||||
<a class="mochiref reference" href="Signal.html">MochiKit.Signal</a>, no other APIs may be used for that same event.</p>
|
||||
<p>Set the property <tt class="docutils literal"><span class="pre">path</span></tt> of <tt class="docutils literal"><span class="pre">target</span></tt> to a function that calls the
|
||||
existing function at that property (if any), then calls <tt class="docutils literal"><span class="pre">func</span></tt>.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">target[path]()</span></tt> returns exactly <tt class="docutils literal"><span class="pre">false</span></tt>, then <tt class="docutils literal"><span class="pre">func</span></tt> will
|
||||
not be called.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">once</span></tt> is <tt class="docutils literal"><span class="pre">true</span></tt>, then <tt class="docutils literal"><span class="pre">target[path]</span></tt> is set to <tt class="docutils literal"><span class="pre">null</span></tt> after
|
||||
the function call stack has completed.</p>
|
||||
<p>If called several times for the same <tt class="docutils literal"><span class="pre">target[path]</span></tt>, it will create
|
||||
a stack of functions (instead of just a pair).</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-appendchildnodes"></a>
|
||||
<a class="mochidef reference" href="#fn-appendchildnodes">appendChildNodes(node[, childNode[, ...]])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Append children to a DOM element using the <a class="reference" href="#dom-coercion-rules">DOM Coercion Rules</a>.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">node</span></tt>:</dt>
|
||||
<dd>A reference to the DOM element to add children to
|
||||
(if a string is given, <a class="mochiref reference" href="#fn-getelement">getElement(node)</a>
|
||||
will be used to locate the node)</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">childNode</span></tt>...:</dt>
|
||||
<dd>All additional arguments, if any, will be coerced into DOM
|
||||
nodes that are appended as children using the
|
||||
<a class="reference" href="#dom-coercion-rules">DOM Coercion Rules</a>.</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd>The given DOM element</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-computedstyle"></a>
|
||||
<a class="mochidef reference" href="#fn-computedstyle">computedStyle(htmlElement, cssProperty, mozillaEquivalentCSS)</a>:</p>
|
||||
<blockquote>
|
||||
Looks up a CSS property for the given element. The element can be
|
||||
specified as either a string with the element's ID or the element
|
||||
object itself.</blockquote>
|
||||
<p>
|
||||
<a name="fn-createdom"></a>
|
||||
<a class="mochidef reference" href="#fn-createdom">createDOM(name[, attrs[, node[, ...]]])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Create a DOM fragment in a really convenient manner, much like
|
||||
Nevow`s <a class="footnote-reference" href="#id5" id="id3" name="id3">[1]</a> stan <a class="footnote-reference" href="#id6" id="id4" name="id4">[2]</a>.</p>
|
||||
<p>Partially applied versions of this function for common tags are
|
||||
available as aliases:</p>
|
||||
<ul class="simple">
|
||||
<li><tt class="docutils literal"><span class="pre">A</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">BUTTON</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">BR</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">CANVAS</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">DIV</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">FIELDSET</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">FORM</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">H1</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">H2</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">H3</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">HR</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">IMG</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">INPUT</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">LABEL</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">LEGEND</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">LI</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">OL</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">OPTGROUP</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">OPTION</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">P</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">PRE</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">SELECT</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">SPAN</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">STRONG</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">TABLE</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">TBODY</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">TD</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">TEXTAREA</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">TFOOT</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">TH</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">THEAD</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">TR</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">TT</span></tt></li>
|
||||
<li><tt class="docutils literal"><span class="pre">UL</span></tt></li>
|
||||
</ul>
|
||||
<p>See <a class="reference" href="#creating-dom-element-trees">Creating DOM Element Trees</a> for a comprehensive example.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">name</span></tt>:</dt>
|
||||
<dd>The kind of fragment to create (e.g. 'span'), such as you would
|
||||
pass to <tt class="docutils literal"><span class="pre">document.createElement</span></tt>.</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">attrs</span></tt>:</dt>
|
||||
<dd><p class="first">An object whose properties will be used as the attributes
|
||||
(e.g. <tt class="docutils literal"><span class="pre">{'style':</span> <span class="pre">'display:block'}</span></tt>), or <tt class="docutils literal"><span class="pre">null</span></tt> if no
|
||||
attributes need to be set.</p>
|
||||
<p>See <a class="mochiref reference" href="#fn-updatenodeattributes">updateNodeAttributes</a> for more information.</p>
|
||||
<p class="last">For convenience, if <tt class="docutils literal"><span class="pre">attrs</span></tt> is a string, <tt class="docutils literal"><span class="pre">null</span></tt> is used
|
||||
and the string will be considered the first <tt class="docutils literal"><span class="pre">node</span></tt>.</p>
|
||||
</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">node</span></tt>...:</dt>
|
||||
<dd>All additional arguments, if any, will be coerced into DOM
|
||||
nodes that are appended as children using the
|
||||
<a class="reference" href="#dom-coercion-rules">DOM Coercion Rules</a>.</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd>A DOM element</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-createdomfunc"></a>
|
||||
<a class="mochidef reference" href="#fn-createdomfunc">createDOMFunc(tag[, attrs[, node[, ...]]])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Convenience function to create a partially applied createDOM
|
||||
function. You'd want to use this if you add additional convenience
|
||||
functions for creating tags, or if you find yourself creating
|
||||
a lot of tags with a bunch of the same attributes or contents.</p>
|
||||
<p>See <a class="mochiref reference" href="#fn-createdom">createDOM</a> for more detailed descriptions of the arguments.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">tag</span></tt>:</dt>
|
||||
<dd>The name of the tag</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">attrs</span></tt>:</dt>
|
||||
<dd>Optionally specify the attributes to apply</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">node</span></tt>...:</dt>
|
||||
<dd>Optionally specify any children nodes it should have</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd>function that takes additional arguments and calls
|
||||
<a class="mochiref reference" href="#fn-createdom">createDOM</a></dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-currentdocument"></a>
|
||||
<a class="mochidef reference" href="#fn-currentdocument">currentDocument()</a>:</p>
|
||||
<blockquote>
|
||||
Return the current <tt class="docutils literal"><span class="pre">document</span></tt> <a class="reference" href="#dom-context">DOM Context</a>. This will always
|
||||
be the same as the global <tt class="docutils literal"><span class="pre">document</span></tt> unless <a class="mochiref reference" href="#fn-withdocument">withDocument</a> or
|
||||
<a class="mochiref reference" href="#fn-withwindow">withWindow</a> is currently executing.</blockquote>
|
||||
<p>
|
||||
<a name="fn-currentwindow"></a>
|
||||
<a class="mochidef reference" href="#fn-currentwindow">currentWindow()</a>:</p>
|
||||
<blockquote>
|
||||
Return the current <tt class="docutils literal"><span class="pre">window</span></tt> <a class="reference" href="#dom-context">DOM Context</a>. This will always
|
||||
be the same as the global <tt class="docutils literal"><span class="pre">window</span></tt> unless <a class="mochiref reference" href="#fn-withwindow">withWindow</a> is
|
||||
currently executing.</blockquote>
|
||||
<p>
|
||||
<a name="fn-elementdimensions"></a>
|
||||
<a class="mochidef reference" href="#fn-elementdimensions">elementDimensions(element)</a>:</p>
|
||||
<blockquote>
|
||||
Return the absolute pixel width and height of <tt class="docutils literal"><span class="pre">element</span></tt> as an object with
|
||||
<tt class="docutils literal"><span class="pre">w</span></tt> and <tt class="docutils literal"><span class="pre">h</span></tt> properties, or <tt class="docutils literal"><span class="pre">undefined</span></tt> if <tt class="docutils literal"><span class="pre">element</span></tt> is not in the
|
||||
document. <tt class="docutils literal"><span class="pre">element</span></tt> may be specified as a string to be looked up with
|
||||
<a class="mochiref reference" href="#fn-getelement">getElement</a>, a DOM element, or trivially as an object with
|
||||
<tt class="docutils literal"><span class="pre">w</span></tt> and/or <tt class="docutils literal"><span class="pre">h</span></tt> properties.</blockquote>
|
||||
<p>
|
||||
<a name="fn-elementposition"></a>
|
||||
<a class="mochidef reference" href="#fn-elementposition">elementPosition(element[, relativeTo={x: 0, y: 0}])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return the absolute pixel position of <tt class="docutils literal"><span class="pre">element</span></tt> in the document as an
|
||||
object with <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt> properties, or <tt class="docutils literal"><span class="pre">undefined</span></tt> if <tt class="docutils literal"><span class="pre">element</span></tt>
|
||||
is not in the document. <tt class="docutils literal"><span class="pre">element</span></tt> may be specified as a string to
|
||||
be looked up with <a class="mochiref reference" href="#fn-getelement">getElement</a>, a DOM element, or trivially
|
||||
as an object with <tt class="docutils literal"><span class="pre">x</span></tt> and/or <tt class="docutils literal"><span class="pre">y</span></tt> properties.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">relativeTo</span></tt> is given, then its coordinates are subtracted from
|
||||
the absolute position of <tt class="docutils literal"><span class="pre">element</span></tt>, e.g.:</p>
|
||||
<pre class="literal-block">
|
||||
var elemPos = elementPosition(elem);
|
||||
var anotherElemPos = elementPosition(anotherElem);
|
||||
var relPos = elementPosition(elem, anotherElem);
|
||||
assert( relPos.x == (elemPos.x - anotherElemPos.x) );
|
||||
assert( relPos.y == (elemPos.y - anotherElemPos.y) );
|
||||
</pre>
|
||||
<p><tt class="docutils literal"><span class="pre">relativeTo</span></tt> may be specified as a string to be looked up with
|
||||
<a class="mochiref reference" href="#fn-getelement">getElement</a>, a DOM element, or trivially as an object
|
||||
with <tt class="docutils literal"><span class="pre">x</span></tt> and/or <tt class="docutils literal"><span class="pre">y</span></tt> properties.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-emithtml"></a>
|
||||
<a class="mochidef reference" href="#fn-emithtml">emitHTML(dom[, lst])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Convert a DOM tree to an <tt class="docutils literal"><span class="pre">Array</span></tt> of HTML string fragments</p>
|
||||
<p>You probably want to use <a class="mochiref reference" href="#fn-tohtml">toHTML</a> instead.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-escapehtml"></a>
|
||||
<a class="mochidef reference" href="#fn-escapehtml">escapeHTML(s)</a>:</p>
|
||||
<blockquote>
|
||||
Make a string safe for HTML, converting the usual suspects (lt,
|
||||
gt, quot, apos, amp)</blockquote>
|
||||
<p>
|
||||
<a name="fn-focusonload"></a>
|
||||
<a class="mochidef reference" href="#fn-focusonload">focusOnLoad(element)</a>:</p>
|
||||
<blockquote>
|
||||
Add an onload event to focus the given element</blockquote>
|
||||
<p>
|
||||
<a name="fn-formcontents"></a>
|
||||
<a class="mochidef reference" href="#fn-formcontents">formContents(elem)</a>:</p>
|
||||
<blockquote>
|
||||
Search the DOM tree, starting at <tt class="docutils literal"><span class="pre">elem</span></tt>, for any elements with a
|
||||
<tt class="docutils literal"><span class="pre">name</span></tt> and <tt class="docutils literal"><span class="pre">value</span></tt> attribute. Return a 2-element <tt class="docutils literal"><span class="pre">Array</span></tt> of
|
||||
<tt class="docutils literal"><span class="pre">names</span></tt> and <tt class="docutils literal"><span class="pre">values</span></tt> suitable for use with
|
||||
<a class="mochiref reference" href="Base.html#fn-querystring">MochiKit.Base.queryString</a>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-getelement"></a>
|
||||
<a class="mochidef reference" href="#fn-getelement">getElement(id[, ...])</a>:</p>
|
||||
<blockquote>
|
||||
<p>A small quick little function to encapsulate the <tt class="docutils literal"><span class="pre">getElementById</span></tt>
|
||||
method. It includes a check to ensure we can use that method.</p>
|
||||
<p>If the id isn't a string, it will be returned as-is.</p>
|
||||
<p>Also available as <a class="mochiref reference" href="#fn-$">$(...)</a> for convenience and compatibility with
|
||||
other JavaScript frameworks.</p>
|
||||
<p>If multiple arguments are given, an <tt class="docutils literal"><span class="pre">Array</span></tt> will be returned.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-getelementsbytagandclassname"></a>
|
||||
<a class="mochidef reference" href="#fn-getelementsbytagandclassname">getElementsByTagAndClassName(tagName, className, parent=document)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Returns an array of elements in <tt class="docutils literal"><span class="pre">parent</span></tt> that match the tag name
|
||||
and class name provided. If <tt class="docutils literal"><span class="pre">parent</span></tt> is a string, it will be looked
|
||||
up with <a class="mochiref reference" href="#fn-getelement">getElement</a>.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">tagName</span></tt> is <tt class="docutils literal"><span class="pre">null</span></tt> or <tt class="docutils literal"><span class="pre">"*"</span></tt>, all elements will be searched
|
||||
for the matching class.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">className</span></tt> is <tt class="docutils literal"><span class="pre">null</span></tt>, all elements matching the provided tag are
|
||||
returned.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-getnodeattribute"></a>
|
||||
<a class="mochidef reference" href="#fn-getnodeattribute">getNodeAttribute(node, attr)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Get the value of the given attribute for a DOM element without
|
||||
ever raising an exception (will return <tt class="docutils literal"><span class="pre">null</span></tt> on exception).</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">node</span></tt>:</dt>
|
||||
<dd>A reference to the DOM element to update (if a string is given,
|
||||
<a class="mochiref reference" href="#fn-getelement">getElement(node)</a> will be used to locate the node)</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">attr</span></tt>:</dt>
|
||||
<dd><p class="first">The name of the attribute</p>
|
||||
<p class="last">Note that it will do the right thing for IE, so don't do
|
||||
the <tt class="docutils literal"><span class="pre">class</span></tt> -> <tt class="docutils literal"><span class="pre">className</span></tt> hack yourself.</p>
|
||||
</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd>The attribute's value, or <tt class="docutils literal"><span class="pre">null</span></tt></dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-getviewportdimensions"></a>
|
||||
<a class="mochidef reference" href="#fn-getviewportdimensions">getViewportDimensions()</a>:</p>
|
||||
<blockquote>
|
||||
Return the pixel width and height of the viewport as an object with <tt class="docutils literal"><span class="pre">w</span></tt>
|
||||
and <tt class="docutils literal"><span class="pre">h</span></tt> properties. <tt class="docutils literal"><span class="pre">element</span></tt> is looked up with
|
||||
<a class="mochiref reference" href="#fn-getelement">getElement</a>, so string identifiers are also acceptable.</blockquote>
|
||||
<p>
|
||||
<a name="fn-haselementclass"></a>
|
||||
<a class="mochidef reference" href="#fn-haselementclass">hasElementClass(element, className[, ...])</a>:</p>
|
||||
<blockquote>
|
||||
Return <tt class="docutils literal"><span class="pre">true</span></tt> if <tt class="docutils literal"><span class="pre">className</span></tt> is found on the <tt class="docutils literal"><span class="pre">element</span></tt>.
|
||||
<tt class="docutils literal"><span class="pre">element</span></tt> is looked up with <a class="mochiref reference" href="#fn-getelement">getElement</a>, so string identifiers
|
||||
are also acceptable.</blockquote>
|
||||
<p>
|
||||
<a name="fn-hideelement"></a>
|
||||
<a class="mochidef reference" href="#fn-hideelement">hideElement(element, ...)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Partial form of <a class="mochiref reference" href="#fn-setdisplayforelement">setDisplayForElement</a>, specifically:</p>
|
||||
<pre class="literal-block">
|
||||
partial(setDisplayForElement, "none")
|
||||
</pre>
|
||||
<p>For information about the caveats of using a <tt class="docutils literal"><span class="pre">style.display</span></tt> based
|
||||
show/hide mechanism, and a CSS based alternative, see
|
||||
<a class="reference" href="#element-visibility">Element Visibility</a>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-registerdomconverter"></a>
|
||||
<a class="mochidef reference" href="#fn-registerdomconverter">registerDOMConverter(name, check, wrap[, override])</a>:</p>
|
||||
<blockquote>
|
||||
Register an adapter to convert objects that match <tt class="docutils literal"><span class="pre">check(obj,</span> <span class="pre">ctx)</span></tt>
|
||||
to a DOM element, or something that can be converted to a DOM
|
||||
element (i.e. number, bool, string, function, iterable).</blockquote>
|
||||
<p>
|
||||
<a name="fn-removeelement"></a>
|
||||
<a class="mochidef reference" href="#fn-removeelement">removeElement(node)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Remove and return <tt class="docutils literal"><span class="pre">node</span></tt> from a DOM tree. This is technically
|
||||
just a convenience for <a class="mochiref reference" href="#fn-swapdom">swapDOM(node, null)</a>.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">node</span></tt>:</dt>
|
||||
<dd>the DOM element (or string id of one) to be removed</dd>
|
||||
<dt><em>returns</em></dt>
|
||||
<dd>The removed element</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-removeelementclass"></a>
|
||||
<a class="mochidef reference" href="#fn-removeelementclass">removeElementClass(element, className)</a>:</p>
|
||||
<blockquote>
|
||||
Ensure that the given <tt class="docutils literal"><span class="pre">element</span></tt> does not have <tt class="docutils literal"><span class="pre">className</span></tt> set as part
|
||||
of its class attribute. This will not disturb other class names.
|
||||
<tt class="docutils literal"><span class="pre">element</span></tt> is looked up with <a class="mochiref reference" href="#fn-getelement">getElement</a>, so string identifiers
|
||||
are also acceptable.</blockquote>
|
||||
<p>
|
||||
<a name="fn-replacechildnodes"></a>
|
||||
<a class="mochidef reference" href="#fn-replacechildnodes">replaceChildNodes(node[, childNode[, ...]])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Remove all children from the given DOM element, then append any given
|
||||
childNodes to it (by calling <a class="mochiref reference" href="#fn-appendchildnodes">appendChildNodes</a>).</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">node</span></tt>:</dt>
|
||||
<dd>A reference to the DOM element to add children to
|
||||
(if a string is given, <a class="mochiref reference" href="#fn-getelement">getElement(node)</a>
|
||||
will be used to locate the node)</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">childNode</span></tt>...:</dt>
|
||||
<dd>All additional arguments, if any, will be coerced into DOM
|
||||
nodes that are appended as children using the
|
||||
<a class="reference" href="#dom-coercion-rules">DOM Coercion Rules</a>.</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd>The given DOM element</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-scrapetext"></a>
|
||||
<a class="mochidef reference" href="#fn-scrapetext">scrapeText(node[, asArray=false])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Walk a DOM tree in-order and scrape all of the text out of it as a
|
||||
<tt class="docutils literal"><span class="pre">string</span></tt>.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">asArray</span></tt> is <tt class="docutils literal"><span class="pre">true</span></tt>, then an <tt class="docutils literal"><span class="pre">Array</span></tt> will be returned with
|
||||
each individual text node. These two are equivalent:</p>
|
||||
<pre class="literal-block">
|
||||
assert( scrapeText(node) == scrapeText(node, true).join("") );
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-setdisplayforelement"></a>
|
||||
<a class="mochidef reference" href="#fn-setdisplayforelement">setDisplayForElement(display, element[, ...])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Change the <tt class="docutils literal"><span class="pre">style.display</span></tt> for the given element(s). Usually
|
||||
used as the partial forms:</p>
|
||||
<ul class="simple">
|
||||
<li><a class="mochiref reference" href="#fn-showelement">showElement(element, ...)</a></li>
|
||||
<li><a class="mochiref reference" href="#fn-hideelement">hideElement(element, ...)</a></li>
|
||||
</ul>
|
||||
<p>Elements are looked up with <a class="mochiref reference" href="#fn-getelement">getElement</a>, so string identifiers
|
||||
are acceptable.</p>
|
||||
<p>For information about the caveats of using a <tt class="docutils literal"><span class="pre">style.display</span></tt> based
|
||||
show/hide mechanism, and a CSS based alternative, see
|
||||
<a class="reference" href="#element-visibility">Element Visibility</a>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-setelementclass"></a>
|
||||
<a class="mochidef reference" href="#fn-setelementclass">setElementClass(element, className)</a>:</p>
|
||||
<blockquote>
|
||||
Set the entire class attribute of <tt class="docutils literal"><span class="pre">element</span></tt> to <tt class="docutils literal"><span class="pre">className</span></tt>.
|
||||
<tt class="docutils literal"><span class="pre">element</span></tt> is looked up with <a class="mochiref reference" href="#fn-getelement">getElement</a>, so string identifiers
|
||||
are also acceptable.</blockquote>
|
||||
<p>
|
||||
<a name="fn-setelementdimensions"></a>
|
||||
<a class="mochidef reference" href="#fn-setelementdimensions">setElementDimensions(element, dimensions[, units='px'])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Sets the dimensions of <tt class="docutils literal"><span class="pre">element</span></tt> in the document from an
|
||||
object with <tt class="docutils literal"><span class="pre">w</span></tt> and <tt class="docutils literal"><span class="pre">h</span></tt> properties.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">node</span></tt>:</dt>
|
||||
<dd>A reference to the DOM element to update (if a string is given,
|
||||
<a class="mochiref reference" href="#fn-getelement">getElement(node)</a> will be used to locate the node)</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">dimensions</span></tt>:</dt>
|
||||
<dd>An object with <tt class="docutils literal"><span class="pre">w</span></tt> and <tt class="docutils literal"><span class="pre">h</span></tt> properties</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">units</span></tt>:</dt>
|
||||
<dd>Optionally set the units to use, default is <tt class="docutils literal"><span class="pre">px</span></tt></dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-setelementposition"></a>
|
||||
<a class="mochidef reference" href="#fn-setelementposition">setElementPosition(element, position[, units='px'])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Sets the absolute position of <tt class="docutils literal"><span class="pre">element</span></tt> in the document from an
|
||||
object with <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt> properties.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">node</span></tt>:</dt>
|
||||
<dd>A reference to the DOM element to update (if a string is given,
|
||||
<a class="mochiref reference" href="#fn-getelement">getElement(node)</a> will be used to locate the node)</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">position</span></tt>:</dt>
|
||||
<dd>An object with <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt> properties</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">units</span></tt>:</dt>
|
||||
<dd>Optionally set the units to use, default is <tt class="docutils literal"><span class="pre">px</span></tt></dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-setnodeattribute"></a>
|
||||
<a class="mochidef reference" href="#fn-setnodeattribute">setNodeAttribute(node, attr, value)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Set the value of the given attribute for a DOM element without
|
||||
ever raising an exception (will return null on exception). If
|
||||
setting more than one attribute, you should use
|
||||
<a class="mochiref reference" href="#fn-updatenodeattributes">updateNodeAttributes</a>.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">node</span></tt>:</dt>
|
||||
<dd>A reference to the DOM element to update (if a string is given,
|
||||
<a class="mochiref reference" href="#fn-getelement">getElement(node)</a> will be used to locate the node)</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">attr</span></tt>:</dt>
|
||||
<dd><p class="first">The name of the attribute</p>
|
||||
<p class="last">Note that it will do the right thing for IE, so don't do
|
||||
the <tt class="docutils literal"><span class="pre">class</span></tt> -> <tt class="docutils literal"><span class="pre">className</span></tt> hack yourself.</p>
|
||||
</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">value</span></tt>:</dt>
|
||||
<dd>The value of the attribute, may be an object to be merged
|
||||
(e.g. for setting style).</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd>The given DOM element or <tt class="docutils literal"><span class="pre">null</span></tt> on failure</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-setopacity"></a>
|
||||
<a class="mochidef reference" href="#fn-setopacity">setOpacity(element, opacity)</a>:</p>
|
||||
<blockquote>
|
||||
Sets <tt class="docutils literal"><span class="pre">opacity</span></tt> for <tt class="docutils literal"><span class="pre">element</span></tt>. Valid <tt class="docutils literal"><span class="pre">opacity</span></tt> values range from 0
|
||||
(invisible) to 1 (opaque). <tt class="docutils literal"><span class="pre">element</span></tt> is looked up with
|
||||
<a class="mochiref reference" href="#fn-getelement">getElement</a>, so string identifiers are also acceptable.</blockquote>
|
||||
<p>
|
||||
<a name="fn-showelement"></a>
|
||||
<a class="mochidef reference" href="#fn-showelement">showElement(element, ...)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Partial form of <a class="mochiref reference" href="#fn-setdisplayforelement">setDisplayForElement</a>, specifically:</p>
|
||||
<pre class="literal-block">
|
||||
partial(setDisplayForElement, "block")
|
||||
</pre>
|
||||
<p>For information about the caveats of using a <tt class="docutils literal"><span class="pre">style.display</span></tt> based
|
||||
show/hide mechanism, and a CSS based alternative, see
|
||||
<a class="reference" href="#element-visibility">Element Visibility</a>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-swapdom"></a>
|
||||
<a class="mochidef reference" href="#fn-swapdom">swapDOM(dest, src)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Replace <tt class="docutils literal"><span class="pre">dest</span></tt> in a DOM tree with <tt class="docutils literal"><span class="pre">src</span></tt>, returning <tt class="docutils literal"><span class="pre">src</span></tt>.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">dest</span></tt>:</dt>
|
||||
<dd>a DOM element (or string id of one) to be replaced</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">src</span></tt>:</dt>
|
||||
<dd>the DOM element (or string id of one) to replace it with, or
|
||||
<tt class="docutils literal"><span class="pre">null</span></tt> if <tt class="docutils literal"><span class="pre">dest</span></tt> is to be removed (replaced with nothing).</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd>a DOM element (<tt class="docutils literal"><span class="pre">src</span></tt>)</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-swapelementclass"></a>
|
||||
<a class="mochidef reference" href="#fn-swapelementclass">swapElementClass(element, fromClass, toClass)</a>:</p>
|
||||
<blockquote>
|
||||
If <tt class="docutils literal"><span class="pre">fromClass</span></tt> is set on <tt class="docutils literal"><span class="pre">element</span></tt>, replace it with <tt class="docutils literal"><span class="pre">toClass</span></tt>.
|
||||
This will not disturb other classes on that element.
|
||||
<tt class="docutils literal"><span class="pre">element</span></tt> is looked up with <a class="mochiref reference" href="#fn-getelement">getElement</a>, so string identifiers
|
||||
are also acceptable.</blockquote>
|
||||
<p>
|
||||
<a name="fn-toggleelementclass"></a>
|
||||
<a class="mochidef reference" href="#fn-toggleelementclass">toggleElementClass(className[, element[, ...]])</a>:</p>
|
||||
<blockquote>
|
||||
Toggle the presence of a given <tt class="docutils literal"><span class="pre">className</span></tt> in the class attribute
|
||||
of all given elements. All elements will be looked up with
|
||||
<a class="mochiref reference" href="#fn-getelement">getElement</a>, so string identifiers are acceptable.</blockquote>
|
||||
<p>
|
||||
<a name="fn-tohtml"></a>
|
||||
<a class="mochidef reference" href="#fn-tohtml">toHTML(dom)</a>:</p>
|
||||
<blockquote>
|
||||
Convert a DOM tree to a HTML string using <a class="mochiref reference" href="#fn-emithtml">emitHTML</a></blockquote>
|
||||
<p>
|
||||
<a name="fn-updatenodeattributes"></a>
|
||||
<a class="mochidef reference" href="#fn-updatenodeattributes">updateNodeAttributes(node, attrs)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Update the attributes of a DOM element from a given object.</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">node</span></tt>:</dt>
|
||||
<dd>A reference to the DOM element to update (if a string is given,
|
||||
<a class="mochiref reference" href="#fn-getelement">getElement(node)</a> will be used to locate the node)</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">attrs</span></tt>:</dt>
|
||||
<dd><p class="first">An object whose properties will be used to set the attributes
|
||||
(e.g. <tt class="docutils literal"><span class="pre">{'class':</span> <span class="pre">'invisible'}</span></tt>), or <tt class="docutils literal"><span class="pre">null</span></tt> if no
|
||||
attributes need to be set. If an object is given for the
|
||||
attribute value (e.g. <tt class="docutils literal"><span class="pre">{'style':</span> <span class="pre">{'display':</span> <span class="pre">'block'}}</span></tt>)
|
||||
then <a class="mochiref reference" href="Base.html#fn-updatetree">MochiKit.Base.updatetree</a> will be used to set that
|
||||
attribute.</p>
|
||||
<p class="last">Note that it will do the right thing for IE, so don't do
|
||||
the <tt class="docutils literal"><span class="pre">class</span></tt> -> <tt class="docutils literal"><span class="pre">className</span></tt> hack yourself, and it deals with
|
||||
setting "on..." event handlers correctly.</p>
|
||||
</dd>
|
||||
<dt><em>returns</em>:</dt>
|
||||
<dd>The given DOM element</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-withwindow"></a>
|
||||
<a class="mochidef reference" href="#fn-withwindow">withWindow(win, func)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Call <tt class="docutils literal"><span class="pre">func</span></tt> with the <tt class="docutils literal"><span class="pre">window</span></tt> <a class="reference" href="#dom-context">DOM Context</a> set to <tt class="docutils literal"><span class="pre">win</span></tt> and
|
||||
the <tt class="docutils literal"><span class="pre">document</span></tt> <a class="reference" href="#dom-context">DOM Context</a> set to <tt class="docutils literal"><span class="pre">win.document</span></tt>. When
|
||||
<tt class="docutils literal"><span class="pre">func()</span></tt> returns or throws an error, the <a class="reference" href="#dom-context">DOM Context</a> will be
|
||||
restored to its previous state.</p>
|
||||
<p>The return value of <tt class="docutils literal"><span class="pre">func()</span></tt> is returned by this function.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-withdocument"></a>
|
||||
<a class="mochidef reference" href="#fn-withdocument">withDocument(doc, func)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Call <tt class="docutils literal"><span class="pre">func</span></tt> with the <tt class="docutils literal"><span class="pre">doc</span></tt> <a class="reference" href="#dom-context">DOM Context</a> set to <tt class="docutils literal"><span class="pre">doc</span></tt>.
|
||||
When <tt class="docutils literal"><span class="pre">func()</span></tt> returns or throws an error, the <a class="reference" href="#dom-context">DOM Context</a>
|
||||
will be restored to its previous state.</p>
|
||||
<p>The return value of <tt class="docutils literal"><span class="pre">func()</span></tt> is returned by this function.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="see-also" name="see-also">See Also</a></h1>
|
||||
<table class="docutils footnote" frame="void" id="id5" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a name="id5">[1]</a></td><td><em>(<a class="fn-backref" href="#id1">1</a>, <a class="fn-backref" href="#id3">2</a>)</em> Nevow, a web application construction kit for Python: <a class="reference" href="http://nevow.com/">http://nevow.com/</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="id6" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a name="id6">[2]</a></td><td><em>(<a class="fn-backref" href="#id2">1</a>, <a class="fn-backref" href="#id4">2</a>)</em> nevow.stan is a domain specific language for Python
|
||||
(read as "crazy getitem/call overloading abuse") that Donovan and I
|
||||
schemed up at PyCon 2003 at this super ninja Python/C++ programmer's
|
||||
(David Abrahams) hotel room. Donovan later inflicted this upon the
|
||||
masses in Nevow. Check out the Divmod project page for some
|
||||
examples: <a class="reference" href="http://nevow.com/Nevow2004Tutorial.html">http://nevow.com/Nevow2004Tutorial.html</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="authors" name="authors">Authors</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="copyright" name="copyright">Copyright</a></h1>
|
||||
<p>Copyright 2005 Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>>. This program is dual-licensed
|
||||
free software; you can redistribute it and/or modify it under the terms of the
|
||||
<a class="reference" href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> or the <a class="reference" href="http://www.opensource.org/licenses/afl-2.1.php">Academic Free License v2.1</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,125 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
||||
<title>MochiKit.DateTime - "what time is it anyway?"</title>
|
||||
|
||||
<link rel="stylesheet" href="../../../include/css/documentation.css" type="text/css" />
|
||||
<script type="text/javascript" src="../../../packed/lib/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="../../js/toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document">
|
||||
<div class="section">
|
||||
<h1><a id="name" name="name">Name</a></h1>
|
||||
<p>MochiKit.DateTime - "what time is it anyway?"</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="synopsis" name="synopsis">Synopsis</a></h1>
|
||||
<pre class="literal-block">
|
||||
stringDate = toISOTimestamp(new Date());
|
||||
dateObject = isoTimestamp(stringDate);
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="description" name="description">Description</a></h1>
|
||||
<p>Remote servers don't give you JavaScript Date objects, and they certainly
|
||||
don't want them from you, so you need to deal with string representations
|
||||
of dates and timestamps. MochiKit.Date does that.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="dependencies" name="dependencies">Dependencies</a></h1>
|
||||
<p>None.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="api-reference" name="api-reference">API Reference</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="functions" name="functions">Functions</a></h2>
|
||||
<p>
|
||||
<a name="fn-isodate"></a>
|
||||
<a class="mochidef reference" href="#fn-isodate">isoDate(str)</a>:</p>
|
||||
<blockquote>
|
||||
Convert an ISO 8601 date (YYYY-MM-DD) to a <tt class="docutils literal"><span class="pre">Date</span></tt> object.</blockquote>
|
||||
<p>
|
||||
<a name="fn-isotimestamp"></a>
|
||||
<a class="mochidef reference" href="#fn-isotimestamp">isoTimestamp(str)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Convert any ISO 8601 <a class="footnote-reference" href="#id3" id="id1" name="id1">[1]</a> timestamp (or something reasonably close to it)
|
||||
to a <tt class="docutils literal"><span class="pre">Date</span></tt> object. Will accept the "de facto" form:</p>
|
||||
<blockquote>
|
||||
YYYY-MM-DD hh:mm:ss</blockquote>
|
||||
<p>or (the proper form):</p>
|
||||
<blockquote>
|
||||
YYYY-MM-DDThh:mm:ssZ</blockquote>
|
||||
<p>If a time zone designator ("Z" or "[+-]HH:MM") is not present, then the
|
||||
local timezone is used.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-toisotime"></a>
|
||||
<a class="mochidef reference" href="#fn-toisotime">toISOTime(date)</a>:</p>
|
||||
<blockquote>
|
||||
Convert a <tt class="docutils literal"><span class="pre">Date</span></tt> object to a string in the form of hh:mm:ss</blockquote>
|
||||
<p>
|
||||
<a name="fn-toisotimestamp"></a>
|
||||
<a class="mochidef reference" href="#fn-toisotimestamp">toISOTimestamp(date, realISO=false)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Convert a <tt class="docutils literal"><span class="pre">Date</span></tt> object to something that's ALMOST but not quite an
|
||||
ISO 8601 [1]_timestamp. If it was a proper ISO timestamp it would be:</p>
|
||||
<blockquote>
|
||||
YYYY-MM-DDThh:mm:ssZ</blockquote>
|
||||
<p>However, we see junk in SQL and other places that looks like this:</p>
|
||||
<blockquote>
|
||||
YYYY-MM-DD hh:mm:ss</blockquote>
|
||||
<p>So, this function returns the latter form, despite its name, unless
|
||||
you pass <tt class="docutils literal"><span class="pre">true</span></tt> for <tt class="docutils literal"><span class="pre">realISO</span></tt>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-toisodate"></a>
|
||||
<a class="mochidef reference" href="#fn-toisodate">toISODate(date)</a>:</p>
|
||||
<blockquote>
|
||||
Convert a <tt class="docutils literal"><span class="pre">Date</span></tt> object to an ISO 8601 <a class="footnote-reference" href="#id3" id="id2" name="id2">[1]</a> date string (YYYY-MM-DD)</blockquote>
|
||||
<p>
|
||||
<a name="fn-americandate"></a>
|
||||
<a class="mochidef reference" href="#fn-americandate">americanDate(str)</a>:</p>
|
||||
<blockquote>
|
||||
Converts a MM/DD/YYYY date to a <tt class="docutils literal"><span class="pre">Date</span></tt> object</blockquote>
|
||||
<p>
|
||||
<a name="fn-topaddedamericandate"></a>
|
||||
<a class="mochidef reference" href="#fn-topaddedamericandate">toPaddedAmericanDate(date)</a>:</p>
|
||||
<blockquote>
|
||||
Converts a <tt class="docutils literal"><span class="pre">Date</span></tt> object to an MM/DD/YYYY date, e.g. 01/01/2001</blockquote>
|
||||
<p>
|
||||
<a name="fn-toamericandate"></a>
|
||||
<a class="mochidef reference" href="#fn-toamericandate">toAmericanDate(date)</a>:</p>
|
||||
<blockquote>
|
||||
Converts a <tt class="docutils literal"><span class="pre">Date</span></tt> object to an M/D/YYYY date, e.g. 1/1/2001</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="see-also" name="see-also">See Also</a></h1>
|
||||
<table class="docutils footnote" frame="void" id="id3" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a name="id3">[1]</a></td><td><em>(<a class="fn-backref" href="#id1">1</a>, <a class="fn-backref" href="#id2">2</a>)</em> W3C profile of ISO 8601: <a class="reference" href="http://www.w3.org/TR/NOTE-datetime">http://www.w3.org/TR/NOTE-datetime</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="authors" name="authors">Authors</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="copyright" name="copyright">Copyright</a></h1>
|
||||
<p>Copyright 2005 Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>>. This program is dual-licensed
|
||||
free software; you can redistribute it and/or modify it under the terms of the
|
||||
<a class="reference" href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> or the <a class="reference" href="http://www.opensource.org/licenses/afl-2.1.php">Academic Free License v2.1</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,241 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
||||
<title>MochiKit.Format - string formatting goes here</title>
|
||||
|
||||
<link rel="stylesheet" href="../../../include/css/documentation.css" type="text/css" />
|
||||
<script type="text/javascript" src="../../../packed/lib/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="../../js/toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document">
|
||||
<div class="section">
|
||||
<h1><a id="name" name="name">Name</a></h1>
|
||||
<p>MochiKit.Format - string formatting goes here</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="synopsis" name="synopsis">Synopsis</a></h1>
|
||||
<pre class="literal-block">
|
||||
assert( truncToFixed(0.12345, 4) == "0.1234" );
|
||||
assert( roundToFixed(0.12345, 4) == "0.1235" );
|
||||
assert( twoDigitAverage(1, 0) == "0" );
|
||||
assert( twoDigitFloat(1.2345) == "1.23" );
|
||||
assert( twoDigitFloat(1) == "1" );
|
||||
assert( percentFormat(1.234567) == "123.46%" );
|
||||
assert( numberFormatter("###,###%")(125) == "12,500%" );
|
||||
assert( numberFormatter("##.000")(1.25) == "1.250" );
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="description" name="description">Description</a></h1>
|
||||
<p>Formatting strings and stringifying numbers is boring, so a couple useful
|
||||
functions in that domain live here.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="dependencies" name="dependencies">Dependencies</a></h1>
|
||||
<p>None.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="overview" name="overview">Overview</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="formatting-numbers" name="formatting-numbers">Formatting Numbers</a></h2>
|
||||
<p>MochiKit provides an extensible number formatting facility, modeled loosely
|
||||
after the Number Format Pattern Syntax <a class="footnote-reference" href="#id2" id="id1" name="id1">[1]</a> from Java.
|
||||
<a class="mochiref reference" href="#fn-numberformatter">numberFormatter(pattern[, placeholder=""[, locale="default"])</a>
|
||||
returns a function that converts Number to string using the given information.
|
||||
<tt class="docutils literal"><span class="pre">pattern</span></tt> is a string consisting of the following symbols:</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="15%" />
|
||||
<col width="85%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th class="head">Symbol</th>
|
||||
<th class="head">Meaning</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><tt class="docutils literal"><span class="pre">-</span></tt></td>
|
||||
<td>If given, used as the position of the minus sign
|
||||
for negative numbers. If not given, the position
|
||||
to the left of the first number placeholder is used.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">#</span></tt></td>
|
||||
<td>The placeholder for a number that does not imply zero
|
||||
padding.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">0</span></tt></td>
|
||||
<td>The placeholder for a number that implies zero padding.
|
||||
If it is used to the right of a decimal separator, it
|
||||
implies trailing zeros, otherwise leading zeros.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">,</span></tt></td>
|
||||
<td>The placeholder for a "thousands separator". May be used
|
||||
at most once, and it must be to the left of a decimal
|
||||
separator. Will be replaced by <tt class="docutils literal"><span class="pre">locale.separator</span></tt> in the
|
||||
result (the default is also <tt class="docutils literal"><span class="pre">,</span></tt>).</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">.</span></tt></td>
|
||||
<td>The decimal separator. The quantity of <tt class="docutils literal"><span class="pre">#</span></tt> or <tt class="docutils literal"><span class="pre">0</span></tt>
|
||||
after the decimal separator will determine the precision of
|
||||
the result. If no decimal separator is present, the
|
||||
fractional precision is <tt class="docutils literal"><span class="pre">0</span></tt> -- meaning that it will be
|
||||
rounded to the nearest integer.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">%</span></tt></td>
|
||||
<td>If present, the number will be multiplied by <tt class="docutils literal"><span class="pre">100</span></tt> and
|
||||
the <tt class="docutils literal"><span class="pre">%</span></tt> will be replaced by <tt class="docutils literal"><span class="pre">locale.percent</span></tt>.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="api-reference" name="api-reference">API Reference</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="functions" name="functions">Functions</a></h2>
|
||||
<p>
|
||||
<a name="fn-formatlocale"></a>
|
||||
<a class="mochidef reference" href="#fn-formatlocale">formatLocale(locale="default")</a>:</p>
|
||||
<blockquote>
|
||||
Return a locale object for the given locale. <tt class="docutils literal"><span class="pre">locale</span></tt> may be either a
|
||||
string, which is looked up in the <tt class="docutils literal"><span class="pre">MochiKit.Format.LOCALE</span></tt> object, or
|
||||
a locale object. If no locale is given, <tt class="docutils literal"><span class="pre">LOCALE.default</span></tt> is used
|
||||
(equivalent to <tt class="docutils literal"><span class="pre">LOCALE.en_US</span></tt>).</blockquote>
|
||||
<p>
|
||||
<a name="fn-lstrip"></a>
|
||||
<a class="mochidef reference" href="#fn-lstrip">lstrip(str, chars="\s")</a>:</p>
|
||||
<blockquote>
|
||||
<p>Returns a string based on <tt class="docutils literal"><span class="pre">str</span></tt> with leading whitespace stripped.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">chars</span></tt> is given, then that expression will be used instead of
|
||||
whitespace. <tt class="docutils literal"><span class="pre">chars</span></tt> should be a string suitable for use in a <tt class="docutils literal"><span class="pre">RegExp</span></tt>
|
||||
<tt class="docutils literal"><span class="pre">[character</span> <span class="pre">set]</span></tt>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-numberformatter"></a>
|
||||
<a class="mochidef reference" href="#fn-numberformatter">numberFormatter(pattern, placeholder="", locale="default")</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return a function <tt class="docutils literal"><span class="pre">formatNumber(aNumber)</span></tt> that formats numbers
|
||||
as a string according to the given pattern, placeholder and locale.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">pattern</span></tt> is a string that describes how the numbers should be formatted,
|
||||
for more information see <a class="reference" href="#formatting-numbers">Formatting Numbers</a>.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">locale</span></tt> is a string of a known locale (en_US, de_DE, fr_FR, default) or
|
||||
an object with the following fields:</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="16%" />
|
||||
<col width="84%" />
|
||||
</colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td>separator</td>
|
||||
<td>The "thousands" separator for this locale (en_US is ",")</td>
|
||||
</tr>
|
||||
<tr><td>decimal</td>
|
||||
<td>The decimal separator for this locale (en_US is ".")</td>
|
||||
</tr>
|
||||
<tr><td>percent</td>
|
||||
<td>The percent symbol for this locale (en_US is "%")</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-percentformat"></a>
|
||||
<a class="mochidef reference" href="#fn-percentformat">percentFormat(someFloat)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Roughly equivalent to: <tt class="docutils literal"><span class="pre">sprintf("%.2f%%",</span> <span class="pre">someFloat</span> <span class="pre">*</span> <span class="pre">100)</span></tt></p>
|
||||
<p>In new code, you probably want to use:
|
||||
<a class="mochiref reference" href="#fn-numberformatter">numberFormatter("#.##%")(someFloat)</a> instead.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-roundtofixed"></a>
|
||||
<a class="mochidef reference" href="#fn-roundtofixed">roundToFixed(aNumber, precision)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return a string representation of <tt class="docutils literal"><span class="pre">aNumber</span></tt>, rounded to <tt class="docutils literal"><span class="pre">precision</span></tt>
|
||||
digits with trailing zeros. This is similar to
|
||||
<tt class="docutils literal"><span class="pre">Number.toFixed(aNumber,</span> <span class="pre">precision)</span></tt>, but this has implementation
|
||||
consistent rounding behavior (some versions of Safari round 0.5 down!)
|
||||
and also includes preceding <tt class="docutils literal"><span class="pre">0</span></tt> for numbers less than <tt class="docutils literal"><span class="pre">1</span></tt> (Safari,
|
||||
again).</p>
|
||||
<p>For example, <a class="mochiref reference" href="#fn-roundtofixed">roundToFixed(0.1357, 2)</a> returns <tt class="docutils literal"><span class="pre">0.14</span></tt> on every
|
||||
supported platform, where some return <tt class="docutils literal"><span class="pre">.13</span></tt> for <tt class="docutils literal"><span class="pre">(0.1357).toFixed(2)</span></tt>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-rstrip"></a>
|
||||
<a class="mochidef reference" href="#fn-rstrip">rstrip(str, chars="\s")</a>:</p>
|
||||
<blockquote>
|
||||
<p>Returns a string based on <tt class="docutils literal"><span class="pre">str</span></tt> with trailing whitespace stripped.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">chars</span></tt> is given, then that expression will be used instead of
|
||||
whitespace. <tt class="docutils literal"><span class="pre">chars</span></tt> should be a string suitable for use in a <tt class="docutils literal"><span class="pre">RegExp</span></tt>
|
||||
<tt class="docutils literal"><span class="pre">[character</span> <span class="pre">set]</span></tt>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-strip"></a>
|
||||
<a class="mochidef reference" href="#fn-strip">strip(str, chars="\s")</a>:</p>
|
||||
<blockquote>
|
||||
<p>Returns a string based on <tt class="docutils literal"><span class="pre">str</span></tt> with leading and trailing whitespace
|
||||
stripped (equivalent to <a class="mochiref reference" href="#fn-lstrip">lstrip(rstrip(str, chars), chars)</a>).</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">chars</span></tt> is given, then that expression will be used instead of
|
||||
whitespace. <tt class="docutils literal"><span class="pre">chars</span></tt> should be a string suitable for use in a <tt class="docutils literal"><span class="pre">RegExp</span></tt>
|
||||
<tt class="docutils literal"><span class="pre">[character</span> <span class="pre">set]</span></tt>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-trunctofixed"></a>
|
||||
<a class="mochidef reference" href="#fn-trunctofixed">truncToFixed(aNumber, precision)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return a string representation of <tt class="docutils literal"><span class="pre">aNumber</span></tt>, truncated to <tt class="docutils literal"><span class="pre">precision</span></tt>
|
||||
digits with trailing zeros. This is similar to
|
||||
<tt class="docutils literal"><span class="pre">aNumber.toFixed(precision)</span></tt>, but this truncates rather than rounds and
|
||||
has implementation consistent behavior for numbers less than 1.
|
||||
Specifically, <a class="mochiref reference" href="#fn-trunctofixed">truncToFixed(aNumber, precision)</a> will always have a
|
||||
preceding <tt class="docutils literal"><span class="pre">0</span></tt> for numbers less than <tt class="docutils literal"><span class="pre">1</span></tt>.</p>
|
||||
<p>For example, <a class="mochiref reference" href="#fn-tofixed">toFixed(0.1357, 2)</a> returns <tt class="docutils literal"><span class="pre">0.13</span></tt>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-twodigitaverage"></a>
|
||||
<a class="mochidef reference" href="#fn-twodigitaverage">twoDigitAverage(numerator, denominator)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Calculate an average from a numerator and a denominator and return
|
||||
it as a string with two digits of precision (e.g. "1.23").</p>
|
||||
<p>If the denominator is 0, "0" will be returned instead of <tt class="docutils literal"><span class="pre">NaN</span></tt>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-twodigitfloat"></a>
|
||||
<a class="mochidef reference" href="#fn-twodigitfloat">twoDigitFloat(someFloat)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Roughly equivalent to: <tt class="docutils literal"><span class="pre">sprintf("%.2f",</span> <span class="pre">someFloat)</span></tt></p>
|
||||
<p>In new code, you probably want to use
|
||||
<a class="mochiref reference" href="#fn-numberformatter">numberFormatter("#.##")(someFloat)</a> instead.</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="see-also" name="see-also">See Also</a></h1>
|
||||
<table class="docutils footnote" frame="void" id="id2" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id1" name="id2">[1]</a></td><td>Java Number Format Pattern Syntax:
|
||||
<a class="reference" href="http://java.sun.com/docs/books/tutorial/i18n/format/numberpattern.html">http://java.sun.com/docs/books/tutorial/i18n/format/numberpattern.html</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="authors" name="authors">Authors</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="copyright" name="copyright">Copyright</a></h1>
|
||||
<p>Copyright 2005 Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>>. This program is dual-licensed
|
||||
free software; you can redistribute it and/or modify it under the terms of the
|
||||
<a class="reference" href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> or the <a class="reference" href="http://www.opensource.org/licenses/afl-2.1.php">Academic Free License v2.1</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,372 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
||||
<title>MochiKit.Iter - itertools for JavaScript; iteration made HARD, and then easy</title>
|
||||
|
||||
<link rel="stylesheet" href="../../../include/css/documentation.css" type="text/css" />
|
||||
<script type="text/javascript" src="../../../packed/lib/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="../../js/toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document">
|
||||
<div class="section">
|
||||
<h1><a id="name" name="name">Name</a></h1>
|
||||
<p>MochiKit.Iter - itertools for JavaScript; iteration made HARD, and then easy</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="synopsis" name="synopsis">Synopsis</a></h1>
|
||||
<pre class="literal-block">
|
||||
theSum = sum(takewhile(
|
||||
partial(operator.gt, 10),
|
||||
imap(
|
||||
partial(operator.mul, 2),
|
||||
count()
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
assert( theSum == (0 + 0 + 2 + 4 + 6 + 8) );
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="description" name="description">Description</a></h1>
|
||||
<p>All of the functional programming missing from <a class="mochiref reference" href="Base.html">MochiKit.Base</a> lives
|
||||
here. The functionality in this module is largely inspired by Python's iteration
|
||||
protocol <a class="footnote-reference" href="#id4" id="id1" name="id1">[1]</a>, and the itertools module <a class="footnote-reference" href="#id5" id="id2" name="id2">[2]</a>.</p>
|
||||
<p>MochiKit.Iter defines a standard way to iterate over anything, that you can
|
||||
extend with <a class="mochiref reference" href="#fn-registeriterator">registerIterator</a>, or by implementing the <tt class="docutils literal"><span class="pre">.iter()</span></tt>
|
||||
protocol. Iterators are lazy, so it can potentially be cheaper to build a
|
||||
filter chain of iterators than to build lots of intermediate arrays.
|
||||
Especially when the data set is very large, but the result is not.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="dependencies" name="dependencies">Dependencies</a></h1>
|
||||
<ul class="simple">
|
||||
<li><a class="mochiref reference" href="Base.html">MochiKit.Base</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="overview" name="overview">Overview</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="iteration-for-javascript" name="iteration-for-javascript">Iteration for JavaScript</a></h2>
|
||||
<p>The best overview right now is in my Iteration for JavaScript <a class="footnote-reference" href="#id6" id="id3" name="id3">[3]</a> blog entry.
|
||||
This information will migrate here eventually.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="api-reference" name="api-reference">API Reference</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="errors" name="errors">Errors</a></h2>
|
||||
<p>
|
||||
<a name="fn-stopiteration"></a>
|
||||
<a class="mochidef reference" href="#fn-stopiteration">StopIteration</a>:</p>
|
||||
<blockquote>
|
||||
The singleton <a class="mochiref reference" href="Base.html#fn-namederror">MochiKit.Base.NamedError</a> that signifies the end
|
||||
of an iterator</blockquote>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="functions" name="functions">Functions</a></h2>
|
||||
<p>
|
||||
<a name="fn-applymap"></a>
|
||||
<a class="mochidef reference" href="#fn-applymap">applymap(fun, seq[, self])</a>:</p>
|
||||
<blockquote>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">applymap(fun,</span> <span class="pre">seq)</span></tt> --></dt>
|
||||
<dd>fun.apply(self, seq0), fun.apply(self, seq1), ...</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-chain"></a>
|
||||
<a class="mochidef reference" href="#fn-chain">chain(p, q[, ...])</a>:</p>
|
||||
<blockquote>
|
||||
<tt class="docutils literal"><span class="pre">chain(p,</span> <span class="pre">q,</span> <span class="pre">...)</span></tt> --> p0, p1, ... plast, q0, q1, ...</blockquote>
|
||||
<p>
|
||||
<a name="fn-count"></a>
|
||||
<a class="mochidef reference" href="#fn-count">count(n=0)</a>:</p>
|
||||
<blockquote>
|
||||
<tt class="docutils literal"><span class="pre">count(n=0)</span></tt> --> n, n + 1, n + 2, ...</blockquote>
|
||||
<p>
|
||||
<a name="fn-cycle"></a>
|
||||
<a class="mochidef reference" href="#fn-cycle">cycle(p)</a>:</p>
|
||||
<blockquote>
|
||||
<tt class="docutils literal"><span class="pre">cycle(p)</span></tt> --> p0, p1, ... plast, p0, p1, ...</blockquote>
|
||||
<p>
|
||||
<a name="fn-dropwhile"></a>
|
||||
<a class="mochidef reference" href="#fn-dropwhile">dropwhile(pred, seq)</a>:</p>
|
||||
<blockquote>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">dropwhile(pred,</span> <span class="pre">seq)</span></tt> --> seq[n], seq[n + 1], starting when</dt>
|
||||
<dd>pred(seq[n]) fails</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-every"></a>
|
||||
<a class="mochidef reference" href="#fn-every">every(iterable, func)</a>:</p>
|
||||
<blockquote>
|
||||
Return <tt class="docutils literal"><span class="pre">true</span></tt> if <tt class="docutils literal"><span class="pre">func(item)</span></tt> is <tt class="docutils literal"><span class="pre">true</span></tt> for every item in
|
||||
<tt class="docutils literal"><span class="pre">iterable</span></tt>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-exhaust"></a>
|
||||
<a class="mochidef reference" href="#fn-exhaust">exhaust(iterable)</a>:</p>
|
||||
<blockquote>
|
||||
Exhausts an iterable without saving the results anywhere,
|
||||
like <a class="mochiref reference" href="#fn-list">list(iterable)</a> when you don't care what the output is.</blockquote>
|
||||
<p>
|
||||
<a name="fn-foreach"></a>
|
||||
<a class="mochidef reference" href="#fn-foreach">forEach(iterable, func[, self])</a>:</p>
|
||||
<blockquote>
|
||||
Call <tt class="docutils literal"><span class="pre">func</span></tt> for each item in <tt class="docutils literal"><span class="pre">iterable</span></tt>, and don't save the results.</blockquote>
|
||||
<p>
|
||||
<a name="fn-groupby"></a>
|
||||
<a class="mochidef reference" href="#fn-groupby">groupby(iterable[, keyfunc])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Make an iterator that returns consecutive keys and groups from the
|
||||
iterable. The key is a function computing a key value for each element.
|
||||
If not specified or is None, key defaults to an identity function and
|
||||
returns the element unchanged. Generally, the iterable needs to already be
|
||||
sorted on the same key function.</p>
|
||||
<p>The returned group is itself an iterator that shares the underlying
|
||||
iterable with <a class="mochiref reference" href="#fn-groupby">groupby()</a>. Because the source is shared, when the
|
||||
groupby object is advanced, the previous group is no longer visible.
|
||||
So, if that data is needed later, it should be stored as an array:</p>
|
||||
<pre class="literal-block">
|
||||
var groups = [];
|
||||
var uniquekeys = [];
|
||||
forEach(groupby(data, keyfunc), function (key_group) {
|
||||
groups.push(list(key_group[1]));
|
||||
uniquekeys.push(key_group[0]);
|
||||
});
|
||||
</pre>
|
||||
<p>As a convenience, <a class="mochiref reference" href="#fn-groupby_as_array">groupby_as_array()</a> is provided to suit the above
|
||||
use case.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-groupby_as_array"></a>
|
||||
<a class="mochidef reference" href="#fn-groupby_as_array">groupby_as_array(iterable[, keyfunc])</a>:</p>
|
||||
<blockquote>
|
||||
Perform the same task as <a class="mochiref reference" href="#fn-groupby">groupby()</a>, except return an array of
|
||||
arrays instead of an iterator of iterators.</blockquote>
|
||||
<p>
|
||||
<a name="fn-iextend"></a>
|
||||
<a class="mochidef reference" href="#fn-iextend">iextend(lst, iterable)</a>:</p>
|
||||
<blockquote>
|
||||
Just like <a class="mochiref reference" href="#fn-list">list(iterable)</a>, except it pushes results on <tt class="docutils literal"><span class="pre">lst</span></tt>
|
||||
rather than creating a new one.</blockquote>
|
||||
<p>
|
||||
<a name="fn-ifilter"></a>
|
||||
<a class="mochidef reference" href="#fn-ifilter">ifilter(pred, seq)</a>:</p>
|
||||
<blockquote>
|
||||
<tt class="docutils literal"><span class="pre">ifilter(pred,</span> <span class="pre">seq)</span></tt> --> elements of seq where <tt class="docutils literal"><span class="pre">pred(elem)</span></tt> is <tt class="docutils literal"><span class="pre">true</span></tt></blockquote>
|
||||
<p>
|
||||
<a name="fn-ifilterfalse"></a>
|
||||
<a class="mochidef reference" href="#fn-ifilterfalse">ifilterfalse(pred, seq)</a>:</p>
|
||||
<blockquote>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">ifilterfalse(pred,</span> <span class="pre">seq)</span></tt> --> elements of seq where <tt class="docutils literal"><span class="pre">pred(elem)</span></tt> is</dt>
|
||||
<dd><tt class="docutils literal"><span class="pre">false</span></tt></dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-imap"></a>
|
||||
<a class="mochidef reference" href="#fn-imap">imap(fun, p, q[, ...])</a>:</p>
|
||||
<blockquote>
|
||||
<tt class="docutils literal"><span class="pre">imap(fun,</span> <span class="pre">p,</span> <span class="pre">q,</span> <span class="pre">...)</span></tt> --> fun(p0, q0, ...), fun(p1, q1, ...), ...</blockquote>
|
||||
<p>
|
||||
<a name="fn-islice"></a>
|
||||
<a class="mochidef reference" href="#fn-islice">islice(seq, [start,] stop[, step])</a>:</p>
|
||||
<blockquote>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">islice(seq,</span> <span class="pre">[start,]</span> <span class="pre">stop[,</span> <span class="pre">step])</span></tt> --> elements from</dt>
|
||||
<dd>seq[start:stop:step] (in Python slice syntax)</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-iter"></a>
|
||||
<a class="mochidef reference" href="#fn-iter">iter(iterable[, sentinel])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Convert the given argument to an iterator (object implementing
|
||||
<tt class="docutils literal"><span class="pre">.next()</span></tt>).</p>
|
||||
<ol class="arabic simple">
|
||||
<li>If <tt class="docutils literal"><span class="pre">iterable</span></tt> is an iterator (implements <tt class="docutils literal"><span class="pre">.next()</span></tt>), then it will
|
||||
be returned as-is.</li>
|
||||
<li>If <tt class="docutils literal"><span class="pre">iterable</span></tt> is an iterator factory (implements <tt class="docutils literal"><span class="pre">.iter()</span></tt>), then
|
||||
the result of <tt class="docutils literal"><span class="pre">iterable.iter()</span></tt> will be returned.</li>
|
||||
<li>Otherwise, the iterator factory <a class="mochiref reference" href="Base.html#fn-adapterregistry">MochiKit.Base.AdapterRegistry</a>
|
||||
is used to find a match.</li>
|
||||
<li>If no factory is found, it will throw <tt class="docutils literal"><span class="pre">TypeError</span></tt></li>
|
||||
</ol>
|
||||
<p>Built-in iterator factories are present for Array-like objects, and
|
||||
objects that implement the <tt class="docutils literal"><span class="pre">iterateNext</span></tt> protocol (e.g. the result of
|
||||
Mozilla's <tt class="docutils literal"><span class="pre">document.evaluate</span></tt>).</p>
|
||||
<p>When used directly, using an iterator should look like this:</p>
|
||||
<pre class="literal-block">
|
||||
var it = iter(iterable);
|
||||
try {
|
||||
while (var o = it.next()) {
|
||||
// use o
|
||||
}
|
||||
} catch (e) {
|
||||
if (e != StopIteration) {
|
||||
throw e;
|
||||
}
|
||||
// pass
|
||||
}
|
||||
</pre>
|
||||
<p>This is ugly, so you should use the higher order functions to work
|
||||
with iterators whenever possible.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-izip"></a>
|
||||
<a class="mochidef reference" href="#fn-izip">izip(p, q[, ...])</a>:</p>
|
||||
<blockquote>
|
||||
<tt class="docutils literal"><span class="pre">izip(p,</span> <span class="pre">q,</span> <span class="pre">...)</span></tt> --> [p0, q0, ...], [p1, q1, ...], ...</blockquote>
|
||||
<p>
|
||||
<a name="fn-list"></a>
|
||||
<a class="mochidef reference" href="#fn-list">list(iterable)</a>:</p>
|
||||
<blockquote>
|
||||
Convert <tt class="docutils literal"><span class="pre">iterable</span></tt> to a new <tt class="docutils literal"><span class="pre">Array</span></tt></blockquote>
|
||||
<p>
|
||||
<a name="fn-next"></a>
|
||||
<a class="mochidef reference" href="#fn-next">next(iterator)</a>:</p>
|
||||
<blockquote>
|
||||
Return <tt class="docutils literal"><span class="pre">iterator.next()</span></tt></blockquote>
|
||||
<p>
|
||||
<a name="fn-range"></a>
|
||||
<a class="mochidef reference" href="#fn-range">range([start,] stop[, step])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Return an iterator containing an arithmetic progression of integers.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">range(i,</span> <span class="pre">j)</span></tt> returns <a class="mochiref reference" href="#fn-iter">iter([i, i + 1, i + 2, ..., j - 1])</a></p>
|
||||
<p><tt class="docutils literal"><span class="pre">start</span></tt> (!) defaults to <tt class="docutils literal"><span class="pre">0</span></tt>. When <tt class="docutils literal"><span class="pre">step</span></tt> is given, it specifies the
|
||||
increment (or decrement). The end point is omitted!</p>
|
||||
<p>For example, <tt class="docutils literal"><span class="pre">range(4)</span></tt> returns <a class="mochiref reference" href="#fn-iter">iter([0, 1, 2, 3])</a>.
|
||||
This iterates over exactly the valid indexes for an array of 4 elements.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-reduce"></a>
|
||||
<a class="mochidef reference" href="#fn-reduce">reduce(fn, iterable[, initial])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Apply <tt class="docutils literal"><span class="pre">fn(a,</span> <span class="pre">b)</span></tt> cumulatively to the items of an
|
||||
iterable from left to right, so as to reduce the iterable
|
||||
to a single value.</p>
|
||||
<p>For example:</p>
|
||||
<pre class="literal-block">
|
||||
reduce(function (a, b) { return x + y; }, [1, 2, 3, 4, 5])
|
||||
</pre>
|
||||
<p>calculates:</p>
|
||||
<pre class="literal-block">
|
||||
((((1 + 2) + 3) + 4) + 5).
|
||||
</pre>
|
||||
<p>If initial is given, it is placed before the items of the sequence
|
||||
in the calculation, and serves as a default when the sequence is
|
||||
empty.</p>
|
||||
<p>Note that the above example could be written more clearly as:</p>
|
||||
<pre class="literal-block">
|
||||
reduce(operator.add, [1, 2, 3, 4, 5])
|
||||
</pre>
|
||||
<p>Or even simpler:</p>
|
||||
<pre class="literal-block">
|
||||
sum([1, 2, 3, 4, 5])
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-registeriteratorfactory"></a>
|
||||
<a class="mochidef reference" href="#fn-registeriteratorfactory">registerIteratorFactory(name, check, iterfactory[, override])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Register an iterator factory for use with the iter function.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">check</span></tt> is a <tt class="docutils literal"><span class="pre">function(a)</span></tt> that returns <tt class="docutils literal"><span class="pre">true</span></tt> if <tt class="docutils literal"><span class="pre">a</span></tt> can be
|
||||
converted into an iterator with <tt class="docutils literal"><span class="pre">iterfactory</span></tt>.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">iterfactory</span></tt> is a <tt class="docutils literal"><span class="pre">function(a)</span></tt> that returns an object with a
|
||||
<tt class="docutils literal"><span class="pre">.next()</span></tt> method that returns the next value in the sequence.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">iterfactory</span></tt> is guaranteed to only be called if <tt class="docutils literal"><span class="pre">check(a)</span></tt>
|
||||
returns a true value.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">override</span></tt> is <tt class="docutils literal"><span class="pre">true</span></tt>, then it will be made the
|
||||
highest precedence iterator factory. Otherwise, the lowest.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-repeat"></a>
|
||||
<a class="mochidef reference" href="#fn-repeat">repeat(elem[, n])</a>:</p>
|
||||
<blockquote>
|
||||
<tt class="docutils literal"><span class="pre">repeat(elem,</span> <span class="pre">[,n])</span></tt> --> elem, elem, elem, ... endlessly or up to n times</blockquote>
|
||||
<p>
|
||||
<a name="fn-reversed"></a>
|
||||
<a class="mochidef reference" href="#fn-reversed">reversed(iterable)</a>:</p>
|
||||
<blockquote>
|
||||
Return a reversed array from iterable.</blockquote>
|
||||
<p>
|
||||
<a name="fn-some"></a>
|
||||
<a class="mochidef reference" href="#fn-some">some(iterable, func)</a>:</p>
|
||||
<blockquote>
|
||||
Return <tt class="docutils literal"><span class="pre">true</span></tt> if <tt class="docutils literal"><span class="pre">func(item)</span></tt> is <tt class="docutils literal"><span class="pre">true</span></tt> for at least one item in
|
||||
<tt class="docutils literal"><span class="pre">iterable</span></tt>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-sorted"></a>
|
||||
<a class="mochidef reference" href="#fn-sorted">sorted(iterable[, cmp])</a>:</p>
|
||||
<blockquote>
|
||||
Return a sorted array from iterable.</blockquote>
|
||||
<p>
|
||||
<a name="fn-sum"></a>
|
||||
<a class="mochidef reference" href="#fn-sum">sum(iterable, start=0)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Returns the sum of a sequence of numbers plus the value
|
||||
of parameter <tt class="docutils literal"><span class="pre">start</span></tt> (with a default of 0). When the sequence is
|
||||
empty, returns start.</p>
|
||||
<p>Equivalent to:</p>
|
||||
<pre class="literal-block">
|
||||
reduce(operator.add, iterable, start);
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-takewhile"></a>
|
||||
<a class="mochidef reference" href="#fn-takewhile">takewhile(pred, seq)</a>:</p>
|
||||
<blockquote>
|
||||
<tt class="docutils literal"><span class="pre">takewhile(pred,</span> <span class="pre">seq)</span></tt> --> seq[0], seq[1], ... until pred(seq[n]) fails</blockquote>
|
||||
<p>
|
||||
<a name="fn-tee"></a>
|
||||
<a class="mochidef reference" href="#fn-tee">tee(iterable, n=2)</a>:</p>
|
||||
<blockquote>
|
||||
<tt class="docutils literal"><span class="pre">tee(it,</span> <span class="pre">n=2)</span></tt> --> [it1, it2, it3, ... itn] splits one iterator into n</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="see-also" name="see-also">See Also</a></h1>
|
||||
<table class="docutils footnote" frame="void" id="id4" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id1" name="id4">[1]</a></td><td>The iteration protocol is described in
|
||||
PEP 234 - Iterators: <a class="reference" href="http://www.python.org/peps/pep-0234.html">http://www.python.org/peps/pep-0234.html</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="id5" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id2" name="id5">[2]</a></td><td>Python's itertools
|
||||
module: <a class="reference" href="http://docs.python.org/lib/module-itertools.html">http://docs.python.org/lib/module-itertools.html</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="id6" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id3" name="id6">[3]</a></td><td>Iteration in JavaScript: <a class="reference" href="http://bob.pythonmac.org/archives/2005/07/06/iteration-in-javascript/">http://bob.pythonmac.org/archives/2005/07/06/iteration-in-javascript/</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="authors" name="authors">Authors</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="copyright" name="copyright">Copyright</a></h1>
|
||||
<p>Copyright 2005 Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>>. This program is dual-licensed
|
||||
free software; you can redistribute it and/or modify it under the terms of the
|
||||
<a class="reference" href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> or the <a class="reference" href="http://www.opensource.org/licenses/afl-2.1.php">Academic Free License v2.1</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,310 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
||||
<title>MochiKit.Logging - we're all tired of alert()</title>
|
||||
|
||||
<link rel="stylesheet" href="../../../include/css/documentation.css" type="text/css" />
|
||||
<script type="text/javascript" src="../../../packed/lib/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="../../js/toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document">
|
||||
<div class="section">
|
||||
<h1><a id="name" name="name">Name</a></h1>
|
||||
<p>MochiKit.Logging - we're all tired of alert()</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="synopsis" name="synopsis">Synopsis</a></h1>
|
||||
<pre class="literal-block">
|
||||
log("INFO messages are so boring");
|
||||
logDebug("DEBUG messages are even worse");
|
||||
log("good thing I can pass", objects, "conveniently");
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="description" name="description">Description</a></h1>
|
||||
<p>MochiKit.Logging steals some ideas from Python's logging module <a class="footnote-reference" href="#id6" id="id1" name="id1">[1]</a>, but
|
||||
completely forgot about the Java <a class="footnote-reference" href="#id7" id="id2" name="id2">[2]</a> inspiration. This is a KISS module for
|
||||
logging that provides enough flexibility to do just about anything via
|
||||
listeners, but without all the cruft.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="dependencies" name="dependencies">Dependencies</a></h1>
|
||||
<ul class="simple">
|
||||
<li><a class="mochiref reference" href="Base.html">MochiKit.Base</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="overview" name="overview">Overview</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="native-console-logging" name="native-console-logging">Native Console Logging</a></h2>
|
||||
<p>As of MochiKit 1.3, the default logger will log all messages to your browser's
|
||||
native console. This is currently supported in Safari, Opera 9, and Firefox
|
||||
when the <a class="reference" href="http://www.joehewitt.com/software/firebug/">FireBug</a> extension is installed.</p>
|
||||
<p>To disable this behavior:</p>
|
||||
<pre class="literal-block">
|
||||
MochiKit.Logging.logger.useNativeLogging = false;
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="bookmarklet-based-debugging" name="bookmarklet-based-debugging">Bookmarklet Based Debugging</a></h2>
|
||||
<p>JavaScript is at a serious disadvantage without a standard console for
|
||||
"print" statements. Everything else has one. The closest thing that
|
||||
you get in a browser environment is the <tt class="docutils literal"><span class="pre">alert</span></tt> function, which is
|
||||
absolutely evil.</p>
|
||||
<p>This leaves you with one reasonable solution: do your logging in the page
|
||||
somehow. The problem here is that you don't want to clutter the page with
|
||||
debugging tools. The solution to that problem is what we call BBD, or
|
||||
Bookmarklet Based Debugging <a class="footnote-reference" href="#id8" id="id4" name="id4">[3]</a>.</p>
|
||||
<p>Simply create a bookmarklet for <a class="reference" href="javascript:MochiKit.Logging.logger.debuggingBookmarklet()">javascript:MochiKit.Logging.logger.debuggingBookmarklet()</a>,
|
||||
and whack it whenever you want to see what's in the logger. Of course, this
|
||||
means you must drink the MochiKit.Logging kool-aid. It's tangy and sweet,
|
||||
don't worry.</p>
|
||||
<p>Currently this is an ugly <tt class="docutils literal"><span class="pre">alert</span></tt>, but we'll have something spiffy
|
||||
Real Soon Now, and when we do, you only have to upgrade MochiKit.Logging,
|
||||
not your bookmarklet!</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="api-reference" name="api-reference">API Reference</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="constructors" name="constructors">Constructors</a></h2>
|
||||
<p>
|
||||
<a name="fn-logmessage"></a>
|
||||
<a class="mochidef reference" href="#fn-logmessage">LogMessage(num, level, info)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Properties:</p>
|
||||
<blockquote>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">num</span></tt>:</dt>
|
||||
<dd>Identifier for the log message</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">level</span></tt>:</dt>
|
||||
<dd>Level of the log message (<tt class="docutils literal"><span class="pre">"INFO"</span></tt>, <tt class="docutils literal"><span class="pre">"WARN"</span></tt>, <tt class="docutils literal"><span class="pre">"DEBUG"</span></tt>,
|
||||
etc.)</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">info</span></tt>:</dt>
|
||||
<dd>All other arguments passed to log function as an <tt class="docutils literal"><span class="pre">Array</span></tt></dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">timestamp</span></tt>:</dt>
|
||||
<dd><tt class="docutils literal"><span class="pre">Date</span></tt> object timestamping the log message</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-logger"></a>
|
||||
<a class="mochidef reference" href="#fn-logger">Logger([maxSize])</a>:</p>
|
||||
<blockquote>
|
||||
<p>A basic logger object that has a buffer of recent messages
|
||||
plus a listener dispatch mechanism for "real-time" logging
|
||||
of important messages.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">maxSize</span></tt> is the maximum number of entries in the log.
|
||||
If <tt class="docutils literal"><span class="pre">maxSize</span> <span class="pre">>=</span> <span class="pre">0</span></tt>, then the log will not buffer more than that
|
||||
many messages. So if you don't like logging at all, be sure to
|
||||
pass <tt class="docutils literal"><span class="pre">0</span></tt>.</p>
|
||||
<p>There is a default logger available named "logger", and several
|
||||
of its methods are also global functions:</p>
|
||||
<blockquote>
|
||||
<tt class="docutils literal"><span class="pre">logger.log</span></tt> -> <tt class="docutils literal"><span class="pre">log</span></tt>
|
||||
<tt class="docutils literal"><span class="pre">logger.debug</span></tt> -> <tt class="docutils literal"><span class="pre">logDebug</span></tt>
|
||||
<tt class="docutils literal"><span class="pre">logger.warning</span></tt> -> <tt class="docutils literal"><span class="pre">logWarning</span></tt>
|
||||
<tt class="docutils literal"><span class="pre">logger.error</span></tt> -> <tt class="docutils literal"><span class="pre">logError</span></tt>
|
||||
<tt class="docutils literal"><span class="pre">logger.fatal</span></tt> -> <tt class="docutils literal"><span class="pre">logFatal</span></tt></blockquote>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-logger.prototype.addlistener"></a>
|
||||
<a class="mochidef reference" href="#fn-logger.prototype.addlistener">Logger.prototype.addListener(ident, filter, listener)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Add a listener for log messages.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">ident</span></tt> is a unique identifier that may be used to remove the listener
|
||||
later on.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">filter</span></tt> can be one of the following:</p>
|
||||
<blockquote>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">null</span></tt>:</dt>
|
||||
<dd><tt class="docutils literal"><span class="pre">listener(msg)</span></tt> will be called for every log message
|
||||
received.</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">string</span></tt>:</dt>
|
||||
<dd><a class="mochiref reference" href="#fn-loglevelatleast">logLevelAtLeast(filter)</a> will be used as the function
|
||||
(see below).</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">function</span></tt>:</dt>
|
||||
<dd><tt class="docutils literal"><span class="pre">filter(msg)</span></tt> will be called for every msg, if it returns
|
||||
true then <tt class="docutils literal"><span class="pre">listener(msg)</span></tt> will be called.</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<p><tt class="docutils literal"><span class="pre">listener</span></tt> is a function that takes one argument, a log message. A log
|
||||
message is an object (<a class="mochiref reference" href="#fn-logmessage">LogMessage</a> instance) that has at least these
|
||||
properties:</p>
|
||||
<blockquote>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">num</span></tt>:</dt>
|
||||
<dd>A counter that uniquely identifies a log message (per-logger)</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">level</span></tt>:</dt>
|
||||
<dd>A string or number representing the log level. If string, you
|
||||
may want to use <tt class="docutils literal"><span class="pre">LogLevel[level]</span></tt> for comparison.</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">info</span></tt>:</dt>
|
||||
<dd>An Array of objects passed as additional arguments to the <tt class="docutils literal"><span class="pre">log</span></tt>
|
||||
function.</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-logger.prototype.baselog"></a>
|
||||
<a class="mochidef reference" href="#fn-logger.prototype.baselog">Logger.prototype.baseLog(level, message[, ...])</a>:</p>
|
||||
<blockquote>
|
||||
<p>The base functionality behind all of the log functions.
|
||||
The first argument is the log level as a string or number,
|
||||
and all other arguments are used as the info list.</p>
|
||||
<p>This function is available partially applied as:</p>
|
||||
<blockquote>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="61%" />
|
||||
<col width="39%" />
|
||||
</colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td>Logger.debug</td>
|
||||
<td>'DEBUG'</td>
|
||||
</tr>
|
||||
<tr><td>Logger.log</td>
|
||||
<td>'INFO'</td>
|
||||
</tr>
|
||||
<tr><td>Logger.error</td>
|
||||
<td>'ERROR'</td>
|
||||
</tr>
|
||||
<tr><td>Logger.fatal</td>
|
||||
<td>'FATAL'</td>
|
||||
</tr>
|
||||
<tr><td>Logger.warning</td>
|
||||
<td>'WARNING'</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</blockquote>
|
||||
<p>For the default logger, these are also available as global functions,
|
||||
see the <a class="mochiref reference" href="#fn-logger">Logger</a> constructor documentation for more info.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-logger.prototype.clear"></a>
|
||||
<a class="mochidef reference" href="#fn-logger.prototype.clear">Logger.prototype.clear()</a>:</p>
|
||||
<blockquote>
|
||||
Clear all messages from the message buffer.</blockquote>
|
||||
<p>
|
||||
<a name="fn-logger.prototype.debuggingbookmarklet"></a>
|
||||
<a class="mochidef reference" href="#fn-logger.prototype.debuggingbookmarklet">Logger.prototype.debuggingBookmarklet()</a>:</p>
|
||||
<blockquote>
|
||||
<p>Display the contents of the logger in a useful way for browsers.</p>
|
||||
<p>Currently, if <a class="mochiref reference" href="LoggingPane.html">MochiKit.LoggingPane</a> is loaded, then a pop-up
|
||||
<a class="mochiref reference" href="LoggingPane.html#fn-loggingpane">MochiKit.LoggingPane.LoggingPane</a> will be used. Otherwise,
|
||||
it will be an alert with <a class="mochiref reference" href="#fn-logger.prototype.getmessagetext">Logger.prototype.getMessageText()</a>.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-logger.prototype.dispatchlisteners"></a>
|
||||
<a class="mochidef reference" href="#fn-logger.prototype.dispatchlisteners">Logger.prototype.dispatchListeners(msg)</a>:</p>
|
||||
<blockquote>
|
||||
Dispatch a log message to all listeners.</blockquote>
|
||||
<p>
|
||||
<a name="fn-logger.prototype.getmessages"></a>
|
||||
<a class="mochidef reference" href="#fn-logger.prototype.getmessages">Logger.prototype.getMessages(howMany)</a>:</p>
|
||||
<blockquote>
|
||||
Return a list of up to <tt class="docutils literal"><span class="pre">howMany</span></tt> messages from the message buffer.</blockquote>
|
||||
<p>
|
||||
<a name="fn-logger.prototype.getmessagetext"></a>
|
||||
<a class="mochidef reference" href="#fn-logger.prototype.getmessagetext">Logger.prototype.getMessageText(howMany)</a>:</p>
|
||||
<blockquote>
|
||||
<p>Get a string representing up to the last <tt class="docutils literal"><span class="pre">howMany</span></tt> messages in the
|
||||
message buffer. The default is <tt class="docutils literal"><span class="pre">30</span></tt>.</p>
|
||||
<p>The message looks like this:</p>
|
||||
<pre class="literal-block">
|
||||
LAST {messages.length} MESSAGES:
|
||||
[{msg.num}] {msg.level}: {m.info.join(' ')}
|
||||
[{msg.num}] {msg.level}: {m.info.join(' ')}
|
||||
...
|
||||
</pre>
|
||||
<p>If you want some other format, use
|
||||
<a class="mochiref reference" href="#fn-logger.prototype.getmessages">Logger.prototype.getMessages</a> and do it yourself.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-logger.prototype.removelistener"></a>
|
||||
<a class="mochidef reference" href="#fn-logger.prototype.removelistener">Logger.prototype.removeListener(ident)</a>:</p>
|
||||
<blockquote>
|
||||
Remove a listener using the ident given to <a class="mochiref reference" href="#fn-logger.prototype.addlistener">Logger.prototype.addListener</a></blockquote>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="functions" name="functions">Functions</a></h2>
|
||||
<p>
|
||||
<a name="fn-alertlistener"></a>
|
||||
<a class="mochidef reference" href="#fn-alertlistener">alertListener(msg)</a>:</p>
|
||||
<blockquote>
|
||||
Ultra-obnoxious <tt class="docutils literal"><span class="pre">alert(...)</span></tt> listener</blockquote>
|
||||
<p>
|
||||
<a name="fn-logdebug"></a>
|
||||
<a class="mochidef reference" href="#fn-logdebug">logDebug(message[, info[, ...]])</a>:</p>
|
||||
<blockquote>
|
||||
Log an INFO message to the default logger</blockquote>
|
||||
<p>
|
||||
<a name="fn-logdebug"></a>
|
||||
<a class="mochidef reference" href="#fn-logdebug">logDebug(message[, info[, ...]])</a>:</p>
|
||||
<blockquote>
|
||||
Log a DEBUG message to the default logger</blockquote>
|
||||
<p>
|
||||
<a name="fn-logerror"></a>
|
||||
<a class="mochidef reference" href="#fn-logerror">logError(message[, info[, ...]])</a>:</p>
|
||||
<blockquote>
|
||||
Log an ERROR message to the default logger</blockquote>
|
||||
<p>
|
||||
<a name="fn-logfatal"></a>
|
||||
<a class="mochidef reference" href="#fn-logfatal">logFatal(message[, info[, ...]])</a>:</p>
|
||||
<blockquote>
|
||||
Log a FATAL message to the default logger</blockquote>
|
||||
<p>
|
||||
<a name="fn-loglevelatleast"></a>
|
||||
<a class="mochidef reference" href="#fn-loglevelatleast">logLevelAtLeast(minLevel)</a>:</p>
|
||||
<blockquote>
|
||||
Return a function that will match log messages whose level
|
||||
is at least minLevel</blockquote>
|
||||
<p>
|
||||
<a name="fn-logwarning"></a>
|
||||
<a class="mochidef reference" href="#fn-logwarning">logWarning(message[, info[, ...]])</a>:</p>
|
||||
<blockquote>
|
||||
Log a WARNING message to the default logger</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="see-also" name="see-also">See Also</a></h1>
|
||||
<table class="docutils footnote" frame="void" id="id6" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id1" name="id6">[1]</a></td><td>Python's logging module: <a class="reference" href="http://docs.python.org/lib/module-logging.html">http://docs.python.org/lib/module-logging.html</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="id7" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id2" name="id7">[2]</a></td><td>PEP 282, where they admit all of the Java influence: <a class="reference" href="http://www.python.org/peps/pep-0282.html">http://www.python.org/peps/pep-0282.html</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="id8" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id4" name="id8">[3]</a></td><td>Original Bookmarklet Based Debugging blather: <a class="reference" href="http://bob.pythonmac.org/archives/2005/07/03/bookmarklet-based-debugging/">http://bob.pythonmac.org/archives/2005/07/03/bookmarklet-based-debugging/</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="authors" name="authors">Authors</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="copyright" name="copyright">Copyright</a></h1>
|
||||
<p>Copyright 2005 Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>>. This program is dual-licensed
|
||||
free software; you can redistribute it and/or modify it under the terms of the
|
||||
<a class="reference" href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> or the <a class="reference" href="http://www.opensource.org/licenses/afl-2.1.php">Academic Free License v2.1</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,121 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
||||
<title>MochiKit.LoggingPane - Interactive MochiKit.Logging pane</title>
|
||||
|
||||
<link rel="stylesheet" href="../../../include/css/documentation.css" type="text/css" />
|
||||
<script type="text/javascript" src="../../../packed/lib/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="../../js/toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document">
|
||||
<div class="section">
|
||||
<h1><a id="name" name="name">Name</a></h1>
|
||||
<p>MochiKit.LoggingPane - Interactive MochiKit.Logging pane</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="synopsis" name="synopsis">Synopsis</a></h1>
|
||||
<pre class="literal-block">
|
||||
// open a pop-up window
|
||||
createLoggingPane()
|
||||
// use a div at the bottom of the document
|
||||
createLoggingPane(true);
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="description" name="description">Description</a></h1>
|
||||
<p>MochiKit.Logging does not have any browser dependencies and is completely
|
||||
unobtrusive. MochiKit.LoggingPane is a browser-based colored viewing pane
|
||||
for your <a class="mochiref reference" href="Logging.html">MochiKit.Logging</a> output that can be used as a pop-up or
|
||||
inline.</p>
|
||||
<p>It also allows for regex and level filtering! MochiKit.LoggingPane is used
|
||||
as the default <a class="mochiref reference" href="Logging.html#fn-debuggingbookmarklet">MochiKit.Logging.debuggingBookmarklet()</a> if it is
|
||||
loaded.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="dependencies" name="dependencies">Dependencies</a></h1>
|
||||
<ul class="simple">
|
||||
<li><a class="mochiref reference" href="Base.html">MochiKit.Base</a></li>
|
||||
<li><a class="mochiref reference" href="Logging.html">MochiKit.Logging</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="api-reference" name="api-reference">API Reference</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="constructors" name="constructors">Constructors</a></h2>
|
||||
<p>
|
||||
<a name="fn-loggingpane"></a>
|
||||
<a class="mochidef reference" href="#fn-loggingpane">LoggingPane(inline=false, logger=MochiKit.Logging.logger)</a>:</p>
|
||||
<blockquote>
|
||||
<p>A listener for a <a class="mochiref reference" href="Logging.html">MochiKit.Logging</a> logger with an interactive
|
||||
DOM representation.</p>
|
||||
<p>If <tt class="docutils literal"><span class="pre">inline</span></tt> is <tt class="docutils literal"><span class="pre">true</span></tt>, then the <tt class="docutils literal"><span class="pre">LoggingPane</span></tt> will be a <tt class="docutils literal"><span class="pre">DIV</span></tt>
|
||||
at the bottom of the document. Otherwise, it will be in a pop-up
|
||||
window with a name based on the calling page's URL. If there is an
|
||||
element in the document with an id of <tt class="docutils literal"><span class="pre">_MochiKit_LoggingPane</span></tt>,
|
||||
it will be used instead of appending a new <tt class="docutils literal"><span class="pre">DIV</span></tt> to the body.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">logger</span></tt> is the reference to the <a class="mochiref reference" href="Logging.html#fn-logger">MochiKit.Logging.Logger</a> to
|
||||
listen to. If not specified, the global default logger is used.</p>
|
||||
<p>Properties:</p>
|
||||
<blockquote>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">win</span></tt>:</dt>
|
||||
<dd>Reference to the pop-up window (<tt class="docutils literal"><span class="pre">undefined</span></tt> if <tt class="docutils literal"><span class="pre">inline</span></tt>)</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">inline</span></tt>:</dt>
|
||||
<dd><tt class="docutils literal"><span class="pre">true</span></tt> if the <tt class="docutils literal"><span class="pre">LoggingPane</span></tt> is inline</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">colorTable</span></tt>:</dt>
|
||||
<dd><p class="first">An object with property->value mappings for each log level
|
||||
and its color. May also be mutated on <tt class="docutils literal"><span class="pre">LoggingPane.prototype</span></tt>
|
||||
to affect all instances. For example:</p>
|
||||
<pre class="last literal-block">
|
||||
MochiKit.LoggingPane.LoggingPane.prototype.colorTable = {
|
||||
DEBUG: "green",
|
||||
INFO: "black",
|
||||
WARNING: "blue",
|
||||
ERROR: "red",
|
||||
FATAL: "darkred"
|
||||
};
|
||||
</pre>
|
||||
</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-loggingpane.prototype.closepane"></a>
|
||||
<a class="mochidef reference" href="#fn-loggingpane.prototype.closepane">LoggingPane.prototype.closePane()</a>:</p>
|
||||
<blockquote>
|
||||
Close the <a class="mochiref reference" href="#fn-loggingpane">LoggingPane</a> (close the child window, or
|
||||
remove the <tt class="docutils literal"><span class="pre">_MochiKit_LoggingPane</span></tt> <tt class="docutils literal"><span class="pre">DIV</span></tt> from the document).</blockquote>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="functions" name="functions">Functions</a></h2>
|
||||
<p>
|
||||
<a name="fn-createloggingpane"></a>
|
||||
<a class="mochidef reference" href="#fn-createloggingpane">createLoggingPane(inline=false)</a>:</p>
|
||||
<blockquote>
|
||||
Create or return an existing <a class="mochiref reference" href="#fn-loggingpane">LoggingPane</a> for this document
|
||||
with the given inline setting. This is preferred over using
|
||||
<a class="mochiref reference" href="#fn-loggingpane">LoggingPane</a> directly, as only one <a class="mochiref reference" href="#fn-loggingpane">LoggingPane</a>
|
||||
should be present in a given document.</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="authors" name="authors">Authors</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="copyright" name="copyright">Copyright</a></h1>
|
||||
<p>Copyright 2005 Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>>. This program is dual-licensed
|
||||
free software; you can redistribute it and/or modify it under the terms of the
|
||||
<a class="reference" href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> or the <a class="reference" href="http://www.opensource.org/licenses/afl-2.1.php">Academic Free License v2.1</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,331 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
||||
<title>MochiKit.Signal - Simple universal event handling</title>
|
||||
|
||||
<link rel="stylesheet" href="../../../include/css/documentation.css" type="text/css" />
|
||||
<script type="text/javascript" src="../../../packed/lib/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="../../js/toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document">
|
||||
<div class="section">
|
||||
<h1><a id="name" name="name">Name</a></h1>
|
||||
<p>MochiKit.Signal - Simple universal event handling</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="synopsis" name="synopsis">Synopsis</a></h1>
|
||||
<p>Signal for DOM events:</p>
|
||||
<pre class="literal-block">
|
||||
// DOM events are also signals. Connect freely! The functions will be
|
||||
// called with the custom event as a parameter.
|
||||
|
||||
// calls myClicked.apply(getElement('myID'), event)
|
||||
connect('myID', 'onclick', myClicked);
|
||||
|
||||
// calls wasClicked.apply(myObject, event)
|
||||
connect('myID', 'onclick', myObject, wasClicked);
|
||||
|
||||
// calls myObject.wasClicked(event)
|
||||
connect('myID', 'onclick', myObject, 'wasClicked');
|
||||
|
||||
// the event is normalized, no more e = e || window.event!
|
||||
myObject.wasClicked = function(e) {
|
||||
var crossBrowserCoordinates = e.mouse().page;
|
||||
// e.mouse().page is a MochiKit.DOM.Coordinates object
|
||||
}
|
||||
</pre>
|
||||
<p>Signal for non-DOM events:</p>
|
||||
<pre class="literal-block">
|
||||
// otherObject.gotFlash() will be called when 'flash' signalled.
|
||||
connect(myObject, 'flash', otherObject, 'gotFlash');
|
||||
|
||||
// gotBang.apply(otherObject) will be called when 'bang' signalled.
|
||||
// You can access otherObject from within gotBang as 'this'.
|
||||
connect(myObject, 'bang', otherObject, gotBang);
|
||||
|
||||
// myFunc.apply(myObject) will be called when 'flash' signalled.
|
||||
// You can access myObject from within myFunc as 'this'.
|
||||
var ident = connect(myObject, 'flash', myFunc);
|
||||
|
||||
// You may disconnect with the return value from connect
|
||||
disconnect(ident);
|
||||
|
||||
// Signal can take parameters. These will be passed along to the connected
|
||||
// functions.
|
||||
signal(myObject, 'flash');
|
||||
signal(myObject, 'bang', 'BANG!');
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="description" name="description">Description</a></h1>
|
||||
<p>Event handling was never so easy!</p>
|
||||
<p>This module takes care of all the hard work—figuring out which event
|
||||
model to use, trying to retrieve the event object, and handling your own
|
||||
internal events, as well as cleanup when the page is unloaded to clean up IE's
|
||||
nasty memory leakage.</p>
|
||||
<p>This event system is largely based on Qt's signal/slot system. Read more on
|
||||
how that is handled and also how it is used in model/view programming at:
|
||||
<a class="reference" href="http://doc.trolltech.com/">http://doc.trolltech.com/</a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="dependencies" name="dependencies">Dependencies</a></h1>
|
||||
<ul class="simple">
|
||||
<li><a class="mochiref reference" href="Base.html">MochiKit.Base</a></li>
|
||||
<li><a class="mochiref reference" href="DOM.html">MochiKit.DOM</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="overview" name="overview">Overview</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="using-signal-for-dom-events" name="using-signal-for-dom-events">Using Signal for DOM Events</a></h2>
|
||||
<p>When using MochiKit.Signal, do not use the browser's native event API. That
|
||||
means, no <tt class="docutils literal"><span class="pre">onclick="blah"</span></tt>, no <tt class="docutils literal"><span class="pre">elem.addEventListener(...)</span></tt>, and certainly
|
||||
no <tt class="docutils literal"><span class="pre">elem.attachEvent(...)</span></tt>. This also means that
|
||||
<a class="mochiref reference" href="DOM.html#fn-addtocallstack">MochiKit.DOM.addToCallStack</a> and
|
||||
<a class="mochiref reference" href="DOM.html#fn-addloadevent">MochiKit.DOM.addLoadEvent</a> should not be used in combination with
|
||||
this module.</p>
|
||||
<p>Signals for DOM objects are named with the <tt class="docutils literal"><span class="pre">'on'</span></tt> prefix, e.g.:
|
||||
<tt class="docutils literal"><span class="pre">'onclick'</span></tt>, <tt class="docutils literal"><span class="pre">'onkeyup'</span></tt>, etc.</p>
|
||||
<p>When the signal fires, your slot will be called with one parameter, the custom
|
||||
event object.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="custom-event-objects-for-dom-events" name="custom-event-objects-for-dom-events">Custom Event Objects for DOM events</a></h2>
|
||||
<p>Signals triggered by DOM events are called with a custom event object as a
|
||||
parameter. The custom event object presents a consistent view of the event
|
||||
across all supported platforms and browsers, and provides many conveniences
|
||||
not available even in a correct W3C implementation.</p>
|
||||
<p>See the <a class="reference" href="#dom-custom-event-object-reference">DOM Custom Event Object Reference</a> for a detailed API description
|
||||
of this object.</p>
|
||||
<p>If you find that you're accessing the native event for any reason, create a
|
||||
<a class="reference" href="http://trac.mochikit.com/newticket">new ticket</a> and we'll look into normalizing the behavior you're looking for.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="memory-usage" name="memory-usage">Memory Usage</a></h2>
|
||||
<p>Any object that has connected slots (via <a class="mochiref reference" href="#fn-connect">connect()</a>) is referenced
|
||||
by the Signal mechanism until it is disconnected via <a class="mochiref reference" href="#fn-disconnect">disconnect()</a>
|
||||
or <a class="mochiref reference" href="#fn-disconnectall">disconnectAll()</a>.</p>
|
||||
<p>Signal does not leak. It registers an <tt class="docutils literal"><span class="pre">'onunload'</span></tt> event that disconnects all
|
||||
objects on the page when the browser leaves the page. However, memory usage
|
||||
will grow during the page view for every connection made until it is
|
||||
disconnected. Even if the DOM object is removed from the document, it
|
||||
will still be referenced by Signal until it is explicitly disconnected.</p>
|
||||
<p>In order to conserve memory during the page view, <a class="mochiref reference" href="#fn-disconnectall">disconnectAll()</a>
|
||||
any DOM elements that are about to be removed from the document.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="using-signal-for-non-dom-objects" name="using-signal-for-non-dom-objects">Using Signal for non-DOM objects</a></h2>
|
||||
<p>Signals are triggered with the <a class="mochiref reference" href="#fn-signal">signal(src, 'signal', ...)</a>
|
||||
function. Additional parameters passed to this are passed onto the
|
||||
connected slots. Explicit signals are not required for DOM events.</p>
|
||||
<p>Slots that are connected to a signal are called in the following manner
|
||||
when that signal is signalled:</p>
|
||||
<ul class="simple">
|
||||
<li>If the slot was a single function, then it is called with <tt class="docutils literal"><span class="pre">this</span></tt> set
|
||||
to the object originating the signal with whatever parameters it was
|
||||
signalled with.</li>
|
||||
<li>If the slot was an object and a function, then it is called with
|
||||
<tt class="docutils literal"><span class="pre">this</span></tt> set to the object, and with whatever parameters it was
|
||||
signalled with.</li>
|
||||
<li>If the slot was an object and a string, then <tt class="docutils literal"><span class="pre">object[string]</span></tt> is
|
||||
called with the parameters to the signal.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="api-reference" name="api-reference">API Reference</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="signal-api-reference" name="signal-api-reference">Signal API Reference</a></h2>
|
||||
<p>
|
||||
<a name="fn-connect"></a>
|
||||
<a class="mochidef reference" href="#fn-connect">connect(src, signal, dest[, func])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Connects a signal to a slot, and return a unique identifier that can be
|
||||
used to disconnect that signal.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">src</span></tt> is the object that has the signal. You may pass in a string, in
|
||||
which case, it is interpreted as an id for an HTML element.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">signal</span></tt> is a string that represents a signal name. If 'src' is an HTML
|
||||
Element, <tt class="docutils literal"><span class="pre">window</span></tt>, or the <tt class="docutils literal"><span class="pre">document</span></tt>, then it can be one of the
|
||||
'on-XYZ' events. You must include the 'on' prefix, and it must be all
|
||||
lower-case.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">dest</span></tt> and <tt class="docutils literal"><span class="pre">func</span></tt> describe the slot, or the action to take when the
|
||||
signal is triggered.</p>
|
||||
<blockquote>
|
||||
<ul class="simple">
|
||||
<li>If <tt class="docutils literal"><span class="pre">dest</span></tt> is an object and <tt class="docutils literal"><span class="pre">func</span></tt> is a string, then
|
||||
<tt class="docutils literal"><span class="pre">dest[func].apply(dest,</span> <span class="pre">...)</span></tt> will be called when the signal
|
||||
is signalled.</li>
|
||||
<li>If <tt class="docutils literal"><span class="pre">dest</span></tt> is an object and <tt class="docutils literal"><span class="pre">func</span></tt> is a function, then
|
||||
<tt class="docutils literal"><span class="pre">func.apply(dest,</span> <span class="pre">...)</span></tt> will be called when the signal is
|
||||
signalled.</li>
|
||||
<li>If <tt class="docutils literal"><span class="pre">func</span></tt> is undefined and <tt class="docutils literal"><span class="pre">dest</span></tt> is a function, then
|
||||
<tt class="docutils literal"><span class="pre">func.apply(src,</span> <span class="pre">...)</span></tt> will be called when the signal is
|
||||
signalled.</li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
<p>No other combinations are allowed and will raise an exception.</p>
|
||||
<p>The return value can be passed to <a class="mochiref reference" href="#fn-disconnect">disconnect</a> to disconnect
|
||||
the signal.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-disconnect"></a>
|
||||
<a class="mochidef reference" href="#fn-disconnect">disconnect(ident)</a>:</p>
|
||||
<blockquote>
|
||||
To disconnect a signal, pass its ident returned by <a class="mochiref reference" href="#fn-connect">connect()</a>.
|
||||
This is similar to how the browser's <tt class="docutils literal"><span class="pre">setTimeout</span></tt> and <tt class="docutils literal"><span class="pre">clearTimeout</span></tt>
|
||||
works.</blockquote>
|
||||
<p>
|
||||
<a name="fn-disconnectall"></a>
|
||||
<a class="mochidef reference" href="#fn-disconnectall">disconnectAll(src[, signal, ...])</a>:</p>
|
||||
<blockquote>
|
||||
<p><tt class="docutils literal"><span class="pre">disconnectAll(src)</span></tt> removes all signals from src.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">disconnectAll(src,</span> <span class="pre">'onmousedown',</span> <span class="pre">'mySignal')</span></tt> will remove all
|
||||
<tt class="docutils literal"><span class="pre">'onmousedown'</span></tt> and <tt class="docutils literal"><span class="pre">'mySignal'</span></tt> signals from src.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-signal"></a>
|
||||
<a class="mochidef reference" href="#fn-signal">signal(src, signal, ...)</a>:</p>
|
||||
<blockquote>
|
||||
This will signal a signal, passing whatever additional parameters on to
|
||||
the connected slots. <tt class="docutils literal"><span class="pre">src</span></tt> and <tt class="docutils literal"><span class="pre">signal</span></tt> are the same as for
|
||||
<a class="mochiref reference" href="#fn-connect">connect()</a>.</blockquote>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a id="dom-custom-event-object-reference" name="dom-custom-event-object-reference">DOM Custom Event Object Reference</a></h2>
|
||||
<p>
|
||||
<a name="fn-event"></a>
|
||||
<a class="mochidef reference" href="#fn-event">event()</a>:</p>
|
||||
<blockquote>
|
||||
The native event produced by the browser. You should not need to use this.</blockquote>
|
||||
<p>
|
||||
<a name="fn-src"></a>
|
||||
<a class="mochidef reference" href="#fn-src">src()</a>:</p>
|
||||
<blockquote>
|
||||
The element that this signal is connected to.</blockquote>
|
||||
<p>
|
||||
<a name="fn-type"></a>
|
||||
<a class="mochidef reference" href="#fn-type">type()</a>:</p>
|
||||
<blockquote>
|
||||
The event type (<tt class="docutils literal"><span class="pre">'click'</span></tt>, <tt class="docutils literal"><span class="pre">'mouseover'</span></tt>, <tt class="docutils literal"><span class="pre">'keypress'</span></tt>, etc.) as a
|
||||
string. Does not include the <tt class="docutils literal"><span class="pre">'on'</span></tt> prefix.</blockquote>
|
||||
<p>
|
||||
<a name="fn-target"></a>
|
||||
<a class="mochidef reference" href="#fn-target">target()</a>:</p>
|
||||
<blockquote>
|
||||
The element that triggered the event. This may be a child of
|
||||
<a class="mochiref reference" href="#fn-src">src()</a>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-modifier"></a>
|
||||
<a class="mochidef reference" href="#fn-modifier">modifier()</a>:</p>
|
||||
<blockquote>
|
||||
Returns <tt class="docutils literal"><span class="pre">{shift,</span> <span class="pre">ctrl,</span> <span class="pre">meta,</span> <span class="pre">alt,</span> <span class="pre">any}</span></tt>, where each property is <tt class="docutils literal"><span class="pre">true</span></tt>
|
||||
if its respective modifier key was pressed, <tt class="docutils literal"><span class="pre">false</span></tt> otherwise. <tt class="docutils literal"><span class="pre">any</span></tt>
|
||||
is <tt class="docutils literal"><span class="pre">true</span></tt> if any modifier is pressed, <tt class="docutils literal"><span class="pre">false</span></tt> otherwise.</blockquote>
|
||||
<p>
|
||||
<a name="fn-stoppropagation"></a>
|
||||
<a class="mochidef reference" href="#fn-stoppropagation">stopPropagation()</a>:</p>
|
||||
<blockquote>
|
||||
Works like W3C's <tt class="docutils literal"><span class="pre">stopPropagation()</span></tt>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-preventdefault"></a>
|
||||
<a class="mochidef reference" href="#fn-preventdefault">preventDefault()</a>:</p>
|
||||
<blockquote>
|
||||
Works like W3C's <tt class="docutils literal"><span class="pre">preventDefault()</span></tt>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-stop"></a>
|
||||
<a class="mochidef reference" href="#fn-stop">stop()</a>:</p>
|
||||
<blockquote>
|
||||
Shortcut that calls <tt class="docutils literal"><span class="pre">stopPropagation()</span></tt> and <tt class="docutils literal"><span class="pre">preventDefault()</span></tt>.</blockquote>
|
||||
<p>
|
||||
<a name="fn-key"></a>
|
||||
<a class="mochidef reference" href="#fn-key">key()</a>:</p>
|
||||
<blockquote>
|
||||
<p>Returns <tt class="docutils literal"><span class="pre">{code,</span> <span class="pre">string}</span></tt>.</p>
|
||||
<p>Use <tt class="docutils literal"><span class="pre">'onkeydown'</span></tt> and <tt class="docutils literal"><span class="pre">'onkeyup'</span></tt> handlers to detect control
|
||||
characters such as <tt class="docutils literal"><span class="pre">'KEY_F1'</span></tt>. Use the <tt class="docutils literal"><span class="pre">'onkeypressed'</span></tt> handler to
|
||||
detect "printable" characters, such as <tt class="docutils literal"><span class="pre">'é'</span></tt>.</p>
|
||||
<p>When a user presses F1, in <tt class="docutils literal"><span class="pre">'onkeydown'</span></tt> and <tt class="docutils literal"><span class="pre">'onkeyup'</span></tt> this method
|
||||
returns <tt class="docutils literal"><span class="pre">{code:</span> <span class="pre">122,</span> <span class="pre">string:</span> <span class="pre">'KEY_F1'}</span></tt>. In <tt class="docutils literal"><span class="pre">'onkeypress'</span></tt>, it returns
|
||||
<tt class="docutils literal"><span class="pre">{code:</span> <span class="pre">0,</span> <span class="pre">string:</span> <span class="pre">''}</span></tt>.</p>
|
||||
<p>If a user presses Shift+2 on a US keyboard, this method returns
|
||||
<tt class="docutils literal"><span class="pre">{code:</span> <span class="pre">50,</span> <span class="pre">string:</span> <span class="pre">'KEY_2'}</span></tt> in <tt class="docutils literal"><span class="pre">'onkeydown'</span></tt> and <tt class="docutils literal"><span class="pre">'onkeyup'</span></tt>.
|
||||
In <tt class="docutils literal"><span class="pre">'onkeypress'</span></tt>, it returns <tt class="docutils literal"><span class="pre">{code:</span> <span class="pre">64,</span> <span class="pre">string:</span> <span class="pre">'@'}</span></tt>.</p>
|
||||
<p>See <tt class="docutils literal"><span class="pre">_specialKeys</span></tt> in the source code for a comprehensive list of
|
||||
control characters.</p>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-mouse"></a>
|
||||
<a class="mochidef reference" href="#fn-mouse">mouse()</a>:</p>
|
||||
<blockquote>
|
||||
<p>Properties for <tt class="docutils literal"><span class="pre">'onmouse*'</span></tt>, <tt class="docutils literal"><span class="pre">'onclick'</span></tt>, <tt class="docutils literal"><span class="pre">'ondblclick'</span></tt>, and
|
||||
<tt class="docutils literal"><span class="pre">'oncontextmenu'</span></tt>:</p>
|
||||
<blockquote>
|
||||
<ul class="simple">
|
||||
<li><tt class="docutils literal"><span class="pre">page</span></tt> is a <a class="mochiref reference" href="DOM.html#fn-coordinates">MochiKit.DOM.Coordinates</a> object that
|
||||
represents the cursor position relative to the HTML document.
|
||||
Equivalent to <tt class="docutils literal"><span class="pre">pageX</span></tt> and <tt class="docutils literal"><span class="pre">pageY</span></tt> in Safari, Mozilla, and
|
||||
Opera.</li>
|
||||
<li><tt class="docutils literal"><span class="pre">client</span></tt> is a <a class="mochiref reference" href="DOM.html#fn-coordinates">MochiKit.DOM.Coordinates</a> object that
|
||||
represents the cursor position relative to the visible portion of
|
||||
the HTML document. Equivalent to <tt class="docutils literal"><span class="pre">clientX</span></tt> and <tt class="docutils literal"><span class="pre">clientY</span></tt> on
|
||||
all browsers.</li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
<p>Properties for <tt class="docutils literal"><span class="pre">'onmouseup'</span></tt>, <tt class="docutils literal"><span class="pre">'onmousedown'</span></tt>, <tt class="docutils literal"><span class="pre">'onclick'</span></tt>, and
|
||||
<tt class="docutils literal"><span class="pre">'ondblclick'</span></tt>:</p>
|
||||
<blockquote>
|
||||
<ul class="simple">
|
||||
<li><tt class="docutils literal"><span class="pre">mouse().button</span></tt> returns <tt class="docutils literal"><span class="pre">{left,</span> <span class="pre">right,</span> <span class="pre">middle}</span></tt> where each
|
||||
property is <tt class="docutils literal"><span class="pre">true</span></tt> if the mouse button was pressed, <tt class="docutils literal"><span class="pre">false</span></tt>
|
||||
otherwise.</li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
<p>Known browser bugs:</p>
|
||||
<blockquote>
|
||||
<ul>
|
||||
<li><p class="first">Current versions of Safari won't signal <tt class="docutils literal"><span class="pre">'ondblclick'</span></tt> when
|
||||
attached via <tt class="docutils literal"><span class="pre">connect()</span></tt> (<a class="reference" href="http://bugzilla.opendarwin.org/show_bug.cgi?id=7790">Safari Bug 7790</a>).</p>
|
||||
</li>
|
||||
<li><p class="first">Mac browsers don't report right-click consistently. Firefox
|
||||
signals the slot and sets <tt class="docutils literal"><span class="pre">modifier().ctrl</span></tt> to true, Opera
|
||||
signals the slot and sets <tt class="docutils literal"><span class="pre">modifier().meta</span></tt> to <tt class="docutils literal"><span class="pre">true</span></tt>, and
|
||||
Safari doesn't signal the slot at all (<a class="reference" href="http://bugzilla.opendarwin.org/show_bug.cgi?id=6595">Safari Bug 6595</a>).</p>
|
||||
<p>To find a right-click in Safari, Firefox, and IE, you can connect
|
||||
an element to <tt class="docutils literal"><span class="pre">'oncontextmenu'</span></tt>. This doesn't work in Opera.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<p>
|
||||
<a name="fn-relatedtarget"></a>
|
||||
<a class="mochidef reference" href="#fn-relatedtarget">relatedTarget()</a>:</p>
|
||||
<blockquote>
|
||||
Returns the document element that the mouse has moved to. This is
|
||||
generated for <tt class="docutils literal"><span class="pre">'onmouseover'</span></tt> and <tt class="docutils literal"><span class="pre">'onmouseout'</span></tt> events.</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="authors" name="authors">Authors</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Jonathan Gardner <<a class="reference" href="mailto:jgardner@jonathangardner.net">jgardner@jonathangardner.net</a>></li>
|
||||
<li>Beau Hartshorne <<a class="reference" href="mailto:beau@hartshornesoftware.com">beau@hartshornesoftware.com</a>></li>
|
||||
<li>Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="copyright" name="copyright">Copyright</a></h1>
|
||||
<p>Copyright 2006 Jonathan Gardner <<a class="reference" href="mailto:jgardner@jonathangardner.net">jgardner@jonathangardner.net</a>>, Beau
|
||||
Hartshorne <<a class="reference" href="mailto:beau@hartshornesoftware.com">beau@hartshornesoftware.com</a>>, and Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>>.
|
||||
This program is dual-licensed free software; you can redistribute it and/or
|
||||
modify it under the terms of the <a class="reference" href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> or the
|
||||
<a class="reference" href="http://www.opensource.org/licenses/afl-2.1.php">Academic Free License v2.1</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,264 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
||||
<title></title>
|
||||
|
||||
<link rel="stylesheet" href="../../../include/css/documentation.css" type="text/css" />
|
||||
<script type="text/javascript" src="../../../packed/lib/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="../../js/toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document">
|
||||
<p>2006-04-29 v1.3.1 (bug fix release)</p>
|
||||
<ul class="simple">
|
||||
<li>Fix sendXMLHttpRequest sendContent regression</li>
|
||||
<li>Internet Explorer fix in MochiKit.Logging (printfire exception)</li>
|
||||
<li>Internet Explorer XMLHttpRequest object leak fixed in MochiKit.Async</li>
|
||||
</ul>
|
||||
<p>2006-04-26 v1.3 "warp zone"</p>
|
||||
<ul class="simple">
|
||||
<li>IMPORTANT: Renamed MochiKit.Base.forward to forwardCall (for export)</li>
|
||||
<li>IMPORTANT: Renamed MochiKit.Base.find to findValue (for export)</li>
|
||||
<li>New MochiKit.Base.method as a convenience form of bind that takes the
|
||||
object before the method</li>
|
||||
<li>New MochiKit.Base.flattenArguments for flattening a list of arguments to
|
||||
a single Array</li>
|
||||
<li>Refactored MochiRegExp example to use MochiKit.Signal</li>
|
||||
<li>New key_events example demonstrating use of MochiKit.Signal's key handling
|
||||
capabilities.</li>
|
||||
<li>MochiKit.DOM.createDOM API change for convenience: if attrs is a string,
|
||||
null is used and the string will be considered the first node. This
|
||||
allows for the more natural P("foo") rather than P(null, "foo").</li>
|
||||
<li>MochiKit Interpreter example refactored to use MochiKit.Signal and now
|
||||
provides multi-line input and a help() function to get MochiKit function
|
||||
signature from the documentation.</li>
|
||||
<li>Native Console Logging for the default MochiKit.Logging logger</li>
|
||||
<li>New MochiKit.Async.DeferredList, gatherResults, maybeDeferred</li>
|
||||
<li>New MochiKit.Signal example: draggable</li>
|
||||
<li>Added sanity checking to Deferred to ensure that errors happen when chaining
|
||||
is used incorrectly</li>
|
||||
<li>Opera sendXMLHttpRequest fix (sends empty string instead of null by default)</li>
|
||||
<li>Fix a bug in MochiKit.Color that incorrectly generated hex colors for
|
||||
component values smaller than 16/255.</li>
|
||||
<li>Fix a bug in MochiKit.Logging that prevented logs from being capped at a
|
||||
maximum size</li>
|
||||
<li>MochiKit.Async.Deferred will now wrap thrown objects that are not instanceof
|
||||
Error, so that the errback chain is used instead of the callback chain.</li>
|
||||
<li>MochiKit.DOM.appendChildNodes and associated functions now append iterables
|
||||
in the correct order.</li>
|
||||
<li>New MochiKit-based SimpleTest test runner as a replacement for Test.Simple</li>
|
||||
<li>MochiKit.Base.isNull no longer matches undefined</li>
|
||||
<li>example doctypes changed to HTML4</li>
|
||||
<li>isDateLike no longer throws error on null</li>
|
||||
<li>New MochiKit.Signal module, modeled after the slot/signal mechanism in Qt</li>
|
||||
<li>updated elementDimensions to calculate width from offsetWidth instead
|
||||
of clientWidth</li>
|
||||
<li>formContents now works with FORM tags that have a name attribute</li>
|
||||
<li>Documentation now uses MochiKit to generate a function index</li>
|
||||
</ul>
|
||||
<p>2006-01-26 v1.2 "the ocho"</p>
|
||||
<ul class="simple">
|
||||
<li>Fixed MochiKit.Color.Color.lighterColorWithLevel</li>
|
||||
<li>Added new MochiKit.Base.findIdentical function to find the index of an
|
||||
element in an Array-like object. Uses === for identity comparison.</li>
|
||||
<li>Added new MochiKit.Base.find function to find the index of an element in
|
||||
an Array-like object. Uses compare for rich comparison.</li>
|
||||
<li>MochiKit.Base.bind will accept a string for func, which will be immediately
|
||||
looked up as self[func].</li>
|
||||
<li>MochiKit.DOM.formContents no longer skips empty form elements for Zope
|
||||
compatibility</li>
|
||||
<li>MochiKit.Iter.forEach will now catch StopIteration to break</li>
|
||||
<li>New MochiKit.DOM.elementDimensions(element) for determining the width and
|
||||
height of an element in the document</li>
|
||||
<li>MochiKit.DOM's initialization is now compatible with
|
||||
HTMLUnit + JWebUnit + Rhino</li>
|
||||
<li>MochiKit.LoggingPane will now re-use a <tt class="docutils literal"><span class="pre">_MochiKit_LoggingPane</span></tt> DIV element
|
||||
currently in the document instead of always creating one.</li>
|
||||
<li>MochiKit.Base now has operator.mul</li>
|
||||
<li>MochiKit.DOM.formContents correctly handles unchecked checkboxes that have
|
||||
a custom value attribute</li>
|
||||
<li>Added new MochiKit.Color constructors fromComputedStyle and fromText</li>
|
||||
<li>MochiKit.DOM.setNodeAttribute should work now</li>
|
||||
<li>MochiKit.DOM now has a workaround for an IE bug when setting the style
|
||||
property to a string</li>
|
||||
<li>MochiKit.DOM.createDOM now has workarounds for IE bugs when setting the
|
||||
name and for properties</li>
|
||||
<li>MochiKit.DOM.scrapeText now walks the DOM tree in-order</li>
|
||||
<li>MochiKit.LoggingPane now sanitizes the window name to work around IE bug</li>
|
||||
<li>MochiKit.DOM now translates usemap to useMap to work around IE bug</li>
|
||||
<li>MochiKit.Logging is now resistant to Prototype's dumb Object.prototype hacks</li>
|
||||
<li>Added new MochiKit.DOM documentation on element visibility</li>
|
||||
<li>New MochiKit.DOM.elementPosition(element[, relativeTo={x: 0, y: 0}])
|
||||
for determining the position of an element in the document</li>
|
||||
<li>Added new MochiKit.DOM createDOMFunc aliases: CANVAS, STRONG</li>
|
||||
</ul>
|
||||
<p>2005-11-14 v1.1</p>
|
||||
<ul class="simple">
|
||||
<li>Fixed a bug in numberFormatter with large numbers</li>
|
||||
<li>Massively overhauled documentation</li>
|
||||
<li>Fast-path for primitives in MochiKit.Base.compare</li>
|
||||
<li>New groupby and groupby_as_array in MochiKit.Iter</li>
|
||||
<li>Added iterator factory adapter for objects that implement iterateNext()</li>
|
||||
<li>Fixed isoTimestamp to handle timestamps with time zone correctly</li>
|
||||
<li>Added new MochiKit.DOM createDOMFunc aliases: SELECT, OPTION, OPTGROUP,
|
||||
LEGEND, FIELDSET</li>
|
||||
<li>New MochiKit.DOM formContents and enhancement to queryString to support it</li>
|
||||
<li>Updated view_source example to use dp.SyntaxHighlighter 1.3.0</li>
|
||||
<li>MochiKit.LoggingPane now uses named windows based on the URL so that
|
||||
a given URL will get the same LoggingPane window after a reload
|
||||
(at the same position, etc.)</li>
|
||||
<li>MochiKit.DOM now has currentWindow() and currentDocument() context
|
||||
variables that are set with withWindow() and withDocument(). These
|
||||
context variables affect all MochiKit.DOM functionality (getElement,
|
||||
createDOM, etc.)</li>
|
||||
<li>MochiKit.Base.items will now catch and ignore exceptions for properties
|
||||
that are enumerable but not accessible (e.g. permission denied)</li>
|
||||
<li>MochiKit.Async.Deferred's addCallback/addErrback/addBoth
|
||||
now accept additional arguments that are used to create a partially
|
||||
applied function. This differs from Twisted in that the callback/errback
|
||||
result becomes the <em>last</em> argument, not the first when this feature
|
||||
is used.</li>
|
||||
<li>MochiKit.Async's doSimpleXMLHttpRequest will now accept additional
|
||||
arguments which are used to create a GET query string</li>
|
||||
<li>Did some refactoring to reduce the footprint of MochiKit by a few
|
||||
kilobytes</li>
|
||||
<li>escapeHTML to longer escapes ' (apos) and now uses
|
||||
String.replace instead of iterating over every char.</li>
|
||||
<li>Added DeferredLock to Async</li>
|
||||
<li>Renamed getElementsComputedStyle to computedStyle and moved
|
||||
it from MochiKit.Visual to MochiKit.DOM</li>
|
||||
<li>Moved all color support out of MochiKit.Visual and into MochiKit.Color</li>
|
||||
<li>Fixed range() to accept a negative step</li>
|
||||
<li>New alias to MochiKit.swapDOM called removeElement</li>
|
||||
<li>New MochiKit.DOM.setNodeAttribute(node, attr, value) which sets
|
||||
an attribute on a node without raising, roughly equivalent to:
|
||||
updateNodeAttributes(node, {attr: value})</li>
|
||||
<li>New MochiKit.DOM.getNodeAttribute(node, attr) which gets the value of
|
||||
a node's attribute or returns null without raising</li>
|
||||
<li>Fixed a potential IE memory leak if using MochiKit.DOM.addToCallStack
|
||||
directly (addLoadEvent did not leak, since it clears the handler)</li>
|
||||
</ul>
|
||||
<p>2005-10-24 v1.0</p>
|
||||
<ul class="simple">
|
||||
<li>New interpreter example that shows usage of MochiKit.DOM to make
|
||||
an interactive JavaScript interpreter</li>
|
||||
<li>New MochiKit.LoggingPane for use with the MochiKit.Logging
|
||||
debuggingBookmarklet, with logging_pane example to show its usage</li>
|
||||
<li>New mochiregexp example that demonstrates MochiKit.DOM and MochiKit.Async
|
||||
in order to provide a live regular expression matching tool</li>
|
||||
<li>Added advanced number formatting capabilities to MochiKit.Format:
|
||||
numberFormatter(pattern, placeholder="", locale="default") and
|
||||
formatLocale(locale="default")</li>
|
||||
<li>Added updatetree(self, obj[, ...]) to MochiKit.Base, and changed
|
||||
MochiKit.DOM's updateNodeAttributes(node, attrs) to use it when appropiate.</li>
|
||||
<li>Added new MochiKit.DOM createDOMFunc aliases: BUTTON, TT, PRE</li>
|
||||
<li>Added truncToFixed(aNumber, precision) and roundToFixed(aNumber, precision)
|
||||
to MochiKit.Format</li>
|
||||
<li>MochiKit.DateTime can now handle full ISO 8601 timestamps, specifically
|
||||
isoTimestamp(isoString) will convert them to Date objects, and
|
||||
toISOTimestamp(date, true) will return an ISO 8601 timestamp in UTC</li>
|
||||
<li>Fixed missing errback for sendXMLHttpRequest when the server does not
|
||||
respond</li>
|
||||
<li>Fixed infinite recusion bug when using roundClass("DIV", ...)</li>
|
||||
<li>Fixed a bug in MochiKit.Async wait (and callLater) that prevented them
|
||||
from being cancelled properly</li>
|
||||
<li>Workaround in MochiKit.Base bind (and partial) for functions that don't
|
||||
have an apply method, such as alert</li>
|
||||
<li>Reliably return null from the string parsing/manipulation functions if
|
||||
the input can't be coerced to a string (s + "") or the input makes no sense;
|
||||
e.g. isoTimestamp(null) and isoTimestamp("") return null</li>
|
||||
</ul>
|
||||
<p>2005-10-08 v0.90</p>
|
||||
<ul class="simple">
|
||||
<li>Fixed ISO compliance with toISODate</li>
|
||||
<li>Added missing operator.sub</li>
|
||||
<li>Placated Mozilla's strict warnings a bit</li>
|
||||
<li>Added JSON serialization and unserialization support to MochiKit.Base:
|
||||
serializeJSON, evalJSON, registerJSON. This is very similar to the repr
|
||||
API.</li>
|
||||
<li>Fixed a bug in the script loader that failed in some scenarios when a script
|
||||
tag did not have a "src" attribute (thanks Ian!)</li>
|
||||
<li>Added new MochiKit.DOM createDOMFunc aliases: H1, H2, H3, BR, HR, TEXTAREA,
|
||||
P, FORM</li>
|
||||
<li>Use encodeURIComponent / decodeURIComponent for MochiKit.Base urlEncode
|
||||
and parseQueryString, when available.</li>
|
||||
</ul>
|
||||
<p>2005-08-12 v0.80</p>
|
||||
<ul class="simple">
|
||||
<li>Source highlighting in all examples, moved to a view-source example</li>
|
||||
<li>Added some experimental syntax highlighting for the Rounded Corners example,
|
||||
via the LGPL dp.SyntaxHighlighter 1.2.0 now included in examples/common/lib</li>
|
||||
<li>Use an indirect binding for the logger conveniences, so that the global
|
||||
logger could be replaced by setting MochiKit.Logger.logger to something else
|
||||
(though an observer is probably a better choice).</li>
|
||||
<li>Allow MochiKit.DOM.getElementsByTagAndClassName to take a string for parent,
|
||||
which will be looked up with getElement</li>
|
||||
<li>Fixed bug in MochiKit.Color.fromBackground (was using node.parent instead of
|
||||
node.parentNode)</li>
|
||||
<li>Consider a 304 (NOT_MODIFIED) response from XMLHttpRequest to be success</li>
|
||||
<li>Disabled Mozilla map(...) fast-path due to Deer Park compatibility issues</li>
|
||||
<li>Possible workaround for Safari issue with swapDOM, where it would get
|
||||
confused because two elements were in the DOM at the same time with the
|
||||
same id</li>
|
||||
<li>Added missing THEAD convenience function to MochiKit.DOM</li>
|
||||
<li>Added lstrip, rstrip, strip to MochiKit.Format</li>
|
||||
<li>Added updateNodeAttributes, appendChildNodes, replaceChildNodes to
|
||||
MochiKit.DOM</li>
|
||||
<li>MochiKit.Iter.iextend now has a fast-path for array-like objects</li>
|
||||
<li>Added HSV color space support to MochiKit.Visual</li>
|
||||
<li>Fixed a bug in the sortable_tables example, it now converts types
|
||||
correctly</li>
|
||||
<li>Fixed a bug where MochiKit.DOM referenced MochiKit.Iter.next from global
|
||||
scope</li>
|
||||
</ul>
|
||||
<p>2005-08-04 v0.70</p>
|
||||
<ul class="simple">
|
||||
<li>New ajax_tables example, which shows off XMLHttpRequest, ajax, json, and
|
||||
a little TAL-ish DOM templating attribute language.</li>
|
||||
<li>sendXMLHttpRequest and functions that use it (loadJSONDoc, etc.) no longer
|
||||
ignore requests with status == 0, which seems to happen for cached or local
|
||||
requests</li>
|
||||
<li>Added sendXMLHttpRequest to MochiKit.Async.EXPORT, d'oh.</li>
|
||||
<li>Changed scrapeText API to return a string by default. This is API-breaking!
|
||||
It was dumb to have the default return value be the form you almost never
|
||||
want. Sorry.</li>
|
||||
<li>Added special form to swapDOM(dest, src). If src is null, dest is removed
|
||||
(where previously you'd likely get a DOM exception).</li>
|
||||
<li>Added three new functions to MochiKit.Base for dealing with URL query
|
||||
strings: urlEncode, queryString, parseQueryString</li>
|
||||
<li>MochiKit.DOM.createDOM will now use attr[k] = v for all browsers if the name
|
||||
starts with "on" (e.g. "onclick"). If v is a string, it will set it to
|
||||
new Function(v).</li>
|
||||
<li>Another workaround for Internet "worst browser ever" Explorer's setAttribute
|
||||
usage in MochiKit.DOM.createDOM (checked -> defaultChecked).</li>
|
||||
<li>Added UL, OL, LI convenience createDOM aliases to MochiKit.DOM</li>
|
||||
<li>Packing is now done by Dojo's custom Rhino interpreter, so it's much smaller
|
||||
now!</li>
|
||||
</ul>
|
||||
<p>2005-07-29 v0.60</p>
|
||||
<ul class="simple">
|
||||
<li>Beefed up the MochiKit.DOM test suite</li>
|
||||
<li>Fixed return value for MochiKit.DOM.swapElementClass, could return
|
||||
false unexpectedly before</li>
|
||||
<li>Added an optional "parent" argument to
|
||||
MochiKit.DOM.getElementsByTagAndClassName</li>
|
||||
<li>Added a "packed" version in packed/lib/MochiKit/MochiKit.js</li>
|
||||
<li>Changed build script to rewrite the URLs in tests to account for the
|
||||
JSAN-required reorganization</li>
|
||||
<li>MochiKit.Compat to potentially work around IE 5.5 issues
|
||||
(5.0 still not supported). Test.Simple doesn't seem to work there,
|
||||
though.</li>
|
||||
<li>Several minor documentation corrections</li>
|
||||
</ul>
|
||||
<p>2005-07-27 v0.50</p>
|
||||
<ul class="simple">
|
||||
<li>Initial Release</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,162 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
||||
<title>MochiKit.Visual - visual effects</title>
|
||||
|
||||
<link rel="stylesheet" href="../../../include/css/documentation.css" type="text/css" />
|
||||
<script type="text/javascript" src="../../../packed/lib/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="../../js/toc.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document">
|
||||
<div class="section">
|
||||
<h1><a id="name" name="name">Name</a></h1>
|
||||
<p>MochiKit.Visual - visual effects</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="synopsis" name="synopsis">Synopsis</a></h1>
|
||||
<pre class="literal-block">
|
||||
// round the corners of all h1 elements
|
||||
roundClass("h1", null);
|
||||
|
||||
// round the top left corner of the element with the id "title"
|
||||
roundElement("title", {corners: "tl"});
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="description" name="description">Description</a></h1>
|
||||
<p>MochiKit.Visual provides visual effects and support functions for visuals.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="dependencies" name="dependencies">Dependencies</a></h1>
|
||||
<ul class="simple">
|
||||
<li><a class="mochiref reference" href="Base.html">MochiKit.Base</a></li>
|
||||
<li><a class="mochiref reference" href="Iter.html">MochiKit.Iter</a></li>
|
||||
<li><a class="mochiref reference" href="DOM.html">MochiKit.DOM</a></li>
|
||||
<li><a class="mochiref reference" href="Color.html">MochiKit.Color</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="overview" name="overview">Overview</a></h1>
|
||||
<p>At this time, MochiKit.Visual provides one visual effect: rounded corners
|
||||
for your HTML elements. These rounded corners are created completely
|
||||
through CSS manipulations and require no external images or style sheets.
|
||||
This implementation was adapted from <a class="reference" href="http://www.openrico.org">Rico</a>.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="api-reference" name="api-reference">API Reference</a></h1>
|
||||
<div class="section">
|
||||
<h2><a id="functions" name="functions">Functions</a></h2>
|
||||
<p>
|
||||
<a name="fn-roundclass"></a>
|
||||
<a class="mochidef reference" href="#fn-roundclass">roundClass(tagName[, className[, options]])</a>:</p>
|
||||
<blockquote>
|
||||
Rounds all of the elements that match the <tt class="docutils literal"><span class="pre">tagName</span></tt> and <tt class="docutils literal"><span class="pre">className</span></tt>
|
||||
specifiers, using the options provided. <tt class="docutils literal"><span class="pre">tagName</span></tt> or <tt class="docutils literal"><span class="pre">className</span></tt> can
|
||||
be <tt class="docutils literal"><span class="pre">null</span></tt> to match all tags or classes. For more information about
|
||||
the options, see the <a class="mochiref reference" href="#fn-roundelement">roundElement</a> function.</blockquote>
|
||||
<p>
|
||||
<a name="fn-roundelement"></a>
|
||||
<a class="mochidef reference" href="#fn-roundelement">roundElement(element[, options])</a>:</p>
|
||||
<blockquote>
|
||||
<p>Immediately round the corners of the specified element.
|
||||
The element can be given as either a string
|
||||
with the element ID, or as an element object.</p>
|
||||
<p>The options mapping has the following defaults:</p>
|
||||
<table border="1" class="docutils">
|
||||
<colgroup>
|
||||
<col width="35%" />
|
||||
<col width="65%" />
|
||||
</colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td>corners</td>
|
||||
<td><tt class="docutils literal"><span class="pre">"all"</span></tt></td>
|
||||
</tr>
|
||||
<tr><td>color</td>
|
||||
<td><tt class="docutils literal"><span class="pre">"fromElement"</span></tt></td>
|
||||
</tr>
|
||||
<tr><td>bgColor</td>
|
||||
<td><tt class="docutils literal"><span class="pre">"fromParent"</span></tt></td>
|
||||
</tr>
|
||||
<tr><td>blend</td>
|
||||
<td><tt class="docutils literal"><span class="pre">true</span></tt></td>
|
||||
</tr>
|
||||
<tr><td>border</td>
|
||||
<td><tt class="docutils literal"><span class="pre">false</span></tt></td>
|
||||
</tr>
|
||||
<tr><td>compact</td>
|
||||
<td><tt class="docutils literal"><span class="pre">false</span></tt></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>corners:</p>
|
||||
<blockquote>
|
||||
<p>specifies which corners of the element should be rounded.
|
||||
Choices are:</p>
|
||||
<ul class="simple">
|
||||
<li>all</li>
|
||||
<li>top</li>
|
||||
<li>bottom</li>
|
||||
<li>tl (top left)</li>
|
||||
<li>bl (bottom left)</li>
|
||||
<li>tr (top right)</li>
|
||||
<li>br (bottom right)</li>
|
||||
</ul>
|
||||
<dl class="docutils">
|
||||
<dt>Example:</dt>
|
||||
<dd><tt class="docutils literal"><span class="pre">"tl</span> <span class="pre">br"</span></tt>: top-left and bottom-right corners are rounded</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
<dl class="docutils">
|
||||
<dt>blend:</dt>
|
||||
<dd>specifies whether the color and background color should be blended
|
||||
together to produce the border color.</dd>
|
||||
</dl>
|
||||
</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="see-also" name="see-also">See Also</a></h1>
|
||||
<table class="docutils footnote" frame="void" id="id1" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a name="id1">[1]</a></td><td>Application Kit Reference - NSColor: <a class="reference" href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSColor.html">http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/ObjC_classic/Classes/NSColor.html</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="id2" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a name="id2">[2]</a></td><td>SVG 1.0 color keywords: <a class="reference" href="http://www.w3.org/TR/SVG/types.html#ColorKeywords">http://www.w3.org/TR/SVG/types.html#ColorKeywords</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="id3" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a name="id3">[3]</a></td><td>W3C CSS3 Color Module: <a class="reference" href="http://www.w3.org/TR/css3-color/#svg-color">http://www.w3.org/TR/css3-color/#svg-color</a></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="authors" name="authors">Authors</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Kevin Dangoor <<a class="reference" href="mailto:dangoor@gmail.com">dangoor@gmail.com</a>></li>
|
||||
<li>Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>></li>
|
||||
<li>Originally adapted from Rico <<a class="reference" href="http://openrico.org/">http://openrico.org/</a>> (though little remains)</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="copyright" name="copyright">Copyright</a></h1>
|
||||
<p>Copyright 2005 Bob Ippolito <<a class="reference" href="mailto:bob@redivi.com">bob@redivi.com</a>>. This program is dual-licensed
|
||||
free software; you can redistribute it and/or modify it under the terms of the
|
||||
<a class="reference" href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> or the <a class="reference" href="http://www.opensource.org/licenses/afl-2.1.php">Academic Free License v2.1</a>.</p>
|
||||
<p>Portions adapted from <a class="reference" href="http://www.openrico.org">Rico</a> are available under the terms of the
|
||||
<a class="reference" href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache License, Version 2.0</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user